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