/** * @file XTPEdit.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPEDIT_H__) # define __XTPEDIT_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPRegExp; class CXTPWinThemeWrapper; class CXTPEditTheme; // afx_msg void memberFxn(); /** * @brief * CXTPEdit is a CEdit derived class. The CXTPEdit class provides the functionality * of a Windows edit control. An edit control is a rectangular child window * in which the user can enter text. * @details * You can create an edit control either from a dialog template or directly * in your code. In both cases, first call the constructor CXTPEdit to construct * the CXTPEdit object, then call the Create member function to create the * Windows edit control and attach it to the CXTPEdit object. * * Construction can be a one-step process in a class derived from CXTPEdit. * Write a constructor for the derived class and call Create from within * the constructor. * * CXTPEdit inherits significant functionality from CWnd. To set and retrieve * text from a CXTPEdit object, use the CWnd member functions SetWindowText * and GetWindowText, which either set or get the entire contents of an edit control * even if it is a multi-line control. Also, if an edit control is multi-line, * get and set part of the control's text by calling the CXTPEdit member * functions GetLine, SetSel, GetSel, and ReplaceSel. * * If you want to handle Windows notification messages sent by an edit * control to its parent (usually a class derived from CDialog), add a * message-map entry and message-handler member function to the parent * class for each message. * * Each message-map entry takes the following form: * *
 * ON_Notification(id, memberFxn)
 * 
* * Where 'id' specifies the child window ID of the edit control sending the * notification, and 'memberFxn' is the name of the parent member function * you have written to handle the notification. * * The parent's function prototype is as follows: * *
 * afx_msg void memberFxn();
 * 
* * Following is a list of potential message-map entries and a description * of the cases in which they would be sent to the parent: * * ON_EN_CHANGE: The user has taken an action that may have altered * text in an edit control. Unlike the EN_UPDATE * notification message, this notification message is * sent after Windows updates the display. * ON_EN_ERRSPACE: The edit control cannot allocate enough memory * to meet a specific request. * ON_EN_HSCROLL: The user clicks an edit control's horizontal * scrollbar. The parent window is notified before * the screen is updated. * ON_EN_KILLFOCUS: The edit control loses the input focus. * ON_EN_MAXTEXT: The current insertion has exceeded the specified * number of characters for the edit control and has * been truncated. Also sent when an edit control * does not have the ES_AUTOHSCROLL style and the * number of characters to be inserted would exceed * the width of the edit control. Also sent when an * edit control does not have the ES_AUTOVSCROLL * style and the total number of lines resulting * from a text insertion would exceed the height of * the edit control. * ON_EN_SETFOCUS: Sent when an edit control receives the input focus. * ON_EN_UPDATE: The edit control is about to display altered text. * Sent after the control has formatted the text but * before it screens the text so that the window size * can be altered, if necessary. * ON_EN_VSCROLL: The user clicks an edit control's vertical * scrollbar. The parent window is notified before * the screen is updated. * * If you create a CXTPEdit object within a dialog box, then the CXTPEdit object * is automatically destroyed when the user closes the dialog box. * * If you create a CXTPEdit object from a dialog resource using the dialog * editor, then the CXTPEdit object is automatically destroyed when the user * closes the dialog box. * * If you create a CXTPEdit object within a window, you may also need to * destroy it. If you create the CXTPEdit object on the stack, it is destroyed * automatically. If you create the CXTPEdit object on the heap by using * the new function, you must call delete on the object to destroy it when * the user terminates the Windows edit control. If you allocate any memory * in the CXTPEdit object, override the CXTPEdit destructor to dispose of * the allocations. */ class _XTP_EXT_CLASS CXTPEdit : public CXTPMaskEditT { DECLARE_DYNAMIC(CXTPEdit) typedef CXTPMaskEditT TBase; public: /** * @brief * Constructs a CXTPEdit object. */ CXTPEdit(); /** * @brief * Destroys a CXTPEdit object, handles cleanup and deallocation. */ virtual ~CXTPEdit(); /** * @brief * This member function will set the mask for the edit control. * @param lpszMask The format for the mask field. For example, if * you wanted to set the mask for a phone number, * and you only wanted digits to be entered, your * mask might look like this; _T("(000) 000-0000"). * @param lpszLiteral The literal format is entered here. Wherever you * place an underscore ('_') is where the user will * be allowed to enter data only. Using the phone * number example; _T("(___) ___-____"). * @param lpszDefault Text that is to be displayed when the control * is initialized. For example; _T("(800) 555-1212"). * If NULL, then 'lpszLiteral' is used to initialize * the edit text. * @details * The values that can be set are: *
	 * Mask Character  Description
	 * ---------------------  ------------------------
	 * 0                      Numeric (0-9)
	 * 9                      Numeric (0-9) or space (' ')
	 * #                      Numeric (0-9) or space (' ') or ('+') or ('-')
	 * L                      Alpha (a-Z)
	 * ?                      Alpha (a-Z) or space (' ')
	 * A                      Alpha numeric (0-9 and a-Z)
	 * a                      Alpha numeric (0-9 and a-Z) or space (' ')
	 * &                      All print character only
	 * H                      Uppercase hex digit (0-9 and A-F)
	 * h                      Lowercase hex digit (0-9 and a-f)
	 * X                      Uppercase hex digit (0-9 and A-F) and space (' ')
	 * x                      Lowercase hex digit (0-9 and a-f) and space (' ')
	 * >                      Forces characters to upper case (A-Z) or any Unicode character
	 * <                      Forces characters to lower case (a-z) or any Unicode character
	 * C                      Uppercase ASCII character
	 * c                      Lowercase ASCII character
	 * 
* @return TRUE if successful; otherwise FALSE. */ BOOL SetEditMask(LPCTSTR lpszMask, LPCTSTR lpszLiteral, LPCTSTR lpszDefault = NULL); /** * @brief * Call this member function to set the pattern for the edit mask. * @param lpszPattern Text pattern to set. */ void SetPattern(LPCTSTR lpszPattern); /** * @brief * Call this member function to determine if the Clipboard contains * information that can be pasted into this edit view. * @return * TRUE if the Clipboard contains data in a format which this edit view * can accept, otherwise FALSE. */ virtual BOOL CanPaste(); /** * @brief * Call this member function to determine if a selection has been made. * @return * TRUE if a selection has been made, otherwise FALSE. */ BOOL HasSelection() const; /** * @brief * Called by the framework to adjust the size of the area to draw * the buddy control borders on. * @param pBuddy Pointer to the buddy control associated with the edit. * @param rcUpDown Size of the buddy border area to be drawn. * @param nAlignment Side of the edit box that the buddy is attached to * (either UDS_ALIGNRIGHT or UDS_ALIGNLEFT). */ void AdjustBuddyRect(CWnd* pBuddy, CRect& rcUpDown, int nAlignment); /** * @brief * Called by the framework to draw the borders for the associated * buddy window. * @param pBuddy Pointer to the buddy control associated with the edit. * @param pDC Pointer to a valid device context. * @param rc Size of the buddy border area to be drawn. * @param nAlignment Side of the edit box that thee buddy is attached to * (either UDS_ALIGNRIGHT or UDS_ALIGNLEFT). */ void DrawBuddyBorders(CWnd* pBuddy, CDC* pDC, CRect rc, int nAlignment); /** * @brief * This member is called to update the color, text and other * visual elements of the control. */ virtual void RefreshMetrics(); /** * @brief * Call this member to switch the visual theme of the control. * @param nTheme New visual theme. Can be any of the values listed in the Remarks section. * @details * nTheme can be one of the following: * xtpControlThemeDefault: Standard appearance style. * xtpControlThemeFlat: Flat appearance style. * xtpControlThemeUltraFlat: Ultra flat appearance style. * xtpControlThemeOffice2000: Office 2000 appearance style. * xtpControlThemeOfficeXP: Office XP appearance style. * xtpControlThemeOffice2003: Office 2003 appearance style. * xtpControlThemeResource: Office 2007 appearance style. * xtpControlThemeVisualStudio2012Light: VS 2012 Light style theme. * xtpControlThemeVisualStudio2012Dark: VS 2012 Dark style theme. */ virtual void SetTheme(XTPControlTheme nTheme); /** * @brief * Call this member function to get the style for the theme. * @return * An XTPControlTheme enumerator index value representing the theme style. */ XTPControlTheme GetThemeID(); /** * @brief * Call this member to retrieve a pointer to the current theme. * @return * A CXTPEditTheme object that represents the current theme. */ CXTPEditTheme* GetTheme(); /** * @brief * Gets the flat style appearance of the button control. * @details * The control will appear flat until the mouse pointer moves over it, * at which point it appears three-dimensional. * @return * TRUE if the flat style is used, otherwise FALSE. */ BOOL GetFlatStyle() const; /** * @brief * Sets the flat style appearance of the button control. * @param bFlatStyle TRUE to use the flat style, FALSE otherwise. * @details * The control will appear flat until the mouse pointer moves over it, * at which point it appears three-dimensional. */ void SetFlatStyle(BOOL bFlatStyle = TRUE); /** * @brief * Determines if the control is drawn using visual styles/SkinFramework, * if supported. * @details * This method enables Windows XP visual styles for the control. * This Control will draw using visual styles if both the control * and the operating system support it. * Visual styles and SkinFramework skins are specifications for * the appearance of controls. GetUseVisualStyle determines whether * to use the currently set Windows XP visual style. If using * SkinFramework, then it determines whether to use the currently set * style of the SkinFramework. * @return * TRUE if the currently set Windows XP visual style will be used to * theme the control. If using SkinFramework, then the currently set * style of the SkinFramework will be used to skin the control. * FALSE if the currently set appearance/style in the OS will be used. */ BOOL GetUseVisualStyle() const; /** * @brief * Enables Windows XP visual styles for the control. * @details * This method enables Windows XP visual styles for the control. * This Control will draw using visual styles if both the control * and the operating system support it. * Visual styles and SkinFramework skins are specifications for * the appearance of controls. GetUseVisualStyle determines whether * to use the currently set Windows XP visual style. If using * SkinFramework, then it determines whether to use the currently set * style of the SkinFramework. * @param bUseVisualStyle TRUE if the currently set Windows XP visual style * will be used to theme the control. If using * SkinFramework, then the currently set style of the * SkinFramework will be used to skin the control. * FALSE if the currently set appearance/style in the * OS will be used. */ void SetUseVisualStyle(BOOL bUseVisualStyle = TRUE); /** * @brief * Called by the framework to determine if the pattern set using * SetPattern() is valid. * @return * TRUE if the previously set pattern is valid. */ BOOL IsPatternValid(); /** * @brief * Call this member function to enable/disable theme border display. * @param bShowThemedBorder TRUE to enable themed borders, * FALSE to disable themed borders. */ void ShowThemedBorder(BOOL bShowThemedBorder); /** * @brief * Call this member function to determine if the edit state is highlighted, * meaning that the mouse cursor is currently hovering over the control. * @return * TRUE if the edit state is highlighted, otherwise FALSE. */ BOOL IsHighlighted() const; /** * @brief * Call this member function to determine if the edit-box has input focus. * @return * TRUE if the edit-box has input focus, otherwise FALSE. */ BOOL IsFocused() const; /** * @brief * Gets the flat style appearance of the edit control. * @details * The control will appear flat until the mouse pointer moves * over it, at which point it appears three-dimensional. * @return * TRUE if the flat style is used, otherwise FALSE. */ BOOL IsFlatStyle() const; /** * @brief * Call this member to determine if non-client borders are displayed. * @return * TRUE if non-client borders are displayed. */ BOOL ShowBorder() const; /** @cond */ virtual bool Initialize(CWnd* pParentWnd); /**< Obsolete */ /** @endcond */ protected: /** * @brief * Retrieves a handle to the client background brush. * @param pDC Pointer to a valid device context. * @return * A HBRUSH handle representing the client background brush. */ HBRUSH GetClientBrush(CDC* pDC); /** * @brief * Called by the framework to redraw the edit control. */ void RedrawEdit(); /** * @brief * Called by the framework to redraw the focus rectangle for the edit control. */ void RedrawFocusedFrame(); CXTPEditTheme* m_pTheme; /**< Pointer to the current edit theme. */ /** @cond */ BOOL PreCreateWindow(CREATESTRUCT& cs); void PreSubclassWindow(); void Init(); //{{AFX_MSG(CXTPEdit) afx_msg void OnContextMenu(CWnd*, CPoint point); afx_msg void OnEditUndo(); afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI); afx_msg void OnEditCut(); afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI); afx_msg void OnEditCopy(); afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI); afx_msg void OnEditPaste(); afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI); afx_msg void OnEditClear(); afx_msg void OnUpdateEditClear(CCmdUI* pCmdUI); afx_msg void OnEditSelectAll(); afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnNcPaint(); afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp); afx_msg void OnMouseLeave(); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg BOOL OnChange(); afx_msg void OnSysColorChange(); afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); afx_msg LRESULT OnSetTheme(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() //}}AFX_MSG /** @endcond */ BOOL m_bPreSubclassInit; /**< TRUE if the control has been subclassed. */ BOOL m_bShowBorder; /**< TRUE if non-client borders are displayed. */ BOOL m_bHighlighted; /**< TRUE when the mouse is hovering over the control. */ BOOL m_bFocused; /**< TRUE when the control has input focus. */ CXTPRegExp* m_pRegExp; /**< Pointer to the CXTPRegExp object for this control. */ }; /** @cond */ AFX_INLINE BOOL CXTPEdit::IsHighlighted() const { return m_bHighlighted; } AFX_INLINE BOOL CXTPEdit::IsFocused() const { return m_bFocused; } AFX_INLINE BOOL CXTPEdit::GetFlatStyle() const { return IsFlatStyle(); } AFX_INLINE BOOL CXTPEdit::ShowBorder() const { return m_bShowBorder; } AFX_INLINE void CXTPEdit::ShowThemedBorder(BOOL bShowThemedBorder) { m_bShowBorder = bShowThemedBorder; } /** @endcond */ ///////////////////////////////////////////////////////////////////////////// // CXTPScrollableEditT /** * @brief * An adaptor for any CEdit derived control that overrides standard scrollbars * with custom scrollbars. * @param EditBase Base CEdit derived class name. * @see * CXTPScrollable */ template class CXTPScrollableEditT : public CXTPScrollable { public: /** * @brief * Initializes scrollable control instance. */ CXTPScrollableEditT(); using CXTPScrollable::ModifyStyle; using CXTPScrollable::ModifyStyleEx; using CXTPScrollable::GetRuntimeClass; protected: /** @cond */ virtual void DisableScrollbars(); virtual void DisableScrollbars(CWnd& wnd); /** @endcond */ }; /** * @brief * Type alias for a CXTPEdit derived scrollable control. */ typedef CXTPScrollableEditT CXTPScrollableEdit; /** @cond */ template AFX_INLINE CXTPScrollableEditT::CXTPScrollableEditT() { _ASSERTE(GetRuntimeClass()->IsDerivedFrom(RUNTIME_CLASS(CEdit))); } template AFX_INLINE void CXTPScrollableEditT::DisableScrollbars() { ModifyStyle(WS_VSCROLL | WS_HSCROLL, 0); ModifyStyleEx(WS_EX_LEFTSCROLLBAR, 0); } template AFX_INLINE void CXTPScrollableEditT::DisableScrollbars(CWnd& wnd) { UNREFERENCED_PARAMETER(wnd); // Do nothing as EDIT behaves improperly if scrollbars gets disabled repeatedly. } /** @endcond */ /** @cond */ class _XTP_EXT_CLASS CXTPEditor_Deprecated : public CXTPEdit { DECLARE_DYNAMIC(CXTPEditor_Deprecated) public: /** * @brief * This member is called to update the color, text, and other visual elements * of the control. */ virtual void RefreshMetrics(); }; _XTP_DEPRECATED_IN_FAVOR(CXTPEdit) typedef CXTPEditor_Deprecated CXTPEditor; /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPEDIT_H__) /** @endcond */