1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxXmlResource
7 // Created: 4-June-2001
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 class wxPyXmlSubclassFactory;
24 WX_XMLRES_CURRENT_VERSION_MAJOR,
25 WX_XMLRES_CURRENT_VERSION_MINOR,
26 WX_XMLRES_CURRENT_VERSION_RELEASE,
27 WX_XMLRES_CURRENT_VERSION_REVISION,
31 enum wxXmlResourceFlags
40 // This class holds XML resources from one or more .xml files
41 // (or derived forms, either binary or zipped -- see manual for
44 class wxXmlResource : public wxObject
48 %pythonAppend wxXmlResource(const wxString& filemask, int flags) "self.InitAllHandlers()"
49 %pythonAppend wxXmlResource(int flags) "val.InitAllHandlers()"
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 %RenameCtor(EmptyXmlResource, wxXmlResource(int flags = wxXRC_USE_LOCALE));
62 // Loads resources from XML files that match given filemask.
63 // This method understands VFS (see filesys.h).
64 bool Load(const wxString& filemask);
67 bool LoadFromString(const wxString& data) {
68 static int s_memFileIdx = 0;
70 // Check for memory FS. If not present, load the handler:
71 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
74 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
75 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
79 wxFileSystem::AddHandler(new wxMemoryFSHandler);
81 // Now put the resource data into the memory FS
82 wxString filename(wxT("XRC_resource/data_string_"));
83 filename << s_memFileIdx;
85 wxMemoryFSHandler::AddFile(filename, data);
87 // Load the "file" into the resource object
88 bool retval = self->Load(wxT("memory:") + filename );
94 // Unload resource from the given XML file (wildcards not allowed)
95 bool Unload(const wxString& filename);
97 // Initialize handlers for all supported controls/windows.
98 void InitAllHandlers();
100 // Initialize only specific handler (or custom handler). Convention says
101 // that handler name is equal to control's name plus 'XmlHandler', e.g.
102 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
103 // (xmlres) can create include file that contains initialization code for
104 // all controls used within the resource.
105 void AddHandler(wxPyXmlResourceHandler *handler);
107 // Add a new handler at the begining of the handler list
108 void InsertHandler(wxPyXmlResourceHandler *handler);
110 // Removes all handlers
111 void ClearHandlers();
113 // Registers subclasses factory for use in XRC. This function is not meant
114 // for public use, please see the comment above wxXmlSubclassFactory
116 static void AddSubclassFactory(wxPyXmlSubclassFactory *factory);
119 // Loads menu from resource. Returns NULL on failure.
120 wxMenu *LoadMenu(const wxString& name);
122 // Loads menubar from resource. Returns NULL on failure.
123 wxMenuBar *LoadMenuBar(const wxString& name);
124 %Rename(LoadMenuBarOnFrame, wxMenuBar* , LoadMenuBar(wxWindow *parent, const wxString& name));
128 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
130 // Loads dialog. dlg points to parent window (if any). Second form
131 // is used to finish creation of already existing instance (main reason
132 // for this is that you may want to use derived class with new event table)
133 // Example (typical usage):
135 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
137 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
138 %Rename(LoadOnDialog, bool, LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name));
140 // Loads panel. panel points to parent window (if any). Second form
141 // is used to finish creation of already existing instance.
142 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
143 %Rename(LoadOnPanel, bool, LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name));
145 // Load a frame's contents from a resource
146 wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
147 %Rename(LoadOnFrame, bool, LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name));
149 // Load an object from the resource specifying both the resource name and
150 // the classname. This lets you load nonstandard container windows.
151 wxObject *LoadObject(wxWindow *parent, const wxString& name,
152 const wxString& classname);
154 // Load an object from the resource specifying both the resource name and
155 // the classname. This form lets you finish the creation of an existing
157 %Rename(LoadOnObject, bool, LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
158 const wxString& classname));
160 // Loads a bitmap resource from a file.
161 wxBitmap LoadBitmap(const wxString& name);
163 // Loads an icon resource from a file.
164 wxIcon LoadIcon(const wxString& name);
166 // Attaches unknown control into given panel/window/dialog:
167 // (unknown controls are used in conjunction with <object class="unknown">)
168 bool AttachUnknownControl(const wxString& name, wxWindow *control,
169 wxWindow *parent = NULL);
171 // Returns a numeric ID that is equivalent to the string ID used in an XML
172 // resource. If an unknown str_id is requested (i.e. other than wxID_XXX
173 // or integer), a new record is created which associates the given string
174 // with a number. If value_if_not_found == wxID_NONE, the number is obtained via
175 // wxNewId(). Otherwise value_if_not_found is used.
176 // Macro XRCID(name) is provided for convenient use in event tables.
177 static int GetXRCID(const wxString& str_id, int value_if_not_found = wxID_NONE);
179 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
180 long GetVersion() const;
182 // Compares resources version to argument. Returns -1 if resources version
183 // is less than the argument, +1 if greater and 0 if they equal.
184 int CompareVersion(int major, int minor, int release, int revision) const;
187 // Gets global resources object or create one if none exists
188 static wxXmlResource *Get();
189 // Sets global resources object and returns pointer to previous one (may be NULL).
190 static wxXmlResource *Set(wxXmlResource *res);
192 // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING.
195 // Set flags after construction.
196 void SetFlags(int flags) { m_flags = flags; }
200 //----------------------------------------------------------------------
203 def XRCID(str_id, value_if_not_found = wx.ID_NONE):
204 return XmlResource_GetXRCID(str_id, value_if_not_found)
206 def XRCCTRL(window, str_id, *ignoreargs):
207 return window.FindWindowById(XRCID(str_id))
210 //---------------------------------------------------------------------------