home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / MCELCV / AMCELCV.CPP next >
Text File  |  1995-05-01  |  8KB  |  151 lines

  1. /******************************************************************************/
  2. /* Canvas Classes Example 3 - Multi Cell Canvas                               */
  3. /*                                                                            */
  4. /* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1993. */
  5. /*                                                                            */
  6. /* DISCLAIMER OF WARRANTIES:                                                  */
  7. /*   The following [enclosed] code is sample code created by IBM              */
  8. /*   Corporation.  This sample code is not part of any standard IBM product   */
  9. /*   and is provided to you solely for the purpose of assisting you in the    */
  10. /*   development of your applications.  The code is provided "AS IS",         */
  11. /*   without warranty of any kind.  IBM shall not be liable for any damages   */
  12. /*   arising out of your use of the sample code, even if they have been       */
  13. /*   advised of the possibility of such damages.                              */
  14. /******************************************************************************/
  15. /* NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          */
  16. /******************************************************************************/
  17. /* Canvas Classes Example 3 - Multi Cell Canvas                               */
  18. /*   key functions:                                                           */
  19. /*      - create a main window                                                */
  20. /*      - run the current application                                         */
  21. /*      - create a multi cell canvas and use as client area                   */
  22. /*           canvas has 4 columns and 7 rows                                  */
  23. /*           one row and one column are expandable                            */
  24. /*           all other controls attached to canvas                            */
  25. /*      - create static text controls                                         */
  26. /*      - create check boxes, radio buttons and push buttons                  */
  27. /*      - control cursor and tab movement between different groups            */
  28. /*      - process 'Command' events generated by the push button               */
  29. /*      - load strings from resource bound to the exe                         */
  30. /******************************************************************************/
  31.                                         //Include IBM UI class headers:
  32. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  33.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  34. #endif                                  //  is defined.
  35. #include <iapp.hpp>                     // IApplication
  36. #include <imsgbox.hpp>                  // IMessageBox
  37. #include <istring.hpp>                  // IString
  38. #include <ireslib.hpp>                  // IResourceId
  39.  
  40. #include "amcelcv.h"
  41. #include "amcelcv.hpp"
  42.  
  43. /******************************************************************************/
  44. /* main  - Application entry point                                            */
  45. /******************************************************************************/
  46. int main()
  47. {
  48.   AMultiCellCanvas mainWindow(WND_MAIN);
  49.   IApplication::current().run();
  50.   return 0;
  51. } /* end main */
  52.  
  53. /******************************************************************************/
  54. /* AMultiCellCanvas :: AMultiCellCanvas - Constructor for our main window     */
  55. /******************************************************************************/
  56. AMultiCellCanvas::AMultiCellCanvas(unsigned long windowId)
  57.   : IFrameWindow(windowId)
  58.   , clientCanvas( WND_MCCANVAS, this, this )
  59.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  60.   , title1( WND_TITLE1, &clientCanvas, &clientCanvas )
  61.   , title2( WND_TITLE2, &clientCanvas, &clientCanvas )
  62.   , check1( WND_CHECK1, &clientCanvas, &clientCanvas )
  63.   , check2( WND_CHECK2, &clientCanvas, &clientCanvas )
  64.   , radio1( WND_RADIO1, &clientCanvas, &clientCanvas )
  65.   , radio2( WND_RADIO2, &clientCanvas, &clientCanvas )
  66.   , pushButton( WND_PUSHBUT, &clientCanvas, &clientCanvas )
  67. {
  68.                                        // Set the icon
  69.   setIcon( id() );
  70.                                        // make multi-cell canvas the client
  71.   setClient( &clientCanvas );
  72.                                        // set status area text
  73.   status.setAlignment( IStaticText::centerCenter );
  74.   status.setText( STR_STATUS );
  75.  
  76.   title1.setAlignment( IStaticText::centerLeft );    // set text and attributes
  77.   title1.setText( STR_TITLE1 );
  78.  
  79.   title2.setAlignment( IStaticText::centerLeft );    // set text and attributes
  80.   title2.setText( STR_TITLE2 );
  81.  
  82.   check1.setText( STR_CHECK1 );                      // set checkbox text
  83.   check2.setText( STR_CHECK2 );
  84.   radio1.setText( STR_RADIO1 );                      // set radio button text
  85.   radio2.setText( STR_RADIO2 );
  86.  
  87.   pushButton.setText( STR_PUSHBUT );
  88.  
  89.   radio1.select();                        // pre-select one radio button
  90.   check1.enableGroup().enableTabStop();   // set tabStop and Group styles
  91.   radio1.enableGroup().enableTabStop();
  92.   pushButton.enableGroup().enableTabStop();
  93.   pushButtonHandler.setOwnerWindow(this);   // initialize push button handler
  94.   pushButtonHandler.handleEventsFor(&clientCanvas);   // add handler to canvas
  95.  
  96.   clientCanvas.addToCell(&status  , 1, 1, 4, 1);     // add controls to canvas.
  97.   clientCanvas.addToCell(&title1  , 1, 3, 2, 1);     // the canvas runs from
  98.   clientCanvas.addToCell(&title2  , 3, 3, 2, 1);     // 1,1 to 4,7
  99.   clientCanvas.addToCell(&check1  , 2, 4);           // exactly one row and
  100.   clientCanvas.addToCell(&check2  , 2, 5);           // one column is
  101.   clientCanvas.addToCell(&radio1  , 4, 4);           // expandable, as this
  102.   clientCanvas.addToCell(&radio2  , 4, 5);           // allows the canvas to
  103.   clientCanvas.addToCell(&pushButton , 2, 7);        // fill the whole client.
  104.  
  105.   clientCanvas.setRowHeight(2, 20, true);           // set size of empty rows
  106.   clientCanvas.setRowHeight(6, 40);
  107.   clientCanvas.setColumnWidth(4, 40, true);         // last column expandable
  108.  
  109.   check1.setFocus();                         // set focus to first checkbox
  110.   show();                                    // show main window
  111.  
  112. } /* end AMultiCellCanvas :: AMultiCellCanvas(...) */
  113.  
  114. /******************************************************************************/
  115. /* AMultiCellCanvas :: displayButtonStatus - display a message box            */
  116. /******************************************************************************/
  117. AMultiCellCanvas& AMultiCellCanvas::displayButtonStatus()
  118. {
  119.   unsigned long str_id1, str_id2, str_id3;
  120.   IMessageBox msgbox(this);
  121.   IResourceLibrary  reslib = IApplication::current().userResourceLibrary();
  122.   msgbox.setTitle( IResourceId(STR_MSGBOX) );
  123.   str_id1 = check1.isSelected() ? STR_CHK1_SEL : STR_CHK1_NOSEL;
  124.   str_id2 = check2.isSelected() ? STR_CHK2_SEL : STR_CHK2_NOSEL;
  125.   IString  str1 = reslib.loadString(str_id1),
  126.            str2 = reslib.loadString(str_id2),
  127.            str3 = reslib.loadString( radio1.selectedIndex() + STR_RAD1_SEL );
  128.  
  129.   str1 += str2 + str3;
  130.   msgbox.show( (char *)str1 , IMessageBox::okButton         |
  131.                               IMessageBox::informationIcon  |
  132.                               IMessageBox::applicationModal |
  133.                               IMessageBox::moveable         );
  134.   return *this;
  135. }
  136.  
  137. /******************************************************************************/
  138. /* APushButtonHandler :: command - handle some command events                 */
  139. /******************************************************************************/
  140. IBase::Boolean APushButtonHandler::command( ICommandEvent& evt )
  141. {
  142. Boolean fProcessed = false;
  143.  
  144.    if (evt.commandId() == WND_PUSHBUT && window)
  145.       {
  146.       window->displayButtonStatus();
  147.       fProcessed = true;
  148.       }
  149.    return fProcessed;
  150. }
  151.