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

  1. /******************************************************************************
  2. * .FILE:         amcelcv.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION:  Canvas Classes Example 3 - Multi Cell Canvas                 *
  5. *                                                                             *
  6. * .CLASSES:      APushButtonHandler                                           *
  7. *                AMultiCellCanvas                                             *
  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 <imsgbox.hpp>
  28. #include <istring.hpp>
  29. #include <ireslib.hpp>
  30. #include <icoordsy.hpp>
  31. #include "amcelcv.h"
  32. #include "amcelcv.hpp"
  33.  
  34. /******************************************************************************/
  35. /* main  - Application entry point                                            */
  36. /******************************************************************************/
  37. int main()
  38. {
  39.   ICoordinateSystem::setApplicationOrientation(
  40.           ICoordinateSystem::originLowerLeft );
  41.   AMultiCellCanvas mainWindow(WND_MAIN);
  42.   IApplication::current().run();
  43.   return 0;
  44. } /* end main */
  45.  
  46. /******************************************************************************
  47. * Class AMultiCellCanvas :: AMultiCellCanvas - Constructor for  main window   *
  48. *                                                                             *
  49. * Defines itself as an IFrameWindow.                                          *
  50. * Create a multicell canvas to layout the controls.                           *
  51. * Create the two title strings of text.                                       *
  52. * Create the two check boxes.                                                 *
  53. * Create the two radio buttons.                                               *
  54. ******************************************************************************/
  55. AMultiCellCanvas::AMultiCellCanvas(unsigned long windowId)
  56.   : IFrameWindow(windowId)
  57.   , clientCanvas( WND_MCCANVAS, this, this )
  58.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  59.   , title1( WND_TITLE1, &clientCanvas, &clientCanvas )
  60.   , title2( WND_TITLE2, &clientCanvas, &clientCanvas )
  61.   , check1( WND_CHECK1, &clientCanvas, &clientCanvas )
  62.   , check2( WND_CHECK2, &clientCanvas, &clientCanvas )
  63.   , radio1( WND_RADIO1, &clientCanvas, &clientCanvas )
  64.   , radio2( WND_RADIO2, &clientCanvas, &clientCanvas )
  65.   , pushButton( WND_PUSHBUT, &clientCanvas, &clientCanvas )
  66. {
  67. /*----------------------------------------------------------------------------|
  68. | Set the icon and the multi cell client canvas.                              |
  69. -----------------------------------------------------------------------------*/
  70.   setIcon( id() );
  71.   setClient( &clientCanvas );
  72.  
  73. /*----------------------------------------------------------------------------|
  74. | Set the text and it attributes for the titles and the status area.          |
  75. -----------------------------------------------------------------------------*/
  76.   status.setAlignment( IStaticText::centerCenter );
  77.   status.setText( STR_STATUS );
  78.  
  79.   title1.setAlignment( IStaticText::centerLeft );
  80.   title1.setText( STR_TITLE1 );
  81.  
  82.   title2.setAlignment( IStaticText::centerLeft );
  83.   title2.setText( STR_TITLE2 );
  84.  
  85. /*----------------------------------------------------------------------------|
  86. | Set the text for the check boxes, the radio buttons, and the push button.   |
  87. -----------------------------------------------------------------------------*/
  88.   check1.setText( STR_CHECK1 );
  89.   check2.setText( STR_CHECK2 );
  90.   radio1.setText( STR_RADIO1 );
  91.   radio2.setText( STR_RADIO2 );
  92.   pushButton.setText( STR_PUSHBUT );
  93.  
  94. /*----------------------------------------------------------------------------|
  95. | Preselect one radio button.                                                 |
  96. | Set tabstops and group styles.                                              |
  97. | Initialize the push button handler                                          |
  98. |
  99. -----------------------------------------------------------------------------*/
  100.   radio1.select();
  101.   check1.enableGroup().enableTabStop();
  102.   radio1.enableGroup().enableTabStop();
  103.   pushButton.enableGroup().enableTabStop();
  104.   pushButtonHandler.setOwnerWindow(this);
  105.   pushButtonHandler.handleEventsFor(&clientCanvas);
  106.  
  107. /*----------------------------------------------------------------------------|
  108. | Place controls into cells on the multicell canvas and configure size        |
  109. |   of cells.                                                                 |
  110. -----------------------------------------------------------------------------*/
  111.   clientCanvas.addToCell(&status  , 1, 1, 4, 1);
  112.   clientCanvas.addToCell(&title1  , 1, 3, 2, 1);
  113.   clientCanvas.addToCell(&title2  , 3, 3, 2, 1);
  114.   clientCanvas.addToCell(&check1  , 2, 4);
  115.   clientCanvas.addToCell(&check2  , 2, 5);
  116.   clientCanvas.addToCell(&radio1  , 4, 4);
  117.   clientCanvas.addToCell(&radio2  , 4, 5);
  118.   clientCanvas.addToCell(&pushButton , 2, 7);
  119.  
  120.   clientCanvas.setRowHeight(2, 20, true);
  121.   clientCanvas.setRowHeight(6, 40);
  122.   clientCanvas.setColumnWidth(4, 40, true);
  123.  
  124. /*----------------------------------------------------------------------------|
  125. | Set focus to the first check box and show the main window.                  |
  126. -----------------------------------------------------------------------------*/
  127.   check1.setFocus();
  128.   show();
  129.  
  130. } /* end AMultiCellCanvas :: AMultiCellCanvas(...) */
  131.  
  132. /******************************************************************************
  133. * Class AMultiCellCanvas :: displayButtonStatus - display a message box       *
  134. ******************************************************************************/
  135. AMultiCellCanvas& AMultiCellCanvas::displayButtonStatus()
  136. {
  137.   unsigned long str_id1, str_id2, str_id3;
  138.   IMessageBox msgbox(this);
  139.   IResourceLibrary  reslib = IApplication::current().userResourceLibrary();
  140.   msgbox.setTitle( IResourceId(STR_MSGBOX) );
  141.   str_id1 = check1.isSelected() ? STR_CHK1_SEL : STR_CHK1_NOSEL;
  142.   str_id2 = check2.isSelected() ? STR_CHK2_SEL : STR_CHK2_NOSEL;
  143.   IString  str1 = reslib.loadString(str_id1),
  144.            str2 = reslib.loadString(str_id2),
  145.            str3 = reslib.loadString( radio1.selectedIndex() + STR_RAD1_SEL );
  146.  
  147.   str1 += str2 + str3;
  148.   msgbox.show( (char *)str1 , IMessageBox::okButton         |
  149.                               IMessageBox::informationIcon  |
  150.                               IMessageBox::applicationModal |
  151.                               IMessageBox::moveable         );
  152.   return *this;
  153. }
  154.  
  155. /*****************************************************************************
  156. * Class APushButtonHandler :: command - handle some command events           *
  157. *****************************************************************************/
  158. IBase::Boolean APushButtonHandler::command( ICommandEvent& evt )
  159. {
  160.   Boolean fProcessed = false;
  161.  
  162.   if (evt.commandId() == WND_PUSHBUT && window)
  163.   {
  164.     window->displayButtonStatus();
  165.     fProcessed = true;
  166.   }
  167.   return fProcessed;
  168. }
  169.