home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
CNR
/
ACNR.CPP
next >
Wrap
Text File
|
1995-05-01
|
14KB
|
382 lines
/******************************************************************************/
/* Container Sample Program - C++ Source Code (ACNR.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 */
/******************************************************************************/
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <iapp.hpp> //IApplication Class
#include <icolor.hpp> //IColor Class
#include <istattxt.hpp> //IStaticText Class
#include <ipopmenu.hpp> //Popup Menu Classes
#include <imenubar.hpp> //IMenuBar Class
#include <imenuhdr.hpp> //IMenuHandler Class
#include <icnr.hpp> //Containers Classes
#include <ireslib.hpp> //Resource Classes
#include <imle.hpp> //IMultiLineEdit Class
#include <istring.hpp> //IString Class
#include <imsgbox.hpp> //IMessageBox Class
#include <iframe.hpp> //Include IFrameWindow Class Header
#include "acnr.hpp" //Include ACnrexWindow Class headers
#include "acnr.h" //Include our Symbolic definitions
//*************************************************************************
// main - Application entry point *
//*************************************************************************
int main() //Main Procedure with no parameters
{
ACnrexWindow mainWindow (WND_MAIN); //Create our main window
IApplication::current().run(); //Get the current application and run
return 0;
} /* end main */
//**************************************************************************
// ACnrexWindow :: ACnrexWindow - Constructor for our main window *
//**************************************************************************
ACnrexWindow :: ACnrexWindow(unsigned long windowId)
: IFrameWindow ( //Call IFrameWindow constructor
IFrameWindow::defaultStyle() // Use default plus
| IFrameWindow::minimizedIcon, // Get Minimized Icon from RC file
windowId) // Main Window ID
{
menuBar=new IMenuBar(WND_MAIN, this);
cnrCtl=new IContainerControl(CNR_RESID, this, this);
_pcnrEdit=new CnrEditHandler(); //Create Container Edit Handler
_pcnrEdit->handleEventsFor(cnrCtl);
ICommandHandler::handleEventsFor(this);
ICnrHandler::handleEventsFor(cnrCtl); //Set Container Handler for handleOpen
Chdr.handleEventsFor(cnrCtl);
Chdr.setCnr(cnrCtl);
_pcnrEdit->handleEventsFor(cnrCtl);
cnrCtl->setExtendedSelection(); //Allow Extended Selection
colIcon=new IContainerColumn (IContainerColumn::isIcon);
colName=new IContainerColumn (IContainerColumn::isIconViewText);
colName->enableDataUpdate();
colCode=new IContainerColumn (offsetof(Department, strCode));
colCode->enableDataUpdate();
colAddress=new IContainerColumn (offsetof(Department, strAddress));
colAddress->enableDataUpdate();
setClient(cnrCtl);
setFocus();
dept1=new Department( //Create Department 1
"OS/2 Development",
IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
"TWPD",
"Building 71");
dept1->enableDataUpdate();
dept2=new Department( //Create Department 2
"Code Development",
IApplication::current().userResourceLibrary().loadIcon(CLOGO),
"TUID",
"Building 71");
dept2->enableDataUpdate();
dept3=new Department( //Create Department 3
"Information Development",
IApplication::current().userResourceLibrary().loadIcon(WLOGO),
"TP1D",
"Building 71");
dept3->enableDataUpdate();
dept4=new Department( //Create Department 4
"Quality Assurance",
IApplication::current().userResourceLibrary().loadIcon(OSLOGO),
"TECD",
"Building 71");
dept4->enableDataUpdate();
dept5=new Department( //Create Department 5
"AIX Development",
IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
"TAIX",
"Building 71");
dept5->enableDataUpdate();
dept6=new Department( //Create Department 6
"Windows Development",
IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
"TWIN",
"Building 71");
dept6->enableDataUpdate();
cnrCtl->addObject(dept1); //Add Department 1 to container
cnrCtl->addObject(dept2,dept1); //Add Department 2 to container under 1
cnrCtl->addObject(dept3,dept1); //Add Department 3 to container under 1
cnrCtl->addObject(dept4,dept1); //Add Department 4 to container under 1
cnrCtl->addObject(dept5); //Add Department 5 to container
cnrCtl->addObject(dept6); //Add Department 6 to container
/* set the title data for details view */
colIcon->setHeadingText("Icon");
colName->setHeadingText("Department Name");
colCode->setHeadingText("Code");
colAddress->setHeadingText("Address ");
/* add column separators */
colIcon->showSeparators(IContainerColumn::horizontalSeparator);
colName->showSeparators(IContainerColumn::verticalSeparator);
colCode->showSeparators();
colAddress->showSeparators();
/* add the columns to the container */
cnrCtl->addColumn(colIcon);
cnrCtl->addColumn(colName);
cnrCtl->addColumn(colCode);
cnrCtl->addColumn(colAddress);
cnrCtl->setDetailsViewSplit(colName, 350);
cnrCtl->setDeleteObjectsOnClose();
/*-----------------------------------------------------*/
/* End of Details View setup */
/*-----------------------------------------------------*/
cnrCtl->arrangeIconView();
cnrCtl->showTreeLine();
cnrCtl->showTitle();
cnrCtl->enableDrawItem();
cnrCtl->showTreeIconView();
cnrCtl->setMixedTargetEmphasis();
menuBar->disableItem(ID_MARKALL); //Disable Mark All Menu Item
menuBar->disableItem(ID_UNMARKALL); //Disable Mark All Menu Item
show();
cnrCtl->show();
} /* end ACnrexWindow :: ACnrexWindow(...) */
Department :: Department(const IString& Name, //Department Constructor
const IPointerHandle& Icon,
const IString& Code,
const IString& Address) :
IContainerObject(Name, Icon), //Call IContainerObject Constructor
strCode (Code), //Set Code
strAddress (Address) //Set Address
{}
void Department :: handleOpen (IContainerControl* container)
{
new ADepartmentView(this, container); // Pass in our Object and Window
}
ADepartmentView :: ADepartmentView (Department * aDept, IContainerControl* anOwner)
: IFrameWindow(WND_DEPT, 0, anOwner)
{
aDept->setOpen();
saveDept=aDept;
setAutoDeleteObject(); //Delete C++ Obj, if PM Obj is deleted
IStaticText * stext=new IStaticText( //Create static text control with
0x1010, this, this); // this as owner & parent
stext->setText(aDept->iconText()); //Set text in Static Text Control
stext->setAlignment( //Set Alignment to Center in both
IStaticText::centerCenter); // directions
stext->setAutoDeleteObject(); //Delete C++ Obj, if PM Obj is deleted
setClient(stext); //Set static text control as Client
sizeTo(ISize(400,300)); //Set the pixel size of main window
setFocus(); //Set focus to window
show(); //Set to show window
}
ADepartmentView :: ~ADepartmentView ()
{
saveDept->setClosed(); //Set Closed
}
IBase::Boolean ACnrexWindow :: command(ICommandEvent& cmdevt) {
switch(cmdevt.commandId()) {
case ID_VTEXT: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showTextView();
}
break;
case ID_VFTEXT: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showFlowedTextView();
}
break;
case ID_VNAME: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showNameView();
}
break;
case ID_VFNAME: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showFlowedNameView();
}
break;
case ID_VDETAILS: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showDetailsView();
}
break;
case ID_FILTER1: { //Handle Show Only level Selected
SelectedObjectsFilter selObjects;
cnrCtl->filter( selObjects );
}
break;
case ID_FILTER2: { //Handle Show all
AllObjectsFilter allObjects;
cnrCtl->filter( allObjects );
}
break;
case ID_VTICON: {
menuBar->disableItem(ID_MARKALL); //Disable Mark All Menu Item
menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
cnrCtl->showTreeIconView();
}
break;
case ID_VTTEXT: {
menuBar->disableItem(ID_MARKALL); //Disable Mark All Menu Item
menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
cnrCtl->showTreeTextView();
}
break;
case ID_VTNAME: {
menuBar->disableItem(ID_MARKALL); //Disable Mark All Menu Item
menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
cnrCtl->showTreeNameView();
}
break;
case ID_VICON: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->showIconView();
}
break;
case ID_VARRANGE: {
menuBar->enableItem(ID_MARKALL); //Enable Mark All Menu Item
menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
cnrCtl->arrangeIconView();
}
break;
case ID_MARKALL: {
IContainerControl::ObjectCursor CO1 (*cnrCtl);
for (CO1.setToFirst(); CO1.isValid(); CO1.setToNext())
{
try
{
cnrCtl->setSelected(cnrCtl->objectAt(CO1));
}
catch (IException& exc) {}
}
}
break;
case ID_UNMARKALL: {
IContainerControl::ObjectCursor CO2 (*cnrCtl);
for (CO2.setToFirst(); CO2.isValid(); CO2.setToNext())
{
try
{
cnrCtl->removeSelected(cnrCtl->objectAt(CO2));
}
catch (IException& exc) {}
}
}
break;
case MI_EDRECORD: {
IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
CO3.setToFirst();
IContainerObject * CurObj = CO3.current();
cnrCtl->editObject(CurObj);
}
break;
case MI_EDNAME: {
IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
CO3.setToFirst();
IContainerObject * CurObj2 = cnrCtl->objectAt(CO3);
cnrCtl->editObject(CurObj2, colName );
}
break;
case MI_EDCODE: {
IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
CO3.setToFirst();
cnrCtl->editObject(CO3.current(),colCode);
}
break;
case MI_EDADDRESS: {
IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
CO3.setToFirst();
cnrCtl->editObject(CO3.current(),colAddress);
}
break;
}
return(false);
}
IBase::Boolean ACnrMenuHandler :: makePopUpMenu(IMenuEvent& cnEvt) //
{ //
IPopUpMenu * popUp; //Define popUp variable
if (popupMenuObject()) {
popUp=new IPopUpMenu(ID_POPMENU, //Create PopUp Menu
cnEvt.window()); //
if (!pcnrCtl->isDetailsView()) //Details View is only way to edit
{ // Name, Code and Address so
popUp->disableItem(MI_EDNAME); // Disable these items if not
popUp->disableItem(MI_EDCODE); // details view.
popUp->disableItem(MI_EDADDRESS); //
}
else
{
popUp->disableItem(MI_EDRECORD); //
}
popUp->setAutoDeleteObject(); //
popUp->show(cnEvt.mousePosition()); //Show PopUp Menu
pcnrCtl->showSourceEmphasis(popupMenuObject());
pcnrCtl->setCursor(popupMenuObject());
return true; //Return PopUp Menu
}
return false;
};