home *** CD-ROM | disk | FTP | other *** search
-
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <dos/dosextens.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/exec.h>
- #include <proto/intuition.h>
- #include <proto/gadtools.h>
- #include <proto/wb.h>
- #include <string.h>
-
- #include "code.h"
- #include "version.h"
- #include "yak.h"
- #include "hotkey_types.h"
- #include "handlers.h"
- #include "keydef.h"
- #include "gui.h"
- #include "KeyDef_Window.h"
- #include "Requesters.h"
- #include "yak_locale_strings.h"
-
-
- IMPORT LONG (*HandleIDCMP)(VOID);
-
- /* Online help system */
- IMPORT void ShowYakHelp(char *, char *);
- IMPORT char *PrefsHelp;
-
-
- struct Window *KeyDefWnd = NULL;
- struct Gadget *KeyDefGList = NULL;
- struct Gadget *KeyDefGadgets[KeyDef_CNT];
- UWORD KeyDefWidth = 535;
- UWORD KeyDefHeight = 84;
- UBYTE *KeyDefWdt = NULL;
- BOOL KeyDefWdi = FALSE;
-
- struct AppWindow *KeyDefAppWin; /* AppWindow pointer */
- IMPORT struct MsgPort *AppMsgPort;
-
- IMPORT UBYTE ParentWindowID;
- static APTR CurObj;
- static YakKeyDef KeyDef;
-
-
- UBYTE *Class0Labels[5];
-
- void
- InitClass0Labels(VOID)
- {
- 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(VOID)
- {
- 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,
- BUTTON_KIND,
- BUTTON_KIND
- };
-
- struct NewGadget KeyDefNGad[] = {
- 66, 13, 166, 13, NULL, NULL, GD_Class, PLACETEXT_LEFT, NULL, CLASS_STRING,
- 343, 13, 186, 13, NULL, NULL, GD_Stroke, PLACETEXT_LEFT, NULL, STROKE_STRING,
- 108, 38, 421, 14, NULL, NULL, GD_Desc, PLACETEXT_LEFT, NULL, DESC_STRING,
- 6, 68, 100, 13, NULL, NULL, GD_Ok, PLACETEXT_IN, NULL, OK_STRING,
- 429, 68, 100, 13, NULL, NULL, GD_Cancel, PLACETEXT_IN, NULL, CANCEL_STRING,
- 147, 68, 100, 13, NULL, NULL, GD_Clear, PLACETEXT_IN, NULL, CLEAR_STRING,
- 288, 68, 100, 13, NULL, NULL, GD_Help, PLACETEXT_IN, NULL, HELP_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),
- (TAG_DONE),
- (TAG_DONE)
- };
-
-
-
- /* 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);
- if (ParentWindowID == MCYCLING_WINDOW)
- {
- InitWindowGadget(GDX_Class, GA_Disabled, 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);
- }
-
-
-
- /* switch from misc window to keydef window */
- BOOL
- SwitchToKeyDefWindow(UBYTE I_ParentWindowID, APTR I_object, char *I_action)
- {
- static char title[80];
- char *def;
-
- strcpy(title, getString(KeyDef_Window_TITLE));
- strcat(title, " ");
- if (I_action)
- {
- strcat(title, I_action);
- }
- else
- {
- strcat(title, "<<unnamed>>");
- }
- KeyDefWdt = title;
-
- ParentWindowID = I_ParentWindowID;
- CurObj = I_object;
-
- if (ParentWindowID == HOTKEY_WINDOW)
- def = ((YakHotKey *)CurObj)->yhk_KeyDef;
- else
- def = ((YakHandler *)CurObj)->KeyDef;
-
- ParseKeyDef(def, &KeyDef);
-
- CloseWindowID(ParentWindowID);
-
- return ShowKeyDefWindow();
- }
-
-
- /* handle KeyDef window events */
- LONG
- HandleKeyDefIDCMP(VOID)
- {
- struct IntuiMessage *msg;
- struct Gadget *gadget;
- ULONG class;
- UWORD code;
- UWORD qual, newqual;
- BOOL close=FALSE;
- LONG ret=RET_OKAY;
-
- while (!close && (msg = GT_GetIMsg(KeyDefWnd->UserPort)))
- {
- class = msg->Class;
- code = msg->Code;
- qual = msg->Qualifier;
- gadget = (struct Gadget *)msg->IAddress;
- GT_ReplyIMsg(msg);
-
- switch (class)
- {
- case GADGETUP:
- case GADGETDOWN:
- switch (gadget->GadgetID)
- {
- case GD_Class:
- KeyDef.ykd_Class = code;
- KeyDef.ykd_Stroke = HKSTROKE_DOWN;
- KeyDef.ykd_Code = NO_IECODE;
- KeyDef.ykd_Qual = KeyDef.ykd_IQual = KeyDef.ykd_SQual = NO_IEQUALIFIER;
-
- InitKeyDefGadgets();
- break;
-
- case GD_Stroke:
- if ((KeyDef.ykd_Stroke=code) == HKSTROKE_UP)
- {
- KeyDef.ykd_Qual &= ~IEQUALIFIER_REPEAT;
- KeyDef.ykd_IQual &= ~IEQUALIFIER_REPEAT;
- }
-
- InitKeyDefGadgets();
- break;
-
- case GD_Desc:
- if (ParseKeyDef(GetString(gadget), &KeyDef) == -1)
- PostError(getString(Invalid_hotkey_specif_ERR));
-
- InitKeyDefGadgets();
-
- break;
-
- case GD_Cancel:
- CloseKeyDefWindow();
- if (!ShowWindowID(ParentWindowID))
- ret = RET_QUIT;
- close = TRUE;
- break;
-
- case GD_Clear:
- KeyDef.ykd_Stroke = HKSTROKE_DOWN;
- KeyDef.ykd_Code = NO_IECODE;
- KeyDef.ykd_Qual =
- KeyDef.ykd_IQual =
- KeyDef.ykd_SQual = NO_IEQUALIFIER;
- InitKeyDefGadgets();
- break;
-
- case GD_Help:
- ShowYakHelp(PrefsHelp, "Hotkey Description String");
- break;
-
- case GD_Ok:
- if (ParentWindowID == HOTKEY_WINDOW)
- {
- if (ModifyYHKKeyDef(CurObj, GetString(KeyDefGadgets[GDX_Desc])) == TRUE)
- {
-
- /* Turn hotkey on active by default */
- ((YakHotKey *)CurObj)->yhk_State = YKHK_ACTIVE;
- }
-
- }
- else
- {
- char *newdef;
-
- if (newdef=DupStr(GetString(KeyDefGadgets[GDX_Desc])))
- {
- YakHandler *curhd=(YakHandler *)CurObj;
- if (curhd->KeyDef) FreeVec(curhd->KeyDef);
- curhd->KeyDef = newdef;
- }
- else
- PostError(getString(Allocation_ERR));
- }
- CloseKeyDefWindow();
- if (!ShowWindowID(ParentWindowID))
- ret = RET_QUIT;
- close = TRUE;
- break;
-
- } /* switch (gadget->GadgetID) */
- break;
-
- case IDCMP_RAWKEY:
- if ( (!(code & IECODE_UP_PREFIX) || code == 0xe2 ) && /* a downstroke || capslock up*/
- ((KeyDef.ykd_Class == HKCLASS_RAWKEY) || (KeyDef.ykd_Class == HKCLASS_RAWMOUSE)) )
- {
- if (newqual = IsQualifierPad(code))
- {
- newqual &= ~KeyDef.ykd_SQual;
- newqual &= ~KeyDef.ykd_IQual;
-
- /* Toggle Qualifier */
- KeyDef.ykd_Qual ^= newqual;
- }
- else
- {
- if (KeyDef.ykd_Class == HKCLASS_RAWKEY)
- {
- if ((code == KeyDef.ykd_Code) && (KeyDef.ykd_Stroke != HKSTROKE_UP))
- {
- /* Toggle Repeat Keyword */
- if(!(KeyDef.ykd_IQual & IEQUALIFIER_REPEAT))
- KeyDef.ykd_Qual ^= IEQUALIFIER_REPEAT;
-
- }
- else /* New key or upstroke mode */
- {
- KeyDef.ykd_Qual &= ~IEQUALIFIER_KEYS;
- KeyDef.ykd_IQual &= ~IEQUALIFIER_KEYS;
- KeyDef.ykd_Qual |= qual & IEQUALIFIER_NUMERICPAD;
- KeyDef.ykd_Code = code;
- }
- }
- }
-
- InitKeyDefGadgets();
- }
- break;
-
- case IDCMP_MOUSEBUTTONS:
- if (!(code & IECODE_UP_PREFIX) && /* a downstroke */
- ((KeyDef.ykd_Class == HKCLASS_RAWKEY) || (KeyDef.ykd_Class == HKCLASS_RAWMOUSE)) )
- {
- switch(code)
- {
- case IECODE_RBUTTON:
- newqual = IEQUALIFIER_RBUTTON;
- break;
- case IECODE_LBUTTON:
- newqual = IEQUALIFIER_LEFTBUTTON;
- break;
- case IECODE_MBUTTON:
- newqual = IEQUALIFIER_MIDBUTTON;
- break;
- default:
- newqual = NO_IEQUALIFIER;
- break;
- }
-
- newqual &= ~KeyDef.ykd_IQual;
-
- if (KeyDef.ykd_Class == HKCLASS_RAWMOUSE)
- {
- if (KeyDef.ykd_Code == code)
- {
- KeyDef.ykd_Qual &= ~newqual;
- KeyDef.ykd_Code = NO_IECODE;
- }
- else
- {
- KeyDef.ykd_Qual |= newqual;
- KeyDef.ykd_Code = code;
- }
- }
- else
- KeyDef.ykd_Qual ^= newqual;
-
- InitKeyDefGadgets();
- }
- break;
-
- case REFRESHWINDOW:
- GT_BeginRefresh(KeyDefWnd);
- GT_EndRefresh(KeyDefWnd, TRUE);
- break;
-
- } /* switch (class) */
-
- } /* while more messages */
-
- return ret;
- }
-
-
- void
- CloseKeyDefWindow( void )
- {
- CloseOneWindow (KeyDefWnd, NULL, KeyDefGList, KeyDefAppWin);
- KeyDefWnd = NULL;
-
- /* Re-enable Yak now that our job is finished */
- BrokerCommand("Yak", CXCMD_ENABLE);
-
- }
-
-
- void
- KeyDefRender( void )
- {
- UWORD Width, Height, X, Y;
-
- ComputeFont( KeyDefWidth, KeyDefHeight );
-
- Width = ComputeX( KeyDefWidth );
- Height= ComputeY( 65);
-
- X = OffX;
- Y = OffY;
- DrawThinBevelBox( Scr, KeyDefWnd->RPort, X,Y,
- Width,
- Height,
- FALSE );
-
- Y = OffY + ComputeY(65);
- DrawThinBevelBox( Scr, KeyDefWnd->RPort, X,Y,
- Width,
- ComputeY(KeyDefHeight)-Height,
- FALSE );
- }
-
-
- int
- OpenKeyDefWindow(VOID)
- {
- struct NewGadget ng;
- struct Gadget *g;
- WORD wleft=WindowLeft, wtop=WindowTop;
- UWORD ww, wh;
- UBYTE lc, tc;
-
- ComputeFont( KeyDefWidth, KeyDefHeight );
-
- ww = OffX + ComputeX( KeyDefWidth ) + Scr->WBorRight;
- wh = OffY + ComputeY( KeyDefHeight ) + Scr->WBorBottom;
-
- SetUpWindowCoordinates(ww, wh, &wleft, &wtop);
-
- if ( ! ( g = CreateContext( &KeyDefGList )))
- return( 1L );
-
- for( lc = 0, tc = 0; lc < KeyDef_CNT; lc++ ) {
-
- CopyMem((char * )&KeyDefNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
-
- ng.ng_VisualInfo = VisualInfo;
- ng.ng_TextAttr = Font;
- ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
- ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
- ng.ng_Width = ComputeX( ng.ng_Width );
- ng.ng_Height = ComputeY( ng.ng_Height);
-
- KeyDefGadgets[ lc ] = g = CreateGadgetA((ULONG)KeyDefGTypes[ lc ], g, &ng, ( struct TagItem * )&KeyDefGTags[ tc ] );
-
- while( KeyDefGTags[ tc ] ) tc += 2;
- tc++;
-
- if ( NOT g )
- return( 2L );
- }
-
- if ( ! ( KeyDefWnd = OpenWindowTags( NULL,
- WA_Left, wleft,
- WA_Top, wtop,
- WA_Width, ww,
- WA_Height, wh,
- WA_IDCMP, CYCLEIDCMP|TEXTIDCMP|BUTTONIDCMP|IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
- WA_Flags, WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_RMBTRAP,
- WA_Gadgets, KeyDefGList,
- WA_Title, KeyDefWdt,
- WA_ScreenTitle, getString(COPYRIGHT_STRING),
- WA_PubScreenName,PubScreenName,
- TAG_DONE )))
- return( 4L );
-
- KeyDefAppWin = AddAppWindowA(0, 0, KeyDefWnd, AppMsgPort, NULL);
-
- GT_RefreshWindow( KeyDefWnd, NULL );
-
- KeyDefRender();
-
- return( 0L );
- }
-
-
- /* show our KeyDef window */
- BOOL
- ShowKeyDefWindow(VOID)
- {
- if (!KeyDefWdi)
- {
- KeyDefWdi = TRUE;
-
- LocalizeNGadLabels (KeyDef_CNT, KeyDefNGad);
- InitClass0Labels ();
- InitStroke0Labels ();
- }
-
- if (!OpenKeyDefWindow()) /* like the name says... */
- {
- /* Disable Yak so that it doesn't interfere with us */
- BrokerCommand("Yak", CXCMD_DISABLE);
-
- InitKeyDefGadgets();
- wndsigflag = 1 << KeyDefWnd->UserPort->mp_SigBit;
- curwin = KeyDefWnd;
- curwinID = KEYDEF_WINDOW;
- HandleIDCMP = HandleKeyDefIDCMP;
- return TRUE;
- }
-
- FreeGadgets(KeyDefGList);
- CloseDownScreen();
- curwin = NULL;
- wndsigflag = 0L;
- return FALSE;
- }
-
-