]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/gdiimage.h
Applied patch [ 1181975 ] [wxMSW] Removes all flicker from wxNotebook
[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
65571936 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
27class WXDLLEXPORT wxGDIImageRefData;
28class WXDLLEXPORT wxGDIImageHandler;
29class WXDLLEXPORT wxGDIImage;
30
258f5b3e
DW
31WX_DECLARE_EXPORTED_LIST(wxGDIImageHandler, wxGDIImageHandlerList);
32
4f72fe4f
DW
33// ----------------------------------------------------------------------------
34// wxGDIImageRefData: common data fields for all derived classes
35// ----------------------------------------------------------------------------
36
37class WXDLLEXPORT wxGDIImageRefData : public wxGDIRefData
38{
39public:
40 wxGDIImageRefData()
41 {
42 m_nWidth = m_nHeight = m_nDepth = 0;
43
44 m_hHandle = 0;
4f72fe4f
DW
45 }
46
47 // accessors
9add53a4
DW
48 bool IsOk() const
49 {
50 if (m_hHandle == 0)
51 return FALSE;
52 return TRUE;
53 }
4f72fe4f
DW
54
55 void SetSize( int nW
56 ,int nH
57 )
58 { m_nWidth = nW; m_nHeight = nH; }
59
60 // free the ressources we allocated
9add53a4 61 virtual void Free() { };
4f72fe4f
DW
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
8bb6da4a 81 UINT m_uId;
4f72fe4f
DW
82};
83
84// ----------------------------------------------------------------------------
85// wxGDIImageHandler: a class which knows how to load/save wxGDIImages.
86// ----------------------------------------------------------------------------
87
88class WXDLLEXPORT wxGDIImageHandler : public wxObject
89{
90public:
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
97507cce 122 ,HPS hPs
4f72fe4f
DW
123 ,long lFlags
124 ,int nDesiredWidth
125 ,int nDesiredHeight
126 ) = 0;
b6f4144e
DW
127 virtual bool Load( wxGDIImage* pImage
128 ,int nId
129 ,long lFlags
130 ,int nDesiredWidth
131 ,int nDesiredHeight
132 ) = 0;
4f72fe4f
DW
133 virtual bool Save( wxGDIImage* pImage
134 ,const wxString& rName
135 ,int lType
136 ) = 0;
137
138protected:
139 wxString m_sName;
140 wxString m_sExtension;
141 long m_lType;
b6f4144e 142}; // end of wxGDIImageHandler
4f72fe4f
DW
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
150class WXDLLEXPORT wxGDIImage : public wxGDIObject
151{
152public:
153 // handlers list interface
258f5b3e 154 static wxGDIImageHandlerList& GetHandlers() { return ms_handlers; }
4f72fe4f
DW
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
9add53a4
DW
176 {
177 wxGDIImageRefData* pData;
178
179 pData = GetGDIImageData();
180 if (!pData)
181 return 0;
182 else
183 return pData->m_hHandle;
184 }
4f72fe4f 185 void SetHandle(WXHANDLE hHandle)
9add53a4
DW
186 {
187 wxGDIImageRefData* pData;
188
189 EnsureHasData();
190 pData = GetGDIImageData();
191 pData->m_hHandle = hHandle;
192 }
4f72fe4f
DW
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
8bb6da4a
DW
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 }
4f72fe4f
DW
231 // forward some of base class virtuals to wxGDIImageRefData
232 bool FreeResource(bool bForce = FALSE);
233 virtual WXHANDLE GetResourceHandle();
234
235protected:
236 // create the data for the derived class here
237 virtual wxGDIImageRefData* CreateData() const = 0;
238
258f5b3e 239 static wxGDIImageHandlerList ms_handlers;
4f72fe4f
DW
240};
241
242#endif // _WX_MSW_GDIIMAGE_H_