| 1 |
#include "data_view_list_ctrl_column.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "bool_property.h" |
| 5 |
#include "choice_property.h" |
| 6 |
#include "col_header_flags_property.h" |
| 7 |
#include "multi_strings_property.h" |
| 8 |
#include "wxgui_helpers.h" |
| 9 |
|
| 10 |
#include <wx/dataview.h> |
| 11 |
|
| 12 |
DataViewListCtrlColumn::DataViewListCtrlColumn() |
| 13 |
: wxcWidget(ID_WXDATAVIEWCOL) |
| 14 |
{ |
| 15 |
m_styles.Clear(); |
| 16 |
m_sizerFlags.Clear(); |
| 17 |
m_properties.DeleteValues(); |
| 18 |
|
| 19 |
wxArrayString coltype; |
| 20 |
coltype.Add("bitmap"); |
| 21 |
coltype.Add("check"); |
| 22 |
coltype.Add("text"); |
| 23 |
coltype.Add("icontext"); |
| 24 |
coltype.Add("progress"); |
| 25 |
coltype.Add("choice"); |
| 26 |
|
| 27 |
wxArrayString alignment; |
| 28 |
alignment.Add("wxALIGN_LEFT"); |
| 29 |
alignment.Add("wxALIGN_RIGHT"); |
| 30 |
alignment.Add("wxALIGN_CENTER"); |
| 31 |
|
| 32 |
wxArrayString cellType; |
| 33 |
cellType.Add("wxDATAVIEW_CELL_INERT"); |
| 34 |
cellType.Add("wxDATAVIEW_CELL_ACTIVATABLE"); |
| 35 |
cellType.Add("wxDATAVIEW_CELL_EDITABLE"); |
| 36 |
|
| 37 |
AddProperty(new CategoryProperty(_("wxDataViewListCtrl Column"))); |
| 38 |
AddProperty(new StringProperty(PROP_NAME, _("My Column"), _("Column Caption"))); |
| 39 |
AddProperty(new StringProperty(PROP_WIDTH, wxT("-2"), |
| 40 |
_("Column Width (in pixels)\n-1 - special value for column width meaning " |
| 41 |
"unspecified/default\n-2 - size the column automatically to fit all values"))); |
| 42 |
AddProperty(new ChoiceProperty(PROP_DV_LISTCTRL_COL_TYPES, coltype, 2, _("Column Type"))); |
| 43 |
AddProperty(new MultiStringsProperty(PROP_OPTIONS, _("Choices strings\nRelevant only for column of type 'choice'"), |
| 44 |
";", "Enter choices")); |
| 45 |
AddProperty(new ChoiceProperty(PROP_DV_LISTCTRL_COL_ALIGN, alignment, 0, _("Cell Alignment"))); |
| 46 |
AddProperty( |
| 47 |
new ChoiceProperty(PROP_DV_CELLMODE, cellType, 0, _("Cell mode (can be editable, activatable or inert)"))); |
| 48 |
AddProperty(new ColHeaderFlagsProperty( |
| 49 |
PROP_DV_COLFLAGS, 0, _("One or more flags of the wxDataViewColumnFlags enumeration"), eColumnKind::kDataView)); |
| 50 |
} |
| 51 |
|
| 52 |
DataViewListCtrlColumn::~DataViewListCtrlColumn() {} |
| 53 |
|
| 54 |
wxcWidget* DataViewListCtrlColumn::Clone() const { return new DataViewListCtrlColumn(); } |
| 55 |
|
| 56 |
wxString DataViewListCtrlColumn::CppCtorCode() const |
| 57 |
{ |
| 58 |
wxString cppCode; |
| 59 |
wxString parentName = GetParent()->GetName(); |
| 60 |
wxString alignstring = PropertyString(PROP_DV_LISTCTRL_COL_ALIGN); |
| 61 |
wxString label = wxCrafter::UNDERSCORE(GetName()); |
| 62 |
wxString coltype = PropertyString(PROP_DV_LISTCTRL_COL_TYPES); |
| 63 |
|
| 64 |
bool childOfDataViewListCtrl = GetParent()->GetType() == ID_WXDATAVIEWLISTCTRL; |
| 65 |
wxString cellMode = PropertyString(PROP_DV_CELLMODE); |
| 66 |
wxString colFlag = PropertyString(PROP_COL_FLAGS, "0"); |
| 67 |
wxString columnWidth; |
| 68 |
columnWidth << "WXC_FROM_DIP(" << PropertyString(PROP_WIDTH) << ")"; |
| 69 |
if(coltype == "bitmap") { |
| 70 |
cppCode << parentName << "->AppendBitmapColumn(" << label << ", " << parentName << "->GetColumnCount(), " |
| 71 |
<< cellMode << ", " << columnWidth << ", " << alignstring << ", " << colFlag << ");"; |
| 72 |
|
| 73 |
} else if(coltype == "check") { |
| 74 |
cppCode << parentName << "->AppendToggleColumn(" << label << ", "; |
| 75 |
if(!childOfDataViewListCtrl) |
| 76 |
cppCode << parentName << "->GetColumnCount(), "; |
| 77 |
cppCode << cellMode << ", " << columnWidth << ", " << alignstring << ", " << colFlag << ");"; |
| 78 |
|
| 79 |
} else if(coltype == "text") { |
| 80 |
cppCode << parentName << "->AppendTextColumn(" << label << ", "; |
| 81 |
if(!childOfDataViewListCtrl) |
| 82 |
cppCode << parentName << "->GetColumnCount(), "; |
| 83 |
cppCode << cellMode << ", " << columnWidth << ", " << alignstring << ", " << colFlag << ");"; |
| 84 |
|
| 85 |
} else if(coltype == "icontext") { |
| 86 |
cppCode << parentName << "->AppendIconTextColumn(" << label << ", "; |
| 87 |
if(!childOfDataViewListCtrl) |
| 88 |
cppCode << parentName << "->GetColumnCount(), "; |
| 89 |
cppCode << cellMode << ", " << columnWidth << ", " << alignstring << ", " << colFlag << ");"; |
| 90 |
|
| 91 |
} else if(coltype == "progress") { |
| 92 |
cppCode << parentName << "->AppendProgressColumn(" << label << ", "; |
| 93 |
if(!childOfDataViewListCtrl) |
| 94 |
cppCode << parentName << "->GetColumnCount(), "; |
| 95 |
cppCode << cellMode << ", " << columnWidth << ", " << alignstring << ", " << colFlag << ");"; |
| 96 |
} else if(coltype == "choice") { |
| 97 |
cppCode << "{\n"; |
| 98 |
cppCode << " wxArrayString choices;\n"; |
| 99 |
|
| 100 |
wxArrayString choices = ::wxStringTokenize(PropertyString(PROP_OPTIONS), ";", wxTOKEN_STRTOK); |
| 101 |
for(size_t i = 0; i < choices.GetCount(); ++i) { |
| 102 |
cppCode << " choices.Add(" << wxCrafter::UNDERSCORE(choices.Item(i)) << ");\n"; |
| 103 |
} |
| 104 |
cppCode << " " << parentName << "->AppendColumn( new wxDataViewColumn( " << label |
| 105 |
<< ", new wxDataViewChoiceRenderer( choices, " << cellMode << ", wxDVR_DEFAULT_ALIGNMENT), " |
| 106 |
<< parentName << "->GetColumnCount(), " << PropertyString(PROP_WIDTH) << ", " << alignstring << ", " |
| 107 |
<< colFlag << "));"; |
| 108 |
cppCode << "}\n"; |
| 109 |
} |
| 110 |
return cppCode; |
| 111 |
} |
| 112 |
|
| 113 |
void DataViewListCtrlColumn::GetIncludeFile(wxArrayString& headers) const { wxUnusedVar(headers); } |
| 114 |
|
| 115 |
wxString DataViewListCtrlColumn::GetWxClassName() const { return ""; } |
| 116 |
|
| 117 |
void DataViewListCtrlColumn::ToXRC(wxString& text, XRC_TYPE type) const |
| 118 |
{ |
| 119 |
if(type == wxcWidget::XRC_LIVE) { |
| 120 |
text << XRCUnknown(); |
| 121 |
} else { |
| 122 |
text << wxT("<object class=\"wxDataViewColumn\">") << wxT("<coltype>") |
| 123 |
<< PropertyString(PROP_DV_LISTCTRL_COL_TYPES) << wxT("</coltype>") << wxT("<width>") |
| 124 |
<< PropertyString(PROP_WIDTH) << wxT("</width>") << wxT("<label>") << wxCrafter::CDATA(GetName()) |
| 125 |
<< wxT("</label>") << wxT("<align>") << PropertyString(PROP_DV_LISTCTRL_COL_ALIGN) << wxT("</align>") |
| 126 |
<< wxT("<cellmode>") << PropertyString(PROP_DV_CELLMODE) << wxT("</cellmode>") << wxT("<choices>") |
| 127 |
<< wxCrafter::XMLEncode(PropertyString(PROP_OPTIONS)) << wxT("</choices>") << wxT("</object>"); |
| 128 |
} |
| 129 |
} |