]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_xmlres.i
bitwise vs. logical operator
[wxWidgets.git] / wxPython / src / _xmlres.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _xmlres.i
3 // Purpose: SWIG interface for wxXmlResource
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 4-June-2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19
20
21 class wxPyXmlSubclassFactory;
22
23 enum {
24 WX_XMLRES_CURRENT_VERSION_MAJOR,
25 WX_XMLRES_CURRENT_VERSION_MINOR,
26 WX_XMLRES_CURRENT_VERSION_RELEASE,
27 WX_XMLRES_CURRENT_VERSION_REVISION,
28 };
29
30
31 enum wxXmlResourceFlags
32 {
33 wxXRC_USE_LOCALE,
34 wxXRC_NO_SUBCLASSING,
35 wxXRC_NO_RELOADING
36 };
37
38
39
40 // This class holds XML resources from one or more .xml files
41 // (or derived forms, either binary or zipped -- see manual for
42 // details).
43
44 class wxXmlResource : public wxObject
45 {
46 public:
47
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()"
52
53 // Ctors.
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));
63
64 ~wxXmlResource();
65
66 //wxXmlNode* GetFirstRoot(); ** Link error
67
68 // Loads resources from XML files that match given filemask.
69 // This method understands VFS (see filesys.h).
70 bool Load(const wxString& filemask);
71
72 %extend {
73 bool LoadFromString(const wxString& data) {
74 static int s_memFileIdx = 0;
75
76 // Check for memory FS. If not present, load the handler:
77 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
78 wxT("dummy data"));
79 wxFileSystem fsys;
80 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
81 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
82 if (f)
83 delete f;
84 else
85 wxFileSystem::AddHandler(new wxMemoryFSHandler);
86
87 // Now put the resource data into the memory FS
88 wxString filename(wxT("XRC_resource/data_string_"));
89 filename << s_memFileIdx;
90 s_memFileIdx += 1;
91 wxMemoryFSHandler::AddFile(filename, data);
92
93 // Load the "file" into the resource object
94 bool retval = self->Load(wxT("memory:") + filename );
95
96 return retval;
97 }
98 }
99
100 // Unload resource from the given XML file (wildcards not allowed)
101 bool Unload(const wxString& filename);
102
103 // Initialize handlers for all supported controls/windows.
104 void InitAllHandlers();
105
106
107 %disownarg( wxPyXmlResourceHandler *handler );
108
109 // Initialize only specific handler (or custom handler). Convention says
110 // that handler name is equal to control's name plus 'XmlHandler', e.g.
111 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
112 // (xmlres) can create include file that contains initialization code for
113 // all controls used within the resource.
114 void AddHandler(wxPyXmlResourceHandler *handler);
115
116 // Add a new handler at the begining of the handler list
117 void InsertHandler(wxPyXmlResourceHandler *handler);
118
119 %cleardisown( wxPyXmlResourceHandler *handler );
120
121
122 // Removes all handlers
123 void ClearHandlers();
124
125 // Registers subclasses factory for use in XRC. This function is not meant
126 // for public use, please see the comment above wxXmlSubclassFactory
127 // definition.
128 static void AddSubclassFactory(wxPyXmlSubclassFactory *factory);
129
130
131 // Loads menu from resource. Returns NULL on failure.
132 wxMenu *LoadMenu(const wxString& name);
133
134 // Loads menubar from resource. Returns NULL on failure.
135 wxMenuBar *LoadMenuBar(const wxString& name);
136 %Rename(LoadMenuBarOnFrame, wxMenuBar* , LoadMenuBar(wxWindow *parent, const wxString& name));
137
138
139 // Loads toolbar
140 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
141
142 // Loads dialog. dlg points to parent window (if any). Second form
143 // is used to finish creation of already existing instance (main reason
144 // for this is that you may want to use derived class with new event table)
145 // Example (typical usage):
146 // MyDialog dlg;
147 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
148 // dlg->ShowModal();
149 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
150 %Rename(LoadOnDialog, bool, LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name));
151
152 // Loads panel. panel points to parent window (if any). Second form
153 // is used to finish creation of already existing instance.
154 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
155 %Rename(LoadOnPanel, bool, LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name));
156
157 // Load a frame's contents from a resource
158 wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
159 %Rename(LoadOnFrame, bool, LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name));
160
161 // Load an object from the resource specifying both the resource name and
162 // the classname. This lets you load nonstandard container windows.
163 wxObject *LoadObject(wxWindow *parent, const wxString& name,
164 const wxString& classname);
165
166 // Load an object from the resource specifying both the resource name and
167 // the classname. This form lets you finish the creation of an existing
168 // instance.
169 %Rename(LoadOnObject, bool, LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
170 const wxString& classname));
171
172 // Loads a bitmap resource from a file.
173 wxBitmap LoadBitmap(const wxString& name);
174
175 // Loads an icon resource from a file.
176 wxIcon LoadIcon(const wxString& name);
177
178 // Attaches unknown control into given panel/window/dialog:
179 // (unknown controls are used in conjunction with <object class="unknown">)
180 bool AttachUnknownControl(const wxString& name, wxWindow *control,
181 wxWindow *parent = NULL);
182
183 // Returns a numeric ID that is equivalent to the string ID used in an XML
184 // resource. If an unknown str_id is requested (i.e. other than wxID_XXX
185 // or integer), a new record is created which associates the given string
186 // with a number. If value_if_not_found == wxID_NONE, the number is obtained via
187 // wxNewId(). Otherwise value_if_not_found is used.
188 // Macro XRCID(name) is provided for convenient use in event tables.
189 static int GetXRCID(const wxString& str_id, int value_if_not_found = wxID_NONE);
190
191 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
192 long GetVersion() const;
193
194 // Compares resources version to argument. Returns -1 if resources version
195 // is less than the argument, +1 if greater and 0 if they equal.
196 int CompareVersion(int major, int minor, int release, int revision) const;
197
198
199 // Gets global resources object or create one if none exists
200 static wxXmlResource *Get();
201 // Sets global resources object and returns pointer to previous one (may be NULL).
202 static wxXmlResource *Set(wxXmlResource *res);
203
204 // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING.
205 int GetFlags();
206
207 // Set flags after construction.
208 void SetFlags(int flags) { m_flags = flags; }
209
210 // Get/Set the domain to be passed to the translation functions, defaults to NULL.
211 wxString GetDomain() const;
212 void SetDomain(const wxString& domain);
213
214 %property(Domain, GetDomain, SetDomain, doc="See `GetDomain` and `SetDomain`");
215 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
216 %property(Version, GetVersion, doc="See `GetVersion`");
217 };
218
219 //----------------------------------------------------------------------
220
221 %pythoncode {
222 def XRCID(str_id, value_if_not_found = wx.ID_NONE):
223 return XmlResource_GetXRCID(str_id, value_if_not_found)
224
225 def XRCCTRL(window, str_id, *ignoreargs):
226 return window.FindWindowById(XRCID(str_id))
227 };
228
229 //---------------------------------------------------------------------------