]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/xrc/xrc.i
Allow loading xrc resources from a string
[wxWidgets.git] / wxPython / contrib / xrc / xrc.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xrc.i
3 // Purpose: Wrappers for the XML based Resource system
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 4-June-2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2001 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module xrc
14
15
16 %{
17 #include "wxPython.h"
18 #include "wx/xrc/xmlres.h"
19 #include <wx/filesys.h>
20 #include <wx/fs_mem.h>
21 %}
22
23 //---------------------------------------------------------------------------
24
25 %include typemaps.i
26 %include my_typemaps.i
27
28 %extern wx.i
29 %extern windows.i
30 %extern _defs.i
31 %extern events.i
32 %extern controls.i
33
34
35 //---------------------------------------------------------------------------
36
37 enum wxXmlResourceFlags
38 {
39 wxXRC_USE_LOCALE = 1,
40 wxXRC_NO_SUBCLASSING = 2
41 };
42
43
44 // This class holds XML resources from one or more .xml files
45 // (or derived forms, either binary or zipped -- see manual for
46 // details).
47
48 class wxXmlResource : public wxObject
49 {
50 public:
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 %name(wxEmptyXmlResource) wxXmlResource(int flags = wxXRC_USE_LOCALE);
59 %pragma(python) addtomethod = "__init__:self.InitAllHandlers()"
60 %pragma(python) addtomethod = "wxEmptyXmlResource:val.InitAllHandlers()"
61
62 ~wxXmlResource();
63
64
65 // Loads resources from XML files that match given filemask.
66 // This method understands VFS (see filesys.h).
67 bool Load(const wxString& filemask);
68
69 %addmethods {
70 bool LoadFromString(const wxString& data) {
71 static int s_memFileIdx = 0;
72
73 // Check for memory FS. If not present, load the handler:
74 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"),
75 wxT("dummy data"));
76 wxFileSystem fsys;
77 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file"));
78 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file"));
79 if (f)
80 delete f;
81 else
82 wxFileSystem::AddHandler(new wxMemoryFSHandler);
83
84 // Now put the resource data into the memory FS
85 wxString filename(wxT("XRC_resource/data_string_"));
86 filename << s_memFileIdx;
87 s_memFileIdx += 1;
88 wxMemoryFSHandler::AddFile(filename, data);
89
90 // Load the "file" into the resource object
91 bool retval = self->Load(wxT("memory:") + filename );
92
93 return retval;
94 }
95 }
96
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();
101
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);
108
109 // Removes all handlers
110 void ClearHandlers();
111
112 // Loads menu from resource. Returns NULL on failure.
113 wxMenu *LoadMenu(const wxString& name);
114
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);
118
119
120 // Loads toolbar
121 wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
122
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):
127 // MyDialog dlg;
128 // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
129 // dlg->ShowModal();
130 wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
131 %name(LoadOnDialog)bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
132
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);
137
138 bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
139
140 // Loads bitmap or icon resource from file:
141 wxBitmap LoadBitmap(const wxString& name);
142 wxIcon LoadIcon(const wxString& name);
143
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);
148
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);
153
154 // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a)
155 long GetVersion() const;
156
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;
160
161
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);
166
167 };
168
169 //----------------------------------------------------------------------
170
171 %pragma(python) code = "
172 def XRCID(str_id):
173 return wxXmlResource_GetXRCID(str_id)
174
175 def XRCCTRL(window, str_id, *ignoreargs):
176 return window.FindWindowById(XRCID(str_id))
177
178 XMLID = XRCID
179 XMLCTRL = XRCCTRL
180 "
181
182 //----------------------------------------------------------------------
183
184 // TODO: Add wxXmlResourceHandler and allow it to be derived from.
185
186 //----------------------------------------------------------------------
187
188 %init %{
189
190 wxClassInfo::CleanUpClasses();
191 wxClassInfo::InitializeClasses();
192
193 wxXmlInitResourceModule();
194 wxXmlResource::Get()->InitAllHandlers();
195
196 %}
197
198 //----------------------------------------------------------------------
199 // This file gets appended to the shadow class file.
200 //----------------------------------------------------------------------
201
202 %pragma(python) include="_xrcextras.py";
203
204