From 9bf713b476658f128aaa20d74cef126ad55dc6d0 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 18 Mar 2002 15:56:00 +0000 Subject: [PATCH] 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 --- src/frontends/xforms/ChangeLog | 20 ++++++++ src/frontends/xforms/FormBase.C | 7 +-- src/frontends/xforms/FormBaseDeprecated.C | 7 +-- src/frontends/xforms/FormBibtex.C | 8 ++-- src/frontends/xforms/FormCitation.C | 30 ++++++------ src/frontends/xforms/FormForks.C | 10 ++-- src/frontends/xforms/FormSendto.C | 4 +- src/frontends/xforms/FormTexinfo.C | 14 +++--- src/frontends/xforms/Toolbar_pimpl.C | 2 +- src/frontends/xforms/Tooltips.C | 30 +++++------- src/frontends/xforms/Tooltips.h | 12 ++--- src/frontends/xforms/xforms_helpers.C | 57 +++++++++++++++++++++-- 12 files changed, 128 insertions(+), 73 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index b674bfa33c..a6ea00521a 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,23 @@ +2002-03-18 Angus Leeming + + * 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 * FormTabular.C (update): deactivate left/right border settings for diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index b637b5fb65..7ac2b85ff8 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -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(); } diff --git a/src/frontends/xforms/FormBaseDeprecated.C b/src/frontends/xforms/FormBaseDeprecated.C index e5735d0712..ad1d032602 100644 --- a/src/frontends/xforms/FormBaseDeprecated.C +++ b/src/frontends/xforms/FormBaseDeprecated.C @@ -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(); } diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index 2a119d17fd..b6ac763db0 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -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); } diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index 81f465fd82..99bbcfa34b 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -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 \" 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 \""); - 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); } diff --git a/src/frontends/xforms/FormForks.C b/src/frontends/xforms/FormForks.C index a4fcb77083..e54df5a7e7 100644 --- a/src/frontends/xforms/FormForks.C +++ b/src/frontends/xforms/FormForks.C @@ -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); } diff --git a/src/frontends/xforms/FormSendto.C b/src/frontends/xforms/FormSendto.C index 39fa5cdae9..6ace8e2078 100644 --- a/src/frontends/xforms/FormSendto.C +++ b/src/frontends/xforms/FormSendto.C @@ -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); } diff --git a/src/frontends/xforms/FormTexinfo.C b/src/frontends/xforms/FormTexinfo.C index 561402f79a..3a54234168 100644 --- a/src/frontends/xforms/FormTexinfo.C +++ b/src/frontends/xforms/FormTexinfo.C @@ -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{} 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); } diff --git a/src/frontends/xforms/Toolbar_pimpl.C b/src/frontends/xforms/Toolbar_pimpl.C index da2f72979b..abb446e3a2 100644 --- a/src/frontends/xforms/Toolbar_pimpl.C +++ b/src/frontends/xforms/Toolbar_pimpl.C @@ -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; diff --git a/src/frontends/xforms/Tooltips.C b/src/frontends/xforms/Tooltips.C index c1aa13cc47..545dffc48f 100644 --- a/src/frontends/xforms/Tooltips.C +++ b/src/frontends/xforms/Tooltips.C @@ -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 Tooltips::tooltipsToggled; +SigC::Signal0 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(timer->u_vdata); - string const help = tooltip->getTooltip(ob); + string const help = tooltip->get(ob); if (help.empty()) return; diff --git a/src/frontends/xforms/Tooltips.h b/src/frontends/xforms/Tooltips.h index bd4342cc0a..5d4753929a 100644 --- a/src/frontends/xforms/Tooltips.h +++ b/src/frontends/xforms/Tooltips.h @@ -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 tooltipsToggled; - - /// This method is connected to the tooltipsToggled signal. - void toggleTooltips(); + static SigC::Signal0 toggled; /// The tooltips are stored so that they can be turned on and off. typedef std::map TooltipsMap; diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 54668d8c06..c6dd5bc457 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -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 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; } -- 2.39.5