/** * @file XTPControlGallery.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(__XTPCONTROLGALLERY_H__) # define __XTPCONTROLGALLERY_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPControlGalleryItems; class CXTPControlGallery; class CXTPControlGalleryPaintManager; class CXTPImageManagerIcon; class CXTPMarkupUIElement; class CXTPMarkupContext; const UINT XTP_GN_PREVIEWSTART = 0x1010; /**< Gallery Notification - Occurs when the gallery preview is started.*/ const UINT XTP_GN_PREVIEWCANCEL = 0x1011; /**< Gallery Notification - Occurs when the gallery preview is canceled.*/ const UINT XTP_GN_PREVIEWAPPLY = 0x1012; /**< Gallery Notification - Occurs when the gallery preview is applied.*/ const UINT XTP_GN_PREVIEWCHANGE = 0x1013; /**< Gallery Notification - Occurs when the gallery preview is changed.*/ const UINT XTP_GN_STARTDRAG = 0x1014; /**< Gallery Notification - Occurs when an item is dragged in the gallery.*/ const UINT XTP_GN_SELCHANGE = 0x1015; /**< Gallery Notification - Occurs when the gallery selection has changed.*/ class CXTPControlGalleryItem; /** * @brief * CXTPControlGallery is a CXTPControlPopup derived class. * It represents a gallery control toolbar. */ class _XTP_EXT_CLASS CXTPControlGallery : public CXTPControlPopup , public CXTPScrollBase { /** @cond */ DECLARE_XTP_CONTROL(CXTPControlGallery) /** @endcond */ public: /** * @brief * Structure contains item position description. */ struct GALLERYITEM_POSITION { RECT rcItem; /**< Bounding rectangle of the item. */ CXTPControlGalleryItem* pItem; /**< Item pointer. */ BOOL bBeginRow; /**< TRUE if the item starts a new row. */ }; public: /** * @brief * Constructs a CXTPControlGallery object. */ CXTPControlGallery(); /** * @brief * Destroys a CXTPControlGallery object, handles cleanup and deallocation. */ ~CXTPControlGallery(); public: /** * @brief * Call this method to set items for the gallery. * @param pItems Pointer to items to be set. */ void SetItems(CXTPControlGalleryItems* pItems); /** * @brief * Call this method to set margins around items. * @param nLeft Left margin to be set. * @param nTop Top margin to be set. * @param nRight nRight margin to be set. * @param nBottom Bottom margin to be set. */ void SetItemsMargin(int nLeft, int nTop, int nRight, int nBottom); /** * @brief * Call this method to set the size of the control. * @param szControl New control size to be set. */ void SetControlSize(CSize szControl); /** * @brief * Call this method to the set size of the control depending on the * number of rows, columns, current item size and current DPI. * @param nColumns Number of columns. * @param nRows Number of rows. * @param szItem Default item size. */ void SetControlSize(int nColumns, int nRows, CSize szItem); public: /** * @brief * Call this method to get the count of items in the gallery. * @return * Count of items in the gallery. * @see * SetItems, GetItem */ int GetItemCount() const; /** * @brief * Call this method to retrieve an item by its index. * @param nIndex Index of the item to be retrieved. * @return * If successful, item at the specified index. Otherwise, NULL. * @see * SetItems, GetItemCount */ CXTPControlGalleryItem* GetItem(int nIndex) const; /** * @brief * Call this method to get items associated with the gallery. * @return Returns items associated with the gallery * @see * SetItems */ virtual CXTPControlGalleryItems* GetItems() const; /** * @brief * Call this method to set the selected item in the gallery. * @param nSelected Item to set as selected. * @see * GetSelectedItem */ void SetSelectedItem(int nSelected); /** * @brief * Call this method to get the selected item in the gallery. * @return * The selected item in the gallery. * @see * SetSelectedItem */ int GetSelectedItem() const; /** * @brief * Call this method to set the checked item identifier for the gallery. * @param nId Item ID. * @see * GetCheckedItem */ void SetCheckedItem(int nId); /** * @brief * Call this method to determine if an item is checked. * @param pItem Item to test. * @return * TRUE if the specified item is checked, otherwise FALSE. * @see * SetCheckedItem */ virtual BOOL IsItemChecked(CXTPControlGalleryItem* pItem) const; /** * @brief * Call this method to get the checked item identifier for the gallery. * @return * Checked item's identifier. * @see * SetCheckedItem */ int GetCheckedItem() const; /** * @brief * Determines if any item in the gallery is selected. * @return * TRUE if any item is selected, otherwise FALSE. * @see * GetSelectedItem */ BOOL IsItemSelected() const; public: static BOOL m_bAutoScaleDpi; /**< TRUE by default. Enables scaling of ribbon gallery items (both inline and displayed in pop-up). */ public: /** * @brief * Call this method to show/hide borders around the gallery. * @param bShowBorders TRUE to show borders around the gallery. * @see * IsShowBorders */ void ShowBorders(BOOL bShowBorders); /** * @brief * Call this method to determine if borders are visible around the gallery. * @return * TRUE if borders are visible, otherwise FALSE. * @see * ShowBorders */ BOOL IsShowBorders() const; /** * @brief * Call this method to show/hide labels for the gallery. * @param bShowLabels TRUE to show labels for the gallery. */ void ShowLabels(BOOL bShowLabels); /** * @brief * Call this method to show/hide the scrollbar for the gallery. * @param bShowScrollBar TRUE to show the scrollbar for the gallery. * @see * IsScrollBarVisible */ void ShowScrollBar(BOOL bShowScrollBar); /** * @brief * Call this method to check if the scrollbar for the gallery is visible. * @return * TRUE if the scrollbar is visible, otherwise FALSE. * @see * ShowScrollBar */ BOOL IsScrollBarVisible() const; /** * @brief * Call this method to automatically show/hide the scrollbar for the gallery. * @param bScrollBarAuto TRUE to show the scrollbar automatically. */ void SetScrollBarAuto(BOOL bScrollBarAuto); /** * @brief * Determines if the scrollbar for the gallery is automatically shown/hidden. * @return * TRUE if the scrollbar is automatically shown. */ BOOL IsScrollBarAuto() const; public: /** * @brief * Call this method to get the border margins for the gallery. * @return * A CRect object containing the border margins for the gallery. */ virtual CRect GetBorders() const; /** * @brief * Determines the bounding rectangle of the item. * @param nIndex Item index. * @return * Bounding rectangle of the item. */ CRect GetItemDrawRect(int nIndex); /** * @brief * This method determines where a point lies in a specified item. * @param point Specifies the point to be tested. * @param lpRect Retrieves rectangle where item is located. Can be NULL. * @return * An index of CXTPControlGalleryItem that occupies the specified * point or NULL if no control occupies the point. */ int HitTestItem(CPoint point, LPRECT lpRect = NULL) const; /** * @brief * Determines the bounding rectangle of the items. * @return * Bounding rectangle of the items. */ CRect GetItemsRect() const; /** * @brief * Call this method to redraw items. * @param lpRect Rectangle to redraw. * @param bAnimate TRUE to animate changes. */ void InvalidateItems(LPCRECT lpRect = NULL, BOOL bAnimate = TRUE); /** * @brief * Retrieves CXTPControlGalleryPaintManager pointer to draw gallery. * @return * Pointer to a CXTPControlGalleryPaintManager object. */ CXTPControlGalleryPaintManager* GetGalleryPaintManager() const; /** * @brief * Retrieves CXTPScrollBarPaintManager pointer to draw ScrollBar. * @return * Pointer to a CXTPScrollBarPaintManager object. */ CXTPScrollBarPaintManager* GetScrollBarPaintManager() const; /** * @brief * Call this member to ensure that a specified item is visible in the gallery. * This will scroll the gallery until the specified item is visible. * @param nIndex Index of the item whose visibility must be ensured. */ void EnsureVisible(int nIndex); /** * @brief * Call this method to set the scrollbar position for the gallery. * @param nScrollPos New scrollbar position to be set. * @see * GetScrollPos */ void SetScrollPos(int nScrollPos); /** * @brief * Call this method to get the scrollbar position for the gallery. * @return * The scrollbar position. * @see * SetScrollPos */ int GetScrollPos() const; /** * @brief * Call this method to scroll gallery to the specified top item. * @param nIndex Item to be scrolled to. * @return * If successful, a value of 0 will be returned. * If an error occurs, a value of -1 will be returned. * @see * SetScrollPos */ int SetTopIndex(int nIndex); /** * @brief * Call this method to allow the user to resize the gallery. * @param bResizeWidth Allow change width. * @param bResizeHeight Allow change height. * @see * IsResizable */ void SetResizable(BOOL bResizeWidth = TRUE, BOOL bResizeHeight = TRUE); /** * @brief * Call this method to check if the gallery can be resized by the user. * @return * TRUE if the gallery can be resized by the user, otherwise FALSE. * @see * SetResizable */ BOOL IsResizable() const; /** * @brief * This method is called when the selection is changed by the user. */ virtual void OnSelectedItemChanged(); public: /** * @brief * Call this function to check if the gallery has a bottom separator. * @return * TRUE if the gallery has a bottom separator, otherwise FALSE. */ BOOL HasBottomSeparator() const; /** * @brief * Call this method to get the index of the next focusable item. * @param nIndex Index to start. * @param nDirection Direction to find (+1 or -1). * @return * Index of the next focusable item. */ long GetNext(long nIndex, int nDirection) const; /** * @brief * Call this method to get the index of the next focusable item in the same row. * @param nIndex Index to start. * @param nDirection Direction to find (+1 or -1). * @return * Index of the next focusable item in the same row. */ long GetNextInRow(long nIndex, int nDirection) const; /** * @brief * Call this method to get the index of the next focusable item in the same column. * @param nIndex Index to start. * @param nDirection Direction to find (+1 or -1). * @return * Index of the next focusable item in the same column. */ long GetNextInColumn(long nIndex, int nDirection) const; /** * @brief * Call this method to get the index of the next focusable item in the same page. * @param nIndex Index to start. * @param nDirection Direction to find (+1 or -1). * @return * Index of the next focusable item in the same page. */ long GetNextInPage(long nIndex, int nDirection) const; /** * @brief * Call this method to search for an item. * @param nStartAfter Index to begin search. * @param lpszItem Item caption to find. * @param bExact TRUE to find whole caption or only part. * @return * If successful, the index of the search item will be returned. * If unsuccessful, a value of -1 will be returned. */ int FindItem(int nStartAfter, LPCTSTR lpszItem, BOOL bExact) const; /** * @brief * Call this method to get the caption of an item. * @param nIndex Index of the item. * @return * Caption of the item. */ CString GetItemCaption(int nIndex); /** * @brief * Determines if the scrollbar button is enabled. * @param ht HitTest of scrollbar button. * @return * TRUE if the scrollbar button is enabled. */ BOOL IsScrollButtonEnabled(int ht); /** * @brief * Call this member to check if the scrollbar is enabled. * @return * TRUE if the scrollbar is enabled, otherwise FALSE. */ BOOL IsScrollBarEnabled() const; /** * @brief * Determines if the gallery is shown as a button. * @return * TRUE if the gallery is shown as a button. */ BOOL IsShownAsButton() const; /** @cond */ _XTP_DEPRECATED_IN_FAVOR(IsShownAsButton) BOOL IsShowAsButton() const { return IsShownAsButton(); } /** @endcond */ /** * @brief * Call this method to hide the selection. */ void HideSelection(); void SetTransparent(BOOL bTransparent = TRUE); BOOL IsTransparent() const; protected: /** * @brief * This method is called to set the position of all items. */ void Reposition(); /** * @brief * This method is called to draw all items. * @param pDC Pointer to a device context to draw. */ void DrawItems(CDC* pDC); protected: /** * @brief * This method is called to copy the control. * @param pControl Pointer to a source CXTPControl object. * @param bRecursive TRUE to copy recursively. */ void Copy(CXTPControl* pControl, BOOL bRecursive = FALSE); /** * @brief * Either reads this object from or writes this object to an archive. * @param pPX A CXTPPropExchange object to serialize to or from. */ void DoPropExchange(CXTPPropExchange* pPX); /** * @brief * This method is called before recalculating the parent command * bar size to calculate the dimensions of the control. * @param dwMode Flags used to determine the height and width of the * dynamic command bar. */ void OnCalcDynamicSize(DWORD dwMode); /** @cond */ public: virtual void SetRect(CRect rcControl); virtual void OnItemsChanged(); BOOL OnHookMouseWheel(UINT nFlags, short zDelta, CPoint pt); protected: virtual CSize GetSize(CDC* pDC); virtual void Draw(CDC* pDC); virtual void OnMouseMove(CPoint point); virtual void OnClick(BOOL bKeyboard = FALSE, CPoint pt = CPoint(0, 0)); virtual void OnLButtonUp(CPoint point); virtual BOOL OnSetSelected(int bSelected); void DoScroll(int cmd, int pos); void GetScrollInfo(SCROLLINFO* pSI); void PerformMouseMove(CPoint point); void PerformMouseDown(CPoint point); void PerformMouseUp(CPoint point); virtual void FillControl(CDC* pDC, CRect rcControl); virtual void SetAction(CXTPControlAction* pAction); virtual int GetCustomizeMinWidth() const; virtual int GetCustomizeMinHeight() const; virtual BOOL IsCustomizeResizeAllow() const; protected: void DrawScrollBar(CDC* pDC); CRect GetScrollBarRect(); void CalcScrollBarInfo(LPRECT lprc, XTP_SCROLLBAR_POSINFO* pSBInfo, SCROLLINFO* pSI); BOOL IsFocused() const; BOOL OnHookKeyDown(UINT nChar, LPARAM lParam); virtual void OnScrollChanged(); virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const; void OnExecute(); BOOL OnSetPopup(BOOL bPopup); void OnMouseHover(); protected: CWnd* GetParentWindow() const; virtual void AdjustExcludeRect(CRect& rc, BOOL /*bVertical*/); virtual void RedrawScrollBar(); void DoAnimate(); void StartAnimation(int nScrollPos); void RepositionCore(); /** @endcond */ protected: /** @cond */ virtual HRESULT GetAccessibleChildCount(long* pcountChildren); virtual HRESULT GetAccessibleChild(VARIANT varChild, IDispatch** ppdispChild); virtual HRESULT GetAccessibleName(VARIANT varChild, BSTR* pszName); virtual HRESULT GetAccessibleRole(VARIANT varChild, VARIANT* pvarRole); virtual HRESULT AccessibleLocation(long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varChild); virtual HRESULT AccessibleHitTest(long xLeft, long yTop, VARIANT* pvarChild); virtual HRESULT GetAccessibleState(VARIANT varChild, VARIANT* pvarState); virtual HRESULT GetAccessibleDefaultAction(VARIANT varChild, BSTR* pszDefaultAction); virtual HRESULT AccessibleDoDefaultAction(VARIANT varChild); virtual HRESULT AccessibleSelect(long flagsSelect, VARIANT varChild); /** @endcond */ # ifdef _XTP_COMMANDBARS_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPControlGallery); void OleSetItems(LPDISPATCH lpDispatch); LPDISPATCH OleGetItems(); DECLARE_PROPERTY(SelectedItem, LPDISPATCH); DECLARE_PROPERTY(CheckedItem, int); /** @endcond */ # endif protected: int m_nChecked; /**< Checked ID. */ int m_nSelected; /**< Index of selected item. */ BOOL m_bHideSelection; /**< TRUE to hide selection. */ BOOL m_bPressed; /**< TRUE if item is pressed. */ CPoint m_ptPressed; /**< Position of pressed item. */ int m_nScrollPos; /**< Scroll position. */ int m_nScrollPosTarget; /**< Scroll position. */ double m_dAnimationStep; /**< Number of steps to complete animation. */ BOOL m_bKeyboardSelected; /**< TRUE if item was selected using keyboard. */ int m_nTotalHeight; /**< Total height of items. */ BOOL m_bShowLabels; /**< TRUE to show labels. */ BOOL m_bShowScrollBar; /**< TRUE to show scrollbars. */ BOOL m_bShowBorders; /**< TRUE to show borders. */ CRect m_rcMargin; /**< Margins of gallery items. */ BOOL m_bPreview; /**< TRUE if control is in preview mode. */ int m_nResizable; /**< TRUE if the pop-up galley is resizable, see XTPGalleryResizable. */ BOOL m_bScrollBarAuto; BOOL m_bTransparent; CArray m_arrRects; /**< bounding rectangles */ friend class CXTPControlGalleryItems; }; # define GETPARTSTATE3(ht, bEnabled) \ (!bEnabled ? 4 : nPressedHt == ht ? 3 : nHotHt == ht ? 2 : 0) # define IS_PART_SELECTED(nState) (nState == 2) # define IS_PART_PRESSED(nState) (nState == 3) # define IS_PART_ENABLED(nState) (nState != 4) /** * @brief * CXTPControlGalleryPaintManager is a standalone class used to draw * a CXTPControlGallery object. */ class _XTP_EXT_CLASS CXTPControlGalleryPaintManager : public CObject { DECLARE_DYNAMIC(CXTPControlGalleryPaintManager); public: /** * @brief * Constructs a CXTPControlGalleryPaintManager object. * @param pPaintManager PaintManager of command bars. */ CXTPControlGalleryPaintManager(CXTPPaintManager* pPaintManager); //----------------------------------------------------------------------- // Handles object destruction //----------------------------------------------------------------------- virtual ~CXTPControlGalleryPaintManager() { } public: /** * @brief * This method is called to draw a label control. * @param pDC Pointer to a device context. * @param pLabel Label item. * @param rc Bounding rectangle of the label. */ virtual void DrawLabel(CDC* pDC, CXTPControlGalleryItem* pLabel, CRect rc); /** * @brief * This method is called to draw the background of the gallery. * @param pDC Pointer to a device context. * @param rc Bounding rectangle of gallery object. * @param pGallery CXTPControlGallery object to draw. */ virtual void FillControl(CDC* pDC, CXTPControlGallery* pGallery, CRect rc); virtual void DrawItem(CDC* pDC, CRect rcItem, BOOL bEnabled, BOOL bSelected, BOOL bPressed, BOOL bChecked, CXTPControlGalleryItem* pGalleryItem, CXTPControlGallery* pGallery); virtual void DrawItemBack(CDC* pDC, CRect rcItem, BOOL bEnabled, BOOL bSelected, BOOL bPressed, BOOL bChecked, XTPBarType barType); virtual COLORREF GetItemTextColor(BOOL bEnabled, BOOL bSelected, BOOL bPressed, BOOL bChecked, XTPBarType barType); /** * @brief * This method is called to draw the scrollbar for an in-place gallery. * @param pDC Pointer to device context. * @param pGallery CXTPControlGallery object to draw. * @see * DrawScrollBar */ virtual void DrawPopupScrollBar(CDC* pDC, CXTPControlGallery* pGallery); /** * @brief * Recalculates gallery metrics. */ virtual void RefreshMetrics(); public: int m_cyPopupUp; /**< Height of up arrow of in-place scrollbar. */ int m_cyPopupDown; /**< Height of down arrow of in-place scrollbar. */ int m_cxPopup; /**< Width of arrows of in-place scrollbar. */ COLORREF m_clrBorder; CXTPPaintManager* m_pPaintManager; }; AFX_INLINE BOOL CXTPControlGallery::IsShowBorders() const { return m_bShowBorders; } AFX_INLINE void CXTPControlGallery::ShowLabels(BOOL bShowLabels) { m_bShowLabels = bShowLabels; } AFX_INLINE void CXTPControlGallery::ShowScrollBar(BOOL bShowScrollBar) { m_bShowScrollBar = bShowScrollBar; } AFX_INLINE void CXTPControlGallery::ShowBorders(BOOL bShowBorders) { m_bShowBorders = bShowBorders; } AFX_INLINE BOOL CXTPControlGallery::IsItemSelected() const { return !m_bHideSelection && GetSelectedItem() != -1; } AFX_INLINE BOOL CXTPControlGallery::IsResizable() const { return !IsShownAsButton() && GetItems() ? m_nResizable : FALSE; } /** @cond */ AFX_INLINE BOOL CXTPControlGallery::IsCustomizeResizeAllow() const { return IsResizable(); } /** @endcond */ AFX_INLINE void CXTPControlGallery::SetScrollBarAuto(BOOL bScrollBarAuto) { m_bScrollBarAuto = bScrollBarAuto; } AFX_INLINE BOOL CXTPControlGallery::IsScrollBarVisible() const { return m_bShowScrollBar; } AFX_INLINE BOOL CXTPControlGallery::IsScrollBarAuto() const { return m_bScrollBarAuto; } AFX_INLINE void CXTPControlGallery::SetTransparent(BOOL bTransparent) { m_bTransparent = bTransparent; } AFX_INLINE BOOL CXTPControlGallery::IsTransparent() const { return m_bTransparent; } /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // #if !defined(__XTPCONTROLGALLERY_H__) /** @endcond */