home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / TransSkel 3.18 / Demos / C Demos / Button / Document.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  3.0 KB  |  156 lines  |  [TEXT/KAHL]

  1. /*
  2.  * The stuff in this file presents a document window with an outlined
  3.  * pushbutton.  It demonstrates:
  4.  * - Button outlining in a document window.
  5.  *
  6.  * Note that button clicks are tracked and return/enter and escape/
  7.  * command-period keyclicks are mapped onto button clicks, but that no
  8.  * other action is associated with those clicks.  This window hander
  9.  * just shows the visible user interface stuff associated with those
  10.  * actions.
  11.  */
  12.  
  13. # include    "TransSkel.h"
  14.  
  15. # include    "Button.h"
  16.  
  17.  
  18. # define    returnKey    13
  19. # define    enterKey    3
  20. # define    escapeKey    27
  21.  
  22.  
  23. static WindowPtr        wind;
  24. static ControlHandle    okBtn;
  25. static ControlHandle    cancelBtn;
  26.  
  27.  
  28. static pascal void
  29. Mouse (Point pt, long t, short mods)
  30. {
  31. ControlHandle    ctrl;
  32. short    partNo;
  33.  
  34.     if ((partNo = FindControl (pt, wind, &ctrl)) != 0)
  35.     {
  36.         if (partNo == inButton)
  37.         {
  38.             if (TrackControl (ctrl, pt, nil))
  39.             {
  40.                 /* nothing done here */
  41.             }
  42.         }
  43.     }
  44. }
  45.  
  46.  
  47. /*
  48.  * Key handler.  Map return/enter onto clicks in OK button.
  49.  * Note that we check whether the OK button is active or not
  50.  * before flashing the button.  In this application the button
  51.  * is never inactive when the window is active, but that may not
  52.  * be generally true.
  53.  */
  54.  
  55. static pascal void
  56. Key (short c, short code, short mods)
  57. {
  58.     if (c == returnKey || c == enterKey)
  59.     {
  60.         if ((**okBtn).contrlHilite == normalHilite)
  61.             SkelFlashButton (okBtn);
  62.     }
  63.     else if (c == escapeKey || SkelCmdPeriod (SkelGetCurrentEvent ()))
  64.     {
  65.         if ((**cancelBtn).contrlHilite == normalHilite)
  66.             SkelFlashButton (cancelBtn);
  67.     }
  68. }
  69.  
  70.  
  71. /*
  72.  * Update the window.
  73.  */
  74.  
  75. static pascal void
  76. Update (Boolean resized)
  77. {
  78. WindowPtr    wind;
  79. Rect    r;
  80. short    h;
  81.  
  82.     GetPort (&wind);
  83.  
  84.     r = wind->portRect;
  85.     EraseRect (&r);
  86.     DrawControls (wind);
  87.     SkelDrawButtonOutline (okBtn);
  88. }
  89.  
  90.  
  91. /*
  92.  * Make the buttons active or inactive as the window becomes active or
  93.  * inactive.  Redraw default button outline to follow state of default
  94.  * button.
  95.  */
  96.  
  97. static pascal void
  98. Activate (Boolean active)
  99. {
  100. short    hilite;
  101.  
  102.     hilite = (active ? normalHilite : dimHilite);
  103.     HiliteControl (okBtn, hilite);
  104.     SkelDrawButtonOutline (okBtn);
  105.     HiliteControl (cancelBtn, hilite);
  106. }
  107.  
  108.  
  109. static pascal void
  110. Clobber (void)
  111. {
  112. WindowPtr    wind;
  113.  
  114.     GetPort (&wind);
  115.     HideWindow (wind);
  116.     DisposeWindow (wind);
  117. }
  118.  
  119.  
  120. /*
  121.  * Initialize document window
  122.  */
  123.  
  124. void
  125. SetupDocument (void)
  126. {
  127. Rect    r;
  128.  
  129.     if (SkelQuery (skelQHasColorQD))
  130.         wind = GetNewCWindow (docWindRes, nil, (WindowPtr) -1L);
  131.     else
  132.         wind = GetNewWindow (docWindRes, nil, (WindowPtr) -1L);
  133.     if (wind == (WindowPtr) nil)
  134.     {
  135.         SysBeep (1);
  136.         return;
  137.     }
  138.     SkelWindow (wind,
  139.                 Mouse,
  140.                 Key,
  141.                 Update,
  142.                 Activate,
  143.                 nil,            /* no close box, so no close handler */
  144.                 Clobber,
  145.                 nil,            /* no idle handler */
  146.                 true);            /* irrelevant since no idle handler */
  147.  
  148.     SetRect (&r, 10, 20, 80, 40);
  149.     cancelBtn = NewControl (wind, &r, "\pCancel", true, 0, 0, 1, pushButProc, 0L);
  150.     OffsetRect (&r, 80, 0);
  151.     okBtn = NewControl (wind, &r, "\pOK", true, 0, 0, 1, pushButProc, 0L);
  152.  
  153.     ShowWindow (wind);
  154.     SkelDoEvents (activMask + updateMask);
  155. }
  156.