home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / util / yak-1.59.lha / Yak-1.59 / Src / Hotkey_Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  14.5 KB  |  475 lines

  1.  
  2. /*
  3.  *  Source machine generated by GadToolsBox V2.0b
  4.  *  which is (c) Copyright 1991-1993 Jaba Development
  5.  *
  6.  *  GUI Designed by : Martin W Scott and GaĆ«l Marziou
  7.  */
  8.  
  9.  
  10.  
  11.  
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/classes.h>
  15. #include <intuition/classusr.h>
  16. #include <intuition/imageclass.h>
  17. #include <intuition/gadgetclass.h>
  18. #include <intuition/intuitionbase.h>
  19. #include <libraries/gadtools.h>
  20. #include <graphics/displayinfo.h>
  21. #include <graphics/gfxbase.h>
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/gadtools.h>
  25. #include <proto/graphics.h>
  26. #include <proto/locale.h>
  27. #include <proto/utility.h>
  28. #include <string.h>
  29.  
  30.  
  31. #include "code.h"
  32. #include "version.h"
  33. #include "hotkey_types.h"
  34. #include "yak.h"
  35. #include "gui.h"
  36.  
  37. #define CATCOMP_NUMBERS
  38. #include "locale/yak_locale_strings.h"
  39.  
  40.  
  41. IMPORT struct Catalog    *Catalog;
  42.  
  43. extern LONG (*HandleIDCMP)(void);
  44.  
  45. struct Window   *HotKeyWnd = NULL;
  46. struct Gadget   *HotKeyGList = NULL;
  47. struct Gadget   *HotKeyGadgets[HotKey_CNT];
  48. UWORD            HotKeyLeft = 0;
  49. UWORD            HotKeyWidth = 530;
  50. UWORD            HotKeyHeight = 159;
  51. UBYTE           *HotKeyWdt = NULL;
  52.  
  53. WORD             HotkeysTop=0;
  54. WORD             ActionsTop=0;
  55.  
  56. UBYTE *Options1Labels[4];
  57.  
  58. VOID
  59. InitOptions1Label()
  60. {
  61.     Options1Labels[0] = getString(NO_SCREEN_CHANGE_STRING);
  62.     Options1Labels[1] = getString(WORKBENCH_TO_FRONT_STRING);
  63.     Options1Labels[2] = getString(DEFAULT_PUBSCR_TO_FRONT_STRING);
  64.     Options1Labels[3] = NULL;
  65. }
  66.  
  67.  
  68. IMPORT struct MinList Actions1List;
  69.  
  70. struct Node Actions1Nodes[] = 
  71. {
  72.     &Actions1Nodes[1] ,(struct Node *)&Actions1List.mlh_Head,0,0,NULL,
  73.     &Actions1Nodes[2] ,&Actions1Nodes[0] ,0,0,NULL,
  74.     &Actions1Nodes[3] ,&Actions1Nodes[1] ,0,0,NULL,
  75.     &Actions1Nodes[4] ,&Actions1Nodes[2] ,0,0,NULL,
  76.     &Actions1Nodes[5] ,&Actions1Nodes[3] ,0,0,NULL,
  77.     &Actions1Nodes[6] ,&Actions1Nodes[5] ,0,0,NULL,
  78.     &Actions1Nodes[7] ,&Actions1Nodes[6] ,0,0,NULL,
  79.     &Actions1Nodes[8] ,&Actions1Nodes[7] ,0,0,NULL,
  80.     &Actions1Nodes[9] ,&Actions1Nodes[8] ,0,0,NULL,
  81.     &Actions1Nodes[10],&Actions1Nodes[9] ,0,0,NULL,
  82.     &Actions1Nodes[11],&Actions1Nodes[10],0,0,NULL,
  83.     &Actions1Nodes[12],&Actions1Nodes[11],0,0,NULL,
  84.     &Actions1Nodes[13],&Actions1Nodes[12],0,0,NULL,
  85.     &Actions1Nodes[14],&Actions1Nodes[13],0,0,NULL,
  86.     &Actions1Nodes[15],&Actions1Nodes[14],0,0,NULL,
  87.     &Actions1Nodes[16],&Actions1Nodes[15],0,0,NULL,
  88.     &Actions1Nodes[17],&Actions1Nodes[16],0,0,NULL,
  89.     (struct Node *)&Actions1List.mlh_Tail,&Actions1Nodes[16],0,0,NULL 
  90. };
  91.  
  92. VOID
  93. InitActions1Nodes()
  94. {
  95.     Actions1Nodes[0].ln_Name  = getString(DOS_Command_ACT);
  96.     Actions1Nodes[1].ln_Name  = getString(Close_Window_ACT);
  97.     Actions1Nodes[2].ln_Name  = getString(Zip_Window_ACT);
  98.     Actions1Nodes[3].ln_Name  = getString(Shrink_Window_ACT);
  99.     Actions1Nodes[4].ln_Name  = getString(Expand_Window_ACT);
  100.     Actions1Nodes[5].ln_Name  = getString(Cycle_Windows_ACT);
  101.     Actions1Nodes[6].ln_Name  = getString(Open_Palette_ACT);
  102.     Actions1Nodes[7].ln_Name  = getString(Screen_to_Front_ACT);
  103.     Actions1Nodes[8].ln_Name  = getString(Screen_to_Back_ACT);
  104.     Actions1Nodes[9].ln_Name  = getString(Activate_Workbench_ACT);
  105.     Actions1Nodes[10].ln_Name = getString(Centre_Screen_ACT);
  106.     Actions1Nodes[11].ln_Name = getString(Blank_Display_ACT);
  107.     Actions1Nodes[12].ln_Name = getString(Insert_Text_ACT);
  108.     Actions1Nodes[13].ln_Name = getString(Insert_Date_ACT);
  109.     Actions1Nodes[14].ln_Name = getString(Show_Yak_Interface_ACT);
  110.     Actions1Nodes[15].ln_Name = getString(Back_Cycle_Windows_ACT);
  111.     Actions1Nodes[16].ln_Name = getString(SetDefaultPublicScreen);
  112.     Actions1Nodes[17].ln_Name = getString(MenuShortcut);
  113. }
  114.  
  115. struct MinList Actions1List = {
  116.     (struct MinNode *)&Actions1Nodes[0],
  117.     (struct MinNode *)NULL,
  118.     (struct MinNode *)&Actions1Nodes[15] };
  119.  
  120.  
  121. UWORD HotKeyGTypes[] = {
  122.         LISTVIEW_KIND,
  123.         LISTVIEW_KIND,
  124.         STRING_KIND,
  125.         CYCLE_KIND,
  126.         BUTTON_KIND,
  127.         BUTTON_KIND,
  128.         BUTTON_KIND
  129. };
  130.  
  131.  
  132. struct NewGadget HotKeyNGad[] = {
  133.         234,15,290,80,NULL,NULL,GD_Hotkeys  ,PLACETEXT_ABOVE|NG_HIGHLABEL,NULL,NULL,
  134.           6,15,224,96,NULL,NULL,GD_Actions  ,PLACETEXT_ABOVE|NG_HIGHLABEL,NULL,NULL,
  135.         234,109,290,14,NULL,NULL,GD_Argument,PLACETEXT_LEFT              ,NULL,NULL,
  136.         234,124,290,13,NULL,NULL,GD_Options ,PLACETEXT_LEFT              ,NULL,NULL,
  137.         234,93,110,13,NULL,NULL,GD_Add      ,PLACETEXT_IN                ,NULL,NULL,
  138.         414,93,110,13,NULL,NULL,GD_Delete   ,PLACETEXT_IN                ,NULL,NULL,
  139.         215,143,100,13,NULL,NULL,GD_Return  ,PLACETEXT_IN                ,NULL,NULL
  140. };
  141.  
  142. VOID InitHotKeyNGad (VOID)
  143. {
  144.     HotKeyNGad[GD_Hotkeys].ng_GadgetText  = getString(HOTKEYS_STRING);
  145.     HotKeyNGad[GD_Actions].ng_GadgetText  = getString(ACTIONS_STRING);
  146.     HotKeyNGad[GD_Argument].ng_GadgetText = getString(ARGUMENT_STRING);
  147.     HotKeyNGad[GD_Options].ng_GadgetText  = getString(OPTIONS_STRING);
  148.     HotKeyNGad[GD_Add].ng_GadgetText      = getString(ADD_STRING);
  149.     HotKeyNGad[GD_Delete].ng_GadgetText   = getString(DELETE_STRING);
  150.     HotKeyNGad[GD_Return].ng_GadgetText   = getString(OK_STRING);
  151. }
  152.  
  153.  
  154.  
  155. ULONG HotKeyGTags[] = {
  156.         (GTLV_ShowSelected),NULL,(TAG_DONE),
  157.         (GTLV_Labels),(ULONG)&Actions1List,(GTLV_ShowSelected),NULL,(TAG_DONE),
  158.         (GTST_MaxChars),512,(TAG_DONE),
  159.         (GTCY_Labels),(ULONG)&Options1Labels[ 0 ],(TAG_DONE),
  160.         (TAG_DONE),
  161.         (TAG_DONE),
  162.         (TAG_DONE)
  163. };
  164.  
  165.  
  166.  
  167.  
  168. VOID
  169. HotKeyRender()
  170. {
  171.     ComputeFont(HotKeyWidth,HotKeyHeight);
  172.  
  173.     DrawBevelBox(HotKeyWnd->RPort,OffX,
  174.                  OffY +ComputeY(140),
  175.                  ComputeX(530),
  176.                  ComputeY(HotKeyHeight) -ComputeY(140),
  177.                  GT_VisualInfo,VisualInfo,TAG_DONE);
  178.     DrawBevelBox(HotKeyWnd->RPort,OffX,
  179.                  OffY,
  180.                  ComputeX(530),
  181.                  ComputeY(140),
  182.                  GT_VisualInfo,VisualInfo,TAG_DONE);
  183. }
  184.  
  185.  
  186.  
  187.  
  188. int
  189. OpenHotKeyWindow()
  190. {
  191.     struct NewGadget        ng;
  192.     struct Gadget   *g;
  193.     UWORD           lc,tc;
  194.     UWORD           wleft = HotKeyLeft,wtop = WindowTop,ww,wh;
  195.  
  196.     ComputeFont(HotKeyWidth,HotKeyHeight);
  197.  
  198.     ww = ComputeX(HotKeyWidth);
  199.     wh = ComputeY(HotKeyHeight);
  200.  
  201.     if ((wleft +ww +OffX +Scr->WBorRight) > Scr->Width) wleft = Scr->Width -ww;
  202.     if ((wtop +wh +OffY +Scr->WBorBottom) > Scr->Height) wtop = Scr->Height -wh;
  203.  
  204.     if (! (g = CreateContext(&HotKeyGList)))
  205.         return(1L);
  206.  
  207.     for(lc = 0,tc = 0; lc < HotKey_CNT; lc++) {
  208.  
  209.         CopyMem((char *)&HotKeyNGad[ lc ],(char *)&ng,(long)sizeof(struct NewGadget));
  210.  
  211.         ng.ng_VisualInfo = VisualInfo;
  212.         ng.ng_TextAttr   = Font;
  213.         ng.ng_LeftEdge   = OffX +ComputeX(ng.ng_LeftEdge);
  214.         ng.ng_TopEdge    = OffY +ComputeY(ng.ng_TopEdge);
  215.         ng.ng_Width      = ComputeX(ng.ng_Width);
  216.         ng.ng_Height     = ComputeY(ng.ng_Height);
  217.  
  218.         HotKeyGadgets[ lc ] = g = CreateGadgetA((ULONG)HotKeyGTypes[ lc ],g,&ng,(struct TagItem *)&HotKeyGTags[ tc ]);
  219.  
  220.         while(HotKeyGTags[ tc ]) tc += 2;
  221.         tc++;
  222.  
  223.         if (NOT g)
  224.             return(2L);
  225.     }
  226.  
  227.     if (! (HotKeyWnd = OpenWindowTags(NULL,
  228.                                       WA_Left,        wleft,
  229.                                       WA_Top,         wtop,
  230.                                       WA_Width,       ww +OffX +Scr->WBorRight,
  231.                                       WA_Height,      wh +OffY +Scr->WBorBottom,
  232.                                       WA_IDCMP,       LISTVIEWIDCMP|STRINGIDCMP|CYCLEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  233.                                       WA_Flags,       WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  234.                                       WA_Gadgets,     HotKeyGList,
  235.                                       WA_Title,       HotKeyWdt,
  236.                                       WA_ScreenTitle,getString(COPYRIGHT_STRING),
  237.                                       WA_PubScreen,TRUE,
  238.                                       WA_PubScreenName,PubScreenName,
  239.                                       TAG_DONE)))
  240.         return(4L);
  241.  
  242.     GT_RefreshWindow(HotKeyWnd,NULL);
  243.  
  244.     HotKeyRender();
  245.  
  246.     return(0L);
  247. }
  248.  
  249.  
  250.  
  251.  
  252. VOID
  253. CloseHotKeyWindow()
  254. {
  255.         CloseOneWindow (HotKeyWnd,NULL,HotKeyGList);
  256.         HotKeyWnd = NULL;
  257. }
  258.  
  259.  
  260. /*******************************************************************************
  261.  *      HOTKEY SPECIFIC DATA/ROUTINES
  262.  *      perhaps move to another file?
  263.  *******************************************************************************/
  264.  
  265. /* prototypes */
  266. static struct Node *GetNode(struct List *lh, UWORD n);
  267. static UWORD GetNodeNum(struct List *lh, struct Node *node);
  268.  
  269. /* external data */
  270. YakHotKey       *curhk;
  271. UWORD           curtype;
  272.  
  273. /* get number of node in list - node MUST be there! */
  274. static UWORD
  275. GetNodeNum(struct List *lh, struct Node *node)
  276. {
  277.         struct Node *ln;
  278.         UWORD i;
  279.  
  280.         for (i = 0, ln = lh->lh_Head; ln != node; ln = ln->ln_Succ, i++)
  281.                 ;
  282.         return i;
  283. }
  284.  
  285. /* get nth node in list - list MUST have >= n nodes!!! */
  286. static struct Node *
  287. GetNode(struct List *lh, UWORD n)
  288. {
  289.         struct Node *ln;
  290.  
  291.         for (ln = lh->lh_Head; n--; ln = ln->ln_Succ)
  292.                 ;
  293.         return ln;
  294. }
  295.  
  296.  
  297.  
  298. /* initialise all gadgets of hotkey window */
  299. static void
  300. InitHotKeyGadgets(void)
  301. {
  302.     InitWindowGadget(GDX_Hotkeys, GTLV_Labels, (LONG)keylist(curtype), HOTKEY_WINDOW);
  303.     InitWindowGadget(GDX_Actions, GTLV_Selected, curtype, HOTKEY_WINDOW);
  304.  
  305.     InitWindowGadget(GDX_Delete, GA_Disabled, !curhk, HOTKEY_WINDOW);
  306.     /* something selected */
  307.     if (curhk)
  308.     {
  309.         UWORD n = GetNodeNum(keylist(curtype), (struct Node *)curhk);
  310.  
  311.         if (YHK_Has_Options(curhk))
  312.         {
  313.             InitWindowGadget(GDX_Options, GA_Disabled, FALSE, HOTKEY_WINDOW);
  314.             InitWindowGadget(GDX_Options, GTCY_Active, (LONG)curhk->yhk_Options, HOTKEY_WINDOW);
  315.         }
  316.         else
  317.             InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
  318.  
  319.  
  320.         if (YHK_Takes_Arg(curhk))
  321.         {
  322.             InitWindowGadget(GDX_Argument, GA_Disabled, FALSE, HOTKEY_WINDOW);
  323.             InitWindowGadget(GDX_Argument, GTST_String, (LONG)curhk->yhk_ArgStr, HOTKEY_WINDOW);
  324.         }
  325.         else
  326.             InitWindowGadget(GDX_Argument, GA_Disabled, TRUE, HOTKEY_WINDOW);
  327.  
  328.         InitWindowGadget(GDX_Actions, GTLV_Top,      curtype, HOTKEY_WINDOW);
  329.         InitWindowGadget(GDX_Hotkeys, GTLV_Top     , n,       HOTKEY_WINDOW);
  330.         InitWindowGadget(GDX_Hotkeys, GTLV_Selected, n,       HOTKEY_WINDOW);
  331.     }
  332.     else                        /* no current hotkey */
  333.     {
  334.         InitWindowGadget(GDX_Hotkeys, GTLV_Selected, -1, HOTKEY_WINDOW);
  335.  
  336.         InitWindowGadget(GDX_Options, GTCY_Active, 0, HOTKEY_WINDOW);
  337.         InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
  338.  
  339.         InitWindowGadget(GDX_Argument, GTST_String, (LONG)"", HOTKEY_WINDOW);
  340.         InitWindowGadget(GDX_Argument, GA_Disabled, TRUE, HOTKEY_WINDOW);
  341.     }
  342. }
  343.  
  344.  
  345. /* handle hotkey window events */
  346. LONG
  347. HandleHotKeyIDCMP(void)
  348. {
  349.     struct IntuiMessage *msg;
  350.     struct Gadget       *gadget;
  351.     ULONG               class;
  352.     UWORD               code;
  353.     static ULONG        savesec;
  354.     static ULONG        savemic;
  355.     static YakHotKey    *savehk;
  356.  
  357.  
  358.     while (msg = GT_GetIMsg(HotKeyWnd->UserPort))
  359.     {
  360.         class = msg->Class;
  361.         code = msg->Code;
  362.         gadget = (struct Gadget *)msg->IAddress;
  363.         GT_ReplyIMsg(msg);
  364.  
  365.         switch (class)
  366.         {
  367.           case CLOSEWINDOW:
  368.             HideInterface();
  369.             return ROOT_OKAY;
  370.  
  371.           case GADGETUP:
  372.           case GADGETDOWN:
  373.             switch (gadget->GadgetID)
  374.             {
  375.               case GD_Actions:
  376.                 if (code != curtype)
  377.                 {
  378.                     curtype = code;
  379.                     curhk   = NULL;
  380.  
  381.                     InitHotKeyGadgets();
  382.                 }
  383.                 break;
  384.  
  385.               case GD_Hotkeys:
  386.                 curhk = (YakHotKey *)GetNode(keylist(curtype), code);
  387.                 if (DoubleClick(savesec, savemic, msg->Seconds, msg->Micros) &&
  388.                     (curhk == savehk) )
  389.                 {
  390.                     savehk  = NULL;
  391.                     savemic = savesec = 0;
  392.  
  393.                     if (SwitchToKeyDefWindow())
  394.                         return ROOT_OKAY;
  395.                     else
  396.                         PostError(getString(Couldnt_open_other_window_ERR));
  397.                 }
  398.                 else
  399.                 {
  400.                     savesec = msg->Seconds;
  401.                     savemic = msg->Micros;
  402.                     savehk  = curhk;
  403.  
  404.                     InitWindowGadget(GDX_Delete, GA_Disabled, !curhk, HOTKEY_WINDOW);
  405.                     InitHotKeyGadgets();
  406.                 }
  407.  
  408.                 break;
  409.  
  410.               case GD_Argument:
  411.                 if (!curhk)     /* shouldn't happen */
  412.                     break;
  413.                 if (!(ModifyYHKArgStr(curhk, GetString(gadget))))
  414.                     InitHotKeyGadgets();
  415.                 break;
  416.  
  417.               case GD_Options:
  418.                 if (curhk)
  419.                     curhk->yhk_Options = code;
  420.                 break;
  421.  
  422.               case GD_Add:
  423.                 curhk = NewYakHotKey(curtype);
  424.                 if (!SwitchToKeyDefWindow())
  425.                     PostError(getString(Couldnt_open_other_window_ERR));
  426.                 return ROOT_OKAY;
  427.  
  428.               case GD_Delete:
  429.                 if (curhk)
  430.                 {
  431.                     DeleteYakHotKey(curhk);
  432.                     curhk = NULL;
  433.                     InitHotKeyGadgets();
  434.                 }
  435.                 break;
  436.  
  437.               case GD_Return:
  438.                 curhk = NULL;   /* in case of reloading */
  439.                 UpdateWindowsPosition();
  440.                 CloseHotKeyWindow();
  441.                 if (!ShowRootWindow())
  442.                     PostError(getString(Couldnt_open_other_window_ERR));
  443.                 return ROOT_OKAY;
  444.  
  445.             }                   /* switch (gadget->GadgetID) */
  446.             break;
  447.  
  448.           case REFRESHWINDOW:
  449.             GT_BeginRefresh(HotKeyWnd);
  450.             GT_EndRefresh(HotKeyWnd, TRUE);
  451.             break;
  452.  
  453.         }                       /* switch (class) */
  454.  
  455.     }                           /* while more messages */
  456.  
  457.     return ROOT_OKAY;
  458. }
  459.  
  460. /* show our hotkey window */
  461. BOOL
  462. ShowHotKeyWindow(void)
  463. {
  464.         if (!OpenHotKeyWindow())        /* like the name says... */
  465.         {
  466.                 InitHotKeyGadgets();
  467.                 wndsigflag = 1 << HotKeyWnd->UserPort->mp_SigBit;
  468.                 curwin = HotKeyWnd;
  469.                 HandleIDCMP = HandleHotKeyIDCMP;
  470.                 return TRUE;
  471.         }
  472.         CloseDownScreen();
  473.         return FALSE;
  474. }
  475.