home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / wmasktb.hpp < prev    next >
C/C++ Source or Header  |  1996-12-02  |  9KB  |  271 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.     private:
  89.         WString                    _inputMask;
  90.         WString                    _outputFormat;
  91.         WString                    _promptStr;
  92.         WString                    _rawText;
  93.         WString                    _maskNoLiterals;
  94.         WChar                      _promptChar;
  95.         WInt                       _maskLen;
  96.         WBool                      _useCurDate;
  97.         WBool                      _autoTab;
  98.         WBool                      _usePDateFormat;
  99.         WBool                      _restore;
  100.         WDateOrder                 _dateOrder;
  101.         char                      *_literalPos;    
  102.         WBool                      _faked;
  103.         
  104.     /**************************************************************
  105.      * Constructors and destructors
  106.      **************************************************************/
  107.     public:
  108.         WMaskedTextBox();
  109.         ~WMaskedTextBox();
  110.  
  111.     /**************************************************************
  112.      * Properties
  113.      **************************************************************/
  114.     public:
  115.  
  116.         // InputMask
  117.         
  118.         WString  GetInputMask() const;
  119.         WBool    SetInputMask( WString mask );
  120.  
  121.         // OutputFormat
  122.         
  123.         WString  GetOutputFormat() const;
  124.         WBool    SetOutputFormat( WString format );
  125.  
  126.         // PromptChar
  127.         
  128.         WChar    GetPromptChar() const;
  129.         WBool    SetPromptChar( WChar newchar );
  130.  
  131.         // UseCurrentDate
  132.  
  133.         WBool    GetUseCurrentDate() const;
  134.         WBool    SetUseCurrentDate( WBool val );
  135.  
  136.         // DateOrder
  137.         
  138.         WBool      SetDateOrder( WDateOrder order );
  139.         WDateOrder GetDateOrder() const;
  140.  
  141.         // Text Properties
  142.         
  143.         WString GetFormattedText() const;
  144.         WString GetMaskedText() const;
  145.  
  146.         // Autotab
  147.  
  148.         WBool GetAutoTab() const;
  149.         WBool SetAutoTab( WBool val );
  150.  
  151.         // Use Period Date Format
  152.  
  153.         WBool GetUsePeriodDateFormat() const;
  154.         WBool SetUsePeriodDateFormat( WBool val );
  155.  
  156.     /**************************************************************
  157.      * Methods
  158.      **************************************************************/
  159.  
  160.     public:
  161.         static WString FormatString( WString input, WString mask,
  162.                                      WBool useCurDate = FALSE,
  163.                                      WBool usePerDateFormat = FALSE,
  164.                                      WDateOrder dOrder = WDateOrderUSA,
  165.                                      WBool stripPromptChars = TRUE,
  166.                                      WChar promptChar = DEFAULT_PROMPT_CHAR );
  167.  
  168.     /**************************************************************
  169.      * Event Handlers
  170.      **************************************************************/
  171.  
  172.     public:
  173.         
  174.         WBool CreateEventHandler( WWindow *, WCreateEventData * );
  175.         WBool LostFocusHandler( WWindow *, WFocusEventData * );
  176.         WBool GotFocusHandler( WWindow *, WFocusEventData * );
  177.         WBool ChangeEventHandler( WWindow *, WEventData * );
  178.  
  179.     /**************************************************************
  180.      * Overriddes
  181.      **************************************************************/
  182.  
  183.     public:
  184.         WBool   ProcessMessage( const WMessage &msg, WLong &returns );
  185.         virtual WBool SetText( const WString &text );
  186.         WString GetText( WULong line ) const;
  187.         virtual WString GetText() const;
  188.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  189.                                    void *data );
  190.         virtual WBool LoadWindow( WWindow * parent,
  191.                                   const WResourceID & id,
  192.                                   WModuleHandle module=_ApplicationModule );
  193.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  194.                                   const WChar *className,
  195.                                   const WChar *title, const WRect & r,
  196.                                   WStyle wstyle, WStyle exStyle,
  197.                                   void * data=NULL );
  198.     
  199.     /**************************************************************
  200.      * Others
  201.      **************************************************************/
  202.  
  203.     private:
  204.         WRange FilterAndInsert( WRange selected, WString text );
  205.         WBool  ProcessKeyPress( WInt key );
  206.         WBool  ProcessCharacter( WInt pos, WInt key );
  207.         void   SetNewPromptStr( WString mask );
  208.         WInt   GetNumLiterals( WRange selRange ) const;
  209.         void   CheckAutoTab() const;
  210.         void   PasteText();
  211.  
  212.  
  213.     /**************************************************************
  214.      * Text formatting functions
  215.      **************************************************************/
  216.  
  217.     private:
  218.         static WString Format( WString input, WString mask,
  219.                               WBool usecurrentdate,
  220.                               WBool usePerDateFormat, WULong inptype );
  221.  
  222.         static WBool GetEraYear( WULong year, WString &sEra, WULong &lYear );
  223.  
  224.         static WULong DaysThisYear( WULong year, WULong month,
  225.                                     WULong daynum );
  226.  
  227.         static void InvBaseDate( WULong daynumber, pdateInfo dinfo );
  228.  
  229.         static WULong BaseDate( WULong year, WULong month, WULong daynum );
  230.  
  231.         static WBool DayCheck( pdateInfo dinfo );
  232.  
  233.         static WBool FormatInDateInfo( pdateInfo dinfo, WString input,
  234.                                        WBool usecurrentdate,
  235.                                        WULong inptype );
  236.  
  237.         static WString FormatOutDateInfo( pdateInfo dinfo, WString mask,
  238.                                           WBool usePerDateFormat );
  239.  
  240.         static WString FormatDate( WString input, WString mask,
  241.                                   WBool usecurrentdate,
  242.                                   WBool usePerDateFormat, WULong inptype );
  243.  
  244.         static WBool FormatInTimeInfo( ptimeInfo tinfo,
  245.                                        WString input, WBool usecurrentdate );
  246.  
  247.         static WString FormatOutTimeInfo( ptimeInfo tinfo,
  248.                                           WString mask );
  249.  
  250.         static WString FormatTime( WString input, WString mask,
  251.                                    WBool usecurrentdate );
  252.  
  253.         static WBool FormatInNumberInfo( pnumInfo ninfo, WString input );
  254.  
  255. /*
  256.         static WULong FormatOutNumber( WChar **output, WChar *mask,
  257.                                        pnumInfo ninfo );
  258. */
  259.         static WULong FormatOutNumber( WString &output, WString mask,
  260.                                        pnumInfo ninfo );
  261.  
  262.         static WString FormatOutNumberInfo( pnumInfo ninfo, WString mask );
  263.  
  264.         static WString FormatNumber( WString input, WString mask );
  265.  
  266.         static WString FormatOutString( WString input, WString mask );
  267. };
  268.  
  269. #endif
  270.  
  271.