/** * @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
* 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* // 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