1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrappers for the XML based Resource system
7 // Created: 4-June-2001
9 // Copyright: (c) 2001 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include "wx/xrc/xmlres.h"
21 //---------------------------------------------------------------------------
24 %include my_typemaps.i
33 //---------------------------------------------------------------------------
35 enum wxXmlResourceFlags
38 wxXRC_NO_SUBCLASSING = 2
42 // This class holds XML resources from one or more .xml files
43 // (or derived forms, either binary or zipped -- see manual for
46 class wxXmlResource : public wxObject
50 // Flags: wxXRC_USE_LOCALE
51 // translatable strings will be translated via _()
52 // wxXRC_NO_SUBCLASSING
53 // subclass property of object nodes will be ignored
54 // (useful for previews in XRC editors)
55 %name(wxXmlResourceEmpty)wxXmlResource(int flags = wxXRC_USE_LOCALE); // TODO, a better %name
58 wxXmlResource(const wxString* filemask, int flags = wxXRC_USE_LOCALE) {
59 wxXmlResource* res = new wxXmlResource(*filemask, flags);
60 res->InitAllHandlers();
68 // Loads resources from XML files that match given filemask.
69 // This method understands VFS (see filesys.h).
70 bool Load(const wxString& filemask);
72 // Initialize handlers for all supported controls/windows. This will
73 // make the executable quite big because it forces linking against
74 // most of wxWin library
75 void InitAllHandlers();
77 // Initialize only specific handler (or custom handler). Convention says
78 // that handler name is equal to control's name plus 'XmlHandler', e.g.
79 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
80 // (xmlres) can create include file that contains initialization code for
81 // all controls used within the resource.
82 void AddHandler(wxXmlResourceHandler *handler);
84 // Removes all handlers
87 // Loads menu from resource. Returns NULL on failure.
88 wxMenu *LoadMenu(const wxString& name);
90 // Loads menubar from resource. Returns NULL on failure.
91 wxMenuBar *LoadMenuBar(const wxString& name);
92 %name(LoadMenuBarOnFrame) wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name);
96 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
98 // Loads dialog. dlg points to parent window (if any). Second form
99 // is used to finish creation of already existing instance (main reason
100 // for this is that you may want to use derived class with new event table)
101 // Example (typical usage):
103 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
105 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
106 %name(LoadOnDialog)bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
108 // Loads panel. panel points to parent window (if any). Second form
109 // is used to finish creation of already existing instance.
110 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
111 %name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
113 bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
115 // Loads bitmap or icon resource from file:
116 wxBitmap LoadBitmap(const wxString& name);
117 wxIcon LoadIcon(const wxString& name);
119 // Attaches unknown control into given panel/window/dialog:
120 // (unknown controls are used in conjunction with <object class="unknown">)
121 bool AttachUnknownControl(const wxString& name, wxWindow *control,
122 wxWindow *parent = NULL);
124 // Returns numeric ID that is equivalent to string id used in XML
125 // resource. To be used in event tables
126 // Macro XMLID is provided for convenience
127 static int GetXRCID(const wxString& str_id);
129 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
130 long GetVersion() const;
132 // Compares resources version to argument. Returns -1 if resources version
133 // is less than the argument, +1 if greater and 0 if they equal.
134 int CompareVersion(int major, int minor, int release, int revision) const;
137 // Gets global resources object or create one if none exists
138 static wxXmlResource *Get();
139 // Sets global resources object and returns pointer to previous one (may be NULL).
140 static wxXmlResource *Set(wxXmlResource *res);
144 //----------------------------------------------------------------------
146 %pragma(python) code = "
148 return wxXmlResource_GetXRCID(str_id)
150 def XRCCTRL(window, str_id, *ignoreargs):
151 return window.FindWindowById(XRCID(str_id))
157 //----------------------------------------------------------------------
159 // TODO: Add wxXmlResourceHandler and allow it to be derived from.
161 //----------------------------------------------------------------------
165 wxClassInfo::CleanUpClasses();
166 wxClassInfo::InitializeClasses();
168 wxXmlInitResourceModule();
169 wxXmlResource::Get()->InitAllHandlers();
173 //----------------------------------------------------------------------
174 // This file gets appended to the shadow class file.
175 //----------------------------------------------------------------------
177 %pragma(python) include="_xrcextras.py";