From: Angus Leeming Date: Tue, 5 Feb 2002 14:59:26 +0000 (+0000) Subject: Provide the framework for really easy feedback messages. X-Git-Tag: 1.6.10~19909 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=625f8c79ac0d1ab747680a9537a8ba857f260c28;p=features.git Provide the framework for really easy feedback messages. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3486 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index c46e717e91..7e7ca081a9 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,18 @@ +2002-02-05 Angus Leeming + + * 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 * forms/form_graphics.fd: small changes to the layout diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index d05caab8ae..ebfd35804f 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -22,15 +22,23 @@ #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(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(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(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(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" diff --git a/src/frontends/xforms/FormBase.h b/src/frontends/xforms/FormBase.h index 3774f2bbf2..81ebf497af 100644 --- a/src/frontends/xforms/FormBase.h +++ b/src/frontends/xforms/FormBase.h @@ -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_; }; diff --git a/src/frontends/xforms/FormBaseDeprecated.C b/src/frontends/xforms/FormBaseDeprecated.C index c020a59cb1..f9ed4ef1fc 100644 --- a/src/frontends/xforms/FormBaseDeprecated.C +++ b/src/frontends/xforms/FormBaseDeprecated.C @@ -22,43 +22,16 @@ #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" + diff --git a/src/frontends/xforms/FormPreamble.C b/src/frontends/xforms/FormPreamble.C index 537ec7012e..154ea4b459 100644 --- a/src/frontends/xforms/FormPreamble.C +++ b/src/frontends/xforms/FormPreamble.C @@ -18,11 +18,6 @@ #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 > 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);