home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 550b.lha / Term_v1.8a / Source.LZH / MacroPanel.c < prev    next >
C/C++ Source or Header  |  1991-07-07  |  14KB  |  480 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: MacroPanel.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17. enum    {    GAD_F1,GAD_F2,GAD_F3,GAD_F4,GAD_F5,GAD_F6,GAD_F7,GAD_F8,GAD_F9,
  18.         GAD_F10,GAD_QUALIFIER,GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
  19.  
  20. enum    {    MEN_USEMACROS=1,MEN_LOADMACROS,MEN_SAVEMACROS,MEN_QUALIFIER,
  21.         MEN_CANCELMACROS,MEN_QUITPANEL };
  22.  
  23. STATIC struct NewMenu MacroMenu[] =
  24. {
  25.     { NM_TITLE, "Project",         0 , 0, 0, (APTR)0},
  26.     {  NM_ITEM, "Load Macros",    "L", 0, 0, (APTR)MEN_LOADMACROS},
  27.     {  NM_ITEM, "Save Macros",    "S", 0, 0, (APTR)MEN_SAVEMACROS},
  28.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  29.     {  NM_ITEM, "Modifier",    "M", 0, 0, (APTR)MEN_QUALIFIER},
  30.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  31.     {  NM_ITEM, "Use",        "U", 0, 0, (APTR)MEN_USEMACROS},
  32.     {  NM_ITEM, "Cancel",        "C", 0, 0, (APTR)MEN_CANCELMACROS},
  33.     {  NM_ITEM, NM_BARLABEL,     0 , 0, 0, (APTR)0},
  34.     {  NM_ITEM, "Quit",        "Q", 0, 0, (APTR)MEN_QUITPANEL},
  35.     { NM_END, 0,             0 , 0, 0, (APTR)0}
  36. };
  37.  
  38. #define WIDTH    535
  39. #define HEIGHT    163
  40.  
  41. STATIC STRPTR ModifierString[5] =
  42. {
  43.     (STRPTR)"None",
  44.     (STRPTR)"Shift",
  45.     (STRPTR)"Alternate",
  46.     (STRPTR)"Control",
  47.     NULL
  48. };
  49.  
  50. STATIC struct Gadget *
  51. CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
  52. {
  53.     struct Gadget        *Gadget;
  54.     struct NewGadget     NewGadget;
  55.     UWORD             Counter = 0,Offset;
  56.  
  57.     if(Gadget = CreateContext(GadgetList))
  58.     {
  59.         NewGadget . ng_Width        = 484;
  60.         NewGadget . ng_Height        = 12;
  61.         NewGadget . ng_GadgetText    = "F 1";
  62.         NewGadget . ng_TextAttr        = &DefaultFont;
  63.         NewGadget . ng_VisualInfo    = VisualInfo;
  64.         NewGadget . ng_GadgetID        = Counter;
  65.         NewGadget . ng_Flags        = NG_HIGHLABEL;
  66.         NewGadget . ng_LeftEdge        = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
  67.         NewGadget . ng_TopEdge        = 1 + TopEdge;
  68.  
  69.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  70.             GTST_MaxChars,256,
  71.         TAG_DONE);
  72.  
  73.         NewGadget . ng_GadgetText    = "F 2";
  74.         NewGadget . ng_GadgetID        = Counter;
  75.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  76.  
  77.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  78.             GTST_MaxChars,256,
  79.         TAG_DONE);
  80.  
  81.         NewGadget . ng_GadgetText    = "F 3";
  82.         NewGadget . ng_GadgetID        = Counter;
  83.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  84.  
  85.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  86.             GTST_MaxChars,256,
  87.         TAG_DONE);
  88.  
  89.         NewGadget . ng_GadgetText    = "F 4";
  90.         NewGadget . ng_GadgetID        = Counter;
  91.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  92.  
  93.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  94.             GTST_MaxChars,256,
  95.         TAG_DONE);
  96.  
  97.         NewGadget . ng_GadgetText    = "F 5";
  98.         NewGadget . ng_GadgetID        = Counter;
  99.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  100.  
  101.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  102.             GTST_MaxChars,256,
  103.         TAG_DONE);
  104.  
  105.         NewGadget . ng_GadgetText    = "F 6";
  106.         NewGadget . ng_GadgetID        = Counter;
  107.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  108.  
  109.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  110.             GTST_MaxChars,256,
  111.         TAG_DONE);
  112.  
  113.         NewGadget . ng_GadgetText    = "F 7";
  114.         NewGadget . ng_GadgetID        = Counter;
  115.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  116.  
  117.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  118.             GTST_MaxChars,256,
  119.         TAG_DONE);
  120.  
  121.         NewGadget . ng_GadgetText    = "F 8";
  122.         NewGadget . ng_GadgetID        = Counter;
  123.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  124.  
  125.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  126.             GTST_MaxChars,256,
  127.         TAG_DONE);
  128.  
  129.         NewGadget . ng_GadgetText    = "F 9";
  130.         NewGadget . ng_GadgetID        = Counter;
  131.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  132.  
  133.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  134.             GTST_MaxChars,256,
  135.         TAG_DONE);
  136.  
  137.         NewGadget . ng_GadgetText    = "F10";
  138.         NewGadget . ng_GadgetID        = Counter;
  139.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  140.  
  141.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  142.             GTST_MaxChars,256,
  143.         TAG_DONE);
  144.  
  145.         NewGadget . ng_GadgetText    = "Key _Modifier";
  146.         NewGadget . ng_Width        = 100;
  147.         NewGadget . ng_GadgetID        = Counter;
  148.         NewGadget . ng_LeftEdge        = WIDTH >> 1;
  149.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 4;
  150.  
  151.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  152.             GT_Underscore,    '_',
  153.             GTCY_Labels,    ModifierString,
  154.             GTCY_Active,    0,
  155.         TAG_DONE);
  156.  
  157.         NewGadget . ng_Width        = 52;
  158.         NewGadget . ng_Height        = 12;
  159.         NewGadget . ng_GadgetText    = "_Use";
  160.         NewGadget . ng_GadgetID        = Counter;
  161.         NewGadget . ng_Flags        = 0;
  162.         NewGadget . ng_LeftEdge        = 10;
  163.         NewGadget . ng_TopEdge        = HEIGHT - 3 - NewGadget . ng_Height;
  164.  
  165.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  166.             GT_Underscore,    '_',
  167.         TAG_DONE);
  168.  
  169.         Offset = (WIDTH + NewGadget . ng_Width) / 4 + 8;
  170.  
  171.         NewGadget . ng_GadgetText    = "_Load";
  172.         NewGadget . ng_GadgetID        = Counter;
  173.         NewGadget . ng_LeftEdge        = NewGadget . ng_LeftEdge + Offset;
  174.  
  175.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  176.             GT_Underscore,    '_',
  177.         TAG_DONE);
  178.  
  179.         NewGadget . ng_GadgetText    = "_Save";
  180.         NewGadget . ng_GadgetID        = Counter;
  181.         NewGadget . ng_LeftEdge        = NewGadget . ng_LeftEdge + Offset;
  182.  
  183.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  184.             GT_Underscore,    '_',
  185.         TAG_DONE);
  186.  
  187.         NewGadget . ng_GadgetText    = "_Cancel";
  188.         NewGadget . ng_GadgetID        = Counter;
  189.         NewGadget . ng_LeftEdge        = NewGadget . ng_LeftEdge + Offset;
  190.  
  191.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  192.             GT_Underscore,    '_',
  193.         TAG_DONE);
  194.     }
  195.  
  196.     DubGadList(GadgetArray[0]);
  197.  
  198.     return(Gadget);
  199. }
  200.  
  201. VOID
  202. MacroPanel(struct MacroKeys *MacroKeys)
  203. {
  204.     struct Window        *PanelWindow;
  205.     struct Menu        *PanelMenu;
  206.     struct Gadget        *GadgetList;
  207.     struct Gadget        *GadgetArray[GAD_CANCEL + 1];
  208.     LONG             i;
  209.  
  210.     struct MacroKeys    *Keys;
  211.  
  212.     if(Keys = (struct MacroKeys *)AllocMem(sizeof(struct MacroKeys),MEMF_PUBLIC|MEMF_CLEAR))
  213.     {
  214.         CopyMem(MacroKeys,Keys,sizeof(struct MacroKeys));
  215.  
  216.         if(CreateAllGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
  217.         {
  218.             if(PanelMenu = CreateMenus(MacroMenu,
  219.                 GTMN_FrontPen, 0,
  220.             TAG_DONE))
  221.             {
  222.                 if(LayoutMenus(PanelMenu,VisualInfo,
  223.                     GTMN_TextAttr,&DefaultFont,
  224.                 TAG_DONE))
  225.                 {
  226.                     if(PanelWindow = OpenWindowTags(NULL,
  227.                         WA_Left,    (Screen -> Width - WIDTH) >> 1,
  228.                         WA_Top,        (Screen -> Height - HEIGHT) >> 1,
  229.                         WA_Width,    WIDTH,
  230.                         WA_Height,    HEIGHT,
  231.  
  232.                         WA_Activate,    TRUE,
  233.                         WA_DragBar,    TRUE,
  234.                         WA_DepthGadget,    TRUE,
  235.                         WA_CloseGadget,    TRUE,
  236.                         WA_RMBTrap,    TRUE,
  237.                         WA_DepthGadget,    TRUE,
  238.                         WA_CustomScreen,Screen,
  239.  
  240.                         WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW,
  241.  
  242.                         WA_Title,    "Macro Preferences",
  243.                     TAG_DONE))
  244.                     {
  245.                         struct IntuiMessage    *Massage;
  246.                         ULONG             Class,Code;
  247.                         struct Gadget        *Gadget;
  248.                         BYTE             Terminated = FALSE;
  249.  
  250.                         UBYTE             DummyBuffer[256],*DummyChar;
  251.  
  252.                         struct FileRequest    *FileRequest;
  253.  
  254.                         LONG             Modifier = 0,Value;
  255.  
  256.                         PushWindow(PanelWindow);
  257.  
  258.                         AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  259.                         RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  260.                         GT_RefreshWindow(PanelWindow,NULL);
  261.  
  262.                         SetMenuStrip(PanelWindow,PanelMenu);
  263.  
  264.                         PanelWindow -> Flags &= ~WFLG_RMBTRAP;
  265.  
  266.                         for(i = 0 ; i < 10 ; i++)
  267.                         {
  268.                             GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
  269.                                 GTST_String,Keys -> Keys[Modifier][i],
  270.                             TAG_DONE);
  271.                         }
  272.  
  273.                         ActivateGadget(GadgetArray[GAD_F1],PanelWindow,NULL);
  274.  
  275.                         ActiveGadget = GadgetArray[GAD_F1];
  276.  
  277.                         while(!Terminated)
  278.                         {
  279.                             WaitPort(PanelWindow -> UserPort);
  280.  
  281.                             while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  282.                             {
  283.                                 Class    = Massage -> Class;
  284.                                 Code    = Massage -> Code;
  285.                                 Gadget    = (struct Gadget *)Massage -> IAddress;
  286.  
  287.                                 GT_ReplyIMsg(Massage);
  288.  
  289.                                 if(Class == IDCMP_ACTIVEWINDOW && ActiveGadget)
  290.                                     ActivateGadget(ActiveGadget,PanelWindow,NULL);
  291.  
  292.                                 if(Class == IDCMP_RAWKEY)
  293.                                 {
  294.                                     if(Code == IECODE_UP_PREFIX|103 && CommandWindow == PanelWindow)
  295.                                         ActivateGadget(CommandGadget,PanelWindow,NULL);
  296.                                 }
  297.  
  298.                                 if(Class == IDCMP_GADGETDOWN)
  299.                                 {
  300.                                     if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  301.                                         ActiveGadget = Gadget;
  302.                                 }
  303.  
  304.                                 if(Class == IDCMP_MENUPICK)
  305.                                 {
  306.                                     struct MenuItem *MenuItem;
  307.  
  308.                                     while(Code != MENUNULL)
  309.                                     {
  310.                                         MenuItem = ItemAddress(PanelMenu,Code);
  311.  
  312.                                         switch((ULONG)MENU_USERDATA(MenuItem))
  313.                                         {
  314.                                             case MEN_QUITPANEL:    Class = IDCMP_CLOSEWINDOW;
  315.                                                         break;
  316.  
  317.                                             case MEN_USEMACROS:    Class = IDCMP_GADGETUP;
  318.                                                         Gadget = GadgetArray[GAD_USE];
  319.                                                         break;
  320.  
  321.                                             case MEN_LOADMACROS:    Class = IDCMP_GADGETUP;
  322.                                                         Gadget = GadgetArray[GAD_LOAD];
  323.                                                         break;
  324.  
  325.                                             case MEN_SAVEMACROS:    Class = IDCMP_GADGETUP;
  326.                                                         Gadget = GadgetArray[GAD_SAVE];
  327.                                                         break;
  328.  
  329.                                             case MEN_QUALIFIER:    if(Modifier == 3)
  330.                                                             Value = 0;
  331.                                                         else
  332.                                                             Value = Modifier + 1;
  333.  
  334.                                                         GT_SetGadgetAttrs(GadgetArray[GAD_QUALIFIER],PanelWindow,NULL,
  335.                                                             GTCY_Active,Value,
  336.                                                         TAG_DONE);
  337.  
  338.                                                         Class = IDCMP_GADGETUP;
  339.                                                         Gadget = GadgetArray[GAD_QUALIFIER];
  340.                                                         Code = Value;
  341.  
  342.                                                         goto GadCheck;
  343.  
  344.                                             case MEN_CANCELMACROS:    Class = IDCMP_GADGETUP;
  345.                                                         Gadget = GadgetArray[GAD_CANCEL];
  346.                                                         break;
  347.  
  348.                                             default:        break;
  349.                                         }
  350.  
  351.                                         Code = MenuItem -> NextSelect;
  352.                                     }
  353.  
  354.                                     if(ActiveGadget)
  355.                                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  356.                                 }
  357.  
  358.                                 if(Class == IDCMP_CLOSEWINDOW)
  359.                                     Terminated = TRUE;
  360.  
  361. GadCheck:                            if(Class == IDCMP_GADGETUP)
  362.                                 {
  363.                                     switch(Gadget -> GadgetID)
  364.                                     {
  365.                                         case GAD_QUALIFIER:    for(i = 0 ; i < 10 ; i++)
  366.                                                         strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
  367.  
  368.                                                     Modifier = Code;
  369.  
  370.                                                     for(i = 0 ; i < 10 ; i++)
  371.                                                     {
  372.                                                         GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
  373.                                                             GTST_String,Keys -> Keys[Modifier][i],
  374.                                                         TAG_DONE);
  375.                                                     }
  376.  
  377.                                                     break;
  378.  
  379.                                         case GAD_USE:        Terminated = TRUE;
  380.  
  381.                                                     for(i = 0 ; i < 10 ; i++)
  382.                                                         strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
  383.  
  384.                                                     CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  385.  
  386.                                                     break;
  387.  
  388.                                         case GAD_LOAD:        strcpy(DummyBuffer,LastMacros);
  389.  
  390.                                                     DummyChar = PathPart(DummyBuffer);
  391.  
  392.                                                     *DummyChar = 0;
  393.  
  394.                                                     SetWait(PanelWindow);
  395.  
  396.                                                     PanelWindow -> Flags |= WFLG_RMBTRAP;
  397.  
  398.                                                     if(FileRequest = GetFile("Load Macro Keys...",DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.term",FALSE,FALSE))
  399.                                                     {
  400.                                                         if(!LoadMacros(DummyBuffer,Keys))
  401.                                                             MyEasyRequest(Window,"Couldn't load macro keys\n\"%s\"!","Continue",DummyBuffer);
  402.                                                         else
  403.                                                         {
  404.                                                             strcpy(Config . MacroFile,DummyBuffer);
  405.  
  406.                                                             strcpy(LastMacros,DummyBuffer);
  407.  
  408.                                                             for(i = 0 ; i < 10 ; i++)
  409.                                                             {
  410.                                                                 GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
  411.                                                                     GTST_String,Keys -> Keys[Modifier][i],
  412.                                                                 TAG_DONE);
  413.                                                             }
  414.                                                         }
  415.                                                     }
  416.  
  417.                                                     ClearPointer(PanelWindow);
  418.                                                     PanelWindow -> Flags &= ~WFLG_RMBTRAP;
  419.  
  420.                                                     break;
  421.  
  422.                                         case GAD_SAVE:        strcpy(DummyBuffer,LastMacros);
  423.  
  424.                                                     DummyChar = PathPart(DummyBuffer);
  425.  
  426.                                                     *DummyChar = 0;
  427.  
  428.                                                     SetWait(PanelWindow);
  429.                                                     PanelWindow -> Flags |= WFLG_RMBTRAP;
  430.  
  431.                                                     for(i = 0 ; i < 10 ; i++)
  432.                                                         strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
  433.  
  434.                                                     if(FileRequest = GetFile("Save Macro Keys...",DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.term",TRUE,FALSE))
  435.                                                     {
  436.                                                         if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct MacroKeys),'KEYS'))
  437.                                                             MyEasyRequest(Window,"Couldn't save macro keys\n\"%s\"!","Continue",DummyBuffer);
  438.                                                         else
  439.                                                             strcpy(LastMacros,DummyBuffer);
  440.                                                     }
  441.  
  442.                                                     ClearPointer(PanelWindow);
  443.                                                     PanelWindow -> Flags &= ~WFLG_RMBTRAP;
  444.  
  445.                                                     break;
  446.  
  447.                                         case GAD_CANCEL:    Terminated = TRUE;
  448.  
  449.                                                     CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  450.  
  451.                                                     break;
  452.  
  453.                                         default:        break;
  454.                                     }
  455.                                 }
  456.                             }
  457.                         }
  458.  
  459.                         PanelWindow -> Flags |= WFLG_RMBTRAP;
  460.  
  461.                         ClearMenuStrip(PanelWindow);
  462.  
  463.                         RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  464.  
  465.                         PopWindow();
  466.  
  467.                         CloseWindow(PanelWindow);
  468.                     }
  469.                 }
  470.  
  471.                 FreeMenus(PanelMenu);
  472.             }
  473.  
  474.             FreeGadgets(GadgetList);
  475.         }
  476.  
  477.         FreeMem(Keys,sizeof(struct MacroKeys));
  478.     }
  479. }
  480.