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