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

  1. //************************************************************
  2. // Controls - Constructor and color example
  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 <iapp.hpp>
  9. #include <icolor.hpp>
  10. #include <icombobx.hpp>
  11. #include <ientryfd.hpp>
  12. #include <iframe.hpp>
  13. #include <ihandle.hpp>
  14. #include <imcelcv.hpp>
  15. #include <ispintxt.hpp>
  16. #include <istattxt.hpp>
  17. #include <icconst.h>
  18.  
  19. #ifdef IC_PM
  20.   #define ID_COMBOBOX_EF  0x029B  // CBID_EDIT from pmwin.h.
  21. #else // IC_WIN
  22.   #define ID_COMBOBOX_EF  0x03E9
  23. #endif
  24.  
  25. void main ( )
  26. {
  27.   // Create a frame window with a spin button and combo
  28.   // box on a multicell canvas client window.
  29.   IFrameWindow
  30.     frame( "Control Constructor and Color Example" );
  31.   IMultiCellCanvas
  32.     client( IC_FRAME_CLIENT_ID, &frame, &frame );
  33.  
  34.   // Set up the spin button and its text label.
  35.   IStaticText
  36.     spinText( 100, &client, &client );
  37.   spinText
  38.    .setAlignment( IStaticText::centerLeft )
  39.    .setText( "Spin button with a cyan entry field" );
  40.  
  41.   ITextSpinButton
  42.     spin( 110, &client, &client, IRectangle(),
  43.           ITextSpinButton::classDefaultStyle
  44.            | IControl::tabStop
  45.            | IControl::group );
  46.   spin
  47.    .addAsFirst( "First entry" )
  48.    .addAsLast( "Second entry" )
  49.    .addAsLast( "Third entry" );
  50.  
  51.   // Set up the combo box and its text label.
  52.   IStaticText
  53.     comboText( 200, &client, &client );
  54.   comboText
  55.    .setAlignment( IStaticText::centerLeft )
  56.    .setText( "Combo box with an orange entry field" );
  57.  
  58.   IComboBox
  59.     combo( 210, &client, &client, IRectangle(),
  60.            ( IComboBox::classDefaultStyle
  61.                & ~IComboBox::simpleType )
  62.              | IComboBox::dropDownType
  63.              | IControl::tabStop
  64.              | IControl::group );
  65.   combo
  66.    .addAsFirst( "First entry" );
  67.   combo
  68.    .addAsLast ( "Second entry" );
  69.   combo
  70.    .addAsLast ( "Third entry" );
  71.  
  72.   // Construct an IEntryField for the existing window, the
  73.   // child window of the spin button.  Find it based on its
  74.   // window identifier after first checking for an existing
  75.   // IWindow object.
  76.   IEntryField
  77.    *spinEF = (IEntryField*)
  78.                 IWindow::windowWithParent( spin.id(), &spin );
  79.   if ( ! spinEF )
  80.   {  // No existing window object.
  81.      // Construct a new one.
  82.      spinEF = new IEntryField( spin.id(), &spin );
  83.      spinEF->setAutoDeleteObject( true );
  84.   }
  85.  
  86.   if ( spinEF )
  87.   {  // Now change its background color.
  88.      // Note: For a window to retain a color change on the
  89.      // Windows operating system, Open Class Library requires
  90.      // that an IWindow object exist for the window for as long
  91.      // as the color change is needed.  As a result, we keep
  92.      // the IEntryField wrapper until the edit control is
  93.      // destroyed.  We let Open Class Library manage the
  94.      // deletion of the IEntryField* for us.
  95.      // For the OS/2 operating system, we could simply delete
  96.      // the IEntryField* immediately after changing the edit
  97.      // control's color.
  98.      spinEF->setBackgroundColor( IColor::cyan );
  99.   }
  100.  
  101.   // Construct an IEntryField for the existing window, the
  102.   // child entry field of the combo box.  Find it based on its
  103.   // window handle after first checking for an existing
  104.   // IWindow object.
  105.   IEntryField
  106.    *comboEF = 0;
  107.   IWindowHandle comboEFHwnd =
  108.     IWindow::handleWithParent( ID_COMBOBOX_EF, combo.handle() );
  109.   if ( comboEFHwnd )
  110.   {
  111.      // Note: In the Windows operating system, CBS_DROPDOWNLIST
  112.      // type combo boxes do not have a child entry field.
  113.      comboEF = (IEntryField*)
  114.                   IWindow::windowWithHandle( comboEFHwnd );
  115.      if ( ! comboEF )
  116.      {  // No existing window object.
  117.         // Construct a new one.
  118.         comboEF = new IEntryField( comboEFHwnd );
  119.         comboEF->setAutoDeleteObject( true );
  120.      }
  121.   }                // Else use the existing window object.
  122.  
  123.   if ( comboEF )
  124.   {  // Now change its background color.
  125.      // Note: For a window to retain a color change on the
  126.      // Windows operating system, Open Class Library requires
  127.      // that an IWindow object exist for the window for as long
  128.      // as the color change is needed.  As a result, we keep
  129.      // the IEntryField wrapper until the edit control is
  130.      // destroyed.  We let Open Class Library manage the
  131.      // deletion of the IEntryField* for us.
  132.      // For the OS/2 operating system, we could simply delete
  133.      // the IEntryField* immediately after changing the edit
  134.      // control's color.
  135.      comboEF->setBackgroundColor( IColor( 255, 127, 0 ) );
  136.   }
  137.  
  138.   // Finish building the window and show it.
  139.   client
  140.    .addToCell( &spinText,  2, 2 )
  141.    .addToCell( &spin,      4, 2 )
  142.    .addToCell( &comboText, 2, 4 )
  143.    .addToCell( &combo,     4, 4 )
  144.    .setColumnWidth( 5, IMultiCellCanvas::defaultCell().width() )
  145.    .setRowHeight( 5, IMultiCellCanvas::defaultCell().height() );
  146.   frame
  147.    .setClient( &client )
  148.    .moveSizeToClient( IRectangle( IPoint( 50, 100 ),
  149.                                   client.minimumSize() ) )
  150.    .setFocus()
  151.    .show();
  152.  
  153.   // Start event processing.
  154.   IApplication::current().run();
  155. }
  156.