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