home *** CD-ROM | disk | FTP | other *** search
- #ifndef __TCKEDIT_H__
- #define __TCKEDIT_H__
-
- #ifdef VF_STATIC
- #undef AFX_EXT_CLASS
- #define AFX_EXT_CLASS
- #endif
-
- #define TCKEDIT_NORMAL 0
- #define TCKEDIT_MASK 1
- #define TCKEDIT_NUMERIC 2
-
- // Boolean Flags
- #define TCKEDITF_LOCKED 0x0001
- #define TCKEDITF_DOLLARSIGN 0x0002
- #define TCKEDITF_ADDCOMMAS 0x0004
- #define TCKEDITF_ALLOWNEGATIVE 0x0008
- #define TCKEDITF_SAVEMASKCHARS 0x0010
-
- #define TCKEDIT_DATE 3
-
- #define MAX_MASKSIZE 63
- #define VMASK_FREE 1
-
- #define AUTO_DECIMALS -1;
-
- #ifndef SetBitFlag
- #define SetBitFlag(bitmap, nFlag, boolVal) \
- if(boolVal) bitmap |= nFlag; \
- else bitmap &= ~nFlag;
- #endif
-
- // -------------------------------------------------------------------------
- // Mask Characters
- //
- // # 0-9
- // 9 0-9 optional
- // A a-z, A-Z, 0-9
- // a a-z, A-Z, 0-9 optional
- // & 32-126 and 128-255 optional
- // ? a-z, A-Z
- // > convert following to uppercase
- // < convert following to lowercase
- // ! stop case conversion after this point
- // Z end of mask - auto set max chars
- // \ escape (for using: #, 9, A, a, &, ?, <, >)
- //
- // In essence, we will create an Overwrite only mode
- // Characters will not shift when deleting or typing
- // The position of the cursor coming into OnKeyDown is fixed
- // we will move one position to the right (unless we hit literals)
- // if space is entered, we will use the prompt
- // A space in m_literal or m_placeHolder means there is not one at this index
- // m_upperLower contains 'u', 'l' or ' ' at each index
- //
- // -------------------------------------------------------------------------
- class AFX_EXT_CLASS CTckEdit : public CEdit
- {
- protected:
- BYTE m_nType; // Type of CTckEdit
- UINT m_nFlags; // Flags for Boolean Values
- // BOOL m_bLocked; // Similar to ReadOnly
-
- // ----- Color Info -----
- COLORREF m_clrText; // Text Color
- COLORREF m_clrBack; // Background Color
- CBrush *m_pBrBack; // Background Color Brush
-
- // ----- Numeric Info -----
- short m_nDigits; // Max number of digits
- short m_nDecimals; // Number of decimals
- // BOOL m_bDollarSign; // Display Dollor Sign
- // BOOL m_bAddCommas; // Add Comma Seperators
- // BOOL m_bAllowNegative; // Allow negative values
-
- // ----- Mask Info -----
- CString m_mask; // Mask
- LPTSTR m_literal; // Literal array
- LPTSTR m_placeHolder; // Place Holder array
- LPTSTR m_upperLower; // Indicates upper/lower
- // BOOL m_bSaveMaskChars; // Save mask characters?
- _TCHAR m_cPrompt; // Prompt Character
- short m_nMaskEnd; // End of mask
- short m_nMaxChars; // Max Chars
-
- // Construction
- public:
- CTckEdit();
-
- // Attributes
- public:
-
- // ------ Color Functions -----
- int GetTextColor() { return m_clrText; }
- int GetBackColor() { return m_clrBack; }
- void SetTextColor(COLORREF clr, BOOL bRedraw = TRUE);
- void SetBackColor(COLORREF clr, BOOL bRedraw = TRUE);
- void Redraw(); // Redraws the Control
-
- virtual BOOL OnChildNotify (UINT msg, WPARAM wParam,
- LPARAM lParam, LRESULT *pLResult);
-
- // ------ General Functions -----
- void Type(int nType) { m_nType = nType; }
- int Type() { return m_nType; }
- BOOL Locked() { return (m_nFlags & TCKEDITF_LOCKED); }
- void Locked(BOOL bFlag) { SetBitFlag(m_nFlags, TCKEDITF_LOCKED, bFlag); }
- void SetText(LPCTSTR szText);
- void GetText(CString&);
- void ApplyFormat(CString&, LPCTSTR szOrig);
-
- // ------ Numeric Functions -----
- int Digits() { return m_nDigits; }
- void Digits(int nDigits) { m_nDigits = nDigits; }
- int Decimals() { return m_nDecimals; }
- void Decimals(int nDecimals) { m_nDecimals = nDecimals; }
- // BOOL DollarSign() { return m_bDollarSign; }
- // void DollarSign(BOOL bFlag) { m_bDollarSign = bFlag; }
- BOOL DollarSign() { return (m_nFlags & TCKEDITF_DOLLARSIGN); }
- void DollarSign(BOOL bFlag) { SetBitFlag(m_nFlags, TCKEDITF_DOLLARSIGN, bFlag); }
- BOOL AddCommas() { return (m_nFlags & TCKEDITF_ADDCOMMAS); }
- void AddCommas(BOOL bFlag) { SetBitFlag(m_nFlags, TCKEDITF_ADDCOMMAS, bFlag); }
- BOOL AllowNegative() { return (m_nFlags & TCKEDITF_ALLOWNEGATIVE); }
- void AllowNegative(BOOL bFlag) { SetBitFlag(m_nFlags, TCKEDITF_ALLOWNEGATIVE, bFlag); }
-
- int IntegerVal();
- void IntegerVal(int nValue);
- double DoubleVal();
- void DoubleVal(double nValue);
-
- // ------ Mask Attributes -----
- LPCTSTR Mask() { return m_mask; }
- void Mask(LPCTSTR szMask);
- int MaxChars() { return m_nMaxChars; }
- void MaxChars(int nMaxChars) { m_nMaxChars = nMaxChars; }
- BOOL SaveMaskChars() { return (m_nFlags & TCKEDITF_SAVEMASKCHARS); }
- void SaveMaskChars(BOOL bFlag) { SetBitFlag(m_nFlags, TCKEDITF_SAVEMASKCHARS, bFlag); }
- _TCHAR PromptChar() { return m_cPrompt; }
- void PromptChar(_TCHAR promptChar) { m_cPrompt = promptChar; }
- void GetStrippedText(CString& );
- BOOL IsOptionalMask(int idx);
-
- // ------ Date Attributes -----
- // Date Format mm/dd/yy, mm/dd/yyyy
-
- // Operations
- public:
- // ------ Numeric Functions -----
- void GetDigitsCount(LPCTSTR szText, int &nDigitCnt,
- int &nDecimalCnt, int &nDecIdx, int &nEndIdx);
- int FormatNumeric(LPCTSTR szOrig, LPTSTR szNew);
- void StripToNumeric(LPCTSTR szOrig, LPTSTR szNew);
- void StripChar(LPCTSTR szOrig, LPTSTR szNew, _TCHAR c);
-
- void OnCharNumeric(UINT nChar, UINT nRepCnt, UINT nFlags);
- void OnKeyDownNumeric(UINT nChar, UINT nRepCnt, UINT nFlags);
- // void OnContextMenuNumeric( CWnd* pWnd, CPoint pos );
-
- // ------ Mask Functions -----
- BOOL ApplyCharCheckMask(_TCHAR &c, int idx);
- void ApplyMaskToText(LPCTSTR szText, LPTSTR szResult);
- void ParseMask(LPCTSTR szMask); // fill in literals, place holders,
- // and upperLower arrays
- void StripMask(LPCTSTR szOrig, LPTSTR szNew);
-
- void OnCharMask(UINT nChar, UINT nRepCnt, UINT nFlags);
- void OnKeyDownMask(UINT nChar, UINT nRepCnt, UINT nFlags);
- void OnContextMenuMask( CWnd* pWnd, CPoint pos );
-
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CTckEdit)
- //}}AFX_VIRTUAL
-
- // Implementation
- public:
- virtual ~CTckEdit();
-
- // Generated message map functions
- protected:
- //{{AFX_MSG(CTckEdit)
- afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnContextMenu( CWnd* pWnd, CPoint pos );
- //}}AFX_MSG
-
- DECLARE_MESSAGE_MAP()
- };
-
-
- #endif