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