]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormParagraph.C
Ensure that the warning message is removed if the underlying paragraph will
[lyx.git] / src / frontends / xforms / FormParagraph.C
index 9fe672b52c8605f53644f14b88cabb6600c652c5..2aa378b7e2dcf2b980a44d71582c1fc41329c170 100644 (file)
@@ -1,13 +1,10 @@
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *           Copyright 2000 The LyX Team.
+/**
+ * \file FormParagraph.C
+ * Copyright 2000-2001 The LyX Team.
+ * See the file COPYING.
  *
- *           @author Jürgen Vigna
- *
- *======================================================*/
+ * \author Jürgen Vigna, jug@sad.it
+ */
 
 #include <config.h>
 
 #pragma implementation
 #endif
 
-#include "lyx_gui_misc.h"
-#include "gettext.h"
 #include FORMS_H_LOCATION
-#include XPM_H_LOCATION
 
 #include "FormParagraph.h"
 #include "form_paragraph.h"
-#include "xform_macros.h"
 #include "Dialogs.h"
-#include "ButtonController.h"
 #include "Liason.h"
 #include "LyXView.h"
-#include "BufferView.h"
 #include "buffer.h"
 #include "lyxtext.h"
+#include "xforms_helpers.h"
+#include "lyxrc.h" // to set the deafult length values
+#include "BufferView.h"
+#include "lyxtextclasslist.h"
+#include "Spacing.h"
+#include "ParagraphParameters.h"
+#include "input_validators.h"
+#include "helper_funcs.h"
 
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-#endif
+#include "support/lstrings.h"
+#include "support/LAssert.h"
 
-#ifdef CXX_WORKING_NAMESPACES
-using Liason::setMinibuffer;
-#endif
+#include <functional>
 
-C_RETURNCB(FormParagraph,  WMHideCB)
-C_GENERICCB(FormParagraph, InputCB)
-C_GENERICCB(FormParagraph, OKCB)
-C_GENERICCB(FormParagraph, ApplyCB)
-C_GENERICCB(FormParagraph, CancelCB)
-C_GENERICCB(FormParagraph, RestoreCB)
-C_GENERICCB(FormParagraph, VSpaceCB)
-       
-FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
-       : dialog_(0), general_(0), extra_(0),
-         lv_(lv), d_(d), u_(0), h_(0),
-         status(POPUP_UNMODIFIED) ,
-         bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
-                                                                 _("Close")))
-{
-    // let the popup 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));
-}
+using Liason::setMinibuffer;
+using SigC::slot;
+using std::vector;
+using std::bind2nd;
+using std::remove_if;
 
 
-FormParagraph::~FormParagraph()
+FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
+       : FormBaseBD(lv, d, _("Paragraph Layout")), par_(0)
 {
-    free();
-    delete bc_;
+       // 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));
 }
 
 
-void FormParagraph::build()
+void FormParagraph::connect()
 {
-    // the tabbed folder
-    dialog_ = build_tabbed_paragraph();
-
-    // manage the restore, ok, apply and cancel/close buttons
-    bc_->setOK(dialog_->button_ok);
-    bc_->setApply(dialog_->button_apply);
-    bc_->setCancel(dialog_->button_cancel);
-    bc_->setUndoAll(dialog_->button_restore);
-    bc_->refresh();
-
-    // the general paragraph data form
-    general_ = 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_->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);
-
-    // the document class form
-    extra_ = build_paragraph_extra();
-
-    fl_set_input_return(extra_->input_pextra_width, FL_RETURN_CHANGED);
-    fl_set_input_return(extra_->input_pextra_widthp, FL_RETURN_CHANGED);
-
-    bc_->addReadOnly (extra_->radio_pextra_indent);
-    bc_->addReadOnly (extra_->radio_pextra_minipage);
-    bc_->addReadOnly (extra_->radio_pextra_floatflt);
-
-    // now make them fit together
-    fl_set_form_atclose(dialog_->form, C_FormParagraphWMHideCB, 0);
-    fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
-    fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"), extra_->form);
+       cp_ = d_->updateParagraph
+               .connect(slot(this, &FormParagraph::changedParagraph));
+       FormBaseBD::connect();
 }
 
 
-void FormParagraph::show()
+void FormParagraph::disconnect()
 {
-    if (!dialog_)
-       build();
-
-    update();  // make sure its up-to-date
-    if (dialog_->form->visible) {
-        fl_raise_form(dialog_->form);
-    } else {
-        fl_show_form(dialog_->form, FL_PLACE_MOUSE | FL_FREE_SIZE,
-                     FL_TRANSIENT, _("Paragraph Layout"));
-       u_ = d_->updateBufferDependent.connect(
-           slot(this, &FormParagraph::update));
-       h_ = d_->hideBufferDependent.connect(
-           slot(this, &FormParagraph::hide));
-    }
+       cp_.disconnect();
+       FormBaseBD::disconnect();
 }
 
 
-void FormParagraph::hide()
+Paragraph const * FormParagraph::getCurrentParagraph() const
 {
-    if (dialog_->form->visible) {
-        fl_hide_form(dialog_->form);
-        u_.disconnect();
-        h_.disconnect();
-    }
+       return lv_->view()->getLyXText()->cursor.par();
 }
 
 
-void FormParagraph::apply()
+void FormParagraph::changedParagraph()
 {
-    if (!lv_->view()->available() || !dialog_)
-       return;
-
-    general_apply();
-    extra_apply();
+       /// Record the paragraph
+       Paragraph const * const p = getCurrentParagraph();
+       if (p == 0 || p == par_)
+               return;
 
-    lv_->view()->update(BufferView::SELECT | BufferView::FITCUR |
-                       BufferView::CHANGE);
-    lv_->buffer()->markDirty();
-    setMinibuffer(lv_, _("Paragraph layout set"));
-}
+       // For now, don't bother checking if the params are different.
 
+       // Will the underlying paragraph accept our changes?
+       Inset * const inset = p->inInset();
+       bool const accept = !(inset && inset->forceDefaultParagraphs(inset));
+       bc().valid(accept);
 
-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()->the_locking_inset)
-       text = lv_->view()->the_locking_inset->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 (!accept) {
+               postWarning(_("Cannot apply paragraph settings to this inset!"));
+       } else {
+               clearMessage();
+       }
 }
 
 
-void FormParagraph::extra_apply()
+void FormParagraph::redraw()
 {
-    char const * width = fl_get_input(extra_->input_pextra_width);
-    char const * widthp = fl_get_input(extra_->input_pextra_widthp);
-    LyXText * text = lv_->view()->text;
-    int type = LyXParagraph::PEXTRA_NONE;
-    LyXParagraph::MINIPAGE_ALIGNMENT
-       alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
-    bool
-       hfill = false,
-       start_minipage = false;
-
-    if (fl_get_button(extra_->radio_pextra_indent)) {
-       type = LyXParagraph::PEXTRA_INDENT;
-    } else if (fl_get_button(extra_->radio_pextra_minipage)) {
-       type = LyXParagraph::PEXTRA_MINIPAGE;
-       hfill = fl_get_button(extra_->radio_pextra_hfill);
-       start_minipage = fl_get_button(extra_->radio_pextra_startmp);
-       if (fl_get_button(extra_->radio_pextra_top))
-           alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
-       else if (fl_get_button(extra_->radio_pextra_middle))
-           alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
-       else if (fl_get_button(extra_->radio_pextra_bottom))
-           alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
-    } else if (fl_get_button(extra_->radio_pextra_floatflt)) {
-       type = LyXParagraph::PEXTRA_FLOATFLT;
-    }
-    text->SetParagraphExtraOpt(lv_->view(), type, width, widthp, alignment,
-                              hfill, start_minipage);
+       if (form() && form()->visible)
+               fl_redraw_form(form());
 }
 
 
-void FormParagraph::cancel()
+FL_FORM * FormParagraph::form() const
 {
+       if (dialog_.get())
+               return dialog_->form;
+       return 0;
 }
 
 
-void FormParagraph::update()
+void FormParagraph::build()
 {
-    if (!dialog_)
-        return;
+       // the tabbed folder
+       dialog_.reset(build_paragraph());
+
+       // 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 | 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);
+
+       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();
+#if 0
+       for (vector<string>::iterator it = units_vec.begin();
+            it != units_vec.end(); ++it) {
+               if (contains(*it, "%"))
+                       it = units_vec.erase(it, it+1) - 1;
+       }
+#else
+       // Something similar to this is a better way to erase
+       vector<string>::iterator del =
+               remove_if(units_vec.begin(), units_vec.end(),
+                         bind2nd(contains_functor(), "%"));
+       units_vec.erase(del, units_vec.end());
+#endif
 
-    general_update();
-    extra_update();
+       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);
 }
 
 
-void FormParagraph::general_update()
+namespace {
+
+VSpace setVSpaceFromWidgets(FL_OBJECT * choice_type,
+                           FL_OBJECT * input_length,
+                           FL_OBJECT * choice_length,
+                           FL_OBJECT * check_keep)
 {
-    if (!general_)
-        return;
-
-    Buffer * buf = lv_->view()->buffer();
-    LyXText * text = 0;
-
-    if (lv_->view()->the_locking_inset)
-       text = lv_->view()->the_locking_inset->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;
-    }
-
-#ifndef NEW_INSETS
-    fl_set_button(general_->check_lines_top,
-                 text->cursor.par()->FirstPhysicalPar()->line_top);
-    
-    fl_set_button(general_->check_lines_bottom,
-                 text->cursor.par()->FirstPhysicalPar()->line_bottom);
-    
-    fl_set_button(general_->check_pagebreaks_top,
-                 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
-    
-    fl_set_button(general_->check_pagebreaks_bottom,
-                 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->FirstPhysicalPar()->noindent);
-#else
-    fl_set_button(general_->check_lines_top,
-                 text->cursor.par()->line_top);
-    fl_set_button(general_->check_lines_bottom,
-                 text->cursor.par()->line_bottom);
-    fl_set_button(general_->check_pagebreaks_top,
-                 text->cursor.par()->pagebreak_top);
-    fl_set_button(general_->check_pagebreaks_bottom,
-                 text->cursor.par()->pagebreak_bottom);
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->noindent);
-#endif
-    fl_set_input (general_->input_space_above, "");
+       // 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;
+       }
+       }
 
-#ifndef NEW_INSETS
-    switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
-#else
-    switch (text->cursor.par()->added_space_top.kind()) {
-#endif
+       if (fl_get_button(check_keep))
+               space.setKeep(true);
 
-    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);
-#ifndef NEW_INSETS
-       fl_set_input  (general_->input_space_above, 
-                      text->cursor.par()->FirstPhysicalPar()->
-                      added_space_top.length().asString().c_str());
-#else
-       fl_set_input  (general_->input_space_above, text->cursor.par()->
-                      added_space_top.length().asString().c_str());
-#endif
-       break;
-    }
-#ifndef NEW_INSETS
-    fl_set_button(general_->check_space_above,
-                  text->cursor.par()->FirstPhysicalPar()->
-                  added_space_top.keep());
-    fl_set_input(general_->input_space_below, "");
-    switch (text->cursor.par()->FirstPhysicalPar()->
-           added_space_bottom.kind()) {
-#else
-    fl_set_button (general_->check_space_above,
-                  text->cursor.par()->added_space_top.keep());
-    fl_set_input (general_->input_space_below, "");
-    switch (text->cursor.par()->added_space_bottom.kind()) {
-#endif
-    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);
-#ifndef NEW_INSETS
-       fl_set_input  (general_->input_space_below, 
-                      text->cursor.par()->FirstPhysicalPar()->
-                      added_space_bottom.length().asString().c_str());
-       break;
-    }
-    fl_set_button(general_->check_space_below,
-                  text->cursor.par()->FirstPhysicalPar()->
-                  added_space_bottom.keep());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->FirstPhysicalPar()->noindent);
-    if (text->cursor.par()->FirstPhysicalPar()->InInset()) {
-       fl_set_button(general_->check_pagebreaks_top, 0);
-       fl_deactivate_object(general_->check_pagebreaks_top);
-       fl_set_object_lcol(general_->check_pagebreaks_top, FL_INACTIVE);
-       fl_set_button(general_->check_pagebreaks_bottom, 0);
-       fl_deactivate_object(general_->check_pagebreaks_bottom);
-       fl_set_object_lcol(general_->check_pagebreaks_bottom, FL_INACTIVE);
-    } else {
-       fl_activate_object(general_->check_pagebreaks_top);
-       fl_set_object_lcol(general_->check_pagebreaks_top, FL_BLACK);
-       fl_activate_object(general_->check_pagebreaks_bottom);
-       fl_set_object_lcol(general_->check_pagebreaks_bottom, FL_BLACK);
-    }
-#else
-        fl_set_input(general_->input_space_below, text->cursor.par()->
-                    added_space_bottom.length().asString().c_str());
-       break;
-    }
-    fl_set_button(general_->check_space_below,
-                  text->cursor.par()->added_space_bottom.keep());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->noindent);
-#endif
+       return space;
 }
 
 
-void FormParagraph::extra_update()
+void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
 {
-    if (!lv_->view()->available() || !extra_)
-        return;
-
-    LyXParagraph * par = lv_->view()->text->cursor.par();
-
-    fl_activate_object(extra_->input_pextra_width);
-    fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-    fl_activate_object(extra_->input_pextra_widthp);
-    fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-    fl_set_input(extra_->input_pextra_width,
-                par->pextra_width.c_str());
-    fl_set_input(extra_->input_pextra_widthp,
-                par->pextra_widthp.c_str());
-    switch(par->pextra_alignment) {
-    case LyXParagraph::MINIPAGE_ALIGN_TOP:
-       fl_set_button(extra_->radio_pextra_top, 1);
-       break;
-    case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
-       fl_set_button(extra_->radio_pextra_middle, 1);
-       break;
-    case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
-       fl_set_button(extra_->radio_pextra_bottom, 1);
-       break;
-    }
-    fl_set_button(extra_->radio_pextra_hfill,
-                 par->pextra_hfill);
-    fl_set_button(extra_->radio_pextra_startmp,
-                 par->pextra_start_minipage);
-    if (par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
-       fl_set_button(extra_->radio_pextra_indent, 1);
-       fl_set_button(extra_->radio_pextra_minipage, 0);
-       fl_set_button(extra_->radio_pextra_floatflt, 0);
-       fl_deactivate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-       CheckParagraphInput(extra_->radio_pextra_indent, 0);
-    } else if (par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
-       fl_set_button(extra_->radio_pextra_indent, 0);
-       fl_set_button(extra_->radio_pextra_minipage, 1);
-       fl_set_button(extra_->radio_pextra_floatflt, 0);
-       fl_activate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_BLACK);
-       fl_activate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_BLACK);
-       fl_activate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_BLACK);
-       CheckParagraphInput(extra_->radio_pextra_minipage, 0);
-    } else if (par->pextra_type == LyXParagraph::PEXTRA_FLOATFLT) {
-       fl_set_button(extra_->radio_pextra_indent, 0);
-       fl_set_button(extra_->radio_pextra_minipage, 0);
-       fl_set_button(extra_->radio_pextra_floatflt, 1);
-       fl_deactivate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-       CheckParagraphInput(extra_->radio_pextra_floatflt, 0);
-    } else {
-       fl_set_button(extra_->radio_pextra_indent, 0);
-       fl_set_button(extra_->radio_pextra_minipage, 0);
-       fl_set_button(extra_->radio_pextra_floatflt, 0);
-       fl_deactivate_object(extra_->input_pextra_width);
-       fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-       fl_deactivate_object(extra_->input_pextra_widthp);
-       fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-       CheckParagraphInput(0, 0);
-    }
-    fl_hide_object(dialog_->text_warning);
+       // 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;
+
+       // If a vspace kind is "Length" but there's no text in
+       // the input field, reset the kind to "None".
+       string const input = strip(getStringFromInput(input_length));
+       if (input.empty())
+               fl_set_choice(choice_type, 1);
 }
 
+} // namespace anon
+
 
-void FormParagraph::free()
+void FormParagraph::apply()
 {
-    if (dialog_) {
-        hide();
-        if (general_) {
-//            fl_free_form(general_->form);
-            delete general_;
-            general_ = 0;
-        }
-        if (extra_) {
-//            fl_free_form(extra_->form);
-            delete extra_;
-            extra_ = 0;
-        }
-//        fl_free_form(dialog_->form);
-        delete dialog_;
-        dialog_ = 0;
-    }
-}
+       if (!lv_->view()->available() || !dialog_.get())
+               return;
+
+       // 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);
+       validateVSpaceWidgets(dialog_->choice_space_below,
+                             dialog_->input_space_below);
+
+       bool const line_top = fl_get_button(dialog_->check_lines_top);
+       bool const line_bottom = fl_get_button(dialog_->check_lines_bottom);
+       bool const pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
+       bool const pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
+
+       VSpace const space_top =
+               setVSpaceFromWidgets(dialog_->choice_space_above,
+                                    dialog_->input_space_above,
+                                    dialog_->choice_value_space_above,
+                                    dialog_->check_space_above);
+
+       VSpace const space_bottom =
+               setVSpaceFromWidgets(dialog_->choice_space_below,
+                                    dialog_->input_space_below,
+                                    dialog_->choice_value_space_below,
+                                    dialog_->check_space_below);
+
+       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;
+
+       string const labelwidthstring =
+               getStringFromInput(dialog_->input_labelwidth);
+
+       bool const noindent = fl_get_button(dialog_->check_noindent);
+
+       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 = getStringFromInput(dialog_->input_linespacing);
+               break;
+       }
 
+       Spacing const spacing(linespacing, other);
 
-int FormParagraph::WMHideCB(FL_FORM * form, void *)
-{
-    // Ensure that the signals (u and h) are disconnected even if the
-    // window manager is used to close the popup.
-    FormParagraph * pre = static_cast<FormParagraph*>(form->u_vdata);
-    pre->hide();
-    pre->bc_->hide();
-    return FL_CANCEL;
+       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"));
 }
 
 
-void FormParagraph::OKCB(FL_OBJECT * ob, long)
+namespace {
+
+void setWidgetsFromVSpace(VSpace const & space,
+                         FL_OBJECT * choice_type,
+                         FL_OBJECT * input_length,
+                         FL_OBJECT * choice_length,
+                         FL_OBJECT * check_keep)
 {
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->apply();
-    pre->hide();
-    pre->bc_->ok();
+       // 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::ApplyCB(FL_OBJECT * ob, long)
+
+void FormParagraph::update()
 {
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->apply();
-    pre->bc_->apply();
-}
+       if (!dialog_.get())
+               return;
+
+       // Do this first; some objects may be de/activated subsequently.
+       bc_.readOnly(lv_->buffer()->isReadonly());
+
+       /// 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);
+
+       LyXTextClass const & tclass =
+               textclasslist[lv_->view()->buffer()->params.textclass];
+
+       int align = par_->getAlign();
+       if (align == LYX_ALIGN_LAYOUT)
+               align = tclass[par_->layout()].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 = tclass[par_->layout()].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;
+       }
 
-void FormParagraph::CancelCB(FL_OBJECT * ob, long)
-{
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->cancel();
-    pre->hide();
-    pre->bc_->cancel();
-}
+       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);
+       }
 
+       setWidgetsFromVSpace(par_->params().spaceTop(),
+                            dialog_->choice_space_above,
+                            dialog_->input_space_above,
+                            dialog_->choice_value_space_above,
+                            dialog_->check_space_above);
 
-void FormParagraph::RestoreCB(FL_OBJECT * ob, long)
-{
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->update();
-    pre->bc_->undoAll();
+       setWidgetsFromVSpace(par_->params().spaceBottom(),
+                            dialog_->choice_space_below,
+                            dialog_->input_space_below,
+                            dialog_->choice_value_space_below,
+                            dialog_->check_space_below);
+
+       fl_set_button(dialog_->check_noindent,
+                     par_->params().noindent());
 }
 
 
-void FormParagraph::InputCB(FL_OBJECT * ob, long)
+namespace {
+
+void synchronizeSpaceWidgets(FL_OBJECT * choice_type,
+                            FL_OBJECT * input_length,
+                            FL_OBJECT * choice_length,
+                            bool readonly)
 {
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->bc_->valid(pre->CheckParagraphInput(ob,0));
-}
+       // 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);
 
+       if (fl_get_choice(choice_type) != 7) {
+               fl_set_input(input_length, "");
+               setEnabled(input_length, false);
+               setEnabled(choice_length, false);
+
+       } else {
+               setEnabled(input_length,  !readonly);
+               setEnabled(choice_length, !readonly);
 
-void FormParagraph::VSpaceCB(FL_OBJECT * ob, long)
+               string const length = getStringFromInput(input_length);
+
+               if (strip(length).empty()) {
+                       bool const metric = lyxrc.default_papersize > 3;
+                       int const default_unit = metric ? 8 : 9;
+
+                       fl_set_choice(choice_length, default_unit);
+               }
+       }
+}
+
+bool validSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
 {
-    FormParagraph * pre = static_cast<FormParagraph*>(ob->form->u_vdata);
-    pre->bc_->valid(pre->CheckParagraphInput(ob,0));
+       // 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 = getStringFromInput(input_length);
+       return (input.empty() ||
+               isValidGlueLength(input) ||
+               isStrDbl(input));
 }
 
+} // namespace anon
+
 
-bool FormParagraph::CheckParagraphInput(FL_OBJECT * ob, long)
+bool 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 (ob == general_->choice_space_above) {
-       if (fl_get_choice (general_->choice_space_above) != 7)
-           fl_set_input (general_->input_space_above, "");
-    } else if (ob == general_->choice_space_below) {
-       if (fl_get_choice (general_->choice_space_below) != 7)
-           fl_set_input (general_->input_space_below, "");
-    }
-    //
-    // then the extra form
-    //
-    else if (ob == extra_->radio_pextra_indent) {
-       int n = fl_get_button(extra_->radio_pextra_indent);
-       if (n) {
-           fl_set_button(extra_->radio_pextra_minipage, 0);
-           fl_set_button(extra_->radio_pextra_floatflt, 0);
-           fl_activate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-           fl_activate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-       } else {
-           fl_deactivate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-           fl_deactivate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
-       }
-       fl_deactivate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-       fl_activate_object(extra_->radio_pextra_hfill);
-       fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
-       fl_activate_object(extra_->radio_pextra_startmp);
-       fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
-    } else if (ob == extra_->radio_pextra_minipage) {
-       int n = fl_get_button(extra_->radio_pextra_minipage);
-       if (n) {
-           fl_set_button(extra_->radio_pextra_indent, 0);
-           fl_set_button(extra_->radio_pextra_floatflt, 0);
-           fl_activate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-           fl_activate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-           fl_activate_object(extra_->radio_pextra_top);
-           fl_set_object_lcol(extra_->radio_pextra_top, FL_BLACK);
-           fl_activate_object(extra_->radio_pextra_middle);
-           fl_set_object_lcol(extra_->radio_pextra_middle, FL_BLACK);
-           fl_activate_object(extra_->radio_pextra_bottom);
-           fl_set_object_lcol(extra_->radio_pextra_bottom, FL_BLACK);
-           fl_activate_object(extra_->radio_pextra_hfill);
-           fl_set_object_lcol(extra_->radio_pextra_hfill, FL_BLACK);
-           fl_activate_object(extra_->radio_pextra_startmp);
-           fl_set_object_lcol(extra_->radio_pextra_startmp, FL_BLACK);
-       } else {
-           fl_deactivate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-           fl_deactivate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
-           fl_deactivate_object(extra_->radio_pextra_top);
-           fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-           fl_deactivate_object(extra_->radio_pextra_middle);
-           fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-           fl_deactivate_object(extra_->radio_pextra_bottom);
-           fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-           fl_activate_object(extra_->radio_pextra_hfill);
-           fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
-           fl_activate_object(extra_->radio_pextra_startmp);
-           fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
+       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,
+                                       lv_->buffer()->isReadonly());
        }
-    } else if (ob == extra_->radio_pextra_floatflt) {
-       int n = fl_get_button(extra_->radio_pextra_floatflt);
-       if (n) {
-           fl_set_button(extra_->radio_pextra_indent, 0);
-           fl_set_button(extra_->radio_pextra_minipage, 0);
-           fl_activate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-           fl_activate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-       } else {
-           fl_deactivate_object(extra_->input_pextra_width);
-           fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-           fl_deactivate_object(extra_->input_pextra_widthp);
-           fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
+
+       if (ob == dialog_->choice_space_below) {
+               synchronizeSpaceWidgets(dialog_->choice_space_below,
+                                       dialog_->input_space_below,
+                                       dialog_->choice_value_space_below,
+                                       lv_->buffer()->isReadonly());
        }
-       fl_deactivate_object(extra_->radio_pextra_top);
-       fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_middle);
-       fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
-       fl_deactivate_object(extra_->radio_pextra_bottom);
-       fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
-       fl_activate_object(extra_->radio_pextra_hfill);
-       fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
-       fl_activate_object(extra_->radio_pextra_startmp);
-       fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
-    }
-    
-    //
-    // first the general form
-    //
-    string input = fl_get_input (general_->input_space_above);
-       
-    if (input.empty()) {
-       fl_set_choice (general_->choice_space_above, 1);
-    } else if (isValidGlueLength (input)) {
-       fl_set_choice (general_->choice_space_above, 7);
-    } else {
-       fl_set_choice (general_->choice_space_above, 7);
-       fl_set_object_label(dialog_->text_warning,
-                   _("Warning: Invalid Length (valid example: 10mm)"));
-       fl_show_object(dialog_->text_warning);
-       ret = false;
-    }
-    
-    input = fl_get_input (general_->input_space_below);
-       
-    if (input.empty()) {
-       fl_set_choice (general_->choice_space_below, 1);
-    } else if (isValidGlueLength(input)) {
-       fl_set_choice (general_->choice_space_below, 7);
-    } else {
-       fl_set_choice (general_->choice_space_below, 7);
-       fl_set_object_label(dialog_->text_warning,
-                   _("Warning: Invalid Length (valid example: 10mm)"));
-       fl_show_object(dialog_->text_warning);
-       ret = false;
-    }
-    //
-    // then the extra form
-    //
-    int n = fl_get_button(extra_->radio_pextra_indent) +
-       fl_get_button(extra_->radio_pextra_minipage) +
-       fl_get_button(extra_->radio_pextra_floatflt);
-    string s1 = fl_get_input(extra_->input_pextra_width);
-    string s2 = fl_get_input(extra_->input_pextra_widthp);
-    if (!n) { // no button pressed both should be deactivated now
-       fl_deactivate_object(extra_->input_pextra_width);
-       fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-       fl_deactivate_object(extra_->input_pextra_widthp);
-       fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
-       fl_hide_object(dialog_->text_warning);
-    } else if (s1.empty() && s2.empty()) {
-       fl_activate_object(extra_->input_pextra_width);
-       fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-       fl_activate_object(extra_->input_pextra_widthp);
-       fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-       fl_hide_object(dialog_->text_warning);
-       ret = false;
-    } else if (!s1.empty()) { // LyXLength parameter
-       fl_activate_object(extra_->input_pextra_width);
-       fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
-       fl_deactivate_object(extra_->input_pextra_widthp);
-       fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
-       if (!isValidLength(s1)) {
-           fl_set_object_label(dialog_->text_warning,
-                       _("Warning: Invalid Length (valid example: 10mm)"));
-           fl_show_object(dialog_->text_warning);
-           ret = false;
+
+       // 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)"));
        }
-    } else { // !s2.empty() % parameter
-       fl_deactivate_object(extra_->input_pextra_width);
-       fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
-       fl_activate_object(extra_->input_pextra_widthp);
-       fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
-       if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
-           ret = false;
-           fl_set_object_label(dialog_->text_warning,
-                       _("Warning: Invalid percent value (0-100)"));
-           fl_show_object(dialog_->text_warning);
+
+       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);
        }
-    }
-    return ret;
+
+       double const spacing =
+               strToDbl(getStringFromInput(dialog_->input_linespacing));
+
+       if (choice_spacing == 5 && int(spacing) == 0)
+               valid = false;
+
+       return valid;
 }