#include "xformsBC.h"
#include "support/LAssert.h"
+#if FL_REVISION < 89
+
+namespace {
+
+int TooltipHandler(FL_OBJECT *ob, int event);
+
+void TooltipTimerCB(FL_OBJECT * timer, long data);
+
+}
+
+extern "C" {
+
+static int C_FormBaseTooltipHandler(FL_OBJECT * ob, int event,
+ FL_Coord, FL_Coord, int, void *)
+{
+ return TooltipHandler(ob, event);
+}
+
+static void C_FormBaseTooltipTimerCB(FL_OBJECT * ob, long data)
+{
+ TooltipTimerCB(ob, data);
+}
+
+}
+
+#endif // FL_REVISION < 89
+
+
extern "C" {
// Callback function invoked by xforms when the dialog is closed by the
: ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
title_(t), warning_posted_(false)
-{}
+{
+#if FL_REVISION < 89
+ tooltip_timer_ = 0;
+#endif
+}
void FormBase::redraw()
}
+void FormBase::setTooltipHandler(FL_OBJECT * ob)
+{
+ lyx::Assert(ob);
+
+#if FL_REVISION < 89
+ if (!tooltip_timer_) {
+ fl_addto_form(form());
+ tooltip_timer_ = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "");
+ fl_end_form();
+ }
+
+ fl_set_object_posthandler(ob, C_FormBaseTooltipHandler);
+ ob->u_cdata = reinterpret_cast<char *>(tooltip_timer_);
+
+#else
+ string const help(getTooltip(ob));
+ if (!help.empty())
+ fl_set_object_helper(ob, help.c_str());
+#endif // FL_REVISION < 89
+}
+
+
void FormBase::setPrehandler(FL_OBJECT * ob)
{
lyx::Assert(ob);
}
+#if FL_REVISION < 89
+
+string const FormBase::getTooltipCB(FL_OBJECT * ob)
+{
+ return getTooltip(ob);
+}
+
+#endif // FL_REVISION < 89
+
+
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;
-}
-
-
void C_FormBaseApplyCB(FL_OBJECT * ob, long)
{
GetForm(ob)->ApplyButton();
}
+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_FormBasePrehandler(FL_OBJECT * ob, int event,
FL_Coord, FL_Coord, int key, void *)
{
return 0;
}
-
+
} // extern "C"
+
+
+#if FL_REVISION < 89
+
+namespace {
+
+void TooltipTimerCB(FL_OBJECT * timer, long data)
+{
+ FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
+ lyx::Assert(ob && ob->form);
+
+ string const help = GetForm(timer)->getTooltipCB(ob);
+ if (help.empty())
+ return;
+
+ fl_show_oneliner(help.c_str(),
+ ob->form->x + ob->x,
+ ob->form->y + ob->y + ob->h);
+}
+
+
+// post_handler for bubble-help (Matthias)
+int TooltipHandler(FL_OBJECT *ob, int event)
+{
+ lyx::Assert(ob);
+ FL_OBJECT * timer = reinterpret_cast<FL_OBJECT *>(ob->u_cdata);
+ lyx::Assert(timer);
+
+ // We do not test for empty help here, since this can never happen
+ if (event == FL_ENTER){
+ fl_set_object_callback(timer,
+ C_FormBaseTooltipTimerCB,
+ reinterpret_cast<long>(ob));
+ fl_set_timer(timer, 1);
+ }
+ else if (event != FL_MOTION){
+ fl_set_timer(timer, 0);
+ fl_hide_oneliner();
+ }
+ return 0;
+}
+
+} // namespace anon
+
+#endif // FL_REVISION < 89
class xformsBC;
+
/** This class is an XForms GUI base class.
*/
class FormBase : public ViewBC<xformsBC>
///
virtual ~FormBase() {}
- /// input callback function
+ /** input callback function.
+ Invoked only by C_FormBaseInputCB and by C_FormBasePrehandler */
void InputCB(FL_OBJECT *, long);
-
- /// feedback callback function
+ /// feedback callback function, invoked only by C_FormBasePrehandler
void FeedbackCB(FL_OBJECT *, int event);
+#if FL_REVISION < 89
+ /// invoked only by TooltipTimerCB
+ string const getTooltipCB(FL_OBJECT *);
+#endif
+
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
+
+ /// Prepare the way to produce a tooltip when the mouse is over ob.
+ void setTooltipHandler(FL_OBJECT * ob);
+
+ /** Prepare the way to:
+ 1. display feedback as the mouse moves over ob. This feedback will
+ typically be rather more verbose than just a tooltip.
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 */
+ when the mouse is no longer over the object.
+ Used in conjunction with setPrehandler(ob) and with feedback(ob),
+ clear_feedback(). */
void setWarningPosted(bool);
private:
that the xform colors have been re-mapped). */
virtual void redraw();
+ ///
+ virtual string const getTooltip(FL_OBJECT *) { return string(); }
+
+ /// post feedback for ob. Defaults to nothing
+ virtual void feedback(FL_OBJECT * /* ob */) {}
+ /// clear the feedback message
+ virtual void clear_feedback() {}
+
/// The dialog's minimum allowable dimensions.
int minw_;
///
/** Variable used to decide whether to remove the existing feedback
message or not (if it is infact a warning) */
bool warning_posted_;
+ /// Enables tooltips for crappy GUI libraries...
+#if FL_REVISION < 89
+ FL_OBJECT * tooltip_timer_;
+#endif
};