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