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"
19 #include <wx/filesys.h>
20 #include <wx/fs_mem.h>
23 //---------------------------------------------------------------------------
26 %include my_typemaps.i
35 //---------------------------------------------------------------------------
37 enum wxXmlResourceFlags
40 wxXRC_NO_SUBCLASSING = 2
44 // This class holds XML resources from one or more .xml files
45 // (or derived forms, either binary or zipped -- see manual for
48 class wxXmlResource : public wxObject
52 // Flags: wxXRC_USE_LOCALE
53 // translatable strings will be translated via _()
54 // wxXRC_NO_SUBCLASSING
55 // subclass property of object nodes will be ignored
56 // (useful for previews in XRC editors)
57 wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
58 %name(wxEmptyXmlResource) wxXmlResource(int flags = wxXRC_USE_LOCALE);
59 %pragma(python) addtomethod = "__init__:self.InitAllHandlers()"
60 %pragma(python) addtomethod = "wxEmptyXmlResource:val.InitAllHandlers()"
65 // Loads resources from XML files that match given filemask.
66 // This method understands VFS (see filesys.h).
67 bool Load(const wxString& filemask);
70 bool LoadFromString(const wxString& data) {
71 static int s_memFileIdx = 0;
73 // Check for memory FS. If not present, load the handler:
74 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
77 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
78 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
82 wxFileSystem::AddHandler(new wxMemoryFSHandler);
84 // Now put the resource data into the memory FS
85 wxString filename(wxT("XRC_resource/data_string_"));
86 filename << s_memFileIdx;
88 wxMemoryFSHandler::AddFile(filename, data);
90 // Load the "file" into the resource object
91 bool retval = self->Load(wxT("memory:") + filename );
97 // Initialize handlers for all supported controls/windows. This will
98 // make the executable quite big because it forces linking against
99 // most of wxWin library
100 void InitAllHandlers();
102 // Initialize only specific handler (or custom handler). Convention says
103 // that handler name is equal to control's name plus 'XmlHandler', e.g.
104 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
105 // (xmlres) can create include file that contains initialization code for
106 // all controls used within the resource.
107 void AddHandler(wxXmlResourceHandler *handler);
109 // Removes all handlers
110 void ClearHandlers();
112 // Loads menu from resource. Returns NULL on failure.
113 wxMenu *LoadMenu(const wxString& name);
115 // Loads menubar from resource. Returns NULL on failure.
116 wxMenuBar *LoadMenuBar(const wxString& name);
117 %name(LoadMenuBarOnFrame) wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name);
121 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
123 // Loads dialog. dlg points to parent window (if any). Second form
124 // is used to finish creation of already existing instance (main reason
125 // for this is that you may want to use derived class with new event table)
126 // Example (typical usage):
128 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
130 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
131 %name(LoadOnDialog)bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
133 // Loads panel. panel points to parent window (if any). Second form
134 // is used to finish creation of already existing instance.
135 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
136 %name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
138 bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
140 // Loads bitmap or icon resource from file:
141 wxBitmap LoadBitmap(const wxString& name);
142 wxIcon LoadIcon(const wxString& name);
144 // Attaches unknown control into given panel/window/dialog:
145 // (unknown controls are used in conjunction with <object class="unknown">)
146 bool AttachUnknownControl(const wxString& name, wxWindow *control,
147 wxWindow *parent = NULL);
149 // Returns numeric ID that is equivalent to string id used in XML
150 // resource. To be used in event tables
151 // Macro XMLID is provided for convenience
152 static int GetXRCID(const wxString& str_id);
154 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
155 long GetVersion() const;
157 // Compares resources version to argument. Returns -1 if resources version
158 // is less than the argument, +1 if greater and 0 if they equal.
159 int CompareVersion(int major, int minor, int release, int revision) const;
162 // Gets global resources object or create one if none exists
163 static wxXmlResource *Get();
164 // Sets global resources object and returns pointer to previous one (may be NULL).
165 static wxXmlResource *Set(wxXmlResource *res);
169 //----------------------------------------------------------------------
171 %pragma(python) code = "
173 return wxXmlResource_GetXRCID(str_id)
175 def XRCCTRL(window, str_id, *ignoreargs):
176 return window.FindWindowById(XRCID(str_id))
182 //----------------------------------------------------------------------
184 // TODO: Add wxXmlResourceHandler and allow it to be derived from.
186 //----------------------------------------------------------------------
190 wxClassInfo::CleanUpClasses();
191 wxClassInfo::InitializeClasses();
193 wxXmlInitResourceModule();
194 wxXmlResource::Get()->InitAllHandlers();
198 //----------------------------------------------------------------------
199 // This file gets appended to the shadow class file.
200 //----------------------------------------------------------------------
202 %pragma(python) include="_xrcextras.py";