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

  1. /******************************************************************************/
  2. /* HELLO WORLD SAMPLE PROGRAM - Version 6: AColorWindow Class  (ACOLORW6.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 <inotebk.hpp>                  //INotebook Class
  25. #include <icolor.hpp>                   //IColor Class
  26. #include <istattxt.hpp>                 //IStaticText Class
  27. #include <ilistbox.hpp>                 //IListBox Class
  28. #include <imcelcv.hpp>                  //IMultiCellCanvas
  29. #include <iradiobt.hpp>                 //IRadioButton
  30. #include <ipushbut.hpp>                 //IPushButton Class
  31. #include <ireslib.hpp>                  //IResourceLibrary/IResourceId Class
  32.  
  33. #include "ahellow6.h"                   //Include our Symbolic definitions
  34. #include "acolorw6.hpp"                 //AColorWindow Class
  35.  
  36. //**************************************************************************
  37. // AColorWindow :: AColorButton:: AColorButton - Constructor               *
  38. //**************************************************************************
  39. AColorWindow :: AColorButton :: AColorButton(
  40.                   unsigned long windowId,         //Window ID
  41.                   IWindow * parentOwner,          //Parent/Owner
  42.                   unsigned long stringId) :       //Resource String ID
  43.                 IRadioButton (windowId,
  44.                   parentOwner, parentOwner)
  45. {
  46.   setText(stringId);
  47. }
  48.  
  49. //**************************************************************************
  50. // AColorWindow :: AColorWindow - Constructor                              *
  51. //**************************************************************************
  52. AColorWindow :: AColorWindow(
  53.                   IStaticText * staticWindow,
  54.                   IListBox * listWindow,
  55.                   IWindow * ownerWnd)
  56.               : IFrameWindow(WND_COLOR, //Call IFrameWindow Constructor
  57.                   ownerWnd)             //  Owner Window
  58. {                                       //
  59.   staticTarget=staticWindow;            //Save Static Target Window
  60.   listTarget=listWindow;                //Save ListBox Target Window
  61.   notebook=new INotebook(WND_COLOR_NOTE,//Create Notebook Color
  62.     this, this, IRectangle(),           //
  63.     INotebook::defaultStyle());         //
  64.   setClient(notebook);                  //Set the client to the notebook
  65.   ICommandHandler::handleEventsFor(this);//Set self as command event handler
  66.  
  67.   createStaticPage();                   //Create Static Color Page
  68.   createListPage();                     //Create ListBox Color Page
  69.   sizeTo(ISize(400,300));               //Set the size of main window
  70.   setFocus();                           //Set focus to main window
  71.   show();                               //Set to show main window
  72.  
  73. } /* end AColorWindow :: AColorWindow(...) */
  74.  
  75. //**************************************************************************
  76. // AColorWindow :: ~AColorWindow - Destructor                              *
  77. //**************************************************************************
  78. AColorWindow :: ~AColorWindow()
  79. {
  80. } /* end AColorWindow :: ~AColorWindow(...) */
  81.  
  82. //**************************************************************************
  83. // AColorWindow :: createStaticPage()                                      *
  84. //                                                                         *
  85. //                              MultiCell Canvas                           *
  86. //                                                                         *
  87. //        Column 1     Column 2     Column 3     Column 4      Column 5    *
  88. // Row 1                                                                   *
  89. // Row 2               <--------------Title---------------->               *
  90. // Row 3               White Button              Pink Button               *
  91. // Row 4               Black Button              Green Button              *
  92. // Row 5               Blue Button               Cyan Button               *       *
  93. // Row 6               Red Button                Yellow Button             *                  *
  94. // Row 7                                                                   *
  95. // Row 8               Apply Button              Cancel Button             *
  96. // Row 9                                                                   *
  97. //**************************************************************************
  98. Boolean AColorWindow :: createStaticPage()
  99. {
  100.   staticCanvas=new IMultiCellCanvas(
  101.     WND_STATIC_COLOR, notebook, this,
  102.     IRectangle());
  103.  
  104.   IStaticText * staticTitle=new         //Create Fore Title Text
  105.     IStaticText(0, staticCanvas, staticCanvas);
  106.   staticTitle->setText(STR_STATIC_COLOR);//Set the text for the title
  107.  
  108.   staticWhite=new AColorButton(         //Static White Radio Button
  109.     WND_SWHITE, staticCanvas, STR_WHITE);
  110.   staticWhite->enableGroup();
  111.   staticWhite->enableTabStop();
  112.   staticBlack=new AColorButton(         //Static Black Radio Button
  113.     WND_SBLACK, staticCanvas, STR_BLACK);
  114.   staticBlue=new AColorButton(          //Static Blue Radio Button
  115.     WND_SBLUE, staticCanvas, STR_BLUE);
  116.   staticRed=new AColorButton(           //Static Red Radio Button
  117.     WND_SRED, staticCanvas, STR_RED);
  118.   staticPink=new AColorButton(          //Static Pink Radio Button
  119.     WND_SPINK, staticCanvas, STR_PINK);
  120.   staticGreen=new AColorButton(         //Static Green Radio Button
  121.     WND_SGREEN, staticCanvas, STR_GREEN);
  122.   staticCyan=new AColorButton(          //Static Cyan Radio Button
  123.     WND_SCYAN, staticCanvas, STR_CYAN);
  124.   staticYellow=new AColorButton(        //Static Yellow Radio Button
  125.     WND_SYELLOW, staticCanvas, STR_YELLOW);
  126.  
  127.   staticApply=new IPushButton(          //Static Apply Button
  128.     WND_SAPPLY, staticCanvas, this);
  129.   staticApply->setText(STR_APPLY);
  130.   staticCancel=new IPushButton(         //Static Cancel Button
  131.     WND_SCANCEL, staticCanvas, this);
  132.   staticCancel->setText(STR_CANCEL);
  133.  
  134.   staticCanvas->addToCell(staticTitle,  2, 2, 3, 1);
  135.   staticCanvas->addToCell(staticWhite,  2, 3);
  136.   staticCanvas->addToCell(staticBlack,  2, 4);
  137.   staticCanvas->addToCell(staticBlue,   2, 5);
  138.   staticCanvas->addToCell(staticRed,    2, 6);
  139.   staticCanvas->addToCell(staticPink,   4, 3);
  140.   staticCanvas->addToCell(staticGreen,  4, 4);
  141.   staticCanvas->addToCell(staticCyan,   4, 5);
  142.   staticCanvas->addToCell(staticYellow, 4, 6);
  143.  
  144.   staticCanvas->addToCell(staticApply,  2, 8);
  145.   staticCanvas->addToCell(staticCancel, 4, 8);
  146.  
  147.   staticCanvas->setColumnWidth(1, 20, true);
  148.   staticCanvas->setColumnWidth(5, 20, true);
  149.   staticCanvas->setRowHeight(1, 20, true);
  150.   staticCanvas->setRowHeight(7, 5);
  151.   staticCanvas->setRowHeight(9, 30, true);
  152.  
  153.   INotebook::Page::Attribute            //Define the Page Attributes
  154.     attribute=INotebook::Page::majorTab //  with a Major Tab and
  155.     | INotebook::Page::autoPageSize;    //  AutoPageSize
  156.   staticPage=INotebook::Page(attribute);//Create Static Color Page
  157.   staticPage.setTabText("1");           //Set Tab Text
  158.   notebook->addFirstPage(staticPage);   //Add as First Page to notebook
  159.   staticPage.setWindow(staticCanvas);   //Add Window After inserting Page
  160.   return true;                          //Return
  161. } /* end AColorWindow :: createStaticPage() */
  162.  
  163. //**************************************************************************
  164. // AColorWindow :: createListPage()                                        *
  165. //                                                                         *
  166. //                              MultiCell Canvas                           *
  167. //                                                                         *
  168. //        Column 1     Column 2     Column 3     Column 4      Column 5    *
  169. // Row 1                                                                   *
  170. // Row 2               <--------------Title---------------->               *
  171. // Row 3               White Button              Pink Button               *
  172. // Row 4               Black Button              Green Button              *
  173. // Row 5               Blue Button               Cyan Button               *       *
  174. // Row 6               Red Button                Yellow Button             *                  *
  175. // Row 7                                                                   *
  176. // Row 8               Apply Button              Cancel Button             *
  177. // Row 9                                                                   *
  178. //**************************************************************************
  179. Boolean AColorWindow :: createListPage()
  180. {
  181.   listCanvas=new IMultiCellCanvas(
  182.     WND_LIST_COLOR, notebook, this,
  183.     IRectangle());
  184.  
  185.   IStaticText * listTitle=new           //Create Fore Title Text
  186.     IStaticText(0, listCanvas, listCanvas);
  187.   listTitle->setText(STR_LIST_COLOR);   //Set the text for the title
  188.  
  189.   listWhite=new AColorButton(           //List White Radio Button
  190.     WND_LWHITE, listCanvas, STR_WHITE);
  191.   listWhite->enableGroup();
  192.   listWhite->enableTabStop();
  193.   listBlack=new AColorButton(           //List Black Radio Button
  194.     WND_LBLACK, listCanvas, STR_BLACK);
  195.   listBlue=new AColorButton(            //List Blue Radio Button
  196.     WND_LBLUE, listCanvas, STR_BLUE);
  197.   listRed=new AColorButton(             //List Red Radio Button
  198.     WND_LRED, listCanvas, STR_RED);
  199.   listPink=new AColorButton(            //List Pink Radio Button
  200.     WND_LPINK, listCanvas, STR_PINK);
  201.   listGreen=new AColorButton(           //List Green Radio Button
  202.     WND_LGREEN, listCanvas, STR_GREEN);
  203.   listCyan=new AColorButton(            //List Cyan Radio Button
  204.     WND_LCYAN, listCanvas, STR_CYAN);
  205.   listYellow=new AColorButton(          //List Yellow Radio Button
  206.     WND_LYELLOW, listCanvas, STR_YELLOW);
  207.  
  208.  
  209.   listApply=new IPushButton(WND_LAPPLY, //ListBox Apply Button
  210.     listCanvas, this);
  211.   listApply->setText(STR_APPLY);
  212.   listCancel=new IPushButton(WND_LCANCEL,//ListBox Cancel Button
  213.     listCanvas, this);
  214.   listCancel->setText(STR_CANCEL);
  215.  
  216.   listCanvas->addToCell(listTitle,  2, 2, 3, 1);
  217.   listCanvas->addToCell(listWhite,  2, 3);
  218.   listCanvas->addToCell(listBlack,  2, 4);
  219.   listCanvas->addToCell(listBlue,   2, 5);
  220.   listCanvas->addToCell(listRed,    2, 6);
  221.   listCanvas->addToCell(listPink,   4, 3);
  222.   listCanvas->addToCell(listGreen,  4, 4);
  223.   listCanvas->addToCell(listCyan,   4, 5);
  224.   listCanvas->addToCell(listYellow, 4, 6);
  225.  
  226.   listCanvas->addToCell(listApply,  2, 8);
  227.   listCanvas->addToCell(listCancel, 4, 8);
  228.  
  229.   listCanvas->setColumnWidth(1, 20, true);
  230.   listCanvas->setColumnWidth(5, 20, true);
  231.   listCanvas->setRowHeight(1, 20, true);
  232.   listCanvas->setRowHeight(7, 5);
  233.   listCanvas->setRowHeight(9, 20, true);
  234.  
  235.   INotebook::Page::Attribute            //Define the Page Attributes
  236.     attribute=INotebook::Page::majorTab //  with a Major Tab and
  237.     | INotebook::Page::autoPageSize;    //  AutoPageSize
  238.  
  239.   listPage=INotebook::Page(attribute);//Create ListBox Color Page
  240.   listPage.setTabText("2");             //Set the tab text
  241.   notebook->addLastPage(listPage);      //Add as the Last Page to Notebook
  242.   listPage.setWindow(listCanvas);       //Add Window after inserting Page
  243.   return true;                          //Return
  244. } /* end AColorWindow :: createListPage() */
  245.  
  246. //**************************************************************************
  247. // AColorWindow :: command - Process Commands                              *
  248. //**************************************************************************
  249. Boolean AColorWindow :: command(ICommandEvent& cmdevt)
  250. {
  251.   switch(cmdevt.commandId()) {
  252.     case WND_SAPPLY:                    //Process Static Apply
  253.       applyStatic();                    //Apply Changes from Page 1
  254.       return(true);                     //Return Processing Completed
  255.       break;
  256.  
  257.     case WND_SCANCEL:                   //Process Static Cancel
  258.       close();                          //Close the Window
  259.       return(true);                     //Return Processing Completed
  260.       break;
  261.  
  262.     case WND_LAPPLY:                    //Process ListBox Apply
  263.       applyList();                      //Apply Changes from Page 2
  264.       return(true);                     //Return Processing Completed
  265.       break;
  266.  
  267.     case WND_LCANCEL:                   //Process ListBox Cancel
  268.       close();                          //Close the Window
  269.       return(true);                     //Return Processing Completed
  270.       break;
  271.  
  272.   }/* end switch */
  273.  
  274.   return(false);                       //Allow Default Processing to occur
  275. } /* end AColorWindow :: command(...) */
  276.  
  277. //**************************************************************************
  278. // AColorWindow :: applyStatic - Apply Changes from Page 1                  *
  279. //**************************************************************************
  280. Boolean AColorWindow :: applyStatic()
  281. {
  282.   switch (staticWhite->selectedIndex())
  283.   {
  284.   case 0:
  285.     staticTarget->setColor(
  286.       IStaticText::foreground,
  287.       IColor(IColor::white));
  288.     break;
  289.  
  290.   case 1:
  291.     staticTarget->setColor(
  292.       IStaticText::foreground,
  293.       IColor(IColor::black));
  294.     break;
  295.  
  296.   case 2:
  297.     staticTarget->setColor(
  298.       IStaticText::foreground,
  299.       IColor(IColor::blue));
  300.     break;
  301.  
  302.   case 3:
  303.     staticTarget->setColor(
  304.       IStaticText::foreground,
  305.       IColor(IColor::red));
  306.     break;
  307.  
  308.   case 4:
  309.     staticTarget->setColor(
  310.       IStaticText::foreground,
  311.       IColor(IColor::pink));
  312.     break;
  313.  
  314.   case 5:
  315.     staticTarget->setColor(
  316.       IStaticText::foreground,
  317.       IColor(IColor::green));
  318.     break;
  319.  
  320.   case 6:
  321.     staticTarget->setColor(
  322.       IStaticText::foreground,
  323.       IColor(IColor::cyan));
  324.     break;
  325.  
  326.   case 7:
  327.     staticTarget->setColor(
  328.       IStaticText::foreground,
  329.       IColor(IColor::yellow));
  330.     break;
  331.  
  332.   } /* endswitch */
  333.   return true;
  334. } /* end AColorWindow :: applyStatic() */
  335.  
  336. //**************************************************************************
  337. // AColorWindow :: applyList - Apply Changes from Page 2                  *
  338. //**************************************************************************
  339. Boolean AColorWindow :: applyList()
  340. {
  341.   switch (listWhite->selectedIndex())
  342.   {
  343.   case 0:
  344.     listTarget->setColor(
  345.       IListBox::foreground,
  346.       IColor(IColor::white));
  347.     break;
  348.  
  349.   case 1:
  350.     listTarget->setColor(
  351.       IListBox::foreground,
  352.       IColor(IColor::black));
  353.     break;
  354.  
  355.   case 2:
  356.     listTarget->setColor(
  357.       IListBox::foreground,
  358.       IColor(IColor::blue));
  359.     break;
  360.  
  361.   case 3:
  362.     listTarget->setColor(
  363.       IListBox::foreground,
  364.       IColor(IColor::red));
  365.     break;
  366.  
  367.   case 4:
  368.     listTarget->setColor(
  369.       IListBox::foreground,
  370.       IColor(IColor::pink));
  371.     break;
  372.  
  373.   case 5:
  374.     listTarget->setColor(
  375.       IListBox::foreground,
  376.       IColor(IColor::green));
  377.     break;
  378.  
  379.   case 6:
  380.     listTarget->setColor(
  381.       IListBox::foreground,
  382.       IColor(IColor::cyan));
  383.     break;
  384.  
  385.   case 7:
  386.     listTarget->setColor(
  387.       IListBox::foreground,
  388.       IColor(IColor::yellow));
  389.     break;
  390.  
  391.   } /* endswitch */
  392.   return true;
  393. } /* end AColorWindow :: applyList() */
  394.