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