]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormVSpace.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / FormVSpace.C
index 80ae1eb3b292bbc787162ef840ba689bda1c146e..0df4171318a063df41e775ab37d651e06c756cde 100644 (file)
 
 #include "lyx_forms.h"
 
-using lyx::support::contains_functor;
-using lyx::support::getStringFromVector;
-using lyx::support::rtrim;
+#include <boost/bind.hpp>
+
+using boost::bind;
 
-using std::bind2nd;
 using std::remove_if;
 
 using std::vector;
 using std::string;
 
+namespace lyx {
+
+using support::contains;
+using support::getStringFromVector;
+using support::rtrim;
+
+namespace frontend {
 
 namespace {
 
@@ -54,83 +60,91 @@ void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
        BOOST_ASSERT(choice_type  && choice_type->objclass  == FL_CHOICE &&
                     input_length && input_length->objclass == FL_INPUT);
 
-       if (fl_get_choice(choice_type) != 7)
+       if (fl_get_choice(choice_type) != 6)
                return;
 
        // If a vspace kind is "Length" but there's no text in
-       // the input field, reset the kind to "None".
+       // the input field, insert nothing.
        string const input = rtrim(getString(input_length));
        if (input.empty())
-               fl_set_choice(choice_type, 1);
+               return;
 }
 
 
 VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
                                  FL_OBJECT * input_length,
-                                 FL_OBJECT * choice_length)
+                                 FL_OBJECT * choice_length,
+                                 bool keep)
 {
        // Paranoia check!
        BOOST_ASSERT(choice_type   && choice_type->objclass   == FL_CHOICE &&
                     input_length  && input_length->objclass  == FL_INPUT &&
                     choice_length && choice_length->objclass == FL_CHOICE);
 
+       VSpace space;
+
        switch (fl_get_choice(choice_type)) {
        case 1:
-               return VSpace(VSpace::NONE);
+               space = VSpace(VSpace::DEFSKIP);
+               break;
        case 2:
-               return VSpace(VSpace::DEFSKIP);
+               space = VSpace(VSpace::SMALLSKIP);
+               break;
        case 3:
-               return VSpace(VSpace::SMALLSKIP);
+               space = VSpace(VSpace::MEDSKIP);
+               break;
        case 4:
-               return VSpace(VSpace::MEDSKIP);
+               space = VSpace(VSpace::BIGSKIP);
+               break;
        case 5:
-               return VSpace(VSpace::BIGSKIP);
+               space = VSpace(VSpace::VFILL);
+               break;
        case 6:
-               return VSpace(VSpace::VFILL);
-       case 7:
-               return VSpace(LyXGlueLength(
-                                     getLengthFromWidgets(input_length, choice_length)));
+               space = VSpace(LyXGlueLength(
+                       getLengthFromWidgets(input_length, choice_length)));
+               break;
        }
 
-       return VSpace(VSpace::NONE);
+       space.setKeep(keep);
+       return space;
 }
 
 
 void setWidgetsFromVSpace(VSpace const & space,
                          FL_OBJECT * choice_type,
                          FL_OBJECT * input_length,
-                         FL_OBJECT * choice_length)
+                         FL_OBJECT * choice_length,
+                         FL_OBJECT * check_keep)
 {
        // Paranoia check!
        BOOST_ASSERT(choice_type   && choice_type->objclass   == FL_CHOICE &&
                     input_length  && input_length->objclass  == FL_INPUT &&
-                    choice_length && choice_length->objclass == FL_CHOICE);
+                    choice_length && choice_length->objclass == FL_CHOICE &&
+                    check_keep    && check_keep->objclass   == FL_CHECKBUTTON);
 
        int pos = 1;
        switch (space.kind()) {
-       case VSpace::NONE:
-               pos = 1;
-               break;
        case VSpace::DEFSKIP:
-               pos = 2;
+               pos = 1;
                break;
        case VSpace::SMALLSKIP:
-               pos = 3;
+               pos = 2;
                break;
        case VSpace::MEDSKIP:
-               pos = 4;
+               pos = 3;
                break;
        case VSpace::BIGSKIP:
-               pos = 5;
+               pos = 4;
                break;
        case VSpace::VFILL:
-               pos = 6;
+               pos = 5;
                break;
        case VSpace::LENGTH:
-               pos = 7;
+               pos = 6;
                break;
        }
        fl_set_choice(choice_type, pos);
+       fl_set_button(check_keep, space.keep());
 
        bool const custom_vspace = space.kind() == VSpace::LENGTH;
        if (custom_vspace) {
@@ -170,10 +184,10 @@ void FormVSpace::build()
        bcview().addReadOnly(dialog_->choice_unit_space);
 
        // check validity of "length + unit" input.
-       // If invalid, the label of choice_space is displayed in red.
+       // If invalid, the label of input_space is displayed in red.
        addCheckedGlueLength(bcview(),
                             dialog_->input_space,
-                            dialog_->choice_space);
+                            dialog_->input_space);
 
        // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(dialog_->input_space);
@@ -181,14 +195,14 @@ void FormVSpace::build()
        fl_set_input_return(dialog_->input_space, FL_RETURN_CHANGED);
 
        string const spacing =
-               _("None|DefSkip|SmallSkip|MedSkip|BigSkip|VFill|Length");
+               _("DefSkip|SmallSkip|MedSkip|BigSkip|VFill|Length");
        fl_addto_choice(dialog_->choice_space, spacing.c_str());
 
        // Create the contents of the unit choices; don't include the "%" terms.
        vector<string> units_vec = getLatexUnits();
        vector<string>::iterator del =
                remove_if(units_vec.begin(), units_vec.end(),
-                         bind2nd(contains_functor(), "%"));
+                         bind(contains<char>, _1, '%'));
        units_vec.erase(del, units_vec.end());
 
        string const units = getStringFromVector(units_vec, "|");
@@ -218,18 +232,15 @@ void FormVSpace::build()
 
 void FormVSpace::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".
+       // the input field, insert nothing.
        validateVSpaceWidgets(dialog_->choice_space, dialog_->input_space);
 
        VSpace const space =
                setVSpaceFromWidgets(dialog_->choice_space,
                                     dialog_->input_space,
-                                    dialog_->choice_unit_space);
+                                    dialog_->choice_unit_space,
+                                    fl_get_button(dialog_->check_keep));
 
        controller().params() = space;
 }
@@ -240,10 +251,11 @@ void FormVSpace::update()
        setWidgetsFromVSpace(controller().params(),
                             dialog_->choice_space,
                             dialog_->input_space,
-                            dialog_->choice_unit_space);
+                            dialog_->choice_unit_space,
+                            dialog_->check_keep);
 
        bool const custom_length =
-               fl_get_choice(dialog_->choice_space) == 7;
+               fl_get_choice(dialog_->choice_space) == 6;
        setEnabled(dialog_->input_space, custom_length);
        setEnabled(dialog_->choice_unit_space, custom_length);
 }
@@ -251,13 +263,16 @@ void FormVSpace::update()
 
 ButtonPolicy::SMInput FormVSpace::input(FL_OBJECT * ob, long)
 {
-       // Enable input when custum length is choosen,
-       // disable 'keep' when no space is choosen
+       // Enable input when custom length is chosen,
+       // disable 'keep' when no space is chosen
        if (ob == dialog_->choice_space) {
                bool const custom_length =
-                       fl_get_choice(dialog_->choice_space) == 7;
+                       fl_get_choice(dialog_->choice_space) == 6;
                setEnabled(dialog_->input_space, custom_length);
                setEnabled(dialog_->choice_unit_space, custom_length);
        }
        return ButtonPolicy::SMI_VALID;
 }
+
+} // namespace frontend
+} // namespace lyx