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