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