home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / wmasktb.hpp < prev    next >
C/C++ Source or Header  |  1997-01-21  |  9KB  |  283 lines

  1. #ifndef _WMASKTB_HPP_INCLUDED
  2. #define _WMASKTB_HPP_INCLUDED
  3.  
  4. /*************************************************************************
  5.  *
  6.  * WMaskedTextBox -- Base MaskedTextBox class
  7.  *
  8.  *
  9.  *   Events:
  10.  *
  11.  ************************************************************************/
  12.  
  13. enum WDateOrder {
  14.     WDateOrderUSA,
  15.     WDateOrderEUR,
  16.     WDateOrderJIS,
  17. };
  18.  
  19. #include <ctype.h>
  20. #ifndef _WTEXTBOX_HPP_INCLUDED
  21. #  include "wtextbox.hpp"
  22. #endif
  23.  
  24. #define DEFAULT_PROMPT_CHAR              '_'
  25. #define MASK_DIGIT                       '#'
  26. #define MASK_ALPHANUM                    '?'
  27. #define MASK_UPPERCASE                   'U'
  28. #define MASK_LOWERCASE                   'L'
  29. #define MASK_MIXEDCASE                   'M'
  30. #define MASK_DECIMAL_SEP                 '.'
  31. #define MASK_THOUSANDS_SEP               ','
  32. #define MASK_TIME_SEP                    ':'
  33. #define MASK_DATE_SEP                    '/'
  34. #define MASK_WILD                        '*'
  35. #define MASK_LITERAL                     '\\'
  36.  
  37. // Text formatting constants and data structures
  38.  
  39. #define VALID_ROUTINE                  0
  40. #define INVALID_ROUTINE                40
  41. #define MAXYEAR                        3000
  42.  
  43. enum {
  44.     DECIMAL_SUB = 0,
  45.     THOUSANDS_SUB,
  46.     TIMESEP_SUB,
  47.     DATESEP_SUB,
  48.     NUM_COUNTRY,
  49. };
  50.  
  51. typedef struct dateInf {
  52.     WULong   month;
  53.     WULong   year;
  54.     WULong   daynum;
  55.     WULong   day;
  56.     WBool    dayset;
  57.     WBool    daynumset;
  58.     WBool    yearset;
  59.     WBool    monthset;
  60. } dateInfo;
  61.  
  62. typedef dateInfo * pdateInfo;
  63.  
  64. typedef struct timeInf {
  65.     WULong   hours;
  66.     WULong   minutes;
  67.     WULong   seconds;
  68.     WULong   millths;
  69.     WBool    millthsset;
  70.     WBool    secondsset;
  71.     WBool    minutesset;
  72.     WBool    hoursset;
  73. } timeInfo;
  74.  
  75. typedef timeInfo * ptimeInfo;
  76.  
  77. typedef struct numInf {
  78.     WString      number;
  79.     WLong        exponent;
  80.     WBool        negative;
  81. } numInfo;
  82.  
  83. typedef numInfo * pnumInfo;
  84.  
  85.  
  86. class WCMCLASS WMaskedTextBox : public WTextBox
  87. {
  88.     /**************************************************************
  89.      * Constructors and destructors
  90.      **************************************************************/
  91.     public:
  92.         WMaskedTextBox();
  93.         ~WMaskedTextBox();
  94.  
  95.     /**************************************************************
  96.      * Properties
  97.      **************************************************************/
  98.     public:
  99.  
  100.         // AcceptLiterals
  101.  
  102.         WBool GetAcceptLiterals() const;
  103.         WBool SetAcceptLiterals( WBool acceptLiterals );
  104.  
  105.         // BeepOnInvalidInput
  106.  
  107.         WBool GetBeepOnInvalidInput() const;
  108.         WBool SetBeepOnInvalidInput( WBool beepOnInvalidInput );
  109.  
  110.         // InputMask
  111.         // InputMask
  112.         
  113.         WString GetInputMask() const;
  114.         WBool SetInputMask( WString mask );
  115.  
  116.         // OutputFormat
  117.         
  118.         WString GetOutputFormat() const;
  119.         WBool SetOutputFormat( WString format );
  120.  
  121.         // PromptChar
  122.         
  123.         WChar GetPromptChar() const;
  124.         WBool SetPromptChar( WChar newchar );
  125.  
  126.         // UseCurrentDate
  127.  
  128.         WBool GetUseCurrentDate() const;
  129.         WBool SetUseCurrentDate( WBool val );
  130.  
  131.         // DateOrder
  132.         
  133.         WBool SetDateOrder( WDateOrder order );
  134.         WDateOrder GetDateOrder() const;
  135.  
  136.         // Text Properties
  137.         
  138.         WString GetFormattedText() const;
  139.         WString GetMaskedText() const;
  140.  
  141.         // Autotab
  142.  
  143.         WBool GetAutoTab() const;
  144.         WBool SetAutoTab( WBool val );
  145.  
  146.         // Use Period Date Format
  147.  
  148.         WBool GetUsePeriodDateFormat() const;
  149.         WBool SetUsePeriodDateFormat( WBool val );
  150.  
  151.     /**************************************************************
  152.      * Methods
  153.      **************************************************************/
  154.  
  155.     public:
  156.         static WString FormatString( WString input, WString mask,
  157.                                      WBool useCurDate = FALSE,
  158.                                      WBool usePerDateFormat = FALSE,
  159.                                      WDateOrder dOrder = WDateOrderUSA,
  160.                                      WBool stripPromptChars = TRUE,
  161.                                      WChar promptChar = DEFAULT_PROMPT_CHAR );
  162.  
  163.     /**************************************************************
  164.      * Event Handlers
  165.      **************************************************************/
  166.  
  167.     public:
  168.         
  169.         WBool CreateEventHandler( WWindow *, WCreateEventData * );
  170.         WBool LostFocusHandler( WWindow *, WFocusEventData * );
  171.         WBool GotFocusHandler( WWindow *, WFocusEventData * );
  172.         WBool ChangeEventHandler( WWindow *, WEventData * );
  173.  
  174.     /**************************************************************
  175.      * Overriddes
  176.      **************************************************************/
  177.  
  178.     public:
  179.         WBool   ProcessMessage( const WMessage &msg, WLong &returns );
  180.         virtual WBool SetText( const WString &text );
  181.         WString GetText( WULong line ) const;
  182.         virtual WString GetText() const;
  183.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  184.                                    void *data );
  185.         virtual WBool LoadWindow( WWindow * parent,
  186.                                   const WResourceID & id,
  187.                                   WModuleHandle module=_ApplicationModule );
  188.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  189.                                   const WChar *className,
  190.                                   const WChar *title, const WRect & r,
  191.                                   WStyle wstyle, WStyle exStyle,
  192.                                   void * data=NULL );
  193.     
  194.     /**************************************************************
  195.      * Others
  196.      **************************************************************/
  197.  
  198.     private:
  199.         WRange FilterAndInsert( WRange selected, WString text );
  200.         WBool  ProcessKeyPress( WInt key );
  201.         WBool  ProcessCharacter( WInt pos, WInt key );
  202.         void   SetNewPromptStr( WString mask );
  203.         WInt   GetNumLiterals( WRange selRange ) const;
  204.         void   CheckAutoTab() const;
  205.         void   PasteText();
  206.  
  207.  
  208.     /**************************************************************
  209.      * Text formatting functions
  210.      **************************************************************/
  211.  
  212.     private:
  213.         static WString Format( WString input, WString mask,
  214.                               WBool usecurrentdate,
  215.                               WBool usePerDateFormat, WULong inptype );
  216.  
  217.         static WBool GetEraYear( WULong year, WString &sEra, WULong &lYear );
  218.  
  219.         static WULong DaysThisYear( WULong year, WULong month,
  220.                                     WULong daynum );
  221.  
  222.         static void InvBaseDate( WULong daynumber, pdateInfo dinfo );
  223.  
  224.         static WULong BaseDate( WULong year, WULong month, WULong daynum );
  225.  
  226.         static WBool DayCheck( pdateInfo dinfo );
  227.  
  228.         static WBool FormatInDateInfo( pdateInfo dinfo, WString input,
  229.                                        WBool usecurrentdate,
  230.                                        WULong inptype );
  231.  
  232.         static WString FormatOutDateInfo( pdateInfo dinfo, WString mask,
  233.                                           WBool usePerDateFormat );
  234.  
  235.         static WString FormatDate( WString input, WString mask,
  236.                                   WBool usecurrentdate,
  237.                                   WBool usePerDateFormat, WULong inptype );
  238.  
  239.         static WBool FormatInTimeInfo( ptimeInfo tinfo,
  240.                                        WString input, WBool usecurrentdate );
  241.  
  242.         static WString FormatOutTimeInfo( ptimeInfo tinfo,
  243.                                           WString mask );
  244.  
  245.         static WString FormatTime( WString input, WString mask,
  246.                                    WBool usecurrentdate );
  247.  
  248.         static WBool FormatInNumberInfo( pnumInfo ninfo, WString input );
  249.  
  250.         static WULong FormatOutNumber( WString &output, WString mask,
  251.                                        pnumInfo ninfo );
  252.  
  253.         static WString FormatOutNumberInfo( pnumInfo ninfo, WString mask );
  254.  
  255.         static WString FormatNumber( WString input, WString mask );
  256.  
  257.         static WString FormatOutString( WString input, WString mask );
  258.  
  259.     /**************************************************************
  260.      * Data Members
  261.      **************************************************************/
  262.  
  263.     private:
  264.         WString                    _inputMask;
  265.         WString                    _outputFormat;
  266.         WString                    _promptStr;
  267.         WString                    _rawText;
  268.         WString                    _maskNoLiterals;
  269.         WChar                      _promptChar;
  270.         WInt                       _maskLen;
  271.         WBool                      _useCurDate;
  272.         WBool                      _autoTab;
  273.         WBool                      _usePDateFormat;
  274.         WBool                      _restore;
  275.         WDateOrder                 _dateOrder;
  276.         char                      *_literalPos;    
  277.         WBool                      _faked;
  278.         WBool                      _acceptLiterals;
  279.         WBool                      _beepOnInvalidInput;
  280. };
  281.  
  282. #endif
  283.