home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / hello6 / anotebw6.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  20.9 KB  |  390 lines

  1. /******************************************************************************
  2. * .FILE         anotebw6.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Hello World Sample Program Version 6: Notebook Implementation *
  5. *                                                                             *
  6. * .CLASSES:     ANotebookWindow                                               *
  7. *               ANotebookHandler                                              *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #include <ibase.hpp>
  26. #include <ireslib.hpp>
  27.  
  28. #include "anotebw6.hpp"
  29. #include "ahellow6.h"
  30.  
  31. /**************************************************************************
  32. * Class ANotebookWindow :: ANotebookWindow - Construcs a child window     *
  33. *   that contains the setting notebook.                                   *
  34. **************************************************************************/
  35. ANotebookWindow :: ANotebookWindow(unsigned long windowId,
  36.                                    AHelloWindow * ownerWnd)
  37.   : IFrameWindow(IResourceId(windowId), ownerWnd)
  38.   , helloSettingsNotebook(WND_NOTEBOOK, this, this)
  39.   , earthPage(WND_EARTHPAGE,&helloSettingsNotebook,&helloSettingsNotebook)
  40.   , earthPageHeading(WND_EARTHPAGEHEADING, &earthPage, &earthPage)
  41.   , starsHeading(WND_STARSHEADING, &earthPage, &earthPage)
  42.   , starsSettings(WND_STARSSETTINGS, &earthPage, &earthPage)
  43.   , twinkleBox(WND_TWINKLEBOX, &starsSettings, &starsSettings)
  44.   , brightBox(WND_BRIGHTBOX, &starsSettings, &starsSettings)
  45.   , layersHeading(WND_LAYERSHEADING, &earthPage, &earthPage)
  46.   , layersSlider(WND_LAYERSSPIN, &earthPage, &earthPage,
  47.                  IRectangle(), 4ul, 0,
  48.                  IProgressIndicator::alignBottom   |
  49.                  IProgressIndicator::snapToTickMark|
  50.                  IProgressIndicator::primaryScale1 |
  51.                  IProgressIndicator::horizontal    |
  52.                  IProgressIndicator::homeLeft      |
  53.                  ISlider::buttonsRight |
  54.                  IWindow::visible)
  55.   , earthColorHeading(WND_EARTHCOLORHEADING, &earthPage, &earthPage)
  56.   , earthColorSettings(WND_EARTHCOLORSETTINGS, &earthPage, &earthPage)
  57.   , cyanButton(WND_CYANBUTTON, &earthColorSettings,&earthColorSettings)
  58.   , greenButton(WND_GREENBUTTON, &earthColorSettings,&earthColorSettings)
  59.   , whiteButton(WND_WHITEBUTTON, &earthColorSettings,&earthColorSettings)
  60.   , yellowButton(WND_YELLOWBUTTON, &earthColorSettings,&earthColorSettings)
  61.   , earthPageButtons(WND_EARTHPAGEBUTTONS, &earthPage, &earthPage)
  62.   , earthApplyButton(DID_EARTHAPPLY, &earthPageButtons,&earthPageButtons)
  63.   , earthResetButton(DID_EARTHRESET, &earthPageButtons,&earthPageButtons)
  64.   , earthCloseButton(DID_NOTEBOOKCLOSE, &earthPageButtons,&earthPageButtons)
  65.   , dateTimePage(WND_DATETIMEPAGE, &helloSettingsNotebook,&helloSettingsNotebook)
  66.   , dateTimePageHeading(WND_DATETIMEPAGEHEADING, &dateTimePage,&dateTimePage)
  67.   , dateHeading(WND_DATEHEADING, &dateTimePage, &dateTimePage)
  68.   , dateSettings(WND_DATESETTINGS, &dateTimePage, &dateTimePage)
  69.   , dateLongButton(WND_DATELONGBOX, &dateSettings, &dateSettings)
  70.   , dateShortButton(WND_DATESHORTBOX, &dateSettings, &dateSettings)
  71.   , dateLongExample(WND_DATELONGEXAMPLE, &dateSettings, &dateSettings)
  72.   , dateShortExample(WND_DATESHORTEXAMPLE,&dateSettings,&dateSettings)
  73.   , timeHeading(WND_TIMEHEADING, &dateTimePage, &dateTimePage)
  74.   , timeSettings(WND_TIMESETTINGS, &dateTimePage, &dateTimePage)
  75.   , timeLongButton(WND_TIMELONGBOX, &timeSettings, &timeSettings)
  76.   , timeShortButton(WND_TIMESHORTBOX, &timeSettings, &timeSettings)
  77.   , timeLongExample(WND_TIMELONGEXAMPLE, &timeSettings, &timeSettings)
  78.   , timeShortExample(WND_TIMESHORTEXAMPLE,&timeSettings,&timeSettings)
  79.   , dateTimePageButtons(WND_DATETIMEPAGEBUTTONS, &dateTimePage,&dateTimePage)
  80.   , dateTimeApplyButton(DID_DATETIMEAPPLY, &dateTimePageButtons,
  81.                   &dateTimePageButtons)
  82.   , dateTimeResetButton(DID_DATETIMERESET, &dateTimePageButtons,
  83.                   &dateTimePageButtons)
  84.   , dateTimeCloseButton(DID_NOTEBOOKCLOSE, &dateTimePageButtons,
  85.                   &dateTimePageButtons)
  86.   , notebookCommandHandler(this)
  87. {
  88. /*------------------------------------------------------------------------|
  89. | Load text strings from the resource file and set alignment where needed.|
  90. |------------------------------------------------------------------------*/
  91.   earthPageHeading.setText(IResourceId(STR_EARTHPAGEHEADING))
  92.                   .setAlignment(IStaticText::centerCenter);
  93.   starsHeading.setText(IResourceId(STR_STARSHEADING));
  94.   twinkleBox.setText(IResourceId(STR_TWINKLEBOX));
  95.   brightBox.setText(IResourceId(STR_BRIGHTBOX));
  96.   layersHeading.setText(IResourceId(STR_LAYERSHEADING));
  97.   earthColorHeading.setText(IResourceId(STR_EARTHCOLORHEADING));
  98.   cyanButton.setText(IResourceId(STR_CYAN));
  99.   greenButton.setText(IResourceId(STR_GREEN));
  100.   whiteButton.setText(IResourceId(STR_WHITE));
  101.   yellowButton.setText(IResourceId(STR_YELLOW));
  102.   earthApplyButton.setText(IResourceId(STR_APPLY));
  103.   earthResetButton.setText(IResourceId(STR_RESET));
  104.   earthCloseButton.setText(IResourceId(STR_CLOSE));
  105.  
  106.   dateTimePageHeading.setText(IResourceId(STR_DATETIMEPAGEHEADING))
  107.                      .setAlignment(IStaticText::centerCenter);
  108.   dateHeading.setText(IResourceId(STR_DATEHEADING));
  109.   dateLongButton.setText(IResourceId(STR_DATELONGBOX));
  110.   dateShortButton.setText(IResourceId(STR_DATESHORTBOX));
  111.   dateLongExample.setText(IResourceId(STR_DATELONGEXAMPLE))
  112.                  .setAlignment(IStaticText::centerLeft);
  113.   dateShortExample.setText(IResourceId(STR_DATESHORTEXAMPLE))
  114.                   .setAlignment(IStaticText::centerLeft);
  115.   timeHeading.setText(IResourceId(STR_TIMEHEADING));
  116.   timeLongButton.setText(IResourceId(STR_TIMELONGBOX));
  117.   timeShortButton.setText(IResourceId(STR_TIMESHORTBOX));
  118.   timeLongExample.setText(IResourceId(STR_TIMELONGEXAMPLE))
  119.                  .setAlignment(IStaticText::centerLeft);
  120.   timeShortExample.setText(IResourceId(STR_TIMESHORTEXAMPLE))
  121.                   .setAlignment(IStaticText::centerLeft);
  122.   dateTimeApplyButton.setText(IResourceId(STR_APPLY));
  123.   dateTimeResetButton.setText(IResourceId(STR_RESET));
  124.   dateTimeCloseButton.setText(IResourceId(STR_CLOSE));
  125.  
  126. /*------------------------------------------------------------------------|
  127. | Set the width and value for each tick mark on the slider.               |
  128. |------------------------------------------------------------------------*/
  129.   layersSlider.setTickLength(5)
  130.               .setTickText(0,"0")
  131.               .setTickText(1,"1")
  132.               .setTickText(2,"2")
  133.               .setTickText(3,"3");
  134.  
  135. /*------------------------------------------------------------------------|
  136. | Place the color buttons in the colors canvas.                           |
  137. |   Start with column 2 to get a left margin.                             |
  138. |------------------------------------------------------------------------*/
  139.   earthColorSettings.addToCell(&cyanButton,  2,1)
  140.                     .addToCell(&greenButton, 2,2)
  141.                     .addToCell(&whiteButton, 3,1)
  142.                     .addToCell(&yellowButton,3,2);
  143.  
  144. /*------------------------------------------------------------------------|
  145. | Organize the Earth settings page on the earthPage multicell canvas.     |
  146. |   Start with column 2 to get a left margin.                             |
  147. |   The headings span 2 columns to prevent stretching of the controls.    |
  148. |------------------------------------------------------------------------*/
  149.   earthPage.addToCell(&earthPageHeading,   2, 1,2,1)
  150.            .addToCell(&starsHeading,       2, 4,2,1)
  151.            .addToCell(&starsSettings,      2, 5,1,1)
  152.            .addToCell(&layersHeading,      2, 8,2,1)
  153.            .addToCell(&layersSlider,       2, 9,1,2)
  154.            .addToCell(&earthColorHeading,  2,13,2,1)
  155.            .addToCell(&earthColorSettings, 2,14,1,2)
  156.            .addToCell(&earthPageButtons,   2,18,2,1);
  157.  
  158. /*------------------------------------------------------------------------|
  159. | Call the function that sets the earth page values from the source       |
  160. |   AEarthWindow.                                                         |
  161. |------------------------------------------------------------------------*/
  162.   resetEarthSettings();
  163.   twinkleBox.enableTabStop();
  164.   layersSlider.enableTabStop();
  165.   cyanButton.enableTabStop();
  166.   earthApplyButton.enableTabStop();
  167.  
  168. /*------------------------------------------------------------------------|
  169. | Organize the date & time radio buttons and examples on the              |
  170. |   dateTimeSettings multicell canvas.                                    |
  171. |   Start with column 2 to get a left margin.                             |
  172. |   The controls are placed in column 2 and the examples in column 3.     |
  173. |   The setAlignment(IStaticText::centerLeft) functions used when setting |
  174. |     the text values cause the examples to align vertically.             |
  175. |------------------------------------------------------------------------*/
  176.  
  177.   dateSettings.addToCell(&dateLongButton,  2, 1)
  178.               .addToCell(&dateLongExample, 3, 1)
  179.               .addToCell(&dateShortButton, 2, 2)
  180.               .addToCell(&dateShortExample,3, 2);
  181.   timeSettings.addToCell(&timeLongButton,  2, 1)
  182.               .addToCell(&timeLongExample, 3, 1)
  183.               .addToCell(&timeShortButton, 2, 2)
  184.               .addToCell(&timeShortExample,3, 2);
  185.  
  186. /*------------------------------------------------------------------------|
  187. | Organize the date & time settings page on the dateTimePage canvas.      |
  188. |   Start with column 2 to get a left margin.                             |
  189. |   The headings span 2 columns to prevent stretching of the controls.    |
  190. |   The settings canvases contained in the page canvas is assigned to an  |
  191. |     area that is two columns by two rows.                               |
  192. |------------------------------------------------------------------------*/
  193.   dateTimePage.addToCell(&dateTimePageHeading,2, 1,2,1)
  194.               .addToCell(&dateHeading,        2, 4,2,1)
  195.               .addToCell(&dateSettings,       2, 5,2,2)
  196.               .addToCell(&timeHeading,        2, 9,1,1)
  197.               .addToCell(&timeSettings,       2,10,2,2)
  198.               .addToCell(&dateTimePageButtons,2,14,2,1);
  199.  
  200. /*------------------------------------------------------------------------|
  201. | Call the function that sets the date & time page values from the source |
  202. |   AHelloWindow.                                                         |
  203. |------------------------------------------------------------------------*/
  204.   resetDateTimeSettings();
  205.   dateLongButton.enableTabStop();
  206.   timeLongButton.enableTabStop();
  207.   dateTimeApplyButton.enableTabStop();
  208.  
  209. /*-------------------- Setup the Settings Notebook -----------------------|
  210. | Create the notebook page settings with attributes for a major tab and   |
  211. |   automatic page size.                                                  |
  212. | Set tab text to the Earth tab text from the resource file.              |
  213. | Use the earthPage canvas and the notebook settings to add a page to the |
  214. |   beginning of the notebook.                                            |
  215. | Reset the tab text to the date and time tab text from the resource file.|
  216. | Use the dateTimePage canvas and the notebook settings to add a page to  |
  217. |   the end of the notebook.                                              |
  218. | The Motif release of the User Interface Class Library automatically     |
  219. |    sizes the major tab. For other releases, manually resize the tabs.   |
  220. |------------------------------------------------------------------------*/
  221.   INotebook::PageSettings
  222.         helloSettings(INotebook::PageSettings::majorTab|
  223.                       INotebook::PageSettings::autoPageSize);
  224.   helloSettings.setTabText(IResourceId(STR_EARTHTAB));
  225.   helloSettingsNotebook.addFirstPage(helloSettings,&earthPage);
  226.   helloSettings.setTabText(IResourceId(STR_DATETIMETAB));
  227.   helloSettingsNotebook.addLastPage(helloSettings,&dateTimePage);
  228. #ifndef IC_MOTIF
  229.   helloSettingsNotebook.setMajorTabSize(ISize(100,30));
  230. #endif
  231.  
  232. /*------------------------------------------------------------------------|
  233. | When a page is added to a notebook and using the autoPageSize style,    |
  234. | the pages are automatically resized to the current notebook size.       |
  235. | Therefore, we need to resize the notebook pages to their minimum size   |
  236. | so that the notebook can properly calculate it's minimum size.          |
  237. -------------------------------------------------------------------------*/
  238.   earthPage.sizeTo( earthPage.minimumSize() );
  239.   dateTimePage.sizeTo( dateTimePage.minimumSize() );
  240.  
  241. /*-------------------- Complete Setup of the Frame -----------------------|
  242. | Place the notebook into the client portion of the ANotebookWindow frame.|
  243. | Start processing command events for all the controls in the notebook.   |
  244. |------------------------------------------------------------------------*/
  245.   setClient(&helloSettingsNotebook);
  246.   notebookCommandHandler.handleEventsFor(&helloSettingsNotebook);
  247.  
  248. /*--------------------------------------------------------------------------|
  249. | Resize the notebook frame window based on the minimum size of the notebook|
  250. ---------------------------------------------------------------------------*/
  251. #ifndef IC_MOTIF
  252.   moveSizeToClient( IRectangle( position(),
  253.                     helloSettingsNotebook.minimumSize() ) );
  254. #else
  255.   moveSizeTo( IRectangle( position(),
  256.               helloSettingsNotebook.minimumSize() ) );
  257. #endif
  258.  
  259. } /* end ANotebookWindow :: ANotebookWindow(...) */
  260.  
  261. /**************************************************************************
  262. * Class ANotebookWindow :: ~ANotebookWindow - Destructor for the notebook *
  263. *   window                                                                *
  264. **************************************************************************/
  265. ANotebookWindow :: ~ANotebookWindow()
  266. {
  267.   notebookCommandHandler.stopHandlingEventsFor(&helloSettingsNotebook);
  268. } /* end ANotebookWindow :: ~ANotebookWindow() */
  269.  
  270. /**************************************************************************
  271. * Class ANotebookWindow :: applyEarthSettings -Apply earth settings       *
  272. *   changes to the owner's earth window.                                  *
  273. **************************************************************************/
  274. ANotebookWindow& ANotebookWindow :: applyEarthSettings()
  275. {
  276.   AHelloWindow *helloWindow = (AHelloWindow *)owner();
  277.   helloWindow->earth()->enableTwinkle(twinkleBox.isSelected());
  278.   helloWindow->earth()->enableBright(brightBox.isSelected());
  279.   helloWindow->earth()->setLayers(layersSlider.armTickOffset());
  280.   if (cyanButton.isSelected())
  281.     helloWindow->earth()->setEarthColor(IColor::cyan);
  282.   if (greenButton.isSelected())
  283.     helloWindow->earth()->setEarthColor(IColor::green);
  284.   if (whiteButton.isSelected())
  285.     helloWindow->earth()->setEarthColor(IColor::white);
  286.   if (yellowButton.isSelected())
  287.     helloWindow->earth()->setEarthColor(IColor::yellow);
  288.  
  289.   return (*this);
  290. } /* end ANotebookWindow :: applyEarthSettings() */
  291.  
  292. /**************************************************************************
  293. * Class ANotebookWindow :: resetEarthSettings - Reset local earth         *
  294. *   settings to the current settings from the owner's earth window.       *
  295. **************************************************************************/
  296. ANotebookWindow& ANotebookWindow :: resetEarthSettings()
  297. {
  298.   AHelloWindow *helloWindow = (AHelloWindow *)owner();
  299.   helloWindow->earth()->isTwinkling()  ? twinkleBox.select()
  300.                                         : twinkleBox.deselect();
  301.   helloWindow->earth()->isBright()     ? brightBox.select()
  302.                                         : brightBox.deselect();
  303.   layersSlider.moveArmToTick(helloWindow->earth()->layers());
  304.   if (helloWindow->earth()->earthColor().value()==IColor::cyan)
  305.     cyanButton.select();
  306.   if (helloWindow->earth()->earthColor().value()==IColor::green)
  307.     greenButton.select();
  308.   if (helloWindow->earth()->earthColor().value()==IColor::white)
  309.     whiteButton.select();
  310.   if (helloWindow->earth()->earthColor().value()==IColor::yellow)
  311.     yellowButton.select();
  312.  
  313.   return (*this);
  314. } /* end ANotebookWindow :: resetEarthSettings() */
  315.  
  316. /**************************************************************************
  317. * Class ANotebookWindow :: applyDateTimeSettings -Apply date and time     *
  318. *   settings changes to the owner's window.                               *
  319. **************************************************************************/
  320. ANotebookWindow& ANotebookWindow :: applyDateTimeSettings()
  321. {
  322.   AHelloWindow *helloWindow = (AHelloWindow *)owner();
  323.   helloWindow->enableDateLong(dateLongButton.isSelected());
  324.   helloWindow->enableTimeLong(timeLongButton.isSelected());
  325.  
  326.   return (*this);
  327. } /* end ANotebookWindow :: applyDateTimeSettings() */
  328.  
  329. /**************************************************************************
  330. * Class ANotebookWindow :: resetDateTimeSettings - Reset local date and   *
  331. *   time settings to current settings from the owner's window.            *
  332. **************************************************************************/
  333. ANotebookWindow
  334.   &ANotebookWindow :: resetDateTimeSettings()
  335. {
  336.   AHelloWindow *helloWindow = (AHelloWindow *)owner();
  337.   helloWindow->isDateLong() ? dateLongButton.select()
  338.                             : dateShortButton.select();
  339.   helloWindow->isTimeLong() ? timeLongButton.select()
  340.                             : timeShortButton.select();
  341.   return (*this);
  342. } /* end ANotebookWindow :: resetDateTimeSettings() */
  343.  
  344. /**************************************************************************
  345. * Class ANotebookCommandHandler :: ANotebookCommandHandler - Constructor  *
  346. *   for the command handler                                               *
  347. * Stores a pointer to the window for which events will be handled.        *
  348. **************************************************************************/
  349. ANotebookCommandHandler :: ANotebookCommandHandler(ANotebookWindow *nbFrame)
  350.    : frame(nbFrame)
  351. {
  352. } /* end ANotebookCommandHandler :: ANotebookCommandHandler(...) */
  353.  
  354. /**************************************************************************
  355. * Class ANotebookCommandHandler :: command - Process command events for   *
  356. *   ANotebookWindow.                                                      *
  357. **************************************************************************/
  358. IBase::Boolean
  359.   ANotebookCommandHandler :: command(ICommandEvent & cmdEvent)
  360. {
  361.   Boolean eventProcessed(true);         //Assume event will be processed
  362.  
  363. /*------------------------------------------------------------------------|
  364. |  Depending on the command event ID,                                     |
  365. |    update or reset local settings to the Hello World settings.          |
  366. |  Regardless of the page, if the close button is pressed, close notebook.|
  367. |------------------------------------------------------------------------*/
  368.   switch (cmdEvent.commandId()) {
  369.     case DID_EARTHAPPLY:
  370.       frame->applyEarthSettings();
  371.       break;
  372.     case DID_EARTHRESET:
  373.       frame->resetEarthSettings();
  374.       break;
  375.     case DID_DATETIMEAPPLY:
  376.       frame->applyDateTimeSettings();
  377.       break;
  378.     case DID_DATETIMERESET:
  379.       frame->resetDateTimeSettings();
  380.       break;
  381.     case DID_NOTEBOOKCLOSE:
  382.       frame->close();
  383.       break;
  384.     default:                            //Otherwise,
  385.       eventProcessed=false;             //  the event wasn't processed
  386.   } /* end switch */
  387.  
  388.   return(eventProcessed);
  389. } /* end ANotebookCommandHandler :: command(...) */
  390.