/** * @file XTPImageManager.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(__XTPIMAGEMANAGER_H__) # define __XTPIMAGEMANAGER_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ namespace Gdiplus { class GpBitmap; } /** @endcond */ /** * @brief * Image state enumerators. * * Example: *
 * // Set Icons
 * pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, xtpImageNormal);
 * pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, IDR_MAINFRAME_HOT, xtpImageHot);
 * 
* @see * CXTPImageManager::SetIcon, CXTPImageManager::SetIcons */ enum XTPImageState { xtpImageNormal, /**< Normal image. */ xtpImageDisabled, /**< Disabled image. */ xtpImageHot, /**< Hot image. */ xtpImageChecked, /**< Checked (selected) image. */ xtpImagePressed /**< Pressed image. */ }; /** * @brief * Icon size matching enumerators. */ enum XTPIconSizeMatching { xtpIconSizeExact, /**< Requires an icon to have size the same as requested. */ xtpIconSizeAtLeast, /**< Requires an icon to have size the same or larger than requested. */ xtpIconSizeAtMost, /**< Requires an icon to have size no more than requested. */ }; class CXTPImageManager; class CXTPImageManagerIconSet; class CXTPImageManagerImageList; class CXTPImageManagerIconHandle; class CXTPImageManagerResource; class CXTPPropExchange; class CXTPMarkupContext; class CXTPMarkupUIElement; class CXTPSvgImage; /** * @brief * Represents a generic interface for a vector image of any possible * format to be used with CXTPImageManager. */ class _XTP_EXT_CLASS CXTPImageManagerVectorImageHandle { public: /** * @brief * Construct an empty vector image handle object. */ CXTPImageManagerVectorImageHandle(); /** * @brief * Handles object destruction, releases vector image resources. */ virtual ~CXTPImageManagerVectorImageHandle(); /** * @brief * Construct a copy of the vector image handle object. * @param rhs a source vector image handle. */ CXTPImageManagerVectorImageHandle(const CXTPImageManagerVectorImageHandle& rhs); /** * @brief * Make the current vector image handle identical to the provided image handle. * @param rhs a source vector image handle. * @return * Self reference. */ CXTPImageManagerVectorImageHandle& operator=(const CXTPImageManagerVectorImageHandle& rhs); /** * @brief * Checks if the current vector image handle has a valid image associated with it. * @return * TRUE if the handle is a valid image. */ operator BOOL() const; /** * @brief * Determines if the handle is associated with Markup image. * @return * TRUE if the handle is associated with Markup image. */ BOOL IsMarkupImage() const; /** * @brief * Determines if the handle is associated with SVG image. * @return * TRUE if the handle is associated with SVG image. */ BOOL IsSvgImage() const; /** * @brief * Draws the image associated with the handle. * @param pDC Target device context pointer. * @param pt Target top-left corner location. * @param szIcon Target image size. */ void Draw(CDC* pDC, CPoint pt, CSize szIcon); /** * @brief * Determines if the encapsulated vector image supports drawing its bits directly into a * memory buffer. * @return * TRUE if direct buffer drawing is supported. * @see * DirectDraw */ BOOL IsDirectDrawSupported() const; /** * @brief * Draws vector image bits directly into the specified memoby buffer. * @param pBits Memory buffer pointer that is at least of szIcon.cx * szIcon.cy * 4 bytes * length. * @param cbSize Memory buffer size in bytes. * @param pt Top left output image coordinates. * @param szIcon The output icon size. * @return * The number of bytes written to the specified memory buffer or 0 if no image data has * been drawn. * @details * Image data consists of Width * Height DWORD color entries where each DWORD color entry * has the following color format: AlphaMask = 0xff000000, RedMask = 0x00ff0000, GreenMask * = 0x0000ff00, BlueMask = 0x000000ff. * @see * IsDirectDrawSupported */ SIZE_T DirectDraw(PVOID pBits, SIZE_T cbSize, CPoint pt, CSize szIcon); /** * @brief * Obtains a handle to image specific serialization data that can be used * storing and re-storing an image from. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ HGLOBAL GetSerializationData() const; /** * @brief * Retrieves the markup context for the icon. * @return * The markup context for the icon. */ CXTPMarkupContext* GetMarkupContext(); /** * @brief * Retrieves the data stream for the icon. * @return * The data stream for the icon. */ IStream* GetDataStream() const; /** * @brief * Creates a Markup image handle. * @param pContext User provided markup context pointer. * @param bSharedContext If TRUE, the user provided markup context pointer * is assumed to be shared, i.e. used and managed by the caller. * FALSE gives the image handle exclusize rights to manage and * release the context once it is no longer needed. * @param SerializationData Markup image serialization data handle that must be * allocated using GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, ...). * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateMarkupHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, HGLOBAL SerializationData); /** * @brief * Creates a Markup image handle. * @param pContext User provided markup context pointer. * @param bSharedContext If TRUE, the user provided markup context pointer * is assumed to be shared, i.e. used and managed by the caller. * FALSE gives the image handle exclusize rights to manage and * release the context once it is no longer needed. * @param pStream Markup image data stream pointer. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateMarkupHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, IStream* pStream); /** * @brief * Creates a Markup image handle. * @param pContext User provided markup context pointer. * @param bSharedContext If TRUE, the user provided markup context pointer * is assumed to be shared, i.e. used and managed by the caller. * FALSE gives the image handle exclusize rights to manage and * release the context once it is no longer needed. * @param lpszCode Markup image code pointer. * @param nLength Optional markup image code length in characters. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateMarkupHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, LPCSTR lpszCode, INT_PTR nLength = -1); /** * @brief * Creates a Markup image handle. * @param pContext User provided markup context pointer. * @param bSharedContext If TRUE, the user provided markup context pointer * is assumed to be shared, i.e. used and managed by the caller. * FALSE gives the image handle exclusize rights to manage and * release the context once it is no longer needed. * @param lpszCode Markup image code pointer. * @param nLength Optional markup image code length in characters. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateMarkupHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, LPCWSTR lpszCode, INT_PTR nLength = -1); /** * @brief * Creates an SVG image handle. * @param SerializationData SVG image serialization data handle that must be * allocated using GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, ...). * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateSvgHandle(HGLOBAL SerializationData); /** * @brief * Creates an SVG image handle. * @param pStream SVG image data stream pointer. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateSvgHandle(IStream* pStream); /** * @brief * Creates an SVG image handle. * @param lpszCode SVG image code pointer. * @param nLength Optional markup image code length in characters. * @return * Serialization data handle. The handle is managed by the object * so the caller must not deallocate or change it. */ static CXTPImageManagerVectorImageHandle CreateSvgHandle(LPCSTR lpszCode, INT_PTR nLength = -1); /** @cond */ CXTPSvgImage* GetSvgImage(); /** @endcond */ private: CXTPImageManagerVectorImageHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, CXTPMarkupUIElement* pMarkupElement, HGLOBAL SerializationData); CXTPImageManagerVectorImageHandle(CXTPMarkupContext* pContext, BOOL bSharedContext, CXTPMarkupUIElement* pMarkupElement, IStream* pSerializationData); CXTPImageManagerVectorImageHandle(CXTPSvgImage* pSvgImage, HGLOBAL SerializationData); CXTPImageManagerVectorImageHandle(CXTPSvgImage* pSvgImage, IStream* pSerializationData); void Reset(); private: struct IMAGE_RESOURCE { ULONG cRefs; enum { MarkupType, SvgType } nType; HGLOBAL SerializationData; IStream* pSerializationDataStream; union { struct { CXTPMarkupContext* pContext; BOOL bSharedContext; CXTPMarkupUIElement* pMarkupElement; } markup; CXTPSvgImage* pSvgImage; // more can be added } u; }; mutable IMAGE_RESOURCE* m_pResource; friend class CXTPImageManagerIcon; }; AFX_INLINE CXTPMarkupContext* CXTPImageManagerVectorImageHandle::GetMarkupContext() { return XTP_SAFE_GET1(m_pResource, u.markup.pContext, NULL); } AFX_INLINE IStream* CXTPImageManagerVectorImageHandle::GetDataStream() const { return XTP_SAFE_GET1(m_pResource, pSerializationDataStream, NULL); } /** * @brief * This structure is used to define the position and style of the icon in resources. */ struct XTP_IMAGERESOURCE_INFO { BOOL bAlpha; /**< TRUE if the icon has alpha layer, otherwise m_hbmpMask used to draw its mask. */ CRect rc; /**< Position of the icon inside resources' m_hbmpImage bitmap. */ CXTPImageManagerResource* pResource; /**< Pointer to owner resources. */ }; /** * @brief * CXTPImageManagerIconHandle is a HICON wrapper class. */ class _XTP_EXT_CLASS CXTPImageManagerIconHandle { public: /** * @brief * Constructs a CXTPImageManagerIconHandle object. */ CXTPImageManagerIconHandle(); /** * @brief * Constructs a CXTPImageManagerIconHandle object. * @param hIcon Icon handle. * @param bUseResources TRUE to use resources. * @param bSharedHandle If FALSE, the resource will be destroyed * when it is no longer in use. */ CXTPImageManagerIconHandle(HICON hIcon, BOOL bUseResources = TRUE, BOOL bSharedHandle = TRUE); /** * @brief * Constructs a CXTPImageManagerIconHandle object. * @param hBitmap Bitmap handle. * @param bSharedHandle If FALSE, the resource will be destroyed * when it is no longer in use. */ CXTPImageManagerIconHandle(HBITMAP hBitmap, BOOL bSharedHandle = TRUE); /** * @brief * Constructs a CXTPImageManagerIconHandle object. * @param hHandle CXTPImageManagerIconHandle reference. */ CXTPImageManagerIconHandle(const CXTPImageManagerIconHandle& hHandle); /** * @brief * Destroys a CXTPImageManagerIconHandle object, handles cleanup and deallocation. */ ~CXTPImageManagerIconHandle(); /** * @brief * This operator returns a HICON object whose value is copied from this * CXTPImageManagerIconHandle object. * @return * HICON handle. */ operator HICON() const; /** * @brief * Copies data from an HBITMAP or CXTPImageManagerIconHandle object. * @param hBitmap Alpha bitmap handler. */ void CopyHandle(HBITMAP hBitmap); /** * @brief * Copies data from an HBITMAP or CXTPImageManagerIconHandle object. * @param handle CXTPImageManagerIconHandle object. */ void CopyHandle(const CXTPImageManagerIconHandle& handle); /** * @brief * Checks if the image has alpha channel. * @return * TRUE if the image has alpha channel, otherwise FALSE. */ BOOL IsAlpha() const; /** * @brief * Checks if the class has no icon. * @return * TRUE if the m_hIcon member is NULL. */ BOOL IsEmpty() const; /** * @brief * Retrieves bitmap handle. * @return * 32bit alpha bitmap. */ HBITMAP GetBitmap() const; /** * @brief * Retrieves the icon handle. * @return * Icon handle. */ HICON GetIcon() const; /** * @brief * Retrieves the size of the icon. * @return * Size of the icon. */ CSize GetExtent() const; /** * @brief * Call this method to draw icons. * @param pDC Pointer to the device context to draw into. * @param pt Positioning of the icon to draw. * @param szIcon Size of the icon to draw. * @param bDrawComposited TRUE to draw inside Vista Composited area. */ void Draw(CDC* pDC, CPoint pt, CSize szIcon, BOOL bDrawComposited = FALSE); /** * @brief * Obtains a new icon handle with the icon image scaled to the specified DPI. * @param nDpi Custom DPI level or 0 for the current DPI value. * @return * A new scaled icon handle. The caller is responsible for destroying the handle. */ HICON GetDpiScaled(int nDpi = 0) const; /** * @brief * Release bitmap and icon handlers. */ void Clear(); /** * @brief * Creates an icon from resource bits describing the icon. * @param lpszResourceName Resource name identifier. * @param szIcon Specifies the desired width and height, in pixels, of the icon. * @param bGroupResource TRUE to check if the RT_GROUP_ICON resource exists. * @param nSizeMatching Specifies how icon size is matched. By default, exact matching * is specified. Used only if bGroupResource is TRUE. * @return * TRUE if successful, otherwise FALSE. */ BOOL CreateIconFromResource(LPCTSTR lpszResourceName, CSize szIcon, BOOL bGroupResource = TRUE, XTPIconSizeMatching nSizeMatching = xtpIconSizeExact); /** * @brief * Creates an icon from resource bits describing the icon. * @param hInst Application instance handler. * @param lpszResourceName Resource name identifier. * @param szIcon Specifies the desired width and height, in pixels, of the icon. * @param bGroupResource TRUE to check if the RT_GROUP_ICON resource exists. * @param nSizeMatching Specifies how icon size is matched. By default, exact matching * is specified. Used only if bGroupResource is TRUE. * @return * TRUE if successful, otherwise FALSE. */ BOOL CreateIconFromResource(HINSTANCE hInst, LPCTSTR lpszResourceName, CSize szIcon, BOOL bGroupResource, XTPIconSizeMatching nSizeMatching = xtpIconSizeExact); /** * @brief * Attaches an object to an existing icon handle. * @param hIcon Source icon handler. * @param bSharedHandle If FALSE, the resource will be destroyed * when it is no longer in use. */ void Attach(HICON hIcon, BOOL bSharedHandle); /** * @brief * Attaches an object to an existing bitmap handle. * @param hBitmap Alpha bitmap handler. * @param bSharedHandle If FALSE, the resource will be destroyed * when it is no longer in use. */ void Attach(HBITMAP hBitmap, BOOL bSharedHandle); /** @cond */ /** * @brief * This operator assigns the icon handler to a * CXTPImageManagerIconHandle object. * @param hIcon Source icon handler. */ _XTP_DEPRECATED_IN_FAVOR2(CXTPImageManagerIconHandle, Attach) const CXTPImageManagerIconHandle& operator=(const HICON hIcon); /** * @brief * This operator assigns the alpha bitmap handler to a * CXTPImageManagerIconHandle object. * @param hBitmap Alpha bitmap handler */ _XTP_DEPRECATED_IN_FAVOR2(CXTPImageManagerIconHandle, Attach) const CXTPImageManagerIconHandle& operator=(const HBITMAP hBitmap); /** @endcond */ /** * @brief * Creates an alpha bitmap with a valid alpha layer. * @return * TRUE if successful, otherwise FALSE. */ LPBYTE PreMultiply(); /** * @brief * Detaches the handle from the associated icon handle without * releasing the resource. */ void Detach(); protected: /** * @brief * Initializes icons. */ void Init(); private: const CXTPImageManagerIconHandle& operator=(const CXTPImageManagerIconHandle&); CSize _GetExtent() const; protected: HICON m_hIcon; /**< The underlying HICON handler for this CXTPImageManagerIconHandle object. */ HBITMAP m_hBitmap; /**< The underlying Alpha bitmap handler for this CXTPImageManagerIconHandle object. */ LPBYTE m_pBits; /**< Alpha bitmap bits. */ BOOL m_bClearHandles; /**< TRUE if object must destroy handlers. */ CXTPImageManager* m_pImageManager; /**< Pointer to parent Image Manager. */ XTP_IMAGERESOURCE_INFO* m_pRInfo; /**< Pointer to resource info if the icon is part of common resources. */ CSize m_szIcon; /**< Size of the icon. */ BOOL m_bUseResources; /**< TRUE to use common resources. */ private: friend class CXTPImageManagerIcon; friend class CXTPImageManagerResource; }; /** * @brief * Icons holder class. */ class _XTP_EXT_CLASS CXTPImageManagerIcon : public CXTPCmdTarget { /** @cond */ DECLARE_DYNAMIC(CXTPImageManagerIcon) /** @endcond */ private: struct ICONDIRENTRY; struct ICONDIRHEADER; struct ICONIMAGE; struct GRPICONDIRENTRY; struct GRPICONDIR; public: /** * @brief * Constructs a CXTPImageManagerIcon object. * @param nID Icon identifier. * @param nWidth Initial width for the icon. * @param nHeight Initial height for the icon. * @param pIconSet Parent icon set icon will belong. */ CXTPImageManagerIcon(UINT nID, int nWidth, int nHeight, CXTPImageManagerIconSet* pIconSet = NULL); /** * @brief * Constructs a CXTPImageManagerIcon object. * @param nID Icon identifier. * @param nWidth Initial width for the icon. * @param nHeight Initial height for the icon. * @param pImageList Parent icon set icon will belong. */ CXTPImageManagerIcon(UINT nID, int nWidth, int nHeight, CXTPImageManagerImageList* pImageList); /** * @brief * Constructs a CXTPImageManagerIcon object. * @param nID Icon identifier. * @param pIconSet Parent icon set icon will belong. * @param szRecommendedExtent Recommended icon size that suits the icon best. * A zero value size component assumes no recommended value. */ CXTPImageManagerIcon(UINT nID, CXTPImageManagerIconSet* pIconSet = NULL, CSize szRecommendedExtent = CSize(0)); /** * @brief * Destroys a CXTPImageManagerIcon object, handles cleanup and deallocation. */ ~CXTPImageManagerIcon(); /** * @brief * Retrieves the image identifier. * @return * Identifier of the image. */ UINT GetID() const; /** * @brief * Checks if the image has alpha channel. * @return * TRUE if the image has alpha channel, otherwise FALSE. */ BOOL IsAlpha() const; /** * @brief * Checks if icons were scaled from another CXTPImageManagerIcon object. * @return * TRUE if icons were scaled from another CXTPImageManagerIcon object. */ BOOL IsScaled() const; /** * @brief * Obtains a pointer to an associated image list if the icon object is an * icon in an image list. If the returned pointer is not NULL, then the * icon ID should be used as an icon index in the returned image list. * @return * Pointer value to an associated image list, or NULL. */ CXTPImageManagerImageList* GetImageList(); /** * @brief * Obtains a pointer to an associated image list if the icon object is an * icon in an image list. If the returned pointer is not NULL, then the * icon ID should be used as an icon index in the returned image list. * @return * Pointer value to an associated image list, or NULL. */ const CXTPImageManagerImageList* GetImageList() const; /** * @brief * Retrieves the icon handle. * @return * Icon handle. * @see * XTPImageState */ CXTPImageManagerIconHandle& GetIcon(); /** * @brief * Retrieves the icon handle. * @param imageState Image state for the icon to retrieve. * @return * Icon handle. * @see * XTPImageState */ CXTPImageManagerIconHandle& GetIcon(XTPImageState imageState); /** * @brief * Retrieves the faded icon. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetFadedIcon(); /** * @brief * Retrieves the shadow for the icon. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetShadowIcon(); /** * @brief * Retrieves the checked icon. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetCheckedIcon(); /** * @brief * Retrieves the pressed icon. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetPressedIcon(); /** * @brief * Retrieves hot icon. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetHotIcon(); /** * @brief * Retrieves the disabled icon. * @param bCreateIfNotExists TRUE to create the disabled icon if the image does not * exist. By default, this parameter is TRUE. * @return * Icon handle. */ CXTPImageManagerIconHandle& GetDisabledIcon(BOOL bCreateIfNotExists = TRUE); /** * @brief * Determines if a state specific icon exists. * @param imageState Image state for which to check icon existence. * @return * TRUE if the state specific icon exists. */ BOOL HasIcon(XTPImageState imageState) const; /** * @brief * Determines if a state specific icon exists. * @return * TRUE if the state specific icon exists. */ BOOL HasNormalIcon() const; /** * @brief * Determines if a state specific icon exists. * @return * TRUE if the state specific icon exists. */ BOOL HasDisabledIcon() const; /** * @brief * Determines if a state specific icon exists. * @return * TRUE if the state specific icon exists. */ BOOL HasCheckedIcon() const; /** * @brief * Determines if a state specific icon exists. * @return * TRUE if the state specific icon exists. */ BOOL HasPressedIcon() const; /** * @brief * Determines if a state specific icon exists. * @return * TRUE if the state specific icon exists. */ BOOL HasHotIcon() const; /** * @brief * Creates a disabled icon. * @param clrDisabledLight The lightest color of icon to generate. * @param clrDisabledDark The darkest color of icon to generate. */ void CreateDisabledIcon(COLORREF clrDisabledLight = (COLORREF)-1, COLORREF clrDisabledDark = (COLORREF)-1); /** * @brief * Sets the icon. * @param hIcon Icon handle to set. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Sets the icon. * @param hIcon Icon handle to set. * @param imageState State of the icon. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetIcon(const CXTPImageManagerIconHandle& hIcon, XTPImageState imageState); /** * @brief * Sets the icon. * @param nIDResourceIcon Icon resource identifier. * @param nWidth Width of the icon. * @param nHeight Height of the icon. * @param nSizeMatching Specifies how icon size is matched. By default, exact matching * is specified. Used only if group icon resources. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetIcon(UINT nIDResourceIcon, int nWidth, int nHeight, XTPIconSizeMatching nSizeMatching = xtpIconSizeExact); /** * @brief * Sets the disabled icon. * @param hIcon Icon handle to set. */ void SetDisabledIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Sets the hot icon. * @param hIcon Icon handle to set. */ void SetHotIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Sets the checked icon. * @param hIcon Icon handle to set. */ void SetCheckedIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Sets the icon. * @param hIcon Icon handle to set. */ void SetNormalIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Sets the pressed icon. * @param hIcon Icon handle to set. */ void SetPressedIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Retrieves the size of the icon. * @return * Size of the icon. * @see * GetRecommendedExtent */ CSize GetExtent() const; /** * @brief * Retrieves the size of the icon. * @param hIcon Icon handle. * @return * Size of the icon. * @see * GetRecommendedExtent */ static CSize AFX_CDECL GetExtent(HICON hIcon); /** * @brief * Retrieves the recommended size of the icon. It is an optional size and may not be * specified by default. Usually it's the size that the icon was added to its icon manager * with. For raster icons its value almost always equals to GetExtent returned value. But * for vector icons that have no extent it will be the size that it was added to the * collection. * @return * The recommended size of the icon. * @see * GetExtent */ CSize GetRecommendedExtent() const; /** * @brief * This method tests if the file is an alpha bitmap. * @param pszFileName File path. * @return * TRUE if the file is an alpha bitmap. */ static BOOL AFX_CDECL IsAlphaBitmapFile(LPCTSTR pszFileName); /** * @brief * This method tests if the file is a .png image. * @param pszFileName File path. * @return * TRUE if the file is a .png image. */ static BOOL AFX_CDECL IsPngBitmapFile(LPCTSTR pszFileName); /** * @brief * This method loads an alpha bitmap from an icon file. * @param pszFileName File path. * @param nWidth Icon width to load. * @return * Alpha bitmap if an icon with the specified width was found, otherwise NULL. */ static HBITMAP AFX_CDECL LoadAlphaIcon(LPCTSTR pszFileName, int nWidth); /** * @brief * This method loads an alpha bitmap from a resource file. * @param nIDResource Resource identifier. * @details * Do not use LoadImage to load an alpha bitmap. It loses alpha channel * in some Windows. * @return * Alpha bitmap handler. */ static HBITMAP AFX_CDECL LoadAlphaBitmap(UINT nIDResource); /** * @brief * This method loads an alpha bitmap from a resource file. * @param hModule Handle to the instance of the module whose executable * file contains the bitmap to be loaded. * @param lpszResource Long pointer to a null-terminated string that contains the * name of the bitmap resource to be loaded. * @details * Do not use LoadImage to load an alpha bitmap. It loses alpha channel * in some Windows. * @return * Alpha bitmap handler. */ static HBITMAP AFX_CDECL LoadAlphaBitmap(HMODULE hModule, LPCTSTR lpszResource); /** * @brief * This method loads a bitmap or .png from a file on disk. * @param lpszFileName File name of a bitmap or .png file. * @param lbAlphaBitmap Determines if a bitmap contains an alpha layer. * @return * Bitmap handler. */ static HBITMAP AFX_CDECL LoadBitmapFromFile(LPCTSTR lpszFileName, BOOL* lbAlphaBitmap = NULL); /** * @brief * This method loads an alpha bitmap or .png from a resource file. * @param lpszResource Long pointer to a null-terminated string that contains the * name of the bitmap resource to be loaded. * @param lbAlphaBitmap Determines if a bitmap contains an alpha layer. * @return * Alpha bitmap handler. */ static HBITMAP AFX_CDECL LoadBitmapFromResource(LPCTSTR lpszResource, BOOL* lbAlphaBitmap); /** * @brief * This method loads an alpha bitmap or .png from a resource file. * @param hModule Handle to the instance of the module whose executable * file contains the bitmap to be loaded. * @param lpszResource Long pointer to a null-terminated string that contains the * name of the bitmap resource to be loaded. * @param lbAlphaBitmap Determines if a bitmap contains an alpha layer. * @return * Alpha bitmap handler. */ static HBITMAP AFX_CDECL LoadBitmapFromResource(HMODULE hModule, LPCTSTR lpszResource, BOOL* lbAlphaBitmap); /** * @brief * Checks if a bitmap with a specified resource has alpha channel. * @param hModule Module of the bitmap to check. * @param lpBitmapName Resource name of the bitmap to check. * @return * TRUE if the bitmap has alpha channel, otherwise FALSE. */ static BOOL AFX_CDECL IsAlphaBitmapResource(HMODULE hModule, LPCTSTR lpBitmapName); /** * @brief * Checks if a bitmap with a specified resource is a .png resource. * @param hModule Module of the bitmap to check. * @param lpBitmapName Resource name of the bitmap to check. * @return * TRUE if the bitmap is a png resource, otherwise FALSE. */ static BOOL AFX_CDECL IsPngBitmapResource(HMODULE hModule, LPCTSTR lpBitmapName); /** * @brief * The DrawAlphaBitmap function displays bitmaps that have transparent * or semitransparent pixels. * @param pDC Pointer to destination device context. * @param ptDest Upper-left corner of the destination rectangle. * @param ptSrc Upper-left corner of the source rectangle. * @param hBitmap Alpha bitmap handler. * @param szDest Destination size. * @param szSrc Source size. * @return */ static void AFX_CDECL DrawAlphaBitmap(CDC* pDC, HBITMAP hBitmap, CPoint ptDest, CSize szDest, CPoint ptSrc = 0, CSize szSrc = 0); /** * @brief * Creates valid alpha bits to use in AlphaBlend. * @param hBitmap Alpha bitmap handler. * @param pbAlpha Reference to a BOOLEAN, TRUE for Alpha. * @param lpBits Pointer to a BYTE structure. * @return * Valid alpha bits. * @see * BLENDFUNCTION, AlphaBlend */ static HBITMAP AFX_CDECL PreMultiplyAlphaBitmap(HBITMAP hBitmap, BOOL* pbAlpha = NULL, LPBYTE* lpBits = NULL); /** * @brief * This method is called to create a mirror copy of a bitmap. * @param hBitmap Bitmap handle to be copied. * @return * New mirror bitmap */ static HBITMAP AFX_CDECL InvertAlphaBitmap(HBITMAP hBitmap); /** * @brief * This helper method retrieves information about an alpha bitmap * and its alpha bits. * @param dcSrc Reference to CDC. * @param hBitmap Alpha bitmap. * @param pbmi Bitmap information. * @param pBits Bitmap bits. * @param nSize Size of bits array. * @return * TRUE if successful, otherwise FALSE. */ static BOOL AFX_CDECL GetBitmapBits(CDC& dcSrc, HBITMAP hBitmap, PBITMAPINFO& pbmi, LPVOID& pBits, UINT& nSize); /** * @brief * Copies an alpha bitmap. * @param hBitmap Bitmap handler to be copied. * @param lpBits Points to a BYTE structure, defaults.to NULL. * @return * New alpha bitmap handler. */ static HBITMAP AFX_CDECL CopyAlphaBitmap(HBITMAP hBitmap, LPBYTE* lpBits = NULL); /** * @brief * Determines whether the provided icon is translucent or not. * @param hIcon Icon handle to check. * @return * TRUE if the icon provided is translucent, otherwise FALSE. */ static BOOL AFX_CDECL IsAlphaIconHandle(HICON hIcon); /** * @brief * Retrieves the icon height. * @return * Height of the icon. */ int GetHeight() const; /** * @brief * Retrieves the icon width. * @return * Width of the icon. */ int GetWidth() const; /** * @brief * Either reads this object from or writes this object to an archive. * @param ar A CArchive object to serialize to or from. */ void Serialize(CArchive& ar); /** * @brief * Makes the current icon a copy of a provided icon. * @param pIcon An icon pointer to copy from. */ void Copy(CXTPImageManagerIcon* pIcon); /** * @brief * Either reads this object from or writes this object to an archive. * @param hIcon Icon to be serialized. * @param ar A CArchive object to serialize to or from. * @param nSchema Schema data. */ void SerializeIcon(CXTPImageManagerIconHandle& hIcon, CArchive& ar, long nSchema); /** * @brief * Either reads this object from or writes this object to an archive. * @param hIcon Icon to be serialized. * @param ar A CArchive object to serialize to or from. * @param nSchema Schema data. */ void SerializeIcon(CXTPImageManagerVectorImageHandle& hIcon, CArchive& ar, long nSchema); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. */ void Draw(CDC* pDC, CPoint pt); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param szIcon Specifies the size of the image. */ void Draw(CDC* pDC, CPoint pt, CSize szIcon); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param imageState State specific image to draw. */ void Draw(CDC* pDC, CPoint pt, XTPImageState imageState); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param imageState State specific image to draw. * @param szIcon Specifies the size of the image. */ void Draw(CDC* pDC, CPoint pt, XTPImageState imageState, CSize szIcon); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param hIcon A handle to an icon. * @param szIcon Specifies the size of the image. * @param clrBK Background color of the image. * @param clrFG Foreground color of the image. * @param uiFlags Drawing style and, optionally, the overlay image. */ void Draw(CDC* pDC, CPoint pt, CXTPImageManagerIconHandle& hIcon, CSize szIcon = 0, COLORREF clrBK = CLR_NONE, COLORREF clrFG = CLR_NONE, UINT uiFlags = 0); /** * @brief * Draws the image at a specified location. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param hIcon A handle to an icon. * @param szIcon Specifies the size of the image. */ void Draw(CDC* pDC, CPoint pt, CXTPImageManagerVectorImageHandle hIcon, CSize szIcon = 0); /** * @brief * Determines if the encapsulated vector image supports drawing its bits directly into a * memory buffer. * @param imageState State specific image to draw. * @return * TRUE if direct buffer drawing is supported. * @see * DirectDraw */ BOOL IsDirectDrawSupported(XTPImageState imageState = xtpImageNormal) const; /** * @brief * Draw vector image bits directly into the specified memoby buffer. * @param pBits Memory buffer pointer that is at least of szIcon.cx * szIcon.cy * 4 bytes * length. * @param cbSize Memory buffer size in bytes. * @param pt Top left output image coordinates. * @param szIcon The output icon size. * @return * The number of bytes written to the specified memory buffer or 0 if no image data has * been drawn. * @details * By default the icon associated with xtpImageNormal image state is assumed. * Image data consists of Width * Height DWORD color entries where each DWORD color entry * has the following color format: AlphaMask = 0xff000000, RedMask = 0x00ff0000, GreenMask * = 0x0000ff00, BlueMask = 0x000000ff. * @see * IsDirectDrawSupported */ SIZE_T DirectDraw(PVOID pBits, SIZE_T cbSize, CPoint pt, CSize szIcon); /** * @brief * Draw vector image bits directly into the specified memoby buffer. * @param pBits Memory buffer pointer that is at least of szIcon.cx * szIcon.cy * 4 bytes * length. * @param cbSize Memory buffer size in bytes. * @param pt Top left output image coordinates. * @param imageState The specific image identified to otain the icon for. * @param szIcon The output icon size. * @return * The number of bytes written to the specified memory buffer or 0 if no image data has * been drawn. * @details * By default the icon associated with xtpImageNormal image state is assumed. * Image data consists of Width * Height DWORD color entries where each DWORD color entry * has the following color format: AlphaMask = 0xff000000, RedMask = 0x00ff0000, GreenMask * = 0x0000ff00, BlueMask = 0x000000ff. * @see * IsDirectDrawSupported */ SIZE_T DirectDraw(PVOID pBits, SIZE_T cbSize, CPoint pt, XTPImageState imageState, CSize szIcon); /** * @brief * Draw vector image bits directly into the specified memoby buffer. * @param pBits Memory buffer pointer that is at least of szIcon.cx * szIcon.cy * 4 bytes * length. * @param cbSize Memory buffer size in bytes. * @param pt Top left output image coordinates. * @param szIcon The output icon size. * @param hIcon The handle of a vector icon to draw. * @return * The number of bytes written to the specified memory buffer or 0 if no image data has * been drawn. * @details * By default the icon associated with xtpImageNormal image state is assumed. * Image data consists of Width * Height DWORD color entries where each DWORD color entry * has the following color format: AlphaMask = 0xff000000, RedMask = 0x00ff0000, GreenMask * = 0x0000ff00, BlueMask = 0x000000ff. * @see * IsDirectDrawSupported */ SIZE_T DirectDraw(PVOID pBits, SIZE_T cbSize, CPoint pt, CXTPImageManagerVectorImageHandle hIcon, CSize szIcon = 0); /** * @brief * Draws the image using the brush specified by the clrBrush parameter. * @param pDC Destination device context. * @param pt Specifies the location of the image. * @param hIcon A handle to an icon. * @param szIcon The output icon size. * @param clrBrush Color of the brush used to draw the image. */ void DrawMono(CDC* pDC, CPoint pt, CXTPImageManagerIconHandle& hIcon, CSize szIcon, COLORREF clrBrush); /** * @brief * Redraws Fade and Shadow icons. */ void Refresh(); /** * @brief * Creates a markup context if it is necessary for the icon and * has not already been created. * @return * A pointer to the created or existing markup context, or NULL if such * a context is not required for the icon type. */ CXTPMarkupContext* CreateMarkupContext(); /** * @brief * Retrieves the markup context for the icon. * @return * The markup context for the icon. */ CXTPMarkupContext* GetMarkupContext(); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorIcon(CXTPImageManagerVectorImageHandle hIcon); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @param imageState Image state identifier to set the icon for. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorIcon(CXTPImageManagerVectorImageHandle hIcon, XTPImageState imageState); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorDisabledIcon(CXTPImageManagerVectorImageHandle hIcon); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorHotIcon(CXTPImageManagerVectorImageHandle hIcon); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorCheckedIcon(CXTPImageManagerVectorImageHandle hIcon); /** * @brief * Sets the icon for a specified state. * @param hIcon Icon handle to use for the specified state. * @return * TRUE if the icon was successfully set. */ BOOL SetVectorPressedIcon(CXTPImageManagerVectorImageHandle hIcon); /** * @brief * Obtains the vector icon handle for a specified state. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorIcon() const; /** * @brief * Obtains the vector icon handle for a specified state. * @param imageState Image state identifier to obtain the icon for. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorIcon(XTPImageState imageState) const; /** * @brief * Obtains the vector icon handle for a specified state. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorCheckedIcon() const; /** * @brief * Obtains the vector icon handle for a specified state. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorPressedIcon() const; /** * @brief * Obtains the vector icon handle for a specified state. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorHotIcon() const; /** * @brief * Obtains the vector icon handle for a specified state. * @return * State specific icon handle. */ CXTPImageManagerVectorImageHandle GetVectorDisabledIcon() const; /** * @brief * Checks if the current icon is a raster icon. * @return * TRUE if the current icon is a raster icon. */ BOOL IsRasterIcon() const; /** * @brief * Checks if the current icon is a vector icon. * @return * TRUE if the current icon is a vector icon. */ BOOL IsVectorIcon() const; /** * @brief * Checks if the current icon has an underfined type, * i.e. no icon is associated with it. * @return * TRUE if the current icon is an undefined icon. */ BOOL IsUndefinedIcon() const; /** * @brief * Use this method to scale an icon. * @param hIcon Icon to be scaled. * @param szExtent Source icon size. * @param nWidth Width of the result icon. * @return A scaled icon handle. */ static HICON AFX_CDECL ScaleToFit(HICON hIcon, CSize szExtent, int nWidth); /** * @brief * Call this method to draw a non-alpha icon in a composited Vista Glass rectangle. * @param pDC Pointer to device context. * @param pt Pointer to draw icon. * @param szIcon Size of the icon. * @param hIcon Icon handle to draw. * @return */ static void AFX_CDECL DrawIconComposited(CDC* pDC, CPoint pt, CSize szIcon, HICON hIcon); /** @cond */ CXTPSvgImage* GetSvgImage(); /** @endcond */ private: void CreateFadedIcon(); void CreateShadowIcon(); void Clear(BOOL bIcon = FALSE); COLORREF LightenColor(COLORREF clr, double factor); BOOL GetDIBBitmap(HBITMAP hBitmap, PBYTE& pBits, UINT& nBitsSize, PBITMAPINFO& pBitmapInfo, UINT& nBitmapInfoSize); HBITMAP ReadDIBBitmap(CArchive& ar, LPBYTE* pBits1); void WriteDIBBitmap(CArchive& ar, HBITMAP hBitmap); CXTPImageManager* GetImageManager() const; private: CXTPImageManagerIcon(const CXTPImageManagerIcon&) : m_nID(0) , m_nType(RasterIcon) , m_pMarkupContext(NULL) { } const CXTPImageManagerIcon& operator=(const CXTPImageManagerIcon&) { return *this; } public: BOOL m_bDrawComposited; /**< Draw on Vista composited rects. */ private: const UINT m_nID; enum IconType { UndefinedIcon, RasterIcon, VectorIcon } m_nType; int m_nWidth; int m_nHeight; CSize m_szRecommendedExtent; CXTPImageManagerIconHandle m_hIcon; CXTPImageManagerIconHandle m_hFaded; CXTPImageManagerIconHandle m_hShadow; CXTPImageManagerIconHandle m_hHot; CXTPImageManagerIconHandle m_hChecked; CXTPImageManagerIconHandle m_hPressed; CXTPImageManagerIconHandle m_hDisabled; CXTPImageManagerIconHandle m_hDisabledAuto; CXTPImageManagerIconSet* m_pIconSet; CXTPImageManagerImageList* m_pImageList; CXTPMarkupContext* m_pMarkupContext; CXTPImageManagerVectorImageHandle m_VectorImageNormal; CXTPImageManagerVectorImageHandle m_VectorImageHot; CXTPImageManagerVectorImageHandle m_VectorImageChecked; CXTPImageManagerVectorImageHandle m_VectorImagePressed; CXTPImageManagerVectorImageHandle m_VectorImageDisabled; private: friend class CXTPImageManager; friend class CXTPImageManagerIconSet; friend class CXTPImageManagerIconHandle; # ifdef _XTP_ACTIVEX /** @cond */ public: DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPImageManagerIcon); afx_msg long OleGetHandle(); afx_msg void OleDraw(long hDC, int x, int y, int cx, int cy, int nState); afx_msg LPDISPATCH OleCreatePicture(int nState); afx_msg LPDISPATCH OleScale(long nWidth); /** @endcond */ # endif }; /** * @brief * CXTPImageManagerIconSet represents the collection of icons for a specified identifier. */ class _XTP_EXT_CLASS CXTPImageManagerIconSet : public CXTPCmdTarget { public: typedef CMap CIconSetMap; /**< Icons collection. */ public: /** * @brief * Constructs a CXTPImageManagerIconSet object. * @param nID Icon set identifier. * @param pImageManager Parent image manager to which CXTPImageManagerIconSet belongs. */ CXTPImageManagerIconSet(UINT nID, CXTPImageManager* pImageManager); /** * @brief * Destroys a CXTPImageManagerIconSet object, handles cleanup and deallocation. */ ~CXTPImageManagerIconSet(); /** * @brief * Call this member to get the icon with the specified width. * @param nWidth Width of the icon to retrieve. * @param bScaled TRUE to scale the icon. * @return * A pointer to a CXTPImageManagerIcon object. */ CXTPImageManagerIcon* GetIcon(UINT nWidth, BOOL bScaled = TRUE); /** * @brief * Retrieves the collection of icons. * @return * A pointer to a CIconSetMap object. */ CIconSetMap* GetIcons(); /** * @brief * Retrieves the identifier of the collection set. * @return * Identifier of icons. */ UINT GetID() const; /** * @brief * Removes all icons. */ void RemoveAll(); /** * @brief * Redraws all icons. */ void RefreshAll(); /** * @brief * Sets state dependent icon from various icon sources. * @param pStream Vector icon data source. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(IStream* pStream, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param pStream Vector icon data source. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorDisabledIcon(IStream* pStream, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param pStream Vector icon data source. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorHotIcon(IStream* pStream, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param pStream Vector icon data source. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorCheckedIcon(IStream* pStream, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param pStream Vector icon data source. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorPressedIcon(IStream* pStream, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param hIcon Pre-loaded vector image handle. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(CXTPImageManagerVectorImageHandle hIcon, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param hIcon Pre-loaded vector image handle. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorDisabledIcon(CXTPImageManagerVectorImageHandle hIcon, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param hIcon Pre-loaded vector image handle. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorHotIcon(CXTPImageManagerVectorImageHandle hIcon, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param hIcon Pre-loaded vector image handle. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorCheckedIcon(CXTPImageManagerVectorImageHandle hIcon, UINT nWidth); /** * @brief * Sets state dependent icon from various icon sources. * @param hIcon Pre-loaded vector image handle. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorPressedIcon(CXTPImageManagerVectorImageHandle hIcon, UINT nWidth); private: CXTPImageManagerIcon* CreateIcon(UINT nWidth); CXTPImageManagerIcon* CreateVectorIcon(UINT nWidth); CXTPImageManagerVectorImageHandle CreateAutoVectorIconHandle(CXTPImageManagerIcon* pIcon, IStream* pStream); void SetIcon(const CXTPImageManagerIconHandle& hIcon, UINT nWidth); void SetDisabledIcon(const CXTPImageManagerIconHandle& hIcon, UINT nWidth); void SetHotIcon(const CXTPImageManagerIconHandle& hIcon, UINT nWidth); void SetCheckedIcon(const CXTPImageManagerIconHandle& hIcon, UINT nWidth); void SetPressedIcon(const CXTPImageManagerIconHandle& hIcon, UINT nWidth); # ifdef _XTP_ACTIVEX /** @cond */ public: DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPImageManagerIconSet); DECLARE_ENUM_VARIANTLIST(CXTPImageManagerIconSet) afx_msg long OleGetCount(); afx_msg long OleGetID(); LPDISPATCH OleGetImage(long Width); /** @endcond */ # endif private: CXTPImageManagerIconSet(const CXTPImageManagerIconSet&) : m_nID(0) { } const CXTPImageManagerIconSet& operator=(const CXTPImageManagerIconSet&) { return *this; } private: CIconSetMap m_mapIcons; const UINT m_nID; CXTPImageManager* m_pImageManager; private: friend class CXTPImageManager; friend class CXTPImageManagerIcon; }; /** * @brief * This class is used to connect ImageManager with specified HIMAGELIST */ class _XTP_EXT_CLASS CXTPImageManagerImageList { public: /** * @brief * Constructs a CXTPImageManagerImageList class. */ CXTPImageManagerImageList(); /** * @brief * Destroys a CXTPImageManagerImageList object, handles cleanup and deallocation. */ ~CXTPImageManagerImageList(); public: /** * @brief * Call this method to determine if ImageList handles a command * with a specified command ID. * @param nCommand Command ID to check. * @return * TRUE if ImageList handles the command with the specified command ID. */ BOOL Lookup(UINT nCommand); /** * @brief * Draws the icon for a command with a specified command ID. * @param nCommand Command ID. * @return * A pointer to a CXTPImageManagerIcon object that can be used to * draw the icon for the command with the specified command ID. */ CXTPImageManagerIcon* GetIcon(UINT nCommand); /** * @brief * Call this method to draw a specified icon. * @param pDC Device context to draw into. * @param pt Position of the icon to draw. * @param pIcon Pointer to the icon to draw. * @param szIcon Size of the icon. * @param clrBK Background color of the image. * @param clrFG Foreground color of the image. * @param uiFlags Drawing style and, optionally, the overlay image. */ void Draw(CDC* pDC, CPoint pt, CXTPImageManagerIcon* pIcon, CSize szIcon, COLORREF clrBK = CLR_NONE, COLORREF clrFG = CLR_NONE, UINT uiFlags = 0); /** * @brief * Cleans all temporary icons. */ void RemoveAll(); /** * @brief * Retrieves the size of images inside HIMAGELIST. * @return * The size of images inside HIMAGELIST. */ CSize GetIconSize() const; /** * @brief * Retrieves the icon handle for an image specified by a command ID. * @param nCommand Command ID. * @return * Icon handle, or NULL. */ HICON GetIconHandle(UINT nCommand) const; /** * @brief * Retrieves the bitmap handle for an image specified by a command ID. * @param nCommand Command ID. * @return * Bitmap handle, or NULL. */ HBITMAP GetBitmapHandle(UINT nCommand) const; private: HIMAGELIST m_hImageList; BOOL m_bDestroyImageList; UINT m_nBaseCommand; CXTPImageManager* m_pImageManager; CMap m_mapIcons; friend class CXTPImageManager; }; /** * @brief * CXTPImageManager is a standalone class. It is used to manipulate icons. */ class _XTP_EXT_CLASS CXTPImageManager : public CXTPCmdTarget { friend class CXTPSingleton; DECLARE_DYNAMIC(CXTPImageManager); public: /** * @brief * Constructs a CXTPImageManager object. */ CXTPImageManager(); /** * @brief * Destroys a CXTPImageManager object, handles cleanup and deallocation. */ ~CXTPImageManager(); public: /** * @brief * Adds the icons. * @param nIDResourceToolBar Toolbar resource identifier. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(UINT nIDResourceToolBar, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param nIDResourceToolBar Resource identifier. * @param nIDResourceBitmap Bitmap resource identifier. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(UINT nIDResourceToolBar, UINT nIDResourceBitmap, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param bmpIcons Bitmap containing the icons to be added. * @param pCommands Pointer to an array of IDs. * @param nCount Number of elements in the array pointed to by lpIDArray. * @param szIcon Size of the icons. * @param imageState Images state. * @param bAlpha TRUE if the bitmap has alpha channel. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(CBitmap& bmpIcons, UINT* pCommands, int nCount, CSize szIcon, XTPImageState imageState = xtpImageNormal, BOOL bAlpha = FALSE); /** * @brief * Adds the icons. * @param nIDResourceToolBar Toolbar resource identifier. * @param bmpIcons Bitmap containing the icons to be added. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(UINT nIDResourceToolBar, CBitmap& bmpIcons, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param nIDResourceBitmap Bitmap resource identifier. * @param pCommands Pointer to an array of IDs. * @param nCount Number of elements in the array pointed to by lpIDArray. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(UINT nIDResourceBitmap, UINT* pCommands, int nCount, CSize szIcon, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param lpszResourceBitmap Bitmap resource identifier. * @param pCommands Pointer to an array of IDs. * @param nCount Number of elements in the array pointed to by lpIDArray. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(LPCTSTR lpszResourceBitmap, UINT* pCommands, int nCount, CSize szIcon, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param imlIcons Image list containing the icons to be added. * @param pCommands Pointer to an array of IDs. * @param nCount Number of elements in the array pointed to by lpIDArray. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(CImageList& imlIcons, UINT* pCommands, int nCount, CSize szIcon, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icons. * @param nIDResourceToolBar Toolbar resource identifier. * @param imlIcons Image list containing the icons to be added. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * * Example: *
	 * static UINT buttons[] =
	 * {
	 *    ID_BACK,
	 *    ID_FORWARD,
	 *    ID_STOP,
	 *    ID_REFRESH,
	 *    ID_HOME
	 * }
	 *
	 * XTPImageManager()->SetMaskColor(RGB(0, 0xFF, 0));
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_SMALL, buttons, _countof(buttons), CSize(16,
	 * 16), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_SMALL, buttons,
	 * _countof(buttons), CSize(16, 16), xtpImageHot);
	 *
	 * XTPImageManager()->SetIcons(IDR_TOOLBAR_NORMAL_LARGE, buttons, _countof(buttons), CSize(24,
	 * 24), xtpImageNormal); XTPImageManager()->SetIcons(IDR_TOOLBAR_HOT_LARGE, buttons,
	 * _countof(buttons), CSize(24, 24), xtpImageHot);
	 * 
* @see * XTPImageState, SetIcon */ BOOL SetIcons(UINT nIDResourceToolBar, CImageList& imlIcons, XTPImageState imageState = xtpImageNormal); /** * @brief * This method loads an icon from an .ico file. * @param lpszFileName Path to .ico file. * @param nIDCommand Icon command. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetIconFromIcoFile(LPCTSTR lpszFileName, UINT nIDCommand, CSize szIcon, XTPImageState imageState); /** * @brief * Call this method to attach images from an HIMAGELIST control to * the image manager. * @param hImageList Pointer to an image list that holds icons. * @param nBaseCommand ID to start numbering icons from the image list. * @param bDestroyImageList TRUE to destroy the image list control after the * icons are copied to the image manager. * By default, this parameter is FALSE. * @return * TRUE if successful, otherwise FALSE. */ BOOL SetImageList(HIMAGELIST hImageList, int nBaseCommand, BOOL bDestroyImageList = FALSE); /** * @brief * Call this method to create a system HIMAGELIST from a bitmap * and add it to the image manager. * @param nIDResourceBitmap Bitmap resource identifier. * @param cx Width of the icons. * @param nBaseCommand ID to start numbering icons from the image list. * @param clrMask Mask color for bitmap. * @return * TRUE if successful, otherwise FALSE. * @details * The SetIcons method loads bitmaps and creates a HICON for each icon in the * bitmap. SetImageList creates only one HIMAGELIST. Use SetImageList * to create only one GDI object for all icons. * @see * SetIcons */ BOOL SetImageList(UINT nIDResourceBitmap, int cx, int nBaseCommand = 0, COLORREF clrMask = (COLORREF)-1); /** * @brief * Adds the icons from another image manager. * @param pImageManager A pointer to another image manager. The icons in * pImageManager will be added to this image manager. */ void AddIcons(CXTPImageManager* pImageManager); /** * @brief * Adds the icons from another image manager. * @param pIconSet A pointer to an image manager icon set. The icons in * pIconSet will be added to this image manager. */ void AddIcons(CXTPImageManagerIconSet* pIconSet); /** * @brief * Adds the icon. * @param hIcon Icon handle to add. * @param nIDCommand Icon identifier. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * @see * XTPImageState, SetIcons */ BOOL SetIcon(const CXTPImageManagerIconHandle& hIcon, UINT nIDCommand, CSize szIcon = 0, XTPImageState imageState = xtpImageNormal); /** * @brief * Adds the icon. * @param nIDResourceIcon Icon resource identifier. * @param nIDCommand Icon identifier. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * @see * XTPImageState, SetIcons */ BOOL SetIcon(UINT nIDResourceIcon, UINT nIDCommand, CSize szIcon = 0, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets the icon. * @param lpszResourceIcon Icon resource identifier. * @param nIDCommand Icon identifier. * @param szIcon Size of the icons. * @param imageState Images state. * @return * TRUE if successful, otherwise FALSE. * @see * XTPImageState, SetIcons */ BOOL SetIcon(LPCTSTR lpszResourceIcon, UINT nIDCommand, CSize szIcon = 0, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param lpResourceType Vector icon resource type name. * @param nIDResource Vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(LPCTSTR lpResourceType, UINT nIDResource, UINT nIDCommand, UINT nWidth, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param lpResourceType Vector icon resource type name. * @param lpResource Vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(LPCTSTR lpResourceType, LPCTSTR lpResource, UINT nIDCommand, UINT nWidth, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hModule Module's instance handle where to look for the icon resource. * @param lpResourceType Vector icon resource type name. * @param nIDResource Vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(HMODULE hModule, LPCTSTR lpResourceType, UINT nIDResource, UINT nIDCommand, UINT nWidth, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hModule Module\'s instance handle where to look for the icon resource. * @param lpResourceType Vector icon resource type name. * @param lpResource Icon resource name. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(HMODULE hModule, LPCTSTR lpResourceType, LPCTSTR lpResource, UINT nIDCommand, UINT nWidth, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hImage Pre-loaded vector image handle. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(CXTPImageManagerVectorImageHandle hImage, UINT nIDCommand, UINT nWidth, XTPImageState imageState = xtpImageNormal); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param lpResourceType Vector icon resource type name. * @param nIDResourceNormal Normal state vector icon resource identifier. * @param nIDResourceDisabled Disabled state vector icon resource identifier. * @param nIDResourceHot Hot state vector icon resource identifier. * @param nIDResourceChecked Checked state vector icon resource identifier. * @param nIDResourcePressed Pressed state vector icon resource identifier. * @param nIDCommand Icon command identifier. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(LPCTSTR lpResourceType, UINT nIDResourceNormal, UINT nIDResourceDisabled, UINT nIDResourceHot, UINT nIDResourceChecked, UINT nIDResourcePressed, UINT nIDCommand, UINT nWidth); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param lpResourceType Vector icon resource type name. * @param lpIDResourceNormal Normal state vector icon resource identifier. * @param lpIDResourceDisabled Disabled state vector icon resource identifier. * @param lpIDResourceHot Hot state vector icon resource identifier. * @param lpIDResourceChecked Checked state vector icon resource identifier. * @param lpIDResourcePressed Pressed state vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(LPCTSTR lpResourceType, LPCTSTR lpIDResourceNormal, LPCTSTR lpIDResourceDisabled, LPCTSTR lpIDResourceHot, LPCTSTR lpIDResourceChecked, LPCTSTR lpIDResourcePressed, UINT nIDCommand, UINT nWidth); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hModule Module's instance handle where to look for the icon resource. * @param lpResourceType Vector icon resource type name. * @param nIDResourceNormal Normal state vector icon resource identifier. * @param nIDResourceDisabled Disabled state vector icon resource identifier. * @param nIDResourceHot Hot state vector icon resource identifier. * @param nIDResourceChecked Checked state vector icon resource identifier. * @param nIDResourcePressed Pressed state vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(HMODULE hModule, LPCTSTR lpResourceType, UINT nIDResourceNormal, UINT nIDResourceDisabled, UINT nIDResourceHot, UINT nIDResourceChecked, UINT nIDResourcePressed, UINT nIDCommand, UINT nWidth); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hModule Module's instance handle where to look for the icon resource. * @param lpResourceType Vector icon resource type name. * @param lpIDResourceNormal Normal state vector icon resource identifier. * @param lpIDResourceDisabled Disabled state vector icon resource identifier. * @param lpIDResourceHot Hot state vector icon resource identifier. * @param lpIDResourceChecked Checked state vector icon resource identifier. * @param lpIDResourcePressed Pressed state vector icon resource identifier. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(HMODULE hModule, LPCTSTR lpResourceType, LPCTSTR lpIDResourceNormal, LPCTSTR lpIDResourceDisabled, LPCTSTR lpIDResourceHot, LPCTSTR lpIDResourceChecked, LPCTSTR lpIDResourcePressed, UINT nIDCommand, UINT nWidth); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param hImageNormal Pre-loaded normal state vector image handle. * @param hImageDisabled Pre-loaded disabled state vector image handle. * @param hImageHot Pre-loaded hot state vector image handle. * @param hImageChecked Pre-loaded checked state vector image handle. * @param hImagePressed Pre-loaded pressed state vector image handle. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(CXTPImageManagerVectorImageHandle hImageNormal, CXTPImageManagerVectorImageHandle hImageDisabled, CXTPImageManagerVectorImageHandle hImageHot, CXTPImageManagerVectorImageHandle hImageChecked, CXTPImageManagerVectorImageHandle hImagePressed, UINT nIDCommand, UINT nWidth); /** * @brief * Sets a vector icon for the specific image state and command identifier. * @param pStream Vector icon data source. * @param nIDCommand Associated command identifier. * @param nWidth Preferred width of the icon. * @param imageState Associated image state. * @return * TRUE if the vector icon image has been successfully added. */ BOOL SetVectorIcon(IStream* pStream, UINT nIDCommand, UINT nWidth, XTPImageState imageState); /** * @brief * Call this method to set the mask color of the bitmaps that will be added. * @param clrMask Mask color to be set. * @return * Previous mask color. */ COLORREF SetMaskColor(COLORREF clrMask); /** * @brief * Retrieves mask color. * @return * Current mask color. */ COLORREF GetMaskColor() const; /** * @brief * Mirrors images around the y-axis, useful in RTL (Right-To-Left) Languages. * @param bDrawReverted If TRUE, images are "flipped" or Mirrored. * This should be used when displaying images in an * application that uses RTL (Right-To-Left) Languages. */ void DrawReverted(BOOL bDrawReverted); /** * @brief * Removes all icons. */ void RemoveAll(); /** * @brief * Removes the specified icon. * @param nIDCommand ID of the icon to be removed. */ void RemoveIcon(UINT nIDCommand); /** * @brief * Redraws all icons. */ void RefreshAll(); /** * @brief * This method is used by CommandBars to add custom icons. * @param hIcon Icon handler to be added. * @return * Identifier of the newly added icon. */ UINT AddCustomIcon(const CXTPImageManagerIconHandle& hIcon); /** * @brief * Call this member to get the icon with the specified ID and width. * @param nCommand ID of the icon to be retrieved. * @param nWidth Width of the icon to be retrieved. * @return * A pointer to a CXTPImageManagerIcon object. */ CXTPImageManagerIcon* GetImage(UINT nCommand, int nWidth = 16) const; /** * @brief * Call this method to determine if a non-scaled image exists in the image manager. * @param nCommand Image identifier to check. * @param nWidth Image width to check. * @return * TRUE if a non-scaled image exists in the image manager. * @see * GetImage */ BOOL IsPrimaryImageExists(UINT nCommand, int nWidth) const; /** * @brief * Call this member to get the icon set with the specified ID. * @param nCommand ID of the icon set to be retrieved. * @return * A pointer to a CXTPImageManagerIconSet object. */ CXTPImageManagerIconSet* GetIconSet(UINT nCommand) const; /** * @brief * Call this member to get the icon set with the specified ID from an image list. * @param nCommand ID of the icon set to be retrieved. * @return * A pointer to a CXTPImageManagerImageList object. */ CXTPImageManagerImageList* GetImageList(UINT nCommand) const; /** * @brief * Retrieves a collection of images. * @return * A CMap object. */ CMap* GetImages(); /** * @brief * Checks if an icon set exists with a specified ID. * @param nCommand ID of the icon set to check for. * @return * TRUE if successful, otherwise FALSE. */ BOOL Lookup(UINT nCommand) const; /** * @brief * Checks if the icons are drawn mirrored/reverted. * @return * TRUE if the icons are drawn mirrored/reverted, * FALSE if icons are drawn normal. */ BOOL IsDrawReverted() const; /** * @brief * Checks if the icons are drawn mirrored/reverted. * @param pDC Pointer to the device context to check. * @return * TRUE if the icons are drawn mirrored/reverted, * FALSE if icons are drawn normal. */ BOOL IsDrawReverted(CDC* pDC) const; /** * @brief * Retrieves resources of a specified size. * @param szIcon Size of resources to retrieve. * @return * Pointer to a CXTPImageManagerResource object containing all * icons of the specified size. */ CXTPImageManagerResource* GetResource(CSize szIcon); /** * @brief * Either reads icons from or writes icons to an archive. * @param ar A CArchive object to serialize to or from. */ void Serialize(CArchive& ar); /** * @brief * Either reads icons from or writes icons to an archive. * @param nCommand Specified command to serialize. * @param ar A CArchive object to serialize to or from. */ void Serialize(UINT nCommand, CArchive& ar); /** * @brief * Either reads icons from or writes icons to an archive. * @param pPX A CXTPPropExchange object to serialize to or from. */ void DoPropExchange(CXTPPropExchange* pPX); /** * @brief * Either reads icons from or writes icons to an archive. * @param nCommand Specified command to serialize. * @param pPX A CXTPPropExchange object to serialize to or from. */ void DoPropExchange(UINT nCommand, CXTPPropExchange* pPX); /** * @brief * Checks if a bitmap with a specified resource has alpha channel. * @param nIDResourceBitmap Resource identifier of the bitmap to check. * @return * TRUE if the bitmap has alpha channel, otherwise FALSE. */ static BOOL AFX_CDECL IsAlphaBitmapResource(UINT nIDResourceBitmap); /** * @brief * Determines if a resource contains a .PNG image. * @param nIDResourceBitmap ID of the resource to check. * @return * TRUE if the resource contains a .PNG image. */ static BOOL AFX_CDECL IsPngBitmapResource(UINT nIDResourceBitmap); /** * @brief * Determines if the OS supports alpha icons. * @return * TRUE if successful; otherwise returns FALSE. * @see * IsAlphaIconsImageListSupported */ BOOL IsAlphaIconsSupported() const; /** * @brief * Determines if the OS supports alpha image list. * @return * TRUE if successful; otherwise returns FALSE * @see * IsAlphaIconsSupported */ static BOOL AFX_CDECL IsAlphaIconsImageListSupported(); /** * @brief * Retrieves the color of the top-left pixel. * @param bmp CBitmap reference. * @param pt Location of the pixel to retrieve. * @return * A COLORREF value that will be used as a transparent color. */ static COLORREF AFX_CDECL GetBitmapMaskColor(CBitmap& bmp, CPoint pt = 0); /** * @brief * Retrieves the color of the top-left pixel. * @param nIDBitmap Bitmap identifier. * @param pt Location of the pixel to retrieve. * @return * A COLORREF value that will be used as a transparent color. */ static COLORREF AFX_CDECL GetBitmapMaskColor(UINT nIDBitmap, CPoint pt = 0); /** * @brief * This method creates a 24bit bitmap from a 32bit alpha bitmap * to draw it in old OSs. * @param bmpAlpha Resource bitmap identifier. * @param clrMask Mask color to be used. * @return * Reduced bitmap handler. */ static HBITMAP AFX_CDECL ResampleAlphaLayer(HBITMAP bmpAlpha, COLORREF clrMask); /** * @brief * This method creates a 24bit bitmap from a 32bit alpha bitmap * to draw it in old OSs. * @param nIDBitmap Resource bitmap identifier. * @param clrMask Mask color to be used. * @return * Reduced bitmap handler. */ static HBITMAP AFX_CDECL ResampleAlphaLayer(UINT nIDBitmap, COLORREF clrMask); /** * @brief * The TransparentBlt function performs a bit-block transfer of the color * data corresponding to a rectangle of pixels from a specified source * device context into a destination device context. * @param hdcDest Handle to destination DC. * @param rcDest Destination rectangle. * @param hdcSrc Handle to source DC. * @param rcSrc Source rectangle. * @param crTransparent Color to make transparent. * @return * TRUE if successful. * @see * AlphaBlend */ BOOL TransparentBlt(HDC hdcDest, const CRect& rcDest, HDC hdcSrc, const CRect& rcSrc, UINT crTransparent) const; /** * @brief * The AlphaBlend function displays bitmaps that have transparent or * semi-transparent pixels. * @param hdcDest Handle to destination DC. * @param rcDest Destination rectangle. * @param hdcSrc Handle to source DC. * @param rcSrc Source rectangle. * @return * TRUE if successful. * @see * TransparentBlt */ BOOL AlphaBlend(HDC hdcDest, const CRect& rcDest, HDC hdcSrc, const CRect& rcSrc) const; /** * @brief * The AlphaBlend function displays bitmaps that have transparent or * semi-transparent pixels. * @param hdcDest Handle to destination DC. * @param rcDest Destination rectangle. * @param hdcSrc Handle to source DC. * @param rcSrc Source rectangle. * @param Transparency Transparency for whole image to draw. * @return * TRUE if successful. * @see * TransparentBlt */ BOOL AlphaBlend2(HDC hdcDest, const CRect& rcDest, HDC hdcSrc, const CRect& rcSrc, BYTE Transparency) const; /** * @brief * This function makes a rectangle in a specified device context disabled. * @param hDC A handle to DC. * @param rcRect A rectangle to be disabled. * @param clrDisabledLight The lightest color of icon to generate. * @param clrDisabledDark The darkest color of icon to generate. * @return * TRUE if successful. * @see * BlackWhiteBitmap */ BOOL DisableBitmap(HDC hDC, const CRect& rcRect, COLORREF clrDisabledLight = (COLORREF)-1, COLORREF clrDisabledDark = (COLORREF)-1); /** * @brief * This function makes a rectangle in a specified device context gray scale. * @param hDC A handle to DC. * @param rcRect A rectangle to be made gray scale. * @param nBlackAndWhiteContrast Black-white contrast as integer from 0 to 255. * @return * TRUE if successful. * @see * DisableBitmap */ BOOL BlackWhiteBitmap(HDC hDC, const CRect& rcRect, int nBlackAndWhiteContrast = 0); /** * @brief * This helper method creates a 32bit bitmap. * @param hDC Pointer to a valid context (can be NULL). * @param iWidth Width of bitmap. * @param iHeight Height of bitmap. * @param lpBits Pointer to bits to return. * @return * The newly created bitmap handle. */ static HBITMAP AFX_CDECL Create32BPPDIBSection(HDC hDC, int iWidth, int iHeight, LPBYTE* lpBits = NULL); /** * @brief * This method adds all icons of a specified size from resources. * @param hInst Module instance to load icons from. * @param lpszResourceName Icon resource identifier. * @param nIDCommand Command to assign for the icon. * @param szIcon Size of the icon to load (0 to load all formats). * @param imageState Image state to assign for the icon. * @return * TRUE if successful. */ BOOL SetIconFromResource(HINSTANCE hInst, LPCTSTR lpszResourceName, UINT nIDCommand, CSize szIcon, XTPImageState imageState); /** * @brief * Fall back for systems without MSIMG32.DLL. * @param hdcDest A handle to the destination device context. * @param nXOriginDest The x-coordinate, in logical units, of the upper-left corner of the * destination rectangle. * @param nYOriginDest The y-coordinate, in logical units, of the upper-left corner of the * destination rectangle. * @param nWidthDest The width, in logical units, of the destination rectangle. * @param nHeightDest The height, in logical units, of the destination rectangle. * @param hdcSrc A handle to the source device context. * @param nXOriginSrc The x-coordinate, in logical units, of the source rectangle. * @param nYOriginSrc The y-coordinate, in logical units, of the source rectangle. * @param nWidthSrc The width, in logical units, of the source rectangle. * @param nHeightSrc The height, in logical units, of the source rectangle. * @param crTransparent The RGB color in the source bitmap to treat as transparent. * @return If the function suceeds True, if not False */ static BOOL AFX_CDECL McTransparentBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT crTransparent); /** * @brief * Pre-multiplies alpha bitmap bits to be used in AlphaBlend. * @param lpBits Alpha bitmap bits. * @param nSize Alpha bitmap bit buffer size in bytes. * @param pbAlpha An optional pointer to a boolean variable that will be set to TRUE * if alpha bits are detected. * @return */ static void AFX_CDECL PreMultiplyAlphaBitmapBits(LPVOID lpBits, SIZE_T nSize, PBOOL pbAlpha = NULL); /** * @brief * Pre-multiplies alpha bitmap bits to be used in AlphaBlend. * @param lpBits Alpha bitmap bits. * @param size Alpha bitmap dimensions. * @param pbAlpha An optional pointer to a boolean variable that will be set to TRUE * if alpha bits are detected. * @return */ static void AFX_CDECL PreMultiplyAlphaBitmapBits(LPVOID lpBits, CSize size, PBOOL pbAlpha = NULL); private: BOOL LoadToolbar(UINT nIDResourceToolBar, UINT*& pItems, int& nCount, CSize& szIcon) const; UINT PasteCustomImage(COleDataObject& data); void CopyImage(UINT nCommand); BOOL SplitBitmap(HBITMAP hbmSource, int nCount, HBITMAP* pDest) const; BOOL IsWindow2000() const; BOOL BitmapsCompatible(LPBITMAP lpbm1, LPBITMAP lpbm2) const; BOOL BlendImages(HBITMAP hbmSrc1, BOOL bRTL1, HBITMAP hbmSrc2, BOOL bRTL2, HBITMAP hbmDst) const; BOOL DoAlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc) const; BOOL DoDisableBitmap(HBITMAP hBmp, COLORREF clrDisabledLight = (COLORREF)-1, COLORREF clrDisabledDark = (COLORREF)-1, int nBlackAndWhiteContrast = -1); BOOL ResourceToStream(HMODULE hModule, LPCTSTR lpResource, LPCTSTR lpResourceType, IStream** ppStream); BOOL FileToStream(LPCTSTR path, IStream** ppStream); public: static double m_dDisabledBrightnessFactor; /**< Brightness factor of disabled icons. */ static double m_dDisabledAlphaFactor; /**< Alpha factor of disabled icons. */ static BOOL m_bAutoResample; /**< TRUE to automatically re-sample alpha bitmaps if msimg32 is not found. */ static CLIPFORMAT m_nImageClipFormat; /**< Clipboard format of icons. */ static CLIPFORMAT m_nAlphaClipFormat; /**< Clipboard format of icons. */ BOOL m_bUseResources; /**< TRUE to create a single bitmap for all icons. */ private: COLORREF m_clrMask; CMap m_mapImages; CArray m_arrImageList; CMap m_mapResources; UINT m_nCustomID; BOOL m_bDrawReverted; private: friend _XTP_EXT_CLASS CXTPImageManager* AFX_CDECL XTPImageManager(); friend class CXTPCustomizeSheet; friend class CXTPImageManagerIcon; friend class CXTPImageManagerIconHandle; /** @cond */ public: static CXTPImageManager* AFX_CDECL FromDispatch(LPDISPATCH pDisp); # ifdef _XTP_ACTIVEX /* x64 #ifdef below is a fix for OLE_HANDLE. While HBITMAP/HICON are still 32-bit on 64-bit Windows, OLE_HANDLE (long) can still be used. But OLE_HANDLE cannot be used as HMODULE which is always 64-bit */ # ifndef _WIN64 # define MODULE_HANDLE OLE_HANDLE # define MODULE_HANDLE_TYPE VTS_I4 # define GDI_HANDLE long # define GDI_HANDLE_TYPE VTS_I4 # else # define MODULE_HANDLE LONG64 # define MODULE_HANDLE_TYPE VTS_I8 # define GDI_HANDLE LONG64 # define GDI_HANDLE_TYPE VTS_I8 # endif DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPImageManager); DECLARE_ENUM_VARIANTLIST(CXTPImageManager) afx_msg long OleGetCount(); afx_msg void OleAddIcon(GDI_HANDLE Handle, long Command, long imageState); afx_msg void OleLoadIcon(LPCTSTR Path, long Command, long imageState); afx_msg void OleLoadBitmap(LPCTSTR Path, const VARIANT& Commands, long imageState); afx_msg void OleAddBitmap(GDI_HANDLE Handle, const VARIANT& Commands, long imageState, BOOL bAlphaBitmap); afx_msg void OleAddIcons(LPDISPATCH lpImageManagerIcons); afx_msg LPDISPATCH OleGetImage(long Command, long Width); afx_msg void OleLoadBitmapFromResource(MODULE_HANDLE Module, long Resource, const VARIANT& Commands, long imageState); afx_msg void OleLoadIconFromResource(MODULE_HANDLE Module, long Resource, long Command, long imageState); afx_msg void OleDoPropExchange(LPDISPATCH lpPropExchage); afx_msg BOOL OleLoadVectorIcon(LPCTSTR Path, long nIDCommand, long nWidth, XTPImageState imageState); afx_msg BOOL OleLoadVectorIconCode(LPCTSTR Code, long nIDCommand, long nWidth, XTPImageState imageState); afx_msg BOOL OleLoadVectorIconFromResource(MODULE_HANDLE Module, LPCTSTR ResourceType, long Resource, long nIDCommand, long nWidth, XTPImageState imageState); # endif /** @endcond */ }; /** * @brief * The CXTPTempColorMask class can be used to temporarily set the color mask * used by XTPImageManager when using images with different color masks. * When the destructor is called, the default mask is reset for XTPImageManager. * * Example: * The following example demonstrates using CXTPTempColorMask: *
 * // temporarily change the mask color.
 * CXTPTempColorMask mask(RGB(0,255,0));
 * XTPImageManager()->SetIcons(IDB_FAVORITES,
 * icons, _countof(icons) CSize(16,16));
 *
 * // set another mask color, CXTPTempColorMask will handle resetting
 * // the default color mask when it is destroyed.
 * XTPImageManager()->SetMaskColor(RGB(255,0,255));
 * XTPImageManager()->SetIcons(IDR_TOOLBAR_MASKED,
 * buttons, _countof(buttons), CSize(16,16), xtpImageNormal);
 * 
* @see * CXTPImageManager::GetMaskColor, CXTPImageManager::SetMaskColor, * CXTPPaintManagerColor::GetStandardColor */ class _XTP_EXT_CLASS CXTPTempColorMask { public: /** * @brief * Constructs a CXTPTempColorMask object, initializes the application * defined mask color, and saves the default mask color * used by XTPImageManager. * @param crNewMask An RGB value that represents the new color mask value * used by XTPImageManager. */ CXTPTempColorMask(COLORREF crNewMask); CXTPTempColorMask(CXTPImageManager* pImageManager, COLORREF crNewMask); /** * @brief * Destructor for CXTPTempColorMask. Resets the default mask color * used by XTPImageManager back to its original color value. */ ~CXTPTempColorMask(); private: COLORREF m_crMask; CXTPImageManager* m_pImageManager; }; /** * @brief * XTPImageManager returns a pointer to the common CXTPImageManager class. * @return * A pointer to the common CXTPImageManager class. * @see * CXTPImageManager */ _XTP_EXT_CLASS CXTPImageManager* AFX_CDECL XTPImageManager(); ////////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE CXTPImageManagerIconHandle::operator HICON() const { return m_hIcon; } AFX_INLINE CXTPImageManagerImageList* CXTPImageManagerIcon::GetImageList() { return m_pImageList; } AFX_INLINE const CXTPImageManagerImageList* CXTPImageManagerIcon::GetImageList() const { return m_pImageList; } AFX_INLINE UINT CXTPImageManagerIconSet::GetID() const { return m_nID; } AFX_INLINE CSize CXTPImageManagerIcon::GetRecommendedExtent() const { return m_szRecommendedExtent; } AFX_INLINE BOOL CXTPImageManagerIcon::IsScaled() const { return FALSE; } AFX_INLINE CXTPImageManagerVectorImageHandle CXTPImageManagerIcon::GetVectorCheckedIcon() const { return GetVectorIcon(xtpImageChecked); } AFX_INLINE CXTPImageManagerVectorImageHandle CXTPImageManagerIcon::GetVectorPressedIcon() const { return GetVectorIcon(xtpImagePressed); } AFX_INLINE CXTPImageManagerVectorImageHandle CXTPImageManagerIcon::GetVectorHotIcon() const { return GetVectorIcon(xtpImageHot); } AFX_INLINE CXTPImageManagerVectorImageHandle CXTPImageManagerIcon::GetVectorDisabledIcon() const { return GetVectorIcon(xtpImageDisabled); } AFX_INLINE BOOL CXTPImageManagerIcon::SetVectorDisabledIcon(CXTPImageManagerVectorImageHandle hIcon) { return SetVectorIcon(hIcon, xtpImageDisabled); } AFX_INLINE BOOL CXTPImageManagerIcon::SetVectorHotIcon(CXTPImageManagerVectorImageHandle hIcon) { return SetVectorIcon(hIcon, xtpImageHot); } AFX_INLINE BOOL CXTPImageManagerIcon::SetVectorCheckedIcon(CXTPImageManagerVectorImageHandle hIcon) { return SetVectorIcon(hIcon, xtpImageChecked); } AFX_INLINE BOOL CXTPImageManagerIcon::SetVectorPressedIcon(CXTPImageManagerVectorImageHandle hIcon) { return SetVectorIcon(hIcon, xtpImagePressed); } AFX_INLINE BOOL CXTPImageManagerIcon::IsRasterIcon() const { return RasterIcon == m_nType; } AFX_INLINE BOOL CXTPImageManagerIcon::IsVectorIcon() const { return VectorIcon == m_nType; } AFX_INLINE BOOL CXTPImageManagerIcon::IsUndefinedIcon() const { return UndefinedIcon == m_nType; } AFX_INLINE CXTPImageManagerIconSet::CIconSetMap* CXTPImageManagerIconSet::GetIcons() { return &m_mapIcons; } AFX_INLINE CMap* CXTPImageManager::GetImages() { return &m_mapImages; } AFX_INLINE void CXTPImageManager::DrawReverted(BOOL bDrawReverted) { m_bDrawReverted = bDrawReverted; } AFX_INLINE BOOL CXTPImageManager::IsDrawReverted() const { return m_bDrawReverted; } AFX_INLINE CXTPTempColorMask::CXTPTempColorMask(COLORREF crNewMask) { m_pImageManager = XTPImageManager(); m_crMask = m_pImageManager->SetMaskColor(crNewMask); } AFX_INLINE CXTPTempColorMask::CXTPTempColorMask(CXTPImageManager* pImageManager, COLORREF crNewMask) { m_pImageManager = pImageManager; m_crMask = m_pImageManager->SetMaskColor(crNewMask); } AFX_INLINE CXTPTempColorMask::~CXTPTempColorMask() { m_pImageManager->SetMaskColor(m_crMask); } /** @endcond */ /** * @brief * Scales bitmap image to the current DPI level. * @param src Source bitmap pointer. * @param dst Destination bitmap pointer. * @return * TRUE if the source bitmap was successfully scaled to the destination bitmap object. */ _XTP_EXT_CLASS BOOL AFX_CDECL XTPScaleBitmap(CBitmap* src, CBitmap* dst); /** @cond */ _XTP_DEPRECATED_IN_FAVOR(XTPScaleBitmap) AFX_INLINE BOOL ScaleBitmap(CBitmap* src, CBitmap* dst) { return XTPScaleBitmap(src, dst); } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif //#if !defined(__XTPIMAGEMANAGER_H__) /** @endcond */