home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
HELLO6
/
ANOTEBW6.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-07
|
32KB
|
408 lines
/*****************************************************************************
* HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (anotebw6.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.
//Include User Interface Class Library class headers: V6
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <ireslib.hpp> //Include IResourceId class header V6
#include "anotebw6.hpp" //Include ANotebookWindow class headerV6
#include "ahellow6.h" //Include symbolic definitions V6
/************************************************************************** V6
* ANotebookWindow :: ANotebookWindow * V6
* Construct a secondary frame window to contain the Hello World * V6
* settings notebook. * V6
* The ISlider object, layersSlider, is created with, * V6
* 4 tick marks (4ul), * V6
* spacing between ticks of 45 pixels (45ul), * V6
* no padding at the bottom (alignBottom), * V6
* a digital arm (snapToTickMark), * V6
* a primary scale, * V6
* a horizontal bar with home on the left (horizontal & homeLeft), * V6
* arrow buttons on the right, and as a visible control. * V6
**************************************************************************/ //V6
ANotebookWindow :: ANotebookWindow(unsigned long windowId, //V6
AHelloWindow * ownerWnd) //V6
: IFrameWindow(IResourceId(windowId), ownerWnd) //V6
,helloSettingsNotebook(WND_NOTEBOOK, this, this) //V6
,earthPage(WND_EARTHPAGE,&helloSettingsNotebook,&helloSettingsNotebook)//V6
,earthPageHeading(WND_EARTHPAGEHEADING, &earthPage, &earthPage) //V6
,starsHeading(WND_STARSHEADING, &earthPage, &earthPage) //V6
,starsSettings(WND_STARSSETTINGS, &earthPage, &earthPage) //V6
,twinkleBox(WND_TWINKLEBOX, &starsSettings, &starsSettings) //V6
,brightBox(WND_BRIGHTBOX, &starsSettings, &starsSettings) //V6
,layersHeading(WND_LAYERSHEADING, &earthPage, &earthPage) //V6
,layersSlider(WND_LAYERSSPIN, &earthPage, &earthPage, //V6
IRectangle(), 4ul, 45ul, //V6
IProgressIndicator::alignBottom | //V6
IProgressIndicator::snapToTickMark| //V6
IProgressIndicator::primaryScale1 | //V6
IProgressIndicator::horizontal | //V6
IProgressIndicator::homeLeft | //V6
ISlider::buttonsRight | //V6
IWindow::visible) //V6
,earthColorHeading(WND_EARTHCOLORHEADING, &earthPage, &earthPage) //V6
,earthColorSettings(WND_EARTHCOLORSETTINGS, &earthPage, &earthPage) //V6
,cyanButton(WND_CYANBUTTON, &earthColorSettings, //V6
&earthColorSettings) //V6
,greenButton(WND_GREENBUTTON, &earthColorSettings, //V6
&earthColorSettings) //V6
,whiteButton(WND_WHITEBUTTON, &earthColorSettings, //V6
&earthColorSettings) //V6
,yellowButton(WND_YELLOWBUTTON, &earthColorSettings, //V6
&earthColorSettings) //V6
,earthPageButtons(WND_EARTHPAGEBUTTONS, &earthPage, &earthPage) //V6
,earthApplyButton(DID_EARTHAPPLY, &earthPageButtons, //V6
&earthPageButtons) //V6
,earthResetButton(DID_EARTHRESET, &earthPageButtons, //V6
&earthPageButtons) //V6
,earthCloseButton(DID_NOTEBOOKCLOSE, &earthPageButtons, //V6
&earthPageButtons) //V6
,dateTimePage(WND_DATETIMEPAGE, &helloSettingsNotebook, //V6
&helloSettingsNotebook) //V6
,dateTimePageHeading(WND_DATETIMEPAGEHEADING, &dateTimePage, //V6
&dateTimePage) //V6
,dateHeading(WND_DATEHEADING, &dateTimePage, &dateTimePage) //V6
,dateSettings(WND_DATESETTINGS, &dateTimePage, &dateTimePage) //V6
,dateLongButton(WND_DATELONGBOX, &dateSettings, &dateSettings) //V6
,dateShortButton(WND_DATESHORTBOX, &dateSettings, &dateSettings) //V6
,dateLongExample(WND_DATELONGEXAMPLE, &dateSettings, &dateSettings)//V6
,dateShortExample(WND_DATESHORTEXAMPLE,&dateSettings,&dateSettings)//V6
,timeHeading(WND_TIMEHEADING, &dateTimePage, &dateTimePage) //V6
,timeSettings(WND_TIMESETTINGS, &dateTimePage, &dateTimePage) //V6
,timeLongButton(WND_TIMELONGBOX, &timeSettings, &timeSettings) //V6
,timeShortButton(WND_TIMESHORTBOX, &timeSettings, &timeSettings) //V6
,timeLongExample(WND_TIMELONGEXAMPLE, &timeSettings, &timeSettings)//V6
,timeShortExample(WND_TIMESHORTEXAMPLE,&timeSettings,&timeSettings)//V6
,dateTimePageButtons(WND_DATETIMEPAGEBUTTONS, &dateTimePage, //V6
&dateTimePage) //V6
,dateTimeApplyButton(DID_DATETIMEAPPLY, &dateTimePageButtons, //V6
&dateTimePageButtons) //V6
,dateTimeResetButton(DID_DATETIMERESET, &dateTimePageButtons, //V6
&dateTimePageButtons) //V6
,dateTimeCloseButton(DID_NOTEBOOKCLOSE, &dateTimePageButtons, //V6
&dateTimePageButtons) //V6
, notebookCommandHandler(this) //V6
{ //V6
/*------------------------ Setup Text Values -----------------------------| V6
| Load text strings from the resource file and set alignment where needed.| V6
|------------------------------------------------------------------------*/ //V6
earthPageHeading.setText(IResourceId(STR_EARTHPAGEHEADING)) //V6
.setAlignment(IStaticText::centerCenter); //V6
starsHeading.setText(IResourceId(STR_STARSHEADING)); //V6
twinkleBox.setText(IResourceId(STR_TWINKLEBOX)); //V6
brightBox.setText(IResourceId(STR_BRIGHTBOX)); //V6
layersHeading.setText(IResourceId(STR_LAYERSHEADING)); //V6
earthColorHeading.setText(IResourceId(STR_EARTHCOLORHEADING)); //V6
cyanButton.setText(IResourceId(STR_CYAN)); //V6
greenButton.setText(IResourceId(STR_GREEN)); //V6
whiteButton.setText(IResourceId(STR_WHITE)); //V6
yellowButton.setText(IResourceId(STR_YELLOW)); //V6
earthApplyButton.setText(IResourceId(STR_APPLY)); //V6
earthResetButton.setText(IResourceId(STR_RESET)); //V6
earthCloseButton.setText(IResourceId(STR_CLOSE)); //V6
dateTimePageHeading.setText(IResourceId(STR_DATETIMEPAGEHEADING)) //V6
.setAlignment(IStaticText::centerCenter); //V6
dateHeading.setText(IResourceId(STR_DATEHEADING)); //V6
dateLongButton.setText(IResourceId(STR_DATELONGBOX)); //V6
dateShortButton.setText(IResourceId(STR_DATESHORTBOX)); //V6
dateLongExample.setText(IResourceId(STR_DATELONGEXAMPLE)) //V6
.setAlignment(IStaticText::centerLeft); //V6
dateShortExample.setText(IResourceId(STR_DATESHORTEXAMPLE)) //V6
.setAlignment(IStaticText::centerLeft); //V6
timeHeading.setText(IResourceId(STR_TIMEHEADING)); //V6
timeLongButton.setText(IResourceId(STR_TIMELONGBOX)); //V6
timeShortButton.setText(IResourceId(STR_TIMESHORTBOX)); //V6
timeLongExample.setText(IResourceId(STR_TIMELONGEXAMPLE)) //V6
.setAlignment(IStaticText::centerLeft); //V6
timeShortExample.setText(IResourceId(STR_TIMESHORTEXAMPLE)) //V6
.setAlignment(IStaticText::centerLeft); //V6
dateTimeApplyButton.setText(IResourceId(STR_APPLY)); //V6
dateTimeResetButton.setText(IResourceId(STR_RESET)); //V6
dateTimeCloseButton.setText(IResourceId(STR_CLOSE)); //V6
/*---------------------------- Setup the Slider --------------------------| V6
| Set the width and value for each tick mark on the slider. | V6
|------------------------------------------------------------------------*/ //V6
layersSlider.setTickLength(5). //V6
setTickText(0,"0"). //V6
setTickText(1,"1"). //V6
setTickText(2,"2"). //V6
setTickText(3,"3"); //V6
/*----------------------- Setup the Color Button Canvas ------------------| V6
| Place the color buttons in the colors canvas. | V6
| Start with column 2 to get a left margin. | V6
|------------------------------------------------------------------------*/ //V6
earthColorSettings.addToCell(&cyanButton, 2,1); //V6
earthColorSettings.addToCell(&greenButton, 2,2); //V6
earthColorSettings.addToCell(&whiteButton, 3,1); //V6
earthColorSettings.addToCell(&yellowButton,3,2); //V6
/*----------------------- Setup the Earth Page Canvas --------------------| V6
| Organize the Earth settings page on the earthPage multicell canvas. | V6
| Start with column 2 to get a left margin. | V6
| The headings span 2 columns to prevent stretching of the controls. | V6
|------------------------------------------------------------------------*/ //V6
earthPage.addToCell(&earthPageHeading, 2, 1,2,1); //V6
earthPage.addToCell(&starsHeading, 2, 4,2,1); //V6
earthPage.addToCell(&starsSettings, 2, 5,1,1); //V6
earthPage.addToCell(&layersHeading, 2, 8,2,1); //V6
earthPage.addToCell(&layersSlider, 2, 9,1,2); //V6
earthPage.addToCell(&earthColorHeading, 2,13,2,1); //V6
earthPage.addToCell(&earthColorSettings, 2,14,1,2); //V6
earthPage.addToCell(&earthPageButtons, 2,18,2,1); //V6
/*----------------------- Set Earth Page Initial Values ------------------| V6
| Call the function that sets the earth page values from the source | V6
| AEarthWindow. | V6
|------------------------------------------------------------------------*/ //V6
resetEarthSettings(); //V6
twinkleBox.enableTabStop(); //V6
layersSlider.enableTabStop(); //V6
cyanButton.enableTabStop(); //V6
earthApplyButton.enableTabStop(); //V6
/*----------------- Setup the Date & Time Settings Canvas ----------------| V6
| Organize the date & time radio buttons and examples on the | V6
| dateTimeSettings multicell canvas. | V6
| Start with column 2 to get a left margin. | V6
| The controls are placed in column 2 and the examples in column 3. | V6
| The setAlignment(IStaticText::centerLeft) functions used when setting | V6
| the text values cause the examples to align vertically. | V6
|------------------------------------------------------------------------*/ //V6
dateSettings.addToCell(&dateLongButton, 2, 1); //V6
dateSettings.addToCell(&dateLongExample, 3, 1); //V6
dateSettings.addToCell(&dateShortButton, 2, 2); //V6
dateSettings.addToCell(&dateShortExample,3, 2); //V6
timeSettings.addToCell(&timeLongButton, 2, 1); //V6
timeSettings.addToCell(&timeLongExample, 3, 1); //V6
timeSettings.addToCell(&timeShortButton, 2, 2); //V6
timeSettings.addToCell(&timeShortExample,3, 2); //V6
/*------------------- Setup the Date & Time Page Canvas ------------------| V6
| Organize the date & time settings page on the dateTimePage canvas. | V6
| Start with column 2 to get a left margin. | V6
| The headings span 2 columns to prevent stretching of the controls. | V6
| The settings canvases contained in the page canvas is assigned to an | V6
| area that is two columns by two rows. | V6
|------------------------------------------------------------------------*/ //V6
dateTimePage.addToCell(&dateTimePageHeading,2, 1,2,1); //V6
dateTimePage.addToCell(&dateHeading, 2, 4,2,1); //V6
dateTimePage.addToCell(&dateSettings, 2, 5,2,2); //V6
dateTimePage.addToCell(&timeHeading, 2, 9,1,1); //V6
dateTimePage.addToCell(&timeSettings, 2,10,2,2); //V6
dateTimePage.addToCell(&dateTimePageButtons,2,14,2,1); //V6
/*------------------- Set Date & Time Page Initial Values ----------------| V6
| Call the function that sets the date & time page values from the source | V6
| AHelloWindow. | V6
|------------------------------------------------------------------------*/ //V6
resetDateTimeSettings(); //V6
dateLongButton.enableTabStop(); //V6
timeLongButton.enableTabStop(); //V6
dateTimeApplyButton.enableTabStop(); //V6
/*-------------------- Setup the Settings Notebook -----------------------| V6
| Create the notebook page settings with attributes for a major tab and | V6
| automatic page size. | V6
| Set tab text to the Earth tab text from the resource file. | V6
| Use the earthPage canvas and the notebook settings to add a page to the | V6
| beginning of the notebook. | V6
| Reset the tab text to the date and time tab text from the resource file.| V6
| Use the dateTimePage canvas and the notebook settings to add a page to | V6
| the end of the notebook. | V6
| The Motif release of the User Interface Class Library automatically | V6
| sizes the major tab. For other releases, manually resize the tabs. | V6
|------------------------------------------------------------------------*/ //V6
INotebook::PageSettings //V6
helloSettings(INotebook::PageSettings::majorTab| //V6
INotebook::PageSettings::autoPageSize); //V6
helloSettings.setTabText(IResourceId(STR_EARTHTAB)); //V6
helloSettingsNotebook.addFirstPage(helloSettings,&earthPage); //V6
helloSettings.setTabText(IResourceId(STR_DATETIMETAB)); //V6
helloSettingsNotebook.addLastPage(helloSettings,&dateTimePage); //V6
#ifndef IC_MOTIF //V6
helloSettingsNotebook.setMajorTabSize(ISize(100,30)); //V6
#endif //V6
/*-----------------------------------------------------------------------------
| When a page is added to a notebook and using the autoPageSize style, |
| the pages are automatically resized to the current notebook size. |
| Therefore, we need to resize the notebook pages to their minimum size |
| so that the notebook can properly calculate it's minimum size. |
-----------------------------------------------------------------------------*/
earthPage.sizeTo( earthPage.minimumSize() ); //V6
dateTimePage.sizeTo( dateTimePage.minimumSize() ); //V6
/*-------------------- Complete Setup of the Frame -----------------------| V6
| Place the notebook into the client portion of the ANotebookWindow frame.| V6
| Start processing command events for all the controls in the notebook. | V6
|------------------------------------------------------------------------*/ //V6
setClient(&helloSettingsNotebook); //V6
notebookCommandHandler.handleEventsFor(&helloSettingsNotebook); //V6
/*-----------------------------------------------------------------------------
| Resize the notebook frame window based on the minimum size of the notebook |
-----------------------------------------------------------------------------*/
#ifndef IC_MOTIF //V6
moveSizeToClient( IRectangle( position(), //V6
helloSettingsNotebook.minimumSize() ) ); //V6
#else //V6
moveSizeTo( IRectangle( position(), //V6
helloSettingsNotebook.minimumSize() ) ); //V6
#endif //V6
} /* end ANotebookWindow :: ANotebookWindow(...) */ //V6
/************************************************************************** V6
* ANotebookWindow :: ~ANotebookWindow - Destructor for the notebook window* V6
* Stop handling events for the notebook. * V6
**************************************************************************/ //V6
ANotebookWindow :: ~ANotebookWindow() //V6
{ //V6
notebookCommandHandler.stopHandlingEventsFor(&helloSettingsNotebook); //V6
} /* end ANotebookWindow :: ~ANotebookWindow() */ //V6
/************************************************************************** V6
* ANotebookWindow :: applyEarthSettings * V6
* Apply earth settings changes to the owner's earth window. * V6
**************************************************************************/ //V6
ANotebookWindow //V6
&ANotebookWindow :: applyEarthSettings() //V6
{ //V6
AHelloWindow *helloWindow = (AHelloWindow *)owner(); //V6
helloWindow->earth()->enableTwinkle(twinkleBox.isSelected()); //V6
helloWindow->earth()->enableBright(brightBox.isSelected()); //V6
helloWindow->earth()->setLayers(layersSlider.armTickOffset()); //V6
if (cyanButton.isSelected()) //V6
helloWindow->earth()->setEarthColor(IColor::cyan); //V6
if (greenButton.isSelected()) //V6
helloWindow->earth()->setEarthColor(IColor::green); //V6
if (whiteButton.isSelected()) //V6
helloWindow->earth()->setEarthColor(IColor::white); //V6
if (yellowButton.isSelected()) //V6
helloWindow->earth()->setEarthColor(IColor::yellow); //V6
//V6
return (*this); //V6
} /* end ANotebookWindow :: applyEarthSettings() */ //V6
//V6
/************************************************************************** V6
* ANotebookWindow :: resetEarthSettings * V6
* Reset local earth settings to the current settings from the * V6
* owner's earth window. * V6
**************************************************************************/ //V6
ANotebookWindow //V6
&ANotebookWindow :: resetEarthSettings() //V6
{ //V6
AHelloWindow *helloWindow = (AHelloWindow *)owner(); //V6
helloWindow->earth()->isTwinkling() ? twinkleBox.select() //V6
: twinkleBox.deselect(); //V6
helloWindow->earth()->isBright() ? brightBox.select() //V6
: brightBox.deselect(); //V6
layersSlider.moveArmToTick(helloWindow->earth()->layers()); //V6
if (helloWindow->earth()->earthColor().value()==IColor::cyan) //V6
cyanButton.select(); //V6
if (helloWindow->earth()->earthColor().value()==IColor::green) //V6
greenButton.select(); //V6
if (helloWindow->earth()->earthColor().value()==IColor::white) //V6
whiteButton.select(); //V6
if (helloWindow->earth()->earthColor().value()==IColor::yellow) //V6
yellowButton.select(); //V6
//V6
return (*this); //V6
} /* end ANotebookWindow :: resetEarthSettings() */ //V6
/************************************************************************** V6
* ANotebookWindow :: applyDateTimeSettings * V6
* Apply date and time settings changes to the owner's window. * V6
**************************************************************************/ //V6
ANotebookWindow //V6
&ANotebookWindow :: applyDateTimeSettings() //V6
{ //V6
AHelloWindow *helloWindow = (AHelloWindow *)owner(); //V6
helloWindow->enableDateLong(dateLongButton.isSelected()); //V6
helloWindow->enableTimeLong(timeLongButton.isSelected()); //V6
//V6
return (*this); //V6
} /* end ANotebookWindow :: applyDateTimeSettings() */ //V6
//V6
/************************************************************************** //V6
* ANotebookWindow :: resetDateTimeSettings * //V6
* Reset local date and time settings to current settings from the * //V6
* owner's window. * //V6
**************************************************************************/ //V6
ANotebookWindow //V6
&ANotebookWindow :: resetDateTimeSettings() //V6
{ //V6
AHelloWindow *helloWindow = (AHelloWindow *)owner(); //V6
helloWindow->isDateLong() ? dateLongButton.select() //V6
: dateShortButton.select(); //V6
helloWindow->isTimeLong() ? timeLongButton.select() //V6
: timeShortButton.select(); //V6
//V6
return (*this); //V6
} /* end ANotebookWindow :: resetDateTimeSettings() */ //V6
//V6
/************************************************************************** V6
* ANotebookCommandHandler :: ANotebookCommandHandler - constructor * V6
* Construct the command handler from a pointer to the * V6
* ANotebookWindow for which events will be handled. * V6
**************************************************************************/ //V6
ANotebookCommandHandler :: ANotebookCommandHandler(ANotebookWindow *nbFrame)//V6
{ //V6
frame=nbFrame; //Save frame to be handled V6
} /* end ANotebookCommandHandler :: ANotebookCommandHandler(...) */ //V6
/************************************************************************** //V6
* ANotebookCommandHandler :: command * //V6
* Process command events for ANotebookWindow. * //V6
**************************************************************************/ //V6
IBase::Boolean //V6
ANotebookCommandHandler :: command(ICommandEvent & cmdEvent) //V6
{ //V6
Boolean eventProcessed(true); //Assume event will be processed //V6
/*--------------------- Process command events ---------------------------| //V6
| Depending on the command event ID, | //V6
| update or reset local settings to the Hello World settings. | //V6
| Regardless of the page, if the close button is pressed, close notebook.| //V6
|------------------------------------------------------------------------*/ //V6
switch (cmdEvent.commandId()) { //V6
case DID_EARTHAPPLY: //V6
frame->applyEarthSettings(); //V6
break; //V6
case DID_EARTHRESET: //V6
frame->resetEarthSettings(); //V6
break; //V6
case DID_DATETIMEAPPLY: //V6
frame->applyDateTimeSettings(); //V6
break; //V6
case DID_DATETIMERESET: //V6
frame->resetDateTimeSettings(); //V6
break; //V6
case DID_NOTEBOOKCLOSE: //V6
frame->close(); //V6
break; //V6
default: //Otherwise, //V6
eventProcessed=false; // the event wasn't processed //V6
} /* end switch */ //V6
//V6
return(eventProcessed); //V6
} /* end ANotebookCommandHandler :: command(...) */ //V6