]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormGraphics.C
index 422286873456a447ab392729dc8dedc480c4353f..936c19bdcd954bc2799ddba8054ca0702fce7fa4 100644 (file)
 #include "FormGraphics.h"
 #include "form_graphics.h"
 
+#include "xforms_helpers.h"
 #include "input_validators.h"
 #include "debug.h" // for lyxerr
 #include "support/lstrings.h"  // for strToDbl & tostr
 #include "support/FileInfo.h"  // for FileInfo
 #include "insets/insetgraphicsParams.h"
+#include "lyxrc.h" // for lyxrc.display_graphics
 
 using std::endl;
 
-static double const tol = 1.0e-08;
+namespace {
+
+// Zero test for double precision numbers
+double const tol = 1.0e-08;
+
+// The maximum digits for the image scale
+int const SCALE_MAXDIGITS = 3;
+
+// The maximum digits for the image width
+int const WIDTH_MAXDIGITS = 3;
+
+// The maximum digits for the image height
+int const HEIGHT_MAXDIGITS = 3;
+
+// The max characters in the rotation angle (minus sign and 3 digits)
+int const ROTATE_MAXCHARS = 4;
+
+// The maximum characters in a filename.
+int const FILENAME_MAXCHARS = 1024;
+} // namespace anon
+
 
 typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
 
@@ -56,6 +79,7 @@ void FormGraphics::build()
        fl_set_input_return (dialog_->input_subcaption,   FL_RETURN_CHANGED);
 
        // Set the maximum characters that can be written in the input texts.
+       fl_set_input_maxchars(dialog_->input_scale,        SCALE_MAXDIGITS);
        fl_set_input_maxchars(dialog_->input_width,        WIDTH_MAXDIGITS);
        fl_set_input_maxchars(dialog_->input_height,       HEIGHT_MAXDIGITS);
        fl_set_input_maxchars(dialog_->input_filename,     FILENAME_MAXCHARS);
@@ -105,16 +129,29 @@ void FormGraphics::apply()
 
        igp.filename = fl_get_input(dialog_->input_filename);
 
-       if (fl_get_button(dialog_->check_display)) {
-               igp.display = InsetGraphicsParams::COLOR;
-       } else {
+       if (lyxrc.display_graphics == "no") {
                igp.display = InsetGraphicsParams::NONE;
+
+       } else {
+               if (fl_get_button(dialog_->check_display)) {
+                       if (lyxrc.display_graphics == "mono") {
+                               igp.display = InsetGraphicsParams::MONOCHROME;
+                       } else if (lyxrc.display_graphics == "gray") {
+                               igp.display = InsetGraphicsParams::GRAYSCALE;
+                       } else if (lyxrc.display_graphics == "color") {
+                               igp.display = InsetGraphicsParams::COLOR;
+                       }
+                       
+               } else {
+                       igp.display = InsetGraphicsParams::NONE;
+               }
        }
 
-       double const scale = strToDbl(fl_get_input(dialog_->input_scale));
+       double const scale =
+               strToDbl(strip(fl_get_input(dialog_->input_scale)));
        if (scale < tol) {
                double const width =
-                       strToDbl(fl_get_input(dialog_->input_width));
+                       strToDbl(strip(fl_get_input(dialog_->input_width)));
 
                if (width < tol) {
                        igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
@@ -140,7 +177,7 @@ void FormGraphics::apply()
                }
                
                double const height =
-                       strToDbl(fl_get_input(dialog_->input_height));
+                       strToDbl(strip(fl_get_input(dialog_->input_height)));
                
                if (height < tol) {
                        igp.heightResize = InsetGraphicsParams::DEFAULT_SIZE;
@@ -168,7 +205,8 @@ void FormGraphics::apply()
                igp.heightSize   = scale;
        }
        
-       igp.rotateAngle = strToDbl(fl_get_input(dialog_->input_rotate_angle));
+       igp.rotateAngle =
+               strToDbl(strip(fl_get_input(dialog_->input_rotate_angle)));
        while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
                if (igp.rotateAngle < 0.0) {
                        igp.rotateAngle += 360.0;
@@ -194,12 +232,18 @@ void FormGraphics::update()
                     igp.filename.c_str());
 
        // To display or not to display
-       if (igp.display == InsetGraphicsParams::NONE) {
+       if (lyxrc.display_graphics == "no") {
                fl_set_button(dialog_->check_display, 0);
        } else {
-               fl_set_button(dialog_->check_display, 1);
+               if (igp.display == InsetGraphicsParams::NONE) {
+                       fl_set_button(dialog_->check_display, 0);
+               } else {
+                       fl_set_button(dialog_->check_display, 1);
+               }
        }
 
+       setEnabled(dialog_->check_display, (lyxrc.display_graphics != "no"));
+
        if (igp.heightResize == InsetGraphicsParams::SCALE) {
                string number = tostr(igp.heightSize);
                fl_set_input(dialog_->input_scale, number.c_str());
@@ -218,7 +262,13 @@ void FormGraphics::update()
                fl_set_input(dialog_->input_width, number.c_str());
 
                int pos = 1;
+               //use inch as default with US papersizes in lyxrc
+               if (lyxrc.default_papersize < 3)
+                       pos = 2;
                switch (igp.widthResize) {
+               case InsetGraphicsParams::CM:
+                       pos = 1; break;
+
                case InsetGraphicsParams::INCH:
                        pos = 2; break;
 
@@ -240,7 +290,13 @@ void FormGraphics::update()
                fl_set_input(dialog_->input_height, number.c_str());
 
                pos = 1;
+               //use inch as default with US papersizes in lyxrc
+               if (lyxrc.default_papersize < 3)
+                       pos = 2;
                switch (igp.heightResize) {
+               case InsetGraphicsParams::CM:
+                       pos = 1; break;
+
                case InsetGraphicsParams::INCH:
                        pos = 2; break;
 
@@ -250,7 +306,7 @@ void FormGraphics::update()
                default:
                        break;
                }
-               fl_set_choice(dialog_->choice_width_units, pos);
+               fl_set_choice(dialog_->choice_height_units, pos);
        }
                
        // Update the rotate angle
@@ -263,8 +319,8 @@ void FormGraphics::update()
        fl_set_input(dialog_->input_subcaption,
                     igp.subcaptionText.c_str());
 
-       // Now make sure that the buttons are set correctly.
-       input(0, 0);
+       setEnabled(dialog_->input_subcaption,
+                  fl_get_button(dialog_->check_subcaption));
 }
 
 
@@ -282,7 +338,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
 
        if (ob == dialog_->input_scale) {
                double const scale =
-                       strToDbl(fl_get_input(dialog_->input_scale));
+                       strToDbl(strip(fl_get_input(dialog_->input_scale)));
                if (scale > tol) {
                        fl_set_input(dialog_->input_width, "");
                        fl_set_choice(dialog_->choice_width_units, 1);
@@ -293,15 +349,20 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
 
        if (ob == dialog_->input_width || ob == dialog_->input_height) {
                double const width =
-                       strToDbl(fl_get_input(dialog_->input_width));
+                       strToDbl(strip(fl_get_input(dialog_->input_width)));
                double const height =
-                       strToDbl(fl_get_input(dialog_->input_height));
+                       strToDbl(strip(fl_get_input(dialog_->input_height)));
 
                if (width > tol || height > tol) {
                        fl_set_input(dialog_->input_scale, "");
                }
        }
 
+       if (ob == dialog_->check_subcaption) {
+               setEnabled(dialog_->input_subcaption,
+                          fl_get_button(dialog_->check_subcaption));
+       }
+
        return checkInput();
 }