/** * @file XTPEditListBox.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(__XTEDITLISTBOX_H__) # define __XTEDITLISTBOX_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" ////////////////////////////////////////////////////////////////////// /** * @brief * CXTPEditListBoxToolBar is a CStatic derived class. It used by the * CXTPEditListBox class to create a toolbar above the edit list box * to display icons for editing. * @details * CXTPEditListBoxToolBar can be used for other classes by * setting the notify window in Initialize. This window will receive * notification messages whenever the new, delete, up, and down * buttons are pressed. You can handle these messages by adding an * ON_BN_CLICKED handler for each of the buttons XTP_IDC_BTN_NEW, * XTP_IDC_BTN_DELETE, XTP_IDC_BTN_UP and XTP_IDC_BTN_DOWN. */ class _XTP_EXT_CLASS CXTPEditListBoxToolBar : public CStatic { /** @cond */ DECLARE_DYNAMIC(CXTPEditListBoxToolBar) /** @endcond */ public: /** * @brief * Constructs a CXTPEditListBoxToolBar object. */ CXTPEditListBoxToolBar(); /** * @brief * Destroys a CXTPEditListBoxToolBar object, handles cleanup and deallocation. */ virtual ~CXTPEditListBoxToolBar(); public: /** * @brief * Initializes the CXTPEditListBoxToolBar control. * @param bAutoFont true to enable automatic font initialization. * @details * Call this member function to initialize the edit group control. This * method should be called directly after creating or sub-classing the * control. */ virtual void Initialize(bool bAutoFont = true); /** * @brief * This member function returns a reference to the new button of the * edit group. * @return * A reference to a CXTPButton object. */ CXTPButton& GetNewButton(); /** * @brief * This member function returns a reference to the delete button of * the edit group. * @return * A reference to a CXTPButton object. */ CXTPButton& GetDeleteButton(); /** * @brief * This member function returns a reference to the up button of the * edit group. * @return * A reference to a CXTPButton object. */ CXTPButton& GetUpButton(); /** * @brief * This member function returns a reference to the down button of the * edit group. * @return * A reference to a CXTPButton object. */ CXTPButton& GetDownButton(); /** * @brief * This member function will enable/disable editing. * @param bEnable true to enable editing, false to disable editing. */ void EnableEdit(bool bEnable); /** * @brief * Call this member to switch the visual theme of the control. * @param eTheme New visual theme. Can be any of the values listed in the Remarks section. * @details * nStyle can be one of the following: * xtpControlThemeDefault: Use default theme. * 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. */ void SetButtonTheme(XTPControlTheme eTheme); /** @cond */ //{{AFX_VIRTUAL(CXTPEditListBoxToolBar) virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL /** @endcond */ /** * @brief * This member function is called by the CXTPEditListBoxToolBar object to * render a text display for the control. * @param pDC Pointer to a valid device context. * @param rcClient Area to draw text on. */ virtual void DrawText(CDC* pDC, CRect& rcClient); /** * @brief * Recalculates the button layout within the CXTPEditListBoxToolBar window. * @details * This member function is called by the CXTPEditListBoxToolBar object to * position the group bar buttons when the window is sized. */ virtual void MoveButtons(); /** * @brief * Sends a notification to the owner window. * @param nCmdID Command ID to send. * @details * This member function sends the command specified by nCmdID * to the owner of the CXTPEditListBoxToolBar object. The command is * sent whenever a button is pressed on the group bar. */ virtual void SendCommand(UINT nCmdID); /** * @brief * This member function returns a reference to the tooltip control. * @return * A reference to a CToolTipCtrl object. */ CToolTipCtrl& GetTooltipControl(); /** * @brief * This member function sets the drawing theme for the control. * @param nTheme A XTPControlTheme constant used to specify which theme * is to be used for the control. * @see * XTPControlTheme */ void SetTheme(XTPControlTheme nTheme); void RefreshMetrics(); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_MSG(CXTPEditListBoxToolBar) afx_msg void OnButtonNew(); afx_msg void OnButtonDelete(); afx_msg void OnButtonUp(); afx_msg void OnButtonDown(); afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg void OnNcPaint(); afx_msg void OnEnable(BOOL bEnable); afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); afx_msg LRESULT OnSetTheme(WPARAM wParam, LPARAM lParam); //}}AFX_MSG /** @endcond */ protected: bool m_bShowUpDownButtons; /**< Controls whether or not the up/down buttons are shown. */ bool m_bShowNewDeleteButtons; /**< Controls whether or not the new/delete buttons are shown. */ bool m_bEnableEdit; /**< true if editing is enabled. */ CRect m_arClipRect[4]; /**< Array of toolbar button sizes. */ CXTPButton m_arButton[4]; /**< Array of toolbar buttons. */ CToolTipCtrl m_tooltip; /**< Tooltip control for edit buttons. */ CXTPPaintManagerColor m_clrBackground; CXTPPaintManagerColor m_clrBorder; CXTPPaintManagerColor m_clrText; XTPControlTheme m_theme; /**< List box toolbar theme. */ friend class CXTPEditListBox; }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE CXTPButton& CXTPEditListBoxToolBar::GetNewButton() { return m_arButton[0]; } AFX_INLINE CXTPButton& CXTPEditListBoxToolBar::GetDeleteButton() { return m_arButton[1]; } AFX_INLINE CXTPButton& CXTPEditListBoxToolBar::GetUpButton() { return m_arButton[2]; } AFX_INLINE CXTPButton& CXTPEditListBoxToolBar::GetDownButton() { return m_arButton[3]; } AFX_INLINE void CXTPEditListBoxToolBar::EnableEdit(bool bEnable) { m_bEnableEdit = bEnable; } AFX_INLINE CToolTipCtrl& CXTPEditListBoxToolBar::GetTooltipControl() { return m_tooltip; } /** @endcond */ // forwards class CXTPItemEdit; const DWORD LBS_XTP_DEFAULT = 0x0000; /**< @see CXTPEditListBox::SetListEditStyle */ const DWORD LBS_XTP_CHOOSEDIR = 0x0001; /**< @see CXTPEditListBox::SetListEditStyle */ const DWORD LBS_XTP_CHOOSEFILE = 0x0002; /**< @see CXTPEditListBox::SetListEditStyle */ const DWORD LBS_XTP_NOTOOLBAR = 0x0008; /**< @see CXTPEditListBox::SetListEditStyle */ const DWORD LBS_XTP_BROWSE = 0x0010; /**< Browse button. */ const DWORD LBS_XTP_HIDE_UP_DOWN = 0x0020; /**< Hide Up/Down buttons. */ const DWORD LBS_XTP_ONLY_UP_DOWN = 0x0040; /**< Only Up/Down buttons. */ const DWORD LBS_XTP_BROWSE_ONLY = 0x0080; /**< Browse button. */ /** * @brief * CXTPEditListBox is a CXTPListBox derived class. It is used to create an * editable list box. This list box can be configured to display a toolbar * for editing. You can define browse styles to search for files or folders. * Each entry is made editable with a double mouse click. */ class _XTP_EXT_CLASS CXTPEditListBox : public CXTPListBox { /** @cond */ DECLARE_DYNAMIC(CXTPEditListBox) /** @endcond */ public: /** * @brief * Constructs a CXTPEditListBox object. */ CXTPEditListBox(); /** * @brief * Destroys a CXTPEditListBox object, handles cleanup and deallocation. */ virtual ~CXTPEditListBox(); public: /** * @brief * Sets the edit style for the edit list box. * @param nTitle Resource ID of the string to load for the caption title. * @param dwLStyle Style for the list edit control. Pass in LBS_XTP_NOTOOLBAR * if you do not wish for the caption edit navigation control * bar to be displayed. * @details * Call this member function to set the style and title for the edit * list box. The style of the edit list box can be set to one or more * of the following values:

* * LBS_XTP_DEFAULT: Standard edit field. * LBS_XTP_CHOOSEDIR: Choose directory browse edit field. * LBS_XTP_CHOOSEFILE: Choose file browse edit field. * LBS_XTP_NOTOOLBAR: Do not display edit toolbar. */ void SetListEditStyle(UINT nTitle, DWORD dwLStyle = LBS_XTP_DEFAULT); /** * @brief * Sets the edit style for the edit list box. * @param lpszTitle NULL-terminated string that represents the caption title. * @param dwLStyle Style for the list edit control. Pass in LBS_XTP_NOTOOLBAR * if you do not wish for the caption edit navigation control * bar to be displayed. * @details * Call this member function to set the style and title for the edit * list box. The style of the edit list box can be set to one or more * of the following values:

* * LBS_XTP_DEFAULT: Standard edit field. * LBS_XTP_CHOOSEDIR: Choose directory browse edit field. * LBS_XTP_CHOOSEFILE: Choose file browse edit field. * LBS_XTP_NOTOOLBAR: Do not display edit toolbar. */ void SetListEditStyle(LPCTSTR lpszTitle, DWORD dwLStyle = LBS_XTP_DEFAULT); /** * @brief * Retrieves the current item index. * @return * An integer value that represents the edit control index. * @details * Call this member function to get the current index for the edit * control. Similar to GetCurSel; however, the current index is the * index of the last item to be modified or added to the edit list * box and not necessarily the selected item. */ int GetCurrentIndex(); /** * @brief * This member function will enable editing for the list box item. * @param iItem Index of the item to edit. */ void EditItem(int iItem); /** * @brief * Retrieves the edited item's text label. * @details * This member function is called to retrieve the text for the item * that is being edited in the list box and save the value to * m_strItemText. */ virtual void GetEditItemText(); /** * @brief * This method is called to set in-place edit text. * @param pcszText Next text to set. */ void SetEditText(LPCTSTR pcszText); /** * @brief * Retrieves a pointer to the CXTPEditListBoxToolBar toolbar. * @return * A reference to a CXTPEditListBoxToolBar object. * @details * Call this member function to return a reference to the * CXTPEditListBoxToolBar control associated with the edit list box. */ CXTPEditListBoxToolBar& GetEditGroup(); /** * @brief * Call this member function to set the default filter for the * file dialog. * @param lpszFilter Pointwe to a NULL-terminated string that represents * the file filter used by the file open dialog. */ void SetDlgFilter(LPCTSTR lpszFilter = NULL); /** * @brief * This member function sets the initial directory for the file dialog. * @param lpszInitialDir [in] Pointer to a NULL-terminated string that represents * the initial directory of the file open dialog. */ void SetDlgInitialDir(LPCTSTR lpszInitialDir); /** * @brief * Call this member function to determine if the edit list has a toolbar. * @return * true if the toolbar is turned on, otherwise false. */ bool HasToolbar(); /** * @brief * This member function will enable/disable editing. * @param bEnable true to enable editing, false to disable editing. */ void EnableEdit(bool bEnable); /** * @brief * Initializes the CXTPEditListBox control. * @param bAutoFont true to enable automatic font initialization. * @details * Call this member function to initialize the list box. This method * should be called directly after creating or sub-classing the * control. */ virtual void Initialize(bool bAutoFont = true); /** * @brief * Recalculates the toolbar layout for the CXTPEditListBox. * @details * Call this member function to correctly reposition the edit list * box toolbar. This will readjust the layout correctly and * position the toolbar in relation to the list. */ virtual void RecalcLayout(); /** * @brief * Call this member function to refresh theme colors and redraw the control. */ virtual void RefreshMetrics(); /** * @brief * Sets the default text for new items. * @param lpszItemDefaultText A NULL-terminated string. * @details * Call this member function to set the default text that is * displayed when a new item is added to the edit list box. */ void SetNewItemDefaultText(LPCTSTR lpszItemDefaultText); /** * @brief * Moves an item up. * @param nIndex Item index to move. */ virtual void MoveItemUp(int nIndex); /** * @brief * Moves an item down. * @param nIndex Item index to move. */ virtual void MoveItemDown(int nIndex); protected: /** * @brief * This member function will create the edit group control. * @param bAutoFont true to enable automatic font initialization. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL CreateEditGroup(bool bAutoFont = true); /** * @brief * Enables editing for the currently selected item. * @param bNewItem TRUE to add a new item. * @details * This member function will enable editing for the currently * selected list box item. If 'bNewItem' is TRUE, then a new * item is added to the end of the list box. */ virtual void EditListItem(BOOL bNewItem); /** * @brief * Deletes the currently selected item. */ virtual void DeleteItem(); # if _MSC_VER > 1200 using CListBox::DeleteItem; # endif /** * @brief * This method is called to create an in-place edit control. * @param rcItem Bounding rectangle of edit control. * @return A newly created edit control object pointer. */ virtual CXTPItemEdit* CreateEditControl(CRect rcItem); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPEditListBox) virtual BOOL PreTranslateMessage(MSG* pMsg); virtual COLORREF GetBackColor(); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPEditListBox) afx_msg void OnEndLabelEdit(); afx_msg void OnItemBrowse(); afx_msg void OnNewItem(); afx_msg void OnDeleteItem(); afx_msg void OnMoveItemUp(); afx_msg void OnMoveItemDown(); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point); afx_msg void OnNcMButtonDown(UINT nHitTest, CPoint point); afx_msg void OnNcRButtonDown(UINT nHitTest, CPoint point); afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos); afx_msg void OnEnable(BOOL bEnable); afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG /** @endcond */ protected: CWnd* m_pParentWnd; /**< Pointer to the parent window. */ CString m_strItemDefaultText; /**< Default text used when new items are created. */ int m_nIndex; /**< Current index when edit functions are performed. */ BOOL m_bNewItem; /**< TRUE if a new item is being entered into the list box. */ bool m_bEnableEdit; /**< true if editing is enabled. */ DWORD m_dwLStyle; /**< List edit styles. */ CString m_strTitle; /**< Caption area title. */ CString m_strFilter; /**< Default file filter. */ CString m_strInitialDir; /**< Initial Dir. */ CString m_strItemText; /**< Current text of a selected item during edit. */ CXTPItemEdit* m_pItemEdit; /**< Pointer to the in-place edit item. */ CXTPEditListBoxToolBar m_editGroup; /**< The edit group (toolbar) that appears above the list box. */ }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE int CXTPEditListBox::GetCurrentIndex() { return m_nIndex; } AFX_INLINE CXTPEditListBoxToolBar& CXTPEditListBox::GetEditGroup() { return m_editGroup; } AFX_INLINE void CXTPEditListBox::SetDlgFilter(LPCTSTR lpszFilter /*=NULL*/) { m_strFilter = lpszFilter; } AFX_INLINE void CXTPEditListBox::SetDlgInitialDir(LPCTSTR lpszInitialDir /*=NULL*/) { m_strInitialDir = lpszInitialDir; } AFX_INLINE bool CXTPEditListBox::HasToolbar() { return ((m_dwLStyle & LBS_XTP_NOTOOLBAR) == 0); } AFX_INLINE void CXTPEditListBox::EnableEdit(bool bEnable) { m_bEnableEdit = bEnable; m_editGroup.EnableEdit(bEnable); } AFX_INLINE void CXTPEditListBox::SetNewItemDefaultText(LPCTSTR lpszItemDefaultText) { m_strItemDefaultText = lpszItemDefaultText; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTEDITLISTBOX_H__) /** @endcond */