Debian Codegraph @

wxcrafter/aui/aui_pane_info.cpp

raw
1 #include "aui_pane_info.h"
2 #include "json_node.h"
3 #include "wxgui_helpers.h"
4 #include <wx/propgrid/propgrid.h>
5
6 #define BOOL_TO_STR(b) (b ? "true" : "false")
7 #define XRC_BOOL_TO_STR(b) (b ? "1" : "0")
8
9 AuiPaneInfo::AuiPaneInfo() { Reset(); }
10
11 AuiPaneInfo::~AuiPaneInfo() {}
12
13 wxString AuiPaneInfo::ToCppCode() const
14 {
15 wxString cppCode = "wxAuiPaneInfo()";
16
17 if(m_name.IsEmpty() == false) { cppCode << ".Name(" << wxCrafter::WXT(m_name) << ")"; }
18
19 if(m_caption.IsEmpty() == false) { cppCode << ".Caption(" << wxCrafter::UNDERSCORE(m_caption) << ")"; }
20
21 cppCode << ".Direction(" << m_dockDirection << ")";
22 cppCode << ".Layer(" << m_layer << ")";
23 cppCode << ".Row(" << m_row << ")";
24 cppCode << ".Position(" << m_position << ")";
25
26 if(m_bestSize != wxDefaultSize) { cppCode << ".BestSize(" << wxCrafter::EncodeSize(m_bestSize) << ")"; }
27
28 if(m_minSize != wxDefaultSize) { cppCode << ".MinSize(" << wxCrafter::EncodeSize(m_minSize) << ")"; }
29
30 if(m_maxSize != wxDefaultSize) { cppCode << ".MaxSize(" << wxCrafter::EncodeSize(m_maxSize) << ")"; }
31
32 if(!m_resizable) { cppCode << ".Fixed()"; }
33
34 cppCode << ".CaptionVisible(" << BOOL_TO_STR(m_captionVisible) << ")";
35 cppCode << ".MaximizeButton(" << BOOL_TO_STR(m_maxButton) << ")";
36 cppCode << ".CloseButton(" << BOOL_TO_STR(m_closeButton) << ")";
37 cppCode << ".MinimizeButton(" << BOOL_TO_STR(m_minButton) << ")";
38 cppCode << ".PinButton(" << BOOL_TO_STR(m_pinButton) << ")";
39
40 if(m_toolbarPane) { cppCode << ".ToolbarPane()"; }
41 return cppCode;
42 }
43
44 void AuiPaneInfo::Construct(wxPropertyGrid* pg) const
45 {
46 // Popuplate the sizer flags
47 wxPGProperty* prop = NULL;
48 wxPGProperty* general = pg->Append(new wxPropertyCategory(_("General")));
49 pg->Expand(general);
50
51 pg->Append(new wxStringProperty(_("Name"), wxPG_LABEL, m_name));
52 pg->Append(new wxStringProperty(_("Caption"), wxPG_LABEL, m_caption));
53
54 prop = pg->Append(new wxBoolProperty(_("Caption Visible"), wxPG_LABEL, m_captionVisible));
55 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
56
57 prop = pg->Append(new wxBoolProperty(_("Resizable"), wxPG_LABEL, m_resizable));
58 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
59
60 prop = pg->Append(new wxBoolProperty(_("ToolBar Pane"), wxPG_LABEL, m_toolbarPane));
61 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
62
63 wxPGProperty* dockings = pg->Append(new wxPropertyCategory(_("Docking")));
64 pg->Expand(dockings);
65
66 wxArrayString directions;
67 directions.Add("wxAUI_DOCK_TOP");
68 directions.Add("wxAUI_DOCK_RIGHT");
69 directions.Add("wxAUI_DOCK_BOTTOM");
70 directions.Add("wxAUI_DOCK_LEFT");
71 directions.Add("wxAUI_DOCK_CENTER");
72 wxEnumProperty* dir = (wxEnumProperty*)pg->Append(new wxEnumProperty(_("Direction"), wxPG_LABEL, directions));
73 pg->Expand(dir);
74 dir->SetChoiceSelection(directions.Index(m_dockDirection));
75
76 pg->Append(new wxIntProperty(_("Layer"), wxPG_LABEL, m_layer));
77 pg->Append(new wxIntProperty(_("Row"), wxPG_LABEL, m_row));
78 pg->Append(new wxIntProperty(_("Position"), wxPG_LABEL, m_position));
79
80 pg->Append(new wxPropertyCategory(_("Size")));
81 pg->Append(new wxStringProperty(_("Best Size"), wxPG_LABEL, wxCrafter::EncodeSize(m_bestSize)));
82 pg->Append(new wxStringProperty(_("Min Size"), wxPG_LABEL, wxCrafter::EncodeSize(m_minSize)));
83 pg->Append(new wxStringProperty(_("Max Size"), wxPG_LABEL, wxCrafter::EncodeSize(m_maxSize)));
84
85 wxPGProperty* propButtons = pg->Append(new wxPropertyCategory(_("Buttons")));
86 pg->Expand(propButtons);
87
88 prop = pg->Append(new wxBoolProperty(_("Close Button"), wxPG_LABEL, m_closeButton));
89 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
90
91 prop = pg->Append(new wxBoolProperty(_("Minimize Button"), wxPG_LABEL, m_minButton));
92 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
93
94 prop = pg->Append(new wxBoolProperty(_("Maximize Button"), wxPG_LABEL, m_maxButton));
95 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
96
97 prop = pg->Append(new wxBoolProperty(_("Pin Button"), wxPG_LABEL, m_pinButton));
98 pg->SetPropertyAttribute(prop, wxPG_BOOL_USE_CHECKBOX, true);
99 }
100
101 void AuiPaneInfo::FromJSON(const JSONElement& json)
102 {
103 Reset();
104 if(json.isOk() == false) { return; }
105
106 m_name = json.namedObject("m_name").toString();
107 m_caption = json.namedObject("m_caption").toString();
108 m_dockDirection = json.namedObject("m_dockDirection").toString();
109 if(m_dockDirection.IsEmpty()) m_dockDirection = "wxAUI_DOCK_LEFT";
110
111 m_layer = json.namedObject("m_layer").toInt();
112 m_row = json.namedObject("m_row").toInt();
113 m_position = json.namedObject("m_position").toInt();
114 m_bestSize = json.namedObject("m_bestSize").toSize();
115 m_minSize = json.namedObject("m_minSize").toSize();
116 m_maxSize = json.namedObject("m_maxSize").toSize();
117 m_resizable = json.namedObject("m_resizable").toBool();
118 m_captionVisible = json.namedObject("m_captionVisible").toBool();
119 m_closeButton = json.namedObject("m_closeButton").toBool();
120 m_minButton = json.namedObject("m_minButton").toBool();
121 m_maxButton = json.namedObject("m_maxButton").toBool();
122 m_pinButton = json.namedObject("m_pinButton").toBool();
123 m_toolbarPane = json.namedObject("m_toolbarPane").toBool();
124 }
125
126 JSONElement AuiPaneInfo::ToJSON() const
127 {
128 JSONElement element = JSONElement::createObject("wxAuiPaneInfo");
129 element.addProperty(wxT("m_name"), m_name);
130 element.addProperty(wxT("m_caption"), m_caption);
131 element.addProperty(wxT("m_dockDirection"), m_dockDirection);
132 element.addProperty(wxT("m_layer"), m_layer);
133 element.addProperty(wxT("m_row"), m_row);
134 element.addProperty(wxT("m_position"), m_position);
135 element.addProperty(wxT("m_bestSize"), m_bestSize);
136 element.addProperty(wxT("m_minSize"), m_minSize);
137 element.addProperty(wxT("m_maxSize"), m_maxSize);
138 element.addProperty(wxT("m_resizable"), m_resizable);
139 element.addProperty(wxT("m_captionVisible"), m_captionVisible);
140 element.addProperty(wxT("m_closeButton"), m_closeButton);
141 element.addProperty(wxT("m_minButton"), m_minButton);
142 element.addProperty(wxT("m_maxButton"), m_maxButton);
143 element.addProperty(wxT("m_pinButton"), m_pinButton);
144 element.addProperty(wxT("m_toolbarPane"), m_toolbarPane);
145 return element;
146 }
147 void AuiPaneInfo::Reset()
148 {
149 m_dockDirection = "wxAUI_DOCK_LEFT";
150 m_layer = 0;
151 m_row = 0;
152 m_position = 0;
153 m_bestSize = wxSize(100, 100);
154 m_minSize = wxSize(100, 100);
155 m_maxSize = wxSize(100, 100);
156 m_resizable = true;
157 m_captionVisible = true;
158 m_closeButton = false;
159 m_minButton = false;
160 m_maxButton = false;
161 m_pinButton = false;
162 m_toolbarPane = false;
163 }
164
165 void AuiPaneInfo::OnChanged(wxPropertyGridEvent& e)
166 {
167 wxPGProperty* prop = e.GetProperty();
168 wxString label = prop->GetLabel();
169 wxString value = prop->GetValueAsString();
170 int iValue = prop->GetValue().GetLong();
171 wxSize szValue = wxCrafter::DecodeSize(value);
172 bool bValue = prop->GetValue().GetBool();
173
174 if(label == _("Name"))
175 m_name = value;
176 else if(label == _("Caption"))
177 m_caption = value;
178 else if(label == _("Caption Visible"))
179 m_captionVisible = bValue;
180 else if(label == _("Resizable"))
181 m_resizable = bValue;
182 else if(label == _("Direction"))
183 m_dockDirection = value;
184 else if(label == _("Layer"))
185 m_layer = iValue;
186 else if(label == _("Row"))
187 m_row = iValue;
188 else if(label == _("Position"))
189 m_position = iValue;
190
191 else if(label == _("Best Size"))
192 m_bestSize = szValue;
193 else if(label == _("Min Size"))
194 m_minSize = szValue;
195 else if(label == _("Max Size"))
196 m_maxSize = szValue;
197
198 else if(label == _("Close Button"))
199 m_closeButton = bValue;
200 else if(label == _("Minimize Button"))
201 m_minButton = bValue;
202 else if(label == _("Maximize Button"))
203 m_maxButton = bValue;
204 else if(label == _("Pin Button"))
205 m_pinButton = bValue;
206 else if(label == _("ToolBar Pane"))
207 m_toolbarPane = bValue;
208 }
209
210 wxString AuiPaneInfo::ToXRC(const wxString& objXRC) const
211 {
212 wxString xrc;
213 xrc << "<object class=\"wxAuiPaneInfo\" name=\"" << m_name << "\">"
214 << "<caption>" << m_caption << "</caption>"
215 << "<caption_visible>" << XRC_BOOL_TO_STR(m_captionVisible)
216 << "</caption_visible>"
217
218 // Dockable Directions
219 << "<top_dockable>1</top_dockable>"
220 << "<left_dockable>1</left_dockable>"
221 << "<bottom_dockable>1</bottom_dockable>"
222 << "<right_dockable>1</right_dockable>"
223
224 // Behaviours
225 << "<resizable>" << (m_resizable ? "1" : "0") << "</resizable>"
226 << "<movable>"
227 << "1"
228 << "</movable>"
229 << "<floatable>"
230 << "1"
231 << "</floatable>"
232
233 // Sizes
234 << "<best_size>" << wxCrafter::EncodeSize(m_bestSize) << "</best_size>"
235 << "<max_size>" << wxCrafter::EncodeSize(m_maxSize) << "</max_size>"
236 << "<min_size>" << wxCrafter::EncodeSize(m_minSize) << "</min_size>";
237
238 if(m_dockDirection == "wxAUI_DOCK_TOP")
239 xrc << "<top>1</top>";
240 else if(m_dockDirection == "wxAUI_DOCK_BOTTOM")
241 xrc << "<bottom>1</bottom>";
242 else if(m_dockDirection == "wxAUI_DOCK_LEFT")
243 xrc << "<left>1</left>";
244 else if(m_dockDirection == "wxAUI_DOCK_RIGHT")
245 xrc << "<right>1</right>";
246 else if(m_dockDirection == "wxAUI_DOCK_CENTER" || m_dockDirection == "wxAUI_DOCK_CENTRE")
247 xrc << "<centre>1</centre>";
248 else
249 xrc << "<left>1</left>"; // Default
250
251 xrc << "<layer>" << m_layer << "</layer>"
252 << "<row>" << m_row << "</row>"
253 << "<position>" << m_position
254 << "</position>"
255
256 // Buttons
257 << "<close_button>" << XRC_BOOL_TO_STR(m_closeButton) << "</close_button>"
258 << "<minimize_button>" << XRC_BOOL_TO_STR(m_minButton) << "</minimize_button>"
259 << "<maximize_button>" << XRC_BOOL_TO_STR(m_maxButton) << "</maximize_button>"
260 << "<pin_button>" << XRC_BOOL_TO_STR(m_pinButton) << "</pin_button>";
261
262 if(m_toolbarPane) { xrc << "<toolbar_pane>" << XRC_BOOL_TO_STR(m_toolbarPane) << "</toolbar_pane>"; }
263 xrc << objXRC << "</object>";
264 return xrc;
265 }