home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / DIALOG.CPP < prev    next >
C/C++ Source or Header  |  1993-09-14  |  2KB  |  106 lines

  1. // ------------- dialog.cpp
  2.  
  3. #include <ctype.h>
  4. #include "dialog.h"
  5. #include "desktop.h"
  6.  
  7. static Color col = {
  8.     LIGHTGRAY,BLUE,
  9.     LIGHTGRAY,BLUE,
  10.     LIGHTGRAY,BLUE,
  11.     LIGHTGRAY,BLUE
  12. };
  13.  
  14. // ----------- common constructor code
  15. void Dialog::OpenWindow()
  16. {
  17.     windowtype = DialogWindow;
  18.     DblBorder = False;
  19.     SetAttribute(BORDER | SAVESELF | CONTROLBOX |
  20.         MOVEABLE | SHADOW);
  21.     colors = col;
  22.     isRunning = False;
  23.     okexit = False;
  24. }
  25.  
  26. void Dialog::CloseWindow()
  27. {
  28.     DFWindow::CloseWindow();
  29.     isRunning = False;
  30. }
  31.  
  32. void Dialog::Keyboard(int key)
  33. {
  34.     switch (key)    {
  35.         case ESC:
  36.             CancelFunction();
  37.             break;
  38.         case '\r':
  39.             OKFunction();
  40.             break;
  41.         case ALT_F4:
  42.             CloseWindow();
  43.             break;
  44.         case ' ':
  45.             if ((desktop.keyboard().GetShift() & ALTKEY) == 0)
  46.                 break;
  47.             // ---- fall through
  48.         case ALT_F6:
  49.             DFWindow::Keyboard(key);
  50.             break;
  51.         default:
  52.             if ((desktop.keyboard().GetShift() & ALTKEY) != 0)
  53.                 TestShortcut(key);
  54.             break;
  55.     }
  56. }
  57.  
  58. void Dialog::TestShortcut(int key)
  59. {
  60.     key = desktop.keyboard().AltConvert(key);
  61.     key = tolower(key);
  62.     Control *Ctl = (Control *)First();
  63.     while (Ctl != 0)    {
  64.         if (key == Ctl->Shortcut())    {
  65.             Ctl->ShortcutSelect();
  66.             break;
  67.         }
  68.         Ctl = (Control *) Ctl->Next();
  69.     }
  70. }
  71.  
  72. void Dialog::Execute()
  73. {
  74.     CaptureFocus();
  75.     Control *Ctl = (Control *) First();
  76.     while (Ctl != 0)    {
  77.         if (Ctl->isEnabled())    {
  78.             Ctl->SetFocus();
  79.             break;
  80.         }
  81.         Ctl = (Control *) Ctl->Next();
  82.     }
  83.  
  84.     // ---- modal dialog box
  85.     isRunning = True;
  86.     while (isRunning)
  87.         desktop.DispatchEvents();
  88. }
  89.  
  90. void Dialog::OKFunction()
  91. {
  92.     okexit = True;
  93.     CloseWindow();
  94. }
  95.  
  96. void Dialog::CancelFunction()
  97. {
  98.     CloseWindow();
  99. }
  100.  
  101. void Dialog::HelpFunction()
  102. {
  103. }
  104.  
  105.  
  106.