X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FTooltips.C;h=d5e3defd6f807d3b3d9517f8844809151067f5cb;hb=8daf842ccd447521676dfcb9dbcd9a541e997e6f;hp=022777504454bab6b74e0a829edc237af529bda9;hpb=7ea7dabed1b72cc25dcbdc482ac006f2b61dacfd;p=lyx.git diff --git a/src/frontends/xforms/Tooltips.C b/src/frontends/xforms/Tooltips.C index 0227775044..d5e3defd6f 100644 --- a/src/frontends/xforms/Tooltips.C +++ b/src/frontends/xforms/Tooltips.C @@ -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. @@ -18,33 +21,71 @@ #endif #include "Tooltips.h" +#include "xforms_helpers.h" // formatted +#include "gettext.h" +#include "support/lstrings.h" #include "support/LAssert.h" +#include FORMS_H_LOCATION + +#include + +bool Tooltips::enabled_ = true; -//#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 +boost::signal0 Tooltips::toggled; -/* -void Tooltips::activateTooltip(FL_OBJECT * ob) + +#if FL_VERSION > 0 || FL_REVISION >= 89 + +Tooltips::Tooltips() { - lyx::Assert(ob); + toggled.connect(boost::bind(&Tooltips::set, this)); +} + + +void Tooltips::toggleEnabled() +{ + enabled_ = !enabled_; + toggled(); +} + - string const help(getTooltip(ob)); - if (!help.empty()) - fl_set_object_helper(ob, help.c_str()); +void Tooltips::set() +{ + if (tooltipsMap.empty()) + return; + + 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); + } } -*/ -//#else // if FL_REVISION < 89 + +void Tooltips::init(FL_OBJECT * ob, string const & tip) +{ + lyx::Assert(ob && ob->form); + + // 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); +} + + +#else // if FL_REVISION < 89 namespace { int TooltipHandler(FL_OBJECT *ob, int event); void TooltipTimerCB(FL_OBJECT * timer, long data); - + } extern "C" { @@ -62,17 +103,54 @@ static void C_TooltipTimerCB(FL_OBJECT * ob, long data) } } - -void Tooltips::activateTooltip(FL_OBJECT * ob) + +Tooltips::Tooltips() + : tooltip_timer_(0) { - lyx::Assert(ob); + toggled.connect(boost::bind(&Tooltips::set, this)); +} + + +void Tooltips::toggleEnabled() +{ + enabled_ = !enabled_; + toggled(); +} + + +void Tooltips::set() +{} + + +void Tooltips::init(FL_OBJECT * ob, string const & tip) +{ + lyx::Assert(ob && ob->form); + + // Paranoia check! + TooltipsMap::const_iterator it = tooltipsMap.find(ob); + if (it != tooltipsMap.end()) + return; + + string const str = trim(tip); + if (str.empty()) + return; + + // Store the tooltip string + tooltipsMap[ob] = formatted(str, 400); if (!tooltip_timer_) { - lyx::Assert(ob->form); - fl_addto_form(ob->form); + if (fl_current_form && ob->form != fl_current_form) + fl_end_form(); + + bool const open_form = !fl_current_form; + if (open_form) + fl_addto_form(ob->form); + tooltip_timer_ = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, ""); - fl_end_form(); + + if (open_form) + fl_end_form(); } fl_set_object_posthandler(ob, C_TooltipHandler); @@ -81,6 +159,15 @@ void Tooltips::activateTooltip(FL_OBJECT * ob) } +string const Tooltips::get(FL_OBJECT * ob) const +{ + TooltipsMap::const_iterator it = tooltipsMap.find(ob); + if (it == tooltipsMap.end()) + return string(); + return it->second; +} + + namespace { void TooltipTimerCB(FL_OBJECT * timer, long data) @@ -89,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(timer->u_vdata); - - string const help = tooltip->getTooltip(ob); + + string const help = tooltip->get(ob); if (help.empty()) return; @@ -99,9 +186,12 @@ void TooltipTimerCB(FL_OBJECT * timer, long data) } -// post_handler for bubble-help (Matthias) -int TooltipHandler(FL_OBJECT *ob, int event) +// post_handler for tooltip help +int TooltipHandler(FL_OBJECT * ob, int event) { + if (!Tooltips::enabled()) + return 0; + lyx::Assert(ob); FL_OBJECT * timer = reinterpret_cast(ob->u_cdata); lyx::Assert(timer); @@ -122,4 +212,4 @@ int TooltipHandler(FL_OBJECT *ob, int event) } // namespace anon -//#endif // FL_REVISION < 89 +#endif // FL_REVISION >= 89