- // break sin up into a vector of individual words
- vector<string> sentence;
- string word;
- for (string::const_iterator sit = sin.begin();
- sit != sin.end(); ++sit) {
- if ((*sit) == ' ' || (*sit) == '\n') {
- sentence.push_back(word);
- word.erase();
- if ((*sit) == '\n') word += '\n';
-
+ // 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)
+{
+ // 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
+ lyx::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 {
+ ostringstream buffer;
+ buffer << len.value();
+ fl_set_input(input, buffer.str().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());