1 | // %flair:license{ |
---|
2 | // This file is part of the Flair framework distributed under the |
---|
3 | // CECILL-C License, Version 1.0. |
---|
4 | // %flair:license} |
---|
5 | // created: 2012/05/02 |
---|
6 | // filename: Widget.cpp |
---|
7 | // |
---|
8 | // author: Guillaume Sanahuja |
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253 |
---|
10 | // |
---|
11 | // version: $Id: $ |
---|
12 | // |
---|
13 | // purpose: Abstract class for all Framework's widget classes |
---|
14 | // |
---|
15 | // |
---|
16 | /*********************************************************************/ |
---|
17 | |
---|
18 | #include "Widget.h" |
---|
19 | #include "Widget_impl.h" |
---|
20 | |
---|
21 | using std::string; |
---|
22 | |
---|
23 | namespace flair { |
---|
24 | namespace gui { |
---|
25 | |
---|
26 | using namespace core; |
---|
27 | |
---|
28 | Widget::Widget(const Widget *parent, string name, string type) |
---|
29 | : Object(parent, name, type) { |
---|
30 | pimpl_ = new Widget_impl(this, parent, name, type); |
---|
31 | } |
---|
32 | |
---|
33 | Widget::~Widget() { delete pimpl_; } |
---|
34 | |
---|
35 | template <> bool Widget::GetPersistentXmlProp(std::string prop, double &value) { |
---|
36 | xmlChar *result = NULL; |
---|
37 | result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str()); |
---|
38 | |
---|
39 | if (result != NULL) { |
---|
40 | value = xmlXPathCastStringToNumber(result); |
---|
41 | xmlFree(result); |
---|
42 | return true; |
---|
43 | } else { |
---|
44 | return false; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | template <> bool Widget::GetPersistentXmlProp(std::string prop, float &value) { |
---|
49 | double tmp; |
---|
50 | if (GetPersistentXmlProp<double>(prop, tmp)) { |
---|
51 | value = tmp; |
---|
52 | return true; |
---|
53 | } else { |
---|
54 | return false; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | template <> bool Widget::GetPersistentXmlProp(std::string prop, bool &value) { |
---|
59 | double tmp; |
---|
60 | if (GetPersistentXmlProp<double>(prop, tmp)) { |
---|
61 | value = tmp; |
---|
62 | return true; |
---|
63 | } else { |
---|
64 | return false; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | template <> |
---|
69 | bool Widget::GetPersistentXmlProp(std::string prop, int32_t &value) { |
---|
70 | double tmp; |
---|
71 | if (GetPersistentXmlProp<double>(prop, tmp)) { |
---|
72 | value = tmp; |
---|
73 | return true; |
---|
74 | } else { |
---|
75 | return false; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | template <> |
---|
80 | bool Widget::GetPersistentXmlProp(std::string prop, uint16_t &value) { |
---|
81 | double tmp; |
---|
82 | if (GetPersistentXmlProp<double>(prop, tmp)) { |
---|
83 | value = tmp; |
---|
84 | return true; |
---|
85 | } else { |
---|
86 | return false; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | template <> |
---|
91 | bool Widget::GetPersistentXmlProp(std::string prop, std::string &value) { |
---|
92 | xmlChar *result = NULL; |
---|
93 | result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str()); |
---|
94 | if (result != NULL) { |
---|
95 | value = std::string((char *)result); |
---|
96 | xmlFree(result); |
---|
97 | return true; |
---|
98 | } else { |
---|
99 | return false; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | template <> |
---|
104 | void Widget::SetVolatileXmlProp(string prop, string value, xmlNodePtr node) { |
---|
105 | if (node == NULL) |
---|
106 | node = pimpl_->send_node; |
---|
107 | xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value.c_str()); |
---|
108 | } |
---|
109 | |
---|
110 | template <> |
---|
111 | void Widget::SetVolatileXmlProp(string prop, char *value, xmlNodePtr node) { |
---|
112 | if (node == NULL) |
---|
113 | node = pimpl_->send_node; |
---|
114 | xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value); |
---|
115 | } |
---|
116 | |
---|
117 | template <> |
---|
118 | void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) { |
---|
119 | xmlChar *xmlChar_value = xmlXPathCastNumberToString(value); |
---|
120 | |
---|
121 | if (node == NULL) |
---|
122 | node = pimpl_->send_node; |
---|
123 | xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value); |
---|
124 | xmlFree(xmlChar_value); |
---|
125 | } |
---|
126 | |
---|
127 | template <> |
---|
128 | void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) { |
---|
129 | SetVolatileXmlProp<double>(prop, value, node); |
---|
130 | } |
---|
131 | |
---|
132 | template <> |
---|
133 | void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) { |
---|
134 | SetVolatileXmlProp<double>(prop, value, node); |
---|
135 | } |
---|
136 | |
---|
137 | template <> |
---|
138 | void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) { |
---|
139 | SetVolatileXmlProp<double>(prop, value, node); |
---|
140 | } |
---|
141 | |
---|
142 | template <> |
---|
143 | void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) { |
---|
144 | SetVolatileXmlProp<double>(prop, value, node); |
---|
145 | } |
---|
146 | |
---|
147 | template <> |
---|
148 | void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) { |
---|
149 | SetVolatileXmlProp<double>(prop, value, node); |
---|
150 | } |
---|
151 | |
---|
152 | template <> |
---|
153 | void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) { |
---|
154 | SetVolatileXmlProp<double>(prop, value, node); |
---|
155 | } |
---|
156 | |
---|
157 | template <> |
---|
158 | void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) { |
---|
159 | SetVolatileXmlProp<double>(prop, value, node); |
---|
160 | } |
---|
161 | |
---|
162 | template <> |
---|
163 | void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) { |
---|
164 | SetVolatileXmlProp<double>(prop, value, node); |
---|
165 | } |
---|
166 | |
---|
167 | template <> |
---|
168 | void Widget::SetVolatileXmlProp(string prop, xmlChar *value, xmlNodePtr node) { |
---|
169 | if (node == NULL) |
---|
170 | node = pimpl_->send_node; |
---|
171 | xmlSetProp(node, (xmlChar *)prop.c_str(), value); |
---|
172 | } |
---|
173 | |
---|
174 | template <> |
---|
175 | void Widget::SetVolatileXmlProp(string prop, DataType const &dataType, |
---|
176 | xmlNodePtr node) { |
---|
177 | if (node == NULL) |
---|
178 | node = pimpl_->send_node; |
---|
179 | xmlSetProp(node, (xmlChar *)prop.c_str(), |
---|
180 | (xmlChar *)dataType.GetDescription().c_str()); |
---|
181 | /* |
---|
182 | switch(dataType) |
---|
183 | { |
---|
184 | case io_data::Float: |
---|
185 | xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"float"); |
---|
186 | break; |
---|
187 | case io_data::Int8_t: |
---|
188 | xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int8_t"); |
---|
189 | break; |
---|
190 | case io_data::Int16_t: |
---|
191 | xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int16_t"); |
---|
192 | break; |
---|
193 | } |
---|
194 | */ |
---|
195 | } |
---|
196 | |
---|
197 | template <> void Widget::SetPersistentXmlProp(std::string prop, double value) { |
---|
198 | SetVolatileXmlProp(prop, value); |
---|
199 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
200 | } |
---|
201 | |
---|
202 | template <> void Widget::SetPersistentXmlProp(std::string prop, float value) { |
---|
203 | SetVolatileXmlProp(prop, value); |
---|
204 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
205 | } |
---|
206 | |
---|
207 | template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) { |
---|
208 | SetVolatileXmlProp(prop, value); |
---|
209 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
210 | } |
---|
211 | |
---|
212 | template <> |
---|
213 | void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) { |
---|
214 | SetVolatileXmlProp(prop, value); |
---|
215 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
216 | } |
---|
217 | |
---|
218 | template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) { |
---|
219 | SetVolatileXmlProp(prop, value); |
---|
220 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
221 | } |
---|
222 | |
---|
223 | template <> void Widget::SetPersistentXmlProp(std::string prop, std::string value) { |
---|
224 | SetVolatileXmlProp(prop, value); |
---|
225 | SetVolatileXmlProp(prop, value, pimpl_->file_node); |
---|
226 | } |
---|
227 | |
---|
228 | void Widget::UnsetPersistentXmlProp(std::string prop) { |
---|
229 | xmlUnsetProp(pimpl_->file_node, (xmlChar *)prop.c_str()); |
---|
230 | } |
---|
231 | |
---|
232 | void Widget::SendXml(void) { pimpl_->SendXml(); } |
---|
233 | |
---|
234 | void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); } |
---|
235 | |
---|
236 | bool Widget::isEnabled(void) const { return pimpl_->isenabled; } |
---|
237 | |
---|
238 | } // end namespace gui |
---|
239 | } // end namespace flair |
---|