home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Utilities / amiCheck / Source / seltempPanel.c < prev    next >
C/C++ Source or Header  |  1998-06-11  |  8KB  |  346 lines

  1. /* seltempPanel.c 
  2.  *
  3.  *  defines the GUIFront characteristics of the seltemp panel 
  4.  */
  5.  
  6. #include <stdio.h>  
  7. #include <intuition/gadgetclass.h>
  8. #include <clib/intuition_protos.h>
  9. #include "amiCheck.h"
  10. #include "seltempPanel.h"
  11. #include "dataBase.h"
  12. #include "regGadget.h"
  13.  
  14. /* prototypes */
  15. void SelHandleGadget(struct IntuiMessage *);
  16. void SelBuildList(void);
  17. UWORD SelTrueTemplate(UWORD index);
  18.  
  19. struct Window *selWin = NULL;
  20. GUIFront *seltempGUI;
  21. ExtErrorData selExtData;
  22. static BOOL done;
  23. WORD usrSel;
  24. static UWORD ordinal;
  25. BOOL selAttach = FALSE;
  26. UWORD filterSel;
  27. struct List usrTemplates;
  28.  
  29. enum {
  30.     SELALL,
  31.     SELCHECK,
  32.     SELWITH,
  33.     SELDEP,
  34. };
  35.  
  36. /* quick configure of some gadgets */
  37. STRPTR templatelabels[] =
  38. {
  39.     "All",
  40.     "Checks",
  41.     "Withdrawals",
  42.     "Deposits",
  43.     NULL,
  44. };
  45.  
  46. struct TagItem templateCycleTags[] =
  47. {
  48.     {GTCY_Labels, templatelabels},
  49.     {TAG_DONE},
  50. };
  51.  
  52. /* define gadgetspec */
  53. GadgetSpec SPgadgetspecs[] = 
  54. {
  55.     {LISTVIEW_KIND,20,10, {0,0,0,0,NULL,NULL,GID_SPTEMPLIST,
  56.         PLACETEXT_ABOVE},ListView,GS_DefaultTags},
  57.  
  58.         {BUTTON_KIND,0,0,{0,0,0,0,"_OK", NULL, GID_SPOK,         
  59.                 PLACETEXT_IN}, NULL, GS_DefaultTags},
  60.  
  61.         {BUTTON_KIND,0,0,{0,0,0,0,"_Cancel", NULL, GID_SPCANCEL,        
  62.                 PLACETEXT_IN}, NULL, GS_DefaultTags},
  63.  
  64.      {CYCLE_KIND,0,0, {0,0,0,0,"_Filter",NULL,GID_SPFILTER,
  65.         PLACETEXT_LEFT},templateCycleTags,GS_DefaultTags},
  66. };
  67.  
  68. /* set up array of pointers to our specs */
  69. GadgetSpec *SP_SelTempSpecs[] =
  70. {
  71.         &SPgadgetspecs[0],
  72.         &SPgadgetspecs[1],
  73.         &SPgadgetspecs[2],
  74.     &SPgadgetspecs[3],
  75.         NULL,
  76. };
  77.  
  78.  
  79. /* define the layout of this panel */
  80. ULONG SP_SelTempPanel[] =
  81. {
  82.    GUIL_Flags, GUILF_PropShare | GUILF_EqualWidth,
  83.  
  84.     GUIL_VertGroup,0,
  85.         GUIL_GadgetSpecID, GID_SPFILTER,                                          
  86.         GUIL_GadgetSpecID, GID_SPTEMPLIST,
  87.     TAG_DONE,
  88.                                        
  89.    TAG_DONE,       
  90. };
  91.  
  92. /****************************************************
  93. * SelTempGUI
  94. *
  95. *    create gui for this panel
  96. *****************************************************/
  97. void SelTempGUI(void)
  98. {
  99.  
  100.    done = FALSE;    
  101.    usrSel = amntState.currTemplate;
  102.    /*AmiLock();*/
  103.  
  104.    if (selWin == NULL) {
  105.            GF_SetGUIAttr(seltempGUI, GUI_OpenGUI, TRUE, TAG_DONE);
  106.         SelTempStrip();
  107.  
  108.        GF_GetGUIAttr(seltempGUI, GUI_Window, &selWin, TAG_DONE);
  109.        ResetMenuStrip(selWin,menuStrip);
  110.     usrSel = amntState.currTemplate;
  111.        GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPTEMPLIST].gs_Gadget,
  112.             GTLV_Labels, &templates,
  113.             GTLV_MakeVisible, amntState.currTemplate,
  114.             GTLV_Selected,amntState.currTemplate,
  115.             TAG_DONE);
  116.  
  117.     selAttach = TRUE;
  118.     filterSel = SELALL;
  119.     NewList(&usrTemplates);
  120.     
  121.     GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPFILTER].gs_Gadget,
  122.             GTCY_Active, filterSel,
  123.             TAG_DONE);
  124.    }
  125.    else {
  126.         WindowToFront(selWin);
  127.         ActivateWindow(selWin);
  128.    }
  129.  
  130. #if 0
  131.    /* Process input events */
  132.     while (!done)
  133.        {
  134.          struct IntuiMessage *imsg;
  135.                     /* Wait for an event to occur */
  136.  
  137.                     GF_Wait(guiapp,0);
  138.  
  139.                     /* We only bother to listen for CLOSEWINDOW events.
  140.                      * Of course, in a real application, you would be
  141.                      * examining the Class field for IDCMP_GADGETUP
  142.                      * messages and act accordingly.
  143.                      */
  144.  
  145.                     while (imsg = GF_GetIMsg(guiapp))
  146.                     {
  147.             if (imsg->IDCMPWindow->UserData == gui)
  148.                 AmiLocalMsg(imsg);
  149.             else    SelTempMsg(imsg);                                  
  150.                         GF_ReplyIMsg(imsg);
  151.                     }
  152.          }
  153.  
  154.    GF_SetGUIAttr(seltempGUI, GUI_OpenGUI, FALSE, TAG_DONE);            
  155.    selWin = NULL;
  156.    SelTempStrip();
  157.    
  158.   /* AmiUnlock();*/
  159. #endif
  160. }
  161.  
  162. /********************************************************
  163. * SelTempMsg()
  164. *
  165. *    Handles messages from afar 
  166. **********************************************************/
  167. BOOL SelTempMsg(struct IntuiMessage *imsg)
  168. {
  169.  BOOL done = FALSE;
  170.  
  171.   switch (imsg->Class) {
  172.     case IDCMP_CLOSEWINDOW:
  173.                     done = TRUE;
  174.                     break;
  175.  
  176.     case IDCMP_RAWKEY:
  177.         if (imsg->Code == 0x44) {
  178.             amntState.currTemplate = SelTrueTemplate(usrSel);
  179.             AmiEnterData();
  180.         }
  181.         else if (imsg->Code == 0x40) {
  182.             done = TRUE;
  183.         }
  184.         else if (GF_ProcessListView(seltempGUI,SP_SelTempSpecs[GID_SPTEMPLIST],
  185.             imsg,&ordinal)) {
  186.                 usrSel = ordinal;
  187.                 if (filterSel == SELALL)
  188.                     amntState.currTemplate = ordinal;
  189.                 else    amntState.currTemplate = SelTrueTemplate(usrSel);
  190.                 AmiNewTemp();
  191.         }
  192.         else AmiHelpKey(imsg,SELTEMP_PANEL);
  193.         break;
  194.  
  195.     case IDCMP_REFRESHWINDOW:
  196.         RegRefresh(TRUE);
  197.         break;
  198.  
  199.     case IDCMP_MENUPICK:
  200.         amidone = done = AmiHandleMenu(imsg);
  201.             if (seldone == TRUE) 
  202.             done = seldone;
  203.         break;
  204.  
  205.     case IDCMP_GADGETUP:
  206.         SelHandleGadget(imsg);
  207.         break;
  208.  }
  209.  
  210.  if (done) {
  211.           SelTempStrip();
  212.           selWin = NULL;
  213.         }
  214.  
  215.  return (done);
  216. }
  217.  
  218. /***************************************************
  219. * SelHandleGadget....
  220. *
  221. *     double clicks and OK will change ord val.
  222. ****************************************************/
  223. void SelHandleGadget(struct IntuiMessage *imsg)
  224. {
  225. struct List *list;
  226. struct Gadget *gad = (struct Gadget *)(imsg->IAddress);
  227. UWORD code = imsg->Code;
  228.  
  229.  switch (gad->GadgetID) {
  230.     case GID_SPTEMPLIST:
  231.         /* find curr template based on which list? */
  232.         amntState.currTemplate = usrSel = code;
  233.  
  234.         if (filterSel != SELALL)
  235.             amntState.currTemplate = SelTrueTemplate(code);
  236.  
  237.         AmiNewTemp();
  238.         AmiEnterData();
  239.         break;
  240.  
  241.     case GID_SPFILTER:
  242.         amntState.currTemplate = SelTrueTemplate(usrSel);
  243.  
  244.         /* detach and free list */
  245.         SelTempStrip();
  246.         if (filterSel != SELALL) {
  247.             DataFreeList(&usrTemplates);
  248.         }
  249.  
  250.         filterSel = code;
  251.         if (filterSel != SELALL) {
  252.             SelBuildList();
  253.             amntState.currTemplate = usrSel = 0;
  254.             list = &usrTemplates;
  255.         }
  256.         else {
  257.             usrSel = amntState.currTemplate;
  258.             list = &templates;
  259.         }
  260.  
  261.         
  262.         GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPTEMPLIST].gs_Gadget,
  263.             GTLV_Labels, list,
  264.             GTLV_Selected, usrSel,
  265.             GTLV_MakeVisible, usrSel,
  266.         TAG_DONE); 
  267.  
  268.         selAttach = TRUE;
  269.         break;
  270.  }
  271. }
  272.  
  273.  
  274. /***********************************************************
  275. * SelTempStrip()
  276. *
  277. *
  278. ************************************************************/
  279. void SelTempStrip(void)
  280. {
  281.    if (selAttach == TRUE) {
  282.           GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPTEMPLIST].gs_Gadget,
  283.                 GTLV_Labels, ~0,
  284.                 TAG_DONE); 
  285.         selAttach = FALSE;
  286.     }
  287. }
  288.  
  289. /***********************************************************
  290. * SelTempInstall()
  291. *
  292. *
  293. ************************************************************/
  294. void SelTempInstall(void)
  295. {
  296.     amntState.currTemplate = 0;
  297.     SelTempStrip();
  298.  
  299.        GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPTEMPLIST].gs_Gadget,
  300.             GTLV_Labels, &templates,
  301.             GTLV_Selected, amntState.currTemplate,
  302.             GTLV_MakeVisible, amntState.currTemplate,
  303.             TAG_DONE); 
  304.  
  305.     selAttach = TRUE;
  306.     filterSel = SELALL;
  307.     NewList(&usrTemplates);
  308.     
  309.     GF_SetGadgetAttrs(seltempGUI,SPgadgetspecs[GID_SPFILTER].gs_Gadget,
  310.             GTCY_Active, filterSel,
  311.             TAG_DONE);
  312.  
  313.     AmiNewTemp();
  314. }
  315.  
  316. /************************************************************
  317. * SelBuildList(void)
  318. *
  319. *    Build a temporary list
  320. *************************************************************/
  321. void SelBuildList(void)
  322. {
  323.  templateNode *node = NULL;
  324.  
  325.  while ( (node = (templateNode *)DataGetNext(&templates,(struct Node *)node)) != NULL) {
  326.     if (node->template.type == filterSel-1 || filterSel == SELALL)
  327.         DataAddTemp(&usrTemplates, node);
  328.  }
  329. }
  330.  
  331. /*****************************************************************
  332. * SelTrueTemplate(int,int)
  333. *
  334. *    Find actual template from sublist
  335. ******************************************************************/
  336. UWORD SelTrueTemplate(UWORD index)
  337. {
  338.  templateNode *node;
  339.  
  340.  if (filterSel != SELALL) {
  341.      node = (templateNode *)DataOrd2Node(&usrTemplates,index);
  342.      return ((UWORD)DataNode2Ord(&templates,node->node.ln_Name));
  343.  }
  344.  else return (amntState.currTemplate);
  345. }
  346.