home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / setcv / asetcv.cpp next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  8.2 KB  |  165 lines

  1. /******************************************************************************
  2. * .FILE:         asetcv.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Set Canvas Example:  Class Implementation                    *
  5. *                                                                             *
  6. * .CLASSES:      ASetCanvas                                                   *
  7. *                AButtonHandler                                               *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #include <ibase.hpp>
  26. #include <iapp.hpp>
  27. #include <ipoint.hpp>
  28. #include <istring.hpp>
  29. #include <icoordsy.hpp>
  30. #include "asetcv.h"
  31. #include "asetcv.hpp"
  32.  
  33. /******************************************************************************
  34. * main  - Application entry point                                             *
  35. ******************************************************************************/
  36. int main()
  37. {
  38.   ICoordinateSystem::setApplicationOrientation(
  39.           ICoordinateSystem::originLowerLeft );
  40.   ASetCanvas mainWindow(WND_MAIN);
  41.   IApplication::current().run();
  42.   return 0;
  43. } /* end main */
  44.  
  45. /******************************************************************************
  46. * ASetCanvas :: ASetCanvas - Constructor for our main window                  *
  47. ******************************************************************************/
  48. ASetCanvas::ASetCanvas(unsigned long windowId)
  49.   : IFrameWindow( windowId )
  50.   , clientCanvas( WND_SPLITCANVAS, this, this, IRectangle(),
  51.                   ISplitCanvas::horizontal | IWindow::visible )
  52.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  53.   , vSetCanvas( WND_VSETCANVAS, &clientCanvas, &clientCanvas )
  54.   , hSetCanvas( WND_HSETCANVAS, &clientCanvas, &clientCanvas )
  55.   , buttonHandler(&status)
  56. {
  57. /*-----------------------------------------------------------------------------|
  58. |  Set the icon for the main window and make the split canvas the client areas |
  59. ------------------------------------------------------------------------------*/
  60.   setIcon( id() );
  61.   setClient( &clientCanvas );
  62.  
  63. /*-----------------------------------------------------------------------------|
  64. |  Set the alignment of the static text in the status area to the center       |                                                                            |
  65. ------------------------------------------------------------------------------*/
  66.   status.setAlignment( IStaticText::centerCenter );
  67.  
  68. /*-----------------------------------------------------------------------------|
  69. |  Set the top canvas so that it has 3 vertical decks                          |
  70. ------------------------------------------------------------------------------*/
  71.   vSetCanvas.setDeckOrientation( ISetCanvas::vertical );
  72.   vSetCanvas.setDeckCount( 3 );
  73.  
  74. /*-----------------------------------------------------------------------------|
  75. | Set the bottom canvas so that it has 3 horizontal decks                      |
  76. ------------------------------------------------------------------------------*/
  77.   hSetCanvas.setDeckOrientation( ISetCanvas::horizontal );
  78.   hSetCanvas.setDeckCount( 3 );
  79.   hSetCanvas.setPad(ISize(10,10));
  80.  
  81. /*-----------------------------------------------------------------------------|
  82. |  Give the button handler the static text string.                             |
  83. ------------------------------------------------------------------------------*/
  84.   unsigned int i, mid = (NUMBER_OF_BUTTONS/2);
  85.  
  86. /*-----------------------------------------------------------------------------|
  87. |  Creates the first set of radio buttons, add the button to the handler,      |
  88. |    and sets the text of the radio button                                     |
  89. |  Sets the first button to the tabStop and Group Styles.                      |
  90. |  Selects the first button in the group.                                      |
  91. ------------------------------------------------------------------------------*/
  92.   for (i = 0 ; i < mid ; ++i)
  93.   {
  94.     radiobut[i] = new IRadioButton( WND_BUTTON + i, &vSetCanvas, &vSetCanvas );
  95.     buttonHandler.handleEventsFor( radiobut[i] );
  96.     radiobut[i]->setText( STR_TEXT + i );
  97.   }
  98.   radiobut[0]->enableGroup().enableTabStop();
  99.   radiobut[0]->select();
  100.  
  101. /*-----------------------------------------------------------------------------|
  102. |  Creates the second set of radio buttons, add the button to the handler,     |
  103. |    and sets the text of the radio button                                     |
  104. |  Sets the mid button to the tabStop and Group Styles.                        |
  105. |  Selects the first button in this group.                                     |
  106. ------------------------------------------------------------------------------*/
  107.   for (i = mid ; i < NUMBER_OF_BUTTONS ; ++i)
  108.   {
  109.     radiobut[i] = new IRadioButton( WND_BUTTON + i, &hSetCanvas, &hSetCanvas );
  110.     buttonHandler.handleEventsFor( radiobut[i] );
  111.     radiobut[i]->setText( STR_TEXT + i );
  112.   }
  113.   radiobut[mid]->enableGroup().enableTabStop();
  114.   radiobut[mid]->select();
  115.  
  116. /*-----------------------------------------------------------------------------|
  117. | Sets focus to the first button and sets the status string to text from       |
  118. |   resource file.                                                             |
  119. ------------------------------------------------------------------------------*/
  120.   radiobut[0]->setFocus();
  121.   status.setText( STR_STATUS );
  122.  
  123.   show();
  124.  
  125. } /* end ASetCanvas :: ASetCanvas(...) */
  126.  
  127. /******************************************************************************
  128. * ASetCanvas ::~ASetCanvas - Destructor for our main window                   *
  129. ******************************************************************************/
  130. ASetCanvas::~ASetCanvas()
  131. {
  132.   for (unsigned int i = 0; i < NUMBER_OF_BUTTONS ; ++i)
  133.   {
  134.     delete radiobut[i];
  135.   }
  136. }
  137.  
  138. /******************************************************************************
  139. * Class AButtonHandler::selected - displays the number of the button selected *
  140. *   in the status area.                                                       *
  141. ******************************************************************************/
  142.  
  143. IBase::Boolean AButtonHandler::selected(IControlEvent& evt )
  144. {
  145.   Boolean
  146.     fHandled = true;
  147.  
  148.   unsigned long
  149.     ulButtonId = evt.controlId();
  150.  
  151. /*----------------------------------------------------------------------------|
  152. |  If the id of the event is one of the buttons, then display the button      |
  153. |  number in the static text control                                          |
  154. -----------------------------------------------------------------------------*/
  155.   if ( ulButtonId >= WND_BUTTON &&
  156.        ulButtonId <= (WND_BUTTON+NUMBER_OF_BUTTONS) &&
  157.        output)
  158.     output->setText( IString( ulButtonId-WND_BUTTON+1 ) );
  159.   else
  160.      fHandled = false;                 // pass event to other handlers
  161.  
  162.   return fHandled;
  163.  
  164. } /* end AButtonHandler::selected(...) */
  165.