/** * @file XTPColorPageStandard.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(__XTPCOLORSTANDARD_H__) # define __XTPCOLORSTANDARD_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * CXTPColorHex is a CStatic derived class. It displays a color selection * grid used by CXTPColorPageStandard. */ class _XTP_EXT_CLASS CXTPColorHex : public CStatic { /** @cond */ DECLARE_DYNAMIC(CXTPColorHex) /** @endcond */ protected: /** * @brief * CRgnCell is a CRgn derived class used by the CXTPColorHex to create * individual color cells. */ class CRgnCell : public CRgn { public: /** * @brief * Contains pre-computed hexagon data for both small and big hexagons. */ struct CTX_DATA { /** * @brief * Describes pre-computed hexagon data. */ struct HEXAGON_DATA { float width; /**< Hexagon width */ float half; /**< Hexagon half */ float height; /**< Hexagon height */ float roof; /**< Hexagon roof */ float side; /**< Hexagon side */ }; HEXAGON_DATA lg; /**< Large hexagon data */ HEXAGON_DATA sm; /**< Small hexagon data */ }; /** * @brief * Constructs a CRgnCell object. * @param data Pre-computed data. * @param rect Returns a reference to a CRect object that represents the * size and position of the color cell. * @param color An RGB value that represents the color of the cell to draw. * @param u Index of the cell to be selected when VK_UP is pressed. * @param d Index of the cell to be selected when VK_DOWN is pressed. */ CRgnCell(const CTX_DATA& data, CXTPRectF& rect, COLORREF color, float u, float d); /** * @brief * Constructs a CRgnCell object. * @param data Pre-computed data. * @param rect Returns a reference to a CRect object that represents the * size and position of the color cell. * @param color An RGB value that represents the color of the cell to draw. * @param u Index of the cell to be selected when VK_UP is pressed. * @param d Index of the cell to be selected when VK_DOWN is pressed. * @param x Specifies the left position of CRgnCell. * @param y Specifies the top of CRgnCell. * @param bLarge TRUE if the cell size is large. */ CRgnCell(const CTX_DATA& data, CXTPRectF& rect, COLORREF color, float u, float d, float x, float y, BOOL bLarge = FALSE); protected: /** * @brief * Used by the CRgnCell to render each color cell. * @param pDC A CDC pointer that represents the current device context. * @return * TRUE if the color cell was successfully drawn, otherwise FALSE. */ virtual BOOL DrawCell(CDC* pDC); /** * @brief * Used by the CRgnCell to display a selection around the active * color cell. * @param pDC A CDC pointer that represents the current device context. * @return * TRUE if the color cell was successfully drawn, otherwise FALSE. */ virtual BOOL DrawSelection(CDC* pDC); int m_iCell[2]; /**< Index array that indicates which cell should be selected when the up or down arrow key is pressed. */ COLORREF m_color; /**< An RGB value that represents the color of the cell. */ CXTPRectF m_rect; /**< Represents the size and position of the color cell. */ CXTPPoint2f m_pts[6]; /**< CPoint array that represents the x- and y- coordinates for each vertex of the cell's polygon. */ friend class CXTPColorHex; private: static void AFX_CDECL ConvertFloatToIntPoints(const CXTPPoint2f (&from)[6], CPoint (&to)[6]); static void AFX_CDECL ComputeHexagon(const CTX_DATA::HEXAGON_DATA& data, float left, float top, CXTPPoint2f (&points)[6]); }; /** * @brief * List for maintaining CRgnCell objects. * @details * CList definition used by the CXTPColorHex control to maintain * a list of CRgnCell objects representing each color cell in * the hex color control. * @see * CXTPColorHex, CRgnCell */ typedef CList CRgnCellList; public: /** * @brief * Constructs a CXTPColorHex object. */ CXTPColorHex(); /** * @brief * Destroys a CXTPColorHex object, handles cleanup and deallocation. */ virtual ~CXTPColorHex(); public: /** * @brief * Call this member function to retrieve RGB information for the * color found at a location specified by 'point'. * @param point Represents the x- and y- coordinates of the cell to * retrieve RGB color information for. * @return * A COLORREF value. */ COLORREF ColorFromPoint(CPoint point); /** * @brief * Call this member function to retrieve a pointer to a CRgnCell object * that represents information for a color cell specified by either * the list 'iIndex' or RGB 'color'. * @param iIndex Index into m_rgnList list. * @return * A pointer to a CRgnCell object. */ CRgnCell* GetColorCell(int iIndex); /** * @brief * Call this member function to retrieve a pointer to a CRgnCell object * that represents information for a color cell specified by either * the list 'iIndex' or RGB 'color'. * @param color An RGB value that represents the color. * @return * A pointer to a CRgnCell object. */ CRgnCell* GetColorCell(COLORREF color); /** * @brief * Call this member function to set the selected color using either * the list 'iIndex' or RGB 'color'. * @param iIndex Index into m_rgnList list. * @param bNotify TRUE to send a WM_XTP_UPDATECOLOR notification to the * owner window indicating that the color has changed. * @return * TRUE if the color cell was selected, otherwise FALSE. */ BOOL SetSelectedColor(int iIndex, BOOL bNotify = TRUE); /** * @brief * Call this member function to set the selected color using either * the list 'iIndex' or RGB 'color'. * @param color An RGB value that represents the color. * @param bNotify TRUE to send a WM_XTP_UPDATECOLOR notification to the * owner window indicating that the color has changed. * @return * TRUE if the color cell was selected, otherwise FALSE. */ BOOL SetSelectedColor(COLORREF color, BOOL bNotify = TRUE); /** * @brief * Call this member function to return the currently selected color. * @return * An RGB color value that represents the currently selected color. */ COLORREF GetSelectedColor() const; protected: /** * @brief * This member function is called by the CXTPColorHex 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 * This member function updates the color selection based on the * x- and y- coordinates specified by 'point'. * @param point Current x- and y- coordinates of the color to select. * @param bNotify TRUE to send a WM_XTP_UPDATECOLOR notification to the * owner window indicating that the color has changed. * @return TRUE if successful; otherwise FALSE. */ BOOL UpdateSelection(CPoint point, BOOL bNotify = TRUE); /** * @brief * This member function updates the color selection based on the * x- and y- coordinates specified by 'point'. * @param pCell Pointer a CRgnCell object to select. * @param bNotify TRUE to send a WM_XTP_UPDATECOLOR notification to the * owner window indicating that the color has changed. * @return TRUE if successful; otherwise FALSE. */ BOOL UpdateSelection(CRgnCell* pCell, BOOL bNotify = TRUE); /** * @brief * This member function is called to determine if a specified * color is defined in the color array. * @param color A COLORREF value to check. * @return * true if the specified color is defined in the color array, * otherwise false. */ virtual bool IsValidColor(COLORREF color) const; /** * @brief * This member function is called by the CXTPColorHex class to build * the array of color cells used to render the hex color control. */ void CreateCellArray(); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPColorHex) virtual void PreSubclassWindow(); virtual BOOL PreTranslateMessage(MSG* pMsg); virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPColorHex) afx_msg void OnPaint(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); //}}AFX_MSG /** @endcond */ CBitmap m_bmpPicker; /**< Background device context. */ bool m_bPreSubclassInit; /**< true when initializing from PreSubclassWindow. */ COLORREF m_clrColor; /**< A COLORREF value that contains the RGB information for the current color. */ CRgnCellList m_rgnList; /**< Array of CRgnCellList objects that represent displayed color cells. */ CRgnCell* m_pCell; /**< Pointer to a CRgnCell object that represents the currently selected color. */ }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE COLORREF CXTPColorHex::GetSelectedColor() const { return m_clrColor; } /** @endcond */ /** * @brief * CXTPColorPageStandard is derived from CPropertyPage. It is * used to create a CXTPColorPageStandard dialog. */ class _XTP_EXT_CLASS CXTPColorPageStandard : public CPropertyPage { public: /** * @brief * Constructs a CXTPColorPageStandard object. * @param pParentSheet Pointer to the parent property sheet. */ CXTPColorPageStandard(CXTPColorDialog* pParentSheet = NULL); /** * @brief * Destroys a CXTPColorPageStandard object, handles cleanup and * deallocation. */ virtual ~CXTPColorPageStandard(); /** * @brief * This member function is called to set the selected color for * the page. * @param clr An RGB value that represents the color. */ void SetColor(COLORREF clr); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPColorPageStandard) virtual void DoDataExchange(CDataExchange* pDX); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPColorPageStandard) afx_msg LRESULT OnUpdateColor(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnColorDblClick(WPARAM wParam, LPARAM lParam); //}}AFX_MSG //{{AFX_DATA(CXTPColorPageStandard) enum { IDD = XTP_IDD_COLORSTANDARD }; //}}AFX_DATA /** @endcond */ protected: CXTPColorHex m_colorHex; /**< ColorHex control. */ CXTPColorDialog* m_pParentSheet; /**< Pointer to the parent property sheet. */ friend class CXTPColorHex; public: virtual BOOL OnSetActive(); }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE void CXTPColorPageStandard::SetColor(COLORREF clr) { m_colorHex.SetSelectedColor(clr, FALSE); } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPCOLORSTANDARD_H__) /** @endcond */