home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / dflat5 / button.c < prev    next >
Text File  |  1991-06-27  |  2KB  |  69 lines

  1. /* -------------- button.c -------------- */
  2.  
  3. #include <conio.h>
  4. #include "dflat.h"
  5.  
  6. #ifdef INCLUDE_DIALOG_BOXES
  7.  
  8. int ButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  9. {
  10.     DBOX *db = GetParent(wnd)->extension;
  11.     CTLWINDOW *ct = ControlBox(db, wnd);
  12.     int x;
  13.     switch (msg)    {
  14.         case SETFOCUS:
  15.             BaseWndProc(BUTTON, wnd, msg, p1, p2);
  16.             /* ------- fall through ------- */
  17.         case PAINT:
  18.             if (isVisible(wnd))    {
  19.                 if (TestAttribute(wnd, SHADOW))    {
  20.                     /* -------- draw the button's shadow ------- */
  21.                     background = WndBackground(GetParent(wnd));
  22.                     foreground = BLACK;
  23.                     PutWindowChar(wnd, WindowWidth(wnd), 0, 220);
  24.                     for (x = 0; x < WindowWidth(wnd); x++)
  25.                         PutWindowChar(wnd, x+1, 1, 223);
  26.                 }
  27.                 /* --------- write the button's text ------- */
  28.                 WriteTextLine(wnd, NULL, 0, wnd == inFocus);
  29.             }
  30.             return TRUE;
  31.         case KEYBOARD:
  32. #ifdef INCLUDE_SYSTEM_MENUS
  33.             if (WindowMoving || WindowSizing)
  34.                 break;
  35. #endif
  36.             if (p1 != '\r')
  37.                 break;
  38.             /* ---- fall through ---- */
  39.         case LEFT_BUTTON:
  40. #ifdef PUSHBUTTON_DEPRESS
  41.             /* --------- draw a pushed button -------- */
  42.             background = WndBackground(GetParent(wnd));
  43.             foreground = WndBackground(wnd);
  44.             PutWindowChar(wnd, 0, 0, ' ');
  45.             for (x = 0; x < WindowWidth(wnd); x++)    {
  46.                 PutWindowChar(wnd, x+1, 0, 220);
  47.                 PutWindowChar(wnd, x+1, 1, 223);
  48.             }
  49.             if (msg == LEFT_BUTTON)
  50.                 SendMessage(NULLWND, WAITMOUSE, 0, 0);
  51.             else
  52.                 SendMessage(NULLWND, WAITKEYBOARD, 0, 0);
  53.             SendMessage(wnd, PAINT, 0, 0);
  54. #endif
  55.             if (ct->setting == ON)
  56.                 PostMessage(GetParent(wnd), COMMAND, ct->command, 0);
  57.             else
  58.                 beep();
  59.             return TRUE;
  60.         case HORIZSCROLL:
  61.             return TRUE;
  62.         default:
  63.             break;
  64.     }
  65.     return BaseWndProc(BUTTON, wnd, msg, p1, p2);
  66. }
  67.  
  68. #endif
  69.