]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormDocument.C
layout as string
[lyx.git] / src / frontends / xforms / FormDocument.C
index f531cbb2ee60c7cfa10c3e8f45226396ce24eed0..f37303d53b4d6cdbdb1f572f5a67880f4b4022f5 100644 (file)
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
+#include <functional>
+
+using std::bind2nd;
+
 using Liason::setMinibuffer;
 using SigC::slot;
+using std::vector;
 
 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
        : FormBaseBD(lv, d, _("Document Layout")),
@@ -65,14 +70,14 @@ FormDocument::FormDocument(LyXView * lv, Dialogs * d)
 
 void FormDocument::redraw()
 {
-       if( form() && form()->visible )
-               fl_redraw_form( form() );
+       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 );
+               fl_redraw_form(outer_form);
 }
 
 
@@ -119,35 +124,23 @@ void FormDocument::build()
        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_inner_margin,
-                           fl_unsigned_float_filter);
-       fl_set_input_filter(paper_->input_outer_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...
-       std::vector<string> units_vec = getLatexUnits();
-       for (std::vector<string>::iterator it = units_vec.begin();
+       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
+       vector<string>::iterator ret =
+               remove_if(units_vec.begin(),
+                         units_vec.end(),
+                         bind2nd(contains_functor(), "%"));
+       units_vec.erase(ret, units_vec.end());
+#endif
        string units = getStringFromVector(units_vec, "|");
 
        fl_addto_choice(paper_->choice_custom_width_units,  units.c_str());
@@ -210,10 +203,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);
@@ -397,9 +389,9 @@ bool saveParamsAsDefault(BufferParams const &params)
 
 } //namespace
 
-bool FormDocument::input( FL_OBJECT * ob, long data )
+bool FormDocument::input(FL_OBJECT * ob, long data)
 {
-       State cb = static_cast<State>( data );
+       State cb = static_cast<State>(data);
 
        switch (cb) {
        case CHECKCHOICECLASS:
@@ -745,7 +737,7 @@ bool FormDocument::class_apply()
 
        if (params.textclass != old_class) {
                // try to load new_class
-               if (textclasslist.Load(params.textclass)) {
+               if (textclasslist[params.textclass].load()) {
                        // successfully loaded
                        redo = true;
                        setMinibuffer(lv_, _("Converting document to new document class..."));
@@ -755,7 +747,7 @@ bool FormDocument::class_apply()
                                lv_->buffer()->params);
                        if (ret) {
                                string s;
-                               if (ret==1) {
+                               if (ret == 1) {
                                        s = _("One paragraph couldn't be converted");
                                } else {
                                        s += tostr(ret);
@@ -953,10 +945,9 @@ void FormDocument::class_update(BufferParams const & params)
        if (!class_.get())
                return;
 
-       LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
+       LyXTextClass const & tclass = textclasslist[params.textclass];
 
-       combo_doc_class->select(
-               textclasslist.DescOfClass(params.textclass));
+       combo_doc_class->select(tclass.description());
        fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
        fl_clear_choice(class_->choice_doc_fontsize);
        fl_addto_choice(class_->choice_doc_fontsize, "default");
@@ -1022,9 +1013,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
@@ -1046,6 +1037,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;
        }
        }
@@ -1223,12 +1215,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);
@@ -1246,7 +1284,7 @@ bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
 }
 
 
-void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
+void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
 {
        BufferParams & param = lv_->buffer()->params;
 
@@ -1279,13 +1317,13 @@ void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
        BufferParams & param = lv_->buffer()->params;
 
        int data = 0;
-       if (cb == BULLETDEPTH1 )
+       if (cb == BULLETDEPTH1)
                data = 0;
-       else if (cb == BULLETDEPTH2 )
+       else if (cb == BULLETDEPTH2)
                data = 1;
-       else if (cb == BULLETDEPTH3 )
+       else if (cb == BULLETDEPTH3)
                data = 2;
-       else if (cb == BULLETDEPTH4 )
+       else if (cb == BULLETDEPTH4)
                data = 3;
 
        switch (fl_get_button_numb(ob)) {
@@ -1308,17 +1346,17 @@ void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
        /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
     
        int data = 0;
-       if (cb == BULLETPANEL1 )
+       if (cb == BULLETPANEL1)
                data = 0;
-       else if (cb == BULLETPANEL2 )
+       else if (cb == BULLETPANEL2)
                data = 1;
-       else if (cb == BULLETPANEL3 )
+       else if (cb == BULLETPANEL3)
                data = 2;
-       else if (cb == BULLETPANEL4 )
+       else if (cb == BULLETPANEL4)
                data = 3;
-       else if (cb == BULLETPANEL5 )
+       else if (cb == BULLETPANEL5)
                data = 4;
-       else if (cb == BULLETPANEL6 )
+       else if (cb == BULLETPANEL6)
                data = 5;
 
        if (data != current_bullet_panel) {
@@ -1364,7 +1402,7 @@ void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
 }
 
 
-void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
+void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
 {
        /* handle the user input by setting the current bullet depth's pixmap */
        /* to that extracted from the current chosen position of the BMTable  */
@@ -1390,7 +1428,7 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
        lv_->prohibitInput();
 
        unsigned int tc = combo_doc_class->get() - 1;
-       if (textclasslist.Load(tc)) {
+       if (textclasslist[tc].load()) {
                // we use a copy of the bufferparams because we do not
                // want to modify them yet.
                BufferParams params = lv_->buffer()->params;