home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / VFORM.ZIP / Source / TckEdit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-10  |  6.3 KB  |  191 lines

  1. #ifndef __TCKEDIT_H__
  2. #define __TCKEDIT_H__
  3.  
  4. #ifdef VF_STATIC
  5.     #undef AFX_EXT_CLASS
  6.     #define AFX_EXT_CLASS
  7. #endif
  8.  
  9. #define TCKEDIT_NORMAL    0
  10. #define TCKEDIT_MASK    1
  11. #define TCKEDIT_NUMERIC    2
  12.  
  13. // Boolean Flags
  14. #define TCKEDITF_LOCKED            0x0001
  15. #define TCKEDITF_DOLLARSIGN        0x0002
  16. #define TCKEDITF_ADDCOMMAS        0x0004
  17. #define TCKEDITF_ALLOWNEGATIVE    0x0008
  18. #define TCKEDITF_SAVEMASKCHARS    0x0010
  19.  
  20. #define TCKEDIT_DATE    3
  21.  
  22. #define MAX_MASKSIZE    63
  23. #define VMASK_FREE        1
  24.  
  25. #define AUTO_DECIMALS    -1;
  26.  
  27. #ifndef SetBitFlag
  28. #define SetBitFlag(bitmap, nFlag, boolVal) \
  29.                     if(boolVal)    bitmap |= nFlag; \
  30.                     else        bitmap &= ~nFlag;
  31. #endif
  32.  
  33. // -------------------------------------------------------------------------
  34. // Mask Characters
  35. //
  36. //  #    0-9
  37. //    9    0-9                    optional
  38. //    A    a-z, A-Z, 0-9
  39. //    a    a-z, A-Z, 0-9        optional
  40. //    &    32-126 and 128-255    optional
  41. //    ?    a-z, A-Z
  42. //    >    convert following to uppercase
  43. //    <    convert following to lowercase
  44. //    !    stop case conversion after this point
  45. //    Z    end of mask - auto set max chars
  46. //    \    escape (for using: #, 9, A, a, &, ?, <, >)
  47. //
  48. //  In essence, we will create an Overwrite only mode
  49. //    Characters will not shift when deleting or typing
  50. //  The position of the cursor coming into OnKeyDown is fixed
  51. //  we will move one position to the right (unless we hit literals)
  52. //  if space is entered, we will use the prompt
  53. //    A space in m_literal or m_placeHolder means there is not one at this index
  54. //  m_upperLower contains 'u', 'l' or ' ' at each index
  55. //  
  56. // -------------------------------------------------------------------------
  57. class AFX_EXT_CLASS CTckEdit : public CEdit
  58. {
  59. protected:
  60.     BYTE        m_nType;            // Type of CTckEdit
  61.     UINT        m_nFlags;            // Flags for Boolean Values
  62.     // BOOL        m_bLocked;            // Similar to ReadOnly
  63.  
  64.     // ----- Color Info -----
  65.     COLORREF    m_clrText;            // Text Color
  66.     COLORREF    m_clrBack;            // Background Color
  67.     CBrush        *m_pBrBack;            // Background Color Brush
  68.  
  69.     // ----- Numeric Info -----
  70.     short    m_nDigits;                // Max number of digits
  71.     short    m_nDecimals;            // Number of decimals
  72.     // BOOL    m_bDollarSign;            // Display Dollor Sign
  73.     // BOOL    m_bAddCommas;            // Add Comma Seperators
  74.     // BOOL    m_bAllowNegative;        // Allow negative values
  75.  
  76.     // ----- Mask Info -----
  77.     CString    m_mask;                    // Mask
  78.     LPTSTR    m_literal;                // Literal array
  79.     LPTSTR    m_placeHolder;            // Place Holder array
  80.     LPTSTR    m_upperLower;            // Indicates upper/lower
  81.     // BOOL    m_bSaveMaskChars;        // Save mask characters?
  82.     _TCHAR    m_cPrompt;                // Prompt Character
  83.     short    m_nMaskEnd;                // End of mask
  84.     short    m_nMaxChars;            // Max Chars
  85.  
  86. // Construction
  87. public:
  88.     CTckEdit();
  89.  
  90. // Attributes
  91. public:
  92.  
  93.     // ------ Color Functions -----
  94.     int        GetTextColor()    { return m_clrText; }
  95.     int        GetBackColor()    { return m_clrBack; }
  96.     void    SetTextColor(COLORREF clr, BOOL bRedraw = TRUE);
  97.     void    SetBackColor(COLORREF clr, BOOL bRedraw = TRUE);
  98.     void    Redraw();                        // Redraws the Control
  99.  
  100.     virtual BOOL OnChildNotify (UINT msg, WPARAM wParam, 
  101.                                 LPARAM lParam, LRESULT *pLResult);
  102.  
  103.     // ------ General Functions -----
  104.     void    Type(int nType)                { m_nType = nType; }
  105.     int        Type()                        { return m_nType; }
  106.     BOOL    Locked()                    { return (m_nFlags & TCKEDITF_LOCKED); }
  107.     void    Locked(BOOL bFlag)            { SetBitFlag(m_nFlags, TCKEDITF_LOCKED, bFlag); }
  108.     void    SetText(LPCTSTR szText);
  109.     void    GetText(CString&);
  110.     void    ApplyFormat(CString&, LPCTSTR szOrig);
  111.  
  112.     // ------ Numeric Functions -----
  113.     int        Digits()                    { return m_nDigits; }
  114.     void    Digits(int nDigits)            { m_nDigits = nDigits; }
  115.     int        Decimals()                    { return m_nDecimals; }
  116.     void    Decimals(int nDecimals)        { m_nDecimals = nDecimals; }
  117.     // BOOL    DollarSign()                { return m_bDollarSign; }
  118.     // void    DollarSign(BOOL bFlag)        { m_bDollarSign = bFlag; }
  119.     BOOL    DollarSign()                { return (m_nFlags & TCKEDITF_DOLLARSIGN); }
  120.     void    DollarSign(BOOL bFlag)        { SetBitFlag(m_nFlags, TCKEDITF_DOLLARSIGN, bFlag); }
  121.     BOOL    AddCommas()                    { return (m_nFlags & TCKEDITF_ADDCOMMAS); }
  122.     void    AddCommas(BOOL bFlag)        { SetBitFlag(m_nFlags, TCKEDITF_ADDCOMMAS, bFlag); }
  123.     BOOL    AllowNegative()                { return (m_nFlags & TCKEDITF_ALLOWNEGATIVE); }
  124.     void    AllowNegative(BOOL bFlag)    { SetBitFlag(m_nFlags, TCKEDITF_ALLOWNEGATIVE, bFlag); }
  125.  
  126.     int        IntegerVal();
  127.     void    IntegerVal(int nValue);
  128.     double    DoubleVal();
  129.     void    DoubleVal(double nValue);
  130.  
  131.     // ------ Mask Attributes -----
  132.     LPCTSTR    Mask()                        { return m_mask; }
  133.     void    Mask(LPCTSTR szMask);
  134.     int        MaxChars()                    { return m_nMaxChars; }
  135.     void    MaxChars(int nMaxChars)        { m_nMaxChars = nMaxChars; }
  136.     BOOL    SaveMaskChars()                { return (m_nFlags & TCKEDITF_SAVEMASKCHARS); }
  137.     void    SaveMaskChars(BOOL bFlag)    { SetBitFlag(m_nFlags, TCKEDITF_SAVEMASKCHARS, bFlag); }
  138.     _TCHAR    PromptChar()                { return m_cPrompt; }
  139.     void    PromptChar(_TCHAR promptChar)    { m_cPrompt = promptChar; }
  140.     void    GetStrippedText(CString& );
  141.     BOOL    IsOptionalMask(int idx);
  142.  
  143.     // ------ Date Attributes -----
  144.     // Date Format    mm/dd/yy, mm/dd/yyyy
  145.  
  146. // Operations
  147. public:
  148.     // ------ Numeric Functions -----
  149.     void    GetDigitsCount(LPCTSTR szText, int &nDigitCnt,
  150.                     int &nDecimalCnt, int &nDecIdx, int &nEndIdx);
  151.     int        FormatNumeric(LPCTSTR szOrig, LPTSTR szNew);
  152.     void    StripToNumeric(LPCTSTR szOrig, LPTSTR szNew);
  153.     void    StripChar(LPCTSTR szOrig, LPTSTR szNew, _TCHAR c);
  154.  
  155.     void    OnCharNumeric(UINT nChar, UINT nRepCnt, UINT nFlags);
  156.     void    OnKeyDownNumeric(UINT nChar, UINT nRepCnt, UINT nFlags);
  157.     // void    OnContextMenuNumeric( CWnd* pWnd, CPoint pos );
  158.  
  159.     // ------ Mask Functions -----
  160.     BOOL    ApplyCharCheckMask(_TCHAR &c, int idx);
  161.     void    ApplyMaskToText(LPCTSTR szText, LPTSTR szResult);
  162.     void    ParseMask(LPCTSTR szMask);        // fill in literals, place holders,
  163.                                             // and upperLower arrays
  164.     void    StripMask(LPCTSTR szOrig, LPTSTR szNew);
  165.  
  166.     void    OnCharMask(UINT nChar, UINT nRepCnt, UINT nFlags);
  167.     void    OnKeyDownMask(UINT nChar, UINT nRepCnt, UINT nFlags);
  168.     void    OnContextMenuMask( CWnd* pWnd, CPoint pos );
  169.  
  170. // Overrides
  171.     // ClassWizard generated virtual function overrides
  172.     //{{AFX_VIRTUAL(CTckEdit)
  173.     //}}AFX_VIRTUAL
  174.  
  175. // Implementation
  176. public:
  177.     virtual ~CTckEdit();
  178.  
  179.     // Generated message map functions
  180. protected:
  181.     //{{AFX_MSG(CTckEdit)
  182.     afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  183.     afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  184.     afx_msg void OnContextMenu( CWnd* pWnd, CPoint pos );
  185.     //}}AFX_MSG
  186.  
  187.     DECLARE_MESSAGE_MAP()
  188. };
  189.  
  190.  
  191. #endif