Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
form.cc
Go to the documentation of this file.
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
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22#include "form.hh"
23#include "dlib/dlib.h"
24
25namespace form {
26
27using namespace dw::core::ui;
28
30{
31 this->name = dStrdup (name);
32}
33
35{
36 free((char *)name);
37}
38
40 TextResource *resource):
42{
43 this->resource = resource;
44}
45
47{
48 return resource->getText ();
49}
50
52 (const char *name, RadioButtonResource *resource, const char **values):
54{
55 this->resource = resource;
56
57 int n = 0;
58 while (values[n])
59 n++;
60 this->values = new const char*[n + 1];
61 for (int i = 0; i < n; i++)
62 this->values[i] = dStrdup (values[i]);
63 this->values[n] = 0;
64}
65
67{
68 for (int i = 0; values[i]; i++)
69 free((char *)values[i]);
70 delete[] values;
71}
72
74{
76 int i;
77 for (it = resource->groupIterator (), i = 0; it->hasNext (); i++) {
78 RadioButtonResource *resource = it->getNext ();
79 if(resource->isActivated ()) {
80 it->unref ();
81 return values[i];
82 }
83 }
84
85 it->unref ();
86 return NULL;
87}
88
90 (const char *name, CheckButtonResource *resource):
92{
93 this->resource = resource;
94}
95
97{
98 return resource->isActivated () ? "true" : NULL;
99}
100
102 (const char *name, SelectionResource *resource, const char **values):
103 Form::ResourceDecorator (name)
104{
105 this->resource = resource;
106
107 int n = 0;
108 while (values[n])
109 n++;
110 this->values = new const char*[n + 1];
111 for(int i = 0; i < n; i++)
112 this->values[i] = dStrdup (values[i]);
113 this->values[n] = 0;
114}
115
117{
118 for(int i = 0; values[i]; i++)
119 free((char *)values[i]);
120 delete[] values;
121}
122
124{
125 valueBuf.clear();
126 int n = resource->getNumberOfItems ();
127 bool first = true;
128 for (int i = 0; i < n; i++) {
129 if (resource->isSelected (i)) {
130 if (!first)
131 valueBuf.append (", ");
132 valueBuf.append (values[i]);
133 first = false;
134 }
135 }
136
137 return valueBuf.getChars ();
138}
139
141{
142 form->send (NULL, NULL, -1, -1);
143}
144
148
152
154 const char *value)
155{
156 this->form = form;
157 this->name = dStrdup (name);
158 this->value = dStrdup (value);
159}
160
162{
163 free((char *)name);
164 free((char *)value);
165}
166
169{
170 form->send (name, value, event->xCanvas, event->yCanvas);
171}
172
174{
175 resources = new lout::container::typed::List <ResourceDecorator> (true);
178 new lout::container::typed::List <FormClickedReceiver> (true);
179}
180
182{
183 delete resources;
184 delete activateReceiver;
185 delete clickedReceivers;
186}
187
191void Form::addTextResource (const char *name,
193{
194 resources->append (new TextResourceDecorator (name, resource));
196}
197
203void Form::addRadioButtonResource (const char *name,
205 const char **values)
206{
207 resources->append (new RadioButtonResourceDecorator (name, resource,
208 values));
210}
211
215void Form::addCheckButtonResource (const char *name,
217{
218 resources->append (new CheckButtonResourceDecorator (name, resource));
220}
221
225void Form::addSelectionResource (const char *name,
227 const char **values)
228{
229 resources->append (new SelectionResourceDecorator (name, resource, values));
231}
232
236void Form::addButtonResource (const char *name,
238 const char *value)
239{
240 FormClickedReceiver *receiver =
241 new FormClickedReceiver (this, name, value);
242 resource->connectClicked (receiver);
243 clickedReceivers->append (receiver);
244}
245
249void Form::send (const char *buttonName, const char *buttonValue, int x, int y)
250{
251 for (lout::container::typed::Iterator <ResourceDecorator> it =
252 resources->iterator ();
253 it.hasNext (); ) {
254 ResourceDecorator *resource = it.getNext ();
255 const char *value = resource->getValue ();
256 if (value)
257 printf ("%s = %s; x=%d y=%d\n", resource->getName (), value, x, y);
258 }
259
260 if(buttonName && buttonValue)
261 printf ("%s = %s\n", buttonName, buttonValue);
262}
263
264} // namespace form
Represents a button press or release event.
Definition events.hh:58
virtual RadioButtonResource * getNext()=0
Basic interface for all resources.
Definition ui.hh:289
void connectClicked(ClickedReceiver *receiver)
Definition ui.hh:388
void connectActivate(ActivateReceiver *receiver)
Definition ui.hh:386
Base interface for dw::core::ui::ListResource and dw::core::ui::OptionMenuResource.
Definition ui.hh:467
virtual const char * getText()=0
Decorates instances of dw::core::ui::CheckButtonResource.
Definition form.hh:80
dw::core::ui::CheckButtonResource * resource
Definition form.hh:82
CheckButtonResourceDecorator(const char *name, dw::core::ui::CheckButtonResource *resource)
Definition form.cc:90
void leave(dw::core::ui::Resource *resource)
Definition form.cc:149
void activate(dw::core::ui::Resource *resource)
Definition form.cc:140
void enter(dw::core::ui::Resource *resource)
Definition form.cc:145
FormClickedReceiver(Form *form, const char *name, const char *value)
Definition form.cc:153
void clicked(dw::core::ui::Resource *resource, dw::core::EventButton *event)
Definition form.cc:167
Decorates instances of dw::core::ui::RadioButtonResource.
Definition form.hh:62
dw::core::ui::RadioButtonResource * resource
Definition form.hh:64
RadioButtonResourceDecorator(const char *name, dw::core::ui::RadioButtonResource *resource, const char **values)
Definition form.cc:52
Decorates instances of dw::core::ui::Resource.
Definition form.hh:28
ResourceDecorator(const char *name)
Definition form.cc:29
virtual const char * getValue()=0
const char * getName()
Definition form.hh:37
Decorates instances of dw::core::ui::SelectionResource.
Definition form.hh:95
SelectionResourceDecorator(const char *name, dw::core::ui::SelectionResource *resource, const char **values)
Definition form.cc:102
dw::core::ui::SelectionResource * resource
Definition form.hh:97
Decorates instances of dw::core::ui::TextResource.
Definition form.hh:45
TextResourceDecorator(const char *name, dw::core::ui::TextResource *resource)
Definition form.cc:39
dw::core::ui::TextResource * resource
Definition form.hh:47
Handles HTML form data.
Definition form.hh:19
void addSelectionResource(const char *name, dw::core::ui::SelectionResource *resource, const char **values)
Adds an instance of dw::core::ui::SelectionResource.
Definition form.cc:225
lout::container::typed::List< FormClickedReceiver > * clickedReceivers
Definition form.hh:139
void addCheckButtonResource(const char *name, dw::core::ui::CheckButtonResource *resource)
Adds an instance of dw::core::ui::CheckButtonResource.
Definition form.cc:215
void addTextResource(const char *name, dw::core::ui::TextResource *resource)
Adds an instance of dw::core::ui::TextResource.
Definition form.cc:191
FormActivateReceiver * activateReceiver
Definition form.hh:138
void addRadioButtonResource(const char *name, dw::core::ui::RadioButtonResource *resource, const char **values)
Adds an instance of dw::core::ui::RadioButtonResource.
Definition form.cc:203
lout::container::typed::List< ResourceDecorator > * resources
Definition form.hh:137
void addButtonResource(const char *name, dw::core::ui::ButtonResource *resource, const char *value)
Definition form.cc:236
void send(const char *buttonName, const char *buttonValue, int x, int y)
Definition form.cc:249
char * dStrdup(const char *s)
Definition dlib.c:77
Anything related to embedded UI widgets is defined here.
Definition core.hh:36
Definition form.cc:25