home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / biz / misc / banker / src / gui.c < prev    next >
C/C++ Source or Header  |  1993-12-17  |  26KB  |  746 lines

  1. /*
  2.  * gui.c
  3.  */
  4.  
  5. /* $Id: gui.c,v 1.11 1993/09/03 00:16:55 beust Exp beust $ */
  6.  
  7. #include "common.h"
  8.  
  9. struct Library *MUIMasterBase;
  10. struct _Gui Gui;
  11.  
  12. /* Id's returned when certain gadgets are pressed */
  13.  
  14. #define ID_GE_REPLACE 10
  15. #define ID_GE_OK      11
  16. #define ID_GE_CLEAR   12
  17.  
  18. #define ID_AU_NEW              20
  19. #define ID_AU_ADD              21
  20. #define ID_AU_REPLACE          22
  21. #define ID_AU_DELETE           23
  22. #define ID_AU_DOUBLECLICK      24
  23.  
  24. #define ID_LI_DOUBLECLICK 30
  25.  
  26. #define ID_MA_LIST 40
  27. #define ID_MA_AUTO 41
  28. #define ID_MA_GETENTRY 42
  29.  
  30. #define ID_MENU_START                         100
  31.  
  32. #define ID_MENU_FILE          (ID_MENU_START + 0)
  33. #define ID_MENU_OPEN          (ID_MENU_FILE + 1)
  34. #define ID_MENU_SAVE          (ID_MENU_OPEN + 1)
  35. #define ID_MENU_SAVEAS        (ID_MENU_SAVE + 1)
  36. #define ID_MENU_PRINT         (ID_MENU_SAVEAS + 1)
  37. #define ID_MENU_EXPORT        (ID_MENU_PRINT + 1)
  38. #define ID_MENU_QUIT          (ID_MENU_EXPORT + 1)
  39.  
  40. #define ID_MENU_PREFS         (ID_MENU_QUIT + 1)
  41. #define ID_MENU_SAVEPREFS     (ID_MENU_PREFS + 1)
  42.  
  43. #define ID_MENU_END           ID_MENU_START + 50
  44.  
  45. /*************************/
  46. /* Init & Fail Functions */
  47. /*************************/
  48.  
  49. static void fail(APTR app,char *str)
  50. {
  51.    if (app)
  52.       MUI_DisposeObject(app);
  53.  
  54. #ifndef _DCC
  55.    if (MUIMasterBase)
  56.       CloseLibrary(MUIMasterBase);
  57. #endif
  58.  
  59.    if (str)
  60.    {
  61.       fprintf(stderr, "MUI error %d: %s\n", MUI_Error(), str);
  62.       exit(20);
  63.    }
  64. }
  65.  
  66. static void init(void)
  67. {
  68. #ifndef _DCC
  69.    if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  70.       fail(NULL,"Failed to open "MUIMASTER_NAME".");
  71. #endif
  72. }
  73.  
  74. #ifndef __SASC
  75. static void stccpy(char *dest,char *source,int len)
  76. {
  77.    strncpy(dest,source,len);
  78.    dest[len-1]='\0';
  79. }
  80.  
  81. int wbmain(struct WBStartup *wb_startup)
  82. {
  83.    extern int main(int argc, char *argv[]);
  84.    return (main(0, NULL));
  85. }
  86. #endif
  87.  
  88.  
  89. /*****************
  90.  * Private
  91.  *****************/
  92.  
  93. static char *
  94. returnListFormatString(Entries entries, struct ListEntry *le, char *result)
  95. {
  96.    int i;
  97.    char acc[64];
  98.  
  99.    strcpy(result, "COL=0");    /* that's for '*' or ' ' */
  100.    for (i=1; i < le -> numberOfColumns + 1; i++) {
  101.       strcpy(acc, "");
  102.       if (i != 0) strcat(result, ",");
  103.       sprintf(acc, "COL=%d", i);
  104.       strcat(result, acc);
  105.    }
  106.    return result;
  107. }
  108.  
  109. APTR __saveds __asm
  110. displayEntryFunc(register __a0 struct Hook *hook,
  111.          register __a2 char **array,
  112.          register __a1 void *entry)
  113. {
  114.    int i, j;
  115.    LONG l[MAX_FIELDS + 1];
  116.    char s[64];
  117.    Entry ent = (Entry) entry;    /* works with auto and entry as well */
  118.    struct ListEntry *le = (struct ListEntry *) hook -> h_Data;
  119.  
  120.    if (ent -> generatedBy) *array++ = "+ ";
  121.    else if (ent -> validated) *array++ = "  ";
  122.    else *array++ = "* ";
  123.    for (i=0; i < le -> numberOfColumns; i++) {
  124.       struct ColumnListEntry *col = & le -> col[i];
  125.       for (j = 0; j < col -> numberOfFields; j++) {
  126.          enum Fields f = (enum Fields) col -> fields[j];
  127.          
  128.          switch (f) {
  129.             case DATEFIELD : l[j] = (LONG) myDateToStr(& ent -> date); break;
  130.             case TRANSACTIONFIELD : l[j] = (LONG) ent -> transaction; break;
  131.             case CHECKNUMBERFIELD : l[j] = (LONG) ent -> checkNumber; break;
  132.             case AMOUNTFIELD : l[j] = (LONG) ent -> amount; break;
  133.             case IMPUTATIONFIELD : l[j] = (LONG) ent -> imputation; break;
  134.             case REASONFIELD : l[j] = (LONG) ent -> reason; break;
  135.          }
  136.       }
  137.       l[j] = NULL;
  138.       mySprintf(s, col -> format, l);
  139.       *array++ = strdup(s);
  140.    }
  141.    return NULL;
  142. }
  143.  
  144. struct Hook displayEntryHook = {
  145.         {NULL, NULL},
  146.         (void *)displayEntryFunc,
  147.         NULL, & DisplayEntryFormat
  148. };
  149.  
  150. APTR __saveds __asm
  151. displayAutomaticFunc(register __a0 struct Hook *hook,
  152.              register __a2 char **array,
  153.              register __a1 void *entry)
  154. {
  155.    Automatic ent = (Automatic) entry;    /* works with auto and entry as well */
  156.    *array = ent -> formattedString;
  157.    return NULL;
  158. }
  159.  
  160. struct Hook displayAutomaticHook = {
  161.         {NULL, NULL},
  162.         (void *)displayAutomaticFunc,
  163.         NULL, NULL
  164. };
  165.  
  166. LONG __saveds __asm
  167. compareEntryFunc(register __a0 struct Hook *hook,
  168.          register __a1 Entry p1,
  169.          register __a2 Entry p2)
  170. /* Actually, compare in reverse order, so that the most recent date */
  171. /* appears on top */
  172. {
  173.   
  174.    LONG result = ((LONG) p2 -> date.ds_Days) - ((LONG) p1 -> date.ds_Days);
  175. /*
  176.    if (count++ < 30) {
  177.       D(printf("'%s' (%d)'%s' (%d) -> %d\n",
  178.            myDateToStr(&p1->date), p1->date.ds_Days,
  179.            myDateToStr(&p2->date), p2->date.ds_Days,
  180.           result));
  181.    }
  182. */
  183.    return result;
  184. }
  185.  
  186. static struct Hook compareEntryHook = {
  187.     {NULL, NULL},
  188.     (void *) compareEntryFunc,
  189.     NULL, NULL
  190. };
  191.  
  192. /************
  193.  * Menu related functions
  194.  ************/
  195.  
  196. /* The strings are actually filled by the function initMenus() */
  197. void
  198. initMenus(Gui_t gui, struct NewMenu *nm)
  199. /* Set up the menus */
  200. {
  201.    int i = 0;
  202.  
  203.    addToNewMenu(nm, gui, NM_TITLE, getString(MSG_MENU_FILE), NULL,
  204.                 0, NULL, i++);
  205.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_OPEN), "o",
  206.                    ID_MENU_OPEN, menuOpen, i++);
  207.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_SAVE), "w",
  208.                    ID_MENU_SAVE, menuSave, i++);
  209.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_SAVE_AS), "a",
  210.                    ID_MENU_SAVEAS, menuSaveAs, i++);
  211.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_PRINT), "p",
  212.                    ID_MENU_PRINT, menuPrint, i++);
  213.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_EXPORT), "e",
  214.                    ID_MENU_EXPORT, menuExport, i++);
  215.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_QUIT), "q",
  216.                    MUIV_Application_ReturnID_Quit, NULL, i++);
  217.    addToNewMenu(nm, gui, NM_TITLE, getString(MSG_MENU_PREFERENCES), NULL,
  218.                 0, NULL, i++);
  219.       addToNewMenu(nm, gui, NM_ITEM, getString(MSG_MENU_FILE_SAVE), NULL,
  220.                    ID_MENU_SAVEPREFS, menuSavePrefs, i++);
  221.  
  222.  
  223.    addToNewMenu(nm, gui, NM_END, NULL, NULL,
  224.                 0, NULL, i++);
  225.  
  226.    if (i >= MENU_ITEM_COUNT) {
  227.       fprintf(stderr, "too many menus!\n");
  228.    }
  229. }
  230.  
  231. /**************
  232.  * Main function
  233.  **************/
  234.  
  235.  
  236. int
  237. buildGui(Gui_t gui, Entries entries, struct OptionsFileStruct *ofStruct)
  238. {
  239.    ULONG signal;
  240.    APTR app;
  241.    APTR mainWindowObject, newEntryWin;
  242.    APTR pb1, pb2, pb3, pb4;        /*  main window objects */
  243.    APTR s1, s2, s3, s4, s5, s6, c1, pbok, pbrepl, pbclear; /* get entry objects */
  244.    APTR s10, s11, s12, s13, s14, pb10, pb11, pb12, pb13,
  245.         s15, s16, s17, s18, lv10;   /* getauto objects */
  246.    APTR lv20, cy20, te20, te21;   /* list objects */
  247.    char *payment[10], *actions[10];
  248.    char validatedString[40], totalString[40];
  249.    float total;
  250.    Entry entry;
  251.    int i, running, cycle;
  252.    Entry activeEntry;
  253.    Automatic activeAutomatic;
  254.    struct NewMenu *mainMenu;
  255.    char listFormatString[128];   /* will contain "COL=0,COL=1,..." */
  256.  
  257. /* Fill the constant listviews */
  258.    i = 0;
  259.    payment[i++] = getString(MSG_CHECK);
  260.    payment[i++] = getString(MSG_CREDITCARD);
  261.    payment[i++] = NULL;
  262.  
  263.    i = 0;
  264.    actions[i++] = getString(MSG_ACCOUNT);
  265.    actions[i++] = getString(MSG_EDIT);
  266.    actions[i++] = getString(MSG_DELETE);
  267.    actions[i++] = NULL;
  268.  
  269.    sprintf(validatedString, getString(MSG_VALIDATED),
  270.            computeValidatedTotal(entries));
  271.    total = computeTotal(entries);
  272.    sprintf(totalString, getString(MSG_TOTAL), total);
  273.  
  274. /* Initialize MUI */
  275.    init();
  276.  
  277. /* Initialize the GUI's global area */
  278.    memset(& gui -> autoSA, 0, sizeof(gui -> autoSA));  /* smartalloc structures */
  279.    memset(& gui -> entrySA, 0, sizeof(gui -> entrySA));
  280.    mainMenu = (struct NewMenu *) malloc(sizeof(struct NewMenu) * MENU_ITEM_COUNT);
  281.    gui -> menuFunctions = (void **) malloc(sizeof(void **) * MENU_ITEM_COUNT);
  282.    initMenus(gui, mainMenu);
  283.    returnListFormatString(entries, DisplayEntryFormat, listFormatString);
  284.  
  285.    /*
  286.    ** Create the application.
  287.    ** Note that we generate two empty groups without children.
  288.    ** These children will be added later with OM_ADDMEMBER.
  289.    */
  290.  
  291.    gui -> app = app = ApplicationObject,
  292.       MUIA_Application_Title      , "Banker",
  293.       MUIA_Application_Version    , "$VER: 2.0beta (12.93)",
  294.       MUIA_Application_Copyright  , "©1992/93, Cédric BEUST",
  295.       MUIA_Application_Author     , "Cédric BEUST",
  296.       MUIA_Application_Description, "A home budget program",
  297.       MUIA_Application_Base       , "BANKER",
  298.       MUIA_Application_Menu       , mainMenu,
  299.  
  300. /*
  301.  * MainWindow
  302.  */
  303.  
  304.       SubWindow, gui -> mainWindowObject = mainWindowObject = WindowObject,
  305.             MUIA_Window_ID, ID_MAINWINDOW,
  306.             MUIA_Window_Title, "Banker",
  307.             WindowContents,  VGroup,
  308.                Child, pb1 = KeyButton(getString(MSG_WINDOW_NEW_ENTRY_WITH__),
  309.                            getSignificantCharacter(MSG_WINDOW_NEW_ENTRY_WITH__)),
  310.                Child, pb2 = KeyButton(getString(MSG_WINDOW_LIST_ENTRIES),
  311.                            getSignificantCharacter(MSG_WINDOW_LIST_ENTRIES)),
  312.                Child, pb3 = KeyButton(getString(MSG_WINDOW_PERIODIC_ENTRY),
  313.                            getSignificantCharacter(MSG_WINDOW_PERIODIC_ENTRY)),
  314.                Child, pb4 = KeyButton(getString(MSG_WINDOW_CLEAR_FILE),
  315.                            getSignificantCharacter(MSG_WINDOW_CLEAR_FILE)),
  316.              End,  /* windowcontents */
  317.       End,  /* subwindow */
  318.  
  319. /*
  320.  * GetEntry Window
  321.  */
  322.  
  323.       SubWindow, gui -> getEntryWindowObject = newEntryWin = WindowObject,
  324.           MUIA_Window_ID, ID_GETENTRYWINDOW,
  325.           MUIA_Window_Title, getString(MSG_WINDOW_NEW_ENTRY),
  326.              WindowContents, VGroup,
  327.              Child, HGroup,
  328.                    Child, gui -> geDate = s1 = StringObject,
  329.                       StringFrame,
  330.                       MUIA_String_MaxLen, DATEL,
  331.                       MUIA_FrameTitle, getString(MSG_GADGET_DATE),
  332.                    End,
  333.                    Child, gui -> geCheckNumber = s2 = StringObject,
  334.                       StringFrame,
  335.                       MUIA_String_MaxLen, CHECKNUMBERL,
  336.                       MUIA_FrameTitle, getString(MSG_GADGET_CHECKNUMBER),
  337.                    End,
  338.              End,
  339.              Child, HGroup,
  340.                    Child, gui -> geTransaction = s3 = StringObject,
  341.                       StringFrame,
  342.                       MUIA_String_MaxLen, TRANSACTIONL,
  343.                       MUIA_FrameTitle, getString(MSG_GADGET_TRANSACTION),
  344.                    End,
  345.                    Child, gui -> geImputation = s4 = StringObject,
  346.                       StringFrame,
  347.                       MUIA_String_MaxLen, IMPUTATIONL,
  348.                       MUIA_FrameTitle, getString(MSG_GADGET_IMPUTATION),
  349.                    End,
  350.              End,
  351.              Child, HGroup,
  352.                    Child, gui -> geAmount = s5 = StringObject,
  353.                       StringFrame,
  354.                       MUIA_String_MaxLen, AMOUNTL,
  355.                       MUIA_FrameTitle, getString(MSG_GADGET_MONTANT),
  356.                    End,
  357.                    Child, gui -> geReason = s6 = StringObject,
  358.                       StringFrame,
  359.                       MUIA_String_MaxLen, REASONL,
  360.                       MUIA_FrameTitle, getString(MSG_GADGET_LIBELLE),
  361.                    End,
  362.              End,
  363.              Child, HGroup,
  364.                 Child, RectangleObject,
  365.                    MUIA_Weight, 300,
  366.                 End,
  367.                 Child, c1 = CycleObject,
  368.                    MUIA_Cycle_Entries, payment,
  369.                 End,
  370.                 Child, RectangleObject,
  371.                    MUIA_Weight, 300,
  372.                 End,
  373.              End,
  374.              Child, HGroup,
  375.                 Child, RectangleObject,
  376.                    MUIA_Weight, 150,
  377.                 End,
  378.                 Child, pbok = KeyButton(getString(MSG_OK),
  379.                                  getSignificantCharacter(MSG_OK)),
  380.                 Child, RectangleObject,
  381.                    MUIA_Weight, 150,
  382.                 End,
  383.                 Child, gui->geReplace=pbrepl=KeyButton(getString(MSG_REPLACE_FULL),
  384.                                  getSignificantCharacter(MSG_REPLACE_FULL)),
  385.                 Child, RectangleObject,
  386.                    MUIA_Weight, 150,
  387.                 End,
  388.                 Child, pbclear = KeyButton(getString(MSG_CLEAR),
  389.                                  getSignificantCharacter(MSG_CLEAR)),
  390.                 Child, RectangleObject,
  391.                    MUIA_Weight, 150,
  392.                 End,
  393.                 MUIA_Weight, 0,
  394.              End,
  395.              
  396.           End, /* vgroup */
  397.       End,  /* subwindow */
  398.  
  399. /*
  400.  * List Window
  401.  */
  402.  
  403.       SubWindow, gui -> listWindowObject = WindowObject,
  404.           MUIA_Window_ID, ID_LISTWINDOW,
  405.           MUIA_Window_Title, "List",
  406.              WindowContents, VGroup,
  407.                 Child, gui -> liListviewObject = lv20 = ListviewObject,
  408.                    MUIA_Listview_Input, TRUE,
  409.                    MUIA_Listview_List, gui -> liListObject = ListObject,
  410.                       ReadListFrame,
  411.                       MUIA_List_DisplayHook, & displayEntryHook,
  412.                       MUIA_List_CompareHook, & compareEntryHook,
  413.                       MUIA_List_Format, listFormatString,
  414.                    End,  /* listobject */
  415.                 End,  /* list */
  416.                 Child, HGroup,
  417.                    Child, RectangleObject,
  418.                       MUIA_Weight, 100,
  419.                    End,
  420.                    Child, gui -> liCycleObject = cy20 = CycleObject,
  421.                       MUIA_Cycle_Entries, actions,
  422.                    End, /* cycle */
  423.                    Child, RectangleObject,
  424.                       MUIA_Weight, 50,
  425.                    End,
  426.                    Child, VGroup,
  427.                       GroupFrame,
  428.                       Child, gui -> liValidatedObject = te20 = RectangleObject,
  429.                          MUIA_FrameTitle, validatedString,
  430.                       End,
  431.                       Child, gui -> liTotalObject = te21 = RectangleObject,
  432.                          MUIA_FrameTitle, totalString,
  433.                       End,
  434.                    End, /* group */
  435.                    Child, RectangleObject,
  436.                       MUIA_Weight, 30,
  437.                    End,
  438.                 End,  /* group */
  439.           End, /* hgroup */
  440.       End, /* subwindow */
  441.  
  442. /*
  443.  * GetAutomatic Window
  444.  */
  445.  
  446.       SubWindow, gui -> automaticWindowObject = WindowObject,
  447.           MUIA_Window_ID, ID_AUTOMATICWINDOW,
  448.           MUIA_Window_Title, getString(MSG_WINDOW_AUTOMATIC_ENTRIES),
  449.              WindowContents, HGroup,
  450.                 Child, VGroup,
  451.                    GroupFrame,
  452.                    Child, HGroup,
  453.                       Child, gui -> auFrom = s10 = StringObject,
  454.                          StringFrame,
  455.                          MUIA_String_MaxLen, 30,
  456.                          MUIA_FrameTitle, getString(MSG_START_AT_DATE),
  457.                       End, /* object */
  458.                       Child, gui -> auTo = s11 = StringObject,
  459.                          StringFrame,
  460.                          MUIA_String_MaxLen, 30,
  461.                          MUIA_FrameTitle, getString(MSG_END_AT_DATE),
  462.                       End, /* object */
  463.                       Child, gui -> auAmount = s12 = StringObject,
  464.                          StringFrame,
  465.                          MUIA_String_MaxLen, AMOUNTL,
  466.                          MUIA_FrameTitle, getString(MSG_GADGET_MONTANT),
  467.                       End, /* object */
  468.                    End, /* hgroup */
  469.  
  470. /*
  471.                    Child, RectangleObject,
  472.                       MUIA_Weight, 200,
  473.                    End,
  474. */
  475.  
  476.                    Child, HGroup,
  477.                       Child, VGroup,
  478.                          Child, gui -> auDays = s13 = StringObject,
  479.                              StringFrame,
  480.                             MUIA_String_MaxLen, 10,
  481.                             MUIA_FrameTitle, getString(MSG_DAYS),
  482.                             MUIA_Weight, 50,
  483.                          End, /* object */
  484.                          Child, gui -> auWeeks = s14 = StringObject,
  485.                              StringFrame,
  486.                             MUIA_String_MaxLen, 10,
  487.                             MUIA_FrameTitle, getString(MSG_WEEKS),
  488.                             MUIA_Weight, 50,
  489.                          End, /* object */
  490.                          Child, gui -> auMonths = s15 = StringObject,
  491.                              StringFrame,
  492.                             MUIA_String_MaxLen, 10,
  493.                             MUIA_FrameTitle, getString(MSG_MONTHS),
  494.                             MUIA_Weight, 50,
  495.                          End, /* object */
  496.                          Child, gui -> auYears = s16 = StringObject,
  497.                              StringFrame,
  498.                             MUIA_String_MaxLen, 10,
  499.                             MUIA_FrameTitle, getString(MSG_YEARS),
  500.                             MUIA_Weight, 50,
  501.                          End, /* object */
  502.                       End, /* vgroup */
  503.                       Child, RectangleObject,
  504.                          MUIA_Weight, 50,
  505.                       End,
  506.                       Child, VGroup,
  507.                          Child, RectangleObject,
  508.                             MUIA_Weight, 50,
  509.                          End,
  510.                          Child, gui->auNew=pb10= KeyButton(getString(MSG_NEW_FULL),
  511.                                            getSignificantCharacter(MSG_NEW_FULL)),
  512.                          Child, RectangleObject,
  513.                             MUIA_Weight, 50,
  514.                          End,
  515.                          Child, gui->auAdd=pb11= KeyButton(getString(MSG_ADD_FULL),
  516.                                            getSignificantCharacter(MSG_ADD_FULL)),
  517.                          Child, RectangleObject,
  518.                             MUIA_Weight, 50,
  519.                          End,
  520.                          Child, gui->auReplace=pb12 = KeyButton(getString(MSG_REPLACE_FULL),
  521.                                       getSignificantCharacter(MSG_REPLACE_FULL)),
  522.                          Child, RectangleObject,
  523.                             MUIA_Weight, 50,
  524.                          End,
  525.                          Child, gui->auDelete=pb13 = KeyButton(getString(MSG_DELETE_FULL),
  526.                                         getSignificantCharacter(MSG_DELETE_FULL)),
  527.                       End, /* vgroup */
  528.                    End, /* hgroup */
  529.  
  530. /*
  531.                    Child, RectangleObject,
  532.                       MUIA_Weight, 200,
  533.                    End,
  534. */
  535.  
  536.                    Child, HGroup,
  537.                          Child, gui -> auReason = s17 = StringObject,
  538.                              StringFrame,
  539.                             MUIA_String_MaxLen, REASONL,
  540.                             MUIA_FrameTitle,getString(MSG_GADGET_TRANSACTION),
  541.                          End, /* object */
  542.                    End, /* hgroup */
  543.                    Child, HGroup,
  544.                          Child, gui -> auImputation = s18 = StringObject,
  545.                              StringFrame,
  546.                             MUIA_String_MaxLen, IMPUTATIONL,
  547.                             MUIA_FrameTitle, getString(MSG_GADGET_IMPUTATION),
  548.                          End, /* object */
  549.                    End, /* hgroup */
  550.                 End, /* vgroup */
  551.  
  552.                 Child, gui -> auListviewObject = lv10 = ListviewObject,
  553.                    MUIA_Listview_Input, TRUE,
  554.                    MUIA_Listview_List, gui -> auListObject = ListObject,
  555.                       MUIA_List_DisplayHook, & displayAutomaticHook,
  556.                       MUIA_List_Format, "DELTA=8",
  557.                       ReadListFrame,
  558.                    End,  /* listobject */
  559.                 End,  /* listviewobject */
  560.  
  561.          End, /* hgroup */
  562.       End, /* windowcontents */
  563.    End;  /* app */
  564.  
  565.    if (! app) fail(app,"Failed to create Application.");
  566.    if (! gui -> mainWindowObject) fail(app, "Couldn't open main window");
  567.  
  568.  
  569.    /*
  570.    ** Main window settings
  571.    */
  572.  
  573.    DoMethod(gui -> mainWindowObject,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  574.             app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  575.  
  576.  
  577.    /* Connect the buttons to open the proper windows */
  578.    DoMethod(pb1, MUIM_Notify, MUIA_Pressed, FALSE,
  579.             app, 2, MUIM_Application_ReturnID, ID_MA_GETENTRY);
  580.    DoMethod(pb2, MUIM_Notify, MUIA_Pressed, FALSE,
  581.             app, 2, MUIM_Application_ReturnID, ID_MA_LIST);
  582.    DoMethod(pb3, MUIM_Notify, MUIA_Pressed, FALSE,
  583.             app, 2, MUIM_Application_ReturnID, ID_MA_AUTO);
  584.  
  585.    /*
  586.    ** GetEntry window settings
  587.    */
  588.  
  589.    DoMethod(pbok, MUIM_Notify, MUIA_Pressed, FALSE,
  590.             app, 2, MUIM_Application_ReturnID, ID_GE_OK);
  591.    DoMethod(pbrepl, MUIM_Notify, MUIA_Pressed, FALSE,
  592.             app, 2, MUIM_Application_ReturnID, ID_GE_REPLACE);
  593.    DoMethod(pbclear, MUIM_Notify, MUIA_Pressed, FALSE,
  594.             app, 2, MUIM_Application_ReturnID, ID_GE_CLEAR);
  595.    DoMethod(gui->getEntryWindowObject, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  596.             gui -> getEntryWindowObject, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  597.    DoMethod(gui -> getEntryWindowObject, MUIM_Window_SetCycleChain,
  598.             s1, s2, s3, s4, s5, s6, c1, pbok, pbrepl, pbclear, NULL);
  599.  
  600.  
  601.    /*
  602.    ** List window settings
  603.    */
  604.  
  605.    DoMethod(gui-> listWindowObject,MUIM_Notify,MUIA_Window_CloseRequest, TRUE,
  606.             gui -> listWindowObject, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  607.    DoMethod(gui-> liListviewObject, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  608.             app, 2, MUIM_Application_ReturnID, ID_LI_DOUBLECLICK);
  609.    DoMethod(gui -> listWindowObject, MUIM_Window_SetCycleChain,
  610.             lv20, cy20, NULL);
  611.  
  612.  
  613.    /*
  614.    ** Automatic window settings
  615.    */
  616.  
  617.    DoMethod(gui->automaticWindowObject,MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  618.             gui -> automaticWindowObject, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  619.    DoMethod(gui ->automaticWindowObject, MUIM_Window_SetCycleChain,
  620.             s10, s11, s12, s13, s14, s15, s16, s17, s18, 
  621.             pb10, pb11, pb12, pb13, lv10, NULL);
  622.    DoMethod(pb10, MUIM_Notify, MUIA_Pressed, FALSE,
  623.             app, 2, MUIM_Application_ReturnID, ID_AU_NEW);
  624.    DoMethod(pb11, MUIM_Notify, MUIA_Pressed, FALSE,
  625.             app, 2, MUIM_Application_ReturnID, ID_AU_ADD);
  626.    DoMethod(pb12, MUIM_Notify, MUIA_Pressed, FALSE,
  627.             app, 2, MUIM_Application_ReturnID, ID_AU_REPLACE);
  628.    DoMethod(pb13, MUIM_Notify, MUIA_Pressed, FALSE,
  629.             app, 2, MUIM_Application_ReturnID, ID_AU_DELETE);
  630.    DoMethod(gui-> auListviewObject, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  631.             app, 2, MUIM_Application_ReturnID, ID_AU_DOUBLECLICK);
  632.    set(pb12, MUIA_Disabled, TRUE);
  633.    set(pb13, MUIA_Disabled, TRUE);
  634.  
  635.    /*
  636.    ** Open the windows
  637.    */
  638.  
  639.    set(gui -> mainWindowObject, MUIA_Window_Open, TRUE);
  640.    if (ofStruct -> getEntry.isOpen) openGetentryWindow(gui, entries);
  641.    if (ofStruct -> automatic.isOpen) openAutomaticWindow(gui, entries);
  642.    if (ofStruct -> list.isOpen) openListWindow(gui, entries);
  643.  
  644.    running = 1;
  645.    while (running) {
  646.      int id;
  647.      id = DoMethod(app,MUIM_Application_Input,&signal);
  648.  
  649.      /*
  650.      ** If it's a menu, I have an array of functions for each of then
  651.      */
  652.      if (id >= ID_MENU_START && id <= ID_MENU_END) {
  653.         void (*f)();
  654.         f = (void (*)()) gui -> menuFunctions[id - ID_MENU_START];
  655.         if (f) (*f)(gui, entries);
  656.      }
  657.  
  658.      switch(id) {
  659.        case MUIV_Application_ReturnID_Quit :
  660.          if (FileModified) {
  661.             if (showRequester(gui, getString(MSG_TITLE_FILE_MODIFIED),
  662.                        getString(MSG_FILE_MODIFIED_QUIT),
  663.                        getString(MSG_YES_OR_NO)) == 0) break;
  664.             else
  665.                running = 0;
  666.          }
  667.          break;
  668.  
  669.     /*
  670.     ** These cases are related to the Main window
  671.     */
  672.  
  673.        case ID_MA_LIST :
  674.          openListWindow(gui, entries);
  675.          break;
  676.  
  677.     /*
  678.     ** These cases are related to the List window
  679.     */
  680.  
  681.        case ID_LI_DOUBLECLICK :
  682.          DoMethod(gui -> liListviewObject, MUIM_List_GetEntry,
  683.                   MUIV_List_GetEntry_Active, & activeEntry);
  684.          get(gui -> liCycleObject, MUIA_Cycle_Active, & cycle);
  685.          switch(cycle) {
  686.             case 0 :
  687.               handleValidate(gui, entries, activeEntry); break;
  688.             case 1 :
  689.               handleEdit(gui, entries, activeEntry); break;
  690.             case 2 :
  691.               handleDelete(gui, entries, activeEntry); break;
  692.             default :;
  693.          }
  694.          break;
  695.  
  696.     /*
  697.     ** These cases are related to the GetEntry window
  698.     */
  699.  
  700.        case ID_MA_GETENTRY :
  701.          openGetentryWindow(gui, entries);
  702.          break;
  703.        case ID_GE_OK :
  704.          addEntry(gui, entries);
  705.          break;
  706.        case ID_GE_REPLACE :
  707.          replaceEntry(gui, entries);
  708.          break;
  709.        case ID_GE_CLEAR :
  710.          clearGetentryGadgets(gui);
  711.          break;
  712.  
  713.     /*
  714.     ** These cases are related to the Automatic window
  715.     */
  716.  
  717.        case ID_MA_AUTO :
  718.          openAutomaticWindow(gui, entries);
  719.          break;
  720.        case ID_AU_NEW :
  721.          newAutomatic(gui, entries);
  722.          break;
  723.        case ID_AU_REPLACE :
  724.          replaceAutomatic(gui, entries);
  725.          break;
  726.        case ID_AU_ADD :
  727.          addAutomatic(gui, entries);
  728.          break;
  729.        case ID_AU_DELETE :
  730.          deleteAutomatic(gui, entries, NULL);
  731.          break;
  732.        case ID_AU_DOUBLECLICK :
  733.          DoMethod(gui -> auListviewObject, MUIM_List_GetEntry,
  734.                   MUIV_List_GetEntry_Active, & activeAutomatic);
  735.          editAutomatic(gui, activeAutomatic);
  736.      }
  737.  
  738.      if (signal) Wait(signal);
  739.    }
  740.  
  741.    set(gui -> mainWindowObject,MUIA_Window_Open,FALSE);
  742.  
  743.    fail(app,NULL);
  744.    return 0;
  745. }
  746.