blob: c181d6741f95c353541e5a2edac89a3c5463708a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#include "form.hh"
#include "html.hh"
namespace form {
using namespace dw::core::ui;
Form::ResourceDecorator::ResourceDecorator (const char *name)
{
this->name = strdup (name);
}
Form::ResourceDecorator::~ResourceDecorator ()
{
delete name;
}
Form::TextResourceDecorator::TextResourceDecorator (const char *name,
TextResource *resource):
Form::ResourceDecorator (name)
{
this->resource = resource;
}
const char *Form::TextResourceDecorator::getValue ()
{
return resource->getText ();
}
Form::RadioButtonResourceDecorator::RadioButtonResourceDecorator
(const char *name, RadioButtonResource *resource, const char **values):
Form::ResourceDecorator (name)
{
this->resource = resource;
int n = 0;
while (values[n])
n++;
this->values = new const char*[n];
for(int i = 0; i < n; i++)
this->values[i] = strdup (values[i]);
values[n] = 0;
}
Form::RadioButtonResourceDecorator::~RadioButtonResourceDecorator ()
{
for(int i = 0; values[i]; i++)
delete values[i];
delete values;
}
const char *Form::RadioButtonResourceDecorator::getValue ()
{
RadioButtonResource::GroupIterator *it;
int i;
for (it = resource->groupIterator (), i = 0; it->hasNext (); i++) {
RadioButtonResource *resource = it->getNext ();
if(resource->isActivated ()) {
it->unref ();
return values[i];
}
}
it->unref ();
return NULL;
}
Form::Form (void *p)
{
ext_data = p;
resources = new container::typed::List <ResourceDecorator> (true);
}
Form::~Form ()
{
delete resources;
}
void Form::clicked (ButtonResource *resource, int buttonNo)
{
/*
for (container::typed::Iterator <ResourceDecorator> it =
resources->iterator ();
it.hasNext (); ) {
ResourceDecorator *resource = it.getNext ();
const char *value = resource->getValue ();
if (value)
printf ("%s = %s\n", resource->getName (), value);
}
*/
printf ("Form::clicked:: Button was clicked\n");
// Let html.cc handle the event
a_Html_form_event_handler(ext_data, this, (Resource*)resource);
}
void Form::activate (Resource *resource)
{
a_Html_form_event_handler(ext_data, this, (Resource*)resource);
}
} // namespace form
|