home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
strgen.zip
/
strgen.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-15
|
12KB
|
352 lines
/*******************************************************************************
* FILE NAME: strgen.cpp *
* *
* DESCRIPTION: *
* Class implementation of the class: *
* strgen- Sample of using IStringGenerator class *
* ---------------------------------------------------------------------------- *
* Warning: This file was generated by the VisualAge C++ Visual Builder. *
* Modifications to this source file will be lost when the part is regenerated. *
*******************************************************************************/
#ifndef _IFRAME_
#include <iframe.hpp>
#endif
#ifndef _ICANVAS_
#include <icanvas.hpp>
#endif
#ifndef _ILISTCVW_
#include <ilistcvw.hpp>
#endif
#ifndef _MYSTRGEN_
#include "mystrgen.hpp"
#endif
#ifndef _IRECT_
#include <irect.hpp>
#endif
#ifndef _IPOINT_
#include <ipoint.hpp>
#endif
#ifndef _ISTATTXT_
#include <istattxt.hpp>
#endif
#ifndef _CUSTOMER_
#include "Customer.hpp"
#endif
#ifndef _IVSEQ_H_
#include <ivseq.h>
#endif
#ifndef _INOTIFEV_
#include <inotifev.hpp>
#endif
#ifndef _IOBSERVR_
#include <iobservr.hpp>
#endif
#ifndef _ISTDNTFY_
#include <istdntfy.hpp>
#endif
#ifndef _STRGEN_
#include "strgen.hpp"
#endif
#ifndef _IVBDEFS_
#include <ivbdefs.h>
#endif
#ifndef _ITRACE_
#include <itrace.hpp>
#endif
//*****************************************************************************
// Class definition for strgenConn0
//*****************************************************************************
class strgenConn0 : public IObserver {
public:
virtual ~strgenConn0(){};
//---------------------------------------------------------------------------
// public member functions
//---------------------------------------------------------------------------
void initialize(IVSequence< Customer* > * aSource, ICollectionViewListBox< Customer*, IVSequence< Customer* > > * aTarget)
{source = aSource; target = aTarget; aligning = false; };
void setSource()
{ };
void setTarget()
{
if (aligning==false) {
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP(" firing connection : VSequence1(this) to CollectionViewListBox1(items))");
ITRACE_DEVELOP(" setting target from source ");
aligning = true;
try {target->setItems(source);}
catch (IException& exc) {};
aligning = false;
}
};
protected:
//---------------------------------------------------------------------------
// protected member functions
//---------------------------------------------------------------------------
virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
{
if (anEvent.notificationId() == VBINITIALIZEID) setTarget();
if ((anEvent.notificationId() == ICollectionViewListBox< Customer*, IVSequence< Customer* > >::itemsId) && (target == &anEvent.notifier()))
setSource(); /* set source to target value */
return(*this);
};
private:
//---------------------------------------------------------------------------
// private member data
//---------------------------------------------------------------------------
IVSequence< Customer* > * source;
ICollectionViewListBox< Customer*, IVSequence< Customer* > > * target;
Boolean aligning;
}; //strgenConn0
//*****************************************************************************
// Class definition for strgenConn1
//*****************************************************************************
class strgenConn1 : public IObserver, public IStandardNotifier {
public:
virtual ~strgenConn1(){};
//---------------------------------------------------------------------------
// public member functions
//---------------------------------------------------------------------------
void initialize(strgen * aSource, IVSequence< Customer* > * aTarget)
{source = aSource; target = aTarget; enableNotification(); };
strgenConn1 & setElement(Customer * aSelf) {iElement = aSelf; return *this;};
protected:
//---------------------------------------------------------------------------
// protected member functions
//---------------------------------------------------------------------------
virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
{
if (anEvent.notificationId() == strgen::readyId)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP(" firing connection : (ready) to VSequence1(addAsLast))");
try {target->addAsLast(iElement);}
catch (IException& exc) {};
}
return(*this);
};
private:
//---------------------------------------------------------------------------
// private member data
//---------------------------------------------------------------------------
strgen * source;
IVSequence< Customer* > * target;
Customer * iElement;
}; //strgenConn1
//*****************************************************************************
// Class definition for strgenConn2
//*****************************************************************************
class strgenConn2 : public IObserver, public IStandardNotifier {
public:
virtual ~strgenConn2(){};
//---------------------------------------------------------------------------
// public member functions
//---------------------------------------------------------------------------
void initialize(strgen * aSource, IVSequence< Customer* > * aTarget)
{source = aSource; target = aTarget; enableNotification(); };
strgenConn2 & setElement(Customer * aSelf) {iElement = aSelf; return *this;};
protected:
//---------------------------------------------------------------------------
// protected member functions
//---------------------------------------------------------------------------
virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
{
if (anEvent.notificationId() == strgen::readyId)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP(" firing connection : (ready) to VSequence1(addAsLast))");
try {target->addAsLast(iElement);}
catch (IException& exc) {};
}
return(*this);
};
private:
//---------------------------------------------------------------------------
// private member data
//---------------------------------------------------------------------------
strgen * source;
IVSequence< Customer* > * target;
Customer * iElement;
}; //strgenConn2
#pragma export (strgen::readyId)
const INotificationId strgen::readyId = "strgen::readyId";
#pragma export (strgen::partWindowId)
unsigned long strgen::partWindowId = 0;
//------------------------------------------------------------------------------
// strgen :: defaultFramingSpec
//------------------------------------------------------------------------------
#pragma export (strgen::defaultFramingSpec())
const IRectangle strgen::defaultFramingSpec()
{
return(IRectangle(IPoint(30, IWindow::desktopWindow()->size().height() - 30 - 384),ISize(512, 384)));
}
//------------------------------------------------------------------------------
// strgen :: defaultTitle
//------------------------------------------------------------------------------
#pragma export (strgen::defaultTitle())
IString strgen::defaultTitle()
{
return("IStringGenerator Sample");
}
//------------------------------------------------------------------------------
// strgen :: strgen
//------------------------------------------------------------------------------
#pragma export (strgen::strgen(unsigned long, IWindow*, IWindow*, const IRectangle&, const IFrameWindow::Style&, const char*))
strgen::strgen(
unsigned long id,
IWindow* parent,
IWindow* owner,
const IRectangle& rect,
const IFrameWindow::Style& style,
const char* title)
: IFrameWindow((partWindowId) ? partWindowId : id, parent, owner, rect, style, title)
{
partWindowId = (partWindowId) ? partWindowId : id;
iCanvas = new ICanvas(
IC_FRAME_CLIENT_ID,
this,
this,
IRectangle());
iCollectionViewListBox1 = new ICollectionViewListBox< Customer*, IVSequence< Customer* > >(
partWindowId+WNDOFFSET_strgen_CollectionViewListBox1,
iCanvas,
iCanvas,
IRectangle(IPoint(65,105),ISize(383, 183)),
IBaseListBox::defaultStyle ( ),
MyStringGen());
iStaticText1 = new IStaticText(
partWindowId+WNDOFFSET_strgen_StaticText1,
iCanvas,
iCanvas,
IRectangle(IPoint(70,294),ISize(285, 25)));
iCustomer1 = new Customer();
iCustomer2 = new Customer();
iVSequence1 = new IVSequence< Customer* >();
conn0 = new strgenConn0();
conn1 = new strgenConn1();
conn2 = new strgenConn2();
this->setFocus();
this->setClient(iCanvas);
iStaticText1->setText("Customer - CollectionViewListBox");
iCustomer1->setName("John Smith");
iCustomer1->setStreet("123 42nd Street");
iCustomer1->setPhone("512-235-8212");
iCustomer1->setCity("NewYork");
iCustomer2->setName("Mike Lawrence");
iCustomer2->setStreet("88 Columbus Ave");
iCustomer2->setPhone("416-123-8888");
iCustomer2->setCity("Ajax");
} //end constructor
//------------------------------------------------------------------------------
// strgen :: ~strgen
//------------------------------------------------------------------------------
#pragma export (strgen::~strgen())
strgen::~strgen()
{
conn0->stopHandlingNotificationsFor(*iVSequence1);
conn0->stopHandlingNotificationsFor(*iCollectionViewListBox1);
conn1->stopHandlingNotificationsFor(*this);
conn2->stopHandlingNotificationsFor(*this);
delete conn0;
delete conn1;
delete conn2;
delete iCanvas;
delete iCollectionViewListBox1;
delete iStaticText1;
delete iCustomer1;
delete iCustomer2;
delete iVSequence1;
}
//------------------------------------------------------------------------------
// strgen :: initializePart
//------------------------------------------------------------------------------
#pragma export (strgen::initializePart())
strgen & strgen::initializePart()
{
makeConnections();
notifyObservers(INotificationEvent(readyId, *this));
return *this;
}
//------------------------------------------------------------------------------
// strgen :: makeConnections
//------------------------------------------------------------------------------
#pragma export (strgen::makeConnections())
Boolean strgen::makeConnections()
{
this->enableNotification();
iCanvas->enableNotification();
iCollectionViewListBox1->enableNotification();
iStaticText1->enableNotification();
iCustomer1->enableNotification();
iCustomer2->enableNotification();
iVSequence1->enableNotification();
conn0->initialize(iVSequence1, iCollectionViewListBox1);
conn0->handleNotificationsFor(*iVSequence1);
conn0->handleNotificationsFor(*iCollectionViewListBox1);
conn1->initialize(this, iVSequence1);
conn1->handleNotificationsFor(*this);
conn2->initialize(this, iVSequence1);
conn2->handleNotificationsFor(*this);
conn1->setElement(iCustomer1);
conn2->setElement(iCustomer2);
conn0->setTarget();
return true;
}