+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
#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)
+
{}
}
+// 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)
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"
/// 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;
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
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_;
};
#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,
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"
+
#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)
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);