/** * @file XTPBrowseEdit.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(__XTPBROWSEEDIT_H__) # define __XTPBROWSEEDIT_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPBrowseEdit; # define XTP_IDC_LBOX_EDIT 101 /** * @brief * CXTPBrowseButton is a CXTPButton derived class. It is used by * CXTPBrowseEdit to create the browse button used for * displaying file dialogs and pop-up menus. */ class _XTP_EXT_CLASS CXTPBrowseButton : public CXTPButton { /** @cond */ DECLARE_DYNAMIC(CXTPBrowseButton) /** @endcond */ public: /** * @brief * Constructs a CXTPBrowseButton object. */ CXTPBrowseButton(); /** * @brief * Destroys a CXTPBrowseButton object, handles cleanup and deallocation. */ virtual ~CXTPBrowseButton(); public: /** * @brief * This member function is called to create the browse button used by * the edit control. * @param pEditWnd [in] Parent edit control. * @param dwBStyle [in] Search type. * @param nID [in] Resource ID for push button. * @param nMenu [in] Pop-up menu ID. * @param nSubMenuIndx [in] Index of pop-up submenu. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(CXTPBrowseEdit* pEditWnd, DWORD dwBStyle, UINT nID, UINT nMenu = (UINT)-1, UINT nSubMenuIndx = (UINT)-1); /** * @brief * This member function will set the browse style for the button. * @param dwxStyle Specifies the browse style. The button style can be defined * as one or more of the styles listed in the Remarks section. * @details * The CXTPBrowseButton can be set to use one or more of the following * styles: * BES_XTP_CHOOSEDIR: Display the choose folder dialog. * BES_XTP_CHOOSEFILE: Display the choose file dialog. * BES_XTP_POPUPMENU: Display a user-defined context menu. * @see * SetXButtonStyle */ void SetBrowseStyle(DWORD dwxStyle); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPItemEdit) virtual BOOL PreTranslateMessage(MSG* pMsg); virtual void OnClicked(); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPBrowseButton) afx_msg void OnEnable(BOOL bEnable); afx_msg void OnBtnClicked(); //}}AFX_MSG /** @endcond */ private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); protected: DWORD m_dwBStyle; /**< Search type. */ UINT m_nID; /**< Resource ID for push button. */ UINT m_nMenu; /**< Pop-up menu ID. */ UINT m_nSubMenuIndx; /**< Index of pop-up sub-menu. */ CXTPBrowseEdit* m_pEditWnd; /**< Parent edit control. */ friend class CXTPBrowseEdit; }; /** * @brief * CXTPBrowseEdit is a CXTPEdit derived class. This class also * has a push button associated with it. The control can be used to * search for directories and files or activate a pop-up menu. */ class _XTP_EXT_CLASS CXTPBrowseEdit : public CXTPEdit { /** @cond */ DECLARE_DYNAMIC(CXTPBrowseEdit) /** @endcond */ public: /** * @brief * Constructs a CXTPBrowseEdit object. */ CXTPBrowseEdit(); /** * @brief * Destroys a CXTPBrowseEdit object, handles cleanup and deallocation. */ virtual ~CXTPBrowseEdit(); public: /** * @brief * Call this member function to determine if the browse edit control * is in the middle of a browse operation. * @return * true if the control is displaying a File Open dialog or pop-up menu. */ bool IsBrowsing(); /** * @brief * Call this member function to set the gap between the browse button * and the edit window. * @param nGap [in] Gap, in pixels, between the browse button and the edit window. */ void SetGap(int nGap); /** * @brief * This member function will set a CFileDialog derived class object to * be the file open dialog. * @param pFileDialog [in] Pointer to the CFileDialog object that will replace the * standard File Open dialog. */ virtual void SetFileDialog(CFileDialog* pFileDialog); /** * @brief * This member function will set the File Open dialog style. * @param bOpenFileDialog [in] TRUE to construct a File Open dialog box, or * FALSE to construct a File Save As dialog box. */ virtual void SetDlgOpenFile(BOOL bOpenFileDialog = TRUE); /** * @brief * This member function sets the default extension for the File Open dialog. * @param lpszDefExt [in] Pointer to a NULL-terminated string that represents the * default file extension to be used with the File Open dialog. */ void SetDlgDefExt(LPCTSTR lpszDefExt = NULL); /** * @brief * This member function sets the default file name for the File Open dialog. * @param lpszFileName [in] Pointer to a NULL-terminated string that represents the * default file name to be used with the File Open dialog. */ void SetDlgFileName(LPCTSTR lpszFileName = NULL); /** * @brief * This member function sets the style flags for the File Open dialog. * @param dwFlags [in] The desired OFN_ styles for the File Open dialog. */ virtual void SetDlgStyle(DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT); /** * @brief * This member function sets the file filter for the File Open dialog. * @param lpszFilter [in] Pointer 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 title for the directory dialog. * @param lpszTitle [in] Pointer to a NULL-terminated string that represents the * title of the "browse for directory" dialog. */ void SetDlgTitle(LPCTSTR lpszTitle = NULL); /** * @brief * This member function sets the initial directory for the directory dialog. * @param lpszInitialDir [in] Pointer to a NULL-terminated string that represents the * initial directory of the dialog. */ void SetDlgInitialDir(LPCTSTR lpszInitialDir); /** * @brief * This member function is called to initialize the browse edit control. * @param pParentWnd [in] Pointer to the parent of the edit control. * @param dwBStyle [in] A DWORD value that represents the type of * search to perform. It can be any one of the styles listed * in the remarks section. * @param nMenu [in] If dwBStyle contains the BES_XTP_POPUPMENU flag, * then nMenu represents the resource ID of a pop-up * menu. Otherwise this value is ignored. * @param nSubMenuIndx [in] Index of the submenu to display. * @details * The Initialize function must be called once for each browse edit * control to complete initialization. This should be done after you * have subclassed or created the browse edit control.
* * The browse edit control can be defined to use any of the following * styles: * BES_XTP_CHOOSEDIR: Display the choose folder dialog. * BES_XTP_CHOOSEFILE: Display the choose file dialog. * BES_XTP_POPUPMENU: Display a user-defined context menu. * * The single argument version of Initialize will call the CXTPEdit * base class to initialize the edit portion of the control only. * Generally you would not want to use this override for standard * initialization. * Example: * The following example demonstrates the use of Initialize: *
* BOOL CBrowseEditDlg::OnInitDialog()
* {
* CXTPResizeDialog::OnInitDialog();
* ...
* // Initialize browse edit controls.
* m_edit1.Initialize(this, BES_XTP_POPUPMENU, IDR_POPUP);
* m_edit2.Initialize(this, BES_XTP_CHOOSEDIR);
* m_edit3.Initialize(this, BES_XTP_CHOOSEFILE);
*
* return TRUE; // return TRUE unless you set the focus to a control
* }
*
* @return
* TRUE if initialization was successful, otherwise FALSE.
*/
virtual bool Initialize(CWnd* pParentWnd, DWORD dwBStyle, UINT nMenu = 0, int nSubMenuIndx = 0);
/**
* @brief
* This member function is called to initialize the browse edit control.
* @param pParentWnd [in] Pointer to the parent of the edit control.
* @details
* The Initialize function must be called once for each browse edit
* control to complete initialization. This should be done after you
* have subclassed or created the browse edit control.
*
* The browse edit control can be defined to use any of the following
* styles:
* BES_XTP_CHOOSEDIR: Display the choose folder dialog.
* BES_XTP_CHOOSEFILE: Display the choose file dialog.
* BES_XTP_POPUPMENU: Display a user-defined context menu.
*
* The single argument version of Initialize will call the CXTPEdit
* base class to initialize the edit portion of the control only.
* Generally you would not want to use this override for standard
* initialization.
* Example:
* The following example demonstrates the use of Initialize:
*
* BOOL CBrowseEditDlg::OnInitDialog()
* {
* CXTPResizeDialog::OnInitDialog();
* ...
* // Initialize browse edit controls.
* m_edit1.Initialize(this, BES_XTP_POPUPMENU, IDR_POPUP);
* m_edit2.Initialize(this, BES_XTP_CHOOSEDIR);
* m_edit3.Initialize(this, BES_XTP_CHOOSEFILE);
*
* return TRUE; // return TRUE unless you set the focus to a control
* }
*
* @return
* true if initialization was successful, otherwise false.
*/
virtual bool Initialize(CWnd* pParentWnd);
/**
* @brief
* This member function is called whenever the browse button is pressed
* and can be overridden to perform custom browse functions.
*/
virtual void OnBrowse();
/**
* @brief
* This member function is called by the browse edit control to
* display a directory chooser dialog.
*/
virtual void ChooseDirectory();
/**
* @brief
* This member function is called by the browse edit control to
* display a File Open dialog.
*/
virtual void ChooseFile();
/**
* @brief
* This member function is called by the browse edit control to
* create and track a pop-up menu. The menu selection is then copied
* to the edit control.
*/
virtual void PopupMenu();
/**
* @brief
* This member function is called by the browse edit control to position
* the browse button in relation to the edit control.
*/
virtual void PositionBrowseButton();
/**
* @brief
* Call this member function to get a reference to the browse button.
* @return
* A reference to the browse button.
*/
CXTPBrowseButton* GetBrowseButton();
protected:
/** @cond */
//{{AFX_MSG(CXTPBrowseEdit)
afx_msg void OnEnable(BOOL bEnable);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
/** @endcond */
public:
static int m_nDefaultGap; /**< Default distance between the button and edit control. */
protected:
int m_nGap; /**< Distance between the button and edit control. */
bool m_bBrowsing; /**< true if in browse operation. */
BOOL m_bOpenFileDialog; /**< TRUE for Open File dialog, FALSE for Save As. See SetDlgOpenFile.
*/
UINT m_nMenu; /**< Pop-up menu ID. */
UINT m_nSubMenuIndx; /**< Index of a pop-up submenu. */
DWORD m_dwFlags; /**< File dialog styles. */
DWORD m_dwBStyle; /**< Search type. */
CString m_strDefExt; /**< Default file extension. */
CString m_strFileName; /**< Default file name. */
CString m_strFilter; /**< Default file filter. */
CString m_strInitialDir; /**< Initial directory. */
CString m_strTitle; /**< Directory dialog title. */
CFileDialog* m_pFileDialog; /**< Pointer to a valid CFileDialog object. */
CXTPBrowseButton m_btnBrowse; /**< Pointer to a push button. */
};
/** @cond */
//////////////////////////////////////////////////////////////////////
AFX_INLINE bool CXTPBrowseEdit::Initialize(CWnd* pParentWnd)
{
return CXTPEdit::Initialize(pParentWnd);
}
AFX_INLINE void CXTPBrowseEdit::SetGap(int nGap)
{
_ASSERTE(nGap >= 0);
m_nGap = nGap;
}
AFX_INLINE void CXTPBrowseEdit::SetFileDialog(CFileDialog* pFileDialog /*=NULL*/)
{
m_pFileDialog = pFileDialog;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgOpenFile(BOOL bOpenFileDialog /*=TRUE*/)
{
m_bOpenFileDialog = bOpenFileDialog;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgDefExt(LPCTSTR strDefExt /*=NULL*/)
{
m_strDefExt = strDefExt;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgFileName(LPCTSTR strFileName /*=NULL*/)
{
m_strFileName = strFileName;
}
AFX_INLINE void
CXTPBrowseEdit::SetDlgStyle(DWORD dwFlags /*=OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT*/)
{
m_dwFlags = dwFlags;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgFilter(LPCTSTR strFilter /*=NULL*/)
{
m_strFilter = strFilter;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgTitle(LPCTSTR strTitle /*=NULL*/)
{
m_strTitle = strTitle;
}
AFX_INLINE bool CXTPBrowseEdit::IsBrowsing()
{
return m_bBrowsing;
}
AFX_INLINE void CXTPBrowseEdit::SetDlgInitialDir(LPCTSTR lpszInitialDir)
{
m_strInitialDir = lpszInitialDir;
}
/** @endcond */
const DWORD BES_XTP_CHOOSEDIR = 0x0001; /**< Display a choose directory dialog. @see
CXTPBrowseEdit::Initialize */
const DWORD BES_XTP_CHOOSEFILE = 0x0002; /**< Display a choose file dialog. @see
CXTPBrowseEdit::Initialize */
const DWORD BES_XTP_POPUPMENU = 0x0004; /**< Display a popup menu for the dialog. @see
CXTPBrowseEdit::Initialize */
const DWORD BES_XTP_BROWSE = 0x0010; /**< Display a user-defined dialog for browsing. Note: this
must match the LBS_XTP_BROWSE define. @see
CXTPBrowseEdit::Initialize */
/**
* @brief
* CXTPItemEdit is a CXTPBrowseEdit derived class. It is used to create
* a CXTPItemEdit window that can be used as an "in-place" edit field that
* can be dynamically created for controls such as a list box.
*/
class _XTP_EXT_CLASS CXTPItemEdit : public CXTPBrowseEdit
{
/** @cond */
DECLARE_DYNAMIC(CXTPItemEdit)
/** @endcond */
public:
/**
* @brief
* Constructs a CXTPItemEdit object that can be used as an "in-place" edit
* field and can be dynamically created for controls such as a list box
*/
CXTPItemEdit();
/**
* @brief
* Constructs a CXTPItemEdit object that can be used as an "in-place" edit
* field and can be dynamically created for controls such as a list box
* @param pParent Pointer to the parent window.
* @param rect Size of the edit item.
* @param strWindowText Text to be initially displayed in the edit field.
* @param dwBStyle Specifies the browse edit style for the in-place
* edit field. See CXTPBrowseEdit::SetBrowseStyle
* for available styles.
* @param bAutoDelete Set to true if the object is to be self-deleting.
* @return TRUE if successful, FALSE otherwise.
*/
BOOL Create(CWnd* pParent, const CRect& rect, CString& strWindowText,
DWORD dwBStyle = BES_XTP_CHOOSEDIR, bool bAutoDelete = true);
# if _MSC_VER > 1200
using CWnd::Create;
# endif
/**
* @brief
* Destroys a CXTPItemEdit object, handles cleanup and deallocation.
*/
virtual ~CXTPItemEdit();
public:
/**
* @brief
* This member function is called whenever the control loses focus.
* This will destroy the window, and notify the parent via WM_COMMAND
* that the editing has been completed. The two possible commands are:
* ON_BEN_XTP_LABELEDITEND and ON_BEN_XTP_LABELEDITCANCEL
*/
virtual void EndLabelEdit();
protected:
/** @cond */
//{{AFX_VIRTUAL(CXTPItemEdit)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
//{{AFX_MSG(CXTPItemEdit)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
/** @endcond */
public:
bool m_bModified; /**< true if the item was modified. */
bool m_bAutoDelete; /**< true if self-deleting. */
bool m_bEscapeKey; /**< true if the edit window was closed with the escape key. */
CString m_strWindowText; /**< The edit controls text. */
protected:
bool m_bClosePosted; /**< Used internally to determine if a WM_CLOSE message has been sent. */
};
//////////////////////////////////////////////////////////////////////
/** @cond */
AFX_INLINE BOOL CXTPBrowseButton::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 CXTPBrowseButton::Create(LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect,
CWnd* pParentWnd, UINT nID)
{
return CButton::Create(lpszCaption, dwStyle, rect, pParentWnd, nID);
}
AFX_INLINE CXTPBrowseButton* CXTPBrowseEdit::GetBrowseButton()
{
return &m_btnBrowse;
}
/** @endcond */
# include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h"
/** @cond */
#endif // #if !defined(__XTPBROWSEEDIT_H__)
/** @endcond */