+ vector <string> vec;
+
+ switch (ob->objclass) {
+ case FL_CHOICE:
+ for(int i = 0; i < fl_get_choice_maxitems(ob); ++i) {
+ string const text = fl_get_choice_item_text(ob, i+1);
+ vec.push_back(trim(text));
+ }
+ break;
+ case FL_BROWSER:
+ for(int i = 0; i < fl_get_browser_maxline(ob); ++i) {
+ string const text = fl_get_browser_line(ob, i+1);
+ vec.push_back(trim(text));
+ }
+ break;
+ default:
+ BOOST_ASSERT(false);
+ }
+
+ return vec;
+}
+
+
+///
+string const getString(FL_OBJECT * ob, int line)
+{
+ // Negative line value does not make sense.
+ BOOST_ASSERT(line >= 0);
+
+ char const * tmp = 0;
+ switch (ob->objclass) {
+ case FL_INPUT:
+ tmp = fl_get_input(ob);
+ break;
+
+ case FL_BROWSER:
+ if (line == 0)
+ line = fl_get_browser(ob);
+
+ if (line >= 1 && line <= fl_get_browser_maxline(ob))
+ tmp = fl_get_browser_line(ob, line);
+ break;
+
+ case FL_CHOICE:
+ if (line == 0)
+ line = fl_get_choice(ob);
+
+ if (line >= 1 && line <= fl_get_choice_maxitems(ob))
+ tmp = fl_get_choice_item_text(ob, line);
+ break;
+
+ case FL_COMBOX:
+ tmp = fl_get_combox_text(ob);
+ break;
+
+ default:
+ BOOST_ASSERT(false);
+ }
+
+ return tmp ? trim(tmp) : string();
+}
+
+string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
+{
+ // Paranoia check
+ BOOST_ASSERT(input && input->objclass == FL_INPUT &&
+ choice && choice->objclass == FL_CHOICE);
+
+ string const length = trim(fl_get_input(input));
+ if (length.empty())
+ return string();
+
+ // don't return unit-from-choice if the input(field) contains a unit
+ if (isValidGlueLength(length))
+ return length;
+
+ string unit = trim(fl_get_choice_text(choice));
+ unit = subst(unit, "%%", "%");
+
+ return length + unit;
+}
+
+
+void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
+ string const & str,
+ string const & default_unit)
+{
+ // Paranoia check
+ BOOST_ASSERT(input && input->objclass == FL_INPUT &&
+ choice && choice->objclass == FL_CHOICE);
+
+ // use input field only for gluelengths
+ if (!isValidLength(str) && !isStrDbl(str)) {
+ fl_set_input(input, str.c_str());
+ // we assume that "default_unit" is in the choice as "we"
+ // have control over that!
+ // No need to check for its presence in the choice, therefore.
+ fl_set_choice_text(choice, default_unit.c_str());
+ } else {
+ updateWidgetsFromLength(input, choice,
+ LyXLength(str), default_unit);
+ }
+}
+
+
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+ LyXLength const & len,
+ string const & default_unit)
+{
+ // Paranoia check
+ BOOST_ASSERT(input && input->objclass == FL_INPUT &&
+ choice && choice->objclass == FL_CHOICE);
+
+ if (len.empty()) {
+ fl_set_input(input, "");
+ fl_set_choice_text(choice, default_unit.c_str());
+ } else {
+ fl_set_input(input, tostr(len.value()).c_str());
+
+ // Set the choice to the desired unit, if present in the choice.
+ // Else set the choice to the default unit.
+ string const unit = subst(stringFromUnit(len.unit()),"%","%%");
+
+ vector<string> const vec = getVector(choice);
+ vector<string>::const_iterator it =
+ std::find(vec.begin(), vec.end(), unit);
+ if (it != vec.end()) {
+ fl_set_choice_text(choice, unit.c_str());