changeset 468:6ddee709a59a

Moved clicked from ButtonResource to Resource.
author Jorge Arellano Cid <jcid@dillo.org>
date Fri, 19 Dec 2008 16:44:00 -0300
parents c029ea389ba7
children 06a11189d75f
files ChangeLog dw/fltkcomplexbutton.cc dw/ui.cc dw/ui.hh src/form.cc test/form.cc test/form.hh
diffstat 7 files changed, 93 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 19 16:36:16 2008 -0300
+++ b/ChangeLog	Fri Dec 19 16:44:00 2008 -0300
@@ -44,6 +44,8 @@
 
 dw
 
++- Moved clicked from ButtonResource to Resource.
+   Patch: place (AKA corvid)
 +- Cleaned up unused code in fltkviewbase.
    Patch: Johannes Hofmann
 
--- a/dw/fltkcomplexbutton.cc	Fri Dec 19 16:36:16 2008 -0300
+++ b/dw/fltkcomplexbutton.cc	Fri Dec 19 16:44:00 2008 -0300
@@ -87,7 +87,7 @@
     if (pushed()) return 1; // ignore extra pushes on currently-pushed button
     initial_state = state();
     clear_flag(PUSHED);
-    do_callback();
+    /* do_callback(); */
   case DRAG: {
     bool inside = event_inside(rectangle);
     if (inside) {
--- a/dw/ui.cc	Fri Dec 19 16:36:16 2008 -0300
+++ b/dw/ui.cc	Fri Dec 19 16:44:00 2008 -0300
@@ -69,6 +69,19 @@
    resource->emitLeave();
 }
 
+bool Embed::buttonPressImpl (core::EventButton *event)
+{
+   bool handled;
+
+   if (event->button == 3) {
+      resource->emitClicked(event);
+      handled = true;
+   } else {
+      handled = false;
+   }
+   return handled;
+}
+
 void Embed::setWidth (int width)
 {
    resource->setWidth (width);
@@ -201,22 +214,18 @@
    activateEmitter.emitLeave(this);
 }
 
-// ----------------------------------------------------------------------
-
-bool ButtonResource::ClickedEmitter::emitToReceiver (lout::signal::Receiver
-                                                     *receiver,
-                                                     int signalNo,
-                                                     int argc,
-                                                     Object **argv)
+bool Resource::ClickedEmitter::emitToReceiver(lout::signal::Receiver *receiver,
+                                              int signalNo, int argc,
+                                              Object **argv)
 {
    ((ClickedReceiver*)receiver)
-      ->clicked ((ButtonResource*)((Pointer*)argv[0])->getValue (),
+      ->clicked ((Resource*)((Pointer*)argv[0])->getValue (),
                  (EventButton*)((Pointer*)argv[1])->getValue());
    return false;
 }
 
-void ButtonResource::ClickedEmitter::emitClicked (ButtonResource *resource,
-                                                  EventButton *event)
+void Resource::ClickedEmitter::emitClicked (Resource *resource,
+                                            EventButton *event)
 {
    Pointer p1 (resource);
    Pointer p2 (event);
--- a/dw/ui.hh	Fri Dec 19 16:36:16 2008 -0300
+++ b/dw/ui.hh	Fri Dec 19 16:44:00 2008 -0300
@@ -232,6 +232,7 @@
    void sizeAllocateImpl (Allocation *allocation);
    void enterNotifyImpl (core::EventCrossing *event);
    void leaveNotifyImpl (core::EventCrossing *event);
+   bool buttonPressImpl (core::EventButton *event);
 
 public:
    static int CLASS_ID;
@@ -271,6 +272,14 @@
       virtual void enter (Resource *resource) = 0;
       virtual void leave (Resource *resource) = 0;
    };
+   /**
+    * \brief Receiver interface for the "clicked" signal.
+    */
+   class ClickedReceiver: public lout::signal::Receiver
+   {
+   public:
+      virtual void clicked (Resource *resource, EventButton *event) = 0;
+   };
 
 private:
    class ActivateEmitter: public lout::signal::Emitter
@@ -286,8 +295,20 @@
       void emitLeave (Resource *resource);
    };
 
+   class ClickedEmitter: public lout::signal::Emitter
+   {
+   protected:
+      bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
+                           int argc, Object **argv);
+   public:
+      inline void connectClicked (ClickedReceiver *receiver) {
+         connect (receiver); }
+      void emitClicked (Resource *resource, EventButton *event);
+   };
+
    Embed *embed;
    ActivateEmitter activateEmitter;
+   ClickedEmitter clickedEmitter;
 
    void emitEnter ();
    void emitLeave ();
@@ -301,6 +322,8 @@
 
    inline void emitActivate () {
       return activateEmitter.emitActivate (this); }
+   inline void emitClicked (EventButton *event) {
+      clickedEmitter.emitClicked (this, event); }
 
 public:
    inline Resource () { embed = NULL; }
@@ -322,43 +345,13 @@
 
    inline void connectActivate (ActivateReceiver *receiver) {
       activateEmitter.connectActivate (receiver); }
+   inline void connectClicked (ClickedReceiver *receiver) {
+      clickedEmitter.connectClicked (receiver); }
 };
 
 
 class ButtonResource: public Resource
-{
-public:
-   /**
-    * \brief Receiver interface for the "clicked" signal.
-    */
-   class ClickedReceiver: public lout::signal::Receiver
-   {
-   public:
-      virtual void clicked (ButtonResource *resource, EventButton *event) = 0;
-   };
-
-private:
-   class ClickedEmitter: public lout::signal::Emitter
-   {
-   protected:
-      bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
-                           int argc, Object **argv);
-   public:
-      inline void connectClicked (ClickedReceiver *receiver) {
-         connect (receiver); }
-      void emitClicked (ButtonResource *resource, EventButton *event);
-   };
-
-   ClickedEmitter clickedEmitter;
-
-protected:
-   inline void emitClicked (EventButton *event) {
-      clickedEmitter.emitClicked (this, event); }
-
-public:
-   inline void connectClicked (ClickedReceiver *receiver) {
-      clickedEmitter.connectClicked (receiver); }
-};
+{};
 
 /**
  * \brief Interface for labelled buttons resources.
--- a/src/form.cc	Fri Dec 19 16:36:16 2008 -0300
+++ b/src/form.cc	Fri Dec 19 16:44:00 2008 -0300
@@ -119,7 +119,7 @@
 
 class DilloHtmlReceiver:
    public Resource::ActivateReceiver,
-   public ButtonResource::ClickedReceiver
+   public Resource::ClickedReceiver
 {
    friend class DilloHtmlForm;
    DilloHtmlForm* form;
@@ -128,7 +128,7 @@
    void activate (Resource *resource);
    void enter (Resource *resource);
    void leave (Resource *resource);
-   void clicked (ButtonResource *resource, EventButton *event);
+   void clicked (Resource *resource, EventButton *event);
 };
 
 class DilloHtmlInput {
@@ -950,11 +950,15 @@
 void DilloHtmlForm::eventHandler(Resource *resource, EventButton *event)
 {
    MSG("DilloHtmlForm::eventHandler\n");
-   DilloHtmlInput *input = getInput(resource);
-   if (input) {
-      input->activate (this, num_entry_fields, event);
+   if (event && (event->button == 3)) {
+      MSG("Form menu\n");
    } else {
-      MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n");
+      DilloHtmlInput *input = getInput(resource);
+      if (input) {
+         input->activate (this, num_entry_fields, event);
+      } else {
+        MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n");
+      }
    }
 }
 
@@ -1522,7 +1526,7 @@
    a_UIcmd_set_msg(html->bw, "");
 }
 
-void DilloHtmlReceiver::clicked (ButtonResource *resource,
+void DilloHtmlReceiver::clicked (Resource *resource,
                                  EventButton *event)
 {
    form->eventHandler(resource, event);
@@ -1576,30 +1580,17 @@
 {
    Resource *resource;
    if (embed && (resource = embed->getResource())) {
-      switch (type) {
-         case DILLO_HTML_INPUT_UNKNOWN:
-         case DILLO_HTML_INPUT_HIDDEN:
-         case DILLO_HTML_INPUT_CHECKBOX:
-         case DILLO_HTML_INPUT_RADIO:
-         case DILLO_HTML_INPUT_BUTTON:
-         case DILLO_HTML_INPUT_TEXTAREA:
-         case DILLO_HTML_INPUT_SELECT:
-         case DILLO_HTML_INPUT_SEL_LIST:
-            // do nothing
-            break;
-         case DILLO_HTML_INPUT_SUBMIT:
-         case DILLO_HTML_INPUT_RESET:
-         case DILLO_HTML_INPUT_BUTTON_SUBMIT:
-         case DILLO_HTML_INPUT_BUTTON_RESET:
-         case DILLO_HTML_INPUT_IMAGE:
-         case DILLO_HTML_INPUT_FILE:
-            ((ButtonResource *)resource)->connectClicked (form_receiver);
-         case DILLO_HTML_INPUT_TEXT:
-         case DILLO_HTML_INPUT_PASSWORD:
-         case DILLO_HTML_INPUT_INDEX:
-            resource->connectActivate (form_receiver);
-            break;
-         break;
+      resource->connectClicked (form_receiver);
+      if (type == DILLO_HTML_INPUT_SUBMIT ||
+          type == DILLO_HTML_INPUT_RESET ||
+          type == DILLO_HTML_INPUT_BUTTON_SUBMIT ||
+          type == DILLO_HTML_INPUT_BUTTON_RESET ||
+          type == DILLO_HTML_INPUT_IMAGE ||
+          type == DILLO_HTML_INPUT_FILE ||
+          type == DILLO_HTML_INPUT_TEXT ||
+          type == DILLO_HTML_INPUT_PASSWORD ||
+          type == DILLO_HTML_INPUT_INDEX) {
+         resource->connectActivate (form_receiver);
       }
    }
 }
@@ -1610,16 +1601,29 @@
 void DilloHtmlInput::activate(DilloHtmlForm *form, int num_entry_fields,
                               EventButton *event)
 {
-   if (type == DILLO_HTML_INPUT_FILE) {
+   switch (type) {
+   case DILLO_HTML_INPUT_FILE:
       readFile (form->html->bw);
-   } else if (type == DILLO_HTML_INPUT_RESET ||
-              type == DILLO_HTML_INPUT_BUTTON_RESET) {
+      break;
+   case DILLO_HTML_INPUT_RESET:
+   case DILLO_HTML_INPUT_BUTTON_RESET:
       form->reset();
-   } else if ((type != DILLO_HTML_INPUT_TEXT &&
-               type != DILLO_HTML_INPUT_PASSWORD) ||
-              prefs.enterpress_forces_submit ||
-              num_entry_fields == 1) {
+      break;
+   case DILLO_HTML_INPUT_TEXT:
+   case DILLO_HTML_INPUT_PASSWORD:
+      if (!(prefs.enterpress_forces_submit || num_entry_fields == 1)) {
+         break;
+      } else {
+         /* fall through */
+      }
+   case DILLO_HTML_INPUT_SUBMIT:
+   case DILLO_HTML_INPUT_BUTTON_SUBMIT:
+   case DILLO_HTML_INPUT_IMAGE:
+   case DILLO_HTML_INPUT_INDEX:
       form->submit(this, event);
+      break;
+   default:
+      break;
    }
 }
 
--- a/test/form.cc	Fri Dec 19 16:36:16 2008 -0300
+++ b/test/form.cc	Fri Dec 19 16:44:00 2008 -0300
@@ -164,7 +164,7 @@
    delete[] value;
 }
       
-void Form::FormClickedReceiver::clicked (ButtonResource *resource,
+void Form::FormClickedReceiver::clicked (Resource *resource,
                                          dw::core::EventButton *event)
 {
    form->send (name, value, event->xCanvas, event->yCanvas);
--- a/test/form.hh	Fri Dec 19 16:36:16 2008 -0300
+++ b/test/form.hh	Fri Dec 19 16:44:00 2008 -0300
@@ -120,7 +120,7 @@
    };
 
    class FormClickedReceiver:
-      public dw::core::ui::ButtonResource::ClickedReceiver
+      public dw::core::ui::Resource::ClickedReceiver
    {
    private:
       Form *form;
@@ -130,7 +130,7 @@
       FormClickedReceiver (Form *form, const char *name, const char *value);
       ~FormClickedReceiver ();
       
-      void clicked(dw::core::ui::ButtonResource *resource,
+      void clicked(dw::core::ui::Resource *resource,
                    dw::core::EventButton *event);
    };