]>
Commit | Line | Data |
---|---|---|
d56cebe7 RD |
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 "export.h" | |
18 | #include "wx/xrc/xmlres.h" | |
19 | %} | |
20 | ||
21 | //--------------------------------------------------------------------------- | |
22 | ||
23 | %include typemaps.i | |
24 | %include my_typemaps.i | |
25 | ||
26 | %extern wx.i | |
27 | %extern windows.i | |
28 | %extern _defs.i | |
29 | %extern events.i | |
30 | %extern controls.i | |
31 | ||
32 | ||
33 | //--------------------------------------------------------------------------- | |
34 | ||
35 | // This class holds XML resources from one or more .xml files | |
36 | // (or derived forms, either binary or zipped -- see manual for | |
37 | // details). | |
38 | ||
39 | class wxXmlResource : public wxObject | |
40 | { | |
41 | public: | |
42 | // Ctor. If use_locale is TRUE, translatable strings are | |
43 | // translated via _(). You can disable it by passing use_locale=FALSE | |
44 | // (for example if you provide resource file for each locale) | |
45 | %name(wxXmlResourceEmpty)wxXmlResource(bool use_locale = TRUE); // TODO, a better %name | |
46 | ||
47 | %addmethods { | |
48 | wxXmlResource(const wxString* filemask, bool use_locale = TRUE) { | |
49 | wxXmlResource* res = new wxXmlResource(*filemask, use_locale); | |
50 | res->InitAllHandlers(); | |
51 | return res; | |
52 | } | |
53 | } | |
54 | ||
55 | ~wxXmlResource(); | |
56 | ||
57 | ||
58 | // Loads resources from XML files that match given filemask. | |
59 | // This method understands VFS (see filesys.h). | |
60 | bool Load(const wxString& filemask); | |
61 | ||
62 | // Initialize handlers for all supported controls/windows. This will | |
63 | // make the executable quite big because it forces linking against | |
64 | // most of wxWin library | |
65 | void InitAllHandlers(); | |
66 | ||
67 | // Initialize only specific handler (or custom handler). Convention says | |
68 | // that handler name is equal to control's name plus 'XmlHandler', e.g. | |
69 | // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler | |
70 | // (xmlres) can create include file that contains initialization code for | |
71 | // all controls used within the resource. | |
72 | void AddHandler(wxXmlResourceHandler *handler); | |
73 | ||
74 | // Removes all handlers | |
75 | void ClearHandlers(); | |
76 | ||
77 | // Loads menu from resource. Returns NULL on failure. | |
78 | wxMenu *LoadMenu(const wxString& name); | |
79 | ||
80 | // Loads menubar from resource. Returns NULL on failure. | |
81 | wxMenuBar *LoadMenuBar(const wxString& name); | |
82 | ||
83 | // Loads toolbar | |
84 | wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name); | |
85 | ||
86 | // Loads dialog. dlg points to parent window (if any). Second form | |
87 | // is used to finish creation of already existing instance (main reason | |
88 | // for this is that you may want to use derived class with new event table) | |
89 | // Example (typical usage): | |
90 | // MyDialog dlg; | |
91 | // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog"); | |
92 | // dlg->ShowModal(); | |
93 | wxDialog *LoadDialog(wxWindow *parent, const wxString& name); | |
94 | %name(LoadOnDialog)bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name); | |
95 | ||
96 | // Loads panel. panel points to parent window (if any). Second form | |
97 | // is used to finish creation of already existing instance. | |
98 | wxPanel *LoadPanel(wxWindow *parent, const wxString& name); | |
99 | %name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name); | |
100 | ||
101 | bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name); | |
102 | ||
103 | // Loads bitmap or icon resource from file: | |
104 | wxBitmap LoadBitmap(const wxString& name); | |
105 | wxIcon LoadIcon(const wxString& name); | |
106 | ||
107 | // Attaches unknown control into given panel/window/dialog: | |
108 | // (unknown controls are used in conjunction with <object class="unknown">) | |
109 | bool AttachUnknownControl(const wxString& name, wxWindow *control, | |
110 | wxWindow *parent = NULL); | |
111 | ||
112 | // Returns numeric ID that is equivalent to string id used in XML | |
113 | // resource. To be used in event tables | |
114 | // Macro XMLID is provided for convenience | |
115 | static int GetXMLID(const char *str_id); | |
116 | ||
117 | // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a) | |
118 | long GetVersion() const; | |
119 | ||
120 | // Compares resources version to argument. Returns -1 if resources version | |
121 | // is less than the argument, +1 if greater and 0 if they equal. | |
122 | int CompareVersion(int major, int minor, int release, int revision) const; | |
123 | ||
124 | }; | |
125 | ||
126 | //---------------------------------------------------------------------- | |
127 | ||
128 | %readonly | |
129 | // Global instance of resource class. For your convenience. | |
130 | wxXmlResource *wxTheXmlResource; | |
131 | %readwrite | |
132 | ||
133 | //---------------------------------------------------------------------- | |
134 | ||
135 | %pragma(python) code = " | |
136 | def XMLID(str_id): | |
137 | return wxXmlResource_GetXMLID(str_id) | |
138 | ||
139 | def XMLCTRL(window, str_id, *args): | |
140 | return window.FindWindowById(XMLID(str_id)) | |
141 | ||
142 | " | |
143 | ||
144 | //---------------------------------------------------------------------- | |
145 | ||
146 | // TODO: Add wxXmlResourceHandler and etc. | |
147 | ||
148 | //---------------------------------------------------------------------- | |
149 | ||
150 | %init %{ | |
151 | ||
152 | wxClassInfo::CleanUpClasses(); | |
153 | wxClassInfo::InitializeClasses(); | |
154 | ||
155 | wxXmlInitXmlModule(); | |
156 | wxXmlInitResourceModule(); | |
157 | wxTheXmlResource->InitAllHandlers(); | |
158 | ||
159 | %} | |
160 | ||
161 | //--------------------------------------------------------------------------- |