]> git.lyx.org Git - features.git/commitdiff
John's spellchecker patch plus a new helper function getStringFromBrowser.
authorAngus Leeming <leeming@lyx.org>
Tue, 8 Jan 2002 10:05:53 +0000 (10:05 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 8 Jan 2002 10:05:53 +0000 (10:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3309 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FormSpellchecker.C
src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/xforms_helpers.h

index fd51c285ae789e4d2379fe719ae5867fda9ad6ba..216d3381eafc2de7e712a4d78873e2d08f38736c 100644 (file)
@@ -1,3 +1,12 @@
+2002-01-08  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * xform_helpers.[Ch] (getStringFromBrowser): a littel wrapper function
+       for fl_get_browser_line that is guaranteed to return a valid string.
+
+2002-01-08  John Levon  <moz@compsoc.man.ac.uk>
+
+       * FormSpellchecker.C: fix possible crash on clicking a suggestion
+
 2002-01-07  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * FormDocument.C:
index b363e6c5b94bf3c5a5f36648d0b0cca19f7724e4..d13d6fe23b89f445e0ad187f0d779a377d672d2f 100644 (file)
@@ -63,7 +63,7 @@ void FormSpellchecker::hide()
 ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
 {
        if (obj == dialog_->replace) {
-               string tmp = fl_get_input(dialog_->input);
+               string const tmp = fl_get_input(dialog_->input);
                controller().replace(tmp);
        } else if (obj == dialog_->start) {
                controller().check();
@@ -80,13 +80,19 @@ ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
        } else if (obj == dialog_->options) {
                controller().options();
        } else if (obj == dialog_->browser) {
-               int sel = fl_get_browser(dialog_->browser);
-               if (clickline_==sel) {
-                       string tmp = fl_get_input(dialog_->input);
+               int const sel = fl_get_browser(dialog_->browser);
+               if (sel < 1)
+                       return ButtonPolicy::SMI_NOOP;
+
+               if (clickline_ == sel) {
+                       string const tmp = fl_get_input(dialog_->input);
                        controller().replace(tmp);
                }
+
                clickline_ = sel;
-               string tmp = fl_get_browser_line(dialog_->browser, clickline_);
+               char const * cptmp = fl_get_browser_line(dialog_->browser,
+                                                        clickline_);
+               string const tmp = (cptmp) ? cptmp : "";
                fl_set_input(dialog_->input, tmp.c_str());
        }
 
index eb39bd38c2c407ac478874c190e8bb16f2679fe7..f65b70825516fecc4cb8419ef589de9eb9aa598a 100644 (file)
@@ -90,6 +90,19 @@ vector<string> const getVectorFromChoice(FL_OBJECT * ob)
 }
 
 
+// Given an fl_browser, return the contents of the currently
+// highlighted line.
+// If nothing is selected, return an empty string
+string const getStringFromBrowser(FL_OBJECT * ob, int line)
+{
+       if (!ob || ob->objclass != FL_BROWSER || 
+           line < 1 || line > fl_get_browser_maxline(ob))
+               return string();
+
+       char const * tmp = fl_get_browser_line(ob, line);
+       return (tmp) ? tmp : string();
+}
+
 // Given an fl_browser, create a vector of its entries
 vector<string> const getVectorFromBrowser(FL_OBJECT * ob)
 {
index 9c1184e503b58bfa1affecc8c9d78e2bab3f50be..828ada07a09f32c665365c7712baedd89df85e2e 100644 (file)
@@ -39,6 +39,14 @@ std::vector<string> const getVectorFromChoice(FL_OBJECT *);
 /// Given an fl_browser, create a vector of its entries
 std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
 
+/** Given an fl_browser, return the contents of the currently
+    highlighted line (xforms numbering convention; starts at 1).
+    If nothing is selected, return an empty string.
+    This function, although apparently overkill, ensures that we don't get
+    unexpected crashes.
+*/
+string const getStringFromBrowser(FL_OBJECT * ob, int line);
+
 /// Given input and choice widgets, create a string such as "1cm"
 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);