/** * @file XTPToolBar.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(__XTPTOOLBAR_H__) # define __XTPTOOLBAR_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPDockBar; class CXTPCommandBars; class CXTPDockContext; /** * @brief * CXTPToolBar is a CXTPCommandBar derived class. */ class _XTP_EXT_CLASS CXTPToolBar : public CXTPCommandBar { public: /** @cond */ class CToolBarInfo; /** @endcond */ class CXTPPushRoutingFrame { protected: CFrameWnd* pOldRoutingFrame; _AFX_THREAD_STATE* pThreadState; public: CXTPPushRoutingFrame(CFrameWnd* pNewRoutingFrame) { pThreadState = AfxGetThreadState(); pOldRoutingFrame = pThreadState->m_pRoutingFrame; pThreadState->m_pRoutingFrame = pNewRoutingFrame; } ~CXTPPushRoutingFrame() { pThreadState->m_pRoutingFrame = pOldRoutingFrame; } }; private: class CControlButtonExpand; class CControlButtonHide; public: /** * @brief * Constructs a CXTPToolBar object. */ CXTPToolBar(); /** * @brief * Destroys a CXTPToolBar object, handles cleanup and deallocation. */ ~CXTPToolBar(); public: /** * @brief * Call this member to set the visibility of the toolbar. * @param bVisible A BOOL value. TRUE to set the toolbar to visible, * FALSE to hide the toolbar. */ virtual void SetVisible(BOOL bVisible); /** * @brief * Call this member to check the visibility of the toolbar. * @return * A BOOL value. TRUE if the toolbar is visible, otherwise FALSE. */ virtual BOOL IsVisible() const { return m_bVisible; } /** * @brief * Call this member to set the position of the toolbar. * @param barPosition New position of the toolbar. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetPosition(XTPBarPosition barPosition); /** * @brief * Call this member function to load the toolbar specified by nIDResource. * @param nIDResource Resource ID of the toolbar to be loaded. * @param bLoadIcons TRUE to load icons from application resources. * @return * Nonzero if successful; otherwise 0. */ BOOL LoadToolBar(UINT nIDResource, BOOL bLoadIcons = TRUE); public: /** * @brief * This method creates the ToolBar control. * @param dwStyle Styles for the toolbars. * @param pParentWnd Specifies the parent window of the TaskPanel control. * @param nID Specifies the Toolbar control ID. * @return * TRUE if successful; otherwise FALSE. */ BOOL CreateToolBar(DWORD dwStyle, CWnd* pParentWnd, UINT nID = AFX_IDW_TOOLBAR); /** * @brief * Retrieves bar information for serialization routines. * @param pInfo Pointer to a CToolBarInfo object. */ void GetBarInfo(CToolBarInfo* pInfo); /** * @brief * Sets bar information. * @param pInfo Pointer to a CToolBarInfo object. */ void SetBarInfo(CToolBarInfo* pInfo); /** * @brief * This method calculates the dimensions of a toolbar. * @param nLength Length of the bar. * @param dwMode Mode to dock. * @param nWidth Width of the bar. * @return * Size of the docked toolbar. */ virtual CSize CalcDockingLayout(int nLength, DWORD dwMode, int nWidth = 0); /** * @brief * This method calculates the dimensions of a toolbar. * @param nLength The requested dimension of the control bar, either * horizontal or vertical, depending on dwMode. * @param dwMode Mode to dock. * @return * Size of the docked toolbar. */ virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode); /** * @brief * Call this method to set docking flags. * @param dwFlags Flags for docking. Can be any of the values listed in the Remarks section. * @details * dwFlags parameter can be one or more of the following: * xtpFlagAlignTop: Allows docking at the top of the client area. * xtpFlagAlignBottom: Allows docking at the bottom of the client area. * xtpFlagAlignLeft: Allows docking on the left side of the client area. * xtpFlagAlignRight: Allows docking on the right side of the client area. * xtpFlagFloating: Allows floating. * xtpFlagHideWrap: Allows to hide wrapped controls. * xtpFlagStretched: Indicates the bar is stretched. */ void EnableDocking(DWORD dwFlags = xtpFlagAlignAny | xtpFlagFloating | xtpFlagHideWrap); /** * @brief * Determines if the toolbar is built-in. * @return * TRUE if toolbar is built-in; otherwise FALSE. */ BOOL IsBuiltIn() const; /** * @brief * Retrieves the parent dock bar. * @return * A pointer to a CXTPDockBar object. */ CXTPDockBar* GetDockBar() const; /** * @brief * Resets the controls to their original state. * @param bShowWarningMessage TRUE to show warning message. */ virtual void Reset(BOOL bShowWarningMessage); /** * @brief * Call this method to show/hide toolbars in preview mode. * @param bPreview TRUE to show toolbars in preview mode, * FALSE to hide toolbars in preview mode. */ void OnSetPreviewMode(BOOL bPreview); /** * @brief * The framework calls this member function when a non-system key * is pressed. * @param nChar Specifies the virtual key code of the given key. * @param lParam Specifies additional message-dependent information. * @return * TRUE if the key was handled, otherwise FALSE. */ BOOL OnHookKeyDown(UINT nChar, LPARAM lParam); /** * @brief * Call this method to show/hide the toolbar in a context menu. * @param bPresent TRUE to show the toolbar in a context menu. */ void SetContextMenuPresent(BOOL bPresent); /** * @brief * Call this member to determine if this toolbar is included in * the right-click context menu. * @return * TRUE if this toolbar is included in the right-click context menu, * otherwise FALSE. */ BOOL IsContextMenuPresent() const; /** * @brief * Call this method to show/hide the toolbar in a customize dialog. * @param bPresent TRUE to show the toolbar in a customize dialog. */ void SetCustomizeDialogPresent(BOOL bPresent); /** * @brief * Call this member to determine if this toolbar is included in * the customize dialog. * @return * TRUE if this toolbar is included in the customize dialog, * otherwise FALSE. */ BOOL IsCustomizeDialogPresent() const; /** * @brief * Modifies the styles of the toolbar. * @param dwRemove Styles to remove. * @param dwAdd Styles to add. */ void ModifyBarStyle(DWORD dwRemove, DWORD dwAdd); /** * @brief * Call this method to enable/disable the closeable property of the * command bar. * @param bCloseable TRUE to allow the command bar to be closed by the user. */ void SetCloseable(BOOL bCloseable); /** * @brief * Call this method to retrieve the closeable property of the * command bar. * @return * TRUE if the command bar is closeable, otherwise FALSE. */ BOOL IsCloseable() const; /** * @brief * Call this method to determine if the control is temporary. * @details * Temporary toolbars will not be saved to the system registry when * the application is closed (If SaveCommandBars is used), and they * will not be restored when the application is opened * (If LoadCommandBars is used). * @return * TRUE if the control is temporary. */ BOOL IsTemporary() const; /** * @brief * Call this method to set the control to temporary. * @param bTemporary TRUE to set the control to temporary. * @details * Temporary toolbars will not be saved to the system registry when * the application is closed (If SaveCommandBars is used), and they * will not be restored when the application is opened * (If LoadCommandBars is used). */ void SetTemporary(BOOL bTemporary); /** * @brief * Call this method to show/hide the expand button of the toolbar. * @param bShowExpandButton TRUE to show the expand button of the toolbar, * FALSE to hide the expand button of the toolbar. */ void ShowExpandButton(BOOL bShowExpandButton); /** * @brief * This method recalculates the position of the toolbar. */ void OnRecalcLayout(); /** * @brief * Determines if the toolbar is visible on the screen. * @return * TRUE if the toolbar is visible. * @see * IsVisible */ BOOL IsWindowVisible() const; /** * @brief * Tries to update a Customize menu control. * @param pControl A pointer to the customize menu control. * @param pTarget A pointer to the target command handler. * @return * TRUE if the control has been updated, otherwise FALSE. */ static BOOL AFX_CDECL DoUpdateCustomizeMenuControl(CXTPControl* pControl, CCmdTarget* pTarget); protected: /** * @brief * Creates a toolbar. * @param pParentWnd Pointer to a CWnd object. * @param bFloat TRUE to create a floating bar. * @return * TRUE if successful; otherwise FALSE. */ virtual BOOL Create(CWnd* pParentWnd, BOOL bFloat); /** * @brief * Either reads this object from or writes this object to an archive. * @param pPX A CXTPPropExchange object to serialize to or from. */ virtual void DoPropExchange(CXTPPropExchange* pPX); /** * @brief * This method makes a copy of the command bar. * @param pCommandBar Command bar to be copied. * @param bRecursive TRUE to copy recursively. */ virtual void Copy(CXTPCommandBar* pCommandBar, BOOL bRecursive = FALSE); protected: /** * @brief * This method retrieves the borders of the toolbar. * @return * The borders of the toolbar. */ virtual CRect GetBorders(); /** * @brief * This method is called when the paint manager is changed. */ virtual void OnPaintManagerChanged(); protected: /** * @brief * Call this method to check if the toolbar has changed and must be saved. * @return * TRUE if the toolbar has changed and must be saved, otherwise FALSE. */ virtual BOOL ShouldSerializeBar(); /** * @brief * This method is called to restore a toolbar to a previous state. * @param pCommandBar Previously saved toolbar. * @param bSilent TRUE to restore without warnings. * @see * ShouldSerializeBar */ virtual void MergeToolBar(CXTPCommandBar* pCommandBar, BOOL bSilent); /** * @brief * This method is called to restore a toolbar to a previous state. * @param pCommandBar Previously saved toolbar. * @param bSilent TRUE to restore without warnings. * @param nDefaultConfirmationChoice Default confirmation choice value. * @see * ShouldSerializeBar */ virtual void MergeToolBar(CXTPCommandBar* pCommandBar, BOOL bSilent, int nDefaultConfirmationChoice); private: CSize _CalcDynamicLayout(int nLength, DWORD dwMode); void BuildCustomizePopup(CXTPCommandBar* pExpandBar); int _FindNearest(CXTPControls* pControls, CXTPControl* pFind, int nPos, BOOL bVisible = FALSE) const; void _RestoreDeletedControls(); void _GetHiddenControls(CXTPCommandBar* pExpandBar); BOOL IsFloatingFrameFocused() const; protected: virtual void BeforeCustomizeControlAdd(CXTPControl* pControl); # ifdef _XTP_COMMANDBARS_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() afx_msg void OleReset(); afx_msg void OleDelete(); public: virtual void OleEnableCustomization(); /** @endcond */ # endif protected: CXTPDockBar* m_pDockBar; /**< Parent dock bar. */ CXTPDockContext* m_pDockContext; /**< Docking context. */ BOOL m_bBuiltIn; /**< TRUE if toolbar is built-in. */ BOOL m_bTearOff; /**< TRUE if toolbar is tear-offed. */ BOOL m_bPreviewVisible; /**< TRUE if Toolbar was visible in preview mode. */ BOOL m_bPreviewMode; /**< TRUE if Toolbar was visible in preview mode. */ BOOL m_bTemporary; /**< TRUE if Toolbar is temporary (If it will be saved when the CommandBar layout is saved.) */ BOOL m_bShowExpandButton; /**< TRUE to show expand button of toolbar. */ BOOL m_bContextMenuPresent; /**< TRUE if the command bar is present in context menu. */ BOOL m_bInRecalcLayout; /**< TRUE if RecalcLayout method is called */ BOOL m_bVisible; /**< TRUE if the command bar is visible. */ protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_MSG(CXTPToolBar) afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpCreateStruct); afx_msg BOOL OnNcActivate(BOOL bActive); afx_msg LRESULT OnFloatStatus(WPARAM wParam, LPARAM); afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg LRESULT OnNcHitTest(CPoint point); afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnClose(); afx_msg LRESULT OnSizeParent(WPARAM, LPARAM lParam); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint pt); //}}AFX_MSG /** @endcond */ private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); /** @cond */ DECLARE_XTP_COMMANDBAR(CXTPToolBar) /** @endcond */ private: friend class CXTPCommandBars; friend class CXTPDockContext; friend class CXTPDockBar; friend class CXTPCustomizeToolbarsPage; friend class CXTPPopupBar; friend class CControlButtonExpand; }; ////////////////////////////////////////////////////////////////////////// AFX_INLINE BOOL CXTPToolBar::IsBuiltIn() const { return m_bBuiltIn; } AFX_INLINE CXTPDockBar* CXTPToolBar::GetDockBar() const { return m_pDockBar; } AFX_INLINE void CXTPToolBar::SetContextMenuPresent(BOOL bPresent) { m_bContextMenuPresent = bPresent; } AFX_INLINE BOOL CXTPToolBar::IsContextMenuPresent() const { return m_bContextMenuPresent; } AFX_INLINE void CXTPToolBar::SetCustomizeDialogPresent(BOOL bPresent) { m_bCustomizeDialogPresent = bPresent; } AFX_INLINE BOOL CXTPToolBar::IsCustomizeDialogPresent() const { return m_bCustomizeDialogPresent; } AFX_INLINE void CXTPToolBar::ModifyBarStyle(DWORD dwRemove, DWORD dwAdd) { m_dwStyle |= dwAdd; m_dwStyle &= ~dwRemove; } AFX_INLINE void CXTPToolBar::SetCloseable(BOOL bCloseable) { m_bCloseable = bCloseable; } AFX_INLINE BOOL CXTPToolBar::IsCloseable() const { return m_bCloseable; } AFX_INLINE BOOL CXTPToolBar::IsTemporary() const { return m_bTemporary; } AFX_INLINE void CXTPToolBar::SetTemporary(BOOL bTemporary) { m_bTemporary = bTemporary; } AFX_INLINE BOOL CXTPToolBar::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 void CXTPToolBar::ShowExpandButton(BOOL bShowExpandButton) { m_bShowExpandButton = bShowExpandButton; DelayLayout(); } AFX_INLINE void CXTPToolBar::OnPaintManagerChanged() { } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPTOOLBAR_H__) /** @endcond */