home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
entryf.zip
/
EFTYPES.CPP
next >
Wrap
C/C++ Source or Header
|
1994-05-20
|
4KB
|
186 lines
#include "eftypes.hpp"
#include <Istring.hpp>
#include <IWindow.hpp>
#include <imsgbox.hpp>
#define INCL_DOSPROCESS /* Process and thread values */
#include <os2.h>
#include <stdio.h>
#define BEEP_FREQUENCY 1380
#define BEEP_DURATION 100
/*******************************************************************
*
* support of special entry field types
*
*******************************************************************/
EDate::EDate(unsigned long id,IWindow* parent):IEntryField(id,parent)
{
((IFocusHandler*)this)->handleEventsFor(this);
}
/*******************************************************************
*
* Post validation of date field with reformat
*
*******************************************************************/
Boolean EDate::lostFocus(IControlEvent& event )
{
IString dStr = text();
if (dStr.length() == 0) return True;
dStr.translate('/',' ');
dStr.translate('-',' ');
dStr.translate('\\',' ');
IString A = dStr.word(1);
IString B = dStr.word(2);
IString C = dStr.word(3);
int month = A.asInt();
int day = B.asInt();
int year = C.asInt();
if (year < 1900) year += 1900;
IDate Dt((IDate::Month) month,day,year);
if (Dt.isValid((IDate::Month) month,day,year))
{
dStr = Dt.asString(IDate::yyyy);
setText(dStr);
return true;
}
// IMessageBox Error(owner());
// Error.show("Invalid date, must be mm-dd-yy or mm-dd-yyyy ",IMessageBox::okButton);
APIRET rc; /* Return code */
rc = DosBeep(BEEP_FREQUENCY,
BEEP_DURATION *2);
setFocus();
return true;
}
/*******************************************************************
*
* Post validation of phone field with re-format
*
*******************************************************************/
EPhone::EPhone(unsigned long id,IWindow* parent):IEntryField(id,parent)
{
((IFocusHandler*)this)->handleEventsFor(this);
}
Boolean EPhone::lostFocus(IControlEvent& event )
{
/*******************************************************************
*
* Assume a phone is (xxx) xxx-xxxx
*
*******************************************************************/
Boolean warn;
IString pStr= text();
if (pStr.length() == 0) return True;
pStr.translate('/',' ');
pStr.translate('-',' ');
pStr.translate('\\',' ');
pStr.translate('(',' ');
pStr.translate(')',' ');
IString A;
IString B;
IString C;
if (pStr.numWords() ==3)
{
A = pStr.word(1);
B = pStr.word(2);
C = pStr.word(3);
warn = false;
}
else
{
A = " ";
B = pStr.word(1);
C = pStr.word(2);
warn = true;
}
IString phone = "(";
phone += A;
phone +=") ";
phone += B;
phone += '-';
phone += C;
setText(phone);
if (warn)
{
IMessageBox Error(owner());
Error.show("WARNING missing area code ",IMessageBox::okButton);
}
return true;
}
/*******************************************************************
*
* Upper case conversion - post
*
*******************************************************************/
EUEntryField::EUEntryField(unsigned long id,IWindow* parent):IEntryField(id,parent)
{
((IFocusHandler*)this)->handleEventsFor(this);
}
Boolean EUEntryField::lostFocus(IControlEvent & event)
{
IString t = text(); // read the field
t.upperCase(); // convert to upper case
setText(t); // display in upper case
return true;
}
ENumeric::ENumeric(unsigned long id,IWindow* parent):IEntryField(id,parent)
{
((IKeyboardHandler*)this)->handleEventsFor(this);
}
/*******************************************************************
*
* Keyboard validation of numeric char input only
* (allow a decimal point)
*******************************************************************/
ENumeric::characterKeyPress(IKeyboardEvent& event )
{
char a = event.character();
if((a >= '0' & a <= '9')| (a =='.'))
return false;
else
{
APIRET rc; /* Return code */
rc = DosBeep(BEEP_FREQUENCY,
BEEP_DURATION);
return true;
}
}