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 >
Wrap
C/C++ Source or Header
|
1995-05-01
|
76KB
|
1,002 lines
/*****************************************************************************
* HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (ahellow6.cpp)*
* *
* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
* *
* DISCLAIMER OF WARRANTIES: *
* The following [enclosed] code is sample code created by IBM *
* Corporation. This sample code is not part of any standard IBM product *
* and is provided to you solely for the purpose of assisting you in the *
* development of your applications. The code is provided "AS IS", *
* without warranty of any kind. IBM shall not be liable for any damages *
* arising out of your use of the sample code, even if they have been *
* advised of the possibility of such damages. *
*****************************************************************************/
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
/************************************************************************** V1
* C++ Hello World History and Key Functions: * V1
* Version 1: (lines with V1 in column 79-80) * V1
* - Creates and runs a simple application * V1
* - Creates the main window (IFrameWindow) * V1
* - Creates a static text control set to "Hello, World!!!" as the * V1
* client window * V1
* * V2
* Version 2: (lines with V2 in column 79-80) * V2
* - Creates a main window (AHellowWindow) derived from IFrameWindow * V2
* - Gets the "Hello, World!!!" text string and other items from a * V2
* resource file * V2
* - Sets the window title from a resource file * V2
* - Creates and sets the information area below the client window * V2
* * V3
* Version 3: (lines with V3 in column 79-80) * V3
* - Adds alignment menu bar with left, center, and right menu items * V3
* - Adds command processing for aligning the * V3
* "Hello, World!!!" text * V3
* - Places check mark in front of selected menu item * V3
* - Creates and maintains current alignment status line * V3
* * V4
* Version 4: (lines with V4 in column 79-80) * V4
* - Adds accelerator keys for Left (F7), Center(F8), Right(F9) * V4
* - Modifies left, center and right menu items to show function keys * V4
* - Modifies menu bar to create edit menu and "Text..." menu item * V4
* - Adds ADialogText to allow user to change "Hello, World!!!" text * V4
* - Adds push buttons to an ISetCanvas for changing text alignment * V4
* * V5
* Version 5: (lines with V5 in column 79-80) * V5
* - Uses a vertical split canvas as the client window * V5
* - Adds a horizontal split canvas as the left side of the client * V5
* - Adds the hello static text to the top of the horiz. split canvas * V5
* - Adds a new control (AEarthWindow) using native graphics calls * V5
* - Adds AEarthWindow to the bottom of the horizontal split canvas * V5
* - Adds a list box to the right side of the vertical split canvas * V5
* - Adds help windows for the main, dialog, and entry field windows * V5
* * V6
* Version 6: (lines with V6 in column 79-80) * V6
* - Adds a vertical split canvas for combining the status line with * V6
* a running date and time * V6
* - Adds AHelloTimeHandler from ATimeHandler to update time & date * V6
* - Adds setHelloFont function that uses a font dialog to change * V6
* the Hello World font. * V6
* - Adds ANotebookWindow class that uses a notebook control for * V6
* changing earthWindow and date and time settings * V6
* - Adds two pop-up menus for changing user settings * V6
* - Uses a profile from IProfile class to save and read user * V6
* settings * V6
* - Changes the entry field in the text dialog to a combo box * V6
**************************************************************************/
//Include User Interface Class Library class headers:
#include <iapp.hpp> //IApplication class V1
#include <ifont.hpp> //IFont class V3
#include <istring.hpp> //IString class V4
#include <idate.hpp> //IDate class V6
#include <itime.hpp> //ITime class V6
#include <imsgbox.hpp> //IMessageBox class V6
#include <iprofile.hpp> //IProfile class V6
#include <ifontdlg.hpp> //IFontDialog class V6
#include "aearthw6.hpp" //AEarthWindow class v6
#include "ahellow6.hpp" //Include AHelloWindow class headers v6
#include "ahellow6.h" //Include symbolic definitions v6
#include "adialog6.hpp" //Include ATextDialog class v6
#define HELP_LIBRARIES "ahellow6.hlp" //Define help window libraries file V6
#define APPLICATION_NAME "Hello6" //Define user profile application V6
// name and file name V6
/************************************************************************** V1
* main - Application entry point for Hello World Version 6. * v6
* This simple application does the following: * V1
* 1) Creates a new object mainWindow of class AHelloWindow * v2
* 2) Sets Hello World window alignment * V3
* 3) Sets the size of mainWindow * v3
* 4) Sets the window focus to mainWindow * v3
* 5) Displays the mainWindow * v3
* 6) Starts the events processing for the application * v3
**************************************************************************/
int main() //V1
{ //V1
AHelloWindow mainWindow (WND_MAIN); //v2
mainWindow.setAlignment(AHelloWindow::left); //V3
mainWindow.sizeTo(ISize(400,300)); //V1
mainWindow.setFocus(); //V1
mainWindow.show(); //V1
IApplication::current().run(); //V1
return 0;
} /* end main */ //V1
/************************************************************************** V2
* AHelloWindow :: AHelloWindow - Constructor for the main window * V2
* Construct the IFrameWindow using the default style plus minimizedIcon, * V2
* which gets the Icon identified in the resource file and associates it * V2
* with the main window. The accelerator style causes the accelerator * v4
* table to be loaded from the resource file. * V4
* Create a menu bar object for the main window menu bar that was loaded * V3
* from the resource file. menuBar is used by setAlignment to * V3
* manipulate check marks on the menu items. * V3
* Create the statusCanvas split canvas making the AHelloWindow its * V6
* parent window and let its orientation default to vertical. * V6
* Create a static text object for displaying the status of the * V3
* Hello World text alignment and make it the first child of the * v6
* statusCanvas. It will be the leftmost window of the statusCanvas. * V6
* Create static text objects for displaying the date and time and * V6
* make them children of the statusCanvas. The date will be in the * V6
* center window of the canvas while the time will be on the right. * V6
* Create the clientWindow split canvas to be used as the client window * V5
* of this frame and let its orientation default to vertical. * V5
* Create the helloCanvas split canvas making the clientWindow its parent * V5
* window and orient it horizontally. * V5
* Create the hello and earthWindow static text objects as children of * v5
* the helloCanvas. hello is placed in the topmost window of the * V5
* horizontal split canvas because it is created first. earthWindow * V5
* is placed in the bottom window of the split canvas. * V5
* Create the listBox window making the clientWindow its parent window * V5
* and enabling it for tabbing and preventing it from being resized * V5
* due to an item being too long. helloCanvas is placed in the * V5
* leftmost window of the vertical split canvas because it is created * V5
* first. listBox is placed in the right window of the split canvas. * V5
* Create a set canvas that will contain the push buttons and will be * V4
* added to the frame as an extension. * V4
* Create each push button with the set canvas as parent and owner. * V4
* Additionally for Help, specify help style and noPointerFocus style. * V5
* noPointerFocus prevents the mouse from changing the input focus * V5
* to the Help push button when you select it using the mouse. This * V5
* allows you to use contextual help for the control with the input * V5
* focus rather than for the Help push button itself. * V5
* Create the Hello World information area object from IInfoArea class. * V2
* The information area is automatically added as an extension below * V2
* the client window of the frame. * V2
* Create a command handler to process command events from menu item, * v4
* push button, and accelerator key selections. * v4
* Create a select handler to process selections made in the list box. * V5
* Create an IHelpWindow object that is displayed when help is requested * V5
* from a help menu item, the help push button, or the help accelerator * V5
* key, normally F1. * V5
* An IHelpHandler object, helpHandler is created implicitly, see class * V5
* definition for AHelloWindow in ahellow5.hpp. * V5
* Initialize the date and time boolean objects that contain the state of * V6
* the data and time formats. * V6
* Create the pop-up menu for the hello window as a data member of * V6
* AHelloWindow class. * V6
* (Refer to the APopUpHandler::makePopUpMenu function in this file * V6
* for an example of a dynamically created pop-up menu.) * V6
**************************************************************************/ //V2
AHelloWindow :: AHelloWindow(unsigned long windowId) //V2
: IFrameWindow(IFrameWindow::defaultStyle() | //V2
IFrameWindow::minimizedIcon | //v4
IFrameWindow::accelerator, //V4
windowId) //V2
,menuBar(windowId, this) //V3
,statusCanvas(WND_STATUSCANVAS,this, this) //V6
,statusLine(WND_STATUS, &statusCanvas, &statusCanvas) //v6
,statusDate(WND_DATE, &statusCanvas, &statusCanvas) //V6
,statusTime(WND_TIME, &statusCanvas, &statusCanvas) //V6
,clientWindow(WND_CANVAS, this, this) //V5
,helloCanvas(WND_HCANVAS, &clientWindow, &clientWindow, IRectangle(), //V5
IWindow::visible | ISplitCanvas::horizontal) //V5
,hello(WND_HELLO, &helloCanvas, &helloCanvas) //v5
,earthWindow(WND_EARTH, &helloCanvas) //V5
,listBox(WND_LISTBOX, &clientWindow, &clientWindow, IRectangle(), //V5
IListBox::defaultStyle() | //V5
IControl::tabStop | //V5
IListBox::noAdjustPosition) //V5
,buttons(WND_BUTTONS, this, this) //V4
,leftButton(MI_LEFT, &buttons, &buttons) //V4
,centerButton(MI_CENTER, &buttons, &buttons) //V4
,rightButton(MI_RIGHT, &buttons, &buttons) //V4
,helpButton(MI_HELP, &buttons, &buttons, IRectangle(), //V5
IPushButton::defaultStyle() | //V5
IPushButton::help | IButton::noPointerFocus) //V5
,infoArea(this) //V2
,commandHandler(this) //V3
,selectHandler(this) //V5
,helpWindow(HELP_TABLE,this) //V5
,dateLong(false) //V6
,timeLong(true) //V6
,helloPopUpMenu(WND_HELLOPOPUP, &hello) //V6
,settingsNotebook( 0 ) //V6
{ //V2
/*------------------------- Setup the Client Window ----------------------| V5
| Set the clientWindow split canvas as the client window for the | V5
| AHelloWorld frame. | V5
| Set the HelloCanvas object to occupy 60% of the client canvas. | V5
| Set the list box object to occupy 40% of the client canvas. | V5
|------------------------------------------------------------------------*/ //V5
setClient(&clientWindow); //V5
clientWindow.setSplitWindowPercentage(&helloCanvas, 60); //V5
clientWindow.setSplitWindowPercentage(&listBox, 40); //V5
/*------------------------- Setup the Status Area ------------------------| v6
| Add the status area as an extension to the frame above the client | v6
| window with the height calculated from the maximum height of a | V3
| character in the current font. | V3
| Start processing timer events for updating the time. | V6
|------------------------------------------------------------------------*/ //V3
addExtension(&statusCanvas, IFrameWindow::aboveClient, //v6
IFont(&statusLine).maxCharHeight()); //V3
timeHandler.handleEventsFor(this); //V6
/*-------------------------- Setup the List Box --------------------------| V5
| Add the different language versions of Hello World to the list box in | V5
| ascending order. Hello World text strings are stored in the | V5
| resource file with IDs beginning with HI_WORLD with each subsequent | V5
| ID incremented up to HI_WORLD + HI_COUNT - 1. | V5
| Have the select handler handle selections made in the list box. | V5
| The select handler's selected() function is called to process | V5
| list box selections. | V5
|------------------------------------------------------------------------*/ //V5
for (int i=0;i<HI_COUNT;i++ ) //V5
listBox.addAscending(HI_WORLD+i); //V5
selectHandler.handleEventsFor(&listBox); //V5
/*---------------------- Setup the Information Area ----------------------| V5
| Change the size of the information area using the maximum height of | V5
| a character in the current font. | V5
|------------------------------------------------------------------------*/ //V5
setExtensionSize(&infoArea, IFont(&infoArea).maxCharHeight()); //V5
/*---------------------------- Set Text Values ---------------------------| V2
| Set the values for the text controls from strings in the resource file.| V2
| The infoArea inactive text is displayed when no menu item is active. | V2
|------------------------------------------------------------------------*/ //V2
hello.setText(STR_HELLO); //V2
leftButton.setText(STR_LEFTB); //V4
centerButton.setText(STR_CENTERB); //V4
rightButton.setText(STR_RIGHTB); //V4
helpButton.setText(STR_HELPB); //V5
infoArea.setInactiveText(STR_INFO); //V2
/*------------------- Setup Push Buttons Set Canvas ----------------------| V4
| Set the canvas margins and padding between buttons to zero. | V4
| Add the set canvas that contains the push buttons to the frame window | V4
| as an extension immediately below the client window with a height | V4
| equal to the minimum height of the push buttons. You must set the | V4
| text in the push buttons first. | V4
|------------------------------------------------------------------------*/ //V4
leftButton.enableTabStop(); //V4
buttons.setMargin(ISize()); //V4
buttons.setPad(ISize()); //V4
addExtension(&buttons, IFrameWindow::belowClient, //V4
(unsigned long)buttons.minimumSize().height()); //V4
/*----------------------- Setup the Command Handler ----------------------| V3
| Have the command handler handle commands sent from the frame window. | V3
| The command handler's command() function is called to process | V3
| menu item, push button, and accelerator key selections. | v5
| Attach the command handler to the hello and earthWindow static text | V6
| windows to handle command events generated for these windows by | V6
| the pop-up menus. | V6
| Attach the pop-up menu handler to the hello and earthWindow static text| V6
| windows to handle pop-up menu requests made while the pointer is | V6
| over these windows. The makePopUpMenu function will be called when | V6
| the user requests a pop-up menu using the mouse in these windows. | V6
|------------------------------------------------------------------------*/ //V3
commandHandler.handleEventsFor(this); //V3
commandHandler.handleEventsFor(&hello); //V6
commandHandler.handleEventsFor(&earthWindow); //V6
popUpHandler.handleEventsFor(&hello); //V6
popUpHandler.handleEventsFor(&earthWindow); //V6
/*---------------------------- Setup Help --------------------------------| V5
| Add the help library to the help window using addLibraries(). | V5
| Set the help window title from a string in the resource file. | V5
| Begin handling help events for the frame window. | V5
|------------------------------------------------------------------------*/ //V5
try //V5
{ //V5
helpWindow.addLibraries( HELP_LIBRARIES ); //V5
helpWindow.setTitle(STR_HTITLE); //V5
helpHandler.handleEventsFor(this); //V5
} //V5
catch( ... ) //V5
{ //V5
IMessageBox //V5
msgBox( this ); //V5
msgBox.show( STR_HELP_NOT_FOUND, IMessageBox::warning ); //V5
} //V5
/*----------------------- Set Default Alignment --------------------------| V2
| Align the static text, set the status line, and set the check mark in | v3
| the menu bar. | v3
|------------------------------------------------------------------------*/ //V2
setAlignment(center); //v3
} /* end AHelloWindow :: AHelloWindow(...) */ //V2
/************************************************************************** V3
* AHelloWindow :: ~AHelloWindow - Destructor for the main window * V3
* Stop handling command events for the frame. * V3
* Stop handling select events for the list box. * V5
* Stop handling help events for the frame. * V5
* Stop handling timer events for the frame. * V6
* Stop handling menu events for the frame. * V6
**************************************************************************/ //V3
AHelloWindow :: ~AHelloWindow() //V3
{ //V3
commandHandler.stopHandlingEventsFor(this); //V3
commandHandler.stopHandlingEventsFor(&earthWindow); //V6
commandHandler.stopHandlingEventsFor(&hello); //V6
selectHandler.stopHandlingEventsFor(&listBox); //V5
helpHandler.stopHandlingEventsFor(this); //V5
popUpHandler.stopHandlingEventsFor(&hello); //V6
popUpHandler.stopHandlingEventsFor(&earthWindow); //V6
} /* end AHelloWindow :: ~AHelloWindow() */ //V3
/************************************************************************** V3
* AHelloWindow :: setAlignment - Align static text in client window * V3
**************************************************************************/ //V3
AHelloWindow & //V3
AHelloWindow :: setAlignment(Alignment alignment) //V3
{ //V3
/*--------------------- Update Window for New Alignment ------------------| V3
| Depending on the value passed, update the window as follows: | V3
| Set the alignment of the static text control in the client window. | V3
| Set the text of the alignment status line static text control. | V3
| Check the selected menu item; remove check marks from the other two. | V3
|------------------------------------------------------------------------*/ //V3
switch(alignment) //V3
{ //V3
case left: //V3
hello.setAlignment( //V3
IStaticText::centerLeft); //V3
statusLine.setText(STR_LEFT); //V3
menuBar.uncheckItem(MI_CENTER); //V3
menuBar.checkItem(MI_LEFT); //V3
menuBar.uncheckItem(MI_RIGHT); //V3
break; //V3
case center: //V3
hello.setAlignment( //V3
IStaticText::centerCenter); //V3
statusLine.setText(STR_CENTER); //V3
menuBar.checkItem(MI_CENTER); //V3
menuBar.uncheckItem(MI_LEFT); //V3
menuBar.uncheckItem(MI_RIGHT); //V3
break; //V3
case right: //V3
hello.setAlignment( //V3
IStaticText::centerRight); //V3
statusLine.setText(STR_RIGHT); //V3
menuBar.uncheckItem(MI_CENTER); //V3
menuBar.uncheckItem(MI_LEFT); //V3
menuBar.checkItem(MI_RIGHT); //V3
break; //V3
} //V3
return (*this); //Return a reference to the frame V3
} /* end AHelloWindow :: setAlignment(...) */ //V3
/************************************************************************** V4
* AHelloWindow :: editText * V4
* Create and show a dialog window for inputting text that will be used * V4
* to replace the "Hello World!!!" static text string. * V4
**************************************************************************/ //V4
AHelloWindow & //V4
AHelloWindow :: editText() //V4
{ //V4
/*----------------------- Setup for Displaying Dialog --------------------| V4
| Store the current value of the text to be changed. | V4
| Set the text in the information area from the dialog information | V4
| string in the resource file. | V4
|------------------------------------------------------------------------*/ //V4
IString textValue(hello.text()); //V4
infoArea.setInactiveText(STR_INFODLG); //V4
/*------------------------ Create and Show Dialog ------------------------| V4
| Create a new text dialog with textValue as the string to edit and | V4
| AHelloWindow as the owner window. | V4
| Show the dialog modally. This means that the owner window cannot have | V4
| the focus back until the dialog is ended. | V4
|------------------------------------------------------------------------*/ //V4
ATextDialog textDialog(textValue,this); //V4
textDialog.showModally(); //V4
/*------------------------ Process Dialog Result -------------------------| V4
| If the OK button was used to end the dialog, then the static text, | V4
| hello, is set to the textValue string. Else, it is not changed. | V4
| Reset the information area inactive text. | V4
|------------------------------------------------------------------------*/ //V4
if (textDialog.result() == DID_OK) //V4
hello.setText(textValue); //V4
infoArea.setInactiveText(STR_INFO); //V4
return (*this); //Return a reference to the frame V4
} /* end AHelloWindow :: editText() */ //V4
/************************************************************************** V5
* AHelloWindow :: setTextFromListBox * V5
* Public function used by non-AHelloWindow functions to set the Hello * V5
* World text from the first selected item in the AHelloWindow listBox. * V5
**************************************************************************/ //V5
AHelloWindow & //V5
AHelloWindow :: setTextFromListBox() //V5
{ //V5
/*---------------------- Set Hello Text from ListBox ---------------------| V5
| Create a cursor to the list box. Using the default filter for a | V5
| list box cursor, selectedItems, causes the setToFirst() function | V5
| to position the cursor to the first selected item. | V5
| Set the hello IStaticText control text value. | V5
|------------------------------------------------------------------------*/ //V5
IListBox::Cursor lbCursor(listBox); //V5
lbCursor.setToFirst(); //V5
hello.setText(listBox.elementAt(lbCursor)); //V5
return (*this); //Return a reference to the frame V5
} /* end AHelloWindow :: setTextFromListBox() */ //V5
/************************************************************************** V6
* AHelloWindow :: setHelloFont * V6
* Public function used by non-AHelloWindow functions to start a * V6
* font dialog for changing the font of the Hello World text. * V6
**************************************************************************/ //V6
AHelloWindow & //V6
AHelloWindow :: setHelloFont() //V6
{ //V6
/*------------------------- Start the Font Dialog ------------------------| V6
| Set the text in the information area from the font dialog information | V6
| string in the resource file. | V6
| Create a font from the current font of the hello static text object. | V6
| Create a font settings object from the tempFont object. | V6
| Set the title to be used in the font dialog from a string resource in | V6
| the resource file. | V6
| Start the font dialog by creating an IFontDialog object. The font | V6
| dialog is created as a modal dialog window with the desktopWindow | V6
| as the parent, the AHelloWindow frame as the owner, resetButton | V6
| style which supplies the user with a way to reset the fields in the | V6
| dialog, and the font settings that were just created. | V6
|------------------------------------------------------------------------*/ //V6
infoArea.setInactiveText(STR_FONTDLGT); //V6
IFont tempFont(&hello); //V6
IFontDialog::Settings fontSettings(&tempFont); //V6
fontSettings.setTitle(IResourceId(STR_FONTDLGT)); //V6
IFontDialog fontDialog( desktopWindow(), this, //V6
IFontDialog::resetButton, fontSettings); //V6
/*---------------------------- Change the Font ---------------------------| V6
| If the user pressed OK in the font dialog, then change the font for | V6
| the hello IStaticText object using the tempFont object that was set | V6
| by the font dialog. | V6
| Reset the information area inactive text. | V6
|------------------------------------------------------------------------*/ //V6
if (fontDialog.pressedOK()) //V6
{ //V6
hello.setFont(tempFont); //V6
} //V6
infoArea.setInactiveText(STR_INFO); //V6
return (*this); //Return a reference to the frame V6
} /* end AHelloWindow :: setHelloFont() */ //V6
/************************************************************************** V6
* AHelloWindow :: readHelloSettings * V6
* Public function used by non-AHelloWindow functions to read in user * V6
* settings from an IProfile class profile. * V6
**************************************************************************/ //V6
AHelloWindow & //V6
AHelloWindow :: readHelloSettings() //V6
{ //V6
/*---------------------------- Try Not to Fail ---------------------------| V6
| The try-catch blocks are used to prevent a missing profile from | V6
| abending the program. | V6
|------------------------------------------------------------------------*/ //V6
try //V6
{ //V6
/*--------------------------- Open the Profile ---------------------------| V6
| A file named Hello6.ini.iclDB on AIX, or Hello6.ini on OS/2, is | V6
| is expected to exist, and if so, will be opened and the default | V6
| application name, Hello6, is set. | V6
|------------------------------------------------------------------------*/ //V6
IProfile profile(IString(APPLICATION_NAME)+".ini"); //V6
profile.setDefaultApplicationName(APPLICATION_NAME); //V6
/*------------------- Read the Profile and Modify Settings ---------------| V6
| Each Hello6 element in the profile is read using the elementWithKey or | V6
| integerWithKey function, where element is used for reading strings | V6
| and integer is used for values. The elements are identified using | V6
| unique names that are defined by this application. | V6
| The appropriate AHelloWindow function is called to set the date and | V6
| time formats. The arguments for the functions are integers, | V6
| representing true(1) and false(0). | V6
| The Font... settings are used to reset the AHelloWindow::hello | V6
| static text window font. | V6
| The appropriate AEarthWindow functions are called to set the painting | V6
| settings for the Earth window. | V6
|------------------------------------------------------------------------*/ //V6
enableDateLong(profile.integerWithKey("DateLong")); //V6
enableTimeLong(profile.integerWithKey("TimeLong")); //V6
IFont //V6
helloFont(&hello); //V6
helloFont.useVectorOnly(profile.integerWithKey("FontVector")); //V6
helloFont.useNonPropOnly(profile.integerWithKey("FontNonProp")); //V6
helloFont.setName(profile.elementWithKey("FontFace")); //V6
helloFont.setPointSize(profile.integerWithKey("FontSize")); //V6
helloFont.setBold(profile.integerWithKey("FontBold")); //V6
helloFont.setItalic(profile.integerWithKey("FontItalic")); //V6
hello.setFont(helloFont); //V6
earth()->enableTwinkle(profile.integerWithKey("Twinkling")); //V6
earth()->enableBright(profile.integerWithKey("Bright")); //V6
earth()->setLayers(profile.integerWithKey("Layers")); //V6
long //V6
hue=profile.integerWithKey("EarthColor"); //V6
if (hue==IColor(IColor::green).asRGBLong()) //V6
{ earth()->setEarthColor(IColor(IColor::green)); } //V6
else if (hue==IColor(IColor::white).asRGBLong()) //V6
{ earth()->setEarthColor(IColor(IColor::white)); } //V6
else if (hue==IColor(IColor::yellow).asRGBLong()) //V6
{ earth()->setEarthColor(IColor(IColor::yellow)); } //V6
else //V6
{ earth()->setEarthColor(IColor(IColor::cyan)); } //V6
/*------------------------ Tell User Read Worked -------------------------| V6
| A message box with an ok button is used to inform the user that the | V6
| read settings function completed successfully. . | V6
|------------------------------------------------------------------------*/ //V6
IMessageBox mbox(this); //V6
mbox.setTitle(WND_MAIN).show(STR_READOK,IMessageBox::okButton); //V6
} //V6
catch (IException& exc) //V6
{ //V6
/*------------------------ Tell User Read Failed -------------------------| V6
| A default exception message box is used to inform the user that the | V6
| read settings function failed. . | V6
|------------------------------------------------------------------------*/ //V6
IMessageBox mbox(this); //V6
mbox.show(exc); //V6
} //V6
return (*this); //Return a reference to the frame V6
} /* end AHelloWindow :: readHelloSettings() */ //V6
/************************************************************************** V6
* AHelloWindow :: saveHelloSettings * V6
* Public function used by non-AHelloWindow functions to save user * V6
* settings in an IProfile class profile. * V6
**************************************************************************/ //V6
AHelloWindow & //V6
AHelloWindow :: saveHelloSettings() //V6
{ //V6
/*---------------------------- Try Not to Fail ---------------------------| V6
| The try-catch blocks are used to prevent a profile error from | V6
| abending the program. | V6
|------------------------------------------------------------------------*/ //V6
try //V6
{ //V6
/*--------------------------- Open the Profile ---------------------------| V6
| A file named Hello6.ini.iclDB on AIX, or Hello6.ini on OS/2, is | V6
| is opened, if found, or created, if not found, and the default | V6
| application name, Hello6, is set. | V6
|------------------------------------------------------------------------*/ //V6
IProfile profile(IString(APPLICATION_NAME)+".ini"); //V6
profile.setDefaultApplicationName(APPLICATION_NAME); //V6
/*------------------- Save the User Settings in the Profile --------------| V6
| The IProfile overloaded function, addOrReplaceElementWithKey, is used | V6
| to save each setting value in the profile. Numeric and boolean | V6
| values are stored as long integers, while strings are stored as | V6
| character strings. | V6
|------------------------------------------------------------------------*/ //V6
profile.addOrReplaceElementWithKey( //V6
"DateLong", (long)isDateLong()); //V6
profile.addOrReplaceElementWithKey( //V6
"TimeLong", (long)isTimeLong()); //V6
IFont //V6
helloFont(&hello); //V6
profile.addOrReplaceElementWithKey( //V6
"FontVector", helloFont.isVectorOnly()); //V6
profile.addOrReplaceElementWithKey( //V6
"FontNonProp", helloFont.isNonPropOnly()); //V6
profile.addOrReplaceElementWithKey( //V6
"FontFace", helloFont.name()); //V6
profile.addOrReplaceElementWithKey( //V6
"FontSize", helloFont.pointSize()); //V6
profile.addOrReplaceElementWithKey( //V6
"FontBold", helloFont.isBold()); //V6
profile.addOrReplaceElementWithKey( //V6
"FontItalic", helloFont.isItalic()); //V6
profile.addOrReplaceElementWithKey( //V6
"Twinkling",(long)earth()->isTwinkling()); //V6
profile.addOrReplaceElementWithKey( //V6
"Bright", (long)earth()->isBright()); //V6
profile.addOrReplaceElementWithKey( //V6
"Layers", (long)earth()->layers()); //V6
profile.addOrReplaceElementWithKey( //V6
"EarthColor",earth()->earthColor().asRGBLong()); //V6
/*------------------------ Tell User Read Worked -------------------------| V6
| A message box with an ok button is used to inform the user that the | V6
| save settings function completed successfully. . | V6
|------------------------------------------------------------------------*/ //V6
IMessageBox mbox(this); //V6
mbox.setTitle(WND_MAIN).show(STR_SAVEDOK,IMessageBox::okButton); //V6
} //V6
catch (IException& exc) //V6
{ //V6
/*------------------------ Tell User Read Failed -------------------------| V6
| A default exception message box is used to inform the user that the | V6
| save settings function failed. . | V6
|------------------------------------------------------------------------*/ //V6
IMessageBox mbox(this); //V6
mbox.show(exc); //V6
} //V6
return (*this); //Return a reference to the frame V6
} /* end AHelloWindow :: saveHelloSettings() */ //V6
/************************************************************************** V6
* AHelloWindow :: openHelloSettings * V6
* Public function used by non-AHelloWindow functions to open a settings * V6
* notebook for changing Hello World window attributes. * V6
**************************************************************************/ //V6
AHelloWindow & //V6
AHelloWindow :: openHelloSettings() //V6
{ //V6
/*----------------------- Is Notebook Already Created --------------------| V6
| Check if the notebook already exists. | V6
| Zero is returned if the notebook does not exist. | V6
|------------------------------------------------------------------------*/ //V6
if ( settingsNotebook ) //V6
{ //V6
delete settingsNotebook; //V6
} //V6
/*----------------- Dynamically Create the Settings Notebook -------------| V6
| Using the new operator causes the ANotebookWindow object to be | V6
| dynamically allocated. This means that that the object will not go | V6
| out of scope, therefore the application should delete it when it is | V6
| finished with it. | V6
|------------------------------------------------------------------------*/ //V6
settingsNotebook = new ANotebookWindow(WND_NOTEBOOKFRAME,this); //V6
/*----------------------- Move/Show the Notebook -------------------------| V6
| Move the notebook to ensure the entire window is visible on a small | V6
| display. | V6
| The notebook is given control and shown by using setFocus and show. | V6
| The restore function is used in case the window was created | V6
| previously, but minimized. | V6
|------------------------------------------------------------------------*/ //V6
settingsNotebook->moveTo( IPoint(50,50) ); //V6
settingsNotebook->restore().setFocus().show(); //V6
return (*this); //Return a reference to the frame V6
} /* end AHelloWindow :: openHelloSettings() */ //V6
/************************************************************************** V3
* ACommandHandler :: ACommandHandler - constructor for the command handler* V3
* Construct the command handler from a pointer to the AHelloWindow * V3
* that events will be handled for. * V3
**************************************************************************/ //V3
ACommandHandler :: ACommandHandler(AHelloWindow *helloFrame) //V3
{ //V3
frame=helloFrame; //Save frame to be handled V3
} /* end ACommandHandler :: ACommandHandler(...) */ //V3
/************************************************************************** V3
* ACommandHandler :: command * V3
* Handle menu and button commands * V4
**************************************************************************/ //V3
IBase::Boolean //V3
ACommandHandler :: command(ICommandEvent & cmdEvent) //V3
{ //V3
Boolean eventProcessed(true); //Assume event will be processed V3
/*--------------------- Process command events ---------------------------| V3
| Depending on the command event ID, call the AHelloWindow::setAlignment | V3
| function with the appropriate AHelloWorld::Alignment value. | V3
| Do this except when the Text menu item is selected; | V4
| then call the AHelloWindow::editText function for changing the | V4
| Hello World text using a dialog. | V4
|------------------------------------------------------------------------*/ //V3
switch (cmdEvent.commandId()) { //V3
case MI_CENTER: //V3
frame->setAlignment(AHelloWindow::center); //V3
break; //V3
case MI_LEFT: //V3
frame->setAlignment(AHelloWindow::left); //V3
break; //V3
case MI_RIGHT: //V3
frame->setAlignment(AHelloWindow::right); //V3
break; //V3
case MI_TEXT: //V4
frame->editText(); //V4
break; //V4
case MI_FONT: //V6
frame->setHelloFont(); //V6
break; //V6
case MI_READSETS: //V6
frame->readHelloSettings(); //V6
break; //V6
case MI_OPENSETS: //V6
frame->openHelloSettings(); //V6
break; //V6
case MI_SAVESETS: //V6
frame->saveHelloSettings(); //V6
break; //V6
case MI_TWINKLE: //Toggle the twinkle setting V6
frame->earth()->enableTwinkle(!frame->earth()->isTwinkling()); //V6
break; //V6
case MI_BRIGHT: //V6
frame->earth()->enableBright(); //V6
break; //V6
case MI_DIM: //V6
frame->earth()->disableBright(); //V6
break; //V6
default: //Otherwise, V3
eventProcessed=false; // the event wasn't processed V3
} /* end switch */ //V3
return(eventProcessed); //V3
} /* end ACommandHandler :: command(...) */ //V3
/************************************************************************** V5
* ASelectHandler :: ASelectHandler - constructor for the select handler * V5
* Construct the select handler from a pointer to the AHelloWindow * V5
* that will be changed as a result of the selection. * V5
**************************************************************************/ //V5
ASelectHandler :: ASelectHandler(AHelloWindow *helloFrame) //V5
{ //V5
frame=helloFrame; //Save frame to be handled V5
} /* end ASelectHandler :: ASelectHandler(...) */ //V5
/************************************************************************** V5
* ASelectHandler :: selected * V5
* Handle items selected within the list box. * V5
**************************************************************************/ //V5
IBase::Boolean //V5
ASelectHandler :: selected(IControlEvent & evt) //V5
{ //V5
/*---------------------- Call AHelloWindow Function ----------------------| V5
| Call the AHelloWindow::setTextFromListBox function for the frame used | V5
| to construct this select handler. | V5
|------------------------------------------------------------------------*/ //V5
frame->setTextFromListBox(); //V5
return (true); //Event is always processed V5
} /* end ASelectHandler :: selected(...) */ //V5
/************************************************************************** V5
* AHelpHandler :: keysHelpId * V5
* Handle the keys help request event * V5
* This overrides the default action of setting the event result to * V5
* zero, which indicates that no action is required, that is, no * V5
* help information for keys is displayed. * V5
**************************************************************************/ //V5
IBase::Boolean //V5
AHelpHandler :: keysHelpId(IEvent& evt) //V5
{ //V5
evt.setResult(1000); //1000=keys help ID in V5
// ahellow5.ipf file V5
return (true); //Event is always processed V5
} /* end AHelpHandler :: keysHelpId(...) */ //V5
/************************************************************************** V6
* AHelloTimeHandler :: tick * V6
* Process ATimeHandler ticks by calling the AHelloWindow function * V6
* for updating the date and time. * V6
**************************************************************************/ //V6
IBase::Boolean //V6
AHelloTimeHandler::tick(IEvent& evt) //V6
{ //V6
((AHelloWindow *)evt.window())->tickTime(); //V6
return (true); //Event is always processed V6
} /* end AHelloTimeHandler :: tick(...) */ //V6
/************************************************************************** V6
* AHelloWindow :: tickTime * V6
* If the date or time in the status area have changed, update them * V6
* using the current formats. * V6
**************************************************************************/ //V6
AHelloWindow //V6
&AHelloWindow::tickTime() //V6
{ //V6
IString //V6
formattedDate, //V6
formattedTime; //V6
/*--------------------------- Format the Date ----------------------------| V6
| If the date format is long, date should appear as August 10, 1994. | V6
| Otherwise it should appear in the default locale format, eg 08/10/94.| V6
|------------------------------------------------------------------------*/ //V6
if (isDateLong()) //V6
{ //V6
formattedDate =( (IDate().monthName()) +" "+ //V6
IString(IDate().dayOfMonth())+", "+ //V6
IString(IDate().year())); //V6
} //V6
else formattedDate = IDate().asString(); //V6
/*--------------------------- Format the Time ----------------------------| V6
| If the time format is long, time should appear as 01:44:59 pm. | V6
| Otherwise it should appear in shortened military time, eg 13:44. | V6
|------------------------------------------------------------------------*/ //V6
if (isTimeLong()) //V6
{ //V6
formattedTime = ITime().asString("%I:%M:%S %p"); //V6
} //V6
else //V6
formattedTime = ITime().asString("%H:%M"); //V6
/*----------------------- Update Date and Time ---------------------------| V6
| If the date and/or time have changed, update the status area. | V6
|------------------------------------------------------------------------*/ //V6
if (formattedDate != statusDate.text()) //V6
statusDate.setText(formattedDate); //V6
if (formattedTime != statusTime.text()) //V6
statusTime.setText(formattedTime); //V6
return (*this); //V6
} /* end AHelloWindow :: tickTime() */ //V6
/************************************************************************** V6
* AHelloWindow :: earth * V6
* Public function for accessing the earthWindow contained within this * V6
* AHelloWindow class object. * V6
**************************************************************************/ //V6
AEarthWindow //V6
*AHelloWindow::earth() //V6
{ //V6
return (&earthWindow); //V6
} /* end AHelloWindow :: earth() */ //V6
/************************************************************************** V6
* AHelloWindow :: isDateLong * V6
* Public function for querying the state of the date format. * V6
**************************************************************************/ //V6
const IBase::Boolean //V6
AHelloWindow::isDateLong() //V6
{ //V6
return (dateLong); //V6
} /* end AHelloWindow :: isDateLong() */ //V6
/************************************************************************** V6
* AHelloWindow :: enableDateLong * V6
* Public function for setting the date format, by default, to long. * V6
**************************************************************************/ //V6
AHelloWindow //V6
&AHelloWindow::enableDateLong(IBase::Boolean makingLong) //V6
{ //V6
dateLong = makingLong; //V6
return (*this); //V6
} /* end AHelloWindow :: enableDateLong(...) */ //V6
/************************************************************************** V6
* AHelloWindow :: disableDateLong * V6
* Public function for setting the date format to short. * V6
**************************************************************************/ //V6
AHelloWindow //V6
&AHelloWindow::disableDateLong() //V6
{ //V6
dateLong = false; //V6
return (*this); //V6
} /* end AHelloWindow :: disableDateLong() */ //V6
/************************************************************************** V6
* AHelloWindow :: isTimeLong * V6
* Public function for querying the state of the time format. * V6
**************************************************************************/ //V6
const IBase::Boolean //V6
AHelloWindow::isTimeLong() //V6
{ //V6
return (timeLong); //V6
} /* end AHelloWindow :: isTimeLong() */ //V6
/************************************************************************** V6
* AHelloWindow :: enableTimeLong * V6
* Public function for setting the time format, by default, to long. * V6
**************************************************************************/ //V6
AHelloWindow //V6
&AHelloWindow::enableTimeLong(IBase::Boolean makingLong) //V6
{ //V6
timeLong = makingLong; //V6
return (*this); //V6
} /* end AHelloWindow :: enableTimeLong(...) */ //V6
/************************************************************************** V6
* AHelloWindow :: disableTimeLong * V6
* Public function for setting the time format to short. * V6
**************************************************************************/ //V6
AHelloWindow //V6
&AHelloWindow::disableTimeLong() //V6
{ //V6
timeLong = false; //V6
return (*this); //V6
} /* end AHelloWindow :: disableTimeLong() */ //V6
/************************************************************************** V6
* APopUpHandler :: makePopUpMenu * V6
* This function is called whenever the user uses the pointing device * V6
* to request a pop-up menu in a window that is attached to this * V6
* handler. * V6
**************************************************************************/ //V6
IBase::Boolean APopUpHandler::makePopUpMenu(IMenuEvent &menuEvent) //V6
{ //V6
Boolean eventProcessed(true); //Assume event will be processed V6
IPopUpMenu *popUpMenu; //V6
/*--------------------- Create Pointer to Owner Window -------------------| V6
| The window pointer stored in the menu event points to the owner of | V6
| the menu to be popped up. | V6
|------------------------------------------------------------------------*/ //V6
IWindow *popUpOwner = menuEvent.window(); //V6
IStaticText *hello; //V6
AEarthWindow *earth; //V6
/*--------------------- Select the Pop-up Menu ---------------------------| V6
| Determine which menu to pop up based on the window ID of the window | V6
| for which the menu event is being handled. | V6
|------------------------------------------------------------------------*/ //V6
switch (popUpOwner->id()) { //V6
case WND_HELLO: //V6
/*--------------------- Setup the Hello Window Pop-up --------------------| V6
| If the hello window pop-up is requested, then get a pointer to the | V6
| pop-up using windowWithOwner. This pop-up was created as a data | V6
| member of the class that contains the owner window to demonstrate | V6
| how to pop up previously-created, static, pop-up windows. | V6
| The pointer, hello, is created by casting the popUpOwner to the type | V6
| of the AHelloWindow::hello object. The pointer is used to call | V6
| the AHelloWindow::alignment function to determine which pop-up menu | V6
| item to disable. | V6
|------------------------------------------------------------------------*/ //V6
popUpMenu = (IPopUpMenu *) //V6
IWindow::windowWithOwner(WND_HELLOPOPUP,popUpOwner);//V6
if (popUpMenu) //V6
{ //V6
hello = (IStaticText *)popUpOwner; //V6
popUpMenu->enableItem(MI_LEFT, //V6
hello->alignment()!=IStaticText::centerLeft); //V6
popUpMenu->enableItem(MI_CENTER, //V6
hello->alignment()!=IStaticText::centerCenter); //V6
popUpMenu->enableItem(MI_RIGHT, //V6
hello->alignment()!=IStaticText::centerRight); //V6
} //V6
//If the pop-up wasn't found, V6
else eventProcessed=false; // the event wasn't processed V6
break; //V6
case WND_EARTH: //V6
/*--------------------- Setup the Earth Window Pop-up --------------------| V6
| If the earthWindow pop-up is requested, then create the pop-up menu | V6
| dynamically, with the earthWindow as the owner. This approach is | V6
| used to create pop-up menus on demand. The setAutoDeleteObject | V6
| function is used to automatically delete the menu after the user | V6
| has made a selection. | V6
| The pointer, earth, is created by casting the popUpOwner to the type | V6
| of the earthWindow object. The pointer is used to call the | V6
| AEarthWindow isTwinkling and isBright functions. | V6
| The Twinkling menu item contains a check mark when isTwinkling is true.| V6
| Either the Bright or Dim menu item is disabled, depending on the | V6
| result of isBright. | V6
|------------------------------------------------------------------------*/ //V6
popUpMenu = new IPopUpMenu(WND_EARTHPOPUP,popUpOwner); //V6
if (popUpMenu) //V6
{ //V6
popUpMenu->setAutoDeleteObject(); //V6
earth = (AEarthWindow *)popUpOwner; //V6
popUpMenu->checkItem(MI_TWINKLE,earth->isTwinkling()); //V6
if (earth->isBright()) //V6
{ popUpMenu->disableItem(MI_BRIGHT); } //V6
else //V6
{ popUpMenu->disableItem(MI_DIM); } //V6
} //V6
//If the pop-up wasn't created, V6
else eventProcessed=false; // the event wasn't processed V6
break; //V6
default: //If the owner wasn't hello or earth, V6
eventProcessed=false; // the event wasn't processed V6
} /* end switch */ //V6
/*----------------------- Show the Pop-up Menu ---------------------------| V6
| If the pop-up menus were setup successfully, use the | V6
| IPopUpMenu::show function to show the menu at the position where the | V6
| pointing device was when the menu event occurred. | V6
|------------------------------------------------------------------------*/ //V6
if (eventProcessed) //V6
popUpMenu->show(menuEvent.mousePosition()); //V6
return(eventProcessed); //V6
} /* end APopUpHandler :: makePopUpMenu(...) */ //V6