/** * @file XTPColorDialog.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(__XTPCOLORDIALOG_H__) # define __XTPCOLORDIALOG_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * Creates an eye dropper control that can be used to select any color * that is displayed anywhere on the screen. To use the eye dropper control, * click and hold the left mouse button and move it over the screen. The * color that is currently under the cursor will be selected as the new color. */ class _XTP_EXT_CLASS CXTPEyeDropper : public CWnd { public: /** * @brief * Constructs a CXTPEyeDropper object. */ CXTPEyeDropper(); /** * @brief * Destroys a CXTPEyeDropper object, handles cleanup and deallocation. */ virtual ~CXTPEyeDropper(); /** @cond */ //{{AFX_VIRTUAL(CXTPEyeDropper) protected: virtual void PreSubclassWindow(); virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL /** @endcond */ public: /** * @brief * Call this member function to create an eye dropper control. * @param dwStyle Specifies the window style attributes. * @param rect The size and position of the window, in client coordinates * of pParentWnd. * @param pParentWnd The parent window. * @param nID The ID of the child window. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); /** * @brief * Call this member function to enable/disable setting the RGB color * value as text on the Windows clipboard. * @param bSetClipboard TRUE to enable setting the RGB color value * as text on the Windows clipboard. */ void SetClipboard(BOOL bSetClipboard); /** * @brief * Call this member function to enable/disable the display for the * color preview window. The color preview window is a rectangle that * is displayed to the right of the eye dropper that displays the * currently selected color. * @param bShowPreview TRUE to enable the display for the color preview window. */ void ShowPreview(BOOL bShowPreview); /** @cond */ virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); /** @endcond */ protected: int m_nPadding; /**< Size of the gap between the eye dropper and preview display. */ CSize m_icoSize; /**< Size of the preview icon. */ BOOL m_bPreInit; /**< TRUE when initializing from PreSubclassWindow. */ BOOL m_bSetClipboard; /**< TRUE to set the selected RGB color on the clipboard. */ BOOL m_bShowPreview; /**< TRUE to show color preview. */ HICON m_hIcon; /**< Handle to the eye dropper icon. */ HCURSOR m_hCurEyeDropper; /**< Handle to the eye dropper cursor. */ HCURSOR m_hCurPrevious; /**< Handle to the previous cursor. */ COLORREF m_color; /**< Selected RGB color value. */ /** * @brief * This member function is called by the CXTPEyeDropper class to * perform initialization when the window is created or sub-classed. * @return * TRUE if the window was successfully initialized, otherwise FALSE. */ virtual BOOL Init(); /** * @brief * Used by the eye dropper control to draw the eye dropper box. * @param pDC Pointer to a valid device context for the eye dropper window. */ virtual void DrawDropper(CDC* pDC); /** * @brief * Used by the eye dropper control to draw the color preview box. * @param pDC Pointer to a valid device context for the eye dropper window. */ virtual void DrawColor(CDC* pDC); /** * @brief * Used by the eye dropper control to place RGB color values as text * on the Windows clipboard. * @param lpszClipText A NULL-terminated string representing the current * RGB color value. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetClipboardText(LPCTSTR lpszClipText); /** * @brief * Used by the eye dropper control to determine the rectangle for * drawing the color preview box. * @return * A CRect object indicating the size in client coordinates. */ CRect GetColorRect(); /** * @brief * Used by the eye dropper control to determine the rectangle for * drawing the eye dropper box. * @return * A CRect object indicating the size in client coordinates. */ CRect GetDropperRect(); /** @cond */ //{{AFX_MSG(CXTPEyeDropper) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnPaint(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP() /** @endcond */ }; /** * @brief * CXTPColorDialog is a CPropertySheet derived class. * It is an Office(tm) style color dialog and can be used * as a drop in replacement for the MFC CColorDialog API. */ class _XTP_EXT_CLASS CXTPColorDialog : public CPropertySheet { /** @cond */ DECLARE_DYNAMIC(CXTPColorDialog) /** @endcond */ public: /** * @brief * Constructs a CXTPColorDialog object * @param clrNew An RGB value that represents the new color selection. * @param clrCurrent An RGB value that represents the default color selection. * @param dwFlags Style for color dialog. * See the Remarks section for available styles. * @param pWndParent A pointer to the dialog box's parent or owner window. * @details * Styles to be added or removed can be combined by using the bitwise * OR (|) operator. It can be one or more of the following: * CPS_XTP_SHOW3DSELECTION: Displays the color selection * box with a 3D raised border. * CPS_XTP_SHOWHEXVALUE: Displays the hex equivalent of the * selected color. * @see * CXTPColorPopup::Create, CXTPColorSelectorCtrl::Create, * CXTPColorPicker::ModifyCPStyle */ CXTPColorDialog(COLORREF clrNew, COLORREF clrCurrent, DWORD dwFlags = 0L, CWnd* pWndParent = NULL); /** * @brief * Destroys a CXTPColorDialog object, handles cleanup and deallocation. */ virtual ~CXTPColorDialog(); public: /** * @brief * Sets the active color for the dialog. * @param clr An RGB value that represents the color. * @param bNotify TRUE to notify tab pages of a color change. * * @details * Call this member function to set the current color selection to * the color value specified in 'clr'. The dialog box will * automatically update the user's selection based on the value of * the 'clr' parameter. */ void SetNewColor(COLORREF clr, BOOL bNotify = TRUE); /** * @brief * Call this function to set the new color selection to the color * value specified in 'clr'. * @param clr An RGB value that represents the color. */ void SetCurrentColor(COLORREF clr); /** * @brief * Call this member function to retrieve the RGB information for the * current color. * @return * A COLORREF value that contains the RGB information for the * current color specified when the dialog was instantiated. */ COLORREF GetCurrentColor(); /** * @brief * Call this member function to retrieve the RGB information for the * color that the user selected. * @return * A COLORREF value that contains the RGB information for the * new color selected in the color dialog box. */ COLORREF GetColor(); /** * @brief * Call this member function to copy the string specified by * 'strText' to the Windows clipboard. * @param strText A NULL-terminated string. * @return * TRUE if successful, otherwise FALSE. */ BOOL CopyToClipboard(const CString& strText); /** * @brief * This member function returns a CString object that represents the * HEX conversion for the specified RGB color. * @param clr An RGB value that represents the color. * @return * A CString object. */ static CString AFX_CDECL RGBtoHex(COLORREF clr); /** * @brief * Calculates the size of the dialog's tab control. * @details * This function is used to calculate the size of the dialog's tab * control, the first tab item, the size of the OK button, and the size * of the cancel button. Then, resize the tab control to fit on the * dialog. Also, reposition the OK and Cancel buttons. Next, reposition * the Hex-Display. Finally, resize the property sheet. */ virtual void CalculateRects(); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPColorDialog) virtual BOOL OnInitDialog(); void AddPage(CPropertyPage* pPage); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPColorDialog) afx_msg void OnPaint(); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg LRESULT OnEyeDropperMoving(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnEyeDropperSelect(WPARAM wParam, LPARAM lParam); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG /** @endcond */ protected: DWORD m_dwStyle; /**< Styles for the dialog. */ CEdit m_wndHexEdit; /**< Edit window to display the color hex value. */ CXTPEyeDropper m_wndEyeDropper; /**< Eye dropper control. */ CRect m_rcNew; /**< Size of the rectangle that represents the new color. */ CRect m_rcCurrent; /**< Size of the rectangle that represents the current color. */ COLORREF m_clrNew; /**< A COLORREF value that contains the RGB information for the new color. */ COLORREF m_clrCurrent; /**< A COLORREF value that contains the RGB information for the current color. */ private: int m_nTextHeight; int m_nGapSize; }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE COLORREF CXTPColorDialog::GetCurrentColor() { return m_clrCurrent; } AFX_INLINE COLORREF CXTPColorDialog::GetColor() { return m_clrNew; } AFX_INLINE void CXTPEyeDropper::SetClipboard(BOOL bSetClipboard) { m_bSetClipboard = bSetClipboard; } AFX_INLINE void CXTPEyeDropper::ShowPreview(BOOL bShowPreview) { m_bShowPreview = bShowPreview; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPCOLORDIALOG_H__) /** @endcond */