/** * @file XTPPopupControl.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(_XTPPOPUPCONTROL_H__) # define _XTPPOPUPCONTROL_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPPopupItem; class CXTPPopupPaintManager; class CXTPImageManager; class CXTPImageManagerIcon; class CXTPMarkupContext; /** * @brief * Enumeration used to determine the pop-up window theme in use. * Example: *
m_wndPopupControl.SetTheme(xtpPopupThemeOffice2000);* @see * CXTPPopupControl::SetTheme, CXTPPopupControl::GetTheme * @see xtpPopupThemeOffice2000, xtpPopupThemeOfficeXP, xtpPopupThemeOffice2003, * xtpPopupThemeMSN, xtpPopupThemeCustom, xtpPopupThemeOffice2013, xtpPopupThemeOffice2016> */ enum XTPPopupPaintTheme { xtpPopupThemeOffice2000, /**< Office 2000 pop-up theme. */ xtpPopupThemeOfficeXP, /**< Office XP pop-up theme. */ xtpPopupThemeOffice2003, /**< Office 2003 pop-up theme. */ xtpPopupThemeMSN, /**< MSN Messenger pop-up theme. */ xtpPopupThemeResource, /**< A resource based theme. */ xtpPopupThemeCustom, /**< Custom pop-up theme. */ xtpPopupThemeOffice2013, /**< Office 2013 pop-up theme. */ xtpPopupThemeOffice2016 = xtpPopupThemeOffice2013 /**< Office 2016 pop-up theme. */ }; /** @cond */ # define xtpPopupThemeOffice2007 xtpPopupThemeResource /** @endcond */ /** * @brief * Enumeration used to determine the location where the pop-up control is displayed. */ enum XTPPopupLocation { xtpPopupLocationNearTaskBar, /**< Displays in the bottom right of the screen right above the taskbar. */ xtpPopupLocationBottomRight, /**< Displays in the bottom right of the screen. */ xtpPopupLocationCenter /**< Displays in the center of the screen. */ }; /** * @brief * Enumeration used to determine the pop-up window animation in use. * Example: *
m_wndPopupControl.SetPopupAnimation(xtpPopupAnimationFade);* @see * CXTPPopupControl::SetPopupAnimation, CXTPPopupControl::GetPopupAnimation * @see xtpPopupAnimationNone, xtpPopupAnimationFade, xtpPopupAnimationSlide, * xtpPopupAnimationUnfold> */ enum XTPPopupAnimation { xtpPopupAnimationNone, /**< Animation is not used. */ xtpPopupAnimationFade, /**< Fade method animation. */ xtpPopupAnimationSlide, /**< Slide method animation. */ xtpPopupAnimationUnfold /**< Unfold method animation. */ }; /** * @brief * Enumeration used to determine the current pop-up window state. * Example: *
* if (pControl->GetPopupState() == xtpPopupStateClosed)
* {
* EnableItems(TRUE);
* }
*
* @see
* CXTPPopupControl::GetPopupState, CXTPPopupControl::SetPopupState
*
* @see xtpPopupStateClosed, xtpPopupStateExpanding, xtpPopupStateShow,
* xtpPopupStateCollapsing>
*/
enum XTPPopupState
{
xtpPopupStateClosed, /**< The pop-up window is closed. */
xtpPopupStateExpanding, /**< The pop-up window is expanding. */
xtpPopupStateShow, /**< The pop-up window is shown. */
xtpPopupStateCollapsing /**< The pop-up window is collapsing. */
};
/**
* @brief
* The XTPWM_POPUPCONTROL_NOTIFY message is sent to the CXTPPopupControl
* owner window whenever an action occurs within the CXTPPopupControl.
* @param nAction Value of wParam specifies a pop-up control value that
* indicates the user's request. Can be any of the values
* listed in the Remarks section.
* @details
* nAction parameter can be one of the following:
* XTP_PCN_ITEMCLICK: Indicates that the user clicked on the
* pop-up control item.
* XTP_PCN_STATECHANGED: Indicates that the state of the
* control changed.
* @return
* If the application is to process this message, then the return value should be TRUE.
* Otherwise, the return value is FALSE.
* Example:
* Here is an example of how an application would process the XTPWM_POPUPCONTROL_NOTIFY
* message:
*
*
* BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
* //{{AFX_MSG_MAP(CMainFrame)
* ON_MESSAGE(XTPWM_POPUPCONTROL_NOTIFY, OnPopUpNotify)
* //}}AFX_MSG_MAP
* END_MESSAGE_MAP()
*
* LRESULT CMainFrame::OnPopUpNotify(WPARAM wParam, LPARAM lParam)
* {
* if (wParam == XTP_PCN_ITEMCLICK)
* {
* CXTPPopupItem* pItem = (CXTPPopupItem*)lParam;
* _ASSERTE(pItem);
*
* m_wndPopupControl.Close();
*
* if (pItem->GetID() == ID_GOTO_SITE)
* {
* ShellExecute(NULL, _T("open"), _T("http://www.codejock.com/"), NULL, NULL,
* SW_SHOW);
* }
* }
* else if (wParam == XTP_PCN_STATECHANGED)
* {
* CXTPPopupControl* pControl = (CXTPPopupControl*)lParam;
* _ASSERTE(pControl);
*
* if (pControl->GetPopupState() == xtpPopupStateClosed)
* {
* EnableItems(TRUE);
* }
* }
* return TRUE;
* }
*
* @see
* XTP_PCN_ITEMCLICK, XTP_PCN_STATECHANGED, CXTPPopupControl
*/
const UINT XTPWM_POPUPCONTROL_NOTIFY = (WM_XTP_CONTROLS_BASE + 37);
/**
* @brief
* XTP_PCN_ITEMCLICK is used to indicate that the user clicked on a
* pop-up control item.
* @details
* XTP_PCN_ITEMCLICK is sent in the XTPWM_POPUPCONTROL_NOTIFY message to
* the owner window when the user has clicked on a pop-up control item.
* Example:
* See example of XTPWM_POPUPCONTROL_NOTIFY.
* @see
* XTPWM_POPUPCONTROL_NOTIFY, XTP_PCN_STATECHANGED
*/
const UINT XTP_PCN_ITEMCLICK = 1;
/**
* @brief
* XTP_PCN_STATECHANGED is used to indicate that the state of the
* pop-up control has changed.
* @details
* XTP_PCN_STATECHANGED is sent in the XTPWM_POPUPCONTROL_NOTIFY message
* to the owner window when the state of the pop-up control has changed.
* It can be one of the following states:
* xtpPopupStateClosed: Indicates that the pop-up window is closed.
* xtpPopupStateExpanding: Indicates that the pop-up window is expanding.
* xtpPopupStateShow: Indicates that the pop-up window is shown.
* xtpPopupStateCollapsing: Indicates that the pop-up window is collapsing.
* Example:
* See example of XTPWM_POPUPCONTROL_NOTIFY.
* @see
* XTPWM_POPUPCONTROL_NOTIFY, XTP_PCN_ITEMCLICK
*/
const UINT XTP_PCN_STATECHANGED = 2;
/**
* @brief
* XTP_PCN_POSCHANGED is used to indicate that the user moved the
* pop-up control with the mouse.
* @see
* XTPWM_POPUPCONTROL_NOTIFY
*/
const UINT XTP_PCN_POSCHANGED = 3;
/**
* @brief
* CXTPPopupControl is a class for control of a pop-up window.
*/
class _XTP_EXT_CLASS CXTPPopupControl : public CWnd
{
protected:
/**
* @brief
* Pop-up state descriptor.
* @see
* CXTPPopupControl::m_stateTarget, CXTPPopupControl::m_stateCurrent
*/
struct POPUPSTATE
{
CRect rcPopup; /**< Pop-up position. */
int nTransparency; /**< Pop-up transparency. */
};
public:
/**
* @brief
* Constructs a CXTPPopupControl object.
* @param bAutoDelete If TRUE, then the object will be deleted automatically
* upon final release.
*/
CXTPPopupControl(BOOL bAutoDelete = FALSE);
/**
* @brief
* Destroys a CXTPPopupControl object, handles cleanup and
* deallocation.
*/
virtual ~CXTPPopupControl();
public:
/**
* @brief
* Call this member function to set the position of a pop-up window.
* @param ptPopup A CPoint object containing an XY location.
*/
void SetPopupPos(CPoint ptPopup);
/**
* @brief
* Call this member function to get the position of a pop-up window.
* @return
* A CPoint object containing an XY location.
*/
CPoint GetPopupPos() const;
/**
* @brief
* Call this member function to set the size of a pop-up window.
* @param szPopup A CSize object containing an XY size.
*/
void SetPopupSize(CSize szPopup);
/**
* @brief
* Call this member function to get the size of a pop-up window.
* @return
* A CSize object containing an XY size.
*/
CSize GetPopupSize() const;
/**
* @brief
* Call this member function to create and expand a pop-up window.
* @param pParent Pointer to a CWnd object that represents the parent
* window.
* @param nID ID for the pop-up window.
* @return
* TRUE if successful, otherwise FALSE.
*/
BOOL Show(CWnd* pParent, int nID = 0);
/**
* @brief
* Call this method to show a modal pop-up control.
* @param pParent Pointer to a CWnd object that represents the parent
* window.
* @param nID ID for pop-up window.
* @return
* TRUE if successful, otherwise FALSE.
*/
BOOL ShowModal(CWnd* pParent, int nID = 0);
/**
* @brief
* Call this member function to collapse a pop-up window.
*/
void Hide();
/**
* @brief
* Call this member to destroy a pop-up window.
* @return
* TRUE if successful, otherwise FALSE.
*/
BOOL Close();
/**
* @brief
* Call this member function to set the transparency value of a
* pop-up window.
* @param bTransp Value of transparency (0...255).
* If bTransp = 0, then the pop-up window is fully transparent,
* if bTransp = 255, then the pop-up window is fully opaque.
*/
void SetTransparency(BYTE bTransp);
/**
* @brief
* Call this member function to get the transparency value of a
* pop-up window.
* @return
* Transparency value of a pop-up window.
*/
BYTE GetTransparency() const;
/**
* @brief
* Call this member function to set the show delay value for a
* pop-up window.
* @param dwShowDelay Show delay value in milliseconds.
*/
void SetShowDelay(DWORD dwShowDelay);
/**
* @brief
* Call this member function to get the show delay value for a
* pop-up window.
* @return
* Show delay value in milliseconds.
*/
DWORD GetShowDelay() const;
/**
* @brief
* Call this member function to set the animate delay value for a
* pop-up window.
* @param dwAnimateDelay Animate delay value in milliseconds.
*/
void SetAnimateDelay(DWORD dwAnimateDelay);
/**
* @brief
* Call this member function to get the animate delay value for a
* pop-up window.
* @return
* Animate delay value in milliseconds.
*/
DWORD GetAnimateDelay() const;
/**
* @brief
* Call this member function to set the pop-up animation method.
* @param popupAnimation Method to use. See XTPPopupAnimation enum.
*/
void SetPopupAnimation(XTPPopupAnimation popupAnimation);
/**
* @brief
* Call this member function to set the default pop-up animation method.
*/
void SetPopupAnimation();
/**
* @brief
* Call this member function to get the pop-up animation method.
* @return
* Method in use. See XTPPopupAnimation enum.
*/
XTPPopupAnimation GetPopupAnimation() const;
/**
* @brief
* Call this member function to get the current state of a
* pop-up window.
* @return
* Current state. See XTPPopupState enum.
*/
XTPPopupState GetPopupState() const;
/**
* @brief
* Call this member function to set the paint theme or paint manager
* used for drawing a pop-up window.
* @param theme Paint theme to use. See XTPPopupPaintTheme enum.
*/
void SetTheme(XTPPopupPaintTheme theme);
/**
* @brief
* Call this member function to set the paint theme or paint manager
* used for drawing a pop-up window.
* @param pPaintManager Pointer to the paint manager object to use.
*/
void SetTheme(CXTPPopupPaintManager* pPaintManager);
/**
* @brief
* Call this member function to get the paint manager object
* used for drawing a pop-up window.
* @return
* Pointer to the paint manager object.
*/
CXTPPopupPaintManager* GetPaintManager() const;
/**
* @brief
* Call this member function to get the paint theme that the
* pop-up window is currently using.
* @return
* The paint theme that the pop-up window is currently using.
* @see
* SetTheme, XTPPopupPaintTheme
*/
XTPPopupPaintTheme GetTheme() const;
/**
* @brief
* Call this member function to redraw all controlled items of a
* pop-up window.
*/
void RedrawControl();
/**
* @brief
* Call this member function to install a new controlled item in
* a pop-up window.
* @param pItem Pointer to a CXTPPopupItem object which will be installed
* in a pop-up window.
* @return
* Pointer to the installed CXTPPopupItem object.
*/
CXTPPopupItem* AddItem(CXTPPopupItem* pItem);
/**
* @brief
* Call this member function to remove all controlled items from
* a pop-up window.
*/
void RemoveAllItems();
/**
* @brief
* Call this member function to remove a controlled item from
* a pop-up window.
* @param pItem Pointer to the CXTPPopupItem object which will be removed.
*/
void RemoveItem(CXTPPopupItem* pItem);
/**
* @brief
* Call this member function to remove a controlled item from
* a pop-up window.
* @param nIndex Index of the CXTPPopupItem object to remove from the control.
*/
void RemoveItem(int nIndex);
/**
* @brief
* Call this member function to get the count of controlled items in
* a pop-up window.
* @return
* Count of controlled items.
*/
int GetItemCount() const;
/**
* @brief
* Call this member function to get the controlled item at a
* specified index.
* @param nIndex Index of the controlled item.
* @return
* Pointer to a CXTPPopupItem object.
*/
CXTPPopupItem* GetItem(int nIndex) const;
/**
* @brief
* Call this member function to test a point for controlled items
* of a pop-up window.
* @param pt A CPoint object containing an XY location to test.
* @return
* Pointer to a CXTPPopupItem object if the test is successful,
* otherwise NULL.
*/
CXTPPopupItem* HitTest(CPoint pt) const;
/**
* @brief
* Call this member to specify whether the user can click and drag
* the pop-up window when it is displayed.
* @param bAllowMove TRUE to allow the user to click and drag the pop-up
* window anywhere on the screen. FALSE to prevent the
* pop-up window from being moved by the user.
*/
void AllowMove(BOOL bAllowMove);
/**
* @brief
* Call this member to set the bitmap index for the background.
* @param nBackgroundBitmap The bitmap index for the background.
*/
void SetBackgroundBitmap(int nBackgroundBitmap);
/**
* @brief
* Call this member to get the bitmap index for the background.
* @return
* The bitmap index for the background.
* @see
* SetBackgroundBitmap
*/
int GetBackgroundBitmap() const;
/**
* @brief
* Call this member to allow the pop-up control to delete itself
* automatically upon final release.
* @param bAutoDelete If TRUE, then the object will be deleted automatically
* upon final release.
*/
void SetAutoDelete(BOOL bAutoDelete);
/**
* @brief
* Call this member to set the default pop-up location.
* @param nPopupLocation Default Popup Location (Near TaskBar, BottomLeft or Center).
* @see
* SetPopupPos
*/
void SetDefaultLocation(XTPPopupLocation nPopupLocation);
/**
* @brief
* Call this member to see if splash screen mode has been enabled.
* @return
* TRUE if splash screen mode has been enabled.
*/
BOOL GetSplashScreenMode() const;
/**
* @brief
* Call this member to set splash screen mode.
* @param bSet TRUE to enable splash screen mode.
*/
void SetSplashScreenMode(BOOL bSet);
/**
* @brief
* Retrieves the ID assigned to the pop-up window when it was created.
* @return
* An integer value representing the pop-up window ID.
*/
int GetID() const;
/**
* @brief
* Determines if right-to-left (RTL) mode is set.
* @return
* TRUE if text is displayed using right-to-left (RTL)
* reading-order properties.
*/
BOOL IsLayoutRTL() const;
/**
* @brief
* Specifies if right-to-left (RTL) mode should be set.
* @param bRightToLeft TRUE to display text using right-to-left (RTL)
* reading-order properties.
*/
void SetLayoutRTL(BOOL bRightToLeft);
/**
* @brief
* Call this method to set a new image manager.
* @param pImageManager A pointer to the CXTPImageManager object to be set.
* Example:
* * CXTPImageManager* pImageManager = new CXTPImageManager(); * pImageManager->SetIcons(IDR_MAINFRAME); * m_wndPopupControl.SetImageManager(pImageManager); ** @see * GetImageManager */ void SetImageManager(CXTPImageManager* pImageManager); /** * @brief * Call this method to get a pointer to the image manager of the pop-up * control. * @return * A pointer to the image manager of the pop-up control. * @details * The image manager is used to hold all of the icons displayed in the * pop-up control. * @see * SetImageManager */ CXTPImageManager* GetImageManager() const; /** * @brief * Call this method to enable markup for the pop-up control. * @param bEnableMarkup TRUE to enable markup. */ void EnableMarkup(BOOL bEnableMarkup); /** * @brief * Retrieves the markup context associated with the pop-up control. * @return * A pointer to a CXTPMarkupContext object. */ CXTPMarkupContext* GetMarkupContext() const; /** * @brief * Gets DPI bitmap scaling flag. If set, all raster icons and bitmaps * used in the control will be stretched automatically if DPI scaling * factor for control's window isn't equal to 100%. The default value is * derived from CXTPDpi::IsDpiBitmapScalingEnabled. Once changed the new value * will be used. * @return * The current value of the DPI bitmap scaling flag for the control. */ BOOL IsDpiBitmapScalingEnabled() const; /** * @brief * Sets DPI bitmap scaling flag. If set, all raster icons and bitmaps * used in the control will be stretched automatically if DPI scaling * factor for control's window isn't equal to 100%. The default value is * derived from CXTPDpi::IsDpiBitmapScalingEnabled. Once changed the new value * will be used. * @param bEnable TRUE to enable bitmaps scaling, FALSE to disable. */ void EnableDpiBitmapScaling(BOOL bEnable = TRUE); protected: /** * @brief * Creates a pop-up window. * @param pParentWnd Pointer to the parent window. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(CWnd* pParentWnd); /** * @brief * This method is called when the user clicks on a controlled item. * @param pItem A pointer to the item that was clicked. */ virtual void OnClick(CXTPPopupItem* pItem); /** * @brief * This method is called to start the expanding animation. * @param bUpdateCurrent TRUE to update the current state. */ virtual void OnExpanding(BOOL bUpdateCurrent); /** * @brief * This method is called to start the collapsing animation. */ virtual void OnCollapsing(); /** * @brief * This method is called to show the control. */ virtual void OnShow(); /** * @brief * This method is called to notify the parent about an action that * occurred. * @param wParam The action that occurred. * @param lParam Extended parameter. */ virtual void Notify(WPARAM wParam, LPARAM lParam); /** * @brief * This method animates the pop-up control. * @param nStep Current step of the animation. */ void Animate(int nStep); /** * @brief * Updates the position in the animation according to the current * animation step. * @param bInit Initial step of the animation. */ void UpdateState(BOOL bInit = FALSE); /** * @brief * This method is called when the current state of the control * changes. * @param popupState Current state of the control. */ void SetPopupState(XTPPopupState popupState); /** * @brief * Updates the current control's transparency. * @param bAlpha Current alpha level of the window. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetLayeredWindowAttributes(int bAlpha); /** * @brief * Loop of control moving. */ void TrackMove(); protected: /** @cond */ DECLARE_MESSAGE_MAP() virtual void PostNcDestroy(); virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult); //{{AFX_MSG(CXTPPopupControl) afx_msg void OnTimer(UINT_PTR nIDEvent); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnCaptureChanged(CWnd* pWnd); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnMouseLeave(); afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); //}}AFX_MSG /** @endcond */ private: BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); void UpdateBitmapRegion(); HRGN BitmapToRegion(CXTPImageManagerIcon* pIcon); void SetRegionAlphaLayer(CXTPImageManagerIcon* pIcon); protected: CXTPPopupPaintManager* m_pPaintManager; /**< Pointer to CXTPPopupPaintManager object. */ CArray