home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ICLUI.ZIP / HELLO6 / ASPEEDW6.CPP < prev    next >
Text File  |  1993-03-09  |  9KB  |  166 lines

  1. /******************************************************************************/
  2. /* HELLO WORLD SAMPLE PROGRAM - Version 6: ASpeedWindow Class  (ASPEEDW6.CPP) */
  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.  
  16. //**************************************************************************
  17. // The entire file was created at version 6                                *
  18. //**************************************************************************
  19.  
  20. #include <ientryfd.hpp>                 //IEntryField Class
  21. #include <icmdevt.hpp>                  //ICommandEvent
  22. #include <istring.hpp>                  //IString Class
  23. #include <inotebk.hpp>                  //INotebook Class
  24. #include <isetcv.hpp>                   //ISetCanvas Class
  25. #include <imcelcv.hpp>                  //IMultiCellCanvas
  26. #include <islider.hpp>                  //ISlider Class
  27. #include <icolor.hpp>                   //IColor Class
  28. #include <istattxt.hpp>                 //IStaticText Class
  29. #include <ilistbox.hpp>                 //IListBox Class
  30. #include <imcelcv.hpp>                  //IMultiCellCanvas
  31. #include <iradiobt.hpp>                 //IRadioButton
  32. #include <ipushbut.hpp>                 //IPushButton Class
  33. #include <ireslib.hpp>                  //IResourceLibrary/IResourceId Class
  34.  
  35. #include "ahellow6.h"                   //Include our Symbolic definitions
  36. #include "aspeedw6.hpp"                 //ASpeedWindow Class
  37. #include "ahellow6.hpp"                 //AHelloWindow Class
  38.  
  39. //**************************************************************************
  40. // ASpeedWindow :: ASpeedWindow - Constructor                              *
  41. //                                                                         *
  42. //                          MultiCell Canvas                               *
  43. //                                                                         *
  44. //                    Column 1  Column 2  Column 3                         *
  45. //          Row 1                                                          *
  46. //          Row 2                Label 1                                   *
  47. //          Row 3                Label 2                                   *
  48. //          Row 4                Slider                                    *
  49. //          Row 5                                                          *
  50. //                                                                         *
  51. //**************************************************************************
  52. ASpeedWindow :: ASpeedWindow (AHelloWindow * demoWindow,
  53.                   IWindow * ownerWnd)   //Onwer Window
  54.               : IFrameWindow(           //Call IFrameWindow Constructor
  55.                   WND_DEMO_SPEED,       //Window Id
  56.                   ownerWnd)             //Owner Window
  57. {                                       //
  58.   target=demoWindow;                    //Save Target Window
  59.   clientWindow=new IMultiCellCanvas(    //Create Client Window with
  60.     WND_DEMO_CLIENT,                    //  Window ID and
  61.     this, this, IRectangle());          //  parent, owner and size
  62.   setClient(clientWindow);              //Set the client to the split canvas
  63.   ICommandHandler::handleEventsFor(this);//Set self as command event handler
  64.  
  65.   slider=new ISlider(WND_DEMO_SLIDER,   //Create Slider Window
  66.     clientWindow, clientWindow,         //  Set Window ID, client-owner/parent
  67.     IRectangle(), 5);                   //  Set Rectangle and number of Ticks
  68.  
  69.   for (unsigned long i=0; i<5; i++)     //Loop to set the Tick Text
  70.     slider->setTickText(                //  Set the tick text for each tick
  71.     i, (char*)(IString(i+1)));          //  tick number, tick text
  72.   slider->enableSnapToTick();           //Enable Snap to Tick
  73.   slider->moveArmToTick(                //Set the arm (zero based) to the
  74.     target->speed()-1);                 //  current Speed Value from target
  75.  
  76.   label1=new IStaticText(WND_DEMO_LABEL1,//Create Static Text Control
  77.     clientWindow, clientWindow);        //  Pass in client as owner & parent
  78.   label1->setAlignment(                 //Set Alignment to Center in both
  79.       IStaticText::centerCenter);       //  directions
  80.   label1->setText(STR_DEMO_LABEL1);     //Set the demo label 1
  81.  
  82.   label2=new IStaticText(WND_DEMO_LABEL2,//Create Static Text Control
  83.     clientWindow, clientWindow);        //  Pass in client as owner & parent
  84.   label2->setAlignment(                 //Set Alignment to Center in both
  85.       IStaticText::centerCenter);       //  directions
  86.   label2->setText(STR_DEMO_LABEL2);     //Set the demo label 2
  87.  
  88.   clientWindow->addToCell(label1, 2, 2);//Add label1 to Canvas at column 2 row 2
  89.   clientWindow->addToCell(label2, 2, 3);//Add label2 to Canvas at column 2 row 3
  90.   clientWindow->addToCell(slider, 2, 4);//Add Slider to Canvas at column 2 row 4
  91.  
  92.   clientWindow->setColumnWidth(1, 30);  //Specify Column 1 Width for Border
  93.   clientWindow->setColumnWidth(2, 100,  //Specify Column 2 Width and set
  94.     true);                              //  expandable
  95.   clientWindow->setColumnWidth(3, 30);  //Specify Column 3 Width for Border
  96.   clientWindow->setRowHeight(1, 30);    //Specify Row 1 Height for Border
  97.   clientWindow->setRowHeight(2, 0,      //Specify Row 2 as expandable
  98.     true);
  99.   clientWindow->setRowHeight(3, 0,      //Specify Row 3 as expandable
  100.     true);
  101.   clientWindow->setRowHeight(4, 60,     //Specify Row 4 as expandable
  102.     true);
  103.   clientWindow->setRowHeight(5, 30);    //Specify Row 5 Height for Border
  104.  
  105.   buttons=new ISetCanvas(               //Create a Set Canvas for Buttons
  106.     WND_DEMO_BUTTONS, this, this) ;     //  Parent and Owner=me
  107.   buttons->setMargin(ISize());          //Set Canvas Margins to zero
  108.   buttons->setPad(ISize());             //Set Button Canvas Pad to zero
  109.  
  110.   applyButton=new IPushButton(          //Create the Apply Push Button
  111.     WND_DEMO_APPLY,
  112.     buttons, this);                     //  Parent is buttons, owner is me
  113.   applyButton->setText(STR_APPLY);      //Set the text of the Apply Button
  114.   cancelButton=new IPushButton(         //Create the Cancel Push Button
  115.     WND_DEMO_CANCEL,
  116.     buttons, this);                     //  Parent is buttons, owner id me
  117.   cancelButton->setText(STR_CANCEL);    //Set the text of the Cancel Button
  118.  
  119.   addExtension(buttons,                 //Add Buttons below client area
  120.     IFrameWindow::belowClient, 30UL);   //  and specify the height
  121.  
  122.   sizeTo(ISize(400,300));               //Set the size of main window
  123.   setFocus();                           //Set focus to main window
  124.   show();                               //Set to show main window
  125.  
  126. } /* end ASpeedWindow :: ASpeedWindow(...) */
  127.  
  128. //**************************************************************************
  129. // ASpeedWindow :: ~ASpeedWindow - Destructor                              *
  130. //**************************************************************************
  131. ASpeedWindow :: ~ASpeedWindow()
  132. {
  133. } /* end ASpeedWindow :: ~ASpeedWindow(...) */
  134.  
  135. //**************************************************************************
  136. // ASpeedWindow :: command - Process Commands                              *
  137. //**************************************************************************
  138. Boolean ASpeedWindow :: command(ICommandEvent& cmdevt)
  139. {
  140.   switch(cmdevt.commandId()) {
  141.     case WND_DEMO_APPLY:                //Process Apply
  142.       apply();                          //Apply Changes
  143.       return(true);                     //Return Processing Completed
  144.       break;
  145.  
  146.     case WND_DEMO_CANCEL:               //Process Cancel
  147.       close();                          //Close the Window
  148.       return(true);                     //Return Processing Completed
  149.       break;
  150.  
  151.   }/* end switch */
  152.  
  153.   return(false);                       //Allow Default Processing to occur
  154. } /* end ASpeedWindow :: command(...) */
  155.  
  156. //**************************************************************************
  157. // ASpeedWindow :: apply - Apply Changes                                   *
  158. //**************************************************************************
  159. Boolean ASpeedWindow :: apply()
  160. {
  161.   int armOffset;
  162.   armOffset=slider->armTickOffset()+1;  //Get Current Arm Offset (zero based)
  163.   target->setSpeed(armOffset);          //Set New Speed Value into Target
  164.   return true;
  165. } /* end ASpeedWindow :: apply() */
  166.