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