]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormParagraph.C
remove defaults stuff, let Qt handle no toolbar
[lyx.git] / src / frontends / xforms / FormParagraph.C
index 27ac50bf9f4514d1de2451de5b95a79a05c08f27..ed583bc0b74f32ff4e2f9fd6fece2fad4bb76ae0 100644 (file)
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *           Copyright 2000-2001 The LyX Team.
+/**
+ * \file FormParagraph.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           @author Jürgen Vigna
+ * \author Jürgen Vigna
+ * \author Rob Lahaye
  *
- *======================================================*/
+ * Full author contact details are available in file CREDITS
+ */
 
 #include <config.h>
 
-#ifdef __GNUG_
-#pragma implementation
-#endif
-
-#include FORMS_H_LOCATION
 
+#include "ControlParagraph.h"
 #include "FormParagraph.h"
-#include "form_paragraph.h"
-#include "Dialogs.h"
-#include "support/lstrings.h" 
-#include "Liason.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "lyxtext.h"
-#include "xforms_helpers.h"
-#include "BufferView.h"
-#include "Spacing.h"
+#include "forms/form_paragraph.h"
+#include "Tooltips.h"
+
 #include "ParagraphParameters.h"
+
+#include "xforms_helpers.h"
+#include "lyxrc.h" // to set the deafult length values
 #include "input_validators.h"
 #include "helper_funcs.h"
+#include "checkedwidgets.h"
+#include "gettext.h"
+#include "xformsBC.h"
+#include "layout.h" // LyXAlignment
 
-using Liason::setMinibuffer;
-using SigC::slot;
+#include "support/lstrings.h"
+#include "support/LAssert.h"
 
+#include FORMS_H_LOCATION
 
-FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
-       : FormBaseBD(lv, d, _("Paragraph Layout")), par_(0)
-{
-    // let the dialog be shown
-    // This is a permanent connection so we won't bother
-    // storing a copy because we won't be disconnecting.
-    d->showParagraph.connect(slot(this, &FormParagraph::show));
-}
+#include <functional>
+
+using std::vector;
+using std::bind2nd;
+using std::remove_if;
 
 
-void FormParagraph::connect()
+namespace
 {
-       cp_ = d_->updateParagraph
-               .connect(slot(this, &FormParagraph::changedParagraph));
-       FormBaseBD::connect();
-}
+
+string defaultUnit("cm");
+
+void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length);
+
+VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
+                                 FL_OBJECT * input_length,
+                                 FL_OBJECT * choice_length,
+                                 FL_OBJECT * check_keep);
+
+void setWidgetsFromVSpace(VSpace const & space,
+                         FL_OBJECT * choice_type,
+                         FL_OBJECT * input_length,
+                         FL_OBJECT * choice_length,
+                         FL_OBJECT * check_keep);
+
+} // namespace anon
 
 
-void FormParagraph::disconnect()
+typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
+
+FormParagraph::FormParagraph(Dialog & parent)
+       : base_class(parent, _("Paragraph Layout"))
+{}
+
+
+void FormParagraph::build()
 {
-       cp_.disconnect();
-       FormBaseBD::disconnect();
+       // the tabbed folder
+       dialog_.reset(build_paragraph(this));
+
+       // Manage the ok, apply, restore and cancel/close buttons
+       bcview().setOK(dialog_->button_ok);
+       bcview().setApply(dialog_->button_apply);
+       bcview().setCancel(dialog_->button_close);
+       bcview().setRestore(dialog_->button_restore);
+
+       // disable for read-only documents
+       bcview().addReadOnly(dialog_->check_line_above);
+       bcview().addReadOnly(dialog_->check_pagebreak_above);
+       bcview().addReadOnly(dialog_->choice_space_above);
+       bcview().addReadOnly(dialog_->input_space_above);
+       bcview().addReadOnly(dialog_->check_space_above);
+
+       bcview().addReadOnly(dialog_->check_noindent);
+       bcview().addReadOnly(dialog_->choice_linespacing);
+       bcview().addReadOnly(dialog_->input_linespacing);
+
+       bcview().addReadOnly(dialog_->check_line_below);
+       bcview().addReadOnly(dialog_->check_pagebreak_below);
+       bcview().addReadOnly(dialog_->choice_space_below);
+       bcview().addReadOnly(dialog_->input_space_below);
+       bcview().addReadOnly(dialog_->check_space_below);
+
+       bcview().addReadOnly(dialog_->input_labelwidth);
+
+       // check validity of "length + unit" input
+       addCheckedGlueLength(bcview(),
+                            dialog_->input_space_above,
+                            dialog_->choice_space_above);
+       addCheckedGlueLength(bcview(),
+                            dialog_->input_space_below,
+                            dialog_->choice_space_below);
+
+       // trigger an input event for cut&paste with middle mouse button.
+       setPrehandler(dialog_->input_space_above);
+       setPrehandler(dialog_->input_space_below);
+       setPrehandler(dialog_->input_linespacing);
+       setPrehandler(dialog_->input_labelwidth);
+
+       fl_set_input_return(dialog_->input_space_above, FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->input_space_below, FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->input_labelwidth,  FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
+
+       // limit these inputs to unsigned floats
+       fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
+
+       // add alignment radio buttons
+       alignment_.init(dialog_->radio_align_left,   LYX_ALIGN_LEFT);
+       alignment_.init(dialog_->radio_align_right,  LYX_ALIGN_RIGHT);
+       alignment_.init(dialog_->radio_align_block,  LYX_ALIGN_BLOCK);
+       alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
+
+       string const parspacing = _("None|DefSkip|SmallSkip|MedSkip|BigSkip|VFill|Length");
+       fl_addto_choice(dialog_->choice_space_above, parspacing.c_str());
+       fl_addto_choice(dialog_->choice_space_below, parspacing.c_str());
+
+       string const linespacing = _("Default|Single|OneHalf|Double|Custom");
+       fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
+
+       // Create the contents of the unit choices; don't include the "%" terms.
+       vector<string> units_vec = getLatexUnits();
+       vector<string>::iterator del =
+               remove_if(units_vec.begin(), units_vec.end(),
+                         bind2nd(contains_functor(), "%"));
+       units_vec.erase(del, units_vec.end());
+
+       string const units = getStringFromVector(units_vec, "|");
+       fl_addto_choice(dialog_->choice_unit_space_above, units.c_str());
+       fl_addto_choice(dialog_->choice_unit_space_below, units.c_str());
+
+       // set up the tooltips
+       string str = _("Add a separator line above this paragraph.");
+       tooltips().init(dialog_->check_line_above, str);
+       str = _("Enforce a page break above this paragraph.");
+       tooltips().init(dialog_->check_pagebreak_above, str);
+       str = _("Add additional space above this paragraph.");
+       tooltips().init(dialog_->choice_space_above, str);
+       str = _("Never suppress space (e.g. at top of page or new page).");
+       tooltips().init(dialog_->check_space_above, str);
+
+       str = _("Add a separator line below this paragraph.");
+       tooltips().init(dialog_->check_line_below, str);
+       str = _("Enforce a page break below this paragraph.");
+       tooltips().init(dialog_->check_pagebreak_below, str);
+       str = _("Add additional space below this paragraph.");
+       tooltips().init(dialog_->choice_space_below, str);
+       str = _("Never suppress space (e.g. at bottom of page or new page).");
+       tooltips().init(dialog_->check_space_below, str);
+
+       // set default unit for custom length
+       switch (lyxrc.default_papersize) {
+               case BufferParams::PAPER_DEFAULT:
+               case BufferParams::PAPER_USLETTER:
+               case BufferParams::PAPER_LEGALPAPER:
+               case BufferParams::PAPER_EXECUTIVEPAPER:
+                       defaultUnit = "in";
+                       break;
+               case BufferParams::PAPER_A3PAPER:
+               case BufferParams::PAPER_A4PAPER:
+               case BufferParams::PAPER_A5PAPER:
+               case BufferParams::PAPER_B5PAPER:
+                       defaultUnit = "cm";
+                       break;
+       }
 }
 
 
-Paragraph const * FormParagraph::getCurrentParagraph() const
+void FormParagraph::apply()
 {
-       return lv_->view()->getLyXText()->cursor.par();
+       if (!form()) return;
+
+       // spacing
+       // If a vspace choice is "Length" but there's no text in
+       // the input field, reset the choice to "None".
+       validateVSpaceWidgets(dialog_->choice_space_above,
+                             dialog_->input_space_above);
+
+       VSpace const space_above =
+               setVSpaceFromWidgets(dialog_->choice_space_above,
+                                    dialog_->input_space_above,
+                                    dialog_->choice_unit_space_above,
+                                    dialog_->check_space_above);
+
+       controller().params().spaceTop(space_above);
+
+       validateVSpaceWidgets(dialog_->choice_space_below,
+                             dialog_->input_space_below);
+
+       VSpace const space_below =
+               setVSpaceFromWidgets(dialog_->choice_space_below,
+                                    dialog_->input_space_below,
+                                    dialog_->choice_unit_space_below,
+                                    dialog_->check_space_below);
+
+       controller().params().spaceBottom(space_below);
+
+       // lines and pagebreaks
+       bool const line_above = fl_get_button(dialog_->check_line_above);
+       controller().params().lineTop(line_above);
+
+       bool const line_below = fl_get_button(dialog_->check_line_below);
+       controller().params().lineBottom(line_below);
+
+       bool const pagebreak_above =
+               fl_get_button(dialog_->check_pagebreak_above);
+       controller().params().pagebreakTop(pagebreak_above);
+
+       bool const pagebreak_below =
+               fl_get_button(dialog_->check_pagebreak_below);
+       controller().params().pagebreakBottom(pagebreak_below);
+
+
+       // alignment
+       LyXAlignment const alignment =
+               static_cast<LyXAlignment>(alignment_.get());
+       controller().params().align(alignment);
+
+       // label width
+       string const labelwidthstring =
+               getString(dialog_->input_labelwidth);
+       controller().params().labelWidthString(labelwidthstring);
+
+       // indendation
+       bool const noindent = fl_get_button(dialog_->check_noindent);
+       controller().params().noindent(noindent);
+
+       // get spacing
+       Spacing::Space linespacing = Spacing::Default;
+       string other;
+       switch (fl_get_choice(dialog_->choice_linespacing)) {
+       case 1:
+               linespacing = Spacing::Default;
+               break;
+       case 2:
+               linespacing = Spacing::Single;
+               break;
+       case 3:
+               linespacing = Spacing::Onehalf;
+               break;
+       case 4:
+               linespacing = Spacing::Double;
+               break;
+       case 5:
+               // reset to default if input is empty
+               other = getString(dialog_->input_linespacing);
+               if (!other.empty()) {
+                       linespacing = Spacing::Other;
+               } else {
+                       linespacing = Spacing::Default;
+                       fl_set_choice(dialog_->choice_linespacing, 1);
+               }
+               break;
+       }
+       Spacing const spacing(linespacing, other);
+       controller().params().spacing(spacing);
 }
 
 
-void FormParagraph::changedParagraph()
+void FormParagraph::update()
 {
-       /// Record the paragraph
-       Paragraph const * const p = getCurrentParagraph();
-       if (p == 0 || p == par_)
+       if (!dialog_.get())
                return;
 
-       // For now don't bother checking if the params are different,
-       // just activate the Apply button
-       bc().valid();
+       // label width
+       string const labelwidth = controller().params().labelWidthString();
+       fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
+       setEnabled(dialog_->input_labelwidth,
+                  labelwidth != _("Senseless with this layout!"));
+
+       // alignment
+       alignment_.set(controller().params().align());
+
+       // mark default alignment
+       LyXAlignment const default_alignment = controller().alignDefault();
+
+       string label = _("Block");
+       if (default_alignment == LYX_ALIGN_BLOCK) {
+               label += _(" (default)");
+       }
+       fl_set_object_label(dialog_->radio_align_block, label.c_str());
+       fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
+
+       label = _("Center");
+       if (default_alignment == LYX_ALIGN_CENTER) {
+               label += _(" (default)");
+       }
+       fl_set_object_label(dialog_->radio_align_center, label.c_str());
+       fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
+
+       label = _("Left");
+       if (default_alignment == LYX_ALIGN_LEFT) {
+               label += _(" (default)");
+       }
+       fl_set_object_label(dialog_->radio_align_left, label.c_str());
+       fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
+
+       label = _("Right");
+       if (default_alignment == LYX_ALIGN_RIGHT) {
+               label = _(" (default)");
+       }
+       fl_set_object_label(dialog_->radio_align_right, label.c_str());
+       fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
+
+       // Ensure that there's no crud left on the screen from this change
+       // of labels.
+       fl_redraw_form(form());
+
+       LyXAlignment alignpos = controller().alignPossible();
+       setEnabled(dialog_->radio_align_block,
+                  bool(alignpos & LYX_ALIGN_BLOCK));
+       setEnabled(dialog_->radio_align_center,
+                  bool(alignpos & LYX_ALIGN_CENTER));
+       setEnabled(dialog_->radio_align_left,
+                  bool(alignpos & LYX_ALIGN_LEFT));
+       setEnabled(dialog_->radio_align_right,
+                  bool(alignpos & LYX_ALIGN_RIGHT));
+
+       // no inset-text-owned paragraph may have pagebreaks
+       bool ininset = controller().inInset();
+       setEnabled(dialog_->check_pagebreak_above, !ininset);
+       setEnabled(dialog_->check_pagebreak_below, !ininset);
+
+       // lines, pagebreaks and indent
+       fl_set_button(dialog_->check_line_above,
+                     controller().params().lineTop());
+       fl_set_button(dialog_->check_line_below,
+                     controller().params().lineBottom());
+       fl_set_button(dialog_->check_pagebreak_above,
+                     controller().params().pagebreakTop());
+       fl_set_button(dialog_->check_pagebreak_below,
+                     controller().params().pagebreakBottom());
+       fl_set_button(dialog_->check_noindent,
+                     controller().params().noindent());
+
+       // linespacing
+       Spacing const space = controller().params().spacing();
+
+       int pos;
+       switch (space.getSpace()) {
+       case Spacing::Other:
+               pos = 5;
+               break;
+       case Spacing::Double:
+               pos = 4;
+               break;
+       case Spacing::Onehalf:
+               pos = 3;
+               break;
+       case Spacing::Single:
+               pos = 2;
+               break;
+       case Spacing::Default:
+       default:
+               pos = 1;
+               break;
+       }
+       fl_set_choice(dialog_->choice_linespacing, pos);
+
+       bool const spacing_other = space.getSpace() == Spacing::Other;
+       setEnabled(dialog_->input_linespacing, spacing_other);
+       if (spacing_other) {
+               string const sp = tostr(space.getValue());
+               fl_set_input(dialog_->input_linespacing, sp.c_str());
+       } else {
+               fl_set_input(dialog_->input_linespacing, "");
+       }
+
+       // vspace top
+       setWidgetsFromVSpace(controller().params().spaceTop(),
+                            dialog_->choice_space_above,
+                            dialog_->input_space_above,
+                            dialog_->choice_unit_space_above,
+                            dialog_->check_space_above);
+
+       // vspace bottom
+       setWidgetsFromVSpace(controller().params().spaceBottom(),
+                            dialog_->choice_space_below,
+                            dialog_->input_space_below,
+                            dialog_->choice_unit_space_below,
+                            dialog_->check_space_below);
+
+       // no indent
+       fl_set_button(dialog_->check_noindent,
+                     controller().params().noindent());
 }
 
 
-void FormParagraph::redraw()
+ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
 {
-       if( form() && form()->visible )
-               fl_redraw_form( form() );
+       // Enable input when custum length is choosen,
+       // disable 'keep' when no space is choosen
+       if (ob == dialog_->choice_space_above) {
+               bool const custom_length =
+                       fl_get_choice(dialog_->choice_space_above) == 7;
+               setEnabled(dialog_->input_space_above, custom_length);
+               setEnabled(dialog_->choice_unit_space_above, custom_length);
+
+               bool const space =
+                       fl_get_choice(dialog_->choice_space_above) != 1;
+               setEnabled(dialog_->check_space_above, space);
+
+       } else if (ob == dialog_->choice_space_below) {
+               bool const custom_length =
+                       fl_get_choice(dialog_->choice_space_below) == 7;
+               setEnabled(dialog_->input_space_below, custom_length);
+               setEnabled(dialog_->choice_unit_space_below, custom_length);
+
+               bool const space =
+                       fl_get_choice(dialog_->choice_space_below) != 1;
+               setEnabled(dialog_->check_space_below, space);
+
+       } else if (ob == dialog_->choice_linespacing) {
+               bool const custom_spacing =
+                       fl_get_choice(dialog_->choice_linespacing) == 5;
+               setEnabled(dialog_->input_linespacing, custom_spacing);
+       }
+
+       return ButtonPolicy::SMI_VALID;
 }
 
 
-FL_FORM * FormParagraph::form() const
-{
-    if (dialog_.get()) return dialog_->form;
-    return 0;
-}
-
+namespace {
 
-void FormParagraph::build()
+void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
 {
-    // the tabbed folder
-    dialog_.reset(build_paragraph());
-
-    fl_addto_choice(dialog_->choice_space_above,
-                   _(" None | Defskip | Smallskip "
-                     "| Medskip | Bigskip | VFill | Length "));
-    fl_addto_choice(dialog_->choice_space_below,
-                   _(" None | Defskip | Smallskip "
-                     "| Medskip | Bigskip | VFill | Length ")); 
-
-    fl_addto_choice(dialog_->choice_linespacing,
-                    _(" Default | Single | OneHalf | Double | Other "));
-    fl_set_input_return(dialog_->input_space_above, FL_RETURN_CHANGED);
-    fl_set_input_return(dialog_->input_space_below, FL_RETURN_CHANGED);
-    fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
-    fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
-    fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
-    fl_set_input_filter(dialog_->input_space_above, fl_float_filter);
-    fl_set_input_filter(dialog_->input_space_below, fl_float_filter);
-
-    // Create the contents of the unit choices
-    // Don't include the "%" terms...
-    std::vector<string> units_vec = getLatexUnits();
-    for (std::vector<string>::iterator it = units_vec.begin();
-       it != units_vec.end(); ++it) {
-       if (contains(*it, "%"))
-               it = units_vec.erase(it, it+1) - 1;
-    }
-    string units = getStringFromVector(units_vec, "|");
-
-    fl_addto_choice(dialog_->choice_value_space_above,  units.c_str());
-    fl_addto_choice(dialog_->choice_value_space_below, units.c_str());
-
-    // Manage the ok, apply, restore and cancel/close buttons
-    bc_.setOK(dialog_->button_ok);
-    bc_.setApply(dialog_->button_apply);
-    bc_.setCancel(dialog_->button_cancel);
-    bc_.setRestore(dialog_->button_restore);
-
-    bc_.addReadOnly (dialog_->group_radio_alignment);
-    // bc_.addReadOnly (dialog_->radio_align_right);
-    // bc_.addReadOnly (dialog_->radio_align_left);
-    // bc_.addReadOnly (dialog_->radio_align_block);
-    // bc_.addReadOnly (dialog_->radio_align_center);
-    bc_.addReadOnly (dialog_->check_lines_top);
-    bc_.addReadOnly (dialog_->check_lines_bottom);
-    bc_.addReadOnly (dialog_->check_pagebreaks_top);
-    bc_.addReadOnly (dialog_->check_pagebreaks_bottom);
-    bc_.addReadOnly (dialog_->choice_space_above);
-    bc_.addReadOnly (dialog_->input_space_above);
-    bc_.addReadOnly (dialog_->check_space_above);
-    bc_.addReadOnly (dialog_->choice_space_below);
-    bc_.addReadOnly (dialog_->input_space_below);
-    bc_.addReadOnly (dialog_->check_space_below);
-    bc_.addReadOnly (dialog_->choice_linespacing);
-    bc_.addReadOnly (dialog_->input_linespacing); 
-    bc_.addReadOnly (dialog_->check_noindent);
-    bc_.addReadOnly (dialog_->input_labelwidth);
-}
+       // Paranoia check!
+       lyx::Assert(choice_type  && choice_type->objclass  == FL_CHOICE &&
+                   input_length && input_length->objclass == FL_INPUT);
 
+       if (fl_get_choice(choice_type) != 7)
+               return;
 
-void FormParagraph::apply()
-{
-    if (!lv_->view()->available() || !dialog_.get())
-       return;
-
-    VSpace space_top, space_bottom;
-    LyXAlignment align;
-    string labelwidthstring;
-    bool noindent;
-
-    // If a vspace kind is "Length" but there's no text in
-    // the input field, reset the kind to "None". 
-    if ((fl_get_choice (dialog_->choice_space_above) == 7) &&
-       !*(fl_get_input (dialog_->input_space_above)))
-    {
-       fl_set_choice (dialog_->choice_space_above, 1);
-    }
-    if ((fl_get_choice (dialog_->choice_space_below) == 7) &&
-       !*(fl_get_input (dialog_->input_space_below)))
-    {
-       fl_set_choice (dialog_->choice_space_below, 1);
-    }
-   
-    bool line_top = fl_get_button(dialog_->check_lines_top);
-    bool line_bottom = fl_get_button(dialog_->check_lines_bottom);
-    bool pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
-    bool pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
-    
-    switch (fl_get_choice (dialog_->choice_space_above)) {
-    case 1:
-       space_top = VSpace(VSpace::NONE);
-       break;
-    case 2:
-       space_top = VSpace(VSpace::DEFSKIP);
-       break;
-    case 3:
-       space_top = VSpace(VSpace::SMALLSKIP);
-       break;
-    case 4:
-       space_top = VSpace(VSpace::MEDSKIP);
-       break;
-    case 5:
-       space_top = VSpace(VSpace::BIGSKIP);
-       break;
-    case 6:
-       space_top = VSpace(VSpace::VFILL);
-       break;
-    case 7:
-    {
-           string const length =
-                   getLengthFromWidgets(dialog_->input_space_above,
-                                        dialog_->choice_value_space_above);
-       space_top =
-               VSpace(LyXGlueLength(length));
-       break;
-    }
-    }
-
-    if (fl_get_button (dialog_->check_space_above))
-       space_top.setKeep (true);
-    switch (fl_get_choice (dialog_->choice_space_below)) {
-    case 1:
-       space_bottom = VSpace(VSpace::NONE);
-       break;
-    case 2:
-       space_bottom = VSpace(VSpace::DEFSKIP);
-       break;
-    case 3:
-       space_bottom = VSpace(VSpace::SMALLSKIP);
-       break;
-    case 4:
-       space_bottom = VSpace(VSpace::MEDSKIP);
-       break;
-    case 5:
-       space_bottom = VSpace(VSpace::BIGSKIP);
-       break;
-    case 6:
-       space_bottom = VSpace(VSpace::VFILL);
-       break;
-    case 7:
-       string const length =
-               getLengthFromWidgets(dialog_->input_space_below,
-               dialog_->choice_value_space_below);
-       space_bottom = VSpace(LyXGlueLength(length));
-       break;
-    }
-    if (fl_get_button (dialog_->check_space_below))
-       space_bottom.setKeep (true);
-
-    if (fl_get_button(dialog_->radio_align_left))
-       align = LYX_ALIGN_LEFT;
-    else if (fl_get_button(dialog_->radio_align_right))
-       align = LYX_ALIGN_RIGHT;
-    else if (fl_get_button(dialog_->radio_align_center))
-       align = LYX_ALIGN_CENTER;
-    else 
-       align = LYX_ALIGN_BLOCK;
-   
-    labelwidthstring = fl_get_input(dialog_->input_labelwidth);
-    noindent = fl_get_button(dialog_->check_noindent);
-    Spacing::Space linespacing = Spacing::Default;
-    string other_linespacing;
-    switch (fl_get_choice(dialog_->choice_linespacing)) {
-        case 1: linespacing = Spacing::Default; break;
-        case 2: linespacing = Spacing::Single; break;
-        case 3: linespacing = Spacing::Onehalf; break;
-        case 4: linespacing = Spacing::Double; break;
-        case 5:
-            linespacing = Spacing::Other;
-            other_linespacing = fl_get_input(dialog_->input_linespacing);
-            break;
-    }
-
-    Spacing const spacing(linespacing, other_linespacing);
-    LyXText * text(lv_->view()->getLyXText());
-    text->setParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
-                      pagebreak_bottom, space_top, space_bottom, spacing,
-                       align, labelwidthstring, noindent);
-
-
-    // Actually apply these settings
-    lv_->view()->update(text, 
-                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
-    lv_->buffer()->markDirty();
-    setMinibuffer(lv_, _("Paragraph layout set"));
+       // If a vspace kind is "Length" but there's no text in
+       // the input field, reset the kind to "None".
+       string const input = rtrim(getString(input_length));
+       if (input.empty())
+               fl_set_choice(choice_type, 1);
 }
 
 
-void FormParagraph::update()
+VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
+                                 FL_OBJECT * input_length,
+                                 FL_OBJECT * choice_length,
+                                 FL_OBJECT * check_keep)
 {
-    if (!dialog_.get())
-        return;
-
-    // Do this first; some objects may be de/activated subsequently.
-    bc_.readOnly(lv_->buffer()->isReadonly());
-
-    Buffer * buf = lv_->view()->buffer();
-
-    /// Record the paragraph
-    par_ = getCurrentParagraph();
-
-    fl_set_input(dialog_->input_labelwidth,
-                par_->getLabelWidthString().c_str());
-    setEnabled(dialog_->input_labelwidth,
-              (par_->getLabelWidthString() != _("Senseless with this layout!")));
-
-    fl_set_button(dialog_->radio_align_right, 0);
-    fl_set_button(dialog_->radio_align_left, 0);
-    fl_set_button(dialog_->radio_align_center, 0);
-    fl_set_button(dialog_->radio_align_block, 0);
-
-    int align = par_->getAlign();
-    if (align == LYX_ALIGN_LAYOUT)
-       align = textclasslist.Style(buf->params.textclass,
-                                   par_->getLayout()).align;
-
-    switch (align) {
-    case LYX_ALIGN_RIGHT:
-       fl_set_button(dialog_->radio_align_right, 1);
-       break;
-    case LYX_ALIGN_LEFT:
-       fl_set_button(dialog_->radio_align_left, 1);
-       break;
-    case LYX_ALIGN_CENTER:
-       fl_set_button(dialog_->radio_align_center, 1);
-       break;
-    default:
-       fl_set_button(dialog_->radio_align_block, 1);
-       break;
-    }
-
-    LyXAlignment alignpos =
-           textclasslist.Style(buf->params.textclass,
-                               par_->getLayout()).alignpossible;
-
-    setEnabled(dialog_->radio_align_block,  bool(alignpos & LYX_ALIGN_BLOCK));
-    setEnabled(dialog_->radio_align_center, bool(alignpos & LYX_ALIGN_CENTER));
-    setEnabled(dialog_->radio_align_left,   bool(alignpos & LYX_ALIGN_LEFT));
-    setEnabled(dialog_->radio_align_right,  bool(alignpos & LYX_ALIGN_RIGHT));
-    
-    // no inset-text-owned paragraph may have pagebreaks
-    setEnabled(dialog_->check_pagebreaks_top, !par_->inInset());
-    setEnabled(dialog_->check_pagebreaks_bottom, !par_->inInset());
-
-    fl_set_button(dialog_->check_lines_top,
-                 par_->params().lineTop());
-    fl_set_button(dialog_->check_lines_bottom,
-                 par_->params().lineBottom());
-    fl_set_button(dialog_->check_pagebreaks_top,
-                 par_->params().pagebreakTop());
-    fl_set_button(dialog_->check_pagebreaks_bottom,
-                 par_->params().pagebreakBottom());
-    fl_set_button(dialog_->check_noindent,
-                 par_->params().noindent());
-
-    int linespacing;
-    Spacing const space = par_->params().spacing();
-
-    switch (space.getSpace()) {
-        default: linespacing = 1; break;
-        case Spacing::Single: linespacing = 2; break;
-        case Spacing::Onehalf: linespacing = 3; break;
-        case Spacing::Double: linespacing = 4; break;
-        case Spacing::Other: linespacing = 5; break;
-    }
-    fl_set_choice(dialog_->choice_linespacing, linespacing);
-    if (space.getSpace() == Spacing::Other) {
-        string const sp = tostr(space.getValue());
-        fl_set_input(dialog_->input_linespacing, sp.c_str());
-        setEnabled(dialog_->input_linespacing, true);
-    } else {
-        fl_set_input(dialog_->input_linespacing, "");
-        setEnabled(dialog_->input_linespacing, false);
-    }
-
-    fl_set_input (dialog_->input_space_above, "");
-
-    setEnabled(dialog_->input_space_above, false);
-    setEnabled(dialog_->choice_value_space_above, false);
-    switch (par_->params().spaceTop().kind()) {
-    case VSpace::NONE:
-       fl_set_choice (dialog_->choice_space_above, 1);
-       break;
-    case VSpace::DEFSKIP:
-       fl_set_choice (dialog_->choice_space_above, 2);
-       break;
-    case VSpace::SMALLSKIP:
-       fl_set_choice (dialog_->choice_space_above, 3);
-       break;
-    case VSpace::MEDSKIP:
-       fl_set_choice (dialog_->choice_space_above, 4);
-       break;
-    case VSpace::BIGSKIP:
-       fl_set_choice (dialog_->choice_space_above, 5);
-       break;
-    case VSpace::VFILL:
-       fl_set_choice (dialog_->choice_space_above, 6);
-       break;
-    case VSpace::LENGTH:
-    {
-           setEnabled(dialog_->input_space_above, true);
-           setEnabled(dialog_->choice_value_space_above, true);
-           string const default_unit = "cm";
-           string const length = par_->params().spaceTop().length().asString();
-           updateWidgetsFromLengthString(dialog_->input_space_above,
-                                         dialog_->choice_value_space_above,
-                                         length, default_unit);
-           break;
-    }
-    }
-    
-    fl_set_button (dialog_->check_space_above,
-                  par_->params().spaceTop().keep());
-    fl_set_input (dialog_->input_space_below, "");
-
-    setEnabled(dialog_->input_space_below, false);
-    setEnabled(dialog_->choice_value_space_below, false);
-    switch (par_->params().spaceBottom().kind()) {
-    case VSpace::NONE:
-       fl_set_choice (dialog_->choice_space_below, 1);
-       break;
-    case VSpace::DEFSKIP:
-       fl_set_choice (dialog_->choice_space_below, 2);
-       break;
-    case VSpace::SMALLSKIP:
-       fl_set_choice (dialog_->choice_space_below, 3);
-       break;
-    case VSpace::MEDSKIP:
-       fl_set_choice (dialog_->choice_space_below, 4);
-       break;
-    case VSpace::BIGSKIP:
-       fl_set_choice (dialog_->choice_space_below, 5);
-       break;
-    case VSpace::VFILL:
-       fl_set_choice (dialog_->choice_space_below, 6);
-       break;
-    case VSpace::LENGTH:
-    {
-           setEnabled(dialog_->input_space_below, true);
-           setEnabled(dialog_->choice_value_space_below, true);
-           string const default_unit = "cm";
-           string const length =
-                   par_->params().spaceBottom().length().asString();
-           updateWidgetsFromLengthString(dialog_->input_space_below,
-                                         dialog_->choice_value_space_below,
-                                         length, default_unit);
-           break;
-    }
-    }
-
-    fl_set_button(dialog_->check_space_below,
-                  par_->params().spaceBottom().keep());
-    fl_set_button(dialog_->check_noindent,
-                 par_->params().noindent());
+       // Paranoia check!
+       lyx::Assert(choice_type   && choice_type->objclass   == FL_CHOICE &&
+                   input_length  && input_length->objclass  == FL_INPUT &&
+                   choice_length && choice_length->objclass == FL_CHOICE &&
+                   check_keep    && check_keep->objclass    == FL_CHECKBUTTON);
+
+       VSpace space;
+       switch (fl_get_choice(choice_type)) {
+       case 1:
+               space = VSpace(VSpace::NONE);
+               break;
+       case 2:
+               space = VSpace(VSpace::DEFSKIP);
+               break;
+       case 3:
+               space = VSpace(VSpace::SMALLSKIP);
+               break;
+       case 4:
+               space = VSpace(VSpace::MEDSKIP);
+               break;
+       case 5:
+               space = VSpace(VSpace::BIGSKIP);
+               break;
+       case 6:
+               space = VSpace(VSpace::VFILL);
+               break;
+       case 7:
+               {
+               string const length =
+                       getLengthFromWidgets(input_length, choice_length);
+               space = VSpace(LyXGlueLength(length));
+               break;
+               }
+       }
+
+       if (fl_get_button(check_keep))
+               space.setKeep(true);
+
+       return space;
 }
 
 
-bool FormParagraph::input(FL_OBJECT * ob, long)
+void setWidgetsFromVSpace(VSpace const & space,
+                         FL_OBJECT * choice_type,
+                         FL_OBJECT * input_length,
+                         FL_OBJECT * choice_length,
+                         FL_OBJECT * check_keep)
 {
-    bool valid = true; 
-
-    fl_hide_object(dialog_->text_warning);
-
-    // First check the buttons which are exclusive and you have to
-    // check only the actuall de/activated button.
-    //
-    // "Synchronize" the choices and input fields, making it
-    // impossible to commit senseless data.
-
-    if (ob == dialog_->choice_space_above) {
-        if (fl_get_choice (dialog_->choice_space_above) != 7) {
-            fl_set_input (dialog_->input_space_above, "");
-            setEnabled (dialog_->input_space_above, false);
-           setEnabled (dialog_->choice_value_space_above, false);
-        } else {
-            setEnabled (dialog_->input_space_above, !lv_->buffer()->isReadonly());
-           setEnabled (dialog_->choice_value_space_above, !lv_->buffer()->isReadonly());
-           int const default_unit = 8;
-           if (strip(fl_get_input(dialog_->input_space_above)).empty())
-                       fl_set_choice(dialog_->choice_value_space_above,
-                                     default_unit);
-        }
-    }
-    if (ob == dialog_->choice_space_below) {
-        if (fl_get_choice (dialog_->choice_space_below) != 7) {
-            fl_set_input (dialog_->input_space_below, "");
-            setEnabled (dialog_->input_space_below, false);
-           setEnabled (dialog_->choice_value_space_below, false);
-        } else {
-            setEnabled (dialog_->input_space_below, !lv_->buffer()->isReadonly());
-           setEnabled (dialog_->choice_value_space_below, !lv_->buffer()->isReadonly());
-           int const default_unit = 8;
-           if (strip(fl_get_input(dialog_->input_space_below)).empty())
-                       fl_set_choice(dialog_->choice_value_space_below,
-                                     default_unit);
-        }
-    }
-    if (fl_get_choice (dialog_->choice_linespacing) == 5)
-        setEnabled (dialog_->input_linespacing, true);
-    else {
-        setEnabled (dialog_->input_linespacing, false);
-        fl_set_input (dialog_->input_linespacing, "");
-    }
-
-    double spacing(strToDbl(fl_get_input(dialog_->input_linespacing)));
-
-    if (fl_get_choice (dialog_->choice_linespacing) == 5
-        && int(spacing) == 0)
-        valid = false;
-
-    return valid;
+       // Paranoia check!
+       lyx::Assert(choice_type   && choice_type->objclass   == FL_CHOICE &&
+                   input_length  && input_length->objclass  == FL_INPUT &&
+                   choice_length && choice_length->objclass == FL_CHOICE &&
+                   check_keep    && check_keep->objclass    == FL_CHECKBUTTON);
+
+       fl_set_button(check_keep, space.keep());
+
+       int pos = 1;
+       switch (space.kind()) {
+       case VSpace::NONE:
+               pos = 1;
+               break;
+       case VSpace::DEFSKIP:
+               pos = 2;
+               break;
+       case VSpace::SMALLSKIP:
+               pos = 3;
+               break;
+       case VSpace::MEDSKIP:
+               pos = 4;
+               break;
+       case VSpace::BIGSKIP:
+               pos = 5;
+               break;
+       case VSpace::VFILL:
+               pos = 6;
+               break;
+       case VSpace::LENGTH:
+               pos = 7;
+               break;
+       }
+       fl_set_choice(choice_type, pos);
+
+       bool const custom_vspace = space.kind() == VSpace::LENGTH;
+       setEnabled(input_length, custom_vspace);
+       setEnabled(choice_length, custom_vspace);
+       if (custom_vspace) {
+               string const length = space.length().asString();
+               updateWidgetsFromLengthString(input_length, choice_length,
+                                             length, defaultUnit);
+       } else {
+               bool const no_vspace = space.kind() == VSpace::NONE;
+               setEnabled(check_keep, !no_vspace);
+               fl_set_input(input_length, "");
+               fl_set_choice_text(choice_length, defaultUnit.c_str());
+       }
 }
+
+} // namespace anon