]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xrc/xmlreshandler.h
Applied rowspan patch #15276 (dghart)
[wxWidgets.git] / include / wx / xrc / xmlreshandler.h
CommitLineData
a3b9c43b
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/xrc/xmlreshandler.cpp
3// Purpose: XML resource handler
4// Author: Steven Lamerton
5// Created: 2011/01/26
6// RCS-ID: $id$
7// Copyright: (c) 2011 Steven Lamerton
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_XRC_XMLRESHANDLER_H_
12#define _WX_XRC_XMLRESHANDLER_H_
13
14#include "wx/defs.h"
15
16#if wxUSE_XRC
17
18#include "wx/string.h"
19#include "wx/artprov.h"
20#include "wx/colour.h"
a3b9c43b
VZ
21#include "wx/filesys.h"
22#include "wx/imaglist.h"
65b139c8 23#include "wx/window.h"
a3b9c43b 24
bdb4b832
VZ
25class WXDLLIMPEXP_FWD_ADV wxAnimation;
26
a3b9c43b
VZ
27class WXDLLIMPEXP_FWD_XML wxXmlNode;
28class WXDLLIMPEXP_FWD_XML wxXmlResource;
29
30class WXDLLIMPEXP_FWD_CORE wxXmlResourceHandler;
31
32// Helper macro used by the classes derived from wxXmlResourceHandler but also
33// by wxXmlResourceHandler implementation itself.
34#define XRC_ADD_STYLE(style) AddStyle(wxT(#style), style)
35
36// Abstract base class for the implementation object used by
37// wxXmlResourceHandlerImpl. The real implementation is in
38// wxXmlResourceHandlerImpl class in the "xrc" library while this class is in
39// the "core" itself -- but it is so small that it doesn't matter.
40
41class WXDLLIMPEXP_CORE wxXmlResourceHandlerImplBase : public wxObject
42{
43public:
44 // Constructor.
45 wxXmlResourceHandlerImplBase(wxXmlResourceHandler *handler)
46 : m_handler(handler)
47 {}
48
49 // Destructor.
50 virtual ~wxXmlResourceHandlerImplBase() {}
51
52 virtual wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
53 wxObject *instance) = 0;
54 virtual bool IsOfClass(wxXmlNode *node, const wxString& classname) const = 0;
55 virtual wxString GetNodeContent(const wxXmlNode *node) = 0;
56 virtual bool HasParam(const wxString& param) = 0;
57 virtual wxXmlNode *GetParamNode(const wxString& param) = 0;
58 virtual wxString GetParamValue(const wxString& param) = 0;
59 virtual wxString GetParamValue(const wxXmlNode* node) = 0;
60 virtual int GetStyle(const wxString& param = wxT("style"), int defaults = 0) = 0;
61 virtual wxString GetText(const wxString& param, bool translate = true) = 0;
62 virtual int GetID() = 0;
63 virtual wxString GetName() = 0;
64 virtual bool GetBool(const wxString& param, bool defaultv = false) = 0;
65 virtual long GetLong(const wxString& param, long defaultv = 0) = 0;
66 virtual float GetFloat(const wxString& param, float defaultv = 0) = 0;
67 virtual wxColour GetColour(const wxString& param,
68 const wxColour& defaultv = wxNullColour) = 0;
69 virtual wxSize GetSize(const wxString& param = wxT("size"),
70 wxWindow *windowToUse = NULL) = 0;
71 virtual wxPoint GetPosition(const wxString& param = wxT("pos")) = 0;
72 virtual wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0,
73 wxWindow *windowToUse = NULL) = 0;
74 virtual wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT) = 0;
75 virtual wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
76 const wxArtClient& defaultArtClient = wxART_OTHER,
77 wxSize size = wxDefaultSize) = 0;
78 virtual wxBitmap GetBitmap(const wxXmlNode* node,
79 const wxArtClient& defaultArtClient = wxART_OTHER,
80 wxSize size = wxDefaultSize) = 0;
81 virtual wxIcon GetIcon(const wxString& param = wxT("icon"),
82 const wxArtClient& defaultArtClient = wxART_OTHER,
83 wxSize size = wxDefaultSize) = 0;
84 virtual wxIcon GetIcon(const wxXmlNode* node,
85 const wxArtClient& defaultArtClient = wxART_OTHER,
86 wxSize size = wxDefaultSize) = 0;
87 virtual wxIconBundle GetIconBundle(const wxString& param,
88 const wxArtClient& defaultArtClient = wxART_OTHER) = 0;
89 virtual wxImageList *GetImageList(const wxString& param = wxT("imagelist")) = 0;
90
91#if wxUSE_ANIMATIONCTRL
bdb4b832 92 virtual wxAnimation* GetAnimation(const wxString& param = wxT("animation")) = 0;
a3b9c43b
VZ
93#endif
94
95 virtual wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL) = 0;
96 virtual bool GetBoolAttr(const wxString& attr, bool defaultv) = 0;
97 virtual void SetupWindow(wxWindow *wnd) = 0;
98 virtual void CreateChildren(wxObject *parent, bool this_hnd_only = false) = 0;
99 virtual void CreateChildrenPrivately(wxObject *parent,
100 wxXmlNode *rootnode = NULL) = 0;
101 virtual wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent,
102 wxObject *instance = NULL) = 0;
103
104#if wxUSE_FILESYSTEM
105 virtual wxFileSystem& GetCurFileSystem() = 0;
106#endif
107 virtual void ReportError(wxXmlNode *context, const wxString& message) = 0;
108 virtual void ReportError(const wxString& message) = 0;
109 virtual void ReportParamError(const wxString& param, const wxString& message) = 0;
110
111 wxXmlResourceHandler* GetHandler() { return m_handler; }
112
113protected:
114 wxXmlResourceHandler *m_handler;
115};
116
117// Base class for all XRC handlers.
118//
119// Notice that this class is defined in the core library itself and so can be
120// used as the base class by classes in any GUI library. However to actually be
121// usable, it needs to be registered with wxXmlResource which implies linking
122// the application with the xrc library.
123//
124// Also note that all the methods forwarding to GetImpl() are documented only
125// in wxXmlResourceHandlerImpl in wx/xrc/xmlres.h to avoid duplication.
126
127class WXDLLIMPEXP_CORE wxXmlResourceHandler : public wxObject
128{
129public:
130 // Constructor creates an unusable object, before anything can be done with
131 // it, SetImpl() needs to be called as done by wxXmlResource::AddHandler().
132 wxXmlResourceHandler()
133 {
8e912ebf
VZ
134 m_node = NULL;
135 m_parent =
136 m_instance = NULL;
137 m_parentAsWindow = NULL;
138 m_resource = NULL;
139
a3b9c43b
VZ
140 m_impl = NULL;
141 }
142
143 // This should be called exactly once.
144 void SetImpl(wxXmlResourceHandlerImplBase* impl)
145 {
146 wxASSERT_MSG( !m_impl, wxS("Should be called exactly once") );
147
148 m_impl = impl;
149 }
150
151
152 // Destructor.
153 virtual ~wxXmlResourceHandler()
154 {
155 delete m_impl;
156 }
157
158 wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
159 wxObject *instance)
160 {
161 return GetImpl()->CreateResource(node, parent, instance);
162 }
163
164 // This one is called from CreateResource after variables
165 // were filled.
166 virtual wxObject *DoCreateResource() = 0;
167
168 // Returns true if it understands this node and can create
169 // a resource from it, false otherwise.
170 virtual bool CanHandle(wxXmlNode *node) = 0;
171
172
173 void SetParentResource(wxXmlResource *res)
174 {
175 m_resource = res;
176 }
177
178
179 // These methods are not forwarded to wxXmlResourceHandlerImpl because they
180 // are called from the derived classes ctors and so before SetImpl() can be
181 // called.
182
183 // Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags
184 // understood by this handler.
185 void AddStyle(const wxString& name, int value);
186
187 // Add styles common to all wxWindow-derived classes.
188 void AddWindowStyles();
189
190protected:
191 // Everything else is simply forwarded to wxXmlResourceHandlerImpl.
192 void ReportError(wxXmlNode *context, const wxString& message)
193 {
0c118232 194 GetImpl()->ReportError(context, message);
a3b9c43b
VZ
195 }
196 void ReportError(const wxString& message)
197 {
0c118232 198 GetImpl()->ReportError(message);
a3b9c43b
VZ
199 }
200 void ReportParamError(const wxString& param, const wxString& message)
201 {
0c118232 202 GetImpl()->ReportParamError(param, message);
a3b9c43b
VZ
203 }
204
205 bool IsOfClass(wxXmlNode *node, const wxString& classname) const
206 {
207 return GetImpl()->IsOfClass(node, classname);
208 }
209 wxString GetNodeContent(const wxXmlNode *node)
210 {
211 return GetImpl()->GetNodeContent(node);
212 }
213 bool HasParam(const wxString& param)
214 {
215 return GetImpl()->HasParam(param);
216 }
217
218 wxXmlNode *GetParamNode(const wxString& param)
219 {
220 return GetImpl()->GetParamNode(param);
221 }
222 wxString GetParamValue(const wxString& param)
223 {
224 return GetImpl()->GetParamValue(param);
225 }
226 wxString GetParamValue(const wxXmlNode* node)
227 {
228 return GetImpl()->GetParamValue(node);
229 }
230 int GetStyle(const wxString& param = wxT("style"), int defaults = 0)
231 {
232 return GetImpl()->GetStyle(param, defaults);
233 }
234 wxString GetText(const wxString& param, bool translate = true)
235 {
236 return GetImpl()->GetText(param, translate);
237 }
238 int GetID() const
239 {
240 return GetImpl()->GetID();
241 }
242 wxString GetName()
243 {
244 return GetImpl()->GetName();
245 }
246 bool GetBool(const wxString& param, bool defaultv = false)
247 {
248 return GetImpl()->GetBool(param, defaultv);
249 }
250 long GetLong(const wxString& param, long defaultv = 0)
251 {
252 return GetImpl()->GetLong(param, defaultv);
253 }
254 float GetFloat(const wxString& param, float defaultv = 0)
255 {
256 return GetImpl()->GetFloat(param, defaultv);
257 }
258 wxColour GetColour(const wxString& param,
259 const wxColour& defaultv = wxNullColour)
260 {
261 return GetImpl()->GetColour(param, defaultv);
262 }
263 wxSize GetSize(const wxString& param = wxT("size"),
264 wxWindow *windowToUse = NULL)
265 {
266 return GetImpl()->GetSize(param, windowToUse);
267 }
268 wxPoint GetPosition(const wxString& param = wxT("pos"))
269 {
270 return GetImpl()->GetPosition(param);
271 }
272 wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0,
273 wxWindow *windowToUse = NULL)
274 {
275 return GetImpl()->GetDimension(param, defaultv, windowToUse);
276 }
277 wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT)
278 {
279 return GetImpl()->GetDirection(param, dir);
280 }
281 wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
282 const wxArtClient& defaultArtClient = wxART_OTHER,
283 wxSize size = wxDefaultSize)
284 {
285 return GetImpl()->GetBitmap(param, defaultArtClient, size);
286 }
287 wxBitmap GetBitmap(const wxXmlNode* node,
288 const wxArtClient& defaultArtClient = wxART_OTHER,
289 wxSize size = wxDefaultSize)
290 {
291 return GetImpl()->GetBitmap(node, defaultArtClient, size);
292 }
293 wxIcon GetIcon(const wxString& param = wxT("icon"),
294 const wxArtClient& defaultArtClient = wxART_OTHER,
295 wxSize size = wxDefaultSize)
296 {
297 return GetImpl()->GetIcon(param, defaultArtClient, size);
298 }
299 wxIcon GetIcon(const wxXmlNode* node,
300 const wxArtClient& defaultArtClient = wxART_OTHER,
301 wxSize size = wxDefaultSize)
302 {
303 return GetImpl()->GetIcon(node, defaultArtClient, size);
304 }
305 wxIconBundle GetIconBundle(const wxString& param,
306 const wxArtClient& defaultArtClient = wxART_OTHER)
307 {
308 return GetImpl()->GetIconBundle(param, defaultArtClient);
309 }
310 wxImageList *GetImageList(const wxString& param = wxT("imagelist"))
311 {
312 return GetImpl()->GetImageList(param);
313 }
314
315#if wxUSE_ANIMATIONCTRL
bdb4b832 316 wxAnimation* GetAnimation(const wxString& param = wxT("animation"))
a3b9c43b
VZ
317 {
318 return GetImpl()->GetAnimation(param);
319 }
320#endif
321
322 wxFont GetFont(const wxString& param = wxT("font"),
323 wxWindow* parent = NULL)
324 {
325 return GetImpl()->GetFont(param, parent);
326 }
327 bool GetBoolAttr(const wxString& attr, bool defaultv)
328 {
329 return GetImpl()->GetBoolAttr(attr, defaultv);
330 }
331 void SetupWindow(wxWindow *wnd)
332 {
333 GetImpl()->SetupWindow(wnd);
334 }
335 void CreateChildren(wxObject *parent, bool this_hnd_only = false)
336 {
337 GetImpl()->CreateChildren(parent, this_hnd_only);
338 }
339 void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL)
340 {
341 GetImpl()->CreateChildrenPrivately(parent, rootnode);
342 }
343 wxObject *CreateResFromNode(wxXmlNode *node,
344 wxObject *parent, wxObject *instance = NULL)
345 {
346 return GetImpl()->CreateResFromNode(node, parent, instance);
347 }
348
349#if wxUSE_FILESYSTEM
350 wxFileSystem& GetCurFileSystem()
351 {
352 return GetImpl()->GetCurFileSystem();
353 }
354#endif
355
356 // Variables (filled by CreateResource)
357 wxXmlNode *m_node;
358 wxString m_class;
359 wxObject *m_parent, *m_instance;
360 wxWindow *m_parentAsWindow;
361 wxXmlResource *m_resource;
362
c6f41dc8
RD
363 // provide method access to those member variables
364 wxXmlResource* GetResource() const { return m_resource; }
365 wxXmlNode* GetNode() const { return m_node; }
366 wxString GetClass() const { return m_class; }
367 wxObject* GetParent() const { return m_parent; }
368 wxObject* GetInstance() const { return m_instance; }
369 wxWindow* GetParentAsWindow() const { return m_parentAsWindow; }
370
371
a3b9c43b
VZ
372 wxArrayString m_styleNames;
373 wxArrayInt m_styleValues;
374
375 friend class wxXmlResourceHandlerImpl;
376
377private:
378 // This is supposed to never return NULL because SetImpl() should have been
379 // called.
380 wxXmlResourceHandlerImplBase* GetImpl() const;
381
382 wxXmlResourceHandlerImplBase *m_impl;
383
384 wxDECLARE_ABSTRACT_CLASS(wxXmlResourceHandler);
385};
386
387#endif // wxUSE_XRC
388
389#endif // _WX_XRC_XMLRESHANDLER_H_