home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
HELLO6
/
ADIALOG6.CPP
next >
Wrap
C/C++ Source or Header
|
1995-04-07
|
13KB
|
176 lines
/*****************************************************************************
* HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (adialog6.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: V4
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <istring.hpp> //Include IString class header V4
#include <ireslib.hpp> //Include IResourceId class header V4
#include <ihelp.hpp> //Include IHelpWindow class header V5
#include "ahellow6.h" //Include symbolic definitions v6
#include "adialog6.hpp" //Include ATextDialog class header v6
/************************************************************************** V4
* ATextDialog :: ATextDialog - Constructor for the text dialog window * V4
* Construct the dialog as a frame window owned by the window passed. * V4
* The size and position of the window are calculated as an offset * V4
* from the left bottom position of the owner window. * V4
* The style is set to match that of an OS/2 PM dialog template plus * V4
* settings for system menu and title bar. * V4
* NOTE: IWindow::visible should not be used with dialogBackground. * V4
* Create the multicell canvas with this dialog frame as owner. * V4
* Place the dialog's push buttons on a set canvas so that they are * V4
* evenly spaced. * V4
* Place the dialog controls for the static text and the entry field * V4
* along with the set canvas into a multicell canvas. * V4
* (Version 6 replaces the entry field with a drop-down combo box) * V6
* Construct the dialog command handler passing a pointer to this frame. * V4
* Save the text string reference passed into the constructor. * V4
**************************************************************************/ //V4
ATextDialog :: ATextDialog(IString & textString, IWindow * ownerWnd) //V4
: IFrameWindow(IResourceId(WND_TEXTDIALOG) //V4
,IWindow::desktopWindow() //V4
,ownerWnd //V4
,IRectangle(29,50,375,350) //v6
.moveBy(ownerWnd->rect().bottomLeft()) //V4
,IWindow::synchPaint //V4
|IWindow::clipSiblings //V4
|IWindow::saveBits //V4
|dialogBackground //V4
|dialogBorder //V4
|systemMenu //V4
|titleBar) //V4
,clientCanvas(WND_MCCANVAS,this,this) //V4
,buttons(WND_STCANVAS, &clientCanvas, &clientCanvas) //V4
,statText(DID_STATIC,&clientCanvas,&clientCanvas) //V4
,textField( DID_ENTRY,&clientCanvas,&clientCanvas //v6
,IRectangle(), IWindow::visible|IComboBox::dropDownType) //V6
,pushButton1( DID_OK,&buttons,&buttons) //V4
,pushButton2(DID_CANCEL,&buttons,&buttons) //V4
,dialogCommandHandler(this) //V4
,saveText(textString) //V4
{ //V4
/*----------------------------- Set Up Frame -----------------------------| V4
| Since the entry field is now a combox box, load the box with items | V6
| from the resource file. | V6
| Set the entry field text to the string passed in on the ATextDialog | V4
| constructor and set the style. | V4
| Set the entry field prompt and push button text strings from strings | V4
| in the resource file. | V4
| Set the push buttons and set canvas styles. The buttons set canvas | V4
| pack type is set to expanded to size both push buttons to the same | V4
| size. | V4
|------------------------------------------------------------------------*/ //V4
for (int i=0;i<HI_COUNT;i++ ) //V6
textField.addAscending(HI_WORLD+i); //V6
textField.setText(saveText); //V4
textField.disableAutoScroll().enableMargin().enableTabStop(); //V4
statText.setText(DID_STATIC); //V4
pushButton1.enableDefault().setText(IResourceId(DID_OK)).enableTabStop(); //V4
pushButton2.setText(IResourceId(DID_CANCEL)); //V4
buttons.setPackType(ISetCanvas::expanded).setMargin(ISize()); //V4
/*------------------------------- Fill Canvas ----------------------------| V4
| Position the dialog controls in the multicell canvas. | V4
|------------------------------------------------------------------------*/ //V4
clientCanvas.addToCell(&statText , 2, 4); //V4
clientCanvas.addToCell(&textField, 2, 7); //V4
clientCanvas.addToCell(&buttons, 2, 9); //V4
clientCanvas.setRowHeight(7ul, 10ul, true); //V6
/*-------------------------- Set Up Frame Window -------------------------| V4
| Set the multicell canvas as the ATextDialog client window. | V4
| Have the command handler start handling events for the frame window. | V4
| Set the focus to the entry field. | V4
|------------------------------------------------------------------------*/ //V4
setClient( &clientCanvas ); //V4
dialogCommandHandler.handleEventsFor(this); //V4
textField.setFocus(); //V4
/*------------------------ Use Owner's Help Window -----------------------| V5
| IHelpWindow::setAssociatedWindow is called to associate the dialog with| V5
| its owner's help window so that the help window is positioned | V5
| relative to this window, and so that this window is correctly | V5
| activated when the user dismisses the help window. | V5
|------------------------------------------------------------------------*/ //V5
IHelpWindow::helpWindow(ownerWnd)->setAssociatedWindow(this); //V5
} /* end ATextDialog :: ATextDialog(...) */ //V4
/************************************************************************** V4
* ATextDialog :: ~ATextDialog - Destructor for the dialog frame window * V4
* Stop handling command events for the frame. * V4
**************************************************************************/ //V4
ATextDialog :: ~ATextDialog() //V4
{ //V4
dialogCommandHandler.stopHandlingEventsFor(this); //V4
} /* end ATextDialog :: ~ATextDialog() */ //V4
/************************************************************************** V4
* ATextDialog :: setTextFromEntryField * V4
* Update the string reference passed into ATextDialog constructor using * V4
* the text from the entry field. * V4
**************************************************************************/ //V4
ATextDialog & //V4
ATextDialog::setTextFromEntryField() //V4
{ //V4
saveText = textField.text(); //V4
return (*this); //Return a reference to the frame V4
} /* end AHelloWindow :: setTextFromEntryField */ //V4
/************************************************************************** V4
* ADialogCommandHandler :: ADialogCommandHandler * V4
* Construct the command handler from a pointer to the ATextDialog * V4
* that events are handled for. * V4
**************************************************************************/ //V4
ADialogCommandHandler :: ADialogCommandHandler(ATextDialog *dialogFrame) //V4
{ //V4
frame=dialogFrame; //Save frame to be handled V4
} /* end ADialogCommandHandler :: ADialogCommandHandler(...) */ //V4
/************************************************************************** V4
* ADialogCommandHandler :: command * V4
* Handle button commands * V4
**************************************************************************/ //V4
IBase::Boolean //V4
ADialogCommandHandler :: command(ICommandEvent & cmdEvent) //V4
{ //V4
Boolean eventProcessed(true); //Assume event will be processed V4
/*--------------------- Process command events ---------------------------| V4
| Depending on the command event ID, | V4
| optionally update the Hello World text; | V4
| then dismiss the text dialog passing the event ID as the result. | V4
|------------------------------------------------------------------------*/ //V4
switch (cmdEvent.commandId()) { //V4
case DID_OK: //V4
frame->setTextFromEntryField(); //V4
frame->dismiss(DID_OK); //V4
break; //V4
case DID_CANCEL: //V4
frame->dismiss(DID_CANCEL); //V4
break; //V4
default: //Otherwise, V4
eventProcessed=false; // the event wasn't processed V4
} /* end switch */ //V4
return(eventProcessed); //V4
} /* end ADialogCommandHandler :: command(...) */ //V4