#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;
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);
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;
}
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;
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;
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());
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;
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;
default:
break;
}
- fl_set_choice(dialog_->choice_width_units, pos);
+ fl_set_choice(dialog_->choice_height_units, pos);
}
// Update the rotate angle
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));
}
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);
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();
}