]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
the convert patch
[lyx.git] / src / frontends / xforms / FormGraphics.C
index 3ce01d793f4b881028e1d3556a08100cc89e9d2c..d794ac0f4279a1641c17c221400d2af4ee790cbe 100644 (file)
@@ -31,7 +31,7 @@
 #include "frontends/Alert.h"
 
 #include "support/lyxlib.h"  // for float_equal
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include "lyx_forms.h"
 
@@ -51,8 +51,6 @@ namespace lyx {
 using support::bformat;
 using support::float_equal;
 using support::getStringFromVector;
-using support::strToDbl;
-using support::strToInt;
 using support::token;
 
 namespace frontend {
@@ -306,7 +304,7 @@ void FormGraphics::apply()
        igp.filename.set(getString(file_->input_filename),
                         kernel().bufferFilepath());
 
-       igp.lyxscale = strToInt(getString(file_->input_lyxscale));
+       igp.lyxscale = convert<int>(getString(file_->input_lyxscale));
        if (igp.lyxscale == 0) {
                igp.lyxscale = 100;
        }
@@ -331,12 +329,14 @@ void FormGraphics::apply()
        // first item in choice_width means scaling
        if (fl_get_choice(file_->choice_width) == 1) {
                igp.scale = getString(file_->input_width);
-               if (igp.scale.empty() || igp.scale == "0" || igp.scale == "100") {
-                       igp.scale = string();
+               if (igp.scale.empty()
+                       || float_equal(convert<double>(igp.scale), 0.0, 0.05)
+                       || float_equal(convert<double>(igp.scale), 100.0, 0.05)) {
+                       igp.scale.erase();
                }
                igp.width = LyXLength();
        } else {
-               igp.scale = string();
+               igp.scale.erase();
                igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
                                                           file_->choice_width));
        }
@@ -409,10 +409,10 @@ void FormGraphics::apply()
        igp.rotateAngle = getString(extra_->input_rotate_angle);
 
        // map angle into -360 (clock-wise) to +360 (counter clock-wise)
-       float rotAngle = strToDbl(igp.rotateAngle);
+       double rotAngle = convert<double>(igp.rotateAngle);
        if (std::abs(rotAngle) > 360.0) {
                 rotAngle -= 360.0 * floor(rotAngle / 360.0);
-                igp.rotateAngle = tostr(rotAngle);
+                igp.rotateAngle = convert<string>(rotAngle);
        }
 
        fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
@@ -439,7 +439,7 @@ void FormGraphics::update() {
        string const name =
                igp.filename.outputFilename(kernel().bufferFilepath());
        fl_set_input(file_->input_filename, name.c_str());
-       fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());
+       fl_set_input(file_->input_lyxscale, convert<string>(igp.lyxscale).c_str());
 
        switch (igp.display) {
        case graphics::NoDisplay:
@@ -459,7 +459,7 @@ void FormGraphics::update() {
        }
 
        // set width input fields according to scaling or width/height input
-       if (!igp.scale.empty() && igp.scale != "0") {
+       if (!igp.scale.empty() && !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
                fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
                fl_set_input_maxchars(file_->input_width, 0);
                fl_set_input(file_->input_width, igp.scale.c_str());
@@ -475,7 +475,8 @@ void FormGraphics::update() {
                                igp.height, defaultUnit);
 
        // disable height input in case of scaling
-       bool const disable_height = (!igp.scale.empty() && igp.scale != "0");
+       bool const disable_height = (!igp.scale.empty()
+               && !float_equal(convert<double>(igp.scale), 0.0, 0.05));
        setEnabled(file_->input_height, !disable_height);
        setEnabled(file_->choice_height, !disable_height);
 
@@ -499,11 +500,9 @@ void FormGraphics::update() {
        // the extra section
        fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
 
-       int origin_pos;
-       if (igp.rotateOrigin.empty()) {
-               origin_pos = 1;
-       } else {
-               origin_pos = 1 + findPos(origins_, igp.rotateOrigin);
+       int origin_pos = 1;
+       if (!igp.rotateOrigin.empty()) {
+               origin_pos += findPos(origins_, igp.rotateOrigin);
        }
        fl_set_choice(extra_->choice_origin, origin_pos);