home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / src / TDialog.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  3KB  |  114 lines

  1. /*
  2.  * TDialog.cc
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #define Uses_TKeys
  13. #define Uses_TDialog
  14. #define Uses_TEvent
  15. #include <tvision/tv.h>
  16.  
  17. // TMultiCheckboxes flags
  18. //   hibyte = number of bits
  19. //   lobyte = bit mask
  20.  
  21.  
  22. TDialog::TDialog( const TRect& bounds, const char *aTitle ) :
  23.     TWindow( bounds, aTitle, wnNoNumber ),
  24.     TWindowInit( &TDialog::initFrame )
  25. {
  26.    growMode = 0;
  27.    flags = wfMove | wfClose;
  28.    palette = dpGrayDialog;
  29. }
  30.  
  31. TPalette& TDialog::getPalette() const
  32. {
  33.     static TPalette paletteGray( cpGrayDialog, sizeof( cpGrayDialog )-1 );
  34.     static TPalette paletteBlue( cpBlueDialog, sizeof( cpBlueDialog )-1 );
  35.     static TPalette paletteCyan( cpCyanDialog, sizeof( cpCyanDialog )-1 );
  36.  
  37.     switch (palette)
  38.     {
  39.        case dpGrayDialog:
  40.           return paletteGray;
  41.        case dpBlueDialog:
  42.           return paletteBlue;
  43.        case dpCyanDialog:
  44.           return paletteCyan;
  45.     }
  46.     return paletteGray;
  47. }
  48.  
  49. void TDialog::handleEvent(TEvent& event)
  50. {
  51.     TWindow::handleEvent(event);
  52.     switch (event.what)
  53.         {
  54.         case evKeyDown:
  55.             switch (event.keyDown.keyCode)
  56.                 {
  57.                 case kbEsc:
  58.                     event.what = evCommand;
  59.                     event.message.command = cmCancel;
  60.                     event.message.infoPtr = 0;
  61.                     putEvent(event);
  62.                     clearEvent(event);
  63.                     break;
  64.                 case kbEnter:
  65.                     event.what = evBroadcast;
  66.                     event.message.command = cmDefault;
  67.                     event.message.infoPtr = 0;
  68.                     putEvent(event);
  69.                     clearEvent(event);
  70.                     break;
  71.                 }
  72.             break;
  73.  
  74.         case evCommand:
  75.             switch( event.message.command )
  76.                 {
  77.                 case cmOK:
  78.                 case cmCancel:
  79.                 case cmYes:
  80.                 case cmNo:
  81.                     if( (state & sfModal) != 0 )
  82.                         {
  83.                         endModal(event.message.command);
  84.                         clearEvent(event);
  85.                         }
  86.                     break;
  87.                 }
  88.             break;
  89.         }
  90. }
  91.  
  92. Boolean TDialog::valid( ushort command )
  93. {
  94.     if( command == cmCancel )
  95.         return True;
  96.     else
  97.         return TGroup::valid( command );
  98. }
  99.  
  100. #if !defined(NO_STREAMABLE)
  101.  
  102. TStreamable *TDialog::build()
  103. {
  104.     return new TDialog( streamableInit );
  105. }
  106.  
  107. TDialog::TDialog( StreamableInit ) :
  108.     TWindow( streamableInit ),
  109.     TWindowInit( 0 )
  110. {
  111. }
  112.  
  113. #endif
  114.