summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/form.cc102
-rw-r--r--src/form.hh90
-rw-r--r--src/html.cc66
-rw-r--r--src/html.hh5
5 files changed, 44 insertions, 221 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c427152e..fd2549a2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,8 +67,6 @@ dillo_fltk_SOURCES = \
capi.c \
capi.h \
plain.cc \
- form.cc \
- form.hh \
html.cc \
html.hh \
bookmark.c \
diff --git a/src/form.cc b/src/form.cc
deleted file mode 100644
index 73464f5d..00000000
--- a/src/form.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "form.hh"
-#include "html.hh"
-
-namespace form {
-
-using namespace dw::core::ui;
-
-Form::ResourceDecorator::ResourceDecorator (const char *name)
-{
- this->name = dStrdup (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] = dStrdup (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 lout::container::typed::List <ResourceDecorator> (true);
-}
-
-Form::~Form ()
-{
- delete resources;
-}
-
-void Form::clicked (ButtonResource *resource, int buttonNo, int x, int y)
-{
-/*
- 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, x, y);
-}
-
-void Form::activate (Resource *resource)
-{
- a_Html_form_event_handler(ext_data, this, (Resource*)resource, -1, -1);
-}
-
-} // namespace form
diff --git a/src/form.hh b/src/form.hh
deleted file mode 100644
index be5d0557..00000000
--- a/src/form.hh
+++ /dev/null
@@ -1,90 +0,0 @@
-#ifndef __FORM_HH__
-#define __FORM_HH__
-
-#include "dw/core.hh"
-#include "dw/ui.hh"
-
-namespace form {
-
-/**
- * \brief Handles HTML form data.
- *
- * Add resources by calling the respective add...Resource method. Furthermore,
- * this class implements dw::core::ui::ButtonResource::ClickedReceiver and
- * dw::core::ui::Resource::ActivateReceiver.
- */
-class Form: public dw::core::ui::ButtonResource::ClickedReceiver,
- public dw::core::ui::Resource::ActivateReceiver
-{
-private:
- /**
- * \brief Decorates instances of dw::core::ui::Resource.
- *
- * This is the abstract base class, sub classes have to be defined to
- * decorate specific sub interfaces of dw::core::ui::Resource.
- */
- class ResourceDecorator: public lout::object::Object
- {
- private:
- const char *name;
-
- protected:
- ResourceDecorator (const char *name);
- ~ResourceDecorator ();
-
- public:
- inline const char *getName () { return name; }
- virtual const char *getValue () = 0;
- };
-
- /**
- * \brief Decorates instances of dw::core::ui::TextResource.
- */
- class TextResourceDecorator: public ResourceDecorator
- {
- private:
- dw::core::ui::TextResource *resource;
-
- public:
- TextResourceDecorator (const char *name,
- dw::core::ui::TextResource *resource);
- const char *getValue ();
- };
-
- /**
- * \brief Decorates instances of dw::core::ui::RadioButtonResource.
- *
- * This class has to be instanciated only once for a group of radio
- * buttons.
- */
- class RadioButtonResourceDecorator: public ResourceDecorator
- {
- private:
- dw::core::ui::RadioButtonResource *resource;
- const char **values;
-
- public:
- RadioButtonResourceDecorator (const char *name,
- dw::core::ui::RadioButtonResource
- *resource,
- const char **values);
- ~RadioButtonResourceDecorator ();
- const char *getValue ();
- };
-
- lout::container::typed::List <ResourceDecorator> *resources;
-
- void *ext_data; // external data pointer
-
-public:
- Form (void *p);
- ~Form ();
- void clicked (dw::core::ui::ButtonResource *resource, int buttonNo,
- int x, int y);
- void activate (dw::core::ui::Resource *resource);
-
-};
-
-} // namespace form
-
-#endif // __FORM_HH__
diff --git a/src/html.cc b/src/html.cc
index 61287015..4f9f04f1 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -98,6 +98,7 @@ typedef struct _DilloLinkImage DilloLinkImage;
typedef struct _DilloHtmlClass DilloHtmlClass;
typedef struct _DilloHtmlState DilloHtmlState;
class DilloHtmlForm;
+class DilloHtmlReceiver;
class DilloHtmlInput;
typedef struct _DilloHtmlSelect DilloHtmlSelect;
typedef struct _DilloHtmlOption DilloHtmlOption;
@@ -223,12 +224,11 @@ struct _DilloHtmlState {
};
class DilloHtmlForm {
- friend void a_Html_form_event_handler(void *data,
- form::Form *form_receiver,
- void *v_resource,
- int click_x, int click_y);
+ friend class DilloHtmlReceiver;
DilloHtml *html;
+ void eventHandler(Resource *resource, int click_x, int click_y);
+
public: //BUG: for now everything is public
DilloHtmlMethod method;
DilloUrl *action;
@@ -240,7 +240,7 @@ public: //BUG: for now everything is public
int num_entry_fields;
int num_submit_buttons;
- form::Form *form_receiver;
+ DilloHtmlReceiver *form_receiver;
public:
DilloHtmlForm (DilloHtml *html,
@@ -248,7 +248,7 @@ public:
DilloHtmlEnc enc, const char *charset);
~DilloHtmlForm ();
inline DilloHtmlInput *getCurrentInput ();
- DilloHtmlInput *getInput (void *v_resource);
+ DilloHtmlInput *getInput (Resource *resource);
DilloHtmlInput *getRadioInput (const char *name);
void reset ();
void addInput(DilloHtmlInputType type,
@@ -262,6 +262,18 @@ public:
char *makeMultipartBoundary(iconv_t encoder, DilloHtmlInput *active_submit);
};
+class DilloHtmlReceiver:
+ public Resource::ActivateReceiver,
+ public ButtonResource::ClickedReceiver
+{
+ friend class DilloHtmlForm;
+ DilloHtmlForm* form;
+ DilloHtmlReceiver (DilloHtmlForm* form2) { form = form2; }
+ ~DilloHtmlReceiver () { }
+ void activate (Resource *resource);
+ void clicked (ButtonResource *resource, int buttonNo, int x, int y);
+};
+
struct _DilloHtmlOption {
char *value, *content;
bool selected, enabled;
@@ -289,7 +301,7 @@ public: //BUG: for now everything is public
todo: may become a list... */
private:
- void connectTo(form::Form *form_receiver);
+ void connectTo(DilloHtmlReceiver *form_receiver);
public:
DilloHtmlInput (DilloHtmlInputType type,
@@ -1196,7 +1208,7 @@ DilloHtmlForm::DilloHtmlForm (DilloHtml *html2,
inputs = new misc::SimpleVector <DilloHtmlInput*> (4);
num_entry_fields = 0;
num_submit_buttons = 0;
- form_receiver = new form::Form (this);
+ form_receiver = new DilloHtmlReceiver (this);
}
/*
@@ -1310,7 +1322,7 @@ DilloHtmlInput::~DilloHtmlInput ()
/*
* Connect to a receiver.
*/
-void DilloHtmlInput::connectTo(form::Form *form_receiver)
+void DilloHtmlInput::connectTo(DilloHtmlReceiver *form_receiver)
{
Resource *resource = NULL;
if (embed)
@@ -4499,23 +4511,33 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *input,
}
/*
- * Handler for events related to forms.
+ * Handlers for events related to forms.
*
* TODO: Currently there's "clicked" for buttons, we surely need "enter" for
* textentries, and maybe the "mouseover, ...." set for Javascript.
*/
-void a_Html_form_event_handler(void *data, form::Form *form_receiver,
- void *v_resource, int click_x, int click_y)
+
+void DilloHtmlReceiver::activate (Resource *resource)
{
- MSG("Html_form_event_handler %p\n", form_receiver);
+ form->eventHandler(resource, -1, -1);
+}
- DilloHtmlForm *form = (DilloHtmlForm*)data;
- DilloHtmlInput *input = form->getInput(v_resource);
- BrowserWindow *bw = form->html->bw;
+void DilloHtmlReceiver::clicked (ButtonResource *resource,
+ int buttonNo, int x, int y)
+{
+ form->eventHandler(resource, x, y);
+}
+
+void DilloHtmlForm::eventHandler(Resource *resource, int click_x, int click_y)
+{
+ MSG("DilloHtmlForm::eventHandler\n");
+
+ DilloHtmlInput *input = getInput(resource);
+ BrowserWindow *bw = html->bw;
if (!input) {
- MSG("a_Html_form_event_handler: ERROR, input not found!\n");
- } else if (form->num_entry_fields > 1 &&
+ MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n");
+ } else if (num_entry_fields > 1 &&
!prefs.enterpress_forces_submit &&
(input->type == DILLO_HTML_INPUT_TEXT ||
input->type == DILLO_HTML_INPUT_PASSWORD)) {
@@ -4538,9 +4560,9 @@ void a_Html_form_event_handler(void *data, form::Form *form_receiver,
}
} else if (input->type == DILLO_HTML_INPUT_RESET ||
input->type == DILLO_HTML_INPUT_BUTTON_RESET) {
- form->reset();
+ reset();
} else {
- DilloUrl *url = form->buildQueryUrl(input, click_x, click_y);
+ DilloUrl *url = buildQueryUrl(input, click_x, click_y);
if (url) {
a_Nav_push(bw, url);
a_Url_free(url);
@@ -4553,12 +4575,12 @@ void a_Html_form_event_handler(void *data, form::Form *form_receiver,
/*
* Return the input with a given resource.
*/
-DilloHtmlInput *DilloHtmlForm::getInput (void *v_resource)
+DilloHtmlInput *DilloHtmlForm::getInput (Resource *resource)
{
for (int idx = 0; idx < inputs->size(); idx++) {
DilloHtmlInput *input = inputs->get(idx);
if (input->embed &&
- v_resource == (void*)input->embed->getResource())
+ resource == input->embed->getResource())
return input;
}
return NULL;
diff --git a/src/html.hh b/src/html.hh
index 910f3e47..58369ed3 100644
--- a/src/html.hh
+++ b/src/html.hh
@@ -2,7 +2,6 @@
#define __HTML_HH__
#include "url.h" // for DilloUrl
-#include "form.hh" // for form::Form
#ifdef __cplusplus
extern "C" {
@@ -11,10 +10,6 @@ extern "C" {
/*
* Exported functions
*/
-void a_Html_form_event_handler(void *data,
- form::Form *form_receiver,
- void *v_resource,
- int click_x, int click_y);
void a_Html_free(void *data);
void a_Html_load_images(void *v_html, DilloUrl *pattern);