home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLUI / MCELCV / AMCELCV.CPP < prev    next >
Text File  |  1993-05-12  |  8KB  |  145 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. #include <iapp.hpp>                     // IApplication
  33. #include <imsgbox.hpp>                  // IMessageBox
  34. #include <istring.hpp>                  // IString
  35. #include <ireslib.hpp>                  // IResourceId
  36.  
  37. #include "amcelcv.h"
  38. #include "amcelcv.hpp"
  39.  
  40. /******************************************************************************/
  41. /* main  - Application entry point                                            */
  42. /******************************************************************************/
  43. void main()
  44. {
  45.   AMultiCellCanvas mainWindow(WND_MAIN);
  46.   IApplication::current().run();
  47. } /* end main */
  48.  
  49. /******************************************************************************/
  50. /* AMultiCellCanvas :: AMultiCellCanvas - Constructor for our main window     */
  51. /******************************************************************************/
  52. AMultiCellCanvas::AMultiCellCanvas(unsigned long windowId)
  53.   : IFrameWindow(windowId)
  54.   , clientCanvas( WND_MCCANVAS, this, this )
  55.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  56.   , title1( WND_TITLE1, &clientCanvas, &clientCanvas )
  57.   , title2( WND_TITLE2, &clientCanvas, &clientCanvas )
  58.   , check1( WND_CHECK1, &clientCanvas, &clientCanvas )
  59.   , check2( WND_CHECK2, &clientCanvas, &clientCanvas )
  60.   , radio1( WND_RADIO1, &clientCanvas, &clientCanvas )
  61.   , radio2( WND_RADIO2, &clientCanvas, &clientCanvas )
  62.   , pushButton( WND_PUSHBUT, &clientCanvas, &clientCanvas )
  63. {
  64.                                        // make multi-cell canvas the client
  65.   setClient( &clientCanvas );
  66.                                        // set status area text
  67.   status.setAlignment( IStaticText::centerCenter );
  68.   status.setText( STR_STATUS );
  69.  
  70.   title1.setAlignment( IStaticText::centerLeft );    // set text and attributes
  71.   title1.setText( STR_TITLE1 );
  72.  
  73.   title2.setAlignment( IStaticText::centerLeft );    // set text and attributes
  74.   title2.setText( STR_TITLE2 );
  75.  
  76.   check1.setText( STR_CHECK1 );                      // set checkbox text
  77.   check2.setText( STR_CHECK2 );
  78.   radio1.setText( STR_RADIO1 );                      // set radio button text
  79.   radio2.setText( STR_RADIO2 );
  80.  
  81.   pushButton.setText( STR_PUSHBUT );
  82.  
  83.   radio1.select();                        // pre-select one radio button
  84.   check1.enableGroup().enableTabStop();   // set tabStop and Group styles
  85.   radio1.enableGroup().enableTabStop();
  86.   pushButton.enableGroup().enableTabStop();
  87.   pushButtonHandler.setOwnerWindow(this);   // initialize push button handler
  88.   pushButtonHandler.handleEventsFor(&clientCanvas);   // add handler to canvas
  89.  
  90.   clientCanvas.addToCell(&status  , 1, 1, 4, 1);     // add controls to canvas.
  91.   clientCanvas.addToCell(&title1  , 1, 3, 2, 1);     // the canvas runs from
  92.   clientCanvas.addToCell(&title2  , 3, 3, 2, 1);     // 1,1 to 4,7
  93.   clientCanvas.addToCell(&check1  , 2, 4);           // exactly one row and
  94.   clientCanvas.addToCell(&check2  , 2, 5);           // one column is
  95.   clientCanvas.addToCell(&radio1  , 4, 4);           // expandable, as this
  96.   clientCanvas.addToCell(&radio2  , 4, 5);           // allows the canvas to
  97.   clientCanvas.addToCell(&pushButton , 2, 7);        // fill the whole client.
  98.  
  99.   clientCanvas.setRowHeight(2, 20, true);           // set size of empty rows
  100.   clientCanvas.setRowHeight(6, 40);
  101.   clientCanvas.setColumnWidth(4, 40, true);         // last column expandable
  102.  
  103.   check1.setFocus();                         // set focus to first checkbox
  104.   show();                                    // show main window
  105.  
  106. } /* end AMultiCellCanvas :: AMultiCellCanvas(...) */
  107.  
  108. /******************************************************************************/
  109. /* AMultiCellCanvas :: displayButtonStatus - display a message box            */
  110. /******************************************************************************/
  111. AMultiCellCanvas& AMultiCellCanvas::displayButtonStatus()
  112. {
  113.   unsigned long str_id1, str_id2, str_id3;
  114.   IMessageBox msgbox(this);
  115.   IResourceLibrary  reslib = IApplication::current().userResourceLibrary();
  116.   msgbox.setTitle( IResourceId(STR_MSGBOX) );
  117.   str_id1 = check1.isSelected() ? STR_CHK1_SEL : STR_CHK1_NOSEL;
  118.   str_id2 = check2.isSelected() ? STR_CHK2_SEL : STR_CHK2_NOSEL;
  119.   IString  str1 = reslib.loadString(str_id1),
  120.            str2 = reslib.loadString(str_id2),
  121.            str3 = reslib.loadString( radio1.selectedIndex() + STR_RAD1_SEL );
  122.  
  123.   str1 += str2 + str3;
  124.   msgbox.show( (char *)str1 , IMessageBox::okButton         |
  125.                               IMessageBox::informationIcon  |
  126.                               IMessageBox::applicationModal |
  127.                               IMessageBox::moveable         );
  128.   return *this;
  129. }
  130.  
  131. /******************************************************************************/
  132. /* APushButtonHandler :: command - handle some command events                 */
  133. /******************************************************************************/
  134. Boolean APushButtonHandler::command( ICommandEvent& evt )
  135. {
  136. Boolean fProcessed = false;
  137.  
  138.    if (evt.commandId() == WND_PUSHBUT && window)
  139.       {
  140.       window->displayButtonStatus();
  141.       fProcessed = true;
  142.       }
  143.    return fProcessed;
  144. }
  145.