]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormDocument.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormDocument.C
index 24246d1049acc07371e6db73b785f5b12f428181..c18b7d201cbee126888ce90f697cb87f06a612ec 100644 (file)
 #pragma implementation
 #endif
 
-#include "Alert.h"
 #include "FormDocument.h"
 #include "form_document.h"
+#include "Alert.h"
 #include "Dialogs.h"
-#include "layout.h"
+#include "lyxtextclasslist.h"
 #include "combox.h"
 #include "tex-strings.h"
 #include "bufferparams.h"
-#include "insets/insetquotes.h"
 #include "vspace.h"
 #include "bmtable.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
 #include "language.h"
 #include "LyXView.h"
 #include "lyxfunc.h"
 #include "helper_funcs.h" 
 #include "lyx_main.h" // for user_lyxdir
 
+#include "insets/insetquotes.h"
+
+#include "support/filetools.h"
+#include "support/lstrings.h"
+
 using Liason::setMinibuffer;
 using SigC::slot;
 
@@ -108,36 +109,16 @@ void FormDocument::build()
                          "| Very small Margins "
                          "| Very wide Margins "));
 
-       fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_custom_width,  FL_RETURN_CHANGED);
        fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_top_margin,    FL_RETURN_CHANGED);
        fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
-       fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_inner_margin,  FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_outer_margin,  FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_head_height,   FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_head_sep,      FL_RETURN_CHANGED);
+       fl_set_input_return(paper_->input_foot_skip,     FL_RETURN_CHANGED);
 
-       // Set input filters on width and height to make them accept only
-       // unsigned numbers.
-       fl_set_input_filter(paper_->input_custom_width,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_custom_height,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_top_margin,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_bottom_margin,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_left_margin,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_right_margin,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_head_height,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_head_sep,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_foot_skip,
-                           fl_unsigned_float_filter);
 
        // Create the contents of the unit choices
        // Don't include the "%" terms...
@@ -153,8 +134,8 @@ void FormDocument::build()
        fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
        fl_addto_choice(paper_->choice_top_margin_units,    units.c_str());
        fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
-       fl_addto_choice(paper_->choice_left_margin_units,   units.c_str());
-       fl_addto_choice(paper_->choice_right_margin_units,  units.c_str());
+       fl_addto_choice(paper_->choice_inner_margin_units,  units.c_str());
+       fl_addto_choice(paper_->choice_outer_margin_units,  units.c_str());
        fl_addto_choice(paper_->choice_head_height_units,   units.c_str());
        fl_addto_choice(paper_->choice_head_sep_units,      units.c_str());
        fl_addto_choice(paper_->choice_foot_skip_units,     units.c_str());
@@ -169,8 +150,8 @@ void FormDocument::build()
        bc().addReadOnly (paper_->input_custom_height);
        bc().addReadOnly (paper_->input_top_margin);
        bc().addReadOnly (paper_->input_bottom_margin);
-       bc().addReadOnly (paper_->input_left_margin);
-       bc().addReadOnly (paper_->input_right_margin);
+       bc().addReadOnly (paper_->input_inner_margin);
+       bc().addReadOnly (paper_->input_outer_margin);
        bc().addReadOnly (paper_->input_head_height);
        bc().addReadOnly (paper_->input_head_sep);
        bc().addReadOnly (paper_->input_foot_skip);
@@ -209,10 +190,9 @@ void FormDocument::build()
        fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
        fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
 
-       // Set input filters on doc skip to make it accept only
+       // Set input filters on doc spacing to make it accept only
        // unsigned numbers.
-       fl_set_input_filter(class_->input_doc_skip,
-                           fl_unsigned_float_filter);
+       fl_set_input_filter(class_->input_doc_spacing, fl_unsigned_float_filter);
 
        bc().addReadOnly (class_->radio_doc_indent);
        bc().addReadOnly (class_->radio_doc_skip);
@@ -450,8 +430,10 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
                setEnabled(class_->choice_default_skip_units,
                           skip_used && length_input);
                // Default unit choice is cm if metric, inches if US paper.
+               // If papersize is default, check the lyxrc-settings
                int const paperchoice = fl_get_choice(paper_->choice_papersize);
-               bool const metric = paperchoice < 3 || paperchoice > 5;
+               bool const metric = (paperchoice == 1 && lyxrc.default_papersize > 3)
+                       || paperchoice == 2 || paperchoice > 5;
                int const default_unit = metric ? 8 : 9;
                if (strip(fl_get_input(class_->input_doc_skip)).empty())
                        fl_set_choice(class_->choice_default_skip_units,
@@ -486,6 +468,7 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
 
        if (ob == paper_->choice_papersize) {
                int const paperchoice = fl_get_choice(paper_->choice_papersize);
+               bool const defsize = paperchoice == 1;
                bool const custom = paperchoice == 2;
                bool const a3size = paperchoice == 6;
                bool const b3size = paperchoice == 9;
@@ -500,15 +483,15 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
 
                setEnabled(paper_->input_top_margin,    use_geom);
                setEnabled(paper_->input_bottom_margin, use_geom);
-               setEnabled(paper_->input_left_margin,   use_geom);
-               setEnabled(paper_->input_right_margin,  use_geom);
+               setEnabled(paper_->input_inner_margin,  use_geom);
+               setEnabled(paper_->input_outer_margin,  use_geom);
                setEnabled(paper_->input_head_height,   use_geom);
                setEnabled(paper_->input_head_sep,      use_geom);
                setEnabled(paper_->input_foot_skip,     use_geom);
                setEnabled(paper_->choice_top_margin_units,    use_geom);
                setEnabled(paper_->choice_bottom_margin_units, use_geom);
-               setEnabled(paper_->choice_left_margin_units,   use_geom);
-               setEnabled(paper_->choice_right_margin_units,  use_geom);
+               setEnabled(paper_->choice_inner_margin_units,  use_geom);
+               setEnabled(paper_->choice_outer_margin_units,  use_geom);
                setEnabled(paper_->choice_head_height_units,   use_geom);
                setEnabled(paper_->choice_head_sep_units,      use_geom);
                setEnabled(paper_->choice_foot_skip_units,     use_geom);
@@ -523,11 +506,13 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
                setEnabled(paper_->radio_landscape, !custom);
 
                // Default unit choice is cm if metric, inches if US paper.
-               bool const metric = paperchoice < 3 || paperchoice > 5;
+               // If papersize is default, use the lyxrc-settings
+               bool const metric = (defsize && lyxrc.default_papersize > 3)
+                       || paperchoice == 2 || paperchoice > 5;
                int const default_unit = metric ? 8 : 9;
                if (strip(fl_get_input(paper_->input_custom_width)).empty())
-                       fl_set_choice(paper_->choice_custom_width_units,
-                                     default_unit);
+               fl_set_choice(paper_->choice_custom_width_units,
+                             default_unit);
                if (strip(fl_get_input(paper_->input_custom_height)).empty())
                        fl_set_choice(paper_->choice_custom_height_units,
                                      default_unit);
@@ -537,11 +522,11 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
                if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
                        fl_set_choice(paper_->choice_bottom_margin_units,
                                      default_unit);
-               if (strip(fl_get_input(paper_->input_left_margin)).empty())
-                       fl_set_choice(paper_->choice_left_margin_units,
+               if (strip(fl_get_input(paper_->input_inner_margin)).empty())
+                       fl_set_choice(paper_->choice_inner_margin_units,
                                      default_unit);
-               if (strip(fl_get_input(paper_->input_right_margin)).empty())
-                       fl_set_choice(paper_->choice_right_margin_units,
+               if (strip(fl_get_input(paper_->input_outer_margin)).empty())
+                       fl_set_choice(paper_->choice_outer_margin_units,
                                      default_unit);
                if (strip(fl_get_input(paper_->input_head_height)).empty())
                        fl_set_choice(paper_->choice_head_height_units,
@@ -573,15 +558,15 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
 
                        setEnabled(paper_->input_top_margin,    false);
                        setEnabled(paper_->input_bottom_margin, false);
-                       setEnabled(paper_->input_left_margin,   false);
-                       setEnabled(paper_->input_right_margin,  false);
+                       setEnabled(paper_->input_inner_margin,  false);
+                       setEnabled(paper_->input_outer_margin,  false);
                        setEnabled(paper_->input_head_height,   false);
                        setEnabled(paper_->input_head_sep,      false);
                        setEnabled(paper_->input_foot_skip,     false);
                        setEnabled(paper_->choice_top_margin_units,    false);
                        setEnabled(paper_->choice_bottom_margin_units, false);
-                       setEnabled(paper_->choice_left_margin_units,   false);
-                       setEnabled(paper_->choice_right_margin_units,  false);
+                       setEnabled(paper_->choice_inner_margin_units,  false);
+                       setEnabled(paper_->choice_outer_margin_units,  false);
                        setEnabled(paper_->choice_head_height_units,   false);
                        setEnabled(paper_->choice_head_sep_units,      false);
                        setEnabled(paper_->choice_foot_skip_units,     false);
@@ -601,15 +586,15 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
                bool const use_geom = fl_get_button(paper_->check_use_geometry);
                setEnabled(paper_->input_top_margin,    use_geom);
                setEnabled(paper_->input_bottom_margin, use_geom);
-               setEnabled(paper_->input_left_margin,   use_geom);
-               setEnabled(paper_->input_right_margin,  use_geom);
+               setEnabled(paper_->input_inner_margin,  use_geom);
+               setEnabled(paper_->input_outer_margin,  use_geom);
                setEnabled(paper_->input_head_height,   use_geom);
                setEnabled(paper_->input_head_sep,      use_geom);
                setEnabled(paper_->input_foot_skip,     use_geom);
                setEnabled(paper_->choice_top_margin_units,    use_geom);
                setEnabled(paper_->choice_bottom_margin_units, use_geom);
-               setEnabled(paper_->choice_left_margin_units,   use_geom);
-               setEnabled(paper_->choice_right_margin_units,  use_geom);
+               setEnabled(paper_->choice_inner_margin_units,  use_geom);
+               setEnabled(paper_->choice_outer_margin_units,  use_geom);
                setEnabled(paper_->choice_head_height_units,   use_geom);
                setEnabled(paper_->choice_head_sep_units,      use_geom);
                setEnabled(paper_->choice_foot_skip_units,     use_geom);
@@ -745,7 +730,8 @@ bool FormDocument::class_apply()
                        setMinibuffer(lv_, _("Converting document to new document class..."));
                        int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
                                old_class, params.textclass,
-                               lv_->buffer()->paragraph);
+                               lv_->buffer()->paragraph,
+                               lv_->buffer()->params);
                        if (ret) {
                                string s;
                                if (ret==1) {
@@ -797,16 +783,16 @@ void FormDocument::paper_apply(BufferParams & params)
                                     paper_->choice_custom_height_units);
 
        params.leftmargin =
-               getLengthFromWidgets(paper_->input_left_margin,
-                                    paper_->choice_left_margin_units);
+               getLengthFromWidgets(paper_->input_inner_margin,
+                                    paper_->choice_inner_margin_units);
 
        params.topmargin =
                getLengthFromWidgets(paper_->input_top_margin,
                                     paper_->choice_top_margin_units);
 
        params.rightmargin =
-               getLengthFromWidgets(paper_->input_right_margin,
-                                    paper_->choice_right_margin_units);
+               getLengthFromWidgets(paper_->input_outer_margin,
+                                    paper_->choice_outer_margin_units);
 
        params.bottommargin =
                getLengthFromWidgets(paper_->input_bottom_margin,
@@ -863,11 +849,21 @@ bool FormDocument::language_apply(BufferParams & params)
        else
                params.quotes_times = InsetQuotes::DoubleQ;
 
+       Language const * old_language = params.language;
        Language const * new_language = 
                languages.getLanguage(combo_language->getline());
        if (!new_language)
                new_language = default_language;
 
+       if (old_language != new_language
+           && old_language->RightToLeft() == params.language->RightToLeft()
+           && !lv_->buffer()->isMultiLingual())
+               lv_->buffer()->changeLanguage(old_language, params.language);
+
+       if (old_language != new_language) {
+               redo = true;
+       }
+
        params.language = new_language;
        params.inputenc = fl_get_choice_text(language_->choice_inputenc);
 
@@ -877,20 +873,7 @@ bool FormDocument::language_apply(BufferParams & params)
 
 bool FormDocument::language_apply()
 {
-       BufferParams & params = lv_->buffer()->params;
-       Language const * old_language = params.language;
-
-       bool redo = language_apply(params);
-
-       if (old_language != params.language
-           && old_language->RightToLeft() == params.language->RightToLeft()
-           && !lv_->buffer()->isMultiLingual())
-               lv_->buffer()->changeLanguage(old_language, params.language);
-       if (old_language != params.language) {
-               redo = true;
-       }
-
-       return redo;
+       return language_apply(lv_->buffer()->params);
 }
 
 
@@ -989,13 +972,14 @@ void FormDocument::class_update(BufferParams const & params)
                break;
        case VSpace::LENGTH:
        {
-               int const paperchoice = params.papersize2 + 1;
-               bool const metric = paperchoice < 3 || paperchoice > 5;
+               int const paperchoice = fl_get_choice(paper_->choice_papersize);
+               bool const metric = (paperchoice == 1 && lyxrc.default_papersize > 3)
+                       || paperchoice == 2 || paperchoice > 5;
                string const default_unit = metric ? "cm" : "in";
                string const length = params.getDefSkip().asLyXCommand();
                updateWidgetsFromLengthString(class_->input_doc_skip,
-                                             class_->choice_default_skip_units,
-                                             length, default_unit);
+                                     class_->choice_default_skip_units,
+                                     length, default_unit);
                break;
        }
        default:
@@ -1017,9 +1001,9 @@ void FormDocument::class_update(BufferParams const & params)
                fl_set_button(class_->radio_doc_columns_two, 1);
        else
                fl_set_button(class_->radio_doc_columns_one, 1);
        fl_set_input(class_->input_doc_spacing, "");
-
-       setEnabled(class_->input_doc_spacing, input_length);
+       setEnabled(class_->input_doc_spacing, false);
 
        switch (params.spacing.getSpace()) {
        case Spacing::Default: // nothing bad should happen with this
@@ -1041,6 +1025,7 @@ void FormDocument::class_update(BufferParams const & params)
                char sval[20];
                sprintf(sval,"%g",params.spacing.getValue()); 
                fl_set_input(class_->input_doc_spacing, sval);
+               setEnabled(class_->input_doc_spacing, true);
                break;
        }
        }
@@ -1120,11 +1105,12 @@ void FormDocument::paper_update(BufferParams const & params)
                   && fl_get_button(paper_->radio_portrait));
 
        // Default unit choice is cm if metric, inches if US paper.
-       bool const metric = paperchoice < 3 || paperchoice > 5;
+       bool const metric = (paperchoice == 1 && lyxrc.default_papersize > 3)
+                       || paperchoice == 2 || paperchoice > 5;
        string const default_unit = metric ? "cm" : "in";
        updateWidgetsFromLengthString(paper_->input_custom_width,
-                                     paper_->choice_custom_width_units,
-                                     params.paperwidth, default_unit);
+                             paper_->choice_custom_width_units,
+                             params.paperwidth, default_unit);
        setEnabled(paper_->input_custom_width, useCustom);
        setEnabled(paper_->choice_custom_width_units, useCustom);
 
@@ -1134,11 +1120,11 @@ void FormDocument::paper_update(BufferParams const & params)
        setEnabled(paper_->input_custom_height, useCustom);
        setEnabled(paper_->choice_custom_height_units, useCustom);
 
-       updateWidgetsFromLengthString(paper_->input_left_margin,
-                                     paper_->choice_left_margin_units,
+       updateWidgetsFromLengthString(paper_->input_inner_margin,
+                                     paper_->choice_inner_margin_units,
                                      params.leftmargin, default_unit);
-       setEnabled(paper_->input_left_margin, useGeom);
-       setEnabled(paper_->choice_left_margin_units, useGeom);
+       setEnabled(paper_->input_inner_margin, useGeom);
+       setEnabled(paper_->choice_inner_margin_units, useGeom);
 
        updateWidgetsFromLengthString(paper_->input_top_margin,
                                      paper_->choice_top_margin_units,
@@ -1146,11 +1132,11 @@ void FormDocument::paper_update(BufferParams const & params)
        setEnabled(paper_->input_top_margin, useGeom);
        setEnabled(paper_->choice_top_margin_units, useGeom);
 
-       updateWidgetsFromLengthString(paper_->input_right_margin,
-                                     paper_->choice_right_margin_units,
+       updateWidgetsFromLengthString(paper_->input_outer_margin,
+                                     paper_->choice_outer_margin_units,
                                      params.rightmargin, default_unit);
-       setEnabled(paper_->input_right_margin, useGeom);
-       setEnabled(paper_->choice_right_margin_units, useGeom);
+       setEnabled(paper_->input_outer_margin, useGeom);
+       setEnabled(paper_->choice_outer_margin_units, useGeom);
 
        updateWidgetsFromLengthString(paper_->input_bottom_margin,
                                      paper_->choice_bottom_margin_units,
@@ -1217,12 +1203,58 @@ void FormDocument::checkReadOnly()
 }
 
 
-bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
+bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
 {
        string str;
        bool ok = true;
        char const * input;
 
+       // this has to be all out of if/elseif because it has to deactivate
+       // the document buttons and so the whole stuff has to be tested again.
+       // disable OK/Apply if input is not valid
+       str = fl_get_input(class_->input_doc_skip);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_custom_width);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_custom_height);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_outer_margin);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_inner_margin);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_top_margin);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_bottom_margin);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_head_height);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_head_sep);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+       str = fl_get_input(paper_->input_foot_skip);
+       ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str));
+
+       //display warning if input is not valid
+       if (ob == class_->input_doc_skip
+                       || ob == paper_->input_custom_width
+                       || ob == paper_->input_custom_height
+                       || ob == paper_->input_outer_margin
+                       || ob == paper_->input_inner_margin
+                       || ob == paper_->input_top_margin
+                       || ob == paper_->input_bottom_margin
+                       || ob == paper_->input_head_height
+                       || ob == paper_->input_head_sep
+                       || ob == paper_->input_foot_skip) {
+               if (!ok) {
+                       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;
+               }
+       }
+
        // "Synchronize" the choice and the input field, so that it
        // is impossible to commit senseless data.
        input = fl_get_input (class_->input_doc_skip);