gdiimage.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/os2/gdiimage.h
  3. // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor
  4. // under OS/2
  5. // Author: David Webster (adapted from msw version by Vadim Zeitlin)
  6. // Modified by:
  7. // Created: 20.11.99
  8. // Copyright: (c) 1999 David Webster
  9. // Licence: wxWindows licence
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // NB: this is a private header, it is not intended to be directly included by
  12. // user code (but may be included from other, public, wxWin headers
  13. #ifndef _WX_OS2_GDIIMAGE_H_
  14. #define _WX_OS2_GDIIMAGE_H_
  15. #include "wx/gdiobj.h" // base class
  16. #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID
  17. #include "wx/list.h"
  18. class WXDLLIMPEXP_FWD_CORE wxGDIImageRefData;
  19. class WXDLLIMPEXP_FWD_CORE wxGDIImageHandler;
  20. class WXDLLIMPEXP_FWD_CORE wxGDIImage;
  21. WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
  22. // ----------------------------------------------------------------------------
  23. // wxGDIImageRefData: common data fields for all derived classes
  24. // ----------------------------------------------------------------------------
  25. class WXDLLIMPEXP_CORE wxGDIImageRefData : public wxGDIRefData
  26. {
  27. public:
  28. wxGDIImageRefData()
  29. {
  30. m_nWidth = m_nHeight = m_nDepth = 0;
  31. m_hHandle = 0;
  32. }
  33. // accessors
  34. virtual bool IsOk() const
  35. {
  36. if (m_hHandle == 0)
  37. return false;
  38. return true;
  39. }
  40. void SetSize( int nW
  41. ,int nH
  42. )
  43. { m_nWidth = nW; m_nHeight = nH; }
  44. // free the ressources we allocated
  45. virtual void Free() { }
  46. // for compatibility, the member fields are public
  47. // the size of the image
  48. int m_nWidth;
  49. int m_nHeight;
  50. // the depth of the image
  51. int m_nDepth;
  52. // the handle to it
  53. union
  54. {
  55. WXHANDLE m_hHandle; // for untyped access
  56. WXHBITMAP m_hBitmap;
  57. WXHICON m_hIcon;
  58. WXHCURSOR m_hCursor;
  59. };
  60. unsigned int m_uId;
  61. };
  62. // ----------------------------------------------------------------------------
  63. // wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
  64. // ----------------------------------------------------------------------------
  65. class WXDLLIMPEXP_CORE wxGDIImageHandler : public wxObject
  66. {
  67. public:
  68. // ctor
  69. wxGDIImageHandler() { m_lType = wxBITMAP_TYPE_INVALID; }
  70. wxGDIImageHandler( const wxString& rName
  71. ,const wxString& rExt
  72. ,wxBitmapType lType
  73. )
  74. : m_sName(rName)
  75. , m_sExtension(rExt)
  76. {
  77. m_lType = lType;
  78. }
  79. // accessors
  80. void SetName(const wxString& rName) { m_sName = rName; }
  81. void SetExtension(const wxString& rExt) { m_sExtension = rExt; }
  82. void SetType(wxBitmapType lType) { m_lType = lType; }
  83. wxString GetName() const { return m_sName; }
  84. wxString GetExtension() const { return m_sExtension; }
  85. wxBitmapType GetType() const { return m_lType; }
  86. // real handler operations: to implement in derived classes
  87. virtual bool Create( wxGDIImage* pImage
  88. ,const void* pData
  89. ,wxBitmapType lFlags
  90. ,int nWidth
  91. ,int nHeight
  92. ,int nDepth = 1
  93. ) = 0;
  94. virtual bool Load( wxGDIImage* pImage
  95. ,const wxString& rName
  96. ,HPS hPs
  97. ,wxBitmapType lFlags
  98. ,int nDesiredWidth
  99. ,int nDesiredHeight
  100. ) = 0;
  101. virtual bool Load( wxGDIImage* pImage
  102. ,int nId
  103. ,wxBitmapType lFlags
  104. ,int nDesiredWidth
  105. ,int nDesiredHeight
  106. ) = 0;
  107. virtual bool Save( const wxGDIImage* pImage
  108. ,const wxString& rName
  109. ,wxBitmapType lType
  110. ) const = 0;
  111. protected:
  112. wxString m_sName;
  113. wxString m_sExtension;
  114. wxBitmapType m_lType;
  115. }; // end of wxGDIImageHandler
  116. // ----------------------------------------------------------------------------
  117. // wxGDIImage: this class supports GDI image handlers which may be registered
  118. // dynamically and will be used for loading/saving the images in the specified
  119. // format. It also falls back to wxImage if no appropriate image is found.
  120. // ----------------------------------------------------------------------------
  121. class WXDLLIMPEXP_CORE wxGDIImage : public wxGDIObject
  122. {
  123. public:
  124. // handlers list interface
  125. static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
  126. static void AddHandler(wxGDIImageHandler* hHandler);
  127. static void InsertHandler(wxGDIImageHandler* hHandler);
  128. static bool RemoveHandler(const wxString& rName);
  129. static wxGDIImageHandler* FindHandler(const wxString& rName);
  130. static wxGDIImageHandler* FindHandler(const wxString& rExtension, wxBitmapType lType);
  131. static wxGDIImageHandler* FindHandler(wxBitmapType lType);
  132. static void InitStandardHandlers();
  133. static void CleanUpHandlers();
  134. // access to the ref data casted to the right type
  135. wxGDIImageRefData *GetGDIImageData() const
  136. { return (wxGDIImageRefData *)m_refData; }
  137. // create data if we don't have it yet
  138. void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); }
  139. // accessors
  140. WXHANDLE GetHandle() const
  141. {
  142. wxGDIImageRefData* pData;
  143. pData = GetGDIImageData();
  144. if (!pData)
  145. return 0;
  146. else
  147. return pData->m_hHandle;
  148. }
  149. void SetHandle(WXHANDLE hHandle)
  150. {
  151. wxGDIImageRefData* pData;
  152. EnsureHasData();
  153. pData = GetGDIImageData();
  154. pData->m_hHandle = hHandle;
  155. }
  156. int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth; }
  157. int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight; }
  158. int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth; }
  159. wxSize GetSize() const
  160. {
  161. return IsNull() ? wxSize(0,0) :
  162. wxSize(GetGDIImageData()->m_nWidth, GetGDIImageData()->m_nHeight);
  163. }
  164. void SetWidth(int nW) { EnsureHasData(); GetGDIImageData()->m_nWidth = nW; }
  165. void SetHeight(int nH) { EnsureHasData(); GetGDIImageData()->m_nHeight = nH; }
  166. void SetDepth(int nD) { EnsureHasData(); GetGDIImageData()->m_nDepth = nD; }
  167. void SetSize( int nW
  168. ,int nH
  169. )
  170. {
  171. EnsureHasData();
  172. GetGDIImageData()->SetSize(nW, nH);
  173. }
  174. void SetSize(const wxSize& rSize) { SetSize(rSize.x, rSize.y); }
  175. unsigned int GetId(void) const
  176. {
  177. wxGDIImageRefData* pData;
  178. pData = GetGDIImageData();
  179. if (!pData)
  180. return 0;
  181. else
  182. return pData->m_uId;
  183. } // end of WxWinGdi_CGDIImage::GetId
  184. void SetId(unsigned int uId)
  185. {
  186. wxGDIImageRefData* pData;
  187. EnsureHasData();
  188. pData = GetGDIImageData();
  189. pData->m_uId = uId;
  190. }
  191. // forward some of base class virtuals to wxGDIImageRefData
  192. bool FreeResource(bool bForce = false);
  193. virtual WXHANDLE GetResourceHandle() const;
  194. protected:
  195. // create the data for the derived class here
  196. virtual wxGDIImageRefData* CreateData() const = 0;
  197. virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); }
  198. // we can't [efficiently] clone objects of this class
  199. virtual wxGDIRefData *
  200. CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
  201. {
  202. wxFAIL_MSG( wxT("must be implemented if used") );
  203. return NULL;
  204. }
  205. static wxGDIImageHandlerList ms_handlers;
  206. };
  207. #endif // _WX_MSW_GDIIMAGE_H_