home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / PhClient / site.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-02  |  5.0 KB  |  170 lines  |  [TEXT/MPS ]

  1. /*_____________________________________________________________________
  2.  
  3.       site.c - Server Site Movable Modal Dialog.
  4.     
  5.     This movable modal dialog is used to select both the default server
  6.     site and the help server site.
  7. _____________________________________________________________________*/
  8.  
  9. #pragma load "precompile"
  10. #include "rez.h"
  11. #include "site.h"
  12. #include "utl.h"
  13. #include "glob.h"
  14. #include "oop.h"
  15. #include "wstm.h"
  16.  
  17. /*_____________________________________________________________________
  18.  
  19.     Global Variables.
  20. _____________________________________________________________________*/
  21.  
  22. static DialogPtr        Window;            /* ptr to dialog window */
  23. static Rect                PopupRect;        /* rectangle for popup menu */
  24. static short            CurSel;            /* currently selected popup menu item */
  25.  
  26. static oop_Dispatch dispatch = {
  27.                                 oop_DoPeriodic,
  28.                                 oop_DoClick,
  29.                                 site_DoKey,
  30.                                 oop_DoUpdate,
  31.                                 oop_DoActivate,
  32.                                 oop_DoDeactivate,
  33.                                 oop_DoGrow,
  34.                                 oop_DoZoom,
  35.                                 oop_DoClose,
  36.                                 oop_DoCommand
  37.                             };
  38.  
  39. /*_____________________________________________________________________
  40.  
  41.     site_DoKey - Process a Key Down Event.
  42.     
  43.     Entry:    w = pointer to window record.
  44.                 key = ascii code of key.
  45.                 modifiers = modifiers from event record.
  46. _____________________________________________________________________*/
  47.  
  48. void site_DoKey (WindowPtr w, char key, short modifiers)
  49.  
  50. {
  51.     if (!glob_FilterAsciiChar(w, key, modifiers)) return;
  52.     oop_DoKey(w, key, modifiers);
  53. }
  54.  
  55. /*_____________________________________________________________________
  56.  
  57.     DrawPopUp - Draw Popup Menu.
  58.     
  59.     Entry:    theWindow = pointer to dialog window.
  60.                 itemNo = item number of popup menu user item.
  61. _____________________________________________________________________*/
  62.  
  63. static pascal void DrawPopUp (WindowPtr theWindow, short itemNo)
  64.  
  65. {
  66. #pragma unused (theWindow, itemNo)
  67.  
  68.     if (!SiteMenu) return;
  69.     glob_DrawSitePopup(&PopupRect, CurSel);
  70. }
  71.  
  72. /*_____________________________________________________________________
  73.  
  74.     DoOne - Do One Server Dialog.
  75.     
  76.     Entry:    server = initial value for server domain name field.
  77.                 label1 = index in stringsID STR# resource of message to use
  78.                     if site list exists.
  79.                 label2 = index in stringsID STR# resource of message to use
  80.                     if site list does not exist.
  81.     
  82.     Exit:        function result = true if dialog canceled.
  83.                 server = new default server domain name.
  84. _____________________________________________________________________*/
  85.  
  86. Boolean DoOne (Str255 server, short label1, short label2)
  87.  
  88. {
  89.     short            itemType;    /* item type */
  90.     Handle        item;            /* handle to item */
  91.     Rect            box;            /* item rectangle */
  92.     Str255        label;        /* dialog label static text */
  93.     short            itemHit;        /* item hit */
  94.     short            menuWidth;    /* menu width */
  95.     short            newSel;        /* new index of server in menu */
  96.     Str255        newDomain;    /* new server domain name */
  97.  
  98.     ShowCursor();
  99.     Window = wstm_Restore(true, siteDlogID, nil, &SiteState);
  100.     utl_SetDialogText(Window, siteServField, server);
  101.     SelIText(Window, siteServField, 0, 0x7fff);
  102.     GetIndString(label, stringsID, SiteMenu ? label1 : label2);
  103.     utl_SetDialogText(Window, siteLabel, label);
  104.     GetDItem(Window, sitePopup, &itemType, &item, &PopupRect);
  105.     if (SiteMenu) {
  106.         CalcMenuSize(SiteMenu);
  107.         menuWidth = (**SiteMenu).menuWidth;
  108.         PopupRect.left = (Window->portRect.right - menuWidth) >> 1;
  109.         PopupRect.right = PopupRect.left + menuWidth;
  110.         CurSel = glob_GetSiteIndex(server);
  111.     }
  112.     SetDItem(Window, sitePopup, itemType, (Handle)DrawPopUp, &PopupRect);
  113.     SetPort(Window);
  114.     TextFont(0);
  115.     TextSize(12);
  116.     oop_NewDialog(Window, siteModal, nil, &dispatch, true, siteOK, siteCancel);
  117.     ShowWindow(Window);
  118.     while (true) {
  119.         oop_ClearWindItemHit(Window);
  120.         while (!(itemHit = oop_GetWindItemHit(Window)) && !Done) 
  121.             oop_DoEvent(nil, everyEvent, 
  122.                 oop_InForeground() ? shortSleep : longSleep, nil);
  123.         if (Done) itemHit = siteCancel;
  124.         if (itemHit == siteCancel) break;
  125.         if (itemHit == sitePopup && SiteMenu) {
  126.             glob_PopupSiteMenu(&PopupRect, CurSel, &newSel, &newDomain);
  127.             if (newSel == -1) continue;
  128.             CurSel = newSel;
  129.             utl_SetDialogText(Window, siteServField, newDomain);
  130.             SelIText(Window, siteServField, 0, 0x7fff);
  131.             InvalRect(&box);
  132.             continue;
  133.         }
  134.         break;
  135.     }
  136.     if (itemHit == siteOK) utl_GetDialogText(Window, siteServField, server);
  137.     wstm_Save(Window, &SiteState);
  138.     oop_DoClose(Window);
  139.     InitCursor();
  140.     return itemHit == siteCancel;
  141. }
  142.  
  143. /*_____________________________________________________________________
  144.  
  145.     site_DoDialog - Do Default Server Dialog.
  146.     
  147.     Entry:    server = initial value for server domain name field.
  148.                 label1 = index in stringsID STR# resource of message to use
  149.                     if site list exists.
  150.                 label2 = index in stringsID STR# resource of message to use
  151.                     if site list does not exist.
  152.     
  153.     Exit:        function result = true if dialog canceled.
  154.                 server = new default server domain name.
  155. _____________________________________________________________________*/
  156.  
  157. Boolean site_DoDialog (Str255 server, short label1, short label2)
  158.  
  159. {
  160.     while (true) {
  161.         if (DoOne(server, label1, label2)) return true;
  162.         if (!*server) {
  163.             glob_Error(servErrors, msgNoServer, nil);
  164.             continue;
  165.         }
  166.         break;
  167.     }
  168.     return false;
  169. }
  170.