]> git.lyx.org Git - features.git/commitdiff
Provide the framework for really easy feedback messages.
authorAngus Leeming <leeming@lyx.org>
Tue, 5 Feb 2002 14:59:26 +0000 (14:59 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 5 Feb 2002 14:59:26 +0000 (14:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3486 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FormBase.C
src/frontends/xforms/FormBase.h
src/frontends/xforms/FormBaseDeprecated.C
src/frontends/xforms/FormPreamble.C

index c46e717e910fa2c53ce5e4d9205d4f6e33616aba..7e7ca081a9107f3c083c64694d5bdc8d4c406016 100644 (file)
@@ -1,3 +1,18 @@
+2002-02-05  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * FormBase.[Ch]: make it really easy to set up and use a prehandler
+       for feedback messages and to invoke an input event on paste from
+       the middle mouse button. The derived class needs invoke only
+       setPrehandler(ob) and for the feedback to override the virtual methods
+       feedback(ob) and clear_feedback(). If the message posted is a warning
+       rather than mere feedback, first setWarningPosted(true) to ensure
+       that the message remains visible.
+
+       * FormBaseDeprecated.C: a physical rearrangement of the file,
+       nothing more.
+
+       * FormPreamble.C: use setPrehandler to invoke an input event on paste.
+
 2002-02-04  Herbert Voss  <voss@lyx.org>
 
        * forms/form_graphics.fd: small changes to the layout
index d05caab8ae280b526c0d3ce1f646f11c6207ac3a..ebfd35804f5dbb38d7ab41cf1e551465f0543aba 100644 (file)
 #include "support/LAssert.h"
 
 extern "C" {
-       // Callback function invoked by xforms when the dialog is closed by the
-       // window manager
-       static int C_FormBaseWMHideCB(FL_FORM * form, void *);
-}
+
+// Callback function invoked by xforms when the dialog is closed by the
+// window manager
+static int C_FormBaseWMHideCB(FL_FORM * form, void *);
+
+// Use this to diaplay feedback messages or to trigger an input event on paste
+// with the middle mouse button
+static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
+                               FL_Coord, FL_Coord, int key, void *);
+
+} // extern "C"
 
 
 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
        : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
-         title_(t)
+         title_(t), warning_posted_(false)
+
 {}
 
 
@@ -114,6 +122,41 @@ ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
 }
 
 
+// preemptive handler for feedback messages
+void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
+{
+       lyx::Assert(ob);
+
+       switch (event) {
+       case FL_ENTER:
+               warning_posted_ = false;
+               feedback(ob);
+               break;
+
+       case FL_LEAVE:
+               if (!warning_posted_)
+                       clear_feedback();
+               break;
+
+       default:
+               break;
+       }
+}
+
+
+void FormBase::setPrehandler(FL_OBJECT * ob)
+{
+       lyx::Assert(ob);
+       fl_set_object_prehandler(ob, C_FormBasePrehandler);
+}
+
+
+void FormBase::setWarningPosted(bool warning)
+{
+       warning_posted_ = warning;
+}
+
+
 namespace {
 
 FormBase * GetForm(FL_OBJECT * ob)
@@ -128,58 +171,74 @@ FormBase * GetForm(FL_OBJECT * ob)
 
 extern "C" {
 
-       static
-       int C_FormBaseWMHideCB(FL_FORM * form, void *)
-       {
-               // Close the dialog cleanly, even if the WM is used to do so.
-               lyx::Assert(form && form->u_vdata);
-               FormBase * pre = static_cast<FormBase *>(form->u_vdata);
-               pre->CancelButton();
-               return FL_CANCEL;
-       }
+static int C_FormBaseWMHideCB(FL_FORM * form, void *)
+{
+       // Close the dialog cleanly, even if the WM is used to do so.
+       lyx::Assert(form && form->u_vdata);
+       FormBase * pre = static_cast<FormBase *>(form->u_vdata);
+       pre->CancelButton();
+       return FL_CANCEL;
+}
 
 
-       void C_FormBaseApplyCB(FL_OBJECT * ob, long)
-       {
-               GetForm(ob)->ApplyButton();
-       }
+void C_FormBaseApplyCB(FL_OBJECT * ob, long)
+{
+       GetForm(ob)->ApplyButton();
+}
 
 
-       void C_FormBaseOKCB(FL_OBJECT * ob, long)
-       {
-               GetForm(ob)->OKButton();
-       }
+void C_FormBaseOKCB(FL_OBJECT * ob, long)
+{
+       GetForm(ob)->OKButton();
+}
 
 
-       void C_FormBaseCancelCB(FL_OBJECT * ob, long)
-       {
-               FormBase * form = GetForm(ob);
-               form->CancelButton();
-       }
+void C_FormBaseCancelCB(FL_OBJECT * ob, long)
+{
+       FormBase * form = GetForm(ob);
+       form->CancelButton();
+}
 
 
-       void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
-       {
-               GetForm(ob)->RestoreButton();
-       }
+void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
+{
+       GetForm(ob)->RestoreButton();
+}
 
 
-       void C_FormBaseInputCB(FL_OBJECT * ob, long d)
-       {
-               GetForm(ob)->InputCB(ob, d);
-       }
+void C_FormBaseInputCB(FL_OBJECT * ob, long d)
+{
+       GetForm(ob)->InputCB(ob, d);
+}
+
+
+static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
+                               FL_Coord, FL_Coord, int key, void *)
+{
+       // Note that the return value is important in the pre-emptive handler.
+       // Don't return anything other than 0.
+       lyx::Assert(ob);
+
+       // Don't Assert this one, as it can happen quite naturally when things
+       // are being deleted in the d-tor.
+       //Assert(ob->form);
+       if (!ob->form) return 0;
+
+       FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
+       if (!pre) return 0;
 
+       if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
+               // Trigger an input event when pasting in an xforms input object
+               // using the middle mouse button.
+               pre->InputCB(ob, 0);
 
-       // To trigger an input event when pasting in an xforms input object
-       // using the middle mouse button.
-       int C_CutandPastePH(FL_OBJECT * ob, int event,
-                           FL_Coord, FL_Coord, int key, void *)
-       {
-               if ((event == FL_PUSH) && (key == 2)
-                   && (ob->objclass == FL_INPUT)) {
-                       C_FormBaseInputCB(ob, 0);
-               }
-               return 0;
+       } else if (event == FL_ENTER || event == FL_LEAVE){
+               // Post feedback as the mouse enters the object,
+               // remove it as the mouse leaves.
+               pre->FeedbackCB(ob, event);
        }
 
+       return 0;
 }
+       
+} // extern "C"
index 3774f2bbf24c8725e510859d4f7713a22cd504e4..81ebf497af9908ac4e188598b2589e4f10828f82 100644 (file)
@@ -40,6 +40,9 @@ public:
        /// input callback function
        void InputCB(FL_OBJECT *, long);
 
+       /// feedback callback function
+       void FeedbackCB(FL_OBJECT *, int event);
+
 protected:
        /// Build the dialog
        virtual void build() = 0;
@@ -47,6 +50,20 @@ protected:
        void hide();
        /// Create the dialog if necessary, update it and display it.
        void show();
+       /** Set a prehandler for ob to:
+           1. display feedback as the mouse moves over it
+           2. activate the button controller after a paste with the middle
+           mouse button */
+       void setPrehandler(FL_OBJECT * ob);
+
+       /// post feedback for ob. Defaults to nothing
+       virtual void feedback(FL_OBJECT * /* ob */) {}
+       /// clear the feedback message
+       virtual void clear_feedback() {}
+
+       /** Flag that the message is a warning and should not be removed
+           when the mouse is no longer over the object */
+       void setWarningPosted(bool);
 
 private:
        /// Pointer to the actual instantiation of xform's form
@@ -66,6 +83,9 @@ private:
        bool allow_resize_;
        /// dialog title, displayed by WM.
        string title_;
+       /** Variable used to decide whether to remove the existing feedback
+           message or not (if it is infact a warning) */
+       bool warning_posted_;
 };
 
 
index c020a59cb1e79f41919af04b64f00a8e677ded6a..f9ed4ef1fce84e8b3d38fe6483e9d926c6a0089f 100644 (file)
 #include "support/LAssert.h"
 #include "xformsBC.h"
 #include "lyxrc.h"
-//#include "debug.h"
 
 using SigC::slot;
 
 extern "C" {
-       
-       static
-       int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d)
-       {
-               return FormBaseDeprecated::WMHideCB(ob, d);
-       }
-
-       void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d)
-       {
-               FormBaseDeprecated::ApplyCB(ob, d);
-       }
-
-       void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d)
-       {
-               FormBaseDeprecated::OKCB(ob, d);
-       }
-
-       void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d)
-       {
-               FormBaseDeprecated::CancelCB(ob, d);
-       }
-
-       void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
-       {
-               FormBaseDeprecated::InputCB(ob, d);
-       }
 
-       void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d)
-       {
-               FormBaseDeprecated::RestoreCB(ob, d);
-       }
-}
+// Callback function invoked by xforms when the dialog is closed by the
+// window manager
+static int C_FormBaseDeprecatedWMHideCB(FL_FORM *, void *);
+} // extern "C"
 
 
 FormBaseDeprecated::FormBaseDeprecated(LyXView * lv, Dialogs * d,
@@ -259,3 +232,44 @@ void FormBaseBD::disconnect()
        u_.disconnect();
        FormBaseDeprecated::disconnect();
 }
+
+
+extern "C" {
+       
+static int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d)
+{
+       return FormBaseDeprecated::WMHideCB(ob, d);
+}
+
+
+void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d)
+{
+       FormBaseDeprecated::ApplyCB(ob, d);
+}
+
+
+void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d)
+{
+       FormBaseDeprecated::OKCB(ob, d);
+}
+
+
+void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d)
+{
+       FormBaseDeprecated::CancelCB(ob, d);
+}
+
+
+void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
+{
+               FormBaseDeprecated::InputCB(ob, d);
+}
+
+
+void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d)
+{
+       FormBaseDeprecated::RestoreCB(ob, d);
+}
+
+} // extern "C"
+
index 537ec7012e48fa2355407ec84f83d023ecdefba5..154ea4b459eb6f063f058e2dad3c10e798e841fe 100644 (file)
 #include "form_preamble.h"
 #include "xforms_helpers.h"
 
-// To trigger an input event when pasting in an xforms input object
-// using the middle mouse button.
-extern "C" int C_CutandPastePH(FL_OBJECT *, int, FL_Coord, FL_Coord,
-                              int, void *);
-
 typedef FormCB<ControlPreamble, FormDB<FD_form_preamble> > base_class;
 
 FormPreamble::FormPreamble(ControlPreamble & c)
@@ -35,7 +30,9 @@ void FormPreamble::build()
        dialog_.reset(build_preamble());
 
        fl_set_input_return(dialog_->input_preamble, FL_RETURN_CHANGED);
-       fl_set_object_prehandler(dialog_->input_preamble, C_CutandPastePH);
+
+       // trigger an input event when pasting using the middle mouse button.
+       setPrehandler(dialog_->input_preamble);
 
        // Manage the ok, apply and cancel/close buttons
        bc().setOK(dialog_->button_ok);