]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormParagraph.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / FormParagraph.C
index ef51c02e2761b00cf17314aac01ddcb1f89ad0c8..61c814a96ec74865ef504b64afb3a40c9d4d61e0 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
  *
- *======================================================*/
+ * Full author contact details are available in file CREDITS
+ */
 
 #include <config.h>
 
-#ifdef __GNUG_
+#ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include FORMS_H_LOCATION
 
 #include "FormParagraph.h"
-#include "form_paragraph.h"
-#include "Dialogs.h"
-#include "Liason.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "lyxtext.h"
+#include "forms/form_paragraph.h"
+#include "ControlParagraph.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 "gettext.h"
+#include "xformsBC.h"
+#include "layout.h" // LyXAlignment
+
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+#include FORMS_H_LOCATION
+
+#include <functional>
+
+using std::vector;
+using std::bind2nd;
+using std::remove_if;
 
-using Liason::setMinibuffer;
-using SigC::slot;
+typedef FormCB<ControlParagraph, FormDB<FD_paragraph> > base_class;
 
+FormParagraph::FormParagraph()
+       : base_class(_("Paragraph Layout"), false)
+{}
 
-FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
-       : FormBaseBD(lv, d, _("Paragraph Layout"))
+void FormParagraph::build()
 {
-    // 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->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
+       // the tabbed folder
+       dialog_.reset(build_paragraph(this));
+
+       // Allow the base class to control messages
+       setMessageWidget(dialog_->text_warning);
+
+       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 | Custom "));
+
+       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);
+
+       setPrehandler(dialog_->input_space_above);
+       setPrehandler(dialog_->input_space_below);
+       setPrehandler(dialog_->input_labelwidth);
+       setPrehandler(dialog_->input_linespacing);
+
+       // 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 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_close);
+       bc().setRestore(dialog_->button_restore);
+
+       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);
 }
 
+namespace {
 
-void FormParagraph::redraw()
+VSpace setVSpaceFromWidgets(FL_OBJECT * choice_type,
+                           FL_OBJECT * input_length,
+                           FL_OBJECT * choice_length,
+                           FL_OBJECT * check_keep)
 {
-       if( form() && form()->visible )
-               fl_redraw_form( form() );
-       else
+       // 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;
+}
+
+void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
+{
+       // 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;
 
-       FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
-       if (outer_form && outer_form->visible)
-               fl_redraw_form( outer_form );
+       // 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);
 }
 
+} // namespace anon
 
-FL_FORM * FormParagraph::form() const
+void FormParagraph::apply()
 {
-    if (dialog_.get()) return dialog_->form;
-    return 0;
+       if (!form()) return;
+
+       /* spacing */
+       // If a vspace kind is "Length" but there's no text in
+       // the input field, reset the kind to "None".
+       validateVSpaceWidgets(dialog_->choice_space_above,
+                             dialog_->input_space_above);
+
+       VSpace const space_top =
+               setVSpaceFromWidgets(dialog_->choice_space_above,
+                                    dialog_->input_space_above,
+                                    dialog_->choice_value_space_above,
+                                    dialog_->check_space_above);
+
+       controller().params().spaceTop(space_top);
+
+       validateVSpaceWidgets(dialog_->choice_space_below,
+                             dialog_->input_space_below);
+
+       VSpace const space_bottom =
+               setVSpaceFromWidgets(dialog_->choice_space_below,
+                                    dialog_->input_space_below,
+                                    dialog_->choice_value_space_below,
+                                    dialog_->check_space_below);
+
+       controller().params().spaceBottom(space_bottom);
+
+       /* lines and pagebreaks */
+       bool const line_top = fl_get_button(dialog_->check_lines_top);
+       controller().params().lineTop(line_top);
+
+       bool const line_bottom = fl_get_button(dialog_->check_lines_bottom);
+       controller().params().lineBottom(line_bottom);
+
+       bool const pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
+       controller().params().pagebreakTop(pagebreak_top);
+
+       bool const pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
+       controller().params().pagebreakBottom(pagebreak_bottom);
+
+
+       /* alignment */
+       LyXAlignment align;
+       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;
+       controller().params().align(align);
+
+       /* 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:
+               linespacing = Spacing::Other;
+               other = getString(dialog_->input_linespacing);
+               break;
+       }
+
+       Spacing const spacing(linespacing, other);
+       controller().params().spacing(spacing);
+
 }
 
+namespace {
 
-void FormParagraph::build()
+void setWidgetsFromVSpace(VSpace const & space,
+                         FL_OBJECT * choice_type,
+                         FL_OBJECT * input_length,
+                         FL_OBJECT * choice_length,
+                         FL_OBJECT * check_keep)
 {
-    // the tabbed folder
-    dialog_.reset(build_tabbed_paragraph());
-
-    // 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);
-
-    // the general paragraph data form
-    general_.reset(build_paragraph_general());
-
-    fl_addto_choice(general_->choice_space_above,
-                   _(" None | Defskip | Smallskip "
-                     "| Medskip | Bigskip | VFill | Length "));
-    fl_addto_choice(general_->choice_space_below,
-                   _(" None | Defskip | Smallskip "
-                     "| Medskip | Bigskip | VFill | Length ")); 
-
-    fl_set_input_return(general_->input_space_above, FL_RETURN_CHANGED);
-    fl_set_input_return(general_->input_space_below, FL_RETURN_CHANGED);
-    fl_set_input_return(general_->input_labelwidth, FL_RETURN_CHANGED);
-
-    bc_.addReadOnly (general_->radio_align_right);
-    bc_.addReadOnly (general_->radio_align_left);
-    bc_.addReadOnly (general_->radio_align_block);
-    bc_.addReadOnly (general_->radio_align_center);
-    bc_.addReadOnly (general_->check_lines_top);
-    bc_.addReadOnly (general_->check_lines_bottom);
-    bc_.addReadOnly (general_->check_pagebreaks_top);
-    bc_.addReadOnly (general_->check_pagebreaks_bottom);
-    bc_.addReadOnly (general_->choice_space_above);
-    bc_.addReadOnly (general_->input_space_above);
-    bc_.addReadOnly (general_->check_space_above);
-    bc_.addReadOnly (general_->choice_space_below);
-    bc_.addReadOnly (general_->input_space_below);
-    bc_.addReadOnly (general_->check_space_below);
-    bc_.addReadOnly (general_->check_noindent);
-    bc_.addReadOnly (general_->input_labelwidth);
-
-    // now make them fit together
-    fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
+       // 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_input(input_length, "");
+       setEnabled(input_length,  false);
+       setEnabled(choice_length, false);
+
+       switch (space.kind()) {
+       case VSpace::NONE:
+               fl_set_choice(choice_type, 1);
+               break;
+       case VSpace::DEFSKIP:
+               fl_set_choice(choice_type, 2);
+               break;
+       case VSpace::SMALLSKIP:
+               fl_set_choice(choice_type, 3);
+               break;
+       case VSpace::MEDSKIP:
+               fl_set_choice(choice_type, 4);
+               break;
+       case VSpace::BIGSKIP:
+               fl_set_choice(choice_type, 5);
+               break;
+       case VSpace::VFILL:
+               fl_set_choice(choice_type, 6);
+               break;
+       case VSpace::LENGTH:
+       {
+               fl_set_choice(choice_type, 7);
+
+               setEnabled(input_length,  true);
+               setEnabled(choice_length, true);
+
+               bool const metric = lyxrc.default_papersize > 3;
+               string const default_unit = metric ? "cm" : "in";
+               string const length = space.length().asString();
+
+               updateWidgetsFromLengthString(input_length, choice_length,
+                                             length, default_unit);
+               break;
+       }
+       }
+
+       fl_set_button(check_keep, space.keep());
 }
 
+} // namespace anon
 
-void FormParagraph::apply()
+void FormParagraph::update()
 {
-    if (!lv_->view()->available() || !dialog_.get())
-       return;
-
-    general_apply();
+       if (!dialog_.get())
+               return;
 
-    lv_->view()->update(lv_->view()->text, 
-                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
-    lv_->buffer()->markDirty();
-    setMinibuffer(lv_, _("Paragraph layout set"));
+       /* label width */
+       string labelwidth = controller().params().labelWidthString();
+       fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
+       setEnabled(dialog_->input_labelwidth,
+                  labelwidth != _("Senseless with this layout!"));
+
+       /* alignment */
+       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);
+
+       LyXAlignment align = controller().params().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 = 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_pagebreaks_top, !ininset);
+       setEnabled(dialog_->check_pagebreaks_bottom, !ininset);
+
+       /* lines, pagebreaks and indent */
+       fl_set_button(dialog_->check_lines_top,
+                     controller().params().lineTop());
+       fl_set_button(dialog_->check_lines_bottom,
+                     controller().params().lineBottom());
+       fl_set_button(dialog_->check_pagebreaks_top,
+                     controller().params().pagebreakTop());
+       fl_set_button(dialog_->check_pagebreaks_bottom,
+                     controller().params().pagebreakBottom());
+       fl_set_button(dialog_->check_noindent,
+                     controller().params().noindent());
+
+       /* linespacing */
+       int linespacing;
+       Spacing const space = controller().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);
+       }
+
+       /* vspace top */
+       setWidgetsFromVSpace(controller().params().spaceTop(),
+                            dialog_->choice_space_above,
+                            dialog_->input_space_above,
+                            dialog_->choice_value_space_above,
+                            dialog_->check_space_above);
+
+       /* vspace bottom */
+       setWidgetsFromVSpace(controller().params().spaceBottom(),
+                            dialog_->choice_space_below,
+                            dialog_->input_space_below,
+                            dialog_->choice_value_space_below,
+                            dialog_->check_space_below);
+
+       /* no indent */
+       fl_set_button(dialog_->check_noindent,
+                     controller().params().noindent());
 }
 
+namespace {
 
-void FormParagraph::update()
+void synchronizeSpaceWidgets(FL_OBJECT * choice_type,
+                            FL_OBJECT * input_length,
+                            FL_OBJECT * choice_length)
 {
-    if (!dialog_.get())
-        return;
+       // 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);
 
-    // Do this first; some objects may be de/activated subsequently.
-    bc_.readOnly(lv_->buffer()->isReadonly());
+       if (fl_get_choice(choice_type) != 7) {
+               fl_set_input(input_length, "");
+               setEnabled(input_length, false);
+               setEnabled(choice_length, false);
 
-    general_update();
-}
+       } else {
+               setEnabled(input_length, true);
+               setEnabled(choice_length, true);
 
+               string const length = getString(input_length);
 
-void FormParagraph::general_apply()
-{
-    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 (general_->choice_space_above) == 7) &&
-       !*(fl_get_input (general_->input_space_above)))
-    {
-       fl_set_choice (general_->choice_space_above, 1);
-    }
-    if ((fl_get_choice (general_->choice_space_below) == 7) &&
-       !*(fl_get_input (general_->input_space_below)))
-    {
-       fl_set_choice (general_->choice_space_below, 1);
-    }
-   
-    bool line_top = fl_get_button(general_->check_lines_top);
-    bool line_bottom = fl_get_button(general_->check_lines_bottom);
-    bool pagebreak_top = fl_get_button(general_->check_pagebreaks_top);
-    bool pagebreak_bottom = fl_get_button(general_->check_pagebreaks_bottom);
-    
-    switch (fl_get_choice (general_->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:
-       space_top =
-               VSpace(LyXGlueLength(fl_get_input(general_->input_space_above)));
-       break;
-    }
-    if (fl_get_button (general_->check_space_above))
-       space_top.setKeep (true);
-    switch (fl_get_choice (general_->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:
-       space_bottom =
-               VSpace(LyXGlueLength(fl_get_input(general_->input_space_below)));
-       break;
-    }
-    if (fl_get_button (general_->check_space_below))
-       space_bottom.setKeep (true);
-
-    if (fl_get_button(general_->radio_align_left))
-       align = LYX_ALIGN_LEFT;
-    else if (fl_get_button(general_->radio_align_right))
-       align = LYX_ALIGN_RIGHT;
-    else if (fl_get_button(general_->radio_align_center))
-       align = LYX_ALIGN_CENTER;
-    else 
-       align = LYX_ALIGN_BLOCK;
-   
-    labelwidthstring = fl_get_input(general_->input_labelwidth);
-    noindent = fl_get_button(general_->check_noindent);
-
-    LyXText * text = 0;
-    if (lv_->view()->theLockingInset())
-       text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
-    if (!text)
-       text = lv_->view()->text;
-    text->SetParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
-                      pagebreak_bottom, space_top, space_bottom, align, 
-                      labelwidthstring, noindent);
-}
+               if (rtrim(length).empty()) {
+                       bool const metric = lyxrc.default_papersize > 3;
+                       int const default_unit = metric ? 8 : 9;
 
+                       fl_set_choice(choice_length, default_unit);
+               }
+       }
+}
 
-void FormParagraph::general_update()
+bool validSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
 {
-    if (!general_.get())
-        return;
-
-    Buffer * buf = lv_->view()->buffer();
-    LyXText * text = 0;
-
-    if (lv_->view()->theLockingInset())
-       text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
-    if (!text)
-       text = lv_->view()->text;
-
-    fl_set_input(general_->input_labelwidth,
-                text->cursor.par()->GetLabelWidthString().c_str());
-    fl_set_button(general_->radio_align_right, 0);
-    fl_set_button(general_->radio_align_left, 0);
-    fl_set_button(general_->radio_align_center, 0);
-    fl_set_button(general_->radio_align_block, 0);
-
-    int align = text->cursor.par()->GetAlign();
-    if (align == LYX_ALIGN_LAYOUT)
-       align = textclasslist.Style(buf->params.textclass,
-                                   text->cursor.par()->GetLayout()).align;
-
-    switch (align) {
-    case LYX_ALIGN_RIGHT:
-       fl_set_button(general_->radio_align_right, 1);
-       break;
-    case LYX_ALIGN_LEFT:
-       fl_set_button(general_->radio_align_left, 1);
-       break;
-    case LYX_ALIGN_CENTER:
-       fl_set_button(general_->radio_align_center, 1);
-       break;
-    default:
-       fl_set_button(general_->radio_align_block, 1);
-       break;
-    }
-
-    LyXAlignment alignpos =
-           textclasslist.Style(buf->params.textclass,
-                               text->cursor.par()->GetLayout()).alignpossible;
-
-    setEnabled(general_->radio_align_block,  bool(alignpos & LYX_ALIGN_BLOCK));
-    setEnabled(general_->radio_align_center, bool(alignpos & LYX_ALIGN_CENTER));
-    setEnabled(general_->radio_align_left,   bool(alignpos & LYX_ALIGN_LEFT));
-    setEnabled(general_->radio_align_right,  bool(alignpos & LYX_ALIGN_RIGHT));
-    
-    fl_set_button(general_->check_lines_top,
-                 text->cursor.par()->params.lineTop());
-    fl_set_button(general_->check_lines_bottom,
-                 text->cursor.par()->params.lineBottom());
-    fl_set_button(general_->check_pagebreaks_top,
-                 text->cursor.par()->params.pagebreakTop());
-    fl_set_button(general_->check_pagebreaks_bottom,
-                 text->cursor.par()->params.pagebreakBottom());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->params.noindent());
-
-    fl_set_input (general_->input_space_above, "");
-
-    switch (text->cursor.par()->params.spaceTop().kind()) {
-    case VSpace::NONE:
-       fl_set_choice (general_->choice_space_above, 1);
-       break;
-    case VSpace::DEFSKIP:
-       fl_set_choice (general_->choice_space_above, 2);
-       break;
-    case VSpace::SMALLSKIP:
-       fl_set_choice (general_->choice_space_above, 3);
-       break;
-    case VSpace::MEDSKIP:
-       fl_set_choice (general_->choice_space_above, 4);
-       break;
-    case VSpace::BIGSKIP:
-       fl_set_choice (general_->choice_space_above, 5);
-       break;
-    case VSpace::VFILL:
-       fl_set_choice (general_->choice_space_above, 6);
-       break;
-    case VSpace::LENGTH:
-       fl_set_choice (general_->choice_space_above, 7);
-       fl_set_input(general_->input_space_above, text->cursor.par()->
-                    params.spaceTop().length().asString().c_str());
-       break;
-    }
-    
-    fl_set_button (general_->check_space_above,
-                  text->cursor.par()->params.spaceTop().keep());
-    fl_set_input (general_->input_space_below, "");
-
-    switch (text->cursor.par()->params.spaceBottom().kind()) {
-    case VSpace::NONE:
-       fl_set_choice (general_->choice_space_below, 1);
-       break;
-    case VSpace::DEFSKIP:
-       fl_set_choice (general_->choice_space_below, 2);
-       break;
-    case VSpace::SMALLSKIP:
-       fl_set_choice (general_->choice_space_below, 3);
-       break;
-    case VSpace::MEDSKIP:
-       fl_set_choice (general_->choice_space_below, 4);
-       break;
-    case VSpace::BIGSKIP:
-       fl_set_choice (general_->choice_space_below, 5);
-       break;
-    case VSpace::VFILL:
-       fl_set_choice (general_->choice_space_below, 6);
-       break;
-    case VSpace::LENGTH:
-       fl_set_choice (general_->choice_space_below, 7);
-        fl_set_input(general_->input_space_below, text->cursor.par()->
-                    params.spaceBottom().length().asString().c_str());
-       break;
-    }
-    fl_set_button(general_->check_space_below,
-                  text->cursor.par()->params.spaceBottom().keep());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->params.noindent());
+       // 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 true;
+
+       string const input = getString(input_length);
+       return (input.empty() ||
+               isValidGlueLength(input) ||
+               isStrDbl(input));
 }
 
+} // namespace anon
 
-bool FormParagraph::input(FL_OBJECT * ob, long)
+ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
 {
-    bool ret = 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.
-    //
-    // general form first
-    //
-    // "Synchronize" the choices and input fields, making it
-    // impossible to commit senseless data.
-
-    if (fl_get_choice (general_->choice_space_above) != 7)
-        fl_set_input (general_->input_space_above, "");
-
-    if (fl_get_choice (general_->choice_space_below) != 7)
-        fl_set_input (general_->input_space_below, "");
-
-    //
-    // first the general form
-    //
-    string input = fl_get_input (general_->input_space_above);
-    bool invalid = false;
-       
-    if (fl_get_choice(general_->choice_space_above)==7)
-        invalid = !input.empty() && !isValidGlueLength(input);
-
-    input = fl_get_input (general_->input_space_below);
-
-    if (fl_get_choice(general_->choice_space_below)==7)
-        invalid = invalid || (!input.empty() && !isValidGlueLength(input));
-    
-    if (ob == general_->input_space_above || ob == general_->input_space_below) {
-        if (invalid) {
-            fl_set_object_label(dialog_->text_warning,
-                _("Warning: Invalid Length (valid example: 10mm)"));
-            fl_show_object(dialog_->text_warning);
-            return false;
-        } else {
-            fl_hide_object(dialog_->text_warning);
-            return true;
-        }
-    }
-
-    return ret;
+       clearMessage();
+
+       // 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) {
+               synchronizeSpaceWidgets(dialog_->choice_space_above,
+                                       dialog_->input_space_above,
+                                       dialog_->choice_value_space_above);
+       }
+
+       if (ob == dialog_->choice_space_below) {
+               synchronizeSpaceWidgets(dialog_->choice_space_below,
+                                       dialog_->input_space_below,
+                                       dialog_->choice_value_space_below);
+       }
+
+       // Display a warning if the input is senseless
+       bool valid = (validSpaceWidgets(dialog_->choice_space_above,
+                                       dialog_->input_space_above) &&
+                     validSpaceWidgets(dialog_->choice_space_below,
+                                       dialog_->input_space_below));
+
+       if (!valid) {
+               postWarning(_("Invalid Length (valid example: 10mm)"));
+       }
+
+       int const choice_spacing = fl_get_choice(dialog_->choice_linespacing);
+
+       if (choice_spacing == 5)
+               setEnabled(dialog_->input_linespacing, true);
+       else {
+               fl_set_input(dialog_->input_linespacing, "");
+               setEnabled(dialog_->input_linespacing, false);
+       }
+
+       double const spacing =
+               strToDbl(getString(dialog_->input_linespacing));
+
+       if (choice_spacing == 5 && int(spacing) == 0)
+               valid = false;
+
+       return ButtonPolicy::SMI_VALID;
 }
-