2002-09-05 14:10:50 +00:00
|
|
|
/**
|
2002-02-06 17:15:28 +00:00
|
|
|
* \file Tooltips.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-02-06 17:15:28 +00:00
|
|
|
*
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-03-11 17:00:41 +00:00
|
|
|
*/
|
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
/* Tooltips for xforms. xforms 0.89 supports them directly, but 0.88 needs
|
2002-02-06 17:15:28 +00:00
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Tooltips.h"
|
2002-03-11 09:54:42 +00:00
|
|
|
#include "xforms_helpers.h" // formatted
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "support/lstrings.h"
|
2002-02-06 17:15:28 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2002-02-06 17:15:28 +00:00
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/bind.hpp>
|
2002-03-11 09:54:42 +00:00
|
|
|
|
2002-05-09 13:43:44 +00:00
|
|
|
bool Tooltips::enabled_ = true;
|
2002-03-11 09:54:42 +00:00
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
boost::signal0<void> Tooltips::toggled;
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
Tooltips::Tooltips()
|
2002-03-11 09:54:42 +00:00
|
|
|
{
|
2002-05-29 16:21:03 +00:00
|
|
|
toggled.connect(boost::bind(&Tooltips::set, this));
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tooltips::toggleEnabled()
|
|
|
|
{
|
|
|
|
enabled_ = !enabled_;
|
2002-03-18 15:56:00 +00:00
|
|
|
toggled();
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
void Tooltips::set()
|
2002-03-11 09:54:42 +00:00
|
|
|
{
|
|
|
|
if (tooltipsMap.empty())
|
|
|
|
return;
|
|
|
|
|
2002-11-29 12:47:33 +00:00
|
|
|
TooltipsMap::const_iterator it = tooltipsMap.begin();
|
|
|
|
TooltipsMap::const_iterator end = tooltipsMap.end();
|
2002-03-11 09:54:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
void Tooltips::init(FL_OBJECT * ob, string const & tip)
|
2002-02-06 17:15:28 +00:00
|
|
|
{
|
2002-03-13 11:26:36 +00:00
|
|
|
lyx::Assert(ob && ob->form);
|
2002-02-06 17:15:28 +00:00
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
// Store the tooltip string
|
2002-12-01 22:59:25 +00:00
|
|
|
string const str = formatted(trim(tip), 400);
|
2002-10-21 11:13:01 +00:00
|
|
|
tooltipsMap[ob] = str;
|
2002-10-14 16:38:00 +00:00
|
|
|
|
|
|
|
// Set the tooltip
|
|
|
|
char const * const c_str = enabled_ ? str.c_str() : 0;
|
|
|
|
fl_set_object_helper(ob, c_str);
|
2002-02-06 17:15:28 +00:00
|
|
|
}
|