]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_xmlres.i
reSWIGged
[wxWidgets.git] / wxPython / src / _xmlres.i
... / ...
CommitLineData
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
21class wxPyXmlSubclassFactory;
22
23enum {
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
31enum 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
44class wxXmlResource : public wxObject
45{
46public:
47
48 %pythonAppend wxXmlResource(const wxString& filemask, int flags) "self.InitAllHandlers()"
49 %pythonAppend wxXmlResource(int flags) "val.InitAllHandlers()"
50
51 // Ctors.
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));
59 ~wxXmlResource();
60
61
62 // Loads resources from XML files that match given filemask.
63 // This method understands VFS (see filesys.h).
64 bool Load(const wxString& filemask);
65
66 %extend {
67 bool LoadFromString(const wxString& data) {
68 static int s_memFileIdx = 0;
69
70 // Check for memory FS. If not present, load the handler:
71 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
72 wxT("dummy data"));
73 wxFileSystem fsys;
74 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
75 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
76 if (f)
77 delete f;
78 else
79 wxFileSystem::AddHandler(new wxMemoryFSHandler);
80
81 // Now put the resource data into the memory FS
82 wxString filename(wxT("XRC_resource/data_string_"));
83 filename << s_memFileIdx;
84 s_memFileIdx += 1;
85 wxMemoryFSHandler::AddFile(filename, data);
86
87 // Load the "file" into the resource object
88 bool retval = self->Load(wxT("memory:") + filename );
89
90 return retval;
91 }
92 }
93
94 // Initialize handlers for all supported controls/windows.
95 void InitAllHandlers();
96
97 // Initialize only specific handler (or custom handler). Convention says
98 // that handler name is equal to control's name plus 'XmlHandler', e.g.
99 // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
100 // (xmlres) can create include file that contains initialization code for
101 // all controls used within the resource.
102 void AddHandler(wxPyXmlResourceHandler *handler);
103
104 // Add a new handler at the begining of the handler list
105 void InsertHandler(wxPyXmlResourceHandler *handler);
106
107 // Removes all handlers
108 void ClearHandlers();
109
110 // Registers subclasses factory for use in XRC. This function is not meant
111 // for public use, please see the comment above wxXmlSubclassFactory
112 // definition.
113 static void AddSubclassFactory(wxPyXmlSubclassFactory *factory);
114
115
116 // Loads menu from resource. Returns NULL on failure.
117 wxMenu *LoadMenu(const wxString& name);
118
119 // Loads menubar from resource. Returns NULL on failure.
120 wxMenuBar *LoadMenuBar(const wxString& name);
121 %Rename(LoadMenuBarOnFrame, wxMenuBar* , LoadMenuBar(wxWindow *parent, const wxString& name));
122
123
124 // Loads toolbar
125 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
126
127 // Loads dialog. dlg points to parent window (if any). Second form
128 // is used to finish creation of already existing instance (main reason
129 // for this is that you may want to use derived class with new event table)
130 // Example (typical usage):
131 // MyDialog dlg;
132 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
133 // dlg->ShowModal();
134 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
135 %Rename(LoadOnDialog, bool, LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name));
136
137 // Loads panel. panel points to parent window (if any). Second form
138 // is used to finish creation of already existing instance.
139 wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
140 %Rename(LoadOnPanel, bool, LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name));
141
142 // Load a frame's contents from a resource
143 wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
144 %Rename(LoadOnFrame, bool, LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name));
145
146 // Load an object from the resource specifying both the resource name and
147 // the classname. This lets you load nonstandard container windows.
148 wxObject *LoadObject(wxWindow *parent, const wxString& name,
149 const wxString& classname);
150
151 // Load an object from the resource specifying both the resource name and
152 // the classname. This form lets you finish the creation of an existing
153 // instance.
154 %Rename(LoadOnObject, bool, LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
155 const wxString& classname));
156
157 // Loads a bitmap resource from a file.
158 wxBitmap LoadBitmap(const wxString& name);
159
160 // Loads an icon resource from a file.
161 wxIcon LoadIcon(const wxString& name);
162
163 // Attaches unknown control into given panel/window/dialog:
164 // (unknown controls are used in conjunction with <object class="unknown">)
165 bool AttachUnknownControl(const wxString& name, wxWindow *control,
166 wxWindow *parent = NULL);
167
168 // Returns numeric ID that is equivalent to string id used in XML
169 // resource. To be used in event tables
170 // Macro XMLID is provided for convenience
171 static int GetXRCID(const wxString& str_id);
172
173 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
174 long GetVersion() const;
175
176 // Compares resources version to argument. Returns -1 if resources version
177 // is less than the argument, +1 if greater and 0 if they equal.
178 int CompareVersion(int major, int minor, int release, int revision) const;
179
180
181 // Gets global resources object or create one if none exists
182 static wxXmlResource *Get();
183 // Sets global resources object and returns pointer to previous one (may be NULL).
184 static wxXmlResource *Set(wxXmlResource *res);
185
186 // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING.
187 int GetFlags();
188
189 // Set flags after construction.
190 void SetFlags(int flags) { m_flags = flags; }
191
192};
193
194//----------------------------------------------------------------------
195
196%pythoncode {
197def XRCID(str_id):
198 return XmlResource_GetXRCID(str_id)
199
200def XRCCTRL(window, str_id, *ignoreargs):
201 return window.FindWindowById(XRCID(str_id))
202};
203
204//---------------------------------------------------------------------------