home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ICLUI.ZIP
/
HELLO5
/
AHELLOW5.CPP
< prev
next >
Wrap
Text File
|
1993-03-09
|
26KB
|
357 lines
/******************************************************************************/
/* HELLO WORLD SAMPLE PROGRAM - Version 5: Class Implementation (AHELLOW5.CPP)*/
/* */
/* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1993. */
/* */
/* 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
//**************************************************************************
// C++ Hello World History and Key Functions: *
// Version 1: *
// - Creates and runs a simple application *
// - Creates the main window (IFrameWindow) *
// - Creates a static text control set to "Hello, World!" as the *
// client window *
// *
// Version 2: (lines with v2 in column 79-80) * v2
// - Create Main Window (AHellowWindow) as subclass of IFrameWindow * .
// - Gets the "Hello, World!!" text string and other items from a * .
// resource file * .
// - Sets the window title from a resource file * .
// - Creates and sets the information area at the bottom of the * .
// client area * v2
// *
// Version 3: (lines with v3 in column 79-80) * v3
// - Add Alignment (Left, Center, Right) Menu Bar * .
// - Add Command Processing to set the "Hello, World" alignment * .
// - Place check in front of the Left, Center or Right Menu Item * .
// - Create and maintain Status Line with current alignment status * v3
// *
// Version 4: (lines with v4 in column 79-80) * v4
// - Add Accelerator Keys for Left (F7), Center(F8), Right(F9) * .
// - Modify Left, Center and Right Menu Items to show function key * .
// - Modify Menu Bar to create Edit Menu and "text..." Menu Item * .
// - Add ADialogText to allow user to change "Hello, World" text * .
// - Add Push Buttons & Set Canvas to change alignment * v4
// *
// Version 5: (lines with v5 in column 79-80) * v5
// - Code a new control (AEarthWindow) using PM Graphics calls * .
// - Add AEarthWindow to the bottom of the client area * .
// - Add Help Windows for the Main, Dialog, Entry Field Windows * .
// - Use Split Canvas as the Client Area * .
// - Add ListBox to Client Area to change "Hello, World" text * v5
//**************************************************************************
//Include IBM UI class headers:
#include <iapp.hpp> //IApplication Class
#include <istattxt.hpp> //IStaticText Class
#include <iinfoa.hpp> //IInfoArea Class v2
#include <imenubar.hpp> //IMenuBar Class v3
#include <ifont.hpp> //IFont v3
#include <istring.hpp> //IString Class v4
#include <isetcv.hpp> //ISetCanvas Class v4
#include <ipushbut.hpp> //IPushButton Class v4
#include <ihelp.hpp> //IHelpWindow Class v5
#include <ihelphdr.hpp> //IHelpHandler Class v5
#include <isplitcv.hpp> //ISplitCanvas Class v5
#include <ilistbox.hpp> //IListBox v5
#include "ahellow5.hpp" //Include AHelloWindow Class headers v2
#include "ahellow5.h" //Include our Symbolic definitions v2
#include "adialog5.hpp" //ATextDialog Class v4
#include "aearthw5.hpp" //AEarthWindow Class v5
//*************************************************************************
// main - Application entry point *
//*************************************************************************
void main() //Main Procedure with no parameters
{
AHelloWindow mainWindow (WND_MAIN); //Create our main window on the
// desktop
IApplication::current().run(); //Get the current application and
// run it
} /* end main */
//**************************************************************************
// AHelloWindow :: AHelloWindow - Constructor for our main window *
//**************************************************************************
AHelloWindow :: AHelloWindow(unsigned long windowId)
: IFrameWindow ( //Call IFrameWindow constructor v2
IFrameWindow::defaultStyle() // Use default plus v2
| IFrameWindow::minimizedIcon // Get Minimized Icon from RC file v2
| IFrameWindow::menuBar // Get Menu Bar from RC file v3
| IFrameWindow::accelerator, // Get Accelerator Table from RC filev4
windowId) // Main Window ID
{
setupClient(); //Setup Client Window v5
setupStatusArea(); //Setup Status Area .
setupInfoArea(); //Setup Information Area v5
setupButtons(); //Setup Buttons v4
setupMenuBar(); //Setup Menu Bar v5
setupHelp(); //Setup Help v5
sizeTo(ISize(400,300)); //Set the size of main window v2
setFocus(); //Set focus to main window
show(); //Set to show main window
} /* end AHelloWindow :: AHelloWindow(...) */
//************************************************************************** v4
// AHelloWindow :: setupButtons * .
// Setup Buttons * .
//************************************************************************** .
Boolean AHelloWindow :: setupButtons() //Setup Buttons .
{ // .
ISetCanvas * buttons; //Define canvas of buttons v4
IPushButton * helpButton; //Define Help Button v5
// v4
buttons=new ISetCanvas(WND_BUTTONS, //Create a Set Canvas for Buttons .
this, this) ; // Parent and Owner=me .
buttons->setMargin(ISize()); //Set Canvas Margins to zero .
buttons->setPad(ISize()); //Set Button Canvas Pad to zero .
leftButton=new IPushButton(MI_LEFT, //Create Left Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
leftButton->setText(STR_LEFTB); //Set Left Button Text .
centerButton=new IPushButton(MI_CENTER,//Create Left Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
centerButton->setText(STR_CENTERB); //Set Center Button Text .
rightButton=new IPushButton(MI_RIGHT, //Create Right Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
rightButton->setText(STR_RIGHTB); //Set Right Button Text v4
helpButton=new IPushButton(MI_HELP, //Create Right Push Button v5
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IPushButton::help | // Help Style .
IControl::tabStop); // tabStop .
helpButton->setText(STR_HELPB); //Set Help Button Text v5
addExtension(buttons, //Add Buttons Canvas v4
IFrameWindow::belowClient, // below client and specify .
30UL); // unsigned long height in pixels .
return true; //Return .
} /* end AHelloWindow :: setupButtons() */ //v4
//************************************************************************** v5
// AHelloWindow :: setupHelp() * .
// Setup Help * .
//************************************************************************** .
Boolean AHelloWindow :: setupHelp() //Setup Help Area .
{ // .
help=new IHelpWindow(HELP_TABLE, //Create Help Window Object .
this); //Setup Help info .
help->addLibraries("AHELLOW5.HLP"); // set self, help table filename .
help->setTitle(STR_HTITLE); //Set the Help Window Title .
// .
AHelpHandler* phelpHandler= //Create Custon Help Handler to .
new AHelpHandler(); // handle the Keys Help .
phelpHandler->handleEventsFor(this); //Start Help Handler .
return true; // .
} /* end AHelloWindow :: setupHelp() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupClient() * .
// Setup Client * .
//************************************************************************** .
Boolean AHelloWindow :: setupClient() //Setup Client Window .
{ // .
clientWindow=new ISplitCanvas( //Create Canvas .
WND_CANVAS, this, this); // with Window Id, parent, owner .
setClient(clientWindow); //Set canvas as Client Window .
helloCanvas=new ISplitCanvas( //Create Hello Canvas .
WND_HCANVAS, clientWindow, // with Window Id, parent .
clientWindow); // and owner .
helloCanvas->setOrientation( //Set the orientation .
ISplitCanvas::horizontalSplit); // to horizontal v5
hello=new IStaticText(WND_HELLO, //Create Static Text Control
helloCanvas, helloCanvas); // Pass in client as owner & parent v5
hello->setText(STR_HELLO); //Set text v2
earthWindow = new AEarthWindow //Create Earth Graphic Window v5
(WND_EARTH, helloCanvas); // Set Window ID, client-owner/parentv5
hello->setAlignment( //Set Alignment to Center in both
IStaticText::centerCenter); // directions
listBox=new IListBox(WND_LISTBOX, //Create ListBox v5
clientWindow, clientWindow, // Parent/Owner is ClientWindow .
IRectangle(), // .
IListBox::defaultStyle() | // .
IControl::tabStop | // Set Tab Stop .
IListBox::noAdjustPosition); // Allow the Canvas to control size .
listBox->addAsc("Hello, World!"); //Add "Hello, World!" .
listBox->addAsc("Hi, World!"); //Add "Hi, World!" .
listBox->addAsc("Howdy, World!"); //Add "Howdy, World!" .
listBox->addAsc("Alo, Mundo!"); //Add Portuguese Version .
listBox->addAsc("Ola, Mondo!"); //Add Spain .
listBox->addAsc("Hallo wereld!"); //Add Dutch .
listBox->addAsc("Hallo Welt!"); //Add German .
listBox->addAsc("Bonjour le monde!"); //Add French .
ISelectHandler::handleEventsFor(listBox);//Set self as select event handler .
// .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
helloCanvas, 60); // the helloCanvas to 60 .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
listBox, 40); // the listBox to 40 .
// .
return true; // .
} /* end AHelloWindow :: setupClient() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupInfoArea() * .
// Setup Information Area * .
//************************************************************************** .
Boolean AHelloWindow :: setupInfoArea() //Setup Information Area .
{ // v5
infoArea=new IInfoArea(this); //Create the information area v2
infoArea->setInactiveText(STR_INFO); //Set information area text from RC v2
setExtensionSize(infoArea, // v5
(int)IFont(infoArea).maxCharHeight());//and specify height .
return true; // .
} /* end AHelloWindow :: setupInfoArea() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupMenuBar() * .
// Setup Menu Bar * .
//************************************************************************** .
Boolean AHelloWindow :: setupMenuBar() //Setup Menu Bar .
{ // .
ICommandHandler::handleEventsFor(this);//Set self as command event handler v5
menuBar=new IMenuBar(WND_MAIN, //Create Menu Bar for main window v3
this); // Set self as parent .
menuBar->checkItem(MI_CENTER); //Place Check on Center Menu Item v3
return true; // v5
} /* end AHelloWindow :: setupMenuBar() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupStatusArea() * .
// Setup Statue Area * .
//************************************************************************** .
Boolean AHelloWindow :: setupStatusArea()//Setup Status Area .
{ // v5
statusLine=new IStaticText //Create Status Area using Static Textv3
(WND_STATUS, this, this); // Window ID, Parent, Owner Parameters.
statusLine->setText(STR_CENTER); //Set Status Text to "Center" from Res .
addExtension(statusLine, //Add Status Line above the client .
IFrameWindow::aboveClient, // and specify the height .
IFont(statusLine).maxCharHeight()); // and specify height v3
return true; // v5
} /* end AHelloWindow :: setupStatusArea() */ //v5
//************************************************************************** v5
// AHelloWindow :: setText(...) * .
// Set Text * .
//************************************************************************** .
Boolean AHelloWindow :: setText(const char* text)//Set Text using String .
{ // .
hello->setText(text); //Set Text in Control .
return true; //Return .
} /* end AHelloWindow :: setText(...) */ //v5
//************************************************************************** v5
// AHelloWindow :: selected(...) * .
// Handle selected command from list box * .
// * .
// Note: It would be easy to change this selected member function to enter * .
//************************************************************************** .
Boolean AHelloWindow :: selected(IControlEvent & evt) // .
{ // .
IListBox::Cursor lbCursor(*listBox); //List Box Cursor .
lbCursor.setToFirst(); //Set to first item selected .
setText(listBox->elementAt(lbCursor));//Set Hello Text to Selected Item .
return true; //Return Command Processed .
} /* end AHelloWindow :: selected(...) */ //v5
//************************************************************************** v3
// AHelloWindow :: command * .
// Handle menu commands * .
//************************************************************************** .
Boolean AHelloWindow :: command(ICommandEvent & cmdEvent) // .
{ //v3
IString temp; //String to pass in/out from dialog v4
unsigned short value; //Return value from dialog v4
switch (cmdEvent.commandId()) { //Get command id v3
case MI_CENTER: //Code to Process Center Command Item v3
hello->setAlignment( //Set alignment of hello text to .
IStaticText::centerCenter); // center-vertical, center-horizontal .
statusLine->setText(STR_CENTER); //Set Status Text to "Center" from Res .
menuBar->checkItem(MI_CENTER); //Place Check on Center Menu Item .
menuBar->uncheckItem(MI_LEFT); //Uncheck Left Menu Item .
menuBar->uncheckItem(MI_RIGHT); //Uncheck Right Menu Item .
return(true); //Return command processed .
break; // v3
case MI_LEFT: //Code to Process Left Command Item v3
hello->setAlignment( //Set alignment of hello text to .
IStaticText::centerLeft); // center-vertical, left-horizontal .
statusLine->setText(STR_LEFT); //Set Status Text to "Left" from Res .
menuBar->uncheckItem(MI_CENTER); //Uncheck Center Menu Item .
menuBar->checkItem(MI_LEFT); //Place Check on Left Menu Item .
menuBar->uncheckItem(MI_RIGHT); //Uncheck Right Menu Item .
return(true); //Return command processed .
break; // v3
case MI_RIGHT: //Code to Process Right Command Item v3
hello->setAlignment( //Set alignment of hello text to .
IStaticText::centerRight); // center-vertical, right-horizontal .
statusLine->setText(STR_RIGHT); //Set Status Text to "Right" from Res .
menuBar->uncheckItem(MI_CENTER); //Uncheck Center Menu Item .
menuBar->uncheckItem(MI_LEFT); //Uncheck Left Menu Item .
menuBar->checkItem(MI_RIGHT); //Place Check on Right Menu Item .
return(true); //Return command processed .
break; // v3
case MI_TEXT: //Code to Process Text Command v4
{
temp=hello->text(); //Get current Hello text .
infoArea->setInactiveText( //Set Info Area to Dialog Active .
STR_INFODLG); // Text from Resource File .
ATextDialog * textDialog=new //Create a Text Dialog .
ATextDialog(temp, this); // .
textDialog->showModally(); //Show this Text Dialog as Modal .
value=textDialog->result(); //Get result (eg OK or Cancel) .
if (value != DID_CANCEL) //Set new string if not canceled .
hello->setText(temp); //Set Hello to Text from Dialog .
infoArea->setText(STR_INFO); //Set Info Text to "Normal" from Res .
delete textDialog; //Delete textDialog .
return(true); //Return Command Processed .
break; // v4
}
case MI_GENERAL_HELP: //Code to Process Help for help v5
help->show(IHelpWindow::general); //Show General Help Panel .
return(true); //Return command processed .
break; // v5
} /* end switch */ // v3
return(false); //Return command not processed v3
} /* end AHelloWindow :: command(...) */ //v3
//************************************************************************** v5
// AHelpHandler :: keysHelpId * .
// Handle the keys help request event * .
// This overrides the default provided by IBMCLASS * .
//************************************************************************** .
Boolean AHelpHandler :: keysHelpId(IEvent& evt) // .
{ // .
evt.setResult(1000); //1000=keys help id in .
// ahellow5.ipf file .
return true; //Return command processed .
} /* end AHelpHandler :: keysHelpId(...) */ //v5