Mercurial > dillo_port1.3
annotate test/form.cc @ 2016:8cf59505bd0a
tests cleanup
author | corvid <corvid@lavabit.com> |
---|---|
date | Sat, 14 May 2011 06:45:42 +0000 |
parents | 02ef25700865 |
children |
rev | line source |
---|---|
347 | 1 /* |
2 * Dillo Widget | |
3 * | |
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 3 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
972
d7dbd3dcfa38
Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents:
468
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
347 | 18 */ |
19 | |
20 | |
21 | |
22 #include "form.hh" | |
23 | |
24 namespace form { | |
25 | |
26 using namespace dw::core::ui; | |
27 | |
28 Form::ResourceDecorator::ResourceDecorator (const char *name) | |
29 { | |
30 this->name = strdup (name); | |
31 } | |
32 | |
33 Form::ResourceDecorator::~ResourceDecorator () | |
34 { | |
2016 | 35 free((char *)name); |
347 | 36 } |
37 | |
38 Form::TextResourceDecorator::TextResourceDecorator (const char *name, | |
39 TextResource *resource): | |
40 Form::ResourceDecorator (name) | |
41 { | |
42 this->resource = resource; | |
43 } | |
44 | |
45 const char *Form::TextResourceDecorator::getValue () | |
46 { | |
47 return resource->getText (); | |
48 } | |
49 | |
50 Form::RadioButtonResourceDecorator::RadioButtonResourceDecorator | |
51 (const char *name, RadioButtonResource *resource, const char **values): | |
1326 | 52 Form::ResourceDecorator (name) |
347 | 53 { |
54 this->resource = resource; | |
55 | |
56 int n = 0; | |
57 while (values[n]) | |
58 n++; | |
59 this->values = new const char*[n + 1]; | |
2016 | 60 for (int i = 0; i < n; i++) |
347 | 61 this->values[i] = strdup (values[i]); |
457
e864ed116f26
- Fixed a segfault bug in the test/ directory.
Jorge Arellano Cid <jcid@dillo.org>
parents:
347
diff
changeset
|
62 this->values[n] = 0; |
347 | 63 } |
64 | |
65 Form::RadioButtonResourceDecorator::~RadioButtonResourceDecorator () | |
66 { | |
2016 | 67 for (int i = 0; values[i]; i++) |
68 free((char *)values[i]); | |
347 | 69 delete[] values; |
70 } | |
71 | |
72 const char *Form::RadioButtonResourceDecorator::getValue () | |
73 { | |
74 RadioButtonResource::GroupIterator *it; | |
75 int i; | |
76 for (it = resource->groupIterator (), i = 0; it->hasNext (); i++) { | |
77 RadioButtonResource *resource = it->getNext (); | |
78 if(resource->isActivated ()) { | |
79 it->unref (); | |
80 return values[i]; | |
81 } | |
82 } | |
83 | |
84 it->unref (); | |
85 return NULL; | |
86 } | |
87 | |
88 Form::CheckButtonResourceDecorator::CheckButtonResourceDecorator | |
89 (const char *name, CheckButtonResource *resource): | |
90 Form::ResourceDecorator (name) | |
91 { | |
92 this->resource = resource; | |
93 } | |
94 | |
95 const char *Form::CheckButtonResourceDecorator::getValue () | |
96 { | |
97 return resource->isActivated () ? "true" : NULL; | |
98 } | |
99 | |
100 Form::SelectionResourceDecorator::SelectionResourceDecorator | |
101 (const char *name, SelectionResource *resource, const char **values): | |
1326 | 102 Form::ResourceDecorator (name) |
347 | 103 { |
104 this->resource = resource; | |
105 | |
106 int n = 0; | |
107 while (values[n]) | |
108 n++; | |
109 this->values = new const char*[n + 1]; | |
110 for(int i = 0; i < n; i++) | |
111 this->values[i] = strdup (values[i]); | |
112 this->values[n] = 0; | |
113 } | |
114 | |
115 Form::SelectionResourceDecorator::~SelectionResourceDecorator () | |
116 { | |
117 for(int i = 0; values[i]; i++) | |
2016 | 118 free((char *)values[i]); |
347 | 119 delete[] values; |
120 } | |
121 | |
122 const char *Form::SelectionResourceDecorator::getValue () | |
123 { | |
124 valueBuf.clear(); | |
125 int n = resource->getNumberOfItems (); | |
126 bool first = true; | |
127 for (int i = 0; i < n; i++) { | |
128 if (resource->isSelected (i)) { | |
129 if (!first) | |
130 valueBuf.append (", "); | |
131 valueBuf.append (values[i]); | |
132 first = false; | |
133 } | |
134 } | |
135 | |
136 return valueBuf.getChars (); | |
137 } | |
138 | |
139 void Form::FormActivateReceiver::activate (Resource *resource) | |
140 { | |
141 form->send (NULL, NULL, -1, -1); | |
142 } | |
143 | |
144 void Form::FormActivateReceiver::enter (Resource *resource) | |
145 { | |
146 } | |
147 | |
148 void Form::FormActivateReceiver::leave (Resource *resource) | |
149 { | |
150 } | |
151 | |
152 Form::FormClickedReceiver::FormClickedReceiver (Form *form, const char *name, | |
153 const char *value) | |
154 { | |
155 this->form = form; | |
156 this->name = strdup (name); | |
157 this->value = strdup (value); | |
158 } | |
159 | |
160 Form::FormClickedReceiver::~FormClickedReceiver () | |
161 { | |
2016 | 162 free((char *)name); |
163 free((char *)value); | |
347 | 164 } |
1326 | 165 |
468
6ddee709a59a
Moved clicked from ButtonResource to Resource.
Jorge Arellano Cid <jcid@dillo.org>
parents:
459
diff
changeset
|
166 void Form::FormClickedReceiver::clicked (Resource *resource, |
459
ddf513f18af5
- Set middle click to submit in a new TAB. (Helps to keep form data!)
Jorge Arellano Cid <jcid@dillo.org>
parents:
457
diff
changeset
|
167 dw::core::EventButton *event) |
347 | 168 { |
459
ddf513f18af5
- Set middle click to submit in a new TAB. (Helps to keep form data!)
Jorge Arellano Cid <jcid@dillo.org>
parents:
457
diff
changeset
|
169 form->send (name, value, event->xCanvas, event->yCanvas); |
347 | 170 } |
171 | |
172 Form::Form () | |
173 { | |
174 resources = new lout::container::typed::List <ResourceDecorator> (true); | |
175 activateReceiver = new FormActivateReceiver (this); | |
1326 | 176 clickedReceivers = |
347 | 177 new lout::container::typed::List <FormClickedReceiver> (true); |
178 } | |
179 | |
180 Form::~Form () | |
181 { | |
182 delete resources; | |
183 delete activateReceiver; | |
184 delete clickedReceivers; | |
185 } | |
186 | |
187 /** | |
188 * \brief Adds an instance of dw::core::ui::TextResource. | |
189 */ | |
190 void Form::addTextResource (const char *name, | |
191 dw::core::ui::TextResource *resource) | |
192 { | |
193 resources->append (new TextResourceDecorator (name, resource)); | |
194 resource->connectActivate (activateReceiver); | |
195 } | |
196 | |
197 /** | |
198 * \brief Adds an instance of dw::core::ui::RadioButtonResource. | |
199 * | |
200 * This method has to be called only once for a group of radio buttons. | |
201 */ | |
202 void Form::addRadioButtonResource (const char *name, | |
203 dw::core::ui::RadioButtonResource *resource, | |
204 const char **values) | |
205 { | |
206 resources->append (new RadioButtonResourceDecorator (name, resource, | |
207 values)); | |
208 resource->connectActivate (activateReceiver); | |
209 } | |
210 | |
211 /** | |
212 * \brief Adds an instance of dw::core::ui::CheckButtonResource. | |
213 */ | |
214 void Form::addCheckButtonResource (const char *name, | |
215 dw::core::ui::CheckButtonResource *resource) | |
216 { | |
217 resources->append (new CheckButtonResourceDecorator (name, resource)); | |
218 resource->connectActivate (activateReceiver); | |
219 } | |
220 | |
221 /** | |
222 * \brief Adds an instance of dw::core::ui::SelectionResource. | |
223 */ | |
224 void Form::addSelectionResource (const char *name, | |
225 dw::core::ui::SelectionResource *resource, | |
226 const char **values) | |
227 { | |
228 resources->append (new SelectionResourceDecorator (name, resource, values)); | |
229 resource->connectActivate (activateReceiver); | |
230 } | |
231 | |
232 /** | |
233 * \todo Comment this; | |
234 */ | |
235 void Form::addButtonResource (const char *name, | |
236 dw::core::ui::ButtonResource *resource, | |
237 const char *value) | |
238 { | |
239 FormClickedReceiver *receiver = | |
240 new FormClickedReceiver (this, name, value); | |
241 resource->connectClicked (receiver); | |
242 clickedReceivers->append (receiver); | |
243 } | |
244 | |
245 /** | |
246 * \todo Comment this; | |
247 */ | |
248 void Form::send (const char *buttonName, const char *buttonValue, int x, int y) | |
249 { | |
250 for (lout::container::typed::Iterator <ResourceDecorator> it = | |
251 resources->iterator (); | |
252 it.hasNext (); ) { | |
253 ResourceDecorator *resource = it.getNext (); | |
254 const char *value = resource->getValue (); | |
255 if (value) | |
256 printf ("%s = %s; x=%d y=%d\n", resource->getName (), value, x, y); | |
257 } | |
258 | |
259 if(buttonName && buttonValue) | |
260 printf ("%s = %s\n", buttonName, buttonValue); | |
261 } | |
262 | |
263 } // namespace form |