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