home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
cdity
/
yak
/
src
/
keydef_window.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-13
|
20KB
|
636 lines
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dosextens.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <intuition/intuitionbase.h>
#include <libraries/gadtools.h>
#include <libraries/commodities.h>
#include <proto/commodities.h>
#include <proto/keymap.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/locale.h>
#include <proto/utility.h>
#include <proto/dos.h>
#include <string.h>
#include <ctype.h>
#include "code.h"
#include "version.h"
#include "hotkey_types.h"
#include "yak.h"
#include "gui.h"
#include "KeyDef_Window.h"
#define CATCOMP_NUMBERS
#include "locale/yak_locale_strings.h"
extern LONG (*HandleIDCMP)(void);
struct Window *KeyDefWnd = NULL;
struct Gadget *KeyDefGList = NULL;
struct Gadget *KeyDefGadgets[KeyDef_CNT];
UWORD KeyDefLeft = 0;
UWORD KeyDefTop = 0;
UWORD KeyDefWidth = 517;
UWORD KeyDefHeight = 85;
UBYTE *KeyDefWdt = NULL;
IMPORT YakHotKey *curhk;
IMPORT UWORD curtype;
static YakKeyDef KeyDef;
UBYTE *Class0Labels[5];
void
InitClass0Labels()
{
Class0Labels[0] = getString(RawKey_CLASS);
Class0Labels[1] = getString(RawMouse_CLASS);
Class0Labels[2] = getString(DiskInserted_CLASS);
Class0Labels[3] = getString(DiskRemoved_CLASS);
Class0Labels[4] = NULL;
}
UBYTE *Stroke0Labels[4];
void
InitStroke0Labels()
{
Stroke0Labels[0] = getString(Down_STROKE);
Stroke0Labels[1] = getString(Up_STROKE);
Stroke0Labels[2] = getString(Down_Up_STROKE);
Stroke0Labels[3] = NULL;
}
UWORD KeyDefGTypes[] =
{
CYCLE_KIND,
CYCLE_KIND,
STRING_KIND,
BUTTON_KIND,
BUTTON_KIND
};
struct NewGadget KeyDefNGad[] = {
66, 13, 166, 13, NULL, NULL, GD_Class, PLACETEXT_LEFT, NULL, NULL,
325, 13, 186, 13, NULL, NULL, GD_Stroke, PLACETEXT_LEFT, NULL, NULL,
108, 38, 403, 14, NULL, NULL, GD_Desc, PLACETEXT_LEFT, NULL, NULL,
6, 68, 79, 13, NULL, NULL, GD_Ok, PLACETEXT_IN, NULL, NULL,
431, 68, 79, 13, NULL, NULL, GD_Cancel, PLACETEXT_IN, NULL, NULL
};
void InitKeyDefNGad (void)
{
KeyDefNGad[GD_Class].ng_GadgetText = getString(CLASS_STRING);
KeyDefNGad[GD_Stroke].ng_GadgetText = getString(STROKE_STRING);
KeyDefNGad[GD_Desc].ng_GadgetText = getString(DESC_STRING);
KeyDefNGad[GD_Ok].ng_GadgetText = getString(OK_STRING);
KeyDefNGad[GD_Cancel].ng_GadgetText = getString(CANCEL_STRING);
}
ULONG KeyDefGTags[] = {
(GTCY_Labels), (ULONG)&Class0Labels[ 0 ], (TAG_DONE),
(GTCY_Labels), (ULONG)&Stroke0Labels[ 0 ], (TAG_DONE),
(GTST_MaxChars), 256, (TAG_DONE),
(TAG_DONE),
(TAG_DONE)
};
static __regargs void
ConvertQualifiers(UWORD qual, UWORD iqual, UWORD squal, char *qualstr)
{
UWORD i;
*qualstr = '\0';
for (i=0; i<SAMEQUALIFIERS_NUMBER; i++)
{
if ((qual & squal & SameQualifierArray[i].qat_ID) == SameQualifierArray[i].qat_ID)
{
*qualstr++ = ' ';
qualstr = stpcpy(qualstr, SameQualifierArray[i].qat_Str);
}
if ((iqual & squal & SameQualifierArray[i].qat_ID) == SameQualifierArray[i].qat_ID)
{
*qualstr++ = ' ';
*qualstr++ = '-';
qualstr = stpcpy(qualstr, SameQualifierArray[i].qat_Str);
}
}
qual &= ~squal;
iqual &= ~squal;
for (i=0; i<QUALIFIERS_NUMBER; i++)
{
if (qual & QualifierArray[i].qat_ID)
{
*qualstr++ = ' ';
qualstr = stpcpy(qualstr, QualifierArray[i].qat_Str);
}
if (iqual & QualifierArray[i].qat_ID)
{
*qualstr++ = ' ';
*qualstr++ = '-';
qualstr = stpcpy(qualstr, QualifierArray[i].qat_Str);
}
}
}
static __regargs BOOL
ConvertCode(UWORD code, char *codestr)
{
*codestr = '\0';
if (code != NO_IECODE)
{
struct InputEvent ievent;
UWORD i;
for (i=0; i<CODES_NUMBER; i++)
{
if (code == CodeArray[i].cat_Code)
{
codestr[0] = ' ';
strcpy(codestr+1, CodeArray[i].cat_Str);
return TRUE;
}
}
ievent.ie_Class = IECLASS_RAWKEY;
ievent.ie_Code = code;
ievent.ie_Qualifier = NO_IEQUALIFIER;
ievent.ie_Prev1DownCode = ievent.ie_Prev1DownQual = NO_IEQUALIFIER;
ievent.ie_Prev2DownCode = ievent.ie_Prev2DownQual = NO_IEQUALIFIER;
if((MapRawKey(&ievent, codestr+1, 1, NULL) == 1) &&
(codestr[1] != '-')) /* forbidden */
{
codestr[0] = ' ';
codestr[2] = '\0';
return TRUE;
}
}
return FALSE;
}
static __regargs BOOL
BuildKeyDef(YakKeyDef *ykd, STRPTR desc)
{
BOOL ret;
UBYTE codestr[20], qualstr[110];
ConvertQualifiers(ykd->ykd_Qual, ykd->ykd_IQual, ykd->ykd_SQual, qualstr);
if (ykd->ykd_Class > HKCLASS_RAWMOUSE)
ret = TRUE;
else
ret = ConvertCode(ykd->ykd_Code, codestr);
stpcpy(desc, ClassArray[ykd->ykd_Class]);
strcat(desc, qualstr);
strcat(desc, StrokeArray[ykd->ykd_Stroke]);
strcat(desc, codestr);
return ret;
}
/* initialise all gadgets of keydef window */
static void
InitKeyDefGadgets(void)
{
UBYTE SeqString[127];
BOOL SeqOk = BuildKeyDef(&KeyDef, SeqString);
InitWindowGadget(GDX_Class, GTCY_Active, KeyDef.ykd_Class, KEYDEF_WINDOW);
InitWindowGadget(GDX_Desc, GTST_String, (LONG)SeqString, KEYDEF_WINDOW);
InitWindowGadget(GDX_Stroke, GTCY_Active, KeyDef.ykd_Stroke, KEYDEF_WINDOW);
InitWindowGadget(GDX_Stroke, GA_Disabled, KeyDef.ykd_Class, KEYDEF_WINDOW);
InitWindowGadget(GDX_Ok, GA_Disabled, !SeqOk, KEYDEF_WINDOW);
}
static __regargs LONG
ParseKeyDef(STRPTR desc, YakKeyDef *ykd)
{
IX ix;
LONG ret;
if (!(ret=ParseIX(desc, &ix)))
{
/* Class ? */
switch(ix.ix_Class)
{
case IECLASS_RAWKEY:
ykd->ykd_Class = HKCLASS_RAWKEY;
break;
case IECLASS_RAWMOUSE:
ykd->ykd_Class = HKCLASS_RAWMOUSE;
break;
case IECLASS_DISKINSERTED:
ykd->ykd_Class = HKCLASS_DISKINSERTED;
break;
case IECLASS_DISKREMOVED:
ykd->ykd_Class = HKCLASS_DISKREMOVED;
break;
default:
return -1;
}
/* Qualifier ? */
ykd->ykd_Qual = ix.ix_Qualifier;
ykd->ykd_IQual = ~ix.ix_QualMask;
ykd->ykd_SQual = NO_IEQUALIFIER;
if (ix.ix_QualSame & IXSYM_SHIFT) ykd->ykd_SQual |= IXSYM_SHIFTMASK;
if (ix.ix_QualSame & IXSYM_CAPS) ykd->ykd_SQual |= IXSYM_CAPSMASK;
if (ix.ix_QualSame & IXSYM_ALT) ykd->ykd_SQual |= IXSYM_ALTMASK;
/* Stroke ? */
if (ix.ix_Code & IECODE_UP_PREFIX)
ykd->ykd_Stroke = HKSTROKE_UP;
else
if (~ix.ix_CodeMask & IECODE_UP_PREFIX)
ykd->ykd_Stroke = HKSTROKE_DOWN_UP;
else
ykd->ykd_Stroke = HKSTROKE_DOWN;
/* Code ? */
if (!ix.ix_Code && (ix.ix_Class == IECLASS_RAWMOUSE))
ykd->ykd_Code = NO_IECODE;
else
ykd->ykd_Code = ix.ix_Code & ~IECODE_UP_PREFIX;
}
else
{
if (ret == -2) /* NULL description */
{
ykd->ykd_Class = HKCLASS_RAWKEY;
ykd->ykd_Qual = ykd->ykd_IQual = ykd->ykd_SQual = NO_IEQUALIFIER;
ykd->ykd_Stroke = HKSTROKE_DOWN;
ykd->ykd_Code = NO_IECODE;
}
}
return ret;
}
static __regargs UWORD
IsQualifierPad(UWORD code)
{
UWORD i;
for (i=0; i<QUALIFIERSPAD_NUMBER; i++)
if (QualifierPadArray[i].qpat_Code == code)
return Qual