| 1 |
#include "myxh_dataview.h" |
| 2 |
#include <wx/dataview.h> |
| 3 |
#include <wx/imaglist.h> |
| 4 |
#include <wx/tokenzr.h> |
| 5 |
|
| 6 |
MyWxDataViewCtrlHandler::MyWxDataViewCtrlHandler() |
| 7 |
: wxXmlResourceHandler() |
| 8 |
{ |
| 9 |
XRC_ADD_STYLE(wxDV_SINGLE); |
| 10 |
XRC_ADD_STYLE(wxDV_MULTIPLE); |
| 11 |
XRC_ADD_STYLE(wxDV_ROW_LINES); |
| 12 |
XRC_ADD_STYLE(wxDV_HORIZ_RULES); |
| 13 |
XRC_ADD_STYLE(wxDV_VERT_RULES); |
| 14 |
XRC_ADD_STYLE(wxDV_VARIABLE_LINE_HEIGHT); |
| 15 |
XRC_ADD_STYLE(wxDV_NO_HEADER); |
| 16 |
AddWindowStyles(); |
| 17 |
} |
| 18 |
|
| 19 |
wxObject* MyWxDataViewCtrlHandler::DoCreateResource() |
| 20 |
{ |
| 21 |
if(m_class == "wxDataViewColumn") { |
| 22 |
HandleListCol(); |
| 23 |
|
| 24 |
} else { |
| 25 |
wxASSERT_MSG(m_class == "wxDataViewCtrl", wxT("can't handle unknown node")); |
| 26 |
|
| 27 |
return HandleListCtrl(); |
| 28 |
} |
| 29 |
|
| 30 |
return m_parentAsWindow; |
| 31 |
} |
| 32 |
|
| 33 |
bool MyWxDataViewCtrlHandler::CanHandle(wxXmlNode* node) |
| 34 |
{ |
| 35 |
return IsOfClass(node, "wxDataViewCtrl") || IsOfClass(node, "wxDataViewColumn"); |
| 36 |
} |
| 37 |
|
| 38 |
void MyWxDataViewCtrlHandler::HandleListCol() |
| 39 |
{ |
| 40 |
// Add column to the wxDataViewCtrl |
| 41 |
wxDataViewCtrl* const list = wxDynamicCast(m_parentAsWindow, wxDataViewCtrl); |
| 42 |
wxCHECK_RET(list, wxT("must have wxDataViewCtrl parent")); |
| 43 |
|
| 44 |
if(!HasParam(wxT("coltype"))) { return; } |
| 45 |
|
| 46 |
// Column properties |
| 47 |
wxString coltype = GetText("coltype"); |
| 48 |
int colwidth = GetLong("width", -1); |
| 49 |
wxString label = GetText("label"); |
| 50 |
wxString salign = GetText("align", false); |
| 51 |
int style = GetLong("style", 0); |
| 52 |
wxString cellmode = GetText("cellmode", false); |
| 53 |
|
| 54 |
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT; |
| 55 |
if(cellmode == "wxDATAVIEW_CELL_ACTIVATABLE") |
| 56 |
mode = wxDATAVIEW_CELL_ACTIVATABLE; |
| 57 |
else if(cellmode == "") |
| 58 |
mode = wxDATAVIEW_CELL_EDITABLE; |
| 59 |
|
| 60 |
wxAlignment al = wxALIGN_LEFT; |
| 61 |
if(salign == "wxALIGN_RIGHT") |
| 62 |
al = wxALIGN_RIGHT; |
| 63 |
else if(salign == "wxALIGN_CENTER") |
| 64 |
al = wxALIGN_CENTER; |
| 65 |
|
| 66 |
if(coltype == "bitmap") { |
| 67 |
list->AppendBitmapColumn(label, list->GetColumnCount(), mode, colwidth, al, style); |
| 68 |
|
| 69 |
} else if(coltype == "check") { |
| 70 |
list->AppendToggleColumn(label, list->GetColumnCount(), mode, colwidth, al, style); |
| 71 |
|
| 72 |
} else if(coltype == "text") { |
| 73 |
list->AppendTextColumn(label, list->GetColumnCount(), mode, colwidth, al, style); |
| 74 |
|
| 75 |
} else if(coltype == "icontext") { |
| 76 |
list->AppendIconTextColumn(label, list->GetColumnCount(), mode, colwidth, al, style); |
| 77 |
|
| 78 |
} else if(coltype == "progress") { |
| 79 |
list->AppendProgressColumn(label, list->GetColumnCount(), mode, colwidth, al, style); |
| 80 |
|
| 81 |
} else if(coltype == "choice") { |
| 82 |
wxString content = GetText("choices", false); |
| 83 |
wxArrayString choices = ::wxStringTokenize(content, ",", wxTOKEN_STRTOK); |
| 84 |
list->AppendColumn(new wxDataViewColumn(label, |
| 85 |
new wxDataViewChoiceRenderer(choices, mode, wxDVR_DEFAULT_ALIGNMENT), |
| 86 |
list->GetColumnCount(), colwidth, al, style)); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
wxDataViewCtrl* MyWxDataViewCtrlHandler::HandleListCtrl() |
| 91 |
{ |
| 92 |
XRC_MAKE_INSTANCE(list, wxDataViewCtrl) |
| 93 |
|
| 94 |
list->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle()); |
| 95 |
list->SetName(GetName()); |
| 96 |
CreateChildrenPrivately(list); |
| 97 |
SetupWindow(list); |
| 98 |
return list; |
| 99 |
} |