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