+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:
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();
} 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());
}
}
+// 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)
{
/// 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);