home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
NOTIFY
/
NOTIFY.CPP
< prev
next >
Wrap
Text File
|
1995-05-01
|
7KB
|
194 lines
/******************************************************************************
* NOTIFY SAMPLE APPLICATION - notify.cpp *
* 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 sample *
* code, even if they have been advised of the possibility of such damages. *
* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
* *
* This program demonstrates notifications. An entryfield is displayed that *
* will only accept characters between 'a' and 'z'. If data is entered that *
* does not match this criteria, a message warning is displayed.
*******************************************************************************/
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <iapp.hpp>
#include <iframe.hpp>
#include <imenubar.hpp>
#include <ientryfd.hpp>
#include <isetcv.hpp>
#include <icmdhdr.hpp>
#include <istattxt.hpp>
#include <istring.hpp>
#include <imsgbox.hpp>
#include <ipushbut.hpp>
#include <iobservr.hpp>
#include <inotifev.hpp>
#include "notify.hpp"
#include "notify.h"
class CustomerObject;
IFrameWindow* frame;
IEntryField* ef;
IPushButton* pb;
CustomerObject* co;
IStaticText* display;
class CustomerObject {
public:
CustomerObject& storeName(IString name)
{
firstName = name;
return *this;
}
IString name()
{
return firstName;
}
private:
IString
firstName;
};
/*********************************************************************/
/* Declare the entryField observer class. Override the */
/* dispatchNotificationEvent function and process the notifications */
/* needed. */
/*********************************************************************/
class efObserver : public IObserver {
public:
virtual IObserver
&dispatchNotificationEvent (const INotificationEvent& anEvent)
{
if (anEvent.notificationId() == IEntryField::textId)
{
IWindow& window = ((IWindow&)anEvent.notifier());
IEntryField* entryField = ((IEntryField*)&window);
IString text(entryField->text());
if (!(text.isAlphabetic()))
{
pb->disable();
IMessageBox msgBox(frame);
msgBox.setTitle("Notification information");
IString
str("Illegal characters entered. Only alphabetic chars allowed");
msgBox.show(str, IMessageBox::information);
}
else
{
pb->enable();
}
}
else if (anEvent.notificationId() == IEntryField::enableId)
{
/**************************************************************/
/* If the entryField is enabled, enable our pushbutton... if */
/* the entryField is disabled, disable our pushbutton. */
/**************************************************************/
if (anEvent.eventData().asUnsignedLong())
{
pb->enable();
}
else
{
pb->disable();
}
}
else if (anEvent.notificationId() == IButton::buttonClickId)
{
/***************************************/
/* Store the data in our bogus object. */
/***************************************/
co->storeName(ef->text());
}
return *this;
}
};
//*************************************************************************
// main - Application entry point *
//*************************************************************************
int main()
{
/************************************/
/* Create our bogus customer object */
/************************************/
co = new CustomerObject();
/*************************************************************/
/* Create the frame window and give it an icon and menu bar. */
/*************************************************************/
frame = new IFrameWindow("Notify Sample",WND_MAIN);
frame->setIcon( WND_MAIN );
MyMenuCommandHandler* menuCmdHandler = new MyMenuCommandHandler();
menuCmdHandler->handleEventsFor(frame);
IMenuBar* menuBar = new IMenuBar(MAIN_MENU, frame);
/*******************************************************************/
/* Create a canvas with a statictext, entryfield and a pushbutton. */
/*******************************************************************/
ISetCanvas* sc = new ISetCanvas(SC_1, frame, frame);
IStaticText* st = new IStaticText(ST_1, sc, sc);
st->setText("alphabetic data only");
ef = new IEntryField(EF_1, sc, sc);
pb = new IPushButton(PB_1, sc, sc);
pb->setText("Enter");
pb->disable();
/*************************************************************/
/* Create our observer and tell it to observe the entryfield */
/* and pushbutton. */
/*************************************************************/
efObserver* entryFieldObserver = new efObserver();
entryFieldObserver->handleNotificationsFor(*ef);
entryFieldObserver->handleNotificationsFor(*pb);
/**********************************************************/
/* Enable the entryfield and pushbutton for notifications */
/**********************************************************/
ef->enableNotification();
pb->enableNotification();
/****************************************************************/
/* Add another static text field to display the contents of our */
/* customer object. */
/****************************************************************/
display = new IStaticText(ST_2, sc, sc);
frame->setClient(sc);
frame->setFocus();
frame->show();
IApplication::current().run();
return 0;
}
IBase::Boolean MyMenuCommandHandler::command(ICommandEvent& event)
{
switch(event.commandId())
{
case MI_DISABLEEF:
ef->disable();
return true;
break;
case MI_ENABLEEF:
ef->enable();
return true;
break;
case MI_SHOW:
display->setText(co->name());
return true;
break;
}
return false;
}