Debian Codegraph @

wxcrafter/controls/data_view_tree_list_ctrl_wrapper.cpp

raw
1 #include "data_view_tree_list_ctrl_wrapper.h"
2
3 #include "allocator_mgr.h"
4 #include "bool_property.h"
5 #include "data_view_list_ctrl_wrapper.h"
6 #include "wxc_project_metadata.h"
7 #include "wxgui_bitmaploader.h"
8 #include "wxgui_helpers.h"
9
10 #include <wx/dataview.h>
11
12 DataViewTreeListCtrlWrapper::DataViewTreeListCtrlWrapper()
13 : wxcWidget(ID_WXDATAVIEWTREELISTCTRL)
14 {
15 PREPEND_STYLE(wxDV_SINGLE, true);
16 PREPEND_STYLE(wxDV_MULTIPLE, false);
17 PREPEND_STYLE(wxDV_ROW_LINES, true);
18 PREPEND_STYLE(wxDV_HORIZ_RULES, false);
19 PREPEND_STYLE(wxDV_VERT_RULES, false);
20 PREPEND_STYLE(wxDV_VARIABLE_LINE_HEIGHT, false);
21 PREPEND_STYLE(wxDV_NO_HEADER, false);
22
23 RegisterEvent("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED", "wxDataViewEvent",
24 _("Process a wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED event"));
25 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED", "wxDataViewEvent",
26 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED event.\nThis event is triggered by double "
27 "clicking an item or pressing some special key (usually \"Enter\") when it is focused"));
28 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING", "wxDataViewEvent",
29 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING event.\nThis event can be vetoed in order to "
30 "prevent editing on an item by item basis"));
31 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED", "wxDataViewEvent",
32 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED event"));
33 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE", "wxDataViewEvent",
34 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE event"));
35 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING", "wxDataViewEvent",
36 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING event"));
37 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED", "wxDataViewEvent",
38 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED event"));
39 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING", "wxDataViewEvent",
40 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING event"));
41 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED", "wxDataViewEvent",
42 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED event"));
43 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED", "wxDataViewEvent",
44 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED event"));
45 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU", "wxDataViewEvent",
46 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU event generated when the user right clicks "
47 "inside the control.\nNotice that this menu is generated even if the click didn't occur on any "
48 "valid item, in this case wxDataViewEvent::GetItem() simply returns an invalid item."));
49 RegisterEvent("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK", "wxDataViewEvent",
50 _("Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK event"));
51 RegisterEvent("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK", "wxDataViewEvent",
52 _("Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK event"));
53 RegisterEvent("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED", "wxDataViewEvent",
54 _("Process a wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED event"));
55 RegisterEvent("wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED", "wxDataViewEvent",
56 _("Process a wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED event"));
57 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG", "wxDataViewEvent",
58 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG event"));
59 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE", "wxDataViewEvent",
60 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE event"));
61 RegisterEvent("wxEVT_COMMAND_DATAVIEW_ITEM_DROP", "wxDataViewEvent",
62 _("Process a wxEVT_COMMAND_DATAVIEW_ITEM_DROP event"));
63
64 m_namePattern = "m_dataview";
65 SetName(GenerateName());
66
67 SetPropertyString(_("Common Settings"), "wxDataViewTreeListCtrl");
68 DelProperty(_("Control Specific Settings"));
69 AddProperty(new CategoryProperty(_("Inherited C++ Class Properties")));
70
71 wxString tip;
72 tip << _("The generated model class name\n")
73 << _("wxCrafter will generate a TreeListCtrl model like 'Tree-List-Ctrl\n")
74 << _("** Leave this field empty if you do not want wxCrafter to generate a model class for you");
75
76 wxString name = GetName();
77 // Using the plain name here, e.g. m_dataview13, creates code that won't compile:
78 // wxObjectDataPtr<m_dataview13Model> m_dataview13Model;
79 if(name.Left(2) == "m_") {
80 name = name.Mid(2);
81 }
82 AddProperty(new StringProperty(PROP_DV_MODEL_CLASS_NAME, name + "Model", tip));
83 AddProperty(new BoolProperty(PROP_DV_CONTAINER_ITEM_HAS_COLUMNS, true,
84 _("Indicate if a container item merely acts as a headline (or for categorisation) or "
85 "if it also acts a normal item with entries for further columns")));
86 }
87
88 DataViewTreeListCtrlWrapper::~DataViewTreeListCtrlWrapper() {}
89
90 wxcWidget* DataViewTreeListCtrlWrapper::Clone() const { return new DataViewTreeListCtrlWrapper(); }
91
92 wxString DataViewTreeListCtrlWrapper::CppCtorCode() const
93 {
94 wxString code = CPPStandardWxCtor("wxDV_SINGLE|wxDV_ROW_LINES");
95 code << AssociateModelCode();
96 return code;
97 }
98
99 void DataViewTreeListCtrlWrapper::GetIncludeFile(wxArrayString& headers) const
100 {
101 headers.Add("#include <wx/dataview.h>");
102
103 wxString modelName = GetModelName();
104 if(modelName.IsEmpty()) {
105 return;
106 }
107
108 // Model file name
109 wxString headerFileName = modelName;
110 headerFileName << "." << wxcProjectMetadata::Get().GetHeaderFileExt();
111 headerFileName.MakeLower();
112
113 wxString modelIncludeStatement;
114 modelIncludeStatement << "#include \"" << headerFileName << "\"";
115 headers.Add(modelIncludeStatement);
116 }
117
118 wxString DataViewTreeListCtrlWrapper::GetWxClassName() const { return "wxDataViewCtrl"; }
119
120 void DataViewTreeListCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const
121 {
122 if(type == XRC_LIVE) {
123 text << XRCUnknown();
124
125 } else {
126 text << "<object class=\""
127 << "wxDataViewListCtrl"
128 << "\" name=\"" << wxCrafter::XMLEncode(GetName()) << "\"";
129 if(!PropertyString(PROP_SUBCLASS_NAME).empty()) {
130 text << " subclass=\"" << wxCrafter::XMLEncode(PropertyString(PROP_SUBCLASS_NAME)) << "\"";
131 }
132 text << ">";
133
134 text << XRCSize() << XRCStyle() << XRCCommonAttributes();
135
136 // Columns...
137 ChildrenXRC(text, type);
138
139 text << XRCSuffix();
140 }
141 }
142
143 void DataViewTreeListCtrlWrapper::GenerateAdditionalFiles(wxStringMap_t& extraFile) const
144 {
145 wxString modelName = GetModelName();
146 if(modelName.IsEmpty()) {
147 return;
148 }
149
150 wxCrafter::ResourceLoader rl;
151 wxString modelCpp = rl.File("my_tree_list_model.cpp");
152 wxString modelHpp = rl.File("my_tree_list_model.hpp");
153
154 wxString blockGuard = modelName;
155 blockGuard << "_GUARD__" << wxcProjectMetadata::Get().GetHeaderFileExt();
156 blockGuard.MakeUpper();
157
158 // Replace place holders
159 modelCpp.Replace("MODEL_NAME", modelName);
160 modelHpp.Replace("MODEL_NAME", modelName);
161 modelHpp.Replace("BLOCK_GUARD", blockGuard);
162 modelHpp.Replace("HAS_CONTAINER_COLUMNS", PropertyBool(PROP_DV_CONTAINER_ITEM_HAS_COLUMNS));
163
164 wxString headerFileName, cppFileName;
165 wxString basename = modelName;
166 basename.MakeLower();
167
168 cppFileName = basename;
169 headerFileName = basename;
170
171 cppFileName << ".cpp";
172 headerFileName << "." << wxcProjectMetadata::Get().GetHeaderFileExt();
173
174 // change the include statement in the template file
175 modelCpp.Replace("my_tree_list_model.hpp", headerFileName);
176
177 // add the files
178 extraFile.insert(std::make_pair(headerFileName, modelHpp));
179 extraFile.insert(std::make_pair(cppFileName, modelCpp));
180 }
181
182 wxString DataViewTreeListCtrlWrapper::DoGenerateClassMember() const
183 {
184 wxString members;
185 members << wxcWidget::DoGenerateClassMember();
186
187 wxString modelName = GetModelName();
188 if(modelName.IsEmpty()) {
189 return members;
190 }
191
192 // Add the model member
193 members << "\n "
194 << "wxObjectDataPtr<" << modelName << "> " << GetName() << "Model;\n";
195 return members;
196 }
197
198 wxString DataViewTreeListCtrlWrapper::AssociateModelCode() const
199 {
200 wxString modelBaseName = GetModelName();
201 if(modelBaseName.IsEmpty()) {
202 return "";
203 }
204
205 wxString code;
206 wxString modelName = GetName() + "Model";
207 code << "\n";
208 code << modelName << " = new " << modelBaseName << ";\n";
209 code << modelName << "->SetColCount( " << GetChildren().size() << " );\n";
210 code << GetName() << "->AssociateModel(" << modelName << ".get() );\n";
211 return code;
212 }
213
214 wxString DataViewTreeListCtrlWrapper::GetModelName() const
215 {
216 wxString modelName = PropertyString(PROP_DV_MODEL_CLASS_NAME);
217 modelName.Trim().Trim(false);
218 return modelName;
219 }