/** * @file XTPPopupBar.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(__XTPPOPUPBAR_H__) # define __XTPPOPUPBAR_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPControlPopup; class CXTPCommandBars; /** * @brief * CXTPPopupBar is a CXTPCommandBar derived class. * It represents a submenu of a menu bar. */ class _XTP_EXT_CLASS CXTPPopupBar : public CXTPCommandBar { /** @cond */ DECLARE_XTP_COMMANDBAR(CXTPPopupBar) /** @endcond */ private: class CControlExpandButton; protected: /** * @brief * Constructs a CXTPPopupBar object. */ CXTPPopupBar(); /** * @brief * Destroys a CXTPPopupBar object, handles cleanup and deallocation. */ virtual ~CXTPPopupBar(); public: /** * @brief * Creates a pop-up bar object. * @param pCommandBars Pointer to a CXTPCommandBars object. * @return * A pointer to a CXTPPopupBar object. */ static CXTPPopupBar* AFX_CDECL CreatePopupBar(CXTPCommandBars* pCommandBars); public: /** * @brief * This method adds the tear-off state to the pop-up bar. * @param lpszCaption Caption of the tear-off toolbar. * @param nID Identifier of the toolbar to be created. * @param nWidth Width of the toolbar. */ void SetTearOffPopup(LPCTSTR lpszCaption, UINT nID, int nWidth = 400); /** * @brief * Determines if the pop-up bar has the tear-off state. * @param strCaption Caption of the tear-off toolbar. * @param nID Identifier of the toolbar to be created. * @param nWidth Width of the toolbar. * @return * TRUE if the pop-up bar has the tear-off state, otherwise FALSE. */ BOOL IsTearOffPopup(CString& strCaption, UINT& nID, int& nWidth); /** * @brief * Call this member to determine if the pop-up menu is visible/displayed. * @return * TRUE if the pop-up menu is visible/displayed, * FALSE if the pop-up menu is currently hidden. */ virtual BOOL IsVisible() const; /** * @brief * This method opens the pop-up bar. * @param xPos Specifies the logical x coordinate of the pop-up bar * @param yPos Specifies the logical y coordinate of the position. * @param rcExclude Excluded area. * @return * TRUE if successful, otherwise FALSE. */ BOOL Popup(int xPos, int yPos, LPCRECT rcExclude); /** * @brief * This method opens the pop-up bar. * @param pControlPopup Pointer to a CXTPControlPopup object. * @param bSelectFirst TRUE to select the first item. * @return * TRUE if successful, otherwise FALSE. */ BOOL Popup(CXTPControlPopup* pControlPopup, BOOL bSelectFirst = FALSE); /** * @brief * Call this member to retrieve the control's pop-up. * @return * A pointer to a CXTPControlPopup object. */ CXTPControlPopup* GetControlPopup() const; /** * @brief * This method expands the bar. */ void ExpandBar(); /** * @brief * Call this member to destroy the window. * @return * TRUE if successful, otherwise FALSE. */ BOOL DestroyWindow(); /** * @brief * Call this method to make the pop-up bar look like a pop-up toolbar. * @param bToolBarType TRUE to make the pop-up bar as a pop-up toolbar. */ void SetPopupToolBar(BOOL bToolBarType); /** * @brief * Sets the default menu item for the specified pop-up bar. * @param uItem Identifier or position of the new default menu item or * -1 for no default item. The meaning of this parameter * depends on the value of fByPos. * @param fByPos Value specifying the meaning of uItem. If this parameter * is FALSE, uItem is a menu item identifier. Otherwise, * it is a menu item position. */ void SetDefaultItem(UINT uItem, BOOL fByPos = FALSE); /** * @brief * Determines the default menu item on the specified pop-up bar. * @param gmdiFlags Reserved. Should be NULL. * @param fByPos Value specifying whether to retrieve the menu item's * identifier or its position. If this parameter is * FALSE, the identifier is returned. Otherwise, the * position is returned. * @return * If the function succeeds, the return value is the identifier * or position of the menu item. If the function fails, the return * value is -1. */ UINT GetDefaultItem(UINT gmdiFlags, BOOL fByPos = FALSE); /** * @brief * Call this method to determine if the pop-up bar has a double gripper. * @return * TRUE if the pop-up bar has a double gripper, otherwise FALSE. */ BOOL IsDoubleGripper() const; /** * @brief * Call this member to set a double gripper for the pop-up bar. * @param bDoubleGripper TRUE to set a double gripper for the pop-up bar. */ void SetDoubleGripper(BOOL bDoubleGripper = TRUE); /** * @brief * Call this member function to determine if the command bar is a CXTPPopupBar. * @return * TRUE if the command bar is a CXTPPopupBar, otherwise FALSE. * @see * CXTPCommandBar, CXTPPopupBar */ virtual BOOL IsPopupBar() const; /** * @brief * Determines if the pop-up bar is a context menu. * @return * TRUE if the pop-up bar is a context menu. * @see * CXTPCommandBarsContextMenus */ BOOL IsContextMenu() const; /** * @brief * Translates all messages in the message queue. */ void PumpMessage(); /** * @brief * This method is called to get the size of the command bar. * @param nLength The requested dimension of the control bar, either * horizontal or vertical, depending on dwMode. * @param dwMode See CControlBar::CalcDynamicLayout for a list of supported flags. * @return * Size of the command bar. */ virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode); /** * @brief * Creates the pop-up bar. * @return * TRUE if successful; otherwise FALSE. */ virtual BOOL Create(); /** * @brief * This method is called to calculate the destination rectangle of the pop-up bar. * @param ptPopup Point to display the pop-up bar. * @param sz Size of the pop-up bar. * @return * Rectangle where the pop-up bar will be located. */ virtual CRect CalculatePopupRect(CPoint ptPopup, CSize sz); /** * @brief * Call this method to set the pop-up direction. * @param dwPopupFlags Direction of pop-up to open. See XTPPopupDirection enumerator. * @see * XTPPopupDirection */ void SetPopupFlags(DWORD dwPopupFlags); /** * @brief * Call this member to change the tracking state. * @param bMode TRUE to set the tracking mode, otherwise FALSE. * @param bSelectFirst TRUE to select the first item. * @param bKeyboard TRUE if the item is pop-up'ed by the keyboard. * @return * TRUE if the method was successful, otherwise FALSE. * @see * IsTrackingMode. */ virtual BOOL SetTrackingMode(int bMode, BOOL bSelectFirst = TRUE, BOOL bKeyboard = FALSE); protected: /** * @brief * Redraw the pop-up bar. */ virtual void DelayRedraw() { Redraw(); } /** * @brief * Call this member to select the specified control. * @param nSelected An integer index of the item to be selected. * @param bKeyboard TRUE if the item was selected using the keyboard. * @return * TRUE if the method was successful, otherwise FALSE. */ virtual BOOL SetSelected(int nSelected, BOOL bKeyboard = FALSE); /** * @brief * This method sets the pop-up bar's position. * @param sz Size of the pop-up bar. */ void UpdateLocation(CSize sz); /** * @brief * Update flags. */ virtual void UpdateFlags(); /** * @brief * Update expanding state. */ void UpdateExpandingState(); /** * @brief * This method is called to draw the command bar in the given context. * @param pDC Pointer to a valid device context. * @param rcClipBox The rectangular area of the control that is invalid. */ virtual void DrawCommandBar(CDC* pDC, CRect rcClipBox); /** * @brief * This method is called when the controls array is changed. */ virtual void OnControlsChanged(); /** * @brief * This method is called to recalculate the command bar layout. */ virtual void OnRecalcLayout(); /** * @brief * Call this member to retrieve the parent command bar. * @return * A pointer to a CXTPCommandBar object. */ CXTPCommandBar* GetParentCommandBar() const; /** * @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 * Call this method make 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); /** * @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. */ virtual BOOL OnHookKeyDown(UINT nChar, LPARAM lParam); /** * @brief * Updates rectangle to set the position where the child pop-up bar becomes visible. * @param rc CRect object specifying the size of the area. * @param bVertical TRUE if the control is located vertically in its parent. */ virtual void AdjustExcludeRect(CRect& rc, BOOL bVertical); public: /** * @brief * Sets the toolbar's borders. * @param rcBorders Borders of the toolbar. */ void SetBorders(CRect rcBorders); /** * @brief * Disables shadow use. */ void DisableShadow(); /** * @brief * Determines if the control can be resized by the user. * @return * TRUE if the control can be resized by the user, otherwise FALSE. */ BOOL IsResizable() const; /** * @brief * Call this method to get the border margins of the command bar. * @return * A CRect object containing the border margins. */ virtual CRect GetBorders(); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_MSG(CXTPPopupBar) afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); BOOL OnNcActivate(BOOL bActive); afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpCreateStruct); LRESULT OnFloatStatus(WPARAM wParam, LPARAM); //}}AFX_MSG /** @endcond */ protected: /** * @brief * Animates pop-up window */ virtual void Animate(); private: void AdjustScrolling(LPSIZE lpSize, BOOL bDown = FALSE, BOOL bInvalidate = FALSE); void TrackTearOff(); void TrackResize(); void RecalcSizeLayout(); void SwitchTearOffTracking(BOOL bShow, CPoint point); void _MakeSameWidth(int nStart, int nLast, int nWidth); BOOL _MouseInResizeGripper(const POINT& pt); XTPAnimationType GetAnimationType() const; public: static double m_dMaxWidthDivisor; /**< Maximum available width of pop-up. */ protected: CXTPControlPopup* m_pControlPopup; /**< Control that pop-up'ed the bar. */ CPoint m_ptPopup; /**< Position of the bar. */ CRect m_rcExclude; /**< Excluded area. */ DWORD m_popupFlags; /**< Flags of the bar. */ BOOL m_bDynamicLayout; /**< TRUE if DynamicLayout routine executed. */ BOOL m_bCollapsed; /**< TRUE if pop-up bar is collapsed. */ BOOL m_bExpanded; /**< TRUE if pop-up bar is expanded. */ BOOL m_bExpanding; /**< TRUE if pop-up bar is expanding. */ BOOL m_bTearOffPopup; /**< TRUE if pop-up bar has tear-off option. */ CRect m_rcTearOffGripper; /**< Tear-off gripper position. */ CRect m_rcResizeGripper; /**< Resizable gripper position. */ BOOL m_bResizable; /**< TRUE to allow resize */ BOOL m_bTearOffSelected; /**< TRUE if gripper selected. */ UINT_PTR m_nTearOffTimer; /**< Tear-off timer. */ BOOL m_bTearOffTracking; /**< Tear-off tracking mode. */ CSize m_szTearOffBar; /**< Size of the bar. */ CXTPToolBar* m_pTearOffBar; /**< Tear-off toolbar pointer. */ CString m_strTearOffCaption; /**< Caption of the Tear-off toolbar. */ UINT m_nTearOffID; /**< ID of the Tear-off toolbar. */ int m_nTearOffWidth; /**< Width of the Tear-off toolbar. */ BOOL m_bShowShadow; /**< TRUE to show the shadow. */ CRect m_rcBorders; /**< Borders of the bar. */ BOOL m_bDoubleGripper; /**< TRUE if pop-up is state pop-up type. */ BOOL m_bContextMenu; /**< TRUE if pop-up bar is context menu. */ int m_nMaxHeight; /**< Maximum height the pop-up bar can become. */ private: XTP_SCROLLINFO m_scrollInfo; # ifdef _XTP_COMMANDBARS_ACTIVEX DECLARE_DISPATCH_MAP() # endif private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); friend class CControlExpandButton; friend class CXTPControlPopup; friend class CXTPCommandBars; friend class CXTPCommandBar; friend class CXTPCommandBarsContextMenus; }; /** * @brief * CXTPPopupToolBar is a CXTPPopupBar derived class. */ class _XTP_EXT_CLASS CXTPPopupToolBar : public CXTPPopupBar { DECLARE_XTP_COMMANDBAR(CXTPPopupToolBar) /** * @brief * Constructs a CXTPPopupToolBar object. */ CXTPPopupToolBar(); public: /** * @brief * Creates a pop-up toolbar object. * @param pCommandBars Pointer to a CXTPCommandBars object. * @return * A pointer to a CXTPPopupToolBar object. */ static CXTPPopupToolBar* AFX_CDECL CreatePopupToolBar(CXTPCommandBars* pCommandBars); protected: /** * @brief * This method is called to get the size of the command bar. * @param nLength The requested dimension of the control bar, either * horizontal or vertical, depending on dwMode. * @param dwMode See CControlBar::CalcDynamicLayout for list of supported flags. * @return * Size of the command bar. */ CSize CalcDynamicLayout(int nLength, DWORD dwMode); }; ////////////////////////////////////////////////////////////////////////// AFX_INLINE void CXTPPopupBar::DisableShadow() { m_bShowShadow = FALSE; } AFX_INLINE void CXTPPopupBar::SetBorders(CRect rcBorders) { m_rcBorders = rcBorders; } AFX_INLINE BOOL CXTPPopupBar::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 CXTPPopupBar::IsDoubleGripper() const { return m_bDoubleGripper; } AFX_INLINE void CXTPPopupBar::SetDoubleGripper(BOOL bDoubleGripper /*= TRUE*/) { m_bDoubleGripper = bDoubleGripper; } AFX_INLINE CXTPControlPopup* CXTPPopupBar::GetControlPopup() const { return m_pControlPopup; } AFX_INLINE BOOL CXTPPopupBar::IsPopupBar() const { return TRUE; } AFX_INLINE BOOL CXTPPopupBar::IsContextMenu() const { return m_bContextMenu; } AFX_INLINE BOOL CXTPPopupBar::IsResizable() const { return m_bResizable; } AFX_INLINE void CXTPPopupBar::SetPopupFlags(DWORD dwPopupFlags) { m_popupFlags = dwPopupFlags; } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // #if !defined(__XTPPOPUPBAR_H__) /** @endcond */