Clean-up tooltips further, rewrite formatted as a one-pass algo and

ensure that fl_set_object_helper is called only when the dialog is
visible, else it does not respect line breaks. Wierd, I know!


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3766 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-03-18 15:56:00 +00:00
parent 53e8fb6000
commit 9bf713b476
12 changed files with 128 additions and 73 deletions

View File

@ -1,3 +1,23 @@
2002-03-18 Angus Leeming <a.leeming@ic.ac.uk>
* Tooltips.[Ch] (initTooltip): renamed init. In the 0.89 version, no
longer call fl_set_object_helper as this routine respects line breaks
only if the dialog is visible.
(getTooltip): renamed get.
(toggleTooltips): renamed set and made public,
* FormBase.C (show):
* FormBaseDeprecated.C (show): move tooltip-inards into Tooltip.
* FormBibtex.C (build):
* FormCitation.C (build):
* FormForks.C (build):
* FormSendto.C (build):
* FormTexinfo.C (build):
* Toolbar_pimpl.C (set): Tooltip::initTooltip -> Tooltip::init.
* xforms_helper.C (formatted): rewritten as a one-pass algorithm.
2002-03-18 Juergen Vigna <jug@sad.it>
* FormTabular.C (update): deactivate left/right border settings for

View File

@ -102,12 +102,7 @@ void FormBase::show()
title_.c_str());
}
// Set the initial state of the cursor
if (form()->visible) {
int const cursor = Tooltips::enabled() ?
XC_question_arrow : FL_DEFAULT_CURSOR;
fl_set_cursor(form()->window, cursor);
}
tooltips().set();
}

View File

@ -122,12 +122,7 @@ void FormBaseDeprecated::show()
title_.c_str());
}
// Set the initial state of the cursor
if (form()->visible) {
int const cursor = Tooltips::enabled() ?
XC_question_arrow : FL_DEFAULT_CURSOR;
fl_set_cursor(form()->window, cursor);
}
tooltips().set();
}

View File

@ -60,16 +60,16 @@ void FormBibtex::build()
// set up the tooltips
string str = N_("The database you want to cite from. Insert it without the default extension \".bib\". If you insert it with the browser, LyX strips the extension. Several databases must be separated by a comma: \"natbib, books\".");
tooltips().initTooltip(dialog_->button_database_browse, str);
tooltips().init(dialog_->button_database_browse, str);
str = N_("Browse your directory for BibTeX stylefiles.");
tooltips().initTooltip(dialog_->button_style_browse, str);
tooltips().init(dialog_->button_style_browse, str);
str = N_("The BibTeX style to use (only one allowed). Insert it without the default extension \".bst\" and without path. Most of the bibstyles are stored in $TEXMF/bibtex/bst. $TEXMF is the root dir of the local TeX tree. In \"Help->TeX Info\" you can list all installed styles.");
tooltips().initTooltip(dialog_->input_style, str);
tooltips().init(dialog_->input_style, str);
str = N_("Activate this option if you want the bibliography to appear in the Table of Contents (which doesn't happen by default).");
tooltips().initTooltip(dialog_->check_bibtotoc, str);
tooltips().init(dialog_->check_bibtotoc, str);
}

View File

@ -172,49 +172,49 @@ void FormCitation::build()
//set up the tooltip mechanism
string str = N_("Add the selected entry to the current citation reference.");
tooltips().initTooltip(dialog_->button_add, str);
tooltips().init(dialog_->button_add, str);
str = N_("Delete the selected entry from the current citation reference.");
tooltips().initTooltip(dialog_->button_del, str);
tooltips().init(dialog_->button_del, str);
str = N_("Move the selected entry upwards (in the current list).");
tooltips().initTooltip(dialog_->button_up, str);
tooltips().init(dialog_->button_up, str);
str = N_("Move the selected entry downwards (in the current list).");
tooltips().initTooltip(dialog_->button_down, str);
tooltips().init(dialog_->button_down, str);
str = N_("The entries which will be cited. Select them with the arrow buttons from the right browser window.");
tooltips().initTooltip(dialog_->browser_cite, str);
tooltips().init(dialog_->browser_cite, str);
str = N_("All entries in the database you have loaded (via \"Insert->Lists&TOC->BibTex Reference\"). Move the ones you want to cite with the arrow buttons into the left browser window.");
tooltips().initTooltip(dialog_->browser_bib, str);
tooltips().init(dialog_->browser_bib, str);
str = N_("Information about the selected entry");
tooltips().initTooltip(dialog_->browser_info, str);
tooltips().init(dialog_->browser_info, str);
str = N_("Here you may select how the citation label should look inside the text (Natbib).");
tooltips().initTooltip(dialog_->choice_style, str);
tooltips().init(dialog_->choice_style, str);
str = N_("Activate if you want to print all authors in a reference with more than three authors, and not \"<First Author> et.al.\" (Natbib).");
tooltips().initTooltip(dialog_->check_full_author_list, str);
tooltips().init(dialog_->check_full_author_list, str);
str = N_("Activate if you want to print the first character of the author name as uppercase (\"Van Gogh\", not \"van Gogh\"). Useful at the beginning of sentences (Natbib).");
tooltips().initTooltip(dialog_->check_force_uppercase, str);
tooltips().init(dialog_->check_force_uppercase, str);
str = N_("Optional text which appears before the citation reference, e.g. \"see <Ref>\"");
tooltips().initTooltip(dialog_->input_before, str);
tooltips().init(dialog_->input_before, str);
str = N_("Optional text which appears after the citation reference, e.g. \"pp. 12\"");
tooltips().initTooltip(dialog_->input_after, str);
tooltips().init(dialog_->input_after, str);
str = N_("Search your database (all fields will be searched).");
tooltips().initTooltip(dialog_->input_search, str);
tooltips().init(dialog_->input_search, str);
str = N_("Activate if you want to have case sensitive search: \"bibtex\" finds \"bibtex\", but not \"BibTeX\".");
tooltips().initTooltip(dialog_->check_search_case, str);
tooltips().init(dialog_->check_search_case, str);
str = N_("Activate if you want to enter Regular Expressions.");
tooltips().initTooltip(dialog_->check_search_type, str);
tooltips().init(dialog_->check_search_type, str);
}

View File

@ -52,19 +52,19 @@ void FormForks::build() {
// Set up the tooltip mechanism
string str = N_("All currently running child processes forked by LyX.");
tooltips().initTooltip(dialog_->browser_children, str);
tooltips().init(dialog_->browser_children, str);
str = N_("A list of all child processes to kill.");
tooltips().initTooltip(dialog_->browser_kill, str);
tooltips().init(dialog_->browser_kill, str);
str = N_("Add all processes to the list of processes to kill.");
tooltips().initTooltip(dialog_->button_all, str);
tooltips().init(dialog_->button_all, str);
str = N_("Add the currently selected child process to the list of processes to kill.");
tooltips().initTooltip(dialog_->button_add, str);
tooltips().init(dialog_->button_add, str);
str = N_("Remove the currently selected item from the list of processes to kill.");
tooltips().initTooltip(dialog_->button_remove, str);
tooltips().init(dialog_->button_remove, str);
}

View File

@ -44,10 +44,10 @@ void FormSendto::build()
// Set up the tooltip mechanism
string str = N_("Export the buffer to this format before running the command below on it.");
tooltips().initTooltip(dialog_->browser_formats, str);
tooltips().init(dialog_->browser_formats, str);
str = N_("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
tooltips().initTooltip(dialog_->input_command, str);
tooltips().init(dialog_->input_command, str);
}

View File

@ -41,25 +41,25 @@ void FormTexinfo::build() {
// set up the tooltips
string str = N_("Runs the script \"TexFiles.sh\" to build new file lists.");
tooltips().initTooltip(dialog_->button_rescan, str);
tooltips().init(dialog_->button_rescan, str);
str = N_("Shows the contents of the marked file. Only possible in full path mode.");
tooltips().initTooltip(dialog_->button_view, str);
tooltips().init(dialog_->button_view, str);
str = N_("Runs the script \"texhash\" which builds the a new LaTeX tree. Needed if you install a new TeX class or style. To execute it, you need the write permissions for the tex-dirs, often /var/lib/texmf and other.");
tooltips().initTooltip(dialog_->button_texhash, str);
tooltips().init(dialog_->button_texhash, str);
str = N_("View full path or only file name. Full path is needed to view the contents of a file.");
tooltips().initTooltip(dialog_->check_fullpath, str);
tooltips().init(dialog_->check_fullpath, str);
str = N_("Shows the installed LaTeX Document classes. Remember, that these classes are only available in LyX if a corresponding LyX layout file exists!");
tooltips().initTooltip(dialog_->radio_cls, str);
tooltips().init(dialog_->radio_cls, str);
str = N_("Shows the installed LaTeX style files, which are available in LyX by default, like \"babel\" or through \\usepackage{<the stylefile>} in LaTeX preamble.");
tooltips().initTooltip(dialog_->radio_sty, str);
tooltips().init(dialog_->radio_sty, str);
str = N_("Shows the installed style files for BibTeX. They can be loaded through insert->Lists&Toc->BibTeX Reference->Style.");
tooltips().initTooltip(dialog_->radio_bst, str);
tooltips().init(dialog_->radio_bst, str);
}

View File

@ -355,7 +355,7 @@ void Toolbar::Pimpl::set(bool doingmain)
// initialise the tooltip
string const tip = _(lyxaction.helpText(obj->argument));
tooltip_->initTooltip(obj, tip);
tooltip_->init(obj, tip);
// The view that this object belongs to.
obj->u_vdata = owner;

View File

@ -6,9 +6,7 @@
* \author Angus Leeming, a.leeming@ic.ac.uk
*/
/*
*
* 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.
@ -32,7 +30,7 @@ using SigC::slot;
bool Tooltips::enabled_ = false;
SigC::Signal0<void> Tooltips::tooltipsToggled;
SigC::Signal0<void> Tooltips::toggled;
#if FL_REVISION >= 89
@ -44,18 +42,18 @@ Tooltips::Tooltips()
first = false;
Dialogs::toggleTooltips.connect(slot(&Tooltips::toggleEnabled));
}
tooltipsToggled.connect(slot(this, &Tooltips::toggleTooltips));
toggled.connect(slot(this, &Tooltips::set));
}
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
@ -82,7 +80,7 @@ void Tooltips::toggleTooltips()
}
void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
void Tooltips::init(FL_OBJECT * ob, string const & tip)
{
lyx::Assert(ob && ob->form);
@ -97,10 +95,6 @@ void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
// Store the tooltip string
tooltipsMap[ob] = formatted(_(str), 400);
// Set the initial state of the tooltips
char const * const c_str = enabled_ ? str.c_str() : 0;
fl_set_object_helper(ob, c_str);
}
@ -139,18 +133,18 @@ Tooltips::Tooltips()
first = false;
Dialogs::toggleTooltips.connect(slot(&Tooltips::toggleEnabled));
}
tooltipsToggled.connect(slot(this, &Tooltips::toggleTooltips));
toggled.connect(slot(this, &Tooltips::set));
}
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
@ -169,7 +163,7 @@ void Tooltips::toggleTooltips()
}
void Tooltips::initTooltip(FL_OBJECT * ob, string const & tip)
void Tooltips::init(FL_OBJECT * ob, string const & tip)
{
lyx::Assert(ob && ob->form);
@ -205,7 +199,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())
@ -223,7 +217,7 @@ void TooltipTimerCB(FL_OBJECT * timer, long data)
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;

View File

@ -31,17 +31,20 @@ public:
Tooltips();
/// Initialise a tooltip for this ob.
void initTooltip(FL_OBJECT * ob, string const & tip);
void init(FL_OBJECT * ob, string const & tip);
/// Are the tooltips on or off?
static bool enabled() { return enabled_; }
/// This method is connected to the tooltipsToggled signal.
void set();
#if FL_REVISION < 89
/** Return the tooltip associated with this object.
* Required by an xforms callback routine.
*/
string const getTooltip(FL_OBJECT *) const;
string const get(FL_OBJECT *) const;
#endif
@ -58,10 +61,7 @@ private:
/** Once enabled_ is changed, then this signal is emitted to update
* all the tooltips.
*/
static SigC::Signal0<void> tooltipsToggled;
/// This method is connected to the tooltipsToggled signal.
void toggleTooltips();
static SigC::Signal0<void> toggled;
/// The tooltips are stored so that they can be turned on and off.
typedef std::map<FL_OBJECT *, string> TooltipsMap;

View File

@ -40,7 +40,6 @@ char const * flyx_shortcut_extract(char const * sc)
if (sd[0] == '|') {
++sd;
//lyxerr << sd << endl;
return sd;
}
return "";
@ -300,11 +299,12 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
// Take a string and add breaks so that it fits into a desired label width, w
string formatted(string const & sin, int w, int size, int style)
{
// FIX: Q: Why cant this be done by a one pass algo? (Lgb)
string sout;
if (sin.empty()) return sout;
#if 0
// FIX: Q: Why cant this be done by a one pass algo? (Lgb)
// breaks in up into a vector of individual words
vector<string> sentence;
string word;
@ -360,6 +360,57 @@ string formatted(string const & sin, int w, int size, int style)
if (sout[sout.length() - 1] == '\n')
sout.erase(sout.length() - 1);
#else
string::size_type curpos = 0;
string line;
for(;;) {
string::size_type const nxtpos1 = sin.find(' ', curpos);
string::size_type const nxtpos2 = sin.find('\n', curpos);
string::size_type const nxtpos = std::min(nxtpos1, nxtpos1);
string const word = nxtpos == string::npos ?
sin.substr(curpos) : sin.substr(curpos, nxtpos-curpos);
bool const newline = (nxtpos2 != string::npos &&
nxtpos2 < nxtpos1);
string const line_plus_word =
line.empty() ? word : line + ' ' + word;
int const length =
fl_get_string_width(style, size,
line_plus_word.c_str(),
int(line_plus_word.length()));
if (length >= w) {
sout += line + '\n';
if (newline) {
sout += word + '\n';
line.erase();
} else {
line = word;
}
} else if (newline) {
sout += line_plus_word + '\n';
line.erase();
} else {
if (!line.empty())
line += ' ';
line += word;
}
if (nxtpos == string::npos) {
if (!line.empty())
sout += line;
break;
}
curpos = nxtpos+1;
}
#endif
return sout;
}