home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLUI / SETCV / ASETCV.CPP < prev    next >
Text File  |  1993-05-12  |  7KB  |  134 lines

  1. /******************************************************************************/
  2. /* Canvas Classes Example 2 - Set 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 2 - Set Canvas                                      */
  18. /*   key functions:                                                           */
  19. /*      - create a main window                                                */
  20. /*      - run the current application                                         */
  21. /*      - create a horizontal split canvas                                    */
  22. /*      - create static text controls                                         */
  23. /*      - create vertical and horizontal set canvases with multiple decks     */
  24. /*      - create radio buttons                                                */
  25. /*      - control cursor and tab movement between different groups            */
  26. /*      - process 'Select' events on the radio buttons                        */
  27. /*      - load strings from resource bound to the exe                         */
  28. /******************************************************************************/
  29.                                         //Include IBM UI class headers:
  30. #include <iapp.hpp>                     // IApplication class
  31. #include <ipoint.hpp>                   // ISize class
  32. #include <istring.hpp>                  // IString class
  33.  
  34. #include "asetcv.h"
  35. #include "asetcv.hpp"
  36.  
  37. /******************************************************************************/
  38. /* main  - Application entry point                                            */
  39. /******************************************************************************/
  40. void main()                             //Main Procedure with no parameters
  41. {
  42.   ASetCanvas mainWindow(WND_MAIN);      //Create our main window on the decktop
  43.   IApplication::current().run();        //Get current & run the application
  44. } /* end main */
  45.  
  46. /******************************************************************************/
  47. /* ASetCanvas :: ASetCanvas - Constructor for our main window                 */
  48. /******************************************************************************/
  49. ASetCanvas::ASetCanvas(unsigned long windowId)
  50.   : IFrameWindow( windowId )
  51.   , clientCanvas( WND_SPLITCANVAS, this, this ,IRectangle(),
  52.                   ISplitCanvas::defaultStyle() | ISplitCanvas::horizontal )
  53.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  54.   , vSetCanvas( WND_VSETCANVAS, &clientCanvas, &clientCanvas )
  55.   , hSetCanvas( WND_HSETCANVAS, &clientCanvas, &clientCanvas )
  56. {
  57.                                        // make split canvas the client area
  58.   setClient( &clientCanvas );
  59.                                        // set alignment of status area text
  60.   status.setAlignment( IStaticText::centerCenter );
  61.  
  62.                                        // top canvas has 3 vertical decks
  63.   vSetCanvas.setDeckOrientation( ISetCanvas::vertical );
  64.   vSetCanvas.setDeckCount( 3 );
  65.                                        // bottom canvas has 3 horizontal decks
  66.   hSetCanvas.setDeckOrientation( ISetCanvas::horizontal );
  67.   hSetCanvas.setDeckCount( 3 );
  68.   hSetCanvas.setPad(ISize(10,10));    // set some space around buttons
  69.  
  70.   buttonHandler.useStatus( &status ); // give button handler a text control
  71.  
  72.   unsigned int i, mid = (NUMBER_OF_BUTTONS/2);
  73.                                       // create the first set of radio buttons
  74.   for (i = 0 ; i < mid ; ++i)
  75.      {
  76.      radiobut[i] = new IRadioButton( WND_BUTTON + i, &vSetCanvas, &vSetCanvas );
  77.      buttonHandler.handleEventsFor( radiobut[i] );     // add handler to button
  78.      radiobut[i]->setText( STR_TEXT + i );
  79.      }
  80.   radiobut[0]->enableGroup().enableTabStop();   // set tabStop and Group styles
  81.   radiobut[0]->select();                        // select first button in group
  82.  
  83.                                       // create the second set of radio buttons
  84.   for (i = mid ; i < NUMBER_OF_BUTTONS ; ++i)
  85.      {
  86.      radiobut[i] = new IRadioButton( WND_BUTTON + i, &hSetCanvas, &hSetCanvas );
  87.      buttonHandler.handleEventsFor( radiobut[i] );     // add handler to button
  88.      radiobut[i]->setText( STR_TEXT + i );
  89.      }
  90.   radiobut[mid]->enableGroup().enableTabStop(); // set tabStop and Group styles
  91.   radiobut[mid]->select();                      // select first button in group
  92.  
  93.   radiobut[0]->setFocus();             // set focus to radio button one
  94.   status.setText( STR_STATUS );        // set status area text from resource
  95.  
  96.   show();                              // show main window
  97.  
  98. } /* end ASetCanvas :: ASetCanvas(...) */
  99.  
  100. /******************************************************************************/
  101. /* ASetCanvas ::~ASetCanvas - Destructor for our main window                  */
  102. /******************************************************************************/
  103. ASetCanvas::~ASetCanvas()
  104. {
  105.    for (unsigned int i = 0; i < NUMBER_OF_BUTTONS ; ++i)
  106.       {
  107.       delete radiobut[i];
  108.       }
  109. }
  110.  
  111. /******************************************************************************/
  112. /* AButtonHandler::selected      - an ISelectEventHandler                     */
  113. /*   return true if event handled else return false                           */
  114. /* display the number of the button selected in a text control                */
  115. /******************************************************************************/
  116. Boolean AButtonHandler::selected(IControlEvent& evt )
  117. {
  118. Boolean fHandled = true;               // assume event is for us
  119.  
  120.    unsigned long ulButtonId = evt.controlId();
  121.                                        // if the id is one of the buttons
  122.                                        // then display the button number in the
  123.                                        // static text control
  124.    if ( ulButtonId >= WND_BUTTON &&
  125.         ulButtonId <= (WND_BUTTON+NUMBER_OF_BUTTONS) &&
  126.         output)
  127.       output->setText( IString( ulButtonId-WND_BUTTON+1 ) );
  128.    else
  129.       fHandled = false;                 // pass event to other handlers
  130.  
  131.    return fHandled;
  132.  
  133. } /* end AButtonHandler::selected(...) */
  134.