home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / C Demos / Button / Dialog1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-15  |  2.1 KB  |  87 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Dialog 1
  3.  *
  4.  * This dialog consists of an OK button that's always the default button,
  5.  * a Cancel button, an edittext item, and a user item that's used for
  6.  * drawing the outline around the default button.
  7.  *
  8.  * The dialog arranges that the OK button is active only when there is text
  9.  * in the edittext item.  The Cancel button is always active so the user
  10.  * can get out of the dialog even when there's no text in the edittext item.
  11.  *
  12.  * This dialog demonstrates:
  13.  * - How to install an outliner for the default item, where the default is
  14.  * the button that's specified in the dialog template as the default.
  15.  * - How to make sure the outline is redrawn properly when the hiliting
  16.  * state of the outlined button changes.
  17.  */
  18.  
  19. # include    "TransSkel.h"
  20.  
  21. # include    "Button.h"
  22.  
  23.  
  24. typedef enum
  25. {
  26.     iOK = 1,
  27.     iCancel,
  28.     iEditText,
  29.     iOutline
  30. };
  31.  
  32.  
  33.  
  34. void
  35. DoDialog1 (void)
  36. {
  37. ModalFilterProcPtr    filter;
  38. DialogPtr    dlog;
  39. GrafPtr    savePort;
  40. short    item;
  41. Str255    str;
  42.  
  43.     dlog = GetNewDialog (dlog1Res, nil, (WindowPtr) -1L);
  44.     if (dlog == (DialogPtr) nil)
  45.     {
  46.         SysBeep (1);
  47.         return;
  48.     }
  49.  
  50.     SkelPositionWindow (dlog, skelPositionOnMainDevice, horizRatio, vertRatio);
  51.  
  52.     GetPort (&savePort);
  53.     SetPort (dlog);
  54.  
  55.     SkelSetDlogButtonOutliner (dlog, iOutline);
  56.     SkelSetDlogStr (dlog, iEditText,
  57.         "\pDefault button is active only when this field is non-empty");
  58.     SelIText (dlog, iEditText, 0, 32767);
  59.  
  60.     ShowWindow (dlog);
  61.  
  62.     for (;;)
  63.     {
  64.         /*
  65.          * Tell the standard filter to map return/enter to the default
  66.          * item (iOK).  Also map escape/command-period to Cancel.
  67.          */
  68.         filter = SkelDlogFilter (nil, true);
  69.         SkelDlogCancelItem (iCancel);
  70.         ModalDialog (filter, &item);
  71.         SkelRmveDlogFilter ();
  72.         if (item == iOK || item == iCancel)
  73.             break;
  74.  
  75.         /*
  76.          * Set hiliting of default button according to whether or not
  77.          * the edittext item now has anything in it.  If hiliting changes,
  78.          * redraw outline.
  79.          */
  80.         SkelGetDlogStr (dlog, iEditText, str);
  81.         if (SkelSetDlogCtlHilite (dlog, iOK, str[0] > 0 ? normalHilite : dimHilite))
  82.             SkelDrawButtonOutline (SkelGetDlogCtl (dlog, iOK));
  83.     }
  84.     DisposeDialog (dlog);
  85.     SetPort (savePort);
  86. }
  87.