]> 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 6b45eb0f258467cf0572c338c8b3ec3815972bf1..a5f36f809618afe07ac452af612ffe5097a24476 100644 (file)
@@ -6,62 +6,48 @@
  * \author Jürgen Vigna
  * \author Rob Lahaye
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "ControlParagraph.h"
 #include "FormParagraph.h"
+#include "ControlParagraph.h"
 #include "forms/form_paragraph.h"
+
+#include "checkedwidgets.h"
+#include "input_validators.h"
 #include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
 
-#include "ParagraphParameters.h"
+#include "controllers/helper_funcs.h"
 
-#include "xforms_helpers.h"
 #include "lyxrc.h" // to set the deafult length values
-#include "input_validators.h"
-#include "helper_funcs.h"
-#include "checkedwidgets.h"
-#include "gettext.h"
-#include "xformsBC.h"
-#include "layout.h" // LyXAlignment
+#include "ParagraphParameters.h"
+#include "Spacing.h"
 
 #include "support/lstrings.h"
-#include "support/tostr.h"
-#include "support/LAssert.h"
+#include "support/convert.h"
 
 #include "lyx_forms.h"
 
-#include <functional>
+#include <boost/bind.hpp>
 
-using namespace lyx::support;
+using boost::bind;
 
-using std::vector;
-using std::bind2nd;
 using std::remove_if;
 
+using std::vector;
+using std::string;
 
-namespace
-{
-
-string defaultUnit("cm");
-
-void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length);
-
-VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
-                                 FL_OBJECT * input_length,
-                                 FL_OBJECT * choice_length,
-                                 FL_OBJECT * check_keep);
-
-void setWidgetsFromVSpace(VSpace const & space,
-                         FL_OBJECT * choice_type,
-                         FL_OBJECT * input_length,
-                         FL_OBJECT * choice_length,
-                         FL_OBJECT * check_keep);
+namespace lyx {
 
-} // namespace anon
+using support::contains;
+using support::getStringFromVector;
+using support::rtrim;
 
+namespace frontend {
 
 typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
 
@@ -82,40 +68,16 @@ void FormParagraph::build()
        bcview().setRestore(dialog_->button_restore);
 
        // disable for read-only documents
-       bcview().addReadOnly(dialog_->check_line_above);
-       bcview().addReadOnly(dialog_->check_pagebreak_above);
-       bcview().addReadOnly(dialog_->choice_space_above);
-       bcview().addReadOnly(dialog_->input_space_above);
-       bcview().addReadOnly(dialog_->check_space_above);
-
        bcview().addReadOnly(dialog_->check_noindent);
        bcview().addReadOnly(dialog_->choice_linespacing);
        bcview().addReadOnly(dialog_->input_linespacing);
 
-       bcview().addReadOnly(dialog_->check_line_below);
-       bcview().addReadOnly(dialog_->check_pagebreak_below);
-       bcview().addReadOnly(dialog_->choice_space_below);
-       bcview().addReadOnly(dialog_->input_space_below);
-       bcview().addReadOnly(dialog_->check_space_below);
-
        bcview().addReadOnly(dialog_->input_labelwidth);
 
-       // check validity of "length + unit" input
-       addCheckedGlueLength(bcview(),
-                            dialog_->input_space_above,
-                            dialog_->choice_space_above);
-       addCheckedGlueLength(bcview(),
-                            dialog_->input_space_below,
-                            dialog_->choice_space_below);
-
        // trigger an input event for cut&paste with middle mouse button.
-       setPrehandler(dialog_->input_space_above);
-       setPrehandler(dialog_->input_space_below);
        setPrehandler(dialog_->input_linespacing);
        setPrehandler(dialog_->input_labelwidth);
 
-       fl_set_input_return(dialog_->input_space_above, FL_RETURN_CHANGED);
-       fl_set_input_return(dialog_->input_space_below, FL_RETURN_CHANGED);
        fl_set_input_return(dialog_->input_labelwidth,  FL_RETURN_CHANGED);
        fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
 
@@ -128,10 +90,6 @@ void FormParagraph::build()
        alignment_.init(dialog_->radio_align_block,  LYX_ALIGN_BLOCK);
        alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
 
-       string const parspacing = _("None|DefSkip|SmallSkip|MedSkip|BigSkip|VFill|Length");
-       fl_addto_choice(dialog_->choice_space_above, parspacing.c_str());
-       fl_addto_choice(dialog_->choice_space_below, parspacing.c_str());
-
        string const linespacing = _("Default|Single|OneHalf|Double|Custom");
        fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
 
@@ -139,94 +97,15 @@ void FormParagraph::build()
        vector<string> units_vec = getLatexUnits();
        vector<string>::iterator del =
                remove_if(units_vec.begin(), units_vec.end(),
-                         bind2nd(contains_functor(), "%"));
+                         bind(contains<char>, _1, '%'));
        units_vec.erase(del, units_vec.end());
-
-       string const units = getStringFromVector(units_vec, "|");
-       fl_addto_choice(dialog_->choice_unit_space_above, units.c_str());
-       fl_addto_choice(dialog_->choice_unit_space_below, units.c_str());
-
-       // set up the tooltips
-       string str = _("Add a separator line above this paragraph.");
-       tooltips().init(dialog_->check_line_above, str);
-       str = _("Enforce a page break above this paragraph.");
-       tooltips().init(dialog_->check_pagebreak_above, str);
-       str = _("Add additional space above this paragraph.");
-       tooltips().init(dialog_->choice_space_above, str);
-       str = _("Never suppress space (e.g. at top of page or new page).");
-       tooltips().init(dialog_->check_space_above, str);
-
-       str = _("Add a separator line below this paragraph.");
-       tooltips().init(dialog_->check_line_below, str);
-       str = _("Enforce a page break below this paragraph.");
-       tooltips().init(dialog_->check_pagebreak_below, str);
-       str = _("Add additional space below this paragraph.");
-       tooltips().init(dialog_->choice_space_below, str);
-       str = _("Never suppress space (e.g. at bottom of page or new page).");
-       tooltips().init(dialog_->check_space_below, str);
-
-       // set default unit for custom length
-       switch (lyxrc.default_papersize) {
-               case BufferParams::PAPER_DEFAULT:
-               case BufferParams::PAPER_USLETTER:
-               case BufferParams::PAPER_LEGALPAPER:
-               case BufferParams::PAPER_EXECUTIVEPAPER:
-                       defaultUnit = "in";
-                       break;
-               case BufferParams::PAPER_A3PAPER:
-               case BufferParams::PAPER_A4PAPER:
-               case BufferParams::PAPER_A5PAPER:
-               case BufferParams::PAPER_B5PAPER:
-                       defaultUnit = "cm";
-                       break;
-       }
 }
 
 
 void FormParagraph::apply()
 {
-       if (!form()) return;
-
-       // spacing
-       // If a vspace choice is "Length" but there's no text in
-       // the input field, reset the choice to "None".
-       validateVSpaceWidgets(dialog_->choice_space_above,
-                             dialog_->input_space_above);
-
-       VSpace const space_above =
-               setVSpaceFromWidgets(dialog_->choice_space_above,
-                                    dialog_->input_space_above,
-                                    dialog_->choice_unit_space_above,
-                                    dialog_->check_space_above);
-
-       controller().params().spaceTop(space_above);
-
-       validateVSpaceWidgets(dialog_->choice_space_below,
-                             dialog_->input_space_below);
-
-       VSpace const space_below =
-               setVSpaceFromWidgets(dialog_->choice_space_below,
-                                    dialog_->input_space_below,
-                                    dialog_->choice_unit_space_below,
-                                    dialog_->check_space_below);
-
-       controller().params().spaceBottom(space_below);
-
-       // lines and pagebreaks
-       bool const line_above = fl_get_button(dialog_->check_line_above);
-       controller().params().lineTop(line_above);
-
-       bool const line_below = fl_get_button(dialog_->check_line_below);
-       controller().params().lineBottom(line_below);
-
-       bool const pagebreak_above =
-               fl_get_button(dialog_->check_pagebreak_above);
-       controller().params().pagebreakTop(pagebreak_above);
-
-       bool const pagebreak_below =
-               fl_get_button(dialog_->check_pagebreak_below);
-       controller().params().pagebreakBottom(pagebreak_below);
-
+       if (!form())
+               return;
 
        // alignment
        LyXAlignment const alignment =
@@ -333,20 +212,7 @@ void FormParagraph::update()
        setEnabled(dialog_->radio_align_right,
                   bool(alignpos & LYX_ALIGN_RIGHT));
 
-       // no inset-text-owned paragraph may have pagebreaks
-       bool ininset = controller().inInset();
-       setEnabled(dialog_->check_pagebreak_above, !ininset);
-       setEnabled(dialog_->check_pagebreak_below, !ininset);
-
        // lines, pagebreaks and indent
-       fl_set_button(dialog_->check_line_above,
-                     controller().params().lineTop());
-       fl_set_button(dialog_->check_line_below,
-                     controller().params().lineBottom());
-       fl_set_button(dialog_->check_pagebreak_above,
-                     controller().params().pagebreakTop());
-       fl_set_button(dialog_->check_pagebreak_below,
-                     controller().params().pagebreakBottom());
        fl_set_button(dialog_->check_noindent,
                      controller().params().noindent());
 
@@ -377,26 +243,12 @@ void FormParagraph::update()
        bool const spacing_other = space.getSpace() == Spacing::Other;
        setEnabled(dialog_->input_linespacing, spacing_other);
        if (spacing_other) {
-               string const sp = tostr(space.getValue());
-               fl_set_input(dialog_->input_linespacing, sp.c_str());
+               fl_set_input(dialog_->input_linespacing,
+                       space.getValueAsString().c_str());
        } else {
                fl_set_input(dialog_->input_linespacing, "");
        }
 
-       // vspace top
-       setWidgetsFromVSpace(controller().params().spaceTop(),
-                            dialog_->choice_space_above,
-                            dialog_->input_space_above,
-                            dialog_->choice_unit_space_above,
-                            dialog_->check_space_above);
-
-       // vspace bottom
-       setWidgetsFromVSpace(controller().params().spaceBottom(),
-                            dialog_->choice_space_below,
-                            dialog_->input_space_below,
-                            dialog_->choice_unit_space_below,
-                            dialog_->check_space_below);
-
        // no indent
        fl_set_button(dialog_->check_noindent,
                      controller().params().noindent());
@@ -407,27 +259,7 @@ 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_space_above) {
-               bool const custom_length =
-                       fl_get_choice(dialog_->choice_space_above) == 7;
-               setEnabled(dialog_->input_space_above, custom_length);
-               setEnabled(dialog_->choice_unit_space_above, custom_length);
-
-               bool const space =
-                       fl_get_choice(dialog_->choice_space_above) != 1;
-               setEnabled(dialog_->check_space_above, space);
-
-       } else if (ob == dialog_->choice_space_below) {
-               bool const custom_length =
-                       fl_get_choice(dialog_->choice_space_below) == 7;
-               setEnabled(dialog_->input_space_below, custom_length);
-               setEnabled(dialog_->choice_unit_space_below, custom_length);
-
-               bool const space =
-                       fl_get_choice(dialog_->choice_space_below) != 1;
-               setEnabled(dialog_->check_space_below, space);
-
-       } else if (ob == dialog_->choice_linespacing) {
+       if (ob == dialog_->choice_linespacing) {
                bool const custom_spacing =
                        fl_get_choice(dialog_->choice_linespacing) == 5;
                setEnabled(dialog_->input_linespacing, custom_spacing);
@@ -436,126 +268,5 @@ ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
        return ButtonPolicy::SMI_VALID;
 }
 
-
-namespace {
-
-void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
-{
-       // Paranoia check!
-       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 = rtrim(getString(input_length));
-       if (input.empty())
-               fl_set_choice(choice_type, 1);
-}
-
-
-VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
-                                 FL_OBJECT * input_length,
-                                 FL_OBJECT * choice_length,
-                                 FL_OBJECT * check_keep)
-{
-       // Paranoia check!
-       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 setWidgetsFromVSpace(VSpace const & space,
-                         FL_OBJECT * choice_type,
-                         FL_OBJECT * input_length,
-                         FL_OBJECT * choice_length,
-                         FL_OBJECT * check_keep)
-{
-       // Paranoia check!
-       Assert(choice_type   && choice_type->objclass   == FL_CHOICE &&
-                   input_length  && input_length->objclass  == FL_INPUT &&
-                   choice_length && choice_length->objclass == FL_CHOICE &&
-                   check_keep    && check_keep->objclass    == FL_CHECKBUTTON);
-
-       fl_set_button(check_keep, space.keep());
-
-       int pos = 1;
-       switch (space.kind()) {
-       case VSpace::NONE:
-               pos = 1;
-               break;
-       case VSpace::DEFSKIP:
-               pos = 2;
-               break;
-       case VSpace::SMALLSKIP:
-               pos = 3;
-               break;
-       case VSpace::MEDSKIP:
-               pos = 4;
-               break;
-       case VSpace::BIGSKIP:
-               pos = 5;
-               break;
-       case VSpace::VFILL:
-               pos = 6;
-               break;
-       case VSpace::LENGTH:
-               pos = 7;
-               break;
-       }
-       fl_set_choice(choice_type, pos);
-
-       bool const custom_vspace = space.kind() == VSpace::LENGTH;
-       setEnabled(input_length, custom_vspace);
-       setEnabled(choice_length, custom_vspace);
-       if (custom_vspace) {
-               string const length = space.length().asString();
-               updateWidgetsFromLengthString(input_length, choice_length,
-                                             length, defaultUnit);
-       } else {
-               bool const no_vspace = space.kind() == VSpace::NONE;
-               setEnabled(check_keep, !no_vspace);
-               fl_set_input(input_length, "");
-               fl_set_choice_text(choice_length, defaultUnit.c_str());
-       }
-}
-
-} // namespace anon
+} // namespace frontend
+} // namespace lyx