home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 634.lha / ppdata_v1.0 / src.LZH / src / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-12  |  4.7 KB  |  176 lines

  1. /*
  2. *    display.c
  3. *
  4. *    NewMenus, NewWindow and WinTexts for ppdata v1.0,
  5. *    and routines for opening display.
  6. *
  7. *    MWS, 3/92.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <libraries/gadtools.h>
  13. #include <proto/gadtools.h>
  14. #include "wintext.h"
  15. #include "display.h"
  16.  
  17. static struct NewMenu mainitems[] = {
  18.     { NM_TITLE, "Project",    NULL, 0, 0, NULL },
  19.     { NM_ITEM,  "Load",    "L",  0, 0, NULL },
  20.     { NM_ITEM,  "Save",    "S",  0, 0, NULL },
  21.     { NM_ITEM,  "Batch",    NULL, 0, 0, NULL },
  22.     { NM_ITEM,  "Delete",    NULL, 0, 0, NULL },
  23.     { NM_ITEM,  "About",    NULL, 0, 0, NULL },
  24.     { NM_ITEM,  "Quit",    "Q",  0, 0, NULL },
  25.  
  26.     { NM_TITLE, "Prefs",    NULL, 0, 0, NULL },
  27.     { NM_ITEM,  "Color",    NULL,  0, 0, NULL },
  28.     { NM_SUB,   "Color 0",    NULL, CHECKIT, ~1, NULL },
  29.     { NM_SUB,   "Color 1",    NULL, CHECKIT, ~2, NULL },
  30.     { NM_SUB,   "Pointer",    NULL, CHECKIT, ~4, NULL },
  31.     { NM_SUB,   "Scroll",    NULL, CHECKIT, ~8, NULL },
  32.     { NM_SUB,   "None",    NULL, CHECKIT, ~16, NULL },
  33.  
  34.     { NM_ITEM,  "Efficiency",NULL,  0, 0, NULL },
  35.     { NM_SUB,   "Fast",    NULL, CHECKIT, ~1, NULL },
  36.     { NM_SUB,   "Mediocre",    NULL, CHECKIT, ~2, NULL },
  37.     { NM_SUB,   "Good",    NULL, CHECKIT, ~4, NULL },
  38.     { NM_SUB,   "Very Good",NULL, CHECKIT, ~8, NULL },
  39.     { NM_SUB,   "Best",    NULL, CHECKIT, ~16, NULL },
  40.  
  41.     { NM_ITEM,  "Speedup",    NULL,  0, 0, NULL },
  42.     { NM_SUB,   "Large",    NULL, CHECKIT, ~1, NULL },
  43.     { NM_SUB,   "Medium",    NULL, CHECKIT, ~2, NULL },
  44.     { NM_SUB,   "Small",    NULL, CHECKIT, ~4, NULL },
  45.  
  46.     { NM_ITEM,  "Suffix",    NULL,  MENUTOGGLE+CHECKIT, 0, NULL },
  47.     { NM_ITEM,  "Overwrite",NULL,  MENUTOGGLE+CHECKIT, 0, NULL },
  48.     { NM_ITEM,  "Save Prefs",NULL,  0, 0, NULL },
  49.  
  50.     { NM_TITLE, "Control",        NULL, 0, 0, NULL },
  51.     { NM_ITEM,  "Always decrunch",    NULL, CHECKIT, ~1, NULL },
  52.     { NM_ITEM,  "Always recrunch",    NULL, CHECKIT, ~2, NULL },
  53.     { NM_ITEM,  "Ignore crunched",    NULL, CHECKIT, ~4, NULL },
  54.     { NM_ITEM,  "Query decrunch",    NULL, CHECKIT, ~8, NULL },
  55.  
  56.     { NM_END }
  57. };
  58.  
  59. static struct NewMenu abortitems[] = {
  60.     { NM_TITLE, "Project",    NULL, 0, 0, NULL },
  61.     { NM_ITEM,  "Abort",    "A", 0, 0, NULL },
  62.     { NM_END }
  63. };
  64.  
  65. struct Menu *mainmenu, *abortmenu;
  66. static APTR vi;        /* visual info for gadtools */
  67.  
  68. struct NewWindow new_window = {
  69.   0,0,0,0,0,1,
  70.   CLOSEWINDOW+MENUPICK,
  71.   WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+NOCAREREFRESH+SMART_REFRESH+ACTIVATE,
  72.   NULL,NULL,
  73.   (UBYTE *)"PPData v1.0",NULL,NULL,
  74.   100,10,-1,-1,WBENCHSCREEN };
  75.  
  76. /***** not at moment - window redraw hassles
  77. WORD zipdata[4]; ****/
  78. struct TagItem window_tags[] = {
  79. /***    { WA_Zoom, (LONG)&zipdata[0] },***/
  80.     { TAG_DONE }
  81. };
  82.  
  83. struct Window *window;
  84. struct TextFont *font;
  85.  
  86. WINTEXTINFO    wtinfo;            /* to be initialised later */
  87. WINTEXT wt_initial[] = {
  88.     { &wt_initial[1], "File Name    :", 0, 0, 3, JAM1, -1 },
  89.     { &wt_initial[2], "File Length  :", 0, 1, 3, JAM1, -1 },
  90.     { NULL,          "(De)Crunched :", 0, 2, 3, JAM1, -1 }
  91. };
  92.  
  93. /********************* DISPLAY OPEN/CLOSE ROUTINES ****************************/
  94.  
  95. BOOL OpenDisplay()    /* alloc wintext memory, set zip window, open window */
  96. {
  97.     if (InitWinTextInfo(&wtinfo, &new_window, TEXT_ROWS, TEXT_COLUMNS))
  98.     {
  99. /****        zipdata[0] = new_window.LeftEdge;
  100.         zipdata[1] = new_window.TopEdge;
  101.         zipdata[2] = new_window.Width;
  102.         zipdata[3] = wtinfo.toffset - 1;
  103. ****/
  104.         if (window = OpenWindowTagList(&new_window, window_tags))
  105.         {
  106.             wtinfo.window = window;
  107.             if (font = OpenFont(wtinfo.tattr))
  108.             {
  109.                 SetFont(window->RPort, font);
  110.                 RenderWinTexts(&wtinfo, wt_initial);
  111.  
  112.                 return TRUE;
  113.             }
  114.             CloseWindow(window);
  115.         }
  116.         FinishWinText(&wtinfo);
  117.     }
  118.     return FALSE;
  119. }
  120.  
  121. void CloseDisplay()    /* free wintext memory, close window */
  122. {
  123.     CloseFont(font);
  124.     FinishWinText(&wtinfo);
  125.     CloseWindow(window);
  126. }
  127.  
  128.  
  129. /********************* ALLOCATION/DEALLOCATION ROUTINES ***********************/
  130.  
  131. /* static prototypes */
  132. static void ClearMsgPort(struct MsgPort *);
  133.  
  134. extern struct Window *window;
  135.  
  136.  
  137. static void ClearMsgPort(struct MsgPort *mp)    /* clear existing messages from */
  138. {                        /* message port (ignoring contents) */
  139.     struct Message *msg;
  140.  
  141.     while (msg = GetMsg(mp))
  142.         ReplyMsg(msg);
  143. }
  144.  
  145. void SetPPDataMenu(int which)        /* clear message port and set new menu */
  146. {
  147.     Forbid();
  148.         ClearMsgPort(window->UserPort);
  149.  
  150.         if (which == MAINMENU)
  151.             SetMenuStrip(window,mainmenu);
  152.         else /* which == ABORTMENU */
  153.             SetMenuStrip(window,abortmenu);
  154.     Permit();
  155. }
  156.  
  157. void FreePPDataMenus()            /* free all menustrips and related data */
  158. {
  159.     if (mainmenu)    FreeMenus(mainmenu);
  160.     if (abortmenu)    FreeMenus(abortmenu);
  161.     if (vi)        FreeVisualInfo(vi);
  162. }
  163.  
  164. BOOL AllocPPDataMenus()            /* allocate menustrips required by program */
  165. {
  166.     if ((mainmenu = CreateMenusA(mainitems, NULL)) &&
  167.         (abortmenu = CreateMenusA(abortitems, NULL)) &&
  168.         (vi = GetVisualInfoA(window->WScreen, NULL)) &&
  169.          (LayoutMenusA(mainmenu, vi, NULL)) &&
  170.         (LayoutMenusA(abortmenu, vi, NULL)))
  171.         return TRUE;
  172.  
  173.     FreePPDataMenus();    /* something failed... */
  174.     return FALSE;
  175. }
  176.