Debian Codegraph @

wxcrafter/xrc_handlers/myxh_auimgr.cpp

raw
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_aui.cpp
3 // Purpose: Implementation of wxAUI XRC handler.
4 // Author: Andrea Zanellato, Steve Lamerton (wxAuiNotebook)
5 // Created: 2011-09-18
6 // Copyright: (c) 2011 wxWidgets Team
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 #include "myxh_auimgr.h"
17 #include <wx/aui/auibook.h>
18 #include <wx/aui/framemanager.h>
19
20 wxIMPLEMENT_DYNAMIC_CLASS(MyWxAuiManagerXmlHandler, wxXmlResourceHandler)
21
22 MyWxAuiManagerXmlHandler::MyWxAuiManagerXmlHandler()
23 : wxXmlResourceHandler()
24 , m_manager(NULL)
25 , m_window(NULL)
26 , m_notebook(NULL)
27 , m_mgrInside(false)
28 , m_anbInside(false)
29 {
30 XRC_ADD_STYLE(wxAUI_MGR_ALLOW_ACTIVE_PANE);
31 XRC_ADD_STYLE(wxAUI_MGR_ALLOW_FLOATING);
32 XRC_ADD_STYLE(wxAUI_MGR_DEFAULT);
33 XRC_ADD_STYLE(wxAUI_MGR_HINT_FADE);
34 XRC_ADD_STYLE(wxAUI_MGR_LIVE_RESIZE);
35 XRC_ADD_STYLE(wxAUI_MGR_NO_VENETIAN_BLINDS_FADE);
36 XRC_ADD_STYLE(wxAUI_MGR_RECTANGLE_HINT);
37 XRC_ADD_STYLE(wxAUI_MGR_TRANSPARENT_DRAG);
38 XRC_ADD_STYLE(wxAUI_MGR_TRANSPARENT_HINT);
39 XRC_ADD_STYLE(wxAUI_MGR_VENETIAN_BLINDS_HINT);
40
41 XRC_ADD_STYLE(wxAUI_NB_DEFAULT_STYLE);
42 XRC_ADD_STYLE(wxAUI_NB_TAB_SPLIT);
43 XRC_ADD_STYLE(wxAUI_NB_TAB_MOVE);
44 XRC_ADD_STYLE(wxAUI_NB_TAB_EXTERNAL_MOVE);
45 XRC_ADD_STYLE(wxAUI_NB_TAB_FIXED_WIDTH);
46 XRC_ADD_STYLE(wxAUI_NB_SCROLL_BUTTONS);
47 XRC_ADD_STYLE(wxAUI_NB_WINDOWLIST_BUTTON);
48 XRC_ADD_STYLE(wxAUI_NB_CLOSE_BUTTON);
49 XRC_ADD_STYLE(wxAUI_NB_CLOSE_ON_ACTIVE_TAB);
50 XRC_ADD_STYLE(wxAUI_NB_CLOSE_ON_ALL_TABS);
51 XRC_ADD_STYLE(wxAUI_NB_MIDDLE_CLICK_CLOSE);
52 XRC_ADD_STYLE(wxAUI_NB_TOP);
53 XRC_ADD_STYLE(wxAUI_NB_BOTTOM);
54
55 AddWindowStyles();
56 }
57
58 wxAuiManager* MyWxAuiManagerXmlHandler::GetAuiManager(wxWindow* managed) const
59 {
60 for(Managers::const_iterator it = m_managers.begin(); it != m_managers.end(); ++it) {
61 wxAuiManager* const mgr = *it;
62 if(mgr->GetManagedWindow() == managed) return mgr;
63 }
64
65 return NULL;
66 }
67
68 void MyWxAuiManagerXmlHandler::OnManagedWindowClose(wxWindowDestroyEvent& event)
69 {
70 wxWindow* window = wxDynamicCast(event.GetEventObject(), wxWindow);
71 for(Managers::iterator it = m_managers.begin(); it != m_managers.end(); ++it) {
72 wxAuiManager* const mgr = *it;
73 if(mgr->GetManagedWindow() == window) {
74 mgr->UnInit();
75 m_managers.erase(it);
76 break;
77 }
78 }
79 event.Skip();
80 }
81
82 wxObject* MyWxAuiManagerXmlHandler::DoCreateResource()
83 {
84 if(m_class == wxS("wxAuiManager")) {
85 wxAuiManager* manager = NULL;
86
87 if(m_parentAsWindow) {
88 // Cache the previous values
89 bool old_ins = m_mgrInside;
90 wxAuiManager* old_mgr = m_manager;
91 wxWindow* old_win = m_window;
92
93 // Create the manager with the specified or default style and
94 // assign the new values related to this manager
95 m_window = m_parentAsWindow;
96 manager = new wxAuiManager(m_window, GetStyle(wxS("style"), wxAUI_MGR_DEFAULT));
97 m_manager = manager;
98 m_mgrInside = true;
99
100 // Add this manager to our manager vector
101 m_managers.push_back(m_manager);
102
103 // Connect the managed window destroy event to
104 // automatically UnInit() later this manager
105 m_window->Bind(wxEVT_DESTROY, &MyWxAuiManagerXmlHandler::OnManagedWindowClose, this);
106
107 // Add AUI panes to this manager
108 CreateChildren(m_manager);
109
110 // Load a custom perspective if any
111 if(HasParam(wxS("perspective"))) m_manager->LoadPerspective(GetParamValue(wxS("perspective")));
112
113 m_manager->Update();
114
115 // Restore the previous values
116 m_window = old_win;
117 m_manager = old_mgr;
118 m_mgrInside = old_ins;
119 } else {
120 ReportError("No wxWindow derived class to manage for this wxAuiManager.");
121 }
122
123 return manager;
124 } else if(m_class == "wxAuiPaneInfo") {
125 wxXmlNode* node = GetParamNode(wxS("object"));
126 wxWindow* window = NULL;
127
128 if(!node) node = GetParamNode(wxS("object_ref"));
129
130 if(node) {
131 bool old_ins = m_mgrInside;
132 m_mgrInside = false;
133
134 wxObject* object = CreateResFromNode(node, m_window, NULL);
135
136 m_mgrInside = old_ins;
137 window = wxDynamicCast(object, wxWindow);
138
139 if(!window && object) { ReportError(node, "wxAuiPaneInfo child must be a window."); }
140 }
141
142 if(window) {
143 wxAuiPaneInfo paneInfo = wxAuiPaneInfo();
144
145 wxString name = GetName();
146 paneInfo.Name(name);
147 // Caption
148 if(HasParam(wxS("caption"))) paneInfo.Caption(GetText(wxS("caption")));
149 if(HasParam(wxS("caption_visible"))) paneInfo.CaptionVisible(GetBool(wxS("caption_visible")));
150 // Buttons
151 if(HasParam(wxS("close_button"))) paneInfo.CloseButton(GetBool(wxS("close_button")));
152 if(HasParam(wxS("minimize_button"))) paneInfo.MinimizeButton(GetBool(wxS("minimize_button")));
153 if(HasParam(wxS("maximize_button"))) paneInfo.MaximizeButton(GetBool(wxS("maximize_button")));
154 if(HasParam(wxS("pin_button"))) paneInfo.PinButton(GetBool(wxS("pin_button")));
155 if(HasParam(wxS("gripper"))) paneInfo.Gripper(GetBool(wxS("gripper")));
156 // Appearance
157 if(HasParam(wxS("pane_border"))) paneInfo.PaneBorder(GetBool(wxS("pane_border")));
158 // State
159 if(HasParam(wxS("dock")))
160 paneInfo.Dock();
161 else if(HasParam(wxS("float")))
162 paneInfo.Float();
163
164 // Dockable Directions
165 if(HasParam(wxS("top_dockable"))) paneInfo.TopDockable(GetBool(wxS("top_dockable")));
166 if(HasParam(wxS("bottom_dockable"))) paneInfo.BottomDockable(GetBool(wxS("bottom_dockable")));
167 if(HasParam(wxS("left_dockable"))) paneInfo.LeftDockable(GetBool(wxS("left_dockable")));
168 if(HasParam(wxS("right_dockable"))) paneInfo.RightDockable(GetBool(wxS("right_dockable")));
169 // Behaviours
170 if(HasParam(wxS("dock_fixed"))) paneInfo.DockFixed(GetBool(wxS("dock_fixed")));
171 if(HasParam(wxS("resizable"))) paneInfo.Resizable(GetBool(wxS("resizable")));
172 if(HasParam(wxS("movable"))) paneInfo.Movable(GetBool(wxS("movable")));
173 if(HasParam(wxS("floatable"))) paneInfo.Floatable(GetBool(wxS("floatable")));
174 // Sizes
175 if(HasParam(wxS("floating_size"))) paneInfo.FloatingSize(GetSize(wxS("floating_size")));
176 if(HasParam(wxS("min_size"))) paneInfo.MinSize(GetSize(wxS("min_size")));
177 if(HasParam(wxS("max_size"))) paneInfo.MaxSize(GetSize(wxS("max_size")));
178 if(HasParam(wxS("best_size"))) paneInfo.BestSize(GetSize(wxS("best_size")));
179 // Positions
180 if(HasParam(wxS("row"))) paneInfo.Row(GetLong(wxS("row")));
181 if(HasParam(wxS("layer"))) paneInfo.Layer(GetLong(wxS("layer")));
182 if(HasParam(wxS("default_pane")))
183 paneInfo.DefaultPane();
184 else if(HasParam(wxS("toolbar_pane")))
185 paneInfo.ToolbarPane();
186
187 // Directions - CenterPane()/CentrePane != Center()/Centre()
188 if(HasParam(wxS("center_pane")) || HasParam(wxS("centre_pane"))) paneInfo.CenterPane();
189 if(HasParam(wxS("direction")))
190 paneInfo.Direction(GetLong(wxS("direction")));
191 else if(HasParam(wxS("top")))
192 paneInfo.Top();
193 else if(HasParam(wxS("bottom")))
194 paneInfo.Bottom();
195 else if(HasParam(wxS("left")))
196 paneInfo.Left();
197 else if(HasParam(wxS("right")))
198 paneInfo.Right();
199 else if(HasParam(wxS("center")) || HasParam(wxS("centre")))
200 paneInfo.Center();
201
202 m_manager->AddPane(window, paneInfo);
203 } else {
204 ReportError("No wxWindow derived class object specified inside wxAuiPaneInfo.");
205 }
206
207 return window;
208 } else if(m_class == wxS("notebookpage")) {
209 wxXmlNode* anb = GetParamNode(wxS("object"));
210
211 if(!anb) anb = GetParamNode(wxS("object_ref"));
212
213 if(anb) {
214 bool old_ins = m_anbInside;
215 m_anbInside = false;
216 wxObject* item = CreateResFromNode(anb, m_notebook, NULL);
217 m_anbInside = old_ins;
218 wxWindow* wnd = wxDynamicCast(item, wxWindow);
219
220 if(wnd) {
221 if(HasParam(wxS("bitmap"))) {
222 m_notebook->AddPage(wnd, GetText(wxS("label")), GetBool(wxS("selected")),
223 GetBitmap(wxS("bitmap"), wxART_OTHER));
224 } else {
225 m_notebook->AddPage(wnd, GetText(wxS("label")), GetBool(wxS("selected")));
226 }
227 } else {
228 ReportError(anb, "notebookpage child must be a window");
229 }
230 return wnd;
231 } else {
232 ReportError("notebookpage must have a window child");
233 return NULL;
234 }
235 } else // if (m_class == wxS("wxAuiNotebook"))
236 {
237 XRC_MAKE_INSTANCE(anb, wxAuiNotebook)
238
239 anb->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(wxS("style")));
240
241 SetupWindow(anb);
242
243 wxAuiNotebook* old_par = m_notebook;
244 m_notebook = anb;
245 bool old_ins = m_anbInside;
246 m_anbInside = true;
247 CreateChildren(m_notebook, true /*only this handler*/);
248 m_anbInside = old_ins;
249 m_notebook = old_par;
250
251 return anb;
252 }
253 }
254
255 bool MyWxAuiManagerXmlHandler::CanHandle(wxXmlNode* node)
256 {
257 return ((!m_mgrInside && IsOfClass(node, wxS("wxAuiManager"))) ||
258 (m_mgrInside && IsOfClass(node, wxS("wxAuiPaneInfo"))) ||
259 (!m_anbInside && IsOfClass(node, wxS("wxAuiNotebook"))) ||
260 (m_anbInside && IsOfClass(node, wxS("notebookpage"))));
261 }