home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
TUTORIAL
/
DEBUGGER
/
MCELCV
/
AMCELCV.CPP
next >
Wrap
Text File
|
1993-04-08
|
8KB
|
145 lines
/******************************************************************************/
/* Canvas Classes Example 3 - Multi Cell Canvas */
/* */
/* 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 */
/******************************************************************************/
/* Canvas Classes Example 3 - Multi Cell Canvas */
/* key functions: */
/* - create a main window */
/* - run the current application */
/* - create a multi cell canvas and use as client area */
/* canvas has 4 columns and 7 rows */
/* one row and one column are expandable */
/* all other controls attached to canvas */
/* - create static text controls */
/* - create check boxes, radio buttons and push buttons */
/* - control cursor and tab movement between different groups */
/* - process 'Command' events generated by the push button */
/* - load strings from resource bound to the exe */
/******************************************************************************/
//Include IBM UI class headers:
#include <iapp.hpp> // IApplication
#include <imsgbox.hpp> // IMessageBox
#include <istring.hpp> // IString
#include <ireslib.hpp> // IResourceId
#include "amcelcv.h"
#include "amcelcv.hpp"
/******************************************************************************/
/* main - Application entry point */
/******************************************************************************/
void main()
{
AMultiCellCanvas mainWindow(WND_MAIN);
IApplication::current().run();
} /* end main */
/******************************************************************************/
/* AMultiCellCanvas :: AMultiCellCanvas - Constructor for our main window */
/******************************************************************************/
AMultiCellCanvas::AMultiCellCanvas(unsigned long windowId)
: IFrameWindow(windowId)
, clientCanvas( WND_MCCANVAS, this, this )
, status( WND_STATUS, &clientCanvas, &clientCanvas )
, title1( WND_TITLE1, &clientCanvas, &clientCanvas )
, title2( WND_TITLE2, &clientCanvas, &clientCanvas )
, check1( WND_CHECK1, &clientCanvas, &clientCanvas )
, check2( WND_CHECK2, &clientCanvas, &clientCanvas )
, radio1( WND_RADIO1, &clientCanvas, &clientCanvas )
, radio2( WND_RADIO2, &clientCanvas, &clientCanvas )
, pushButton( WND_PUSHBUT, &clientCanvas, &clientCanvas )
{
// make multi-cell canvas the client
setClient( &clientCanvas );
// set status area text
status.setAlignment( IStaticText::centerCenter );
status.setText( STR_STATUS );
title1.setAlignment( IStaticText::centerLeft ); // set text and attributes
title1.setText( STR_TITLE1 );
title2.setAlignment( IStaticText::centerLeft ); // set text and attributes
title2.setText( STR_TITLE2 );
check1.setText( STR_CHECK1 ); // set checkbox text
check2.setText( STR_CHECK2 );
radio1.setText( STR_RADIO1 ); // set radio button text
radio2.setText( STR_RADIO2 );
pushButton.setText( STR_PUSHBUT );
radio1.select(); // pre-select one radio button
check1.enableGroup().enableTabStop(); // set tabStop and Group styles
radio1.enableGroup().enableTabStop();
pushButton.enableGroup().enableTabStop();
pushButtonHandler.setOwnerWindow(this); // initialize push button handler
pushButtonHandler.handleEventsFor(&clientCanvas); // add handler to canvas
clientCanvas.addToCell(&status , 1, 1, 4, 1); // add controls to canvas.
clientCanvas.addToCell(&title1 , 1, 3, 2, 1); // the canvas runs from
clientCanvas.addToCell(&title2 , 3, 3, 2, 1); // 1,1 to 4,7
clientCanvas.addToCell(&check1 , 2, 4); // exactly one row and
clientCanvas.addToCell(&check2 , 2, 5); // one column is
clientCanvas.addToCell(&radio1 , 4, 4); // expandable, as this
clientCanvas.addToCell(&radio2 , 4, 5); // allows the canvas to
clientCanvas.addToCell(&pushButton , 2, 7); // fill the whole client.
clientCanvas.setRowHeight(2, 20, true); // set size of empty rows
clientCanvas.setRowHeight(6, 40);
clientCanvas.setColumnWidth(4, 40, true); // last column expandable
check1.setFocus(); // set focus to first checkbox
show(); // show main window
} /* end AMultiCellCanvas :: AMultiCellCanvas(...) */
/******************************************************************************/
/* AMultiCellCanvas :: displayButtonStatus - display a message box */
/******************************************************************************/
AMultiCellCanvas& AMultiCellCanvas::displayButtonStatus()
{
unsigned long str_id1, str_id2, str_id3;
IMessageBox msgbox(this);
IResourceLibrary reslib = IApplication::current().userResourceLibrary();
msgbox.setTitle( IResourceId(STR_MSGBOX) );
str_id1 = check1.isSelected() ? STR_CHK1_SEL : STR_CHK1_NOSEL;
str_id2 = check2.isSelected() ? STR_CHK2_SEL : STR_CHK2_NOSEL;
IString str1 = reslib.loadString(str_id1),
str2 = reslib.loadString(str_id2),
str3 = reslib.loadString( radio1.selectedIndex() + STR_RAD1_SEL );
str1 += str2 + str3;
msgbox.show( (char *)str1 , IMessageBox::okButton |
IMessageBox::informationIcon |
IMessageBox::applicationModal |
IMessageBox::moveable );
return *this;
}
/******************************************************************************/
/* APushButtonHandler :: command - handle some command events */
/******************************************************************************/
Boolean APushButtonHandler::command( ICommandEvent& evt )
{
Boolean fProcessed = false;
if (evt.commandId() == WND_PUSHBUT && window)
{
window->displayButtonStatus();
fProcessed = true;
}
return fProcessed;
}