| 1 |
#include "col_header_flags_property.h" |
| 2 |
#include "wxgui_helpers.h" |
| 3 |
#include <wx/headercol.h> |
| 4 |
#include <wx/dataview.h> |
| 5 |
|
| 6 |
ColHeaderFlagsProperty::ColHeaderFlagsProperty(const wxString& label, int initialValue, const wxString& tip, |
| 7 |
eColumnKind kind) |
| 8 |
: PropertyBase(tip) |
| 9 |
, m_initialValue(initialValue) |
| 10 |
{ |
| 11 |
SetLabel(label); |
| 12 |
if(kind == eColumnKind::kListCtrl) { |
| 13 |
m_names.Add("wxCOL_RESIZABLE"); |
| 14 |
m_names.Add("wxCOL_SORTABLE"); |
| 15 |
m_names.Add("wxCOL_REORDERABLE"); |
| 16 |
m_names.Add("wxCOL_HIDDEN"); |
| 17 |
|
| 18 |
m_values.Add(wxCOL_RESIZABLE); |
| 19 |
m_values.Add(wxCOL_SORTABLE); |
| 20 |
m_values.Add(wxCOL_REORDERABLE); |
| 21 |
m_values.Add(wxCOL_HIDDEN); |
| 22 |
|
| 23 |
} else { |
| 24 |
m_names.Add("wxDATAVIEW_COL_RESIZABLE"); |
| 25 |
m_names.Add("wxDATAVIEW_COL_SORTABLE"); |
| 26 |
m_names.Add("wxDATAVIEW_COL_REORDERABLE"); |
| 27 |
m_names.Add("wxDATAVIEW_COL_HIDDEN"); |
| 28 |
|
| 29 |
m_values.Add(wxDATAVIEW_COL_RESIZABLE); |
| 30 |
m_values.Add(wxDATAVIEW_COL_SORTABLE); |
| 31 |
m_values.Add(wxDATAVIEW_COL_REORDERABLE); |
| 32 |
m_values.Add(wxDATAVIEW_COL_HIDDEN); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
ColHeaderFlagsProperty::ColHeaderFlagsProperty() |
| 37 |
: PropertyBase("") |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
ColHeaderFlagsProperty::~ColHeaderFlagsProperty() {} |
| 42 |
|
| 43 |
PropertyeType ColHeaderFlagsProperty::GetType() { return PT_COL_HEADER_FLAGS; } |
| 44 |
|
| 45 |
wxString ColHeaderFlagsProperty::GetValue() const |
| 46 |
{ |
| 47 |
wxString str_value; |
| 48 |
for(size_t i = 0; i < m_values.GetCount(); ++i) { |
| 49 |
if(m_initialValue & m_values.Item(i)) { str_value << m_names.Item(i) << "|"; } |
| 50 |
} |
| 51 |
if(!str_value.IsEmpty()) { str_value.RemoveLast(); } |
| 52 |
return str_value; |
| 53 |
} |
| 54 |
|
| 55 |
void ColHeaderFlagsProperty::SetValue(const wxString& value) |
| 56 |
{ |
| 57 |
m_initialValue = 0; |
| 58 |
wxArrayString selections = wxCrafter::Split(value, "|,;"); |
| 59 |
for(size_t i = 0; i < selections.GetCount(); ++i) { |
| 60 |
int index = m_names.Index(selections.Item(i)); |
| 61 |
if(index != wxNOT_FOUND) { m_initialValue |= m_values.Item(index); } |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
JSONElement ColHeaderFlagsProperty::Serialize() const |
| 66 |
{ |
| 67 |
JSONElement json = JSONElement::createObject(); |
| 68 |
json.addProperty(wxT("type"), wxT("colHeaderFlags")); |
| 69 |
DoBaseSerialize(json); |
| 70 |
json.addProperty("stringValue", GetValue()); |
| 71 |
return json; |
| 72 |
} |
| 73 |
|
| 74 |
void ColHeaderFlagsProperty::UnSerialize(const JSONElement& json) |
| 75 |
{ |
| 76 |
wxString tmpValue; |
| 77 |
DoBaseUnSerialize(json); |
| 78 |
tmpValue = json.namedObject(wxT("stringValue")).toString(); |
| 79 |
SetValue(tmpValue); |
| 80 |
} |
| 81 |
|
| 82 |
wxArrayString ColHeaderFlagsProperty::GetOptions() const { return m_names; } |
| 83 |
|
| 84 |
wxArrayInt ColHeaderFlagsProperty::GetOptionsValues() const { return m_values; } |
| 85 |
|
| 86 |
long ColHeaderFlagsProperty::GetValueLong() const { return m_initialValue; } |