]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/Tooltips.C
having broken Rob's word count update, I guess I should fix it too ;-)
[lyx.git] / src / frontends / xforms / Tooltips.C
index ee80e055868f6467b4d199f5b1922417df0dfb9e..d5e3defd6f807d3b3d9517f8844809151067f5cb 100644 (file)
@@ -1,11 +1,14 @@
-/*
+/**
  * \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.
 #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);
 }
@@ -103,7 +85,7 @@ namespace {
 int TooltipHandler(FL_OBJECT *ob, int event);
 
 void TooltipTimerCB(FL_OBJECT * timer, long data);
+
 }
 
 extern "C" {
@@ -121,59 +103,43 @@ static void C_TooltipTimerCB(FL_OBJECT * ob, long data)
 }
 
 }
+
 
 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;
-
-       // 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::set()
+{}
 
 
-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();
 
@@ -193,7 +159,7 @@ void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
 }
 
 
-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())
@@ -210,8 +176,8 @@ void TooltipTimerCB(FL_OBJECT * timer, long 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);
+
+       string const help = tooltip->get(ob);
        if (help.empty())
                return;