/** * Copyright (C) 2014-2050 SOUIÍÅ¶Ó * All rights reserved. * * @file SDateTimeEdit.h * @brief ͨÓÿؼþ * @version v1.0 * @author soui * @date 2014-06-27 * * Describe ʱ¼ä¿Ø¼þ */ #pragma once #include #include namespace SOUI{ //=========================================================================== // Summary: // SMaskEdit is a CXTPEdit derived class. It allows text masking to be // applied to the control to format it for special editing restrictions. //=========================================================================== /** * @class SMaskEdit * @brief ÒþÂëÊäÈë¿ò * * Describe ÒþÂëÊäÈë¿ò Ö÷ÒªÓÃÓڹ̶¨ÊäÈë¸ñʽ */ class SMaskEdit : public SEdit { SOUI_CLASS_NAME(SMaskEdit, L"maskedit") public: /** * SMaskEdit::SMaskEdit * @brief ¹¹Ô캯Êý * * Describe ¹¹Ô캯Êý */ SMaskEdit(); /** * SMaskEdit::CanUseMask * @brief ÊÇ·ñÆôÓÃmask¹¦ÄÜ * @return ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓÃmask¹¦ÄÜ */ BOOL CanUseMask() const; /** * SMaskEdit::SetUseMask * @brief ÉèÖÃmask¹¦ÄÜ * @param BOOL bUseMask -- TRUE FALSE * * Describe ÉèÖÃmask¹¦ÄÜ */ void SetUseMask(BOOL bUseMask); /** * SMaskEdit::CanOverType * @brief ÊÇ·ñÆôÓøÄд¹¦ÄÜ * @param ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓøÄд¹¦ÄÜ */ BOOL CanOverType() const; /** * SMaskEdit::SetOverType * @brief ÉèÖøÄд¹¦ÄÜ * @param BOOL bOverType -- TRUE FALSE * * Describe ÉèÖøÄд¹¦ÄÜ */ void SetOverType(BOOL bOverType); /** * SMaskEdit::PosInRange * @brief ÊÇ·ñÆôÓÃmask¹¦ÄÜ * @param ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓÃmask¹¦ÄÜ */ BOOL PosInRange(int nPos) const; /** * SMaskEdit::CanUseMask * @brief ÊÇ·ñÆôÓÃmask¹¦ÄÜ * @param ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓÃmask¹¦ÄÜ */ TCHAR GetPromptChar() const; /** * SMaskEdit::CanUseMask * @brief ÊÇ·ñÆôÓÃmask¹¦ÄÜ * @param ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓÃmask¹¦ÄÜ */ SStringT GetPromptString(int nLength) const; /** * SMaskEdit::CanUseMask * @brief ÊÇ·ñÆôÓÃmask¹¦ÄÜ * @param ·µ»ØBOOL * * Describe ÊÇ·ñÆôÓÃmask¹¦ÄÜ */ void SetPromptChar(TCHAR ch, BOOL bAutoReplace = TRUE); BOOL MaskCut(); BOOL MaskCopy(); void MaskReplaceSel(LPCTSTR lpszNewText); BOOL MaskPaste(); void MaskDeleteSel(); BOOL MaskClear(); void MaskSelectAll(); BOOL IsModified() const; void SetMaskedText(LPCTSTR lpszMaskedText, int nPos = 0, BOOL bUpdateWindow = TRUE); virtual BOOL SetEditMask(LPCTSTR lpszMask, LPCTSTR lpszLiteral, LPCTSTR lpszDefault=NULL); TCHAR ConvertUnicodeAlpha(TCHAR nChar, BOOL bUpperCase) const; virtual BOOL CheckChar(TCHAR& nChar, int nPos); virtual BOOL ProcessMask(TCHAR& nChar, int nEndPos); void DeleteCharAt(int nPos); void InsertCharAt(int nPos, TCHAR nChar); SStringT GetMaskedText(int nStartPos = 0, int nEndPos = -1) const; void GetMaskState(BOOL bCorrectSelection = TRUE); void SetMaskState(); void MaskGetSel(); BOOL CopyToClipboard(const SStringT& strText); BOOL IsPromptPos(int nPos) const; BOOL IsPromptPos(const SStringT& strLiteral, int nPos) const; BOOL CorrectPosition(int& nPos, BOOL bForward = TRUE); void CorrectWindowText(); virtual BOOL IsPrintChar(TCHAR nChar); virtual BOOL IsAlphaChar(TCHAR nChar); virtual void NotifyPosNotInRange(); virtual void NotifyInvalidCharacter(TCHAR /*nChar*/, TCHAR /*chMask*/); void ProcessChar(TCHAR nChar); protected: /** * SMaskEdit::OnCreate * @brief ´´½¨ÏûÏ¢ÏìÓ¦º¯Êý * @param LPVOID * @return ·µ»ØÖµint * * Describe ´Ëº¯ÊýÊÇÏûÏ¢ÏìÓ¦º¯Êý */ int OnCreate(LPVOID); /** * SMaskEdit::OnChar * @brief ×Ö·ûÏûÏ¢ * @param UINT nChar -- °´¼ü¶ÔÓ¦µÄÂëÖµ * @param UINT nRepCnt -- ÖØ¸´´ÎÊý * @param UINT nFlags -- ±êÖ¾ * * Describe ´Ëº¯ÊýÊÇÏûÏ¢ÏìÓ¦º¯Êý */ void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); /** * SMaskEdit::OnKeyDown * @brief ¼üÅ̰´ÏÂʼþ * @param UINT nChar -- °´¼ü¶ÔÓ¦µÄÂëÖµ * @param UINT nRepCnt -- ÖØ¸´´ÎÊý * @param UINT nFlags -- ±êÖ¾ * * Describe ´Ëº¯ÊýÊÇÏûÏ¢ÏìÓ¦º¯Êý */ void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); /** * SMaskEdit::OnSetFocus * @brief ÉèÖý¹µã * * Describe ´Ëº¯ÊýÊÇÏûÏ¢ÏìÓ¦º¯Êý */ void OnSetFocus(SWND wndOld); protected: int m_nStartChar; // Current position of the first character in the current selection. int m_nEndChar; // Current position of the first non-selected character past the end of the current selection. BOOL m_bUseMask; // TRUE to use the edit mask. BOOL m_bOverType; // TRUE to over type the text, set with VK_INSERT key press. BOOL m_bModified; // TRUE if mask edit has been modified. TCHAR m_chPrompt; // Prompt character used to identify the text entry. SStringT m_strMask; // Buffer that holds the actual edit mask value. SStringT m_strDefault; // Contains the edit controls default display text. SStringT m_strWindowText; // Buffer that holds the actual edit text. SStringT m_strLiteral; // Literal format that restricts where the user can enter text. protected: SOUI_MSG_MAP_BEGIN() MSG_WM_CREATE(OnCreate) MSG_WM_CHAR(OnChar) MSG_WM_KEYDOWN(OnKeyDown) MSG_WM_SETFOCUS_EX(OnSetFocus) SOUI_MSG_MAP_END() }; /** * @class SDateEdit * @brief ÈÕÆÚ±à¼­¿ò * * Describe ÈÕÆÚ±à¼­¿ò */ class SDateEdit : public SMaskEdit { SOUI_CLASS_NAME(SDateEdit, L"dateedit") public: /** * SDateEdit::SDateEdit * @brief ¹¹Ô캯Êý * * Describe ¹¹Ô캯Êý */ SDateEdit(); /** * SDateEdit::SetDateTime * @brief ÉèÖÃÈÕÆÚ * @param LPCTSTR strDate -- ÈÕÆÚ×Ö·û´® * * Describe ÉèÖÃÈÕÆÚ */ virtual void SetDateTime(LPCTSTR strDate); /** * SDateEdit::SetDateTime * @brief ÉèÖÃÈÕÆÚ * @param CTime tm -- ÈÕÆÚÀà¶ÔÏó * * Describe ÉèÖÃÈÕÆÚ */ virtual void SetDateTime(CTime tm); /** * SDateEdit::GetWindowDateTime * @brief »ñȡϵͳʱ¼ä * @return SStringT ·µ»Ø×Ö·û´® * * Describe »ñȡϵͳʱ¼ä */ virtual SStringT GetWindowDateTime(); virtual BOOL ProcessMask(TCHAR& nChar, int nEndPos); protected: /** * SDateEdit::OnCreate * @brief ÏûÏ¢ÏìÓ¦º¯Êý * @return int * * Describe ÏûÏ¢ÏìÓ¦º¯Êý */ int OnCreate(LPVOID); protected: SOUI_MSG_MAP_BEGIN() MSG_WM_CREATE(OnCreate) SOUI_MSG_MAP_END() }; //=========================================================================== // CDxTimeEdit /** * @class STimeEdit * @brief ʱ¼ä±à¼­¿ò * * Describe ʱ¼ä±à¼­¿ò */ class STimeEdit : public SDateEdit { SOUI_CLASS_NAME(STimeEdit, L"timeedit") public: /** * STimeEdit::STimeEdit * @brief ¹¹Ô캯Êý * * Describe ¹¹Ô캯Êý */ STimeEdit(); public: /** * SDateEdit::SetHours * @brief ÉèÖÃСʱ * * Describe ÉèÖÃСʱ */ virtual void SetHours(int nHours); /** * SDateEdit::SetMins * @brief ÉèÖ÷ÖÖÓ * * Describe ÉèÖ÷ÖÖÓ */ virtual void SetMins(int nMins); /** * SDateEdit::SetTime * @brief ÉèÖÃʱ¼ä * @param int nHours -- Сʱ * @param int nMins -- ·ÖÖÓ * * Describe ÉèÖÃʱ¼ä */ virtual void SetTime(int nHours, int nMins); /** * SDateEdit::GetHours * @brief »ñȡСʱ * @return ·µ»Øint * * Describe »ñȡСʱ */ int GetHours() const; /** * SDateEdit::GetMins * @brief »ñÈ¡·ÖÖÓ * @return ·µ»Øint * * Describe ÉèÖ÷ÖÖÓ */ int GetMins() const; virtual BOOL ProcessMask(TCHAR& nChar, int nEndPos); void SetMilitary(BOOL bMilitary = TRUE); protected: int m_nHours; /**< Сʱ */ int m_nMins; /**< ·ÖÖÓ */ BOOL m_bMilitary; /**< */ protected: /** * STimeEdit::OnCreate * @brief ÏûÏ¢ÏìÓ¦º¯Êý * @return int * * Describe ÏûÏ¢ÏìÓ¦º¯Êý */ int OnCreate(LPVOID); protected: SOUI_MSG_MAP_BEGIN() MSG_WM_CREATE(OnCreate) SOUI_MSG_MAP_END() }; ////////////////////////////////////////////////////////////////////// inline int STimeEdit::GetHours() const { return m_nHours; } inline int STimeEdit::GetMins() const { return m_nMins; } inline void STimeEdit::SetMilitary(BOOL bMilitary) { m_bMilitary = bMilitary; } }//end of namespace