-/*
+/**
* \file Tooltips.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming
*
- * Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
+ * Full author contact details are available in file CREDITS.
+ */
+
+/* Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
* a bit of jiggery pokery. This class wraps it all up in a neat interface.
* Based on code originally in Toolbar_pimpl.C that appears to have been
* written by Matthias Ettrich and Jean-Marc Lasgouttes.
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "Tooltips.h"
-#include "support/LAssert.h"
-//#if FL_REVISION >= 89
-// Usually, this is all that is needed for xforms 0.89
-// However, I can't see an easy way to change Tooltips on the fly
-// with this method, so for now use the jiggery pokery below. ;-)
-// Angus 6 Feb 2002
+#include "xforms_helpers.h" // formatted
-/*
-void Tooltips::activateTooltip(FL_OBJECT * ob)
-{
- lyx::Assert(ob);
+#include "support/lstrings.h"
- string const help(getTooltip(ob));
- if (!help.empty())
- fl_set_object_helper(ob, help.c_str());
-}
-*/
+#include "lyx_forms.h"
-//#else // if FL_REVISION < 89
+#include <boost/bind.hpp>
-namespace {
+using std::string;
-int TooltipHandler(FL_OBJECT *ob, int event);
-void TooltipTimerCB(FL_OBJECT * timer, long data);
-
-}
+namespace lyx {
-extern "C" {
+using support::trim;
-static int C_TooltipHandler(FL_OBJECT * ob, int event,
- FL_Coord, FL_Coord, int, void *)
-{
- return TooltipHandler(ob, event);
-}
+namespace frontend {
-static void C_TooltipTimerCB(FL_OBJECT * ob, long data)
-{
- TooltipTimerCB(ob, data);
-}
+bool Tooltips::enabled_ = true;
-}
-
+boost::signal<void()> Tooltips::toggled;
-void Tooltips::activateTooltip(FL_OBJECT * ob)
+
+Tooltips::Tooltips()
{
- lyx::Assert(ob);
+ toggled.connect(boost::bind(&Tooltips::set, this));
+}
- if (!tooltip_timer_) {
- lyx::Assert(ob->form);
- fl_addto_form(ob->form);
- tooltip_timer_ = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "");
- fl_end_form();
- }
- fl_set_object_posthandler(ob, C_TooltipHandler);
- ob->u_cdata = reinterpret_cast<char *>(tooltip_timer_);
- tooltip_timer_->u_vdata = this;
+void Tooltips::toggleEnabled()
+{
+ enabled_ = !enabled_;
+ toggled();
}
-namespace {
-
-void TooltipTimerCB(FL_OBJECT * timer, long data)
+void Tooltips::set()
{
- FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
- lyx::Assert(ob && ob->form && timer && timer->u_vdata);
- FL_FORM * form = ob->form;
- Tooltips * tooltip = static_cast<Tooltips *>(timer->u_vdata);
-
- string const help = tooltip->getTooltip(ob);
- if (help.empty())
+ if (tooltipsMap.empty())
return;
- fl_show_oneliner(help.c_str(),
- form->x + ob->x, form->y + ob->y + ob->h);
+ TooltipsMap::const_iterator it = tooltipsMap.begin();
+ TooltipsMap::const_iterator end = tooltipsMap.end();
+ for (; it != end; ++it) {
+ FL_OBJECT * const ob = it->first;
+ char const * const c_str = enabled_ ? it->second.c_str() : 0;
+ fl_set_object_helper(ob, c_str);
+ }
}
-// post_handler for bubble-help (Matthias)
-int TooltipHandler(FL_OBJECT *ob, int event)
+void Tooltips::init(FL_OBJECT * ob, string const & tip)
{
- 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_TooltipTimerCB,
- reinterpret_cast<long>(ob));
- fl_set_timer(timer, 1);
- }
- else if (event != FL_MOTION){
- fl_set_timer(timer, 0);
- fl_hide_oneliner();
- }
- return 0;
-}
+ BOOST_ASSERT(ob && ob->form);
-} // namespace anon
+ // Store the tooltip string
+ string const str = formatted(trim(tip), 400);
+ tooltipsMap[ob] = str;
+
+ // Set the tooltip
+ char const * const c_str = enabled_ ? str.c_str() : 0;
+ fl_set_object_helper(ob, c_str);
+}
-//#endif // FL_REVISION < 89
+} // namespace frontend
+} // namespace lyx