/** * @file XTPGridInplaceControls.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(__XTPGRIDINPLACECONTROLS_H__) # define __XTPGRIDINPLACECONTROLS_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPGridRecord; class CXTPGridControl; class CXTPGridRecordItem; class CXTPGridRecordItemConstraints; class CXTPGridRecordItemConstraint; /** * @brief * CXTPGridInplaceControl is the base class for all in-place controls of * the Grid control item. * @details * There are three built-in, in-place controls for the Grid control item: * CXTPGridInplaceEdit: Represents the edit control to allow users * to change a cell of the Grid control. * CXTPGridInplaceButton: Represents a single button of the item. * CXTPGridInplaceList: Represents the list box to allow users * to select the constraints of the grid item. * @see * CXTPGridInplaceEdit, CXTPGridInplaceButton, CXTPGridInplaceList */ class _XTP_EXT_CLASS CXTPGridInplaceControl : public XTP_GRIDRECORDITEM_ARGS { public: /** * @brief * Constructs a CXTPGridInplaceControl object. */ CXTPGridInplaceControl(); /** * @brief * Destroys a CXTPGridInplaceControl object, handles cleanup * and deallocation. */ virtual ~CXTPGridInplaceControl(); protected: /** * @brief * This method is called internally to fill the item arguments * of an in-place control. * @param pItemArgs Pointer to an XTP_GRIDRECORDITEM_ARGS * structure containing item arguments. */ virtual void SetItemArgs(XTP_GRIDRECORDITEM_ARGS* pItemArgs); }; /** * @brief * CXTPGridInplaceEdit is a CXTPGridInplaceControl derived class that * represents an edit control to allow users to change a cell of a Grid control. */ class _XTP_EXT_CLASS CXTPGridInplaceEdit : public CXTPMaskEditT , public CXTPGridInplaceControl { /** @cond */ DECLARE_DYNAMIC(CXTPGridInplaceEdit) /** @endcond */ public: /** * @brief * Constructs a CXTPGridInplaceEdit object. */ CXTPGridInplaceEdit(); /** * @brief * Destroys a CXTPGridInplaceEdit object, handles cleanup * and deallocation. */ virtual ~CXTPGridInplaceEdit(); public: /** * @brief * Hides the in-place edit control. */ void HideWindow(); /** * @brief * Gets a child Grid control item. * @return * A pointer to a CXTPGridRecordItem object. */ CXTPGridRecordItem* GetItem() const; /** * @brief * Creates an in-place edit control. * @param pItemArgs Pointer to an XTP_GRIDRECORDITEM_ARGS * structure containing item cell parameters. */ void Create(XTP_GRIDRECORDITEM_ARGS* pItemArgs); /** * @brief * Sets edit text. * @param lpszString Edit text to be set. */ void SetWindowText(LPCTSTR lpszString); protected: /** * @brief * Sets the font of the in-place edit control. * @param pFont New font to be set. */ void SetFont(CFont* pFont); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPGridInplaceControl) virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPGridInplaceControl) afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); afx_msg void OnEnKillfocus(); afx_msg void OnSetFocus(CWnd* pWnd); afx_msg void OnEnChange(); afx_msg UINT OnGetDlgCode(); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg HBRUSH CtlColor(CDC* pDC, UINT /*nCtlColor*/); //}}AFX_MSG /** @endcond */ private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); protected: CString m_strValue; /**< The value of item before user change it. */ CString m_strText_prev; /**< The text value from previous change. */ CXTPFont m_xtpFontEdit; /**< Font of in-place edit. */ XTP_SUBSTITUTE_GDI_MEMBER_WITH_CACHED(CFont, m_fntEdit, m_xtpFontEdit, GetEditFontHandle); CXTPGridRecordItemConstraint* m_pSelectedConstraint; /**< Selected constraint. */ COLORREF m_clrText; /**< Text color of in-place edit. */ COLORREF m_clrBack; /**< Background color of in-place edit. */ CXTPBrush m_xtpBrushBack; /**< Background brush of in-place edit. */ XTP_SUBSTITUTE_GDI_MEMBER_WITH_CACHED(CBrush, m_brBack, m_xtpBrushBack, GetBackBrushHandle); BOOL m_bSetWindowText; /**< Indicates that text is being set with the SetWindowText function. */ // private: friend class CXTPGridRecordItem; }; AFX_INLINE CXTPGridRecordItem* CXTPGridInplaceEdit::GetItem() const { return pItem; } AFX_INLINE BOOL CXTPGridInplaceEdit::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } AFX_INLINE BOOL CXTPGridInplaceEdit::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) { return CEdit::Create(dwStyle, rect, pParentWnd, nID); } const UINT XTP_ID_GRID_EXPANDBUTTON = 100; /**< @see CXTPGridInplaceButton::CXTPGridInplaceButton */ const UINT XTP_ID_GRID_COMBOBUTTON = 101; /**< @see CXTPGridInplaceButton::CXTPGridInplaceButton */ const UINT XTP_ID_GRID_SPINBUTTON = 102; /**< @see CXTPGridInplaceButton::CXTPGridInplaceButton */ /** * @brief * CXTPGridInplaceButton is a CXTPGridInplaceControl derived class * that represents a combo button and expand button of a grid cell. */ class _XTP_EXT_CLASS CXTPGridInplaceButton : public CStatic , public CXTPGridInplaceControl { public: /** * @brief * Constructs a CXTPGridInplaceButton object. * @param nID Identifier of the in-place button. Can be any of the * values listed in the Remarks section. * @details * Default identifiers are: * XTP_ID_GRID_EXPANDBUTTON: Indicates that the button * acts like an expand button. * XTP_ID_GRID_COMBOBUTTON: Indicates that the button * acts like a combo button. * XTP_ID_GRID_SPINBUTTON: Indicates that the button * acts like a spin button. */ CXTPGridInplaceButton(UINT nID); /** * @brief * Creates an in-place button control. * @param pItemArgs Pointer to an XTP_GRIDRECORDITEM_ARGS * structure containing item cell parameters. * @param rcButtons Reference to the bounding rectangle of the button. */ void Create(XTP_GRIDRECORDITEM_ARGS* pItemArgs, CRect& rcButtons); /** * @brief * Gets the identifier of the button. * @return * The identifier of the button. */ int GetID() const; /** * @brief * Determines if the user pressed the button. * @return * TRUE if the user pressed the button. */ BOOL IsPressed() const; /** * @brief * Gets the state of the button. * @return * The state of the button. */ int GetState() const; /** * @brief * Gets a child Grid control item. * @return * A pointer to a CXTPGridRecordItem object. */ CXTPGridRecordItem* GetItem() const; /** * @brief * Gets the width of the button. * @return * The width of the button. */ int GetWidth() const; /** * @brief * Determines if the button is placed inside or * outside (near the right cell side) the cell rect. * @return * TRUE if the button is placed inside the cell rect, otherwise FALSE. */ BOOL IsInsideCellButton() const; /** * @brief * Specifies if the button should be placed inside or * outside (near the right cell side) the cell rect. * @param bInsideCell TRUE to place the button inside the cell rect, * FALSE to place the button outside the cell rect. */ void SetInsideCellButton(BOOL bInsideCell); /** * @brief * Sets the icon index for the button. * @param nIconIndex Icon index to be set. * @see * GetIconIndex */ void SetIconIndex(int nIconIndex); /** * @brief * Gets the icon index of the button. * @return * The icon index of the button. * @see * SetIconIndex */ int GetIconIndex() const; /** * @brief * Gets spin button properties. * @return * The requested spin button property value. * @see * SetSpinButtonMin, SetSpinButtonMax, SetSpinButtonStep */ int GetSpinButtonMin() const; /** * @brief * Gets spin button properties. * @return * The requested spin button property value. * @see * SetSpinButtonMin, SetSpinButtonMax, SetSpinButtonStep */ int GetSpinButtonMax() const; /** * @brief * Gets spin button properties. * @return * The requested spin button property value. * @see * SetSpinButtonMin, SetSpinButtonMax, SetSpinButtonStep */ int GetSpinButtonStep() const; /** * @brief * Sets spin button properties. * @param nValue Spin button property value to be set. * @see * GetSpinButtonMin, GetSpinButtonMax, GetSpinButtonStep */ void SetSpinButtonMin(int nValue); /** * @brief * Sets spin button properties. * @param nValue Spin button property value to be set. * @see * GetSpinButtonMin, GetSpinButtonMax, GetSpinButtonStep */ void SetSpinButtonMax(int nValue); /** * @brief * Sets spin button properties. * @param nValue Spin button property value to be set. * @see * GetSpinButtonMin, GetSpinButtonMax, GetSpinButtonStep */ void SetSpinButtonStep(int nValue); /** * @brief * Call this function to activate the button. */ void Activate(); /** * @brief * Gets the number of items to show in the dropdown list. * @return * A number of items to show. */ int GetDropListItemNumber() const; /** * @brief * Sets the number of items to show in the dropdown list. * @param nNumber A number of items to show. */ void SetDropListItemNumber(int nNumber); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPGridInplaceButton) virtual void OnFinalRelease(); //{{AFX_VIRTUAL //{{AFX_MSG(CXTPGridInplaceButton) afx_msg void OnPaint(); afx_msg void OnLButtonDown(UINT, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk(UINT, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnCaptureChanged(CWnd* pWnd); afx_msg void OnTimer(UINT_PTR nIDEvent); //}}AFX_MSG /** @endcond */ # ifdef _XTP_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() XTP_DECLARE_CMDTARGETPROVIDER_INTERFACE() DECLARE_OLETYPELIB_EX(CXTPGridInplaceButton); LPDISPATCH OleGetRow(); LPDISPATCH OleGetColumn(); LPDISPATCH OleGetItem(); void OleGetRect(long* pnLeft, long* pnTop, long* pnRight, long* pnBottom); /** @endcond */ # endif private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); BOOL Create(LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff); protected: int m_nID; /**< Identifier of the button. */ int m_nWidth; /**< Width of the button. */ int m_nFixedHeight; /**< Height of the button. */ BOOL m_bInsideCell; /**< Store button place: inside the cell rect, or outside. */ int m_nIconIndex; /**< Icon index. */ BOOL m_bPressed; /**< TRUE if the button is pressed. */ BOOL m_bOver; /**< TRUE if the mouse cursor is over the button. */ int m_nState; /**< Button state. */ int m_nSpinMin; /**< Spin button only: minimum value. */ int m_nSpinMax; /**< Spin button only: maximum value. */ int m_nSpinStep; /**< Spin button only: step value. */ UINT_PTR m_unSpinTimerCnt; /**< Spin button only: timer counter. */ UINT_PTR m_unSpinTimerId; /**< Spin button only: timer identifier. */ int m_nSpinIncrement; /**< Spin button only: increment value. */ private: int m_Items2Show; /**< Picklist desired item's number to show. Use GetDropListItemNumber/SetDropListItemNumber in order to access its value. */ friend class CXTPGridRecordItem; }; AFX_INLINE int CXTPGridInplaceButton::GetDropListItemNumber() const { return m_Items2Show; } AFX_INLINE void CXTPGridInplaceButton::SetDropListItemNumber(int nNumber) { _ASSERTE(0 <= nNumber); m_Items2Show = nNumber; } AFX_INLINE int CXTPGridInplaceButton::GetID() const { return m_nID; } AFX_INLINE BOOL CXTPGridInplaceButton::IsPressed() const { return m_bPressed && m_bOver; } AFX_INLINE int CXTPGridInplaceButton::GetState() const { return m_bOver ? m_nState : 0; } AFX_INLINE BOOL CXTPGridInplaceButton::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } AFX_INLINE BOOL CXTPGridInplaceButton::Create(LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) { return CStatic::Create(lpszText, dwStyle, rect, pParentWnd, nID); } AFX_INLINE CXTPGridRecordItem* CXTPGridInplaceButton::GetItem() const { return pItem; } AFX_INLINE void CXTPGridInplaceButton::SetIconIndex(int nIconIndex) { m_nIconIndex = nIconIndex; } AFX_INLINE int CXTPGridInplaceButton::GetIconIndex() const { return m_nIconIndex; } /** * @brief * CXTPGridInplaceList is a CXTPGridInplaceControl derived class * that represents a list box with item constraints. * @see * CXTPGridRecordItemConstraints */ class _XTP_EXT_CLASS CXTPGridInplaceList : public CListBox , public CXTPGridInplaceControl { public: /** * @brief * Constructs a CXTPGridInplaceList object. */ CXTPGridInplaceList(); public: /** * @brief * Creates an in-place list control. * @param pItemArgs Pointer to an XTP_GRIDRECORDITEM_ARGS * structure containing item cell parameters. * @param pConstraints Pointer to a CXTPGridRecordItemConstraints * object containing item constraints. */ void Create(XTP_GRIDRECORDITEM_ARGS* pItemArgs, CXTPGridRecordItemConstraints* pConstraints); /** * @brief * Cancels the user selection. */ void Cancel(); /** * @brief * Saves the selected value of the list box. */ void Apply(); /** * @brief * Gets the number of items to show in the dropdown list. * @return * A number of items to show. */ int GetDropListItemNumber() const; /** * @brief * Sets the number of items to show in the dropdown list. * @param nNumber A number of items to show. */ void SetDropListItemNumber(int nNumber); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPGridInplaceList) virtual BOOL PreTranslateMessage(MSG* pMsg); void PostNcDestroy(); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPGridInplaceList) afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); afx_msg UINT OnGetDlgCode(); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnLButtonUp(UINT, CPoint point); afx_msg void OnNcPaint(); //}}AFX_MSG /** @endcond */ /** * @brief * This method is called internally to fill the item arguments * of an in-place control. * @param pItemArgs Pointer to an XTP_GRIDRECORDITEM_ARGS * structure containing item arguments. */ virtual void SetItemArgs(XTP_GRIDRECORDITEM_ARGS* pItemArgs); /** * @brief * This method is called internally when the selection is changed. * @param nLBIndex Index of the selected item in the list. */ virtual void OnSelectionChanged(int nLBIndex); private: CString m_strHotSearchContext; DWORD m_dwLastKeyDownTime; BOOL m_bApply; int m_Items2Show; /**< Use GetDropListItemNumber/SetDropListItemNumber method to access it. */ BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); }; AFX_INLINE int CXTPGridInplaceList::GetDropListItemNumber() const { return m_Items2Show; } AFX_INLINE void CXTPGridInplaceList::SetDropListItemNumber(int nNumber) { _ASSERTE(0 <= nNumber); m_Items2Show = nNumber; } ////////////////////////////////////////////////////////////////////////// AFX_INLINE BOOL CXTPGridInplaceList::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } AFX_INLINE BOOL CXTPGridInplaceList::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) { return CListBox::Create(dwStyle, rect, pParentWnd, nID); } AFX_INLINE int CXTPGridInplaceButton::GetWidth() const { return m_nWidth; } AFX_INLINE BOOL CXTPGridInplaceButton::IsInsideCellButton() const { return m_bInsideCell; } AFX_INLINE void CXTPGridInplaceButton::SetInsideCellButton(BOOL bInsideCell) { m_bInsideCell = bInsideCell; } AFX_INLINE int CXTPGridInplaceButton::GetSpinButtonMin() const { return m_nSpinMin; } AFX_INLINE int CXTPGridInplaceButton::GetSpinButtonMax() const { return m_nSpinMax; } AFX_INLINE int CXTPGridInplaceButton::GetSpinButtonStep() const { return m_nSpinStep; } AFX_INLINE void CXTPGridInplaceButton::SetSpinButtonMin(int nValue) { m_nSpinMin = nValue; } AFX_INLINE void CXTPGridInplaceButton::SetSpinButtonMax(int nValue) { m_nSpinMax = nValue; } AFX_INLINE void CXTPGridInplaceButton::SetSpinButtonStep(int nValue) { m_nSpinStep = nValue; } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // #if !defined(__XTPGRIDINPLACECONTROLS_H__) /** @endcond */