home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / HELLO6 / AHELLOW6.CPP < prev    next >
C/C++ Source or Header  |  1995-05-01  |  76KB  |  1,002 lines

  1. /*****************************************************************************
  2. * HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (ahellow6.cpp)*
  3. *                                                                            *
  4. * COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
  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. /**************************************************************************   V1
  17. * C++ Hello World History and Key Functions:                              *   V1
  18. *   Version 1: (lines with V1 in column 79-80)                            *   V1
  19. *      - Creates and runs a simple application                            *   V1
  20. *      - Creates the main window (IFrameWindow)                           *   V1
  21. *      - Creates a static text control set to "Hello, World!!!" as the    *   V1
  22. *         client window                                                   *   V1
  23. *                                                                         *   V2
  24. *   Version 2: (lines with V2 in column 79-80)                            *   V2
  25. *      - Creates a main window (AHellowWindow) derived from IFrameWindow  *   V2
  26. *      - Gets the "Hello, World!!!" text string and other items from a    *   V2
  27. *         resource file                                                   *   V2
  28. *      - Sets the window title from a resource file                       *   V2
  29. *      - Creates and sets the information area below the client window    *   V2
  30. *                                                                         *   V3
  31. *   Version 3: (lines with V3 in column 79-80)                            *   V3
  32. *      - Adds alignment menu bar with left, center, and right menu items  *   V3
  33. *      - Adds command processing for aligning the                         *   V3
  34. *         "Hello, World!!!" text                                          *   V3
  35. *      - Places check mark in front of selected menu item                 *   V3
  36. *      - Creates and maintains current alignment status line              *   V3
  37. *                                                                         *   V4
  38. *   Version 4: (lines with V4 in column 79-80)                            *   V4
  39. *      - Adds accelerator keys for Left (F7), Center(F8), Right(F9)       *   V4
  40. *      - Modifies left, center and right menu items to show function keys *   V4
  41. *      - Modifies menu bar to create edit menu and "Text..." menu item    *   V4
  42. *      - Adds ADialogText to allow user to change "Hello, World!!!" text  *   V4
  43. *      - Adds push buttons to an ISetCanvas for changing text alignment   *   V4
  44. *                                                                         *   V5
  45. *   Version 5: (lines with V5 in column 79-80)                            *   V5
  46. *      - Uses a vertical split canvas as the client window                *   V5
  47. *      - Adds a horizontal split canvas as the left side of the client    *   V5
  48. *      - Adds the hello static text to the top of the horiz. split canvas *   V5
  49. *      - Adds a new control (AEarthWindow) using native graphics calls    *   V5
  50. *      - Adds AEarthWindow to the bottom of the horizontal split canvas   *   V5
  51. *      - Adds a list box to the right side of the vertical split canvas   *   V5
  52. *      - Adds help windows for the main, dialog, and entry field windows  *   V5
  53. *                                                                         *   V6
  54. *   Version 6: (lines with V6 in column 79-80)                            *   V6
  55. *      - Adds a vertical split canvas for combining the status line with  *   V6
  56. *          a running date and time                                        *   V6
  57. *      - Adds AHelloTimeHandler from ATimeHandler to update time & date   *   V6
  58. *      - Adds setHelloFont function that uses a font dialog to change     *   V6
  59. *          the Hello World font.                                          *   V6
  60. *      - Adds ANotebookWindow class that uses a notebook control for      *   V6
  61. *          changing earthWindow and date and time settings                *   V6
  62. *      - Adds two pop-up menus for changing user settings                 *   V6
  63. *      - Uses a profile from IProfile class to save and read user         *   V6
  64. *          settings                                                       *   V6
  65. *      - Changes the entry field in the text dialog to a combo box        *   V6
  66. **************************************************************************/
  67. //Include User Interface Class Library class headers:
  68. #include <iapp.hpp>                     //IApplication class                  V1
  69. #include <ifont.hpp>                    //IFont class                         V3
  70. #include <istring.hpp>                  //IString class                       V4
  71. #include <idate.hpp>                    //IDate class                         V6
  72. #include <itime.hpp>                    //ITime class                         V6
  73. #include <imsgbox.hpp>                  //IMessageBox class                   V6
  74. #include <iprofile.hpp>                 //IProfile class                      V6
  75. #include <ifontdlg.hpp>                 //IFontDialog class                   V6
  76.  
  77. #include "aearthw6.hpp"                 //AEarthWindow class                  v6
  78. #include "ahellow6.hpp"                 //Include AHelloWindow class headers  v6
  79. #include "ahellow6.h"                   //Include symbolic definitions        v6
  80. #include "adialog6.hpp"                 //Include ATextDialog class           v6
  81. #define HELP_LIBRARIES "ahellow6.hlp"   //Define help window libraries file   V6
  82. #define APPLICATION_NAME "Hello6"       //Define user profile application     V6
  83.                                         //  name and file name                V6
  84.  
  85. /**************************************************************************   V1
  86. * main  - Application entry point for Hello World Version 6.              *   v6
  87. *         This simple application does the following:                     *   V1
  88. *           1) Creates a new object mainWindow of class AHelloWindow      *   v2
  89. *           2) Sets Hello World window alignment                          *   V3
  90. *           3) Sets the size of mainWindow                                *   v3
  91. *           4) Sets the window focus to mainWindow                        *   v3
  92. *           5) Displays the mainWindow                                    *   v3
  93. *           6) Starts the events processing for the application           *   v3
  94. **************************************************************************/
  95. int main()                                                                 //V1
  96. {                                                                           //V1
  97.   AHelloWindow mainWindow (WND_MAIN);                                       //v2
  98.   mainWindow.setAlignment(AHelloWindow::left);                              //V3
  99.   mainWindow.sizeTo(ISize(400,300));                                        //V1
  100.   mainWindow.setFocus();                                                    //V1
  101.   mainWindow.show();                                                        //V1
  102.   IApplication::current().run();                                            //V1
  103.  
  104.   return 0;
  105. } /* end main */                                                            //V1
  106.  
  107. /**************************************************************************   V2
  108. * AHelloWindow :: AHelloWindow - Constructor for the main window          *   V2
  109. * Construct the IFrameWindow using the default style plus minimizedIcon,  *   V2
  110. *   which gets the Icon identified in the resource file and associates it *   V2
  111. *   with the main window.  The accelerator style causes the accelerator   *   v4
  112. *   table to be loaded from the resource file.                            *   V4
  113. *  Create a menu bar object for the main window menu bar that was loaded  *   V3
  114. *    from the resource file.  menuBar is used by setAlignment to          *   V3
  115. *    manipulate check marks on the menu items.                            *   V3
  116. *  Create the statusCanvas split canvas making the AHelloWindow its       *   V6
  117. *    parent window and let its orientation default to vertical.           *   V6
  118. *  Create a static text object for displaying the status of the           *   V3
  119. *    Hello World text alignment and make it the first child of the        *   v6
  120. *    statusCanvas.  It will be the leftmost window of the statusCanvas.   *   V6
  121. *  Create static text objects for displaying the date and time and        *   V6
  122. *    make them children of the statusCanvas.  The date will be in the     *   V6
  123. *    center window of the canvas while the time will be on the right.     *   V6
  124. *  Create the clientWindow split canvas to be used as the client window   *   V5
  125. *    of this frame and let its orientation default to vertical.           *   V5
  126. *  Create the helloCanvas split canvas making the clientWindow its parent *   V5
  127. *    window and orient it horizontally.                                   *   V5
  128. *  Create the hello and earthWindow static text objects as children of    *   v5
  129. *    the helloCanvas.  hello is placed in the topmost window of the       *   V5
  130. *    horizontal split canvas because it is created first.  earthWindow    *   V5
  131. *    is placed in the bottom window of the split canvas.                  *   V5
  132. *  Create the listBox window making the clientWindow its parent window    *   V5
  133. *    and enabling it for tabbing and preventing it from being resized     *   V5
  134. *    due to an item being too long.  helloCanvas is placed in the         *   V5
  135. *    leftmost window of the vertical split canvas because it is created   *   V5
  136. *    first.  listBox is placed in the right window of the split canvas.   *   V5
  137. *  Create a set canvas that will contain the push buttons and will be     *   V4
  138. *    added to the frame as an extension.                                  *   V4
  139. *  Create each push button with the set canvas as parent and owner.       *   V4
  140. *  Additionally for Help, specify help style and noPointerFocus style.    *   V5
  141. *    noPointerFocus prevents the mouse from changing the input focus      *   V5
  142. *    to the Help push button when you select it using the mouse.  This    *   V5
  143. *    allows you to use contextual help for the control with the input     *   V5
  144. *    focus rather than for the Help push button itself.                   *   V5
  145. *  Create the Hello World information area object from IInfoArea class.   *   V2
  146. *    The information area is automatically added as an extension below    *   V2
  147. *    the client window of the frame.                                      *   V2
  148. *  Create a command handler to process command events from menu item,     *   v4
  149. *    push button, and accelerator key selections.                         *   v4
  150. *  Create a select handler to process selections made in the list box.    *   V5
  151. *  Create an IHelpWindow object that is displayed when help is requested  *   V5
  152. *    from a help menu item, the help push button, or the help accelerator *   V5
  153. *    key, normally F1.                                                    *   V5
  154. *  An IHelpHandler object, helpHandler is created implicitly, see class   *   V5
  155. *    definition for AHelloWindow in ahellow5.hpp.                         *   V5
  156. *  Initialize the date and time boolean objects that contain the state of *   V6
  157. *    the data and time formats.                                           *   V6
  158. *  Create the pop-up menu for the hello window as a data member of        *   V6
  159. *    AHelloWindow class.                                                  *   V6
  160. *    (Refer to the APopUpHandler::makePopUpMenu function in this file     *   V6
  161. *    for an example of a dynamically created pop-up menu.)                *   V6
  162. **************************************************************************/ //V2
  163.  
  164. AHelloWindow :: AHelloWindow(unsigned long windowId)                        //V2
  165.   : IFrameWindow(IFrameWindow::defaultStyle() |                             //V2
  166.                  IFrameWindow::minimizedIcon  |                             //v4
  167.                  IFrameWindow::accelerator,                                 //V4
  168.                  windowId)                                                  //V2
  169.    ,menuBar(windowId, this)                                                 //V3
  170.    ,statusCanvas(WND_STATUSCANVAS,this, this)                               //V6
  171.    ,statusLine(WND_STATUS, &statusCanvas, &statusCanvas)                    //v6
  172.    ,statusDate(WND_DATE, &statusCanvas, &statusCanvas)                      //V6
  173.    ,statusTime(WND_TIME, &statusCanvas, &statusCanvas)                      //V6
  174.    ,clientWindow(WND_CANVAS, this, this)                                    //V5
  175.    ,helloCanvas(WND_HCANVAS, &clientWindow, &clientWindow, IRectangle(),    //V5
  176.                 IWindow::visible | ISplitCanvas::horizontal)                //V5
  177.    ,hello(WND_HELLO, &helloCanvas, &helloCanvas)                            //v5
  178.    ,earthWindow(WND_EARTH, &helloCanvas)                                    //V5
  179.    ,listBox(WND_LISTBOX, &clientWindow, &clientWindow, IRectangle(),        //V5
  180.                 IListBox::defaultStyle() |                                  //V5
  181.                 IControl::tabStop |                                         //V5
  182.                 IListBox::noAdjustPosition)                                 //V5
  183.    ,buttons(WND_BUTTONS, this, this)                                        //V4
  184.    ,leftButton(MI_LEFT, &buttons, &buttons)                                 //V4
  185.    ,centerButton(MI_CENTER, &buttons, &buttons)                             //V4
  186.    ,rightButton(MI_RIGHT, &buttons, &buttons)                               //V4
  187.    ,helpButton(MI_HELP, &buttons, &buttons, IRectangle(),                   //V5
  188.                 IPushButton::defaultStyle() |                               //V5
  189.                 IPushButton::help | IButton::noPointerFocus)                //V5
  190.    ,infoArea(this)                                                          //V2
  191.    ,commandHandler(this)                                                    //V3
  192.    ,selectHandler(this)                                                     //V5
  193.    ,helpWindow(HELP_TABLE,this)                                             //V5
  194.    ,dateLong(false)                                                         //V6
  195.    ,timeLong(true)                                                          //V6
  196.    ,helloPopUpMenu(WND_HELLOPOPUP, &hello)                                  //V6
  197.    ,settingsNotebook( 0 )                                                   //V6
  198. {                                                                           //V2
  199. /*------------------------- Setup the Client Window ----------------------|   V5
  200. |  Set the clientWindow split canvas as the client window for the         |   V5
  201. |    AHelloWorld frame.                                                   |   V5
  202. |  Set the HelloCanvas object to occupy 60% of the client canvas.         |   V5
  203. |  Set the list box object to occupy 40% of the client canvas.            |   V5
  204. |------------------------------------------------------------------------*/ //V5
  205.   setClient(&clientWindow);                                                 //V5
  206.   clientWindow.setSplitWindowPercentage(&helloCanvas, 60);                  //V5
  207.   clientWindow.setSplitWindowPercentage(&listBox, 40);                      //V5
  208.  
  209. /*------------------------- Setup the Status Area ------------------------|   v6
  210. |  Add the status area as an extension to the frame above the client      |   v6
  211. |    window with the height calculated from the maximum height of a       |   V3
  212. |    character in the current font.                                       |   V3
  213. |  Start processing timer events for updating the time.                   |   V6
  214. |------------------------------------------------------------------------*/ //V3
  215.   addExtension(&statusCanvas, IFrameWindow::aboveClient,                    //v6
  216.                  IFont(&statusLine).maxCharHeight());                       //V3
  217.   timeHandler.handleEventsFor(this);                                        //V6
  218.  
  219. /*-------------------------- Setup the List Box --------------------------|   V5
  220. |  Add the different language versions of Hello World to the list box in  |   V5
  221. |    ascending order.  Hello World text strings are stored in the         |   V5
  222. |    resource file with IDs beginning with HI_WORLD with each subsequent  |   V5
  223. |    ID incremented up to HI_WORLD + HI_COUNT - 1.                        |   V5
  224. |  Have the select handler handle selections made in the list box.        |   V5
  225. |    The select handler's selected() function is called to process        |   V5
  226. |    list box selections.                                                 |   V5
  227. |------------------------------------------------------------------------*/ //V5
  228.   for (int i=0;i<HI_COUNT;i++ )                                             //V5
  229.      listBox.addAscending(HI_WORLD+i);                                      //V5
  230.   selectHandler.handleEventsFor(&listBox);                                  //V5
  231.  
  232. /*---------------------- Setup the Information Area ----------------------|   V5
  233. |  Change the size of the information area using the maximum height of    |   V5
  234. |    a character in the current font.                                     |   V5
  235. |------------------------------------------------------------------------*/ //V5
  236.   setExtensionSize(&infoArea, IFont(&infoArea).maxCharHeight());            //V5
  237.  
  238. /*---------------------------- Set Text Values ---------------------------|   V2
  239. |  Set the values for the text controls from strings in the resource file.|   V2
  240. |    The infoArea inactive text is displayed when no menu item is active. |   V2
  241. |------------------------------------------------------------------------*/ //V2
  242.   hello.setText(STR_HELLO);                                                 //V2
  243.   leftButton.setText(STR_LEFTB);                                            //V4
  244.   centerButton.setText(STR_CENTERB);                                        //V4
  245.   rightButton.setText(STR_RIGHTB);                                          //V4
  246.   helpButton.setText(STR_HELPB);                                            //V5
  247.   infoArea.setInactiveText(STR_INFO);                                       //V2
  248.  
  249. /*------------------- Setup Push Buttons Set Canvas ----------------------|   V4
  250. |  Set the canvas margins and padding between buttons to zero.            |   V4
  251. |  Add the set canvas that contains the push buttons to the frame window  |   V4
  252. |    as an extension immediately below the client window with a height    |   V4
  253. |    equal to the minimum height of the push buttons.  You must set the   |   V4
  254. |    text in the push buttons first.                                      |   V4
  255. |------------------------------------------------------------------------*/ //V4
  256.   leftButton.enableTabStop();                                               //V4
  257.   buttons.setMargin(ISize());                                               //V4
  258.   buttons.setPad(ISize());                                                  //V4
  259.   addExtension(&buttons, IFrameWindow::belowClient,                         //V4
  260.                 (unsigned long)buttons.minimumSize().height());             //V4
  261.  
  262. /*----------------------- Setup the Command Handler ----------------------|   V3
  263. |  Have the command handler handle commands sent from the frame window.   |   V3
  264. |    The command handler's command() function is called to process        |   V3
  265. |    menu item, push button, and accelerator key selections.              |   v5
  266. |  Attach the command handler to the hello and earthWindow static text    |   V6
  267. |    windows to handle command events generated for these windows by      |   V6
  268. |    the pop-up menus.                                                    |   V6
  269. |  Attach the pop-up menu handler to the hello and earthWindow static text|   V6
  270. |    windows to handle pop-up menu requests made while the pointer is     |   V6
  271. |    over these windows.  The makePopUpMenu function will be called when  |   V6
  272. |    the user requests a pop-up menu using the mouse in these windows.    |   V6
  273. |------------------------------------------------------------------------*/ //V3
  274.   commandHandler.handleEventsFor(this);                                     //V3
  275.   commandHandler.handleEventsFor(&hello);                                   //V6
  276.   commandHandler.handleEventsFor(&earthWindow);                             //V6
  277.   popUpHandler.handleEventsFor(&hello);                                     //V6
  278.   popUpHandler.handleEventsFor(&earthWindow);                               //V6
  279.  
  280. /*---------------------------- Setup Help --------------------------------|   V5
  281. |   Add the help library to the help window using addLibraries().         |   V5
  282. |   Set the help window title from a string in the resource file.         |   V5
  283. |   Begin handling help events for the frame window.                      |   V5
  284. |------------------------------------------------------------------------*/ //V5
  285.    try                                                                      //V5
  286.    {                                                                        //V5
  287.       helpWindow.addLibraries( HELP_LIBRARIES );                            //V5
  288.       helpWindow.setTitle(STR_HTITLE);                                      //V5
  289.       helpHandler.handleEventsFor(this);                                    //V5
  290.    }                                                                        //V5
  291.    catch( ... )                                                             //V5
  292.    {                                                                        //V5
  293.       IMessageBox                                                           //V5
  294.          msgBox( this );                                                    //V5
  295.       msgBox.show( STR_HELP_NOT_FOUND, IMessageBox::warning );              //V5
  296.    }                                                                        //V5
  297.  
  298. /*----------------------- Set Default Alignment --------------------------|   V2
  299. | Align the static text, set the status line, and set the check mark in   |   v3
  300. |   the menu bar.                                                         |   v3
  301. |------------------------------------------------------------------------*/ //V2
  302.   setAlignment(center);                                                     //v3
  303.  
  304. } /* end AHelloWindow :: AHelloWindow(...) */                               //V2
  305.  
  306. /**************************************************************************   V3
  307. * AHelloWindow :: ~AHelloWindow - Destructor for the main window          *   V3
  308. *   Stop handling command events for the frame.                           *   V3
  309. *   Stop handling select events for the list box.                         *   V5
  310. *   Stop handling help events for the frame.                              *   V5
  311. *   Stop handling timer events for the frame.                             *   V6
  312. *   Stop handling menu events for the frame.                              *   V6
  313. **************************************************************************/ //V3
  314. AHelloWindow :: ~AHelloWindow()                                             //V3
  315. {                                                                           //V3
  316.   commandHandler.stopHandlingEventsFor(this);                               //V3
  317.   commandHandler.stopHandlingEventsFor(&earthWindow);                       //V6
  318.   commandHandler.stopHandlingEventsFor(&hello);                             //V6
  319.   selectHandler.stopHandlingEventsFor(&listBox);                            //V5
  320.   helpHandler.stopHandlingEventsFor(this);                                  //V5
  321.  
  322.   popUpHandler.stopHandlingEventsFor(&hello);                               //V6
  323.   popUpHandler.stopHandlingEventsFor(&earthWindow);                         //V6
  324.  
  325. } /* end AHelloWindow :: ~AHelloWindow() */                                 //V3
  326.  
  327. /**************************************************************************   V3
  328. * AHelloWindow :: setAlignment - Align static text in client window       *   V3
  329. **************************************************************************/ //V3
  330. AHelloWindow &                                                              //V3
  331.   AHelloWindow :: setAlignment(Alignment alignment)                         //V3
  332. {                                                                           //V3
  333. /*--------------------- Update Window for New Alignment ------------------|   V3
  334. |  Depending on the value passed, update the window as follows:           |   V3
  335. |    Set the alignment of the static text control in the client window.   |   V3
  336. |    Set the text of the alignment status line static text control.       |   V3
  337. |    Check the selected menu item; remove check marks from the other two. |   V3
  338. |------------------------------------------------------------------------*/ //V3
  339.   switch(alignment)                                                         //V3
  340.   {                                                                         //V3
  341.   case left:                                                                //V3
  342.     hello.setAlignment(                                                     //V3
  343.      IStaticText::centerLeft);                                              //V3
  344.     statusLine.setText(STR_LEFT);                                           //V3
  345.     menuBar.uncheckItem(MI_CENTER);                                         //V3
  346.     menuBar.checkItem(MI_LEFT);                                             //V3
  347.     menuBar.uncheckItem(MI_RIGHT);                                          //V3
  348.     break;                                                                  //V3
  349.   case center:                                                              //V3
  350.     hello.setAlignment(                                                     //V3
  351.       IStaticText::centerCenter);                                           //V3
  352.     statusLine.setText(STR_CENTER);                                         //V3
  353.     menuBar.checkItem(MI_CENTER);                                           //V3
  354.     menuBar.uncheckItem(MI_LEFT);                                           //V3
  355.     menuBar.uncheckItem(MI_RIGHT);                                          //V3
  356.     break;                                                                  //V3
  357.  case right:                                                                //V3
  358.     hello.setAlignment(                                                     //V3
  359.       IStaticText::centerRight);                                            //V3
  360.     statusLine.setText(STR_RIGHT);                                          //V3
  361.     menuBar.uncheckItem(MI_CENTER);                                         //V3
  362.     menuBar.uncheckItem(MI_LEFT);                                           //V3
  363.     menuBar.checkItem(MI_RIGHT);                                            //V3
  364.     break;                                                                  //V3
  365.  }                                                                          //V3
  366.  return (*this);                        //Return a reference to the frame     V3
  367.  
  368. } /* end AHelloWindow :: setAlignment(...) */                               //V3
  369.  
  370. /**************************************************************************   V4
  371. * AHelloWindow :: editText                                                *   V4
  372. *   Create and show a dialog window for inputting text that will be used  *   V4
  373. *   to replace the "Hello World!!!" static text string.                   *   V4
  374. **************************************************************************/ //V4
  375. AHelloWindow &                                                              //V4
  376.   AHelloWindow :: editText()                                                //V4
  377. {                                                                           //V4
  378. /*----------------------- Setup for Displaying Dialog --------------------|   V4
  379. |  Store the current value of the text to be changed.                     |   V4
  380. |  Set the text in the information area from the dialog information       |   V4
  381. |    string in the resource file.                                         |   V4
  382. |------------------------------------------------------------------------*/ //V4
  383.   IString textValue(hello.text());                                          //V4
  384.   infoArea.setInactiveText(STR_INFODLG);                                    //V4
  385.  
  386. /*------------------------ Create and Show Dialog ------------------------|   V4
  387. |  Create a new text dialog with textValue as the string to edit and      |   V4
  388. |    AHelloWindow as the owner window.                                    |   V4
  389. |  Show the dialog modally.  This means that the owner window cannot have |   V4
  390. |    the focus back until the dialog is ended.                            |   V4
  391. |------------------------------------------------------------------------*/ //V4
  392.   ATextDialog textDialog(textValue,this);                                   //V4
  393.   textDialog.showModally();                                                 //V4
  394.  
  395. /*------------------------ Process Dialog Result -------------------------|   V4
  396. |  If the OK button was used to end the dialog, then the static text,     |   V4
  397. |    hello, is set to the textValue string.  Else, it is not changed.     |   V4
  398. |  Reset the information area inactive text.                              |   V4
  399. |------------------------------------------------------------------------*/ //V4
  400.   if (textDialog.result() == DID_OK)                                        //V4
  401.         hello.setText(textValue);                                           //V4
  402.   infoArea.setInactiveText(STR_INFO);                                       //V4
  403.  
  404.   return (*this);                       //Return a reference to the frame     V4
  405. }  /* end AHelloWindow :: editText() */                                     //V4
  406.  
  407. /**************************************************************************   V5
  408. * AHelloWindow :: setTextFromListBox                                      *   V5
  409. *   Public function used by non-AHelloWindow functions to set the Hello   *   V5
  410. *   World text from the first selected item in the AHelloWindow listBox.  *   V5
  411. **************************************************************************/ //V5
  412. AHelloWindow &                                                              //V5
  413.   AHelloWindow :: setTextFromListBox()                                      //V5
  414. {                                                                           //V5
  415.  
  416. /*---------------------- Set Hello Text from ListBox ---------------------|   V5
  417. |  Create a cursor to the list box.  Using the default filter for a       |   V5
  418. |    list box cursor, selectedItems, causes the setToFirst() function     |   V5
  419. |    to position the cursor to the first selected item.                   |   V5
  420. |  Set the hello IStaticText control text value.                          |   V5
  421. |------------------------------------------------------------------------*/ //V5
  422.   IListBox::Cursor lbCursor(listBox);                                       //V5
  423.   lbCursor.setToFirst();                                                    //V5
  424.   hello.setText(listBox.elementAt(lbCursor));                               //V5
  425.  
  426.   return (*this);                       //Return a reference to the frame     V5
  427. }  /* end AHelloWindow :: setTextFromListBox() */                           //V5
  428.  
  429. /**************************************************************************   V6
  430. * AHelloWindow :: setHelloFont                                            *   V6
  431. *   Public function used by non-AHelloWindow functions to start a         *   V6
  432. *     font dialog for changing the font of the Hello World text.          *   V6
  433. **************************************************************************/ //V6
  434. AHelloWindow &                                                              //V6
  435.   AHelloWindow :: setHelloFont()                                            //V6
  436. {                                                                           //V6
  437. /*------------------------- Start the Font Dialog ------------------------|   V6
  438. |  Set the text in the information area from the font dialog information  |   V6
  439. |    string in the resource file.                                         |   V6
  440. |  Create a font from the current font of the hello static text object.   |   V6
  441. |  Create a font settings object from the tempFont object.                |   V6
  442. |  Set the title to be used in the font dialog from a string resource in  |   V6
  443. |    the resource file.                                                   |   V6
  444. |  Start the font dialog by creating an IFontDialog object.  The font     |   V6
  445. |    dialog is created as a modal dialog window with the desktopWindow    |   V6
  446. |    as the parent, the AHelloWindow frame as the owner, resetButton      |   V6
  447. |    style which supplies the user with a way to reset the fields in the  |   V6
  448. |    dialog, and the font settings that were just created.                |   V6
  449. |------------------------------------------------------------------------*/ //V6
  450.   infoArea.setInactiveText(STR_FONTDLGT);                                   //V6
  451.   IFont tempFont(&hello);                                                   //V6
  452.   IFontDialog::Settings fontSettings(&tempFont);                            //V6
  453.   fontSettings.setTitle(IResourceId(STR_FONTDLGT));                         //V6
  454.   IFontDialog fontDialog( desktopWindow(), this,                            //V6
  455.                           IFontDialog::resetButton, fontSettings);          //V6
  456. /*---------------------------- Change the Font ---------------------------|   V6
  457. |  If the user pressed OK in the font dialog, then change the font for    |   V6
  458. |    the hello IStaticText object using the tempFont object that was set  |   V6
  459. |    by the font dialog.                                                  |   V6
  460. |  Reset the information area inactive text.                              |   V6
  461. |------------------------------------------------------------------------*/ //V6
  462.   if (fontDialog.pressedOK())                                               //V6
  463.   {                                                                         //V6
  464.     hello.setFont(tempFont);                                                //V6
  465.   }                                                                         //V6
  466.   infoArea.setInactiveText(STR_INFO);                                       //V6
  467.   return (*this);                       //Return a reference to the frame     V6
  468. }  /* end AHelloWindow :: setHelloFont() */                                 //V6
  469.  
  470. /**************************************************************************   V6
  471. * AHelloWindow :: readHelloSettings                                       *   V6
  472. *   Public function used by non-AHelloWindow functions to read in user    *   V6
  473. *     settings from an IProfile class profile.                            *   V6
  474. **************************************************************************/ //V6
  475. AHelloWindow &                                                              //V6
  476.   AHelloWindow :: readHelloSettings()                                       //V6
  477. {                                                                           //V6
  478. /*---------------------------- Try Not to Fail ---------------------------|   V6
  479. |  The try-catch blocks are used to prevent a missing profile from        |   V6
  480. |    abending the program.                                                |   V6
  481. |------------------------------------------------------------------------*/ //V6
  482.   try                                                                       //V6
  483.   {                                                                         //V6
  484. /*--------------------------- Open the Profile ---------------------------|   V6
  485. |  A file named Hello6.ini.iclDB on AIX, or Hello6.ini on OS/2, is        |   V6
  486. |   is expected to exist, and if so, will be opened and the default       |   V6
  487. |   application name, Hello6, is set.                                     |   V6
  488. |------------------------------------------------------------------------*/ //V6
  489.     IProfile profile(IString(APPLICATION_NAME)+".ini");                     //V6
  490.     profile.setDefaultApplicationName(APPLICATION_NAME);                    //V6
  491.  
  492. /*------------------- Read the Profile and Modify Settings ---------------|   V6
  493. |  Each Hello6 element in the profile is read using the elementWithKey or |   V6
  494. |    integerWithKey function, where element is used for reading strings   |   V6
  495. |    and integer is used for values.  The elements are identified using   |   V6
  496. |    unique names that are defined by this application.                   |   V6
  497. |  The appropriate AHelloWindow function is called to set the date and    |   V6
  498. |    time formats.  The arguments for the functions are integers,         |   V6
  499. |    representing true(1) and false(0).                                   |   V6
  500. |  The Font... settings are used to reset the AHelloWindow::hello         |   V6
  501. |    static text window font.                                             |   V6
  502. |  The appropriate AEarthWindow functions are called to set the painting  |   V6
  503. |    settings for the Earth window.                                       |   V6
  504. |------------------------------------------------------------------------*/ //V6
  505.     enableDateLong(profile.integerWithKey("DateLong"));                     //V6
  506.     enableTimeLong(profile.integerWithKey("TimeLong"));                     //V6
  507.  
  508. IFont                                                                       //V6
  509.     helloFont(&hello);                                                      //V6
  510.     helloFont.useVectorOnly(profile.integerWithKey("FontVector"));          //V6
  511.     helloFont.useNonPropOnly(profile.integerWithKey("FontNonProp"));        //V6
  512.     helloFont.setName(profile.elementWithKey("FontFace"));                  //V6
  513.     helloFont.setPointSize(profile.integerWithKey("FontSize"));             //V6
  514.     helloFont.setBold(profile.integerWithKey("FontBold"));                  //V6
  515.     helloFont.setItalic(profile.integerWithKey("FontItalic"));              //V6
  516.     hello.setFont(helloFont);                                               //V6
  517.  
  518.     earth()->enableTwinkle(profile.integerWithKey("Twinkling"));            //V6
  519.     earth()->enableBright(profile.integerWithKey("Bright"));                //V6
  520.     earth()->setLayers(profile.integerWithKey("Layers"));                   //V6
  521.  
  522. long                                                                        //V6
  523.     hue=profile.integerWithKey("EarthColor");                               //V6
  524.     if (hue==IColor(IColor::green).asRGBLong())                             //V6
  525.       { earth()->setEarthColor(IColor(IColor::green)); }                    //V6
  526.     else if (hue==IColor(IColor::white).asRGBLong())                        //V6
  527.       { earth()->setEarthColor(IColor(IColor::white)); }                    //V6
  528.     else if (hue==IColor(IColor::yellow).asRGBLong())                       //V6
  529.       { earth()->setEarthColor(IColor(IColor::yellow)); }                   //V6
  530.     else                                                                    //V6
  531.       { earth()->setEarthColor(IColor(IColor::cyan)); }                     //V6
  532.  
  533. /*------------------------ Tell User Read Worked -------------------------|   V6
  534. |  A message box with an ok button is used to inform the user that the    |   V6
  535. |    read settings function completed successfully.            .          |   V6
  536. |------------------------------------------------------------------------*/ //V6
  537.     IMessageBox mbox(this);                                                 //V6
  538.     mbox.setTitle(WND_MAIN).show(STR_READOK,IMessageBox::okButton);         //V6
  539.   }                                                                         //V6
  540.   catch (IException& exc)                                                   //V6
  541.   {                                                                         //V6
  542. /*------------------------ Tell User Read Failed -------------------------|   V6
  543. |  A default exception message box is used to inform the user that the    |   V6
  544. |    read settings function failed.                            .          |   V6
  545. |------------------------------------------------------------------------*/ //V6
  546.     IMessageBox mbox(this);                                                 //V6
  547.     mbox.show(exc);                                                         //V6
  548.   }                                                                         //V6
  549.   return (*this);                       //Return a reference to the frame     V6
  550. }  /* end AHelloWindow :: readHelloSettings() */                            //V6
  551.  
  552. /**************************************************************************   V6
  553. * AHelloWindow :: saveHelloSettings                                       *   V6
  554. *   Public function used by non-AHelloWindow functions to save user       *   V6
  555. *     settings in an IProfile class profile.                              *   V6
  556. **************************************************************************/ //V6
  557. AHelloWindow &                                                              //V6
  558.   AHelloWindow :: saveHelloSettings()                                       //V6
  559. {                                                                           //V6
  560. /*---------------------------- Try Not to Fail ---------------------------|   V6
  561. |  The try-catch blocks are used to prevent a profile error from          |   V6
  562. |    abending the program.                                                |   V6
  563. |------------------------------------------------------------------------*/ //V6
  564.   try                                                                       //V6
  565.   {                                                                         //V6
  566. /*--------------------------- Open the Profile ---------------------------|   V6
  567. |  A file named Hello6.ini.iclDB on AIX, or Hello6.ini on OS/2, is        |   V6
  568. |   is opened, if found, or created, if not found, and the default        |   V6
  569. |   application name, Hello6, is set.                                     |   V6
  570. |------------------------------------------------------------------------*/ //V6
  571.     IProfile profile(IString(APPLICATION_NAME)+".ini");                     //V6
  572.     profile.setDefaultApplicationName(APPLICATION_NAME);                    //V6
  573.  
  574. /*------------------- Save the User Settings in the Profile --------------|   V6
  575. |  The IProfile overloaded function, addOrReplaceElementWithKey, is used  |   V6
  576. |    to save each setting value in the profile.  Numeric and boolean      |   V6
  577. |    values are stored as long integers, while strings are stored as      |   V6
  578. |    character strings.                                                   |   V6
  579. |------------------------------------------------------------------------*/ //V6
  580.     profile.addOrReplaceElementWithKey(                                     //V6
  581.                     "DateLong", (long)isDateLong());                        //V6
  582.     profile.addOrReplaceElementWithKey(                                     //V6
  583.                     "TimeLong", (long)isTimeLong());                        //V6
  584.  
  585. IFont                                                                       //V6
  586.     helloFont(&hello);                                                      //V6
  587.     profile.addOrReplaceElementWithKey(                                     //V6
  588.                     "FontVector", helloFont.isVectorOnly());                //V6
  589.     profile.addOrReplaceElementWithKey(                                     //V6
  590.                     "FontNonProp", helloFont.isNonPropOnly());              //V6
  591.     profile.addOrReplaceElementWithKey(                                     //V6
  592.                     "FontFace", helloFont.name());                          //V6
  593.     profile.addOrReplaceElementWithKey(                                     //V6
  594.                     "FontSize", helloFont.pointSize());                     //V6
  595.     profile.addOrReplaceElementWithKey(                                     //V6
  596.                     "FontBold", helloFont.isBold());                        //V6
  597.     profile.addOrReplaceElementWithKey(                                     //V6
  598.                     "FontItalic", helloFont.isItalic());                    //V6
  599.  
  600.     profile.addOrReplaceElementWithKey(                                     //V6
  601.                     "Twinkling",(long)earth()->isTwinkling());              //V6
  602.     profile.addOrReplaceElementWithKey(                                     //V6
  603.                     "Bright",   (long)earth()->isBright());                 //V6
  604.     profile.addOrReplaceElementWithKey(                                     //V6
  605.                     "Layers",   (long)earth()->layers());                   //V6
  606.     profile.addOrReplaceElementWithKey(                                     //V6
  607.                     "EarthColor",earth()->earthColor().asRGBLong());        //V6
  608.  
  609. /*------------------------ Tell User Read Worked -------------------------|   V6
  610. |  A message box with an ok button is used to inform the user that the    |   V6
  611. |    save settings function completed successfully.            .          |   V6
  612. |------------------------------------------------------------------------*/ //V6
  613.     IMessageBox mbox(this);                                                 //V6
  614.     mbox.setTitle(WND_MAIN).show(STR_SAVEDOK,IMessageBox::okButton);        //V6
  615.   }                                                                         //V6
  616.   catch (IException& exc)                                                   //V6
  617.   {                                                                         //V6
  618. /*------------------------ Tell User Read Failed -------------------------|   V6
  619. |  A default exception message box is used to inform the user that the    |   V6
  620. |    save settings function failed.                            .          |   V6
  621. |------------------------------------------------------------------------*/ //V6
  622.     IMessageBox mbox(this);                                                 //V6
  623.     mbox.show(exc);                                                         //V6
  624.   }                                                                         //V6
  625.  
  626.   return (*this);                       //Return a reference to the frame     V6
  627. }  /* end AHelloWindow :: saveHelloSettings() */                            //V6
  628.  
  629. /**************************************************************************   V6
  630. * AHelloWindow :: openHelloSettings                                       *   V6
  631. *   Public function used by non-AHelloWindow functions to open a settings *   V6
  632. *     notebook for changing Hello World window attributes.                *   V6
  633. **************************************************************************/ //V6
  634. AHelloWindow &                                                              //V6
  635.   AHelloWindow :: openHelloSettings()                                       //V6
  636. {                                                                           //V6
  637. /*----------------------- Is Notebook Already Created --------------------|   V6
  638. |  Check if the notebook already exists.                                  |   V6
  639. |    Zero is returned if the notebook does not exist.                     |   V6
  640. |------------------------------------------------------------------------*/ //V6
  641.  
  642.   if ( settingsNotebook )                                                   //V6
  643.   {                                                                         //V6
  644.     delete settingsNotebook;                                                //V6
  645.   }                                                                         //V6
  646.  
  647.  
  648. /*----------------- Dynamically Create the Settings Notebook -------------|   V6
  649. |  Using the new operator causes the ANotebookWindow object to be         |   V6
  650. |    dynamically allocated.  This means that that the object will not go  |   V6
  651. |    out of scope, therefore the application should delete it when it is  |   V6
  652. |    finished with it.                                                    |   V6
  653. |------------------------------------------------------------------------*/ //V6
  654.  
  655.   settingsNotebook = new ANotebookWindow(WND_NOTEBOOKFRAME,this);           //V6
  656.  
  657. /*----------------------- Move/Show the Notebook -------------------------|   V6
  658. |  Move the notebook to ensure the entire window is visible on a small    |   V6
  659. |    display.                                                             |   V6
  660. |  The notebook is given control and shown by using setFocus and show.    |   V6
  661. |    The restore function is used in case the window was created          |   V6
  662. |    previously, but minimized.                                           |   V6
  663. |------------------------------------------------------------------------*/ //V6
  664.   settingsNotebook->moveTo( IPoint(50,50) );                                //V6
  665.   settingsNotebook->restore().setFocus().show();                            //V6
  666.   return (*this);                       //Return a reference to the frame     V6
  667. }  /* end AHelloWindow :: openHelloSettings() */                            //V6
  668.  
  669. /**************************************************************************   V3
  670. * ACommandHandler :: ACommandHandler - constructor for the command handler*   V3
  671. *       Construct the command handler from a pointer to the AHelloWindow  *   V3
  672. *       that events will be handled for.                                  *   V3
  673. **************************************************************************/ //V3
  674. ACommandHandler :: ACommandHandler(AHelloWindow *helloFrame)                //V3
  675. {                                                                           //V3
  676.    frame=helloFrame;                     //Save frame to be handled           V3
  677. } /* end ACommandHandler :: ACommandHandler(...) */                         //V3
  678.  
  679. /**************************************************************************   V3
  680. * ACommandHandler :: command                                              *   V3
  681. *   Handle menu and button commands                                       *   V4
  682. **************************************************************************/ //V3
  683. IBase::Boolean                                                              //V3
  684.   ACommandHandler :: command(ICommandEvent & cmdEvent)                      //V3
  685. {                                                                           //V3
  686.   Boolean eventProcessed(true);         //Assume event will be processed      V3
  687.  
  688. /*--------------------- Process command events ---------------------------|   V3
  689. |  Depending on the command event ID, call the AHelloWindow::setAlignment |   V3
  690. |    function with the appropriate AHelloWorld::Alignment value.          |   V3
  691. |  Do this except when the Text menu item is selected;                    |   V4
  692. |    then call the AHelloWindow::editText function for changing the       |   V4
  693. |    Hello World text using a dialog.                                     |   V4
  694. |------------------------------------------------------------------------*/ //V3
  695.   switch (cmdEvent.commandId()) {                                           //V3
  696.     case MI_CENTER:                                                         //V3
  697.       frame->setAlignment(AHelloWindow::center);                            //V3
  698.       break;                                                                //V3
  699.     case MI_LEFT:                                                           //V3
  700.       frame->setAlignment(AHelloWindow::left);                              //V3
  701.       break;                                                                //V3
  702.     case MI_RIGHT:                                                          //V3
  703.       frame->setAlignment(AHelloWindow::right);                             //V3
  704.       break;                                                                //V3
  705.     case MI_TEXT:                                                           //V4
  706.       frame->editText();                                                    //V4
  707.       break;                                                                //V4
  708.     case MI_FONT:                                                           //V6
  709.       frame->setHelloFont();                                                //V6
  710.       break;                                                                //V6
  711.     case MI_READSETS:                                                       //V6
  712.       frame->readHelloSettings();                                           //V6
  713.       break;                                                                //V6
  714.     case MI_OPENSETS:                                                       //V6
  715.       frame->openHelloSettings();                                           //V6
  716.       break;                                                                //V6
  717.     case MI_SAVESETS:                                                       //V6
  718.       frame->saveHelloSettings();                                           //V6
  719.       break;                                                                //V6
  720.     case MI_TWINKLE:                    //Toggle the twinkle setting          V6
  721.       frame->earth()->enableTwinkle(!frame->earth()->isTwinkling());        //V6
  722.       break;                                                                //V6
  723.     case MI_BRIGHT:                                                         //V6
  724.       frame->earth()->enableBright();                                       //V6
  725.       break;                                                                //V6
  726.     case MI_DIM:                                                            //V6
  727.       frame->earth()->disableBright();                                      //V6
  728.       break;                                                                //V6
  729.  
  730.     default:                            //Otherwise,                          V3
  731.       eventProcessed=false;             //  the event wasn't processed        V3
  732.   } /* end switch */                                                        //V3
  733.  
  734.   return(eventProcessed);                                                   //V3
  735. } /* end ACommandHandler :: command(...) */                                 //V3
  736.  
  737. /**************************************************************************   V5
  738. * ASelectHandler :: ASelectHandler - constructor for the select handler   *   V5
  739. *       Construct the select handler from a pointer to the AHelloWindow   *   V5
  740. *       that will be changed as a result of the selection.                *   V5
  741. **************************************************************************/ //V5
  742. ASelectHandler :: ASelectHandler(AHelloWindow *helloFrame)                  //V5
  743. {                                                                           //V5
  744.    frame=helloFrame;                     //Save frame to be handled           V5
  745. } /* end ASelectHandler :: ASelectHandler(...) */                           //V5
  746.  
  747.  
  748. /**************************************************************************   V5
  749. * ASelectHandler :: selected                                              *   V5
  750. *   Handle items selected within the list box.                            *   V5
  751. **************************************************************************/ //V5
  752. IBase::Boolean                                                              //V5
  753.   ASelectHandler :: selected(IControlEvent & evt)                           //V5
  754. {                                                                           //V5
  755.  
  756. /*---------------------- Call AHelloWindow Function ----------------------|   V5
  757. |  Call the AHelloWindow::setTextFromListBox function for the frame used  |   V5
  758. |    to construct this select handler.                                    |   V5
  759. |------------------------------------------------------------------------*/ //V5
  760.   frame->setTextFromListBox();                                              //V5
  761.  
  762.   return (true);                        //Event is always processed           V5
  763. } /* end ASelectHandler :: selected(...) */                                 //V5
  764.  
  765. /**************************************************************************   V5
  766. * AHelpHandler :: keysHelpId                                              *   V5
  767. *   Handle the keys help request event                                    *   V5
  768. *   This overrides the default action of setting the event result to      *   V5
  769. *     zero, which indicates that no action is required, that is, no       *   V5
  770. *     help information for keys is displayed.                             *   V5
  771. **************************************************************************/ //V5
  772. IBase::Boolean                                                              //V5
  773.   AHelpHandler :: keysHelpId(IEvent& evt)                                   //V5
  774. {                                                                           //V5
  775.   evt.setResult(1000);                  //1000=keys help ID in                V5
  776.                                         //  ahellow5.ipf file                 V5
  777.  
  778.   return (true);                        //Event is always processed           V5
  779. } /* end AHelpHandler :: keysHelpId(...) */                                 //V5
  780.  
  781. /**************************************************************************   V6
  782. * AHelloTimeHandler :: tick                                               *   V6
  783. *   Process ATimeHandler ticks by calling the AHelloWindow function       *   V6
  784. *     for updating the date and time.                                     *   V6
  785. **************************************************************************/ //V6
  786. IBase::Boolean                                                              //V6
  787.   AHelloTimeHandler::tick(IEvent& evt)                                      //V6
  788. {                                                                           //V6
  789.   ((AHelloWindow *)evt.window())->tickTime();                               //V6
  790.   return (true);                        //Event is always processed           V6
  791. } /* end AHelloTimeHandler :: tick(...) */                                  //V6
  792.  
  793. /**************************************************************************   V6
  794. * AHelloWindow :: tickTime                                                *   V6
  795. *   If the date or time in the status area have changed, update them      *   V6
  796. *     using the current formats.                                          *   V6
  797. **************************************************************************/ //V6
  798. AHelloWindow                                                                //V6
  799.   &AHelloWindow::tickTime()                                                 //V6
  800. {                                                                           //V6
  801. IString                                                                     //V6
  802.   formattedDate,                                                            //V6
  803.   formattedTime;                                                            //V6
  804.  
  805. /*--------------------------- Format the Date ----------------------------|   V6
  806. |  If the date format is long, date should appear as August 10, 1994.     |   V6
  807. |    Otherwise it should appear in the default locale format, eg 08/10/94.|   V6
  808. |------------------------------------------------------------------------*/ //V6
  809.   if (isDateLong())                                                         //V6
  810.   {                                                                         //V6
  811.     formattedDate =( (IDate().monthName()) +" "+                            //V6
  812.               IString(IDate().dayOfMonth())+", "+                           //V6
  813.               IString(IDate().year()));                                     //V6
  814.   }                                                                         //V6
  815.   else formattedDate = IDate().asString();                                  //V6
  816.  
  817. /*--------------------------- Format the Time ----------------------------|   V6
  818. |  If the time format is long, time should appear as 01:44:59 pm.         |   V6
  819. |    Otherwise it should appear in shortened military time, eg 13:44.     |   V6
  820. |------------------------------------------------------------------------*/ //V6
  821.   if (isTimeLong())                                                         //V6
  822.   {                                                                         //V6
  823.     formattedTime = ITime().asString("%I:%M:%S %p");                        //V6
  824.   }                                                                         //V6
  825.   else                                                                      //V6
  826.     formattedTime = ITime().asString("%H:%M");                              //V6
  827.  
  828. /*----------------------- Update Date and Time ---------------------------|   V6
  829. |  If the date and/or time have changed, update the status area.          |   V6
  830. |------------------------------------------------------------------------*/ //V6
  831.   if (formattedDate != statusDate.text())                                   //V6
  832.     statusDate.setText(formattedDate);                                      //V6
  833.   if (formattedTime != statusTime.text())                                   //V6
  834.     statusTime.setText(formattedTime);                                      //V6
  835.   return (*this);                                                           //V6
  836. } /* end AHelloWindow :: tickTime() */                                      //V6
  837.  
  838. /**************************************************************************   V6
  839. * AHelloWindow :: earth                                                   *   V6
  840. *   Public function for accessing the earthWindow contained within this   *   V6
  841. *     AHelloWindow class object.                                          *   V6
  842. **************************************************************************/ //V6
  843. AEarthWindow                                                                //V6
  844.   *AHelloWindow::earth()                                                    //V6
  845. {                                                                           //V6
  846.   return (&earthWindow);                                                    //V6
  847. } /* end AHelloWindow :: earth() */                                         //V6
  848.  
  849. /**************************************************************************   V6
  850. * AHelloWindow :: isDateLong                                              *   V6
  851. *   Public function for querying the state of the date format.            *   V6
  852. **************************************************************************/ //V6
  853. const IBase::Boolean                                                        //V6
  854.   AHelloWindow::isDateLong()                                                //V6
  855. {                                                                           //V6
  856.   return (dateLong);                                                        //V6
  857. } /* end AHelloWindow :: isDateLong() */                                    //V6
  858.  
  859. /**************************************************************************   V6
  860. * AHelloWindow :: enableDateLong                                          *   V6
  861. *   Public function for setting the date format, by default, to long.     *   V6
  862. **************************************************************************/ //V6
  863. AHelloWindow                                                                //V6
  864.   &AHelloWindow::enableDateLong(IBase::Boolean makingLong)                  //V6
  865. {                                                                           //V6
  866.   dateLong = makingLong;                                                    //V6
  867.   return (*this);                                                           //V6
  868. } /* end AHelloWindow :: enableDateLong(...) */                             //V6
  869.  
  870. /**************************************************************************   V6
  871. * AHelloWindow :: disableDateLong                                         *   V6
  872. *   Public function for setting the date format to short.                 *   V6
  873. **************************************************************************/ //V6
  874. AHelloWindow                                                                //V6
  875.   &AHelloWindow::disableDateLong()                                          //V6
  876. {                                                                           //V6
  877.   dateLong = false;                                                         //V6
  878.   return (*this);                                                           //V6
  879. } /* end AHelloWindow :: disableDateLong() */                               //V6
  880.  
  881. /**************************************************************************   V6
  882. * AHelloWindow :: isTimeLong                                              *   V6
  883. *   Public function for querying the state of the time format.            *   V6
  884. **************************************************************************/ //V6
  885. const IBase::Boolean                                                        //V6
  886.   AHelloWindow::isTimeLong()                                                //V6
  887. {                                                                           //V6
  888.   return (timeLong);                                                        //V6
  889. } /* end AHelloWindow :: isTimeLong() */                                    //V6
  890.  
  891. /**************************************************************************   V6
  892. * AHelloWindow :: enableTimeLong                                          *   V6
  893. *   Public function for setting the time format, by default, to long.     *   V6
  894. **************************************************************************/ //V6
  895. AHelloWindow                                                                //V6
  896.   &AHelloWindow::enableTimeLong(IBase::Boolean makingLong)                  //V6
  897. {                                                                           //V6
  898.   timeLong = makingLong;                                                    //V6
  899.   return (*this);                                                           //V6
  900. } /* end AHelloWindow :: enableTimeLong(...) */                             //V6
  901.  
  902. /**************************************************************************   V6
  903. * AHelloWindow :: disableTimeLong                                         *   V6
  904. *   Public function for setting the time format to short.                 *   V6
  905. **************************************************************************/ //V6
  906. AHelloWindow                                                                //V6
  907.   &AHelloWindow::disableTimeLong()                                          //V6
  908. {                                                                           //V6
  909.   timeLong = false;                                                         //V6
  910.   return (*this);                                                           //V6
  911. } /* end AHelloWindow :: disableTimeLong() */                               //V6
  912.  
  913. /**************************************************************************   V6
  914. * APopUpHandler :: makePopUpMenu                                          *   V6
  915. *   This function is called whenever the user uses the pointing device    *   V6
  916. *     to request a pop-up menu in a window that is attached to this       *   V6
  917. *     handler.                                                            *   V6
  918. **************************************************************************/ //V6
  919. IBase::Boolean APopUpHandler::makePopUpMenu(IMenuEvent &menuEvent)          //V6
  920. {                                                                           //V6
  921.   Boolean eventProcessed(true);         //Assume event will be processed      V6
  922.   IPopUpMenu    *popUpMenu;                                                 //V6
  923. /*--------------------- Create Pointer to Owner Window -------------------|   V6
  924. |  The window pointer stored in the menu event points to the owner of     |   V6
  925. |    the menu to be popped up.                                            |   V6
  926. |------------------------------------------------------------------------*/ //V6
  927.   IWindow       *popUpOwner = menuEvent.window();                           //V6
  928.   IStaticText   *hello;                                                     //V6
  929.   AEarthWindow  *earth;                                                     //V6
  930. /*--------------------- Select the Pop-up Menu ---------------------------|   V6
  931. |  Determine which menu to pop up based on the window ID of the window    |   V6
  932. |    for which the menu event is being handled.                           |   V6
  933. |------------------------------------------------------------------------*/ //V6
  934.   switch (popUpOwner->id()) {                                               //V6
  935.     case WND_HELLO:                                                         //V6
  936. /*--------------------- Setup the Hello Window Pop-up --------------------|   V6
  937. |  If the hello window pop-up is requested, then get a pointer to the     |   V6
  938. |    pop-up using windowWithOwner.  This pop-up was created as a data     |   V6
  939. |    member of the class that contains the owner window to demonstrate    |   V6
  940. |    how to pop up previously-created, static, pop-up windows.            |   V6
  941. |  The pointer, hello, is created by casting the popUpOwner to the type   |   V6
  942. |    of the AHelloWindow::hello object.  The pointer is used to call      |   V6
  943. |    the AHelloWindow::alignment function to determine which pop-up menu  |   V6
  944. |    item to disable.                                                     |   V6
  945. |------------------------------------------------------------------------*/ //V6
  946.       popUpMenu = (IPopUpMenu *)                                            //V6
  947.                         IWindow::windowWithOwner(WND_HELLOPOPUP,popUpOwner);//V6
  948.       if (popUpMenu)                                                        //V6
  949.       {                                                                     //V6
  950.         hello = (IStaticText *)popUpOwner;                                  //V6
  951.         popUpMenu->enableItem(MI_LEFT,                                      //V6
  952.                         hello->alignment()!=IStaticText::centerLeft);       //V6
  953.         popUpMenu->enableItem(MI_CENTER,                                    //V6
  954.                         hello->alignment()!=IStaticText::centerCenter);     //V6
  955.         popUpMenu->enableItem(MI_RIGHT,                                     //V6
  956.                         hello->alignment()!=IStaticText::centerRight);      //V6
  957.       }                                                                     //V6
  958.                                         //If the pop-up wasn't found,         V6
  959.       else eventProcessed=false;        //  the event wasn't processed        V6
  960.       break;                                                                //V6
  961.     case WND_EARTH:                                                         //V6
  962. /*--------------------- Setup the Earth Window Pop-up --------------------|   V6
  963. |  If the earthWindow pop-up is requested, then create the pop-up menu    |   V6
  964. |    dynamically, with the earthWindow as the owner.  This approach is    |   V6
  965. |    used to create pop-up menus on demand.  The setAutoDeleteObject      |   V6
  966. |    function is used to automatically delete the menu after the user     |   V6
  967. |    has made a selection.                                                |   V6
  968. |  The pointer, earth, is created by casting the popUpOwner to the type   |   V6
  969. |    of the earthWindow object.  The pointer is used to call the          |   V6
  970. |    AEarthWindow  isTwinkling and isBright functions.                    |   V6
  971. |  The Twinkling menu item contains a check mark when isTwinkling is true.|   V6
  972. |  Either the Bright or Dim menu item is disabled, depending on the       |   V6
  973. |    result of isBright.                                                  |   V6
  974. |------------------------------------------------------------------------*/ //V6
  975.       popUpMenu = new IPopUpMenu(WND_EARTHPOPUP,popUpOwner);                //V6
  976.       if (popUpMenu)                                                        //V6
  977.       {                                                                     //V6
  978.         popUpMenu->setAutoDeleteObject();                                   //V6
  979.         earth = (AEarthWindow *)popUpOwner;                                 //V6
  980.         popUpMenu->checkItem(MI_TWINKLE,earth->isTwinkling());              //V6
  981.         if (earth->isBright())                                              //V6
  982.         { popUpMenu->disableItem(MI_BRIGHT); }                              //V6
  983.         else                                                                //V6
  984.         { popUpMenu->disableItem(MI_DIM); }                                 //V6
  985.       }                                                                     //V6
  986.                                         //If the pop-up wasn't created,       V6
  987.       else eventProcessed=false;        //  the event wasn't processed        V6
  988.       break;                                                                //V6
  989.     default:                            //If the owner wasn't hello or earth, V6
  990.       eventProcessed=false;             //  the event wasn't processed        V6
  991.   } /* end switch */                                                        //V6
  992. /*----------------------- Show the Pop-up Menu ---------------------------|   V6
  993. |  If the pop-up menus were setup successfully, use the                   |   V6
  994. |    IPopUpMenu::show function to show the menu at the position where the |   V6
  995. |    pointing device was when the menu event occurred.                    |   V6
  996. |------------------------------------------------------------------------*/ //V6
  997.   if (eventProcessed)                                                       //V6
  998.     popUpMenu->show(menuEvent.mousePosition());                             //V6
  999.   return(eventProcessed);                                                   //V6
  1000. } /* end APopUpHandler :: makePopUpMenu(...) */                             //V6
  1001.  
  1002.