]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormParagraph.C
Change the semantics of 'none' and 'auto' viewers/editors: 'none' means now
[lyx.git] / src / frontends / xforms / FormParagraph.C
index 0c28102a8a7581ae19b283175dc53a5061702c0f..a5f36f809618afe07ac452af612ffe5097a24476 100644 (file)
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *           Copyright 2000 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 "FormParagraph.h"
-#include "form_paragraph.h"
-#include "Dialogs.h"
-#include "Liason.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "lyxtext.h"
-#include "xforms_helpers.h"
+#include "ControlParagraph.h"
+#include "forms/form_paragraph.h"
 
-#ifdef CXX_WORKING_NAMESPACES
-using Liason::setMinibuffer;
-#endif
-
-FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
-       : FormBaseBD(lv, d, _("Paragraph Layout"))
-{
-    // 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));
-}
+#include "checkedwidgets.h"
+#include "input_validators.h"
+#include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
 
+#include "controllers/helper_funcs.h"
 
-void FormParagraph::redraw()
-{
-       if( form() && form()->visible )
-               fl_redraw_form( form() );
-       else
-               return;
-
-       FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
-       if (outer_form && outer_form->visible)
-               fl_redraw_form( outer_form );
-}
+#include "lyxrc.h" // to set the deafult length values
+#include "ParagraphParameters.h"
+#include "Spacing.h"
 
+#include "support/lstrings.h"
+#include "support/convert.h"
 
-FL_FORM * FormParagraph::form() const
-{
-    if (dialog_.get()) return dialog_->form;
-    return 0;
-}
+#include "lyx_forms.h"
 
+#include <boost/bind.hpp>
 
-void FormParagraph::build()
-{
-    // the tabbed folder
-    dialog_.reset(build_tabbed_paragraph());
-
-    // Workaround dumb xforms sizing bug
-    minw_ = form()->w;
-    minh_ = form()->h;
-
-    // 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_.setUndoAll(dialog_->button_restore);
-    bc_.refresh();
-
-    // 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);
-
-    // the document class form
-    extra_.reset(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);
-    bc_.addReadOnly (extra_->radio_pextra_hfill);
-    bc_.addReadOnly (extra_->radio_pextra_startmp);
-
-    // now make them fit together
-    fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
-    fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"), extra_->form);
-}
+using boost::bind;
 
+using std::remove_if;
 
-void FormParagraph::apply()
-{
-    if (!lv_->view()->available() || !dialog_.get())
-       return;
+using std::vector;
+using std::string;
 
-    general_apply();
-    extra_apply();
+namespace lyx {
 
-    lv_->view()->update(lv_->view()->text, 
-                       BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
-    lv_->buffer()->markDirty();
-    setMinibuffer(lv_, _("Paragraph layout set"));
-}
+using support::contains;
+using support::getStringFromVector;
+using support::rtrim;
 
+namespace frontend {
 
-void FormParagraph::update()
-{
-    if (!dialog_.get())
-        return;
+typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
 
-    general_update();
-    extra_update();
-    bc_.readOnly(lv_->buffer()->isReadonly());
-}
+FormParagraph::FormParagraph(Dialog & parent)
+       : base_class(parent, _("Paragraph Settings"))
+{}
 
 
-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);
-}
-
-
-void FormParagraph::extra_apply()
+void FormParagraph::build()
 {
-    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);
+       // 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_noindent);
+       bcview().addReadOnly(dialog_->choice_linespacing);
+       bcview().addReadOnly(dialog_->input_linespacing);
+
+       bcview().addReadOnly(dialog_->input_labelwidth);
+
+       // trigger an input event for cut&paste with middle mouse button.
+       setPrehandler(dialog_->input_linespacing);
+       setPrehandler(dialog_->input_labelwidth);
+
+       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 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(),
+                         bind(contains<char>, _1, '%'));
+       units_vec.erase(del, units_vec.end());
 }
 
 
-void FormParagraph::general_update()
+void FormParagraph::apply()
 {
-    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;
-    }
-
-#ifndef NEW_INSETS
-    fl_set_button(general_->check_lines_top,
-                 text->cursor.par()->FirstPhysicalPar()->params.lineTop());
-    
-    fl_set_button(general_->check_lines_bottom,
-                 text->cursor.par()->FirstPhysicalPar()->params.lineBottom());
-    
-    fl_set_button(general_->check_pagebreaks_top,
-                 text->cursor.par()->FirstPhysicalPar()->params.pagebreakTop());
-    
-    fl_set_button(general_->check_pagebreaks_bottom,
-                 text->cursor.par()->FirstPhysicalPar()->params.pagebreakBottom());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->FirstPhysicalPar()->params.noindent());
-#else
-    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());
-#endif
-    fl_set_input (general_->input_space_above, "");
-
-#ifndef NEW_INSETS
-    switch (text->cursor.par()->FirstPhysicalPar()->params.spaceTop().kind()) {
-#else
-    switch (text->cursor.par()->params.spaceTop().kind()) {
-#endif
-
-    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()->
-                    params.spaceTop().length().asString().c_str());
-#else
-       fl_set_input(general_->input_space_above, text->cursor.par()->
-                    params.spaceTop().length().asString().c_str());
-#endif
-       break;
-    }
-#ifndef NEW_INSETS
-    fl_set_button(general_->check_space_above,
-                  text->cursor.par()->FirstPhysicalPar()->
-                  params.spaceTop().keep());
-    fl_set_input(general_->input_space_below, "");
-    switch (text->cursor.par()->FirstPhysicalPar()->
-           params.spaceBottom().kind()) {
-#else
-    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()) {
-#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()->
-                    params.spaceBottom().length().asString().c_str());
-       break;
-    }
-    fl_set_button(general_->check_space_below,
-                  text->cursor.par()->FirstPhysicalPar()->
-                  params.spaceBottom().keep());
-    fl_set_button(general_->check_noindent,
-                 text->cursor.par()->FirstPhysicalPar()->params.noindent());
-
-    bool const enable = (!text->cursor.par()->FirstPhysicalPar()->InInset());
-
-    setEnabled(general_->check_pagebreaks_top,    enable);
-    setEnabled(general_->check_pagebreaks_bottom, enable);
-    
-    if (!enable) {
-           fl_set_button(general_->check_pagebreaks_top, 0);
-           fl_set_button(general_->check_pagebreaks_bottom, 0);
-    }
-
-#else
-        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());
-#endif
-}
-
+       if (!form())
+               return;
 
-void FormParagraph::extra_update()
-{
-    if (!lv_->view()->available() || !extra_.get())
-        return;
-
-    LyXParagraph * par = lv_->view()->text->cursor.par();
-
-    setEnabled(extra_->input_pextra_width,  true);
-    setEnabled(extra_->input_pextra_widthp, true);
-
-    fl_set_input(extra_->input_pextra_width,
-                par->params.pextraWidth().c_str());
-    fl_set_input(extra_->input_pextra_widthp,
-                par->params.pextraWidthp().c_str());
-    switch (par->params.pextraAlignment()) {
-    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->params.pextraHfill());
-    fl_set_button(extra_->radio_pextra_startmp,
-                 par->params.pextraStartMinipage());
-    if (par->params.pextraType() == 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);
-       setEnabled(extra_->radio_pextra_top,    false);
-       setEnabled(extra_->radio_pextra_middle, false);
-       setEnabled(extra_->radio_pextra_bottom, false);
-       input(extra_->radio_pextra_indent, 0);
-    } else if (par->params.pextraType() == 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);
-       setEnabled(extra_->radio_pextra_top,    true);
-       setEnabled(extra_->radio_pextra_middle, true);
-       setEnabled(extra_->radio_pextra_bottom, true);
-       input(extra_->radio_pextra_minipage, 0);
-    } else if (par->params.pextraType() == 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);
-       setEnabled(extra_->radio_pextra_top,    false);
-       setEnabled(extra_->radio_pextra_middle, false);
-       setEnabled(extra_->radio_pextra_bottom, false);
-       input(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);
-       setEnabled(extra_->input_pextra_width,  false);
-       setEnabled(extra_->input_pextra_widthp, false);
-       setEnabled(extra_->radio_pextra_top,    false);
-       setEnabled(extra_->radio_pextra_middle, false);
-       setEnabled(extra_->radio_pextra_bottom, false);
-       input(0, 0);
-    }
-    fl_hide_object(dialog_->text_warning);
+       // 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);
 }
 
 
-bool FormParagraph::input(FL_OBJECT * ob, long)
+void FormParagraph::update()
 {
-    bool ret = true;
+       if (!dialog_.get())
+               return;
 
-    fl_hide_object(dialog_->text_warning);
+       // 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!"));
 
-    // 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.
+       // alignment
+       alignment_.set(controller().params().align());
 
-    if (fl_get_choice (general_->choice_space_above) != 7)
-        fl_set_input (general_->input_space_above, "");
+       // mark default alignment
+       LyXAlignment const default_alignment = controller().alignDefault();
 
-    if (fl_get_choice (general_->choice_space_below) != 7)
-        fl_set_input (general_->input_space_below, "");
+       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);
 
-    //
-    // then the extra form
-    //
-    if (ob == extra_->radio_pextra_indent) {
-       bool const enable = (fl_get_button(extra_->radio_pextra_indent) != 0);
+       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);
 
-       if (enable) {
-           fl_set_button(extra_->radio_pextra_minipage, 0);
-           fl_set_button(extra_->radio_pextra_floatflt, 0);
+       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);
 
-       setEnabled(extra_->input_pextra_width,  enable);
-       setEnabled(extra_->input_pextra_widthp, enable);
-
-       setEnabled(extra_->radio_pextra_top,     false);
-       setEnabled(extra_->radio_pextra_middle,  false);
-       setEnabled(extra_->radio_pextra_bottom,  false);
-       setEnabled(extra_->radio_pextra_hfill,   false);
-       setEnabled(extra_->radio_pextra_startmp, false);
-
-    } else if (ob == extra_->radio_pextra_minipage) {
-       bool const enable = (fl_get_button(extra_->radio_pextra_minipage) != 0);
-       
-       if (enable) {
-           fl_set_button(extra_->radio_pextra_indent, 0);
-           fl_set_button(extra_->radio_pextra_floatflt, 0);
+       label = _("Right");
+       if (default_alignment == LYX_ALIGN_RIGHT) {
+               label = _(" (default)");
        }
-       
-       setEnabled(extra_->input_pextra_width,   enable);
-       setEnabled(extra_->input_pextra_widthp,  enable);
-       setEnabled(extra_->radio_pextra_top,     enable);
-       setEnabled(extra_->radio_pextra_middle,  enable);
-       setEnabled(extra_->radio_pextra_bottom,  enable);
-       setEnabled(extra_->radio_pextra_hfill,   enable);
-       setEnabled(extra_->radio_pextra_startmp, enable);
-    } else if (ob == extra_->radio_pextra_floatflt) {
-       bool const enable = (fl_get_button(extra_->radio_pextra_floatflt) != 0);
-       
-       if (enable) {
-           fl_set_button(extra_->radio_pextra_indent, 0);
-           fl_set_button(extra_->radio_pextra_minipage, 0);
+       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));
+
+       // lines, pagebreaks and indent
+       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;
        }
-       
-       setEnabled(extra_->input_pextra_width,  enable);
-       setEnabled(extra_->input_pextra_widthp, enable);
-
-       setEnabled(extra_->radio_pextra_top,     false);
-       setEnabled(extra_->radio_pextra_middle,  false);
-       setEnabled(extra_->radio_pextra_bottom,  false);
-       setEnabled(extra_->radio_pextra_hfill,   false);
-       setEnabled(extra_->radio_pextra_startmp, false);
-    }
-    
-    //
-    // 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;
-        }
-    }
-
-    //
-    // 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
-       setEnabled(extra_->input_pextra_width,  false);
-       setEnabled(extra_->input_pextra_widthp, false);
-       fl_hide_object(dialog_->text_warning);
-    } else if (s1.empty() && s2.empty()) {
-       setEnabled(extra_->input_pextra_width,  true);
-       setEnabled(extra_->input_pextra_widthp, true);
-       fl_hide_object(dialog_->text_warning);
-       ret = false;
-    } else if (!s1.empty()) { // LyXLength parameter
-       setEnabled(extra_->input_pextra_width,  true);
-       setEnabled(extra_->input_pextra_widthp, false);
-       if (!isValidLength(s1)) {
-           fl_set_object_label(dialog_->text_warning,
-                       _("Warning: Invalid Length (valid example: 10mm)"));
-           fl_show_object(dialog_->text_warning);
-           ret = false;
+       fl_set_choice(dialog_->choice_linespacing, pos);
+
+       bool const spacing_other = space.getSpace() == Spacing::Other;
+       setEnabled(dialog_->input_linespacing, spacing_other);
+       if (spacing_other) {
+               fl_set_input(dialog_->input_linespacing,
+                       space.getValueAsString().c_str());
+       } else {
+               fl_set_input(dialog_->input_linespacing, "");
        }
-    } else { // !s2.empty() % parameter
-       setEnabled(extra_->input_pextra_width,  false);
-       setEnabled(extra_->input_pextra_widthp, true);
-       if ((lyx::atoi(s2) < 0 ) || (lyx::atoi(s2) > 100)) {
-           ret = false;
-           fl_set_object_label(dialog_->text_warning,
-                       _("Warning: Invalid percent value (0-100)"));
-           fl_show_object(dialog_->text_warning);
+
+       // no indent
+       fl_set_button(dialog_->check_noindent,
+                     controller().params().noindent());
+}
+
+
+ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
+{
+       // Enable input when custum length is choosen,
+       // disable 'keep' when no space is choosen
+       if (ob == dialog_->choice_linespacing) {
+               bool const custom_spacing =
+                       fl_get_choice(dialog_->choice_linespacing) == 5;
+               setEnabled(dialog_->input_linespacing, custom_spacing);
        }
-    }
-    return ret;
+
+       return ButtonPolicy::SMI_VALID;
 }
 
+} // namespace frontend
+} // namespace lyx