diff options
author | jcid <devnull@localhost> | 2007-10-07 00:36:34 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2007-10-07 00:36:34 +0200 |
commit | 93715c46a99c96d6c866968312691ec9ab0f6a03 (patch) | |
tree | 573f19ec6aa740844f53a7c0eb7114f04096bf64 /src/form.cc |
Initial revision
Diffstat (limited to 'src/form.cc')
-rw-r--r-- | src/form.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/form.cc b/src/form.cc new file mode 100644 index 00000000..f170cbef --- /dev/null +++ b/src/form.cc @@ -0,0 +1,98 @@ +#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); +} + +} // namespace form |