home *** CD-ROM | disk | FTP | other *** search
- #ifndef _WMASKTB_HPP_INCLUDED
- #define _WMASKTB_HPP_INCLUDED
-
- /*************************************************************************
- *
- * WMaskedTextBox -- Base MaskedTextBox class
- *
- *
- * Events:
- *
- ************************************************************************/
-
- enum WDateOrder {
- WDateOrderUSA,
- WDateOrderEUR,
- WDateOrderJIS,
- };
-
- #include <ctype.h>
- #ifndef _WTEXTBOX_HPP_INCLUDED
- # include "wtextbox.hpp"
- #endif
-
- #define DEFAULT_PROMPT_CHAR '_'
- #define MASK_DIGIT '#'
- #define MASK_ALPHANUM '?'
- #define MASK_UPPERCASE 'U'
- #define MASK_LOWERCASE 'L'
- #define MASK_MIXEDCASE 'M'
- #define MASK_DECIMAL_SEP '.'
- #define MASK_THOUSANDS_SEP ','
- #define MASK_TIME_SEP ':'
- #define MASK_DATE_SEP '/'
- #define MASK_WILD '*'
- #define MASK_LITERAL '\\'
-
- // Text formatting constants and data structures
-
- #define VALID_ROUTINE 0
- #define INVALID_ROUTINE 40
- #define MAXYEAR 3000
-
- enum {
- DECIMAL_SUB = 0,
- THOUSANDS_SUB,
- TIMESEP_SUB,
- DATESEP_SUB,
- NUM_COUNTRY,
- };
-
- typedef struct dateInf {
- WULong month;
- WULong year;
- WULong daynum;
- WULong day;
- WBool dayset;
- WBool daynumset;
- WBool yearset;
- WBool monthset;
- } dateInfo;
-
- typedef dateInfo * pdateInfo;
-
- typedef struct timeInf {
- WULong hours;
- WULong minutes;
- WULong seconds;
- WULong millths;
- WBool millthsset;
- WBool secondsset;
- WBool minutesset;
- WBool hoursset;
- } timeInfo;
-
- typedef timeInfo * ptimeInfo;
-
- typedef struct numInf {
- WString number;
- WLong exponent;
- WBool negative;
- } numInfo;
-
- typedef numInfo * pnumInfo;
-
-
- class WCMCLASS WMaskedTextBox : public WTextBox
- {
- /**************************************************************
- * Constructors and destructors
- **************************************************************/
- public:
- WMaskedTextBox();
- ~WMaskedTextBox();
-
- /**************************************************************
- * Properties
- **************************************************************/
- public:
-
- // AcceptLiterals
-
- WBool GetAcceptLiterals() const;
- WBool SetAcceptLiterals( WBool acceptLiterals );
-
- // BeepOnInvalidInput
-
- WBool GetBeepOnInvalidInput() const;
- WBool SetBeepOnInvalidInput( WBool beepOnInvalidInput );
-
- // InputMask
- // InputMask
-
- WString GetInputMask() const;
- WBool SetInputMask( WString mask );
-
- // OutputFormat
-
- WString GetOutputFormat() const;
- WBool SetOutputFormat( WString format );
-
- // PromptChar
-
- WChar GetPromptChar() const;
- WBool SetPromptChar( WChar newchar );
-
- // UseCurrentDate
-
- WBool GetUseCurrentDate() const;
- WBool SetUseCurrentDate( WBool val );
-
- // DateOrder
-
- WBool SetDateOrder( WDateOrder order );
- WDateOrder GetDateOrder() const;
-
- // Text Properties
-
- WString GetFormattedText() const;
- WString GetMaskedText() const;
-
- // Autotab
-
- WBool GetAutoTab() const;
- WBool SetAutoTab( WBool val );
-
- // Use Period Date Format
-
- WBool GetUsePeriodDateFormat() const;
- WBool SetUsePeriodDateFormat( WBool val );
-
- /**************************************************************
- * Methods
- **************************************************************/
-
- public:
- static WString FormatString( WString input, WString mask,
- WBool useCurDate = FALSE,
- WBool usePerDateFormat = FALSE,
- WDateOrder dOrder = WDateOrderUSA,
- WBool stripPromptChars = TRUE,
- WChar promptChar = DEFAULT_PROMPT_CHAR );
-
- /**************************************************************
- * Event Handlers
- **************************************************************/
-
- public:
-
- WBool CreateEventHandler( WWindow *, WCreateEventData * );
- WBool LostFocusHandler( WWindow *, WFocusEventData * );
- WBool GotFocusHandler( WWindow *, WFocusEventData * );
- WBool ChangeEventHandler( WWindow *, WEventData * );
-
- /**************************************************************
- * Overriddes
- **************************************************************/
-
- public:
- WBool ProcessMessage( const WMessage &msg, WLong &returns );
- virtual WBool SetText( const WString &text );
- WString GetText( WULong line ) const;
- virtual WString GetText() const;
- virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
- void *data );
- virtual WBool LoadWindow( WWindow * parent,
- const WResourceID & id,
- WModuleHandle module=_ApplicationModule );
- virtual WBool MakeWindow( WWindow * parent, WUInt id,
- const WChar *className,
- const WChar *title, const WRect & r,
- WStyle wstyle, WStyle exStyle,
- void * data=NULL );
-
- /**************************************************************
- * Others
- **************************************************************/
-
- private:
- WRange FilterAndInsert( WRange selected, WString text );
- WBool ProcessKeyPress( WInt key );
- WBool ProcessCharacter( WInt pos, WInt key );
- void SetNewPromptStr( WString mask );
- WInt GetNumLiterals( WRange selRange ) const;
- void CheckAutoTab() const;
- void PasteText();
-
-
- /**************************************************************
- * Text formatting functions
- **************************************************************/
-
- private:
- static WString Format( WString input, WString mask,
- WBool usecurrentdate,
- WBool usePerDateFormat, WULong inptype );
-
- static WBool GetEraYear( WULong year, WString &sEra, WULong &lYear );
-
- static WULong DaysThisYear( WULong year, WULong month,
- WULong daynum );
-
- static void InvBaseDate( WULong daynumber, pdateInfo dinfo );
-
- static WULong BaseDate( WULong year, WULong month, WULong daynum );
-
- static WBool DayCheck( pdateInfo dinfo );
-
- static WBool FormatInDateInfo( pdateInfo dinfo, WString input,
- WBool usecurrentdate,
- WULong inptype );
-
- static WString FormatOutDateInfo( pdateInfo dinfo, WString mask,
- WBool usePerDateFormat );
-
- static WString FormatDate( WString input, WString mask,
- WBool usecurrentdate,
- WBool usePerDateFormat, WULong inptype );
-
- static WBool FormatInTimeInfo( ptimeInfo tinfo,
- WString input, WBool usecurrentdate );
-
- static WString FormatOutTimeInfo( ptimeInfo tinfo,
- WString mask );
-
- static WString FormatTime( WString input, WString mask,
- WBool usecurrentdate );
-
- static WBool FormatInNumberInfo( pnumInfo ninfo, WString input );
-
- static WULong FormatOutNumber( WString &output, WString mask,
- pnumInfo ninfo );
-
- static WString FormatOutNumberInfo( pnumInfo ninfo, WString mask );
-
- static WString FormatNumber( WString input, WString mask );
-
- static WString FormatOutString( WString input, WString mask );
-
- /**************************************************************
- * Data Members
- **************************************************************/
-
- private:
- WString _inputMask;
- WString _outputFormat;
- WString _promptStr;
- WString _rawText;
- WString _maskNoLiterals;
- WChar _promptChar;
- WInt _maskLen;
- WBool _useCurDate;
- WBool _autoTab;
- WBool _usePDateFormat;
- WBool _restore;
- WDateOrder _dateOrder;
- char *_literalPos;
- WBool _faked;
- WBool _acceptLiterals;
- WBool _beepOnInvalidInput;
- };
-
- #endif
-