]>
Commit | Line | Data |
---|---|---|
0d0512bd VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: include/wx/msw/gdiimage.h | |
3 | // Purpose: wxGDIImage class: base class for wxBitmap, wxIcon, wxCursor | |
4 | // under MSW | |
5 | // Author: Vadim Zeitlin | |
6 | // Modified by: | |
7 | // Created: 20.11.99 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
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_MSW_GDIIMAGE_H_ | |
17 | #define _WX_MSW_GDIIMAGE_H_ | |
18 | ||
19 | #ifdef __GNUG__ | |
20 | #pragma interface "gdiimage.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/gdiobj.h" // base class | |
10a0bdb1 VZ |
24 | #include "wx/gdicmn.h" // wxBITMAP_TYPE_INVALID |
25 | #include "wx/list.h" | |
0d0512bd VZ |
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_width = m_height = m_depth = 0; | |
41 | ||
42 | m_handle = 0; | |
43 | ||
44 | #if WXWIN_COMPATIBILITY_2 | |
45 | m_ok = FALSE; | |
46 | #endif // WXWIN_COMPATIBILITY_2 | |
47 | } | |
48 | ||
49 | // accessors | |
50 | bool IsOk() const { return m_handle != 0; } | |
51 | ||
52 | void SetSize(int w, int h) { m_width = w; m_height = h; } | |
53 | ||
54 | // free the ressources we allocated | |
55 | virtual void Free() = 0; | |
56 | ||
57 | // for compatibility, the member fields are public | |
58 | ||
59 | // the size of the image | |
60 | int m_width, m_height; | |
61 | ||
62 | // the depth of the image | |
63 | int m_depth; | |
64 | ||
65 | // the handle to it | |
66 | union | |
67 | { | |
68 | WXHANDLE m_handle; // for untyped access | |
69 | WXHBITMAP m_hBitmap; | |
70 | WXHICON m_hIcon; | |
71 | WXHCURSOR m_hCursor; | |
72 | }; | |
73 | ||
74 | // this filed is redundant and using it is error prone but keep it for | |
75 | // backwards compatibility | |
76 | #if WXWIN_COMPATIBILITY_2 | |
77 | void SetOk() { m_ok = m_handle != 0; } | |
78 | ||
79 | bool m_ok; | |
80 | #endif // WXWIN_COMPATIBILITY_2 | |
81 | }; | |
82 | ||
83 | // ---------------------------------------------------------------------------- | |
84 | // wxGDIImageHandler: a class which knows how to load/save wxGDIImages. | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | class WXDLLEXPORT wxGDIImageHandler : public wxObject | |
88 | { | |
89 | public: | |
90 | // ctor | |
91 | wxGDIImageHandler() { m_type = wxBITMAP_TYPE_INVALID; } | |
92 | wxGDIImageHandler(const wxString& name, | |
93 | const wxString& ext, | |
94 | long type) | |
95 | : m_name(name), m_extension(ext) | |
96 | { | |
97 | m_type = type; | |
98 | } | |
99 | ||
100 | // accessors | |
101 | void SetName(const wxString& name) { m_name = name; } | |
102 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
103 | void SetType(long type) { m_type = type; } | |
104 | ||
105 | wxString GetName() const { return m_name; } | |
106 | wxString GetExtension() const { return m_extension; } | |
107 | long GetType() const { return m_type; } | |
108 | ||
109 | // real handler operations: to implement in derived classes | |
110 | virtual bool Create(wxGDIImage *image, | |
111 | void *data, | |
112 | long flags, | |
113 | int width, int height, int depth = 1) = 0; | |
114 | virtual bool Load(wxGDIImage *image, | |
115 | const wxString& name, | |
116 | long flags, | |
117 | int desiredWidth, int desiredHeight) = 0; | |
118 | virtual bool Save(wxGDIImage *image, | |
119 | const wxString& name, | |
120 | int type) = 0; | |
121 | ||
122 | protected: | |
123 | wxString m_name; | |
124 | wxString m_extension; | |
125 | long m_type; | |
126 | }; | |
127 | ||
128 | // ---------------------------------------------------------------------------- | |
129 | // wxGDIImage: this class supports GDI image handlers which may be registered | |
130 | // dynamically and will be used for loading/saving the images in the specified | |
131 | // format. It also falls back to wxImage if no appropriate image is found. | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
134 | class WXDLLEXPORT wxGDIImage : public wxGDIObject | |
135 | { | |
136 | public: | |
137 | // handlers list interface | |
138 | static wxList& GetHandlers() { return ms_handlers; } | |
139 | ||
140 | static void AddHandler(wxGDIImageHandler *handler); | |
141 | static void InsertHandler(wxGDIImageHandler *handler); | |
142 | static bool RemoveHandler(const wxString& name); | |
143 | ||
144 | static wxGDIImageHandler *FindHandler(const wxString& name); | |
145 | static wxGDIImageHandler *FindHandler(const wxString& extension, long type); | |
146 | static wxGDIImageHandler *FindHandler(long type); | |
147 | ||
148 | static void InitStandardHandlers(); | |
149 | static void CleanUpHandlers(); | |
150 | ||
151 | // access to the ref data casted to the right type | |
152 | wxGDIImageRefData *GetGDIImageData() const | |
153 | { return (wxGDIImageRefData *)m_refData; } | |
154 | ||
155 | // create data if we don't have it yet | |
156 | void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); } | |
157 | ||
158 | // accessors | |
159 | WXHANDLE GetHandle() const | |
160 | { return IsNull() ? 0 : GetGDIImageData()->m_handle; } | |
161 | void SetHandle(WXHANDLE handle) | |
162 | { EnsureHasData(); GetGDIImageData()->m_handle = handle; } | |
163 | ||
164 | bool Ok() const { return GetHandle() != 0; } | |
165 | ||
166 | int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; } | |
167 | int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; } | |
168 | int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; } | |
169 | ||
170 | void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; } | |
171 | void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; } | |
172 | void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; } | |
173 | ||
174 | void SetSize(int w, int h) | |
175 | { | |
176 | EnsureHasData(); | |
177 | GetGDIImageData()->SetSize(w, h); | |
178 | } | |
179 | void SetSize(const wxSize& size) { SetSize(size.x, size.y); } | |
180 | ||
181 | // forward some of base class virtuals to wxGDIImageRefData | |
182 | bool FreeResource(bool force = FALSE); | |
183 | virtual WXHANDLE GetResourceHandle(); | |
184 | ||
185 | protected: | |
186 | // create the data for the derived class here | |
187 | virtual wxGDIImageRefData *CreateData() const = 0; | |
188 | ||
189 | static wxList ms_handlers; | |
190 | }; | |
191 | ||
192 | #endif // _WX_MSW_GDIIMAGE_H_ |