home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / SETCV / ASETCV.CPP next >
Text File  |  1995-05-01  |  8KB  |  139 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. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  31.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  32. #endif                                  //  is defined.
  33. #include <iapp.hpp>                     // IApplication class
  34. #include <ipoint.hpp>                   // ISize class
  35. #include <istring.hpp>                  // IString class
  36.  
  37. #include "asetcv.h"
  38. #include "asetcv.hpp"
  39.  
  40. /******************************************************************************/
  41. /* main  - Application entry point                                            */
  42. /******************************************************************************/
  43. int main()                              //Main Procedure with no parameters
  44. {
  45.   ASetCanvas mainWindow(WND_MAIN);      //Create our main window on the decktop
  46.   IApplication::current().run();        //Get current & run the application
  47.   return 0;
  48. } /* end main */
  49.  
  50. /******************************************************************************/
  51. /* ASetCanvas :: ASetCanvas - Constructor for our main window                 */
  52. /******************************************************************************/
  53. ASetCanvas::ASetCanvas(unsigned long windowId)
  54.   : IFrameWindow( windowId )
  55.   , clientCanvas( WND_SPLITCANVAS, this, this, IRectangle(),
  56.                   ISplitCanvas::horizontal | IWindow::visible )
  57.   , status( WND_STATUS, &clientCanvas, &clientCanvas )
  58.   , vSetCanvas( WND_VSETCANVAS, &clientCanvas, &clientCanvas )
  59.   , hSetCanvas( WND_HSETCANVAS, &clientCanvas, &clientCanvas )
  60. {
  61.   setIcon( id() );                     // Set the icon
  62.                                        // make split canvas the client area
  63.   setClient( &clientCanvas );
  64.                                        // set alignment of status area text
  65.   status.setAlignment( IStaticText::centerCenter );
  66.  
  67.                                        // top canvas has 3 vertical decks
  68.   vSetCanvas.setDeckOrientation( ISetCanvas::vertical );
  69.   vSetCanvas.setDeckCount( 3 );
  70.                                        // bottom canvas has 3 horizontal decks
  71.   hSetCanvas.setDeckOrientation( ISetCanvas::horizontal );
  72.   hSetCanvas.setDeckCount( 3 );
  73.   hSetCanvas.setPad(ISize(10,10));    // set some space around buttons
  74.  
  75.   buttonHandler.useStatus( &status ); // give button handler a text control
  76.  
  77.   unsigned int i, mid = (NUMBER_OF_BUTTONS/2);
  78.                                       // create the first set of radio buttons
  79.   for (i = 0 ; i < mid ; ++i)
  80.      {
  81.      radiobut[i] = new IRadioButton( WND_BUTTON + i, &vSetCanvas, &vSetCanvas );
  82.      buttonHandler.handleEventsFor( radiobut[i] );     // add handler to button
  83.      radiobut[i]->setText( STR_TEXT + i );
  84.      }
  85.   radiobut[0]->enableGroup().enableTabStop();   // set tabStop and Group styles
  86.   radiobut[0]->select();                        // select first button in group
  87.  
  88.                                       // create the second set of radio buttons
  89.   for (i = mid ; i < NUMBER_OF_BUTTONS ; ++i)
  90.      {
  91.      radiobut[i] = new IRadioButton( WND_BUTTON + i, &hSetCanvas, &hSetCanvas );
  92.      buttonHandler.handleEventsFor( radiobut[i] );     // add handler to button
  93.      radiobut[i]->setText( STR_TEXT + i );
  94.      }
  95.   radiobut[mid]->enableGroup().enableTabStop(); // set tabStop and Group styles
  96.   radiobut[mid]->select();                      // select first button in group
  97.  
  98.   radiobut[0]->setFocus();             // set focus to radio button one
  99.   status.setText( STR_STATUS );        // set status area text from resource
  100.  
  101.   show();                              // show main window
  102.  
  103. } /* end ASetCanvas :: ASetCanvas(...) */
  104.  
  105. /******************************************************************************/
  106. /* ASetCanvas ::~ASetCanvas - Destructor for our main window                  */
  107. /******************************************************************************/
  108. ASetCanvas::~ASetCanvas()
  109. {
  110.    for (unsigned int i = 0; i < NUMBER_OF_BUTTONS ; ++i)
  111.       {
  112.       delete radiobut[i];
  113.       }
  114. }
  115.  
  116. /******************************************************************************/
  117. /* AButtonHandler::selected      - an ISelectEventHandler                     */
  118. /*   return true if event handled else return false                           */
  119. /* display the number of the button selected in a text control                */
  120. /******************************************************************************/
  121. IBase::Boolean AButtonHandler::selected(IControlEvent& evt )
  122. {
  123. Boolean fHandled = true;               // assume event is for us
  124.  
  125.    unsigned long ulButtonId = evt.controlId();
  126.                                        // if the id is one of the buttons
  127.                                        // then display the button number in the
  128.                                        // static text control
  129.    if ( ulButtonId >= WND_BUTTON &&
  130.         ulButtonId <= (WND_BUTTON+NUMBER_OF_BUTTONS) &&
  131.         output)
  132.       output->setText( IString( ulButtonId-WND_BUTTON+1 ) );
  133.    else
  134.       fHandled = false;                 // pass event to other handlers
  135.  
  136.    return fHandled;
  137.  
  138. } /* end AButtonHandler::selected(...) */
  139.