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