Debian Codegraph @

wxcrafter/xrc_handlers/myxh_grid.cpp

raw
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_grid.cpp
3 // Purpose: XML resource handler for the grid control
4 // Author: Agron Selimaj
5 // Created: 2005/08/11
6 // RCS-ID: $Id: xh_grid.cpp 67254 2011-03-20 00:14:35Z DS $
7 // Copyright: (c) 2005 Agron Selimaj, Freepour Controls Inc.
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13 #include "wxgui_helpers.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifdef wxOVERRIDE
20 #undef wxOVERRIDE
21 #define wxOVERRIDE
22 #endif
23
24 #include "wx/grid.h"
25
26 #undef wxOVERRIDE
27 #define wxOVERRIDE override
28
29 #include "myxh_grid.h"
30 #include <wx/xml/xml.h>
31
32 MyWxGridXmlHandler::MyWxGridXmlHandler()
33 : wxXmlResourceHandler()
34 {
35 AddWindowStyles();
36 }
37
38 struct GridColInfo {
39 typedef std::vector<GridColInfo> Vector_t;
40
41 wxString label;
42 long size;
43
44 GridColInfo()
45 : size(-1)
46 {
47 }
48 };
49
50 struct GridRowInfo {
51 typedef std::vector<GridRowInfo> Vector_t;
52
53 wxString label;
54 long size;
55
56 GridRowInfo()
57 : size(-1)
58 {
59 }
60 };
61
62 wxObject* MyWxGridXmlHandler::DoCreateResource()
63 {
64 XRC_MAKE_INSTANCE(grid, wxGrid);
65
66 grid->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(wxT("style")), GetName());
67
68 // Extract columns info
69 GridColInfo::Vector_t columns;
70 wxXmlNode* columnsNode = GetParamNode(wxT("columns"));
71 if(columnsNode) {
72 wxXmlNode* colnode = columnsNode->GetChildren();
73 while(colnode) {
74 wxXmlNode* colAttr = colnode->GetChildren();
75 GridColInfo col;
76 while(colAttr) {
77 if(colAttr->GetName() == "name") {
78 col.label = colAttr->GetNodeContent();
79
80 } else if(colAttr->GetName() == "colsize") {
81 colAttr->GetNodeContent().ToCLong(&col.size);
82 }
83 colAttr = colAttr->GetNext();
84 }
85 columns.push_back(col);
86 colnode = colnode->GetNext();
87 }
88 }
89
90 // Extract rows info
91 GridRowInfo::Vector_t rows;
92 wxXmlNode* rowsNode = GetParamNode(wxT("rows"));
93 if(rowsNode) {
94 wxXmlNode* rownode = rowsNode->GetChildren();
95 while(rownode) {
96 wxXmlNode* rowAttr = rownode->GetChildren();
97 GridRowInfo row;
98 while(rowAttr) {
99 if(rowAttr->GetName() == "name") {
100 row.label = rowAttr->GetNodeContent();
101
102 } else if(rowAttr->GetName() == "rowsize") {
103 rowAttr->GetNodeContent().ToCLong(&row.size);
104 }
105 rowAttr = rowAttr->GetNext();
106 }
107 rows.push_back(row);
108 rownode = rownode->GetNext();
109 }
110 }
111
112 grid->CreateGrid(0, columns.size());
113 for(size_t i = 0; i < columns.size(); ++i) {
114 grid->SetColLabelValue(i, columns.at(i).label);
115
116 if(columns.at(i).size != -1) { grid->SetColSize(i, columns.at(i).size); }
117 }
118
119 if(HasParam(wxT("autosizecol"))) {
120 if(GetLong(wxT("autosizecol")) == 1) { grid->AutoSizeColumns(); }
121 }
122
123 if(HasParam(wxT("eidtable"))) { grid->EnableEditing((GetLong(wxT("editable")) == 1)); }
124
125 // Append the rows
126 for(size_t i = 0; i < rows.size(); ++i) {
127 int rowid = grid->GetNumberRows();
128 grid->AppendRows();
129 grid->SetRowLabelValue(rowid, rows.at(i).label);
130 if(rows.at(i).size != -1) { grid->SetRowSize(rowid, rows.at(i).size); }
131 }
132
133 // Alignment
134 wxString rowLabelVAlgn = GetNodeContent("row-label-v-alignment");
135 wxString rowLabelHAlgn = GetNodeContent("row-label-h-alignment");
136
137 wxString colLabelVAlgn = GetNodeContent("col-label-v-alignment");
138 wxString colLabelHAlgn = GetNodeContent("col-label-h-alignment");
139
140 grid->SetRowLabelAlignment(wxCrafter::ToAligment(rowLabelHAlgn), wxCrafter::ToAligment(rowLabelVAlgn));
141 grid->SetColLabelAlignment(wxCrafter::ToAligment(colLabelHAlgn), wxCrafter::ToAligment(colLabelVAlgn));
142
143 grid->UseNativeColHeader(GetBool("native-header", true));
144 // grid->SetUseNativeColLabels(GetBool("native-col-labels", true));
145
146 long colLabelHeight = GetLong("col-label-size");
147 long rowLabelWidth = GetLong("row-label-size");
148
149 if(colLabelHeight != -1) { grid->SetColLabelSize(colLabelHeight); }
150
151 if(rowLabelWidth != -1) { grid->SetRowLabelSize(rowLabelWidth); }
152
153 SetupWindow(grid);
154 return grid;
155 }
156
157 bool MyWxGridXmlHandler::CanHandle(wxXmlNode* node) { return IsOfClass(node, wxT("wxGrid")); }
158
159 wxString MyWxGridXmlHandler::GetNodeContent(const wxString& name)
160 {
161 wxXmlNode* node = GetParamNode(name);
162 if(node) { return node->GetNodeContent(); }
163 return wxEmptyString;
164 }