home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / advframe / fstyle / fstyle.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.6 KB  |  124 lines

  1. //************************************************************
  2. // Advanced Frame Window - Frame Style Test
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <istring.hpp>
  9. #include <iframe.hpp>
  10. #include <istattxt.hpp>
  11. #include <iexcept.hpp>
  12. #include <ifont.hpp>
  13. #include <icmdhdr.hpp>
  14. #include <icconst.h>
  15.  
  16. // Simple handler used to demonstrate
  17. // that accelerator keys are working.
  18. class CmdHandler : public ICommandHandler {
  19. public:
  20.   CmdHandler ( IStaticText &txt )
  21.     : text( txt )
  22.     {
  23.     }
  24. virtual Boolean
  25.   command ( ICommandEvent &event )
  26.     {
  27.     text.setText( IString( event.commandId() ) );
  28.     return true;
  29.     }
  30. private:
  31. IStaticText
  32.  &text;
  33. CmdHandler(const CmdHandler&);
  34. CmdHandler& operator=(const CmdHandler&);
  35. };
  36.  
  37. // Array of "option" mnemonics.
  38. const char
  39.  *options[] =
  40.     { "acc*",   "*adj*",
  41.       "ani*",   "*db*",
  42.       "bor*",   "def*",
  43.       "*backg*","d*l*g*",
  44.       "hid*",   "hor*",
  45.       "*xb*",   "max*",
  46.       "men*",   "*nb*",
  47.       "min*",   "*ico*",
  48.       "*own*",  "*pos*",
  49.       "siz*",   "*modal",
  50.       "sys*",   "tit*",
  51.       "vert*",  "win*" };
  52.  
  53. // Corresponding IFrameWindow::Styles.
  54. IFrameWindow::Style
  55.   styles[] =
  56.     { IFrameWindow::accelerator,   IFrameWindow::alignNoAdjust,
  57.       IFrameWindow::animated,      IFrameWindow::appDBCSStatus,
  58.       IFrameWindow::border,        IFrameWindow::classDefaultStyle,
  59.       IFrameWindow::dialogBackground, IFrameWindow::dialogBorder,
  60.       IFrameWindow::hideButton,    IFrameWindow::horizontalScroll,
  61.       IFrameWindow::maximizeButton,IFrameWindow::maximized,
  62.       IFrameWindow::menuBar,       IFrameWindow::minimizeButton,
  63.       IFrameWindow::minimized,     IFrameWindow::minimizedIcon,
  64.       IFrameWindow::noMoveWithOwner, IFrameWindow::shellPosition,
  65.       IFrameWindow::sizingBorder,  IFrameWindow::systemModal,
  66.       IFrameWindow::systemMenu,    IFrameWindow::titleBar,
  67.       IFrameWindow::verticalScroll,IFrameWindow::windowList };
  68.  
  69. void main( int argc, char *argv[] )
  70.   {
  71.   // Start with empty style.
  72.   IFrameWindow::Style
  73.     style = IWindow::noStyle;
  74.   // Use the default if the user specifies no options.
  75.   if ( argc == 1 )
  76.     style = IFrameWindow::classDefaultStyle;
  77.   else
  78.     {
  79.     int
  80.       n = sizeof options / sizeof options[0];
  81.     // Examine each command line options.
  82.     for ( int i = 1; i < argc; i++ )
  83.       {
  84.       // Get the next option.
  85.       IString
  86.         opt( argv[ i ] );
  87.       Boolean
  88.         not = ( opt[1] == '~' );
  89.       opt.stripLeading( '~' );
  90.       // Check against the array of mnemonics.
  91.       for ( int j = 0; j < n; j++ )
  92.         {
  93.         // Turn the corresponding style bit on or off.
  94.         if ( opt.isLike( options[j] ) )
  95.           {
  96.           if ( not )
  97.             style &= ~styles[ j ];
  98.           else
  99.             style |= styles[ j ];
  100.           break;
  101.           }
  102.         }
  103.       }
  104.     }
  105.   // Put the style (in hex) on the title bar.
  106.   IString
  107.     title( &style, sizeof style );
  108.   title.c2x();
  109.   // Construct the frame window with this style.
  110.   IFrameWindow
  111.     frame( title, IC_DEFAULT_FRAME_ID, style );
  112.   // Set up the handler and client window.
  113.   IStaticText
  114.     text( IC_FRAME_CLIENT_ID, &frame, &frame );
  115.   CmdHandler
  116.     cmdHandler( text );
  117.   cmdHandler.handleEventsFor( &frame );
  118.   text
  119.     .setAlignment( IStaticText::centerCenter )
  120.     .setFont( IFont( "Times Roman", 72 ) );
  121.   // Show the window.
  122.   frame.setClient( &text ).showModally();
  123.   }
  124.