-/*
+/**
* \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
+ *
+ * Full author contact details are available in file CREDITS
*/
-/*
- *
- * Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
+/* 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.
#endif
#include "Tooltips.h"
-#include "Dialogs.h"
#include "xforms_helpers.h" // formatted
#include "gettext.h"
#include "support/lstrings.h"
#include "support/LAssert.h"
+#include FORMS_H_LOCATION
-using SigC::slot;
-
+#include <boost/bind.hpp>
-bool Tooltips::enabled_ = false;
+bool Tooltips::enabled_ = true;
-SigC::Signal0<void> Tooltips::tooltipsToggled;
+boost::signal0<void> Tooltips::toggled;
-#if FL_REVISION >= 89
+#if FL_VERSION > 0 || FL_REVISION >= 89
Tooltips::Tooltips()
{
- static bool first = true;
- if (first) {
- first = false;
- Dialogs::toggleTooltips.connect(slot(&Tooltips::toggleEnabled));
- }
- tooltipsToggled.connect(slot(this, &Tooltips::toggleTooltips));
+ toggled.connect(boost::bind(&Tooltips::set, this));
}
void Tooltips::toggleEnabled()
{
enabled_ = !enabled_;
- tooltipsToggled();
+ toggled();
}
-void Tooltips::toggleTooltips()
+void Tooltips::set()
{
if (tooltipsMap.empty())
- // There are no objects with tooltips in this dialog, so
- // just go away. Don't change the cursor to a question mark.
return;
- TooltipsMap::iterator it = tooltipsMap.begin();
- TooltipsMap::iterator end = tooltipsMap.end();
+ 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);
}
-
- // Set the cursor to a question mark or back to the default.
- FL_OBJECT * const ob = tooltipsMap.begin()->first;
- int const cursor = enabled_ ? XC_question_arrow : FL_DEFAULT_CURSOR;
- fl_set_cursor(FL_ObjWin(ob), cursor);
}
-void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
+void Tooltips::init(FL_OBJECT * ob, string const & tip)
{
- lyx::Assert(ob);
-
- // Paranoia check!
- TooltipsMap::const_iterator it = tooltipsMap.find(ob);
- if (it != tooltipsMap.end())
- return;
-
- string const str = strip(frontStrip(tip));
- if (str.empty())
- return;
+ lyx::Assert(ob && ob->form);
// Store the tooltip string
- tooltipsMap[ob] = formatted(_(str), 400);
+ string const str = formatted(trim(tip), 400);
+ tooltipsMap[ob] = str;
- // Set the initial state of the tooltips
+ // Set the tooltip
char const * const c_str = enabled_ ? str.c_str() : 0;
fl_set_object_helper(ob, c_str);
}
int TooltipHandler(FL_OBJECT *ob, int event);
void TooltipTimerCB(FL_OBJECT * timer, long data);
-
+
}
extern "C" {
}
}
-
+
Tooltips::Tooltips()
: tooltip_timer_(0)
{
- static bool first = true;
- if (first) {
- first = false;
- Dialogs::toggleTooltips.connect(slot(&Tooltips::toggleEnabled));
- }
- tooltipsToggled.connect(slot(this, &Tooltips::toggleTooltips));
+ toggled.connect(boost::bind(&Tooltips::set, this));
}
void Tooltips::toggleEnabled()
{
enabled_ = !enabled_;
- tooltipsToggled();
+ toggled();
}
-void Tooltips::toggleTooltips()
-{
- if (tooltipsMap.empty())
- // There are no objects with tooltips in this dialog, so
- // just go away. Don't change the cursor to a question mark.
- return;
+void Tooltips::set()
+{}
- // Set the cursor to a question mark or back to the default.
- FL_OBJECT * const ob = tooltipsMap.begin()->first;
- int const cursor = enabled_ ? XC_question_arrow : FL_DEFAULT_CURSOR;
- fl_set_cursor(FL_ObjWin(ob), cursor);
-}
-
-void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
+void Tooltips::init(FL_OBJECT * ob, string const & tip)
{
- lyx::Assert(ob);
+ lyx::Assert(ob && ob->form);
// Paranoia check!
TooltipsMap::const_iterator it = tooltipsMap.find(ob);
if (it != tooltipsMap.end())
return;
- string const str = strip(frontStrip(tip));
+ string const str = trim(tip);
if (str.empty())
return;
// Store the tooltip string
- tooltipsMap[ob] = formatted(_(str), 400);
+ tooltipsMap[ob] = formatted(str, 400);
if (!tooltip_timer_) {
- lyx::Assert(ob->form);
if (fl_current_form && ob->form != fl_current_form)
fl_end_form();
}
-string const Tooltips::getTooltip(FL_OBJECT * ob) const
+string const Tooltips::get(FL_OBJECT * ob) const
{
TooltipsMap::const_iterator it = tooltipsMap.find(ob);
if (it == tooltipsMap.end())
FL_FORM * form = ob->form;
Tooltips * tooltip = static_cast<Tooltips *>(timer->u_vdata);
- string const help = tooltip->getTooltip(ob);
+ string const help = tooltip->get(ob);
if (help.empty())
return;