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,
49 const wxString& domain=wxEmptyString) "self.InitAllHandlers()"
50 %pythonAppend wxXmlResource(int flags,
51 const wxString& domain=wxEmptyString) "val.InitAllHandlers()"
54 // Flags: wxXRC_USE_LOCALE
55 // translatable strings will be translated via _()
56 // wxXRC_NO_SUBCLASSING
57 // subclass property of object nodes will be ignored
58 // (useful for previews in XRC editors)
59 wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE,
60 const wxString& domain=wxEmptyString);
61 %RenameCtor(EmptyXmlResource, wxXmlResource(int flags = wxXRC_USE_LOCALE,
62 const wxString& domain=wxEmptyString));
67 // Loads resources from XML files that match given filemask.
68 // This method understands VFS (see filesys.h).
69 bool Load(const wxString& filemask);
72 bool LoadFromString(const wxString& data) {
73 static int s_memFileIdx = 0;
75 // Check for memory FS. If not present, load the handler:
76 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
79 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
80 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
84 wxFileSystem::AddHandler(new wxMemoryFSHandler);
86 // Now put the resource data into the memory FS
87 wxString filename(wxT("XRC_resource/data_string_"));
88 filename << s_memFileIdx;
90 wxMemoryFSHandler::AddFile(filename, data);
92 // Load the "file" into the resource object
93 bool retval = self->Load(wxT("memory:") + filename );
99 // Unload resource from the given XML file (wildcards not allowed)
100 bool Unload(const wxString& filename);
102 // Initialize handlers for all supported controls/windows.
103 void InitAllHandlers();
105 // Initialize only specific handler (or custom handler). Convention says
106 // that handler name is equal to control's name plus 'XmlHandler', e.g.
107 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
108 // (xmlres) can create include file that contains initialization code for
109 // all controls used within the resource.
110 void AddHandler(wxPyXmlResourceHandler *handler);
112 // Add a new handler at the begining of the handler list
113 void InsertHandler(wxPyXmlResourceHandler *handler);
115 // Removes all handlers
116 void ClearHandlers();
118 // Registers subclasses factory for use in XRC. This function is not meant
119 // for public use, please see the comment above wxXmlSubclassFactory
121 static void AddSubclassFactory(wxPyXmlSubclassFactory *factory);
124 // Loads menu from resource. Returns NULL on failure.
125 wxMenu *LoadMenu(const wxString& name);
127 // Loads menubar from resource. Returns NULL on failure.
128 wxMenuBar *LoadMenuBar(const wxString& name);
129 %Rename(LoadMenuBarOnFrame, wxMenuBar* , LoadMenuBar(wxWindow *parent, const wxString& name));
133 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
135 // Loads dialog. dlg points to parent window (if any). Second form
136 // is used to finish creation of already existing instance (main reason
137 // for this is that you may want to use derived class with new event table)
138 // Example (typical usage):
140 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
142 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
143 %Rename(LoadOnDialog, bool, LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name));
145 // Loads panel. panel points to parent window (if any). Second form
146 // is used to finish creation of already existing instance.
147 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
148 %Rename(LoadOnPanel, bool, LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name));
150 // Load a frame's contents from a resource
151 wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
152 %Rename(LoadOnFrame, bool, LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name));
154 // Load an object from the resource specifying both the resource name and
155 // the classname. This lets you load nonstandard container windows.
156 wxObject *LoadObject(wxWindow *parent, const wxString& name,
157 const wxString& classname);
159 // Load an object from the resource specifying both the resource name and
160 // the classname. This form lets you finish the creation of an existing
162 %Rename(LoadOnObject, bool, LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
163 const wxString& classname));
165 // Loads a bitmap resource from a file.
166 wxBitmap LoadBitmap(const wxString& name);
168 // Loads an icon resource from a file.
169 wxIcon LoadIcon(const wxString& name);
171 // Attaches unknown control into given panel/window/dialog:
172 // (unknown controls are used in conjunction with <object class="unknown">)
173 bool AttachUnknownControl(const wxString& name, wxWindow *control,
174 wxWindow *parent = NULL);
176 // Returns a numeric ID that is equivalent to the string ID used in an XML
177 // resource. If an unknown str_id is requested (i.e. other than wxID_XXX
178 // or integer), a new record is created which associates the given string
179 // with a number. If value_if_not_found == wxID_NONE, the number is obtained via
180 // wxNewId(). Otherwise value_if_not_found is used.
181 // Macro XRCID(name) is provided for convenient use in event tables.
182 static int GetXRCID(const wxString& str_id, int value_if_not_found = wxID_NONE);
184 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
185 long GetVersion() const;
187 // Compares resources version to argument. Returns -1 if resources version
188 // is less than the argument, +1 if greater and 0 if they equal.
189 int CompareVersion(int major, int minor, int release, int revision) const;
192 // Gets global resources object or create one if none exists
193 static wxXmlResource *Get();
194 // Sets global resources object and returns pointer to previous one (may be NULL).
195 static wxXmlResource *Set(wxXmlResource *res);
197 // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING.
200 // Set flags after construction.
201 void SetFlags(int flags) { m_flags = flags; }
203 // Get/Set the domain to be passed to the translation functions, defaults to NULL.
204 wxString GetDomain() const;
205 void SetDomain(const wxString& domain);
208 //----------------------------------------------------------------------
211 def XRCID(str_id, value_if_not_found = wx.ID_NONE):
212 return XmlResource_GetXRCID(str_id, value_if_not_found)
214 def XRCCTRL(window, str_id, *ignoreargs):
215 return window.FindWindowById(XRCID(str_id))
218 //---------------------------------------------------------------------------