Debian Codegraph @

wxcrafter/src/sizer_flags_list_view.cpp

raw
1 #include "sizer_flags_list_view.h"
2 #include "notebook_page_wrapper.h"
3 #include "wxc_project_metadata.h"
4 #include "wxc_widget.h"
5 #include "wxgui_defs.h"
6 #include "wxgui_helpers.h"
7 #include "wxguicraft_main_view.h"
8 #include <algorithm>
9 #include <event_notifier.h>
10
11 SizerFlagsListView::SizerFlagsListView()
12 : m_wxcWidget(NULL)
13 , m_flags(NULL)
14 {
15 }
16
17 SizerFlagsListView::~SizerFlagsListView() {}
18
19 void SizerFlagsListView::Changed(wxPropertyGrid* pg, wxPropertyGridEvent& e)
20 {
21 CHECK_POINTER(m_flags);
22 CHECK_POINTER(m_wxcWidget);
23
24 // Update the flags
25
26 // Update wxGB* flags
27 wxPGProperty* prop = e.GetProperty();
28 wxString label = prop->GetLabel();
29 wxString value = prop->GetValueAsString();
30
31 if(label == _("Flags")) {
32 bool showWxAll;
33 if(pg->GetSelection()->GetLabel() == "wxALL") {
34 showWxAll = pg->GetSelection()->GetValue().GetBool();
35 if(showWxAll) {
36 // No need to check if these are already present; duplicates will do no harm
37 value << ",wxLEFT,wxRIGHT,wxTOP,wxBOTTOM";
38 } else {
39 // No need to worry about the commas; we use wxTOKEN_STRTOK below
40 value.Replace("wxLEFT", "");
41 value.Replace("wxRIGHT", "");
42 value.Replace("wxTOP", "");
43 value.Replace("wxBOTTOM", "");
44 }
45
46 wxArrayString arr = wxCrafter::Split(value, ",", wxTOKEN_STRTOK);
47 m_wxcWidget->ClearSizerFlags();
48 for(size_t i = 0; i < arr.GetCount(); ++i) {
49 m_wxcWidget->EnableSizerFlag(arr.Item(i), true);
50 }
51 m_wxcWidget->EnableSizerFlag("wxALL", showWxAll);
52 } else {
53 showWxAll = value.Contains("wxLEFT") && value.Contains("wxRIGHT") && value.Contains("wxTOP") &&
54 value.Contains("wxBOTTOM");
55 wxString flag_modified = pg->GetSelection()->GetLabel();
56 bool flag_added = pg->GetSelection()->GetValue().GetBool();
57 m_wxcWidget->EnableSizerFlag(flag_modified, flag_added);
58 m_wxcWidget->EnableSizerFlag("wxALL", showWxAll);
59 }
60 Construct(pg, m_wxcWidget);
61 }
62
63 if(label == _("Proportion")) {
64 m_wxcWidget->SizerItem().SetProportion(prop->GetValue().GetInteger());
65
66 } else if(label == _("Border")) {
67 m_wxcWidget->SizerItem().SetBorder(prop->GetValue().GetInteger());
68
69 } else if(label == _("wxGBPosition")) {
70 m_wxcWidget->SetGbPos(prop->GetValueAsString());
71
72 } else if(label == _("wxGBSpan")) {
73 m_wxcWidget->SetGbSpan(prop->GetValueAsString());
74 }
75
76 // Notify about modifications
77 wxCommandEvent evt(wxEVT_PROPERTIES_MODIFIED);
78 EventNotifier::Get()->AddPendingEvent(evt);
79 }
80
81 void SizerFlagsListView::Construct(wxPropertyGrid* pg, wxcWidget* wb)
82 {
83 pg->Clear();
84 m_flags = NULL;
85 m_wxcWidget = wb;
86 CHECK_POINTER(m_wxcWidget);
87
88 if(m_wxcWidget->IsTopWindow() || !m_wxcWidget->IsSizerItem()) { return; }
89
90 // Popuplate the sizer flags
91 pg->Append(new wxIntProperty(_("Proportion"), wxPG_LABEL, m_wxcWidget->SizerItem().GetProportion()));
92 pg->Append(new wxIntProperty(_("Border"), wxPG_LABEL, m_wxcWidget->SizerItem().GetBorder()));
93
94 wxPGProperty* gbCategory(NULL);
95 if(m_wxcWidget->IsGridBagSizerItem()) {
96 pg->Append(new wxPropertyCategory(_("GridBagSizer")));
97 pg->Append(new wxStringProperty(_("wxGBPosition"), wxPG_LABEL, m_wxcWidget->GetGbPos()));
98 pg->Append(new wxStringProperty(_("wxGBSpan"), wxPG_LABEL, m_wxcWidget->GetGbSpan()));
99 }
100
101 pg->Append(new wxPropertyCategory(_("Sizer Flags")));
102
103 wxcWidget::MapStyles_t flags = m_wxcWidget->GetSizerFlags();
104 wxcWidget::MapStyles_t::ConstIterator iter = flags.Begin();
105
106 wxArrayString styles;
107 wxArrayInt stylesInt;
108 size_t stylesValue = 0;
109
110 // The control specific flags will show up first
111 wxPGChoices choices;
112 for(; iter != flags.End(); ++iter) {
113
114 //// Rather than using the real bitvalue of the sizer flag, create our own fake one
115 //// This is to avoid clashes between e.g. the composite wxALIGN_CENTER and its constituents
116 /// wxALIGN_CENTER_VERTICAL and HORIZONTAL
117 size_t flag_fake_value;
118 if(iter->second.style_name == "wxALIGN_TOP") {
119 // See the explanation inside enum SIZER_FLAG_VALUE
120 flag_fake_value = wxcWidget::SizerFakeValue(crafterALIGN_TOP);
121
122 } else if(iter->second.style_name == "wxRESERVE_SPACE_EVEN_IF_HIDDEN") {
123 flag_fake_value = wxcWidget::SizerFakeValue(iter->second.style_bit);
124
125 } else {
126 flag_fake_value = wxcWidget::SizerFakeValue(iter->second.style_bit);
127 }
128 choices.Add(iter->second.style_name, flag_fake_value);
129
130 // stylesInt.Add(flag_fake_value); // Add the value
131 if(iter->second.is_set) { stylesValue |= flag_fake_value; }
132 }
133
134 m_flags = (wxFlagsProperty*)pg->Append(new wxFlagsProperty(_("Flags"), wxPG_LABEL, choices, stylesValue));
135 #ifndef __WXMSW__
136 pg->SetPropertyAttribute(m_flags, wxPG_BOOL_USE_CHECKBOX, true);
137 #endif
138 // Set some tooltips to explain (at least to users who read tooltips) why some properties are disabled
139 pg->SetPropertyHelpString("Flags.wxALIGN_BOTTOM", "This will be disabled in vertical boxsizers");
140 pg->SetPropertyHelpString("Flags.wxALIGN_RIGHT", "This will be disabled in horizontal boxsizers");
141 pg->SetPropertyHelpString("Flags.wxALIGN_CENTER_VERTICAL",
142 "This will be disabled in vertical boxsizers, and in horizontal boxsizers with wxEXPAND");
143 pg->SetPropertyHelpString("Flags.wxALIGN_CENTER_HORIZONTAL",
144 "This will be disabled in horizontal boxsizers, and in vertical boxsizers with wxEXPAND");
145
146 pg->Expand(m_flags);
147 if(gbCategory) { pg->Collapse(gbCategory); }
148 pg->SetExtraStyle(wxPG_EX_HELP_AS_TOOLTIPS);
149 }
150
151 void SizerFlagsListView::DoUpdateUI(wxPropertyGrid* pg, wxUpdateUIEvent& event)
152 {
153 CHECK_POINTER(m_wxcWidget);
154 wxcWidget* parent = m_wxcWidget->GetParent();
155 CHECK_POINTER(parent);
156 if(!parent->GetWxClassName().Contains("BoxSizer")) { // we care only about wxBoxSizer and wxStaticBoxSizer
157 return;
158 }
159
160 bool hasEXPAND = pg->GetPropertyValueAsString("Flags").Contains("wxEXPAND");
161 bool hasACHoriz = pg->GetPropertyValueAsString("Flags").Contains("wxALIGN_CENTER_HORIZONTAL");
162 bool hasACVert = pg->GetPropertyValueAsString("Flags").Contains("wxALIGN_CENTER_VERTICAL");
163
164 if(parent->PropertyString(PROP_ORIENTATION) == "wxVERTICAL") {
165 pg->EnableProperty("Flags.wxALIGN_BOTTOM", false); // Can't have wxALIGN_BOTTOM in a vertical boxsizer
166 pg->EnableProperty("Flags.wxALIGN_CENTER_VERTICAL", false); // Can't have wxALIGN_CENTER_VERTICAL in a vertical
167 // boxsizer (unless it's part of wxALIGN_CENTER,
168 // which here is a separate property)
169 pg->EnableProperty("Flags.wxALIGN_CENTER_HORIZONTAL",
170 !hasEXPAND); // Can't have wxALIGN_CENTER_HORIZONTAL plus wxEXPAND in a vertical boxsizer
171 pg->EnableProperty("Flags.wxEXPAND",
172 !hasACHoriz); // Still can't have wxALIGN_CENTER_HORIZONTAL plus wxEXPAND in a vertical boxsizer
173 // Similarly for the relevant toolbar tools
174 event.Enable(!(event.GetId() == ID_TOOL_ALIGN_VCENTER || event.GetId() == ID_TOOL_ALIGN_BOTTOM
175 || (event.GetId() == ID_TOOL_ALIGN_HCENTER) && hasEXPAND
176 )
177 );
178
179 } else {
180 pg->EnableProperty("Flags.wxALIGN_RIGHT", false); // Can't have wxALIGN_RIGHT in a horizontal boxsizer
181 pg->EnableProperty("Flags.wxALIGN_CENTER_HORIZONTAL", false); // Can't have wxALIGN_CENTER_HORIZONTAL in a
182 // horizontal boxsizer (unless it's part of
183 // wxALIGN_CENTER, which here is a separate
184 // property)
185 pg->EnableProperty("Flags.wxALIGN_CENTER_VERTICAL",
186 !hasEXPAND); // Can't have wxALIGN_CENTER_VERTICAL plus wxEXPAND in a horizontal boxsizer
187 pg->EnableProperty("Flags.wxEXPAND",
188 !hasACVert); // Can't have wxALIGN_CENTER_VERTICAL plus wxEXPAND in a horizontal boxsizer
189
190 event.Enable(!(event.GetId() == ID_TOOL_ALIGN_HCENTER || event.GetId() == ID_TOOL_ALIGN_RIGHT
191 || (event.GetId() == ID_TOOL_ALIGN_VCENTER) && hasEXPAND
192 )
193 );
194 }
195 }