home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- ************************* BGUI HOTKEY WINDOW **************************
- ************************************************************************/
-
- #include <exec/types.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/bgui.h>
- #include <libraries/bgui_macros.h>
- #include <graphics/displayinfo.h>
- #include <graphics/gfxbase.h>
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/bgui.h>
- #include <proto/graphics.h>
- #include <proto/locale.h>
- #include <proto/utility.h>
- #include <proto/wb.h>
- #include <clib/alib_protos.h>
- #include <string.h>
-
- #include "code.h"
- #include "yak.h"
- #include "version.h"
- #include "hotkey_types.h"
- #include "gui.h"
- #include "hotkey_window.h"
- #include "KeyDef_window.h"
- #include "Options_window.h"
- #include "Requesters.h"
-
- #define CATCOMP_NUMBERS
- #include "yak_locale_strings.h"
-
- #ifdef _DCC
- # include <lists.h>
- #else
- # include "sas_lists.h"
- #endif
-
- /************************************************************************
- ***************************** REFERENCES ******************************
- ************************************************************************/
-
- IMPORT LONG (*HandleReturnID)(LONG ID);
- IMPORT struct MinList Actions1List;
-
- extern void HookEntry(void); /* from amiga.lib */
-
- IMPORT char *PrefsHelp;
-
- /************************************************************************
- ***************************** PROTOTYPES ******************************
- ************************************************************************/
-
- static void InitHook(struct Hook *hook,ULONG (*hookfn)(),APTR data);
-
- static SAVEDS ASM ULONG ExecListRsrcHandler(REG(a0) struct Hook *hook, REG(a2) void *obj, REG(a1) void *msg);
- static SAVEDS ASM ULONG ExecListDispHandler(REG(a0) struct Hook *hook, REG(a2) void *obj, REG(a1) void *msg);
-
- static void UpdateHotKeyLV(struct List *list);
-
- /************************************************************************
- ***************************** LOCAL DATA ******************************
- ************************************************************************/
-
- struct Window *HotKeyWnd = NULL;
- Object *HotKeyWndObj = NULL;
- Object *HotKeyObjects[HotKey_CNT];
- struct IBox HotKeyBox;
- BOOL HotKeyBoxValid = FALSE;
-
- char *Actions1Array[NUM_HOTKEY_TYPES+1];
-
- struct Hook ExecListRsrcHook;
- struct Hook ExecListDispHook;
-
- /************************************************************************
- ***************************** INITHOOK() ******************************
- *************************************************************************
- * Initialize the hook struct supplied with the hook function and
- * (optional) hook data ptr.
- *
- *************************************************************************/
-
- static void InitHook(struct Hook *hook,ULONG (*hookfn)(),APTR data)
- {
- hook->h_Entry = (ULONG (*)()) HookEntry;
- hook->h_SubEntry = hookfn;
- hook->h_Data = data;
- }
-
- /************************************************************************
- ************************ EXECLISTRSRCHANDLER() ************************
- *************************************************************************
- * Hook called by a listview gadget for adding and deleting entries,
- * which are Exec nodes. Simply returns the entry ptr if MAKE, 0 if KILL.
- * Called from HookEntry().
- *
- *************************************************************************/
-
- static SAVEDS ASM ULONG ExecListRsrcHandler(REG(a0) struct Hook *hook, REG(a2) void *obj, REG(a1) void *msg)
- {
- struct lvResource *lvr;
-
- lvr = (struct lvResource *) msg;
-
- if (lvr->lvr_Command == LVRC_MAKE)
- return((ULONG)lvr->lvr_Entry);
-
- return(0);
- }
-
- /************************************************************************
- ************************ EXECLISTDISPHANDLER() ************************
- *************************************************************************
- * Hook called by a listview gadget for rendering. Simply returns a ptr
- * to the ln_Name of Exec Node struct that is the entry. The internal
- * BGUI renderer will then display this string. Called from HookEntry().
- *
- *************************************************************************/
-
- static SAVEDS ASM ULONG ExecListDispHandler(REG(a0) struct Hook *hook, REG(a2) void *obj, REG(a1) void *msg)
- {
- struct lvRender *lvr;
-
- lvr = (struct lvRender *) msg;
- return((ULONG)(((struct Node *) (lvr->lvr_Entry))->ln_Name));
- }
-
- /************************************************************************
- ************************ CREATEHOTKEYWINDOW() *************************
- *************************************************************************
- * Create the hotkey window object tree. Returns the window object ptr or
- * NULL if create failed. Gadgets are initialised with default values,
- * InitHotKeyGadgets must be called after window opened to reflect current
- * settings.
- *
- *************************************************************************/
-
- APTR CreateHotKeyWindow(VOID)
- {
- Object *obj;
- UWORD i;
-
- /* initialize array of ptrs to names of all the hotkey types */
- for(i=0;i<NUM_HOTKEY_TYPES;i++)
- Actions1Array[i] = getString(yhktypes[i].yhkt_nameID);
- Actions1Array[i] = NULL;
-
- /* initialize the resource and display hooks for the hotkeys listview */
- InitHook(&ExecListRsrcHook,ExecListRsrcHandler,NULL);
- InitHook(&ExecListDispHook,ExecListDispHandler,NULL);
-
- obj = WindowObject,
- WINDOW_PubScreenName, PubScreenName,
- WINDOW_Title, getString(EDIT_HOTKEYS_STRING),
- WINDOW_ScreenTitle, getString(COPYRIGHT_STRING),
- WINDOW_SmartRefresh, TRUE,
- WINDOW_SizeBottom, FALSE, /* put size gadget in right border */
- WINDOW_SizeRight, TRUE,
- WINDOW_AutoAspect, TRUE, /* automatic edges pixel width */
- WINDOW_Position, POS_CENTERMOUSE,
- (HotKeyBoxValid ? WINDOW_Bounds : TAG_IGNORE), &HotKeyBox,
- WINDOW_AppWindow, TRUE, /* make it an appwindow */
- WINDOW_RMBTrap, TRUE, /* trap rmb - no menu */
- WINDOW_CloseGadget, FALSE, /* no windowclose gadget please */
- (TextFont ? WINDOW_Font : TAG_IGNORE), &Attr, /* use font if specified */
- WINDOW_HelpFile, PrefsHelp, /* online help system */
- WINDOW_HelpNode, "Hotkeys",
- WINDOW_MasterGroup,
- VGroupObject, Spacing(4), HOffset(4), VOffset(4),
- StartMember,
- HGroupObject, Spacing(2),
- GROUP_EqualWidth, TRUE,
- StartMember,
- LV_Actions = ListviewObject,
- LAB_Label, getString(ACTIONS_STRING),
- LAB_Place, PLACE_ABOVE,
- LAB_Highlight, TRUE,
- GA_ID, GD_Actions,
- LISTV_EntryArray,Actions1Array,
- PGA_NewLook, TRUE,
- EndObject,
- EndMember,
- VarSpace(DEFAULT_WEIGHT/20),
- StartMember,
- VGroupObject, Spacing(2),
- StartMember,
- LV_HotKeys = ListviewObject,
- LAB_Label, getString(HOTKEYS_STRING),
- LAB_Place, PLACE_ABOVE,
- LAB_Highlight, TRUE,
- GA_ID, GD_Hotkeys,
- LISTV_ResourceHook,&ExecListRsrcHook,
- LISTV_DisplayHook,&ExecListDispHook,
- PGA_NewLook, TRUE,
- LISTV_MinEntriesShown, 5,
- EndObject, Weight(DEFAULT_WEIGHT*5),
- EndMember,
- StartMember,
- STR_Name = StringObject,
- STRINGA_MaxChars,512,
- GA_ID, GD_Name,
- RidgeFrame,
- EndObject,
- EndMember,
- VarSpace(DEFAULT_WEIGHT/10),
- StartMember,
- HGroupObject, Spacing(2), EqualWidth,
- StartMember,
- BT_Add = Button(
- getString(ADD_STRING),
- GD_Add),
- EndMember,
- StartMember,
- BT_Delete = Button(
- getString(DELETE_STRING),
- GD_Delete),
- EndMember,
- EndObject,
- EndMember,
- VarSpace(DEFAULT_WEIGHT/10),
- StartMember,
- HGroupObject, Spacing(2), EqualWidth,
- StartMember,
- BT_Definition = Button(
- getString(DEFINITION_STRING),
- GD_Definition),
- EndMember,
- StartMember,
- BT_Options = Button(
- getString(OPTIONS_STRING),
- GD_Options),
- EndMember,
- EndObject,
- EndMember,
- VarSpace(DEFAULT_WEIGHT/10),
- StartMember,
- HGroupObject, Spacing(2),
- VarSpace(DEFAULT_WEIGHT),
- StartMember,
- CH_State = CheckBoxObject,
- LAB_Label, getString(STATE_ACTIVE_STRING),
- LAB_Place, PLACE_LEFT,
- GA_ID, GD_State,
- ButtonFrame,
- FRM_Flags, FRF_EDGES_ONLY,
- EndObject, FixMinWidth,
- EndMember,
- EndObject,
- EndMember,
- EndObject,
- EndMember,
- EndObject, Weight(DEFAULT_WEIGHT*10),
- EndMember,
- VarSpace(DEFAULT_WEIGHT/10),
- StartMember,
- HorizSeparator,
- EndMember,
- StartMember,
- HGroupObject, Spacing(2),
- VarSpace(DEFAULT_WEIGHT),
- StartMember,
- BT_Return = Button(getString(OK_STRING),GD_Return),
- EndMember,
- VarSpace(DEFAULT_WEIGHT),
- EndObject,
- EndMember,
- EndObject,
- EndObject;
-
- return(obj);
- }
-
- /************************************************************************
- ************************* CLOSEHOTKEYWINDOW() *************************
- *************************************************************************
- * Close the hotkey window, disposing of the window object.
- *
- *************************************************************************/
-
- void CloseHotKeyWindow(void)
- {
- if (HotKeyWnd)
- {
- GetAttr(WINDOW_Bounds,HotKeyWndObj,(ULONG *) &HotKeyBox);
- HotKeyBoxValid = TRUE;
- }
-
- DisposeObject(HotKeyWndObj);
- HotKeyWndObj = NULL;
- HotKeyWnd = NULL;
- }
-
- /***************************************************************************
- * HOTKEY SPECIFIC DATA/ROUTINES
- * perhaps move to another file?
- ***************************************************************************/
-
- /* prototypes */
- static struct Node *GetNode(struct List *lh, UWORD n);
- static UWORD GetNodeNum(struct List *lh, struct Node *node);
-
- /* external data */
- YakHotKey *curhk=NULL;
- UWORD curtype=0;
-
- /* get number of node in list - node MUST be there! */
- static UWORD
- GetNodeNum(struct List *lh, struct Node *node)
- {
- struct Node *ln;
- UWORD i;
-
- for (i = 0, ln = GetHead(lh); ln != node; ln = GetSucc(ln), i++)
- ;
- return i;
- }
-
- /* get nth node in list - list MUST have >= n nodes!!! */
- static struct Node *
- GetNode(struct List *lh, UWORD n)
- {
- struct Node *ln;
-
- for (ln = GetHead(lh); n--; ln = GetSucc(ln))
- ;
- return ln;
- }
-
- /************************************************************************
- ************************** UPDATEHOTKEYLV() ***************************
- *************************************************************************
- * Make the hotkeys listview display the hotkeys in the supplied list
- * (which may be empty).
- *
- *************************************************************************/
-
- static void UpdateHotKeyLV(struct List *list)
- {
- struct Node *n;
-
- LockList(LV_HotKeys);
- ClearList(HotKeyWnd, LV_HotKeys);
-
- if (list)
- {
- for (n=GetHead(list); n; n=GetSucc(n))
- AddEntry(HotKeyWnd, LV_HotKeys, n, LVAP_TAIL);
- }
-
- UnlockList(HotKeyWnd,LV_HotKeys);
- }
-
- /************************************************************************
- ************************ INITHOTKEYGADGETS() **************************
- *************************************************************************
- * Initialize the hotkey window gadgets to reflect current settings.
- * Supply hotkeylv TRUE if you want the hotkeys listview updated as
- * well.
- *
- *************************************************************************/
-
- static void InitHotKeyGadgets(BOOL hotkeylv)
- {
- UWORD n;
-
- if (hotkeylv)
- UpdateHotKeyLV(keylist(curtype));
-
- InitWindowGadget(GDX_Actions, LISTV_Select, curtype, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Delete, GA_Disabled, !curhk, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Definition, GA_Disabled, !curhk, HOTKEY_WINDOW);
-
- if (curhk) /* something selected */
- {
- n = GetNodeNum(keylist(curtype), (struct Node *)curhk);
-
- InitWindowGadget(GDX_Name, GA_Disabled, FALSE, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Name, STRINGA_TextVal, (LONG)curhk->yhk_Name, HOTKEY_WINDOW);
- InitWindowGadget(GDX_State, GA_Disabled, FALSE, HOTKEY_WINDOW);
- InitWindowGadget(GDX_State, GA_Selected, (LONG)curhk->yhk_State, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Actions, LISTV_Select, curtype, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Hotkeys, LISTV_Select, n, HOTKEY_WINDOW);
-
- if (YHK_Takes_Opt(curhk))
- InitWindowGadget(GDX_Options, GA_Disabled, FALSE, HOTKEY_WINDOW);
- else
- InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
- }
- else /* no current hotkey */
- {
- InitWindowGadget(GDX_Name, STRINGA_TextVal, (LONG)"", HOTKEY_WINDOW);
- InitWindowGadget(GDX_Name, GA_Disabled, TRUE, HOTKEY_WINDOW);
- InitWindowGadget(GDX_State, GA_Selected, FALSE, HOTKEY_WINDOW);
- InitWindowGadget(GDX_State, GA_Disabled, TRUE, HOTKEY_WINDOW);
- InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
- }
- }
-
- /************************************************************************
- *********************** HANDLEHOTKEYRETURNID() ************************
- *************************************************************************
- * Handle msgs arriving at hotkey window - supply the ID returned by
- * BGUI. Returns either RET_OKAY or RET_QUIT.
- *
- *************************************************************************/
-
- LONG HandleHotKeyReturnID(LONG id)
- {
- LONG ret;
- ULONG code;
- APTR err;
-
- ret = RET_OKAY;
-
- switch(id)
- {
- case GD_Actions:
- GetAttr(LISTV_LastClickedNum,LV_Actions,&code);
- if (code != curtype)
- {
- curtype = code;
- curhk = (YakHotKey *)GetHead(keylist(curtype));
- InitHotKeyGadgets(TRUE);
- }
- break;
-
- case GD_Hotkeys:
- GetAttr(LISTV_LastClicked,LV_HotKeys,&code);
- curhk = (YakHotKey *)code;
- InitHotKeyGadgets(FALSE);
- break;
-
- case GD_State:
- GetAttr(GA_Selected,CH_State,&code);
- if (curhk)
- curhk->yhk_State = (code ? TRUE : FALSE);
- InitHotKeyGadgets(FALSE);
- break;
-
- case GD_Add:
- if (curhk=NewYakHotKey(curtype))
- {
- DefaultOptions(curhk);
- InitHotKeyGadgets(TRUE);
- ActivateGadget((struct Gadget *)STR_Name, HotKeyWnd, NULL);
- }
- break;
-
- case GD_Delete:
- if (curhk)
- {
- DeleteYakHotKey(curhk);
- curhk = NULL;
- InitHotKeyGadgets(TRUE);
- }
- break;
-
- case GD_Name:
- GetAttr(STRINGA_TextVal,STR_Name,&code);
- if (!ModifyYHKName(curhk, (char *)code))
- ActivateGadget((struct Gadget *)STR_Name, HotKeyWnd, NULL);
- InitHotKeyGadgets(TRUE);
- break;
-
- case GD_Definition:
- if (curhk)
- {
- if (!SwitchToKeyDefWindow(HOTKEY_WINDOW,curhk,curhk->yhk_Name))
- {
- PostError(getString(Couldnt_open_other_window_ERR));
- ret= RET_QUIT;
- }
- }
- break;
-
- case GD_Options:
- if (curhk)
- {
- if (!SwitchToOptionsWindow())
- {
- PostError(getString(Couldnt_open_other_window_ERR));
- ret = RET_QUIT;
- }
- }
- break;
-
- case GD_Return:
- err = NULL;
-
- for (curtype=0; (curtype < NUM_HOTKEY_TYPES) && !err; curtype++)
- {
- for (curhk=(YakHotKey *)GetHead(keylist(curtype));
- curhk && !(err=ControlYakHotKey(curhk));
- curhk=(YakHotKey *)GetSucc(curhk))
- /**/;
- }
-
- if (!err)
- {
- curtype = 0;
- CloseHotKeyWindow();
- if (!ShowWindowID(ROOT_WINDOW))
- ret = RET_QUIT;
- }
- else
- {
- curtype--;
- InitHotKeyGadgets(TRUE);
- PostError(getString(err));
- }
- break;
-
- default:
- break;
- }
-
- return(ret);
- }
-
- /************************************************************************
- ************************* SHOWHOTKEYWINDOW() **************************
- *************************************************************************
- * Create and open the hotkey window and initialize the gadgets to
- * reflect current settings. Sets up HandleReturnID function, curwin,
- * curwinobj and curwinID. Returns TRUE or FALSE to indicate success.
- *
- *************************************************************************/
-
- BOOL ShowHotKeyWindow(void)
- {
- if (HotKeyWndObj = (Object *)CreateHotKeyWindow())
- {
- if (HotKeyWnd = WindowOpen(HotKeyWndObj))
- {
- if (curwinID == ROOT_WINDOW)
- curhk = (YakHotKey *)GetNode(keylist(curtype), 0);
- InitHotKeyGadgets(TRUE);
- HandleReturnID = HandleHotKeyReturnID;
- curwin = HotKeyWnd;
- curwinobj = HotKeyWndObj;
- curwinID = HOTKEY_WINDOW;
- return(TRUE);
- }
- }
-
- CloseHotKeyWindow();
- curwin = NULL;
- curwinobj = NULL;
- wndsigflag = 0L;
- appwinsigflag = 0L;
- return(FALSE);
- }
-
-