]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
remove defaults stuff, let Qt handle no toolbar
[lyx.git] / src / frontends / xforms / FormGraphics.C
index 46bf2111058e741de0b82a0cb9207ff8dfbedcee..32bd0e2011ec351a246e8f6c4c957d67505fd23e 100644 (file)
@@ -12,9 +12,6 @@
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "xformsBC.h"
 #include "ControlGraphics.h"
 #include "frontends/Alert.h"
 
 #include "support/lstrings.h"  // for strToDbl & tostr
+#include "support/lyxlib.h"  // for float_equal
 #include "support/filetools.h"  // for MakeAbsPath etc
 
+#include "support/BoostFormat.h"
+
 #include FORMS_H_LOCATION
 
 using std::endl;
@@ -55,10 +55,10 @@ string defaultUnit("cm");
 } // namespace anon
 
 
-typedef FormCB<ControlGraphics, FormDB<FD_graphics> > base_class;
+typedef FormController<ControlGraphics, FormView<FD_graphics> > base_class;
 
-FormGraphics::FormGraphics()
-       : base_class(_("Graphics"), false)
+FormGraphics::FormGraphics(Dialog & parent)
+       : base_class(parent, _("Graphics"), false)
 {}
 
 
@@ -79,23 +79,23 @@ void FormGraphics::build()
        dialog_.reset(build_graphics(this));
 
        // Manage the ok, apply, restore and cancel/close buttons
-       bc().setOK(dialog_->button_ok);
-       bc().setApply(dialog_->button_apply);
-       bc().setCancel(dialog_->button_close);
-       bc().setRestore(dialog_->button_restore);
+       bcview().setOK(dialog_->button_ok);
+       bcview().setApply(dialog_->button_apply);
+       bcview().setCancel(dialog_->button_close);
+       bcview().setRestore(dialog_->button_restore);
 
        // the file section
        file_.reset(build_graphics_file(this));
 
        // disable for read-only documents
-       bc().addReadOnly(file_->button_browse);   
-       bc().addReadOnly(file_->check_aspectratio);
-       bc().addReadOnly(file_->check_draft);
-       bc().addReadOnly(file_->check_nounzip);
+       bcview().addReadOnly(file_->button_browse);
+       bcview().addReadOnly(file_->check_aspectratio);
+       bcview().addReadOnly(file_->check_draft);
+       bcview().addReadOnly(file_->check_nounzip);
 
        // check validity of "length + unit" input
-       addCheckedGlueLength(bc(), file_->input_width);
-       addCheckedGlueLength(bc(), file_->input_height);
+       addCheckedGlueLength(bcview(), file_->input_width);
+       addCheckedGlueLength(bcview(), file_->input_height);
 
        // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(file_->input_filename);
@@ -110,61 +110,67 @@ void FormGraphics::build()
        fl_set_input_return(file_->input_height, FL_RETURN_CHANGED);
 
        fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
-       fl_set_input_filter(file_->input_lyxscale, fl_unsigned_float_filter);
+       fl_set_input_filter(file_->input_lyxscale, fl_unsigned_int_filter);
 
-       // width default is scaling, thus unsigned integer input
-       fl_set_input_filter(file_->input_width, fl_unsigned_int_filter);
+       // width default is scaling: use unsigned float filter
+       fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
        fl_set_input_maxchars(file_->input_height, SIZE_MAXDIGITS);
-       
+
        string const display_List =
                _("Default|Monochrome|Grayscale|Color|Do not display");
        fl_addto_choice(file_->choice_display, display_List.c_str());
-       
+
+#if USE_BOOST_FORMAT
+       string const width_list = boost::io::str(boost::format(_("Scale%%%%|%1$s")) % choice_Length_All);
+#else
+       // xgettext:no-c-format
        string const width_list = _("Scale%%|") + choice_Length_All;
+#endif
        fl_addto_choice(file_->choice_width, width_list.c_str());
 
        fl_addto_choice(file_->choice_height, choice_Length_All.c_str());
 
        // set up the tooltips for the filesection
-       string str = _("The file you want to insert");
+       string str = _("The file you want to insert.");
        tooltips().init(file_->input_filename, str);
-       str = _("Browse the directories");
+       str = _("Browse the directories.");
        tooltips().init(file_->button_browse, str);
 
-       str = _("Scale the image to inserted percentage value");
+       str = _("Scale the image to inserted percentage value.");
        tooltips().init(file_->input_lyxscale, str);
-       str = _("Select display mode for this image");
+       str = _("Select display mode for this image.");
        tooltips().init(file_->choice_display, str);
 
-       str = _("Set the image width to the inserted value");
+       str = _("Set the image width to the inserted value.");
        tooltips().init(file_->input_width, str);
-       str = _("Select unit for width; Scale% for scaling whole image");
+       // xgettext:no-c-format
+       str = _("Select unit for width; Scale% for scaling whole image.");
        tooltips().init(file_->choice_width, str);
-       str = _("Set the image height to the inserted value");
+       str = _("Set the image height to the inserted value.");
        tooltips().init(file_->input_height, str);
-       str = _("Select unit for height");
+       str = _("Select unit for height.");
        tooltips().init(file_->choice_height, str);
-       str = _("Do not distort the image. " 
-                "Keep image within \"width\" by \"height\" and obey "
-               "aspect ratio");
+       str = _("Do not distort the image. "
+               "Keep image within \"width\" by \"height\" and obey "
+               "aspect ratio.");
        tooltips().init(file_->check_aspectratio, str);
-
        str = _("Pass a filename like \"file.eps.gz\" to the LaTeX output. "
-           "Useful when LaTeX should unzip the file. Needs an additional file "
-           "like \"file.eps.bb\" which holds the values for the bounding box");
+               "Useful when LaTeX should unzip the file. Needs an additional "
+               "file like \"file.eps.bb\" which holds the values for "
+               "the bounding box.");
        tooltips().init(file_->check_nounzip, str);
-       str = _("Show image only as a rectangle of the original size");
+       str = _("Show image only as a rectangle of the original size.");
        tooltips().init(file_->check_draft, str);
 
        // the bounding box selection
        bbox_.reset(build_graphics_bbox(this));
 
        // disable for read-only documents
-       bc().addReadOnly(bbox_->button_getBB);
-       bc().addReadOnly(bbox_->check_clip);
+       bcview().addReadOnly(bbox_->button_getBB);
+       bcview().addReadOnly(bbox_->check_clip);
 
        // check validity of "length + unit" input
-       addCheckedLyXLength(bc(), bbox_->input_bb_x1, bbox_->text_X);
+       addCheckedLyXLength(bcview(), bbox_->input_bb_x1, bbox_->text_X);
 
        // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(bbox_->input_bb_x0);
@@ -182,39 +188,39 @@ void FormGraphics::build()
        fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
        fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
 
-       string const bb_units = "bp|cm|mm|in";
+       string const bb_units = getStringFromVector(frnt::getBBUnits(), "|");
        fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
 
        // set up the tooltips for the bounding-box-section
-       str = _("The lower left x-value of the bounding box");
+       str = _("The lower left x-value of the bounding box.");
        tooltips().init(bbox_->input_bb_x0, str);
-       str = _("The lower left y-value of the bounding box");
+       str = _("The lower left y-value of the bounding box.");
        tooltips().init(bbox_->input_bb_y0, str);
        str = _("The upper right x-value of the bounding box; "
                "only this input field allows length + unit, e.g. 5cm "
-               "and sets the unit for the other input fields");
+               "and sets the unit for the other input fields.");
        tooltips().init(bbox_->input_bb_x1, str);
-       str = _("The upper right y-value of the bounding box");
+       str = _("The upper right y-value of the bounding box.");
        tooltips().init(bbox_->input_bb_y1, str);
-       str = _("Select unit for the bounding box values");
+       str = _("Select unit for the bounding box values.");
        tooltips().init(bbox_->choice_bb_units, str);
 
        str = _("Read the image coordinates new from file. For (e)ps-file "
                "the bounding box is read, otherwise the imagesize in pixels. "
-               "Default unit is \"bp\", the PostScript's b(ig) p(oint)");
+               "Default unit is \"bp\", the PostScript's b(ig) p(oint).");
        tooltips().init(bbox_->button_getBB, str);
 
-       str = _("Clip image to the bounding box values");
+       str = _("Clip image to the bounding box values.");
        tooltips().init(bbox_->check_clip, str);
 
        // the extra section
        extra_.reset(build_graphics_extra(this));
 
        // disable for read-only documents
-       bc().addReadOnly(extra_->input_rotate_angle);
-       bc().addReadOnly(extra_->choice_origin);
-       bc().addReadOnly(extra_->check_subcaption);
-       bc().addReadOnly(extra_->input_special);
+       bcview().addReadOnly(extra_->input_rotate_angle);
+       bcview().addReadOnly(extra_->choice_origin);
+       bcview().addReadOnly(extra_->check_subcaption);
+       bcview().addReadOnly(extra_->input_special);
 
        // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(extra_->input_rotate_angle);
@@ -233,22 +239,22 @@ void FormGraphics::build()
        // Store the identifiers for later
        origins_ = getSecond(origindata);
 
-       string const choice = "Default|" + getStringFromVector(getFirst(origindata), "|");
+       string const choice = getStringFromVector(getFirst(origindata), "|");
        fl_addto_choice(extra_->choice_origin, choice.c_str());
 
        // set up the tooltips for the extra section
        str = _("Insert the rotation angle in degrees. "
-               "Positive value rotates anti-clockwise, "
-               "negative value clockwise");
+               "Positive value rotates anti-clockwise, "
+               "negative value clockwise.");
        tooltips().init(extra_->input_rotate_angle, str);
-       str = _("Insert the point of origin for rotation");
+       str = _("Insert the point of origin for rotation.");
        tooltips().init(extra_->choice_origin, str);
-       str = _("Enables use of subfigure with its own caption");
+       str = _("Enables use of subfigure with its own caption.");
        tooltips().init(extra_->check_subcaption, str);
-       str = _("Insert the optional subfigure caption");
+       str = _("Insert the optional subfigure caption.");
        tooltips().init(extra_->input_subcaption, str);
-       str = _("Add any additional latex option, which is defined in the "
-                "graphicx-package and not mentioned in the gui's tabfolders");
+       str = _("Add any additional LaTeX option, which is defined in the "
+               "graphicx-package and not mentioned in the gui's tabfolders.");
        tooltips().init(extra_->input_special, str);
 
        // add the different tabfolders
@@ -285,7 +291,7 @@ void FormGraphics::apply()
        if (igp.lyxscale == 0) {
                igp.lyxscale = 100;
        }
-       
+
        switch (fl_get_choice(file_->choice_display)) {
        case 5:
                igp.display = grfx::NoDisplay;
@@ -306,7 +312,7 @@ void FormGraphics::apply()
        // first item in choice_width means scaling
        if (fl_get_choice(file_->choice_width) == 1) {
                igp.scale = strToDbl(getString(file_->input_width));
-               if (igp.scale == 0.0) {
+               if (lyx::float_equal(igp.scale, 0.0, 0.05)) {
                        igp.scale = 100.0;
                }
                igp.width = LyXLength();
@@ -324,7 +330,7 @@ void FormGraphics::apply()
 
        // the bb section
        if (!controller().bbChanged) {
-               // don't write anything         
+               // don't write anything
                igp.bb.erase();
        } else {
                // allow length + unit input only for x1 input field
@@ -360,21 +366,21 @@ void FormGraphics::apply()
                        bb = getLengthFromWidgets(bbox_->input_bb_x0,
                                                  bbox_->choice_bb_units);
 
-               bb += " ";
+               bb += ' ';
 
                if (getString(bbox_->input_bb_y0).empty())
-                       bb += "0";
+                       bb += '0';
                else
                        bb += getLengthFromWidgets(bbox_->input_bb_y0,
                                                  bbox_->choice_bb_units);
 
-               bb += " " + x1_str + " ";
+               bb += ' ' + x1_str + ' ';
 
                if (getString(bbox_->input_bb_y1).empty())
-                       bb += "0";
+                       bb += '0';
                else
                        bb += getLengthFromWidgets(bbox_->input_bb_y1,
-                                                  bbox_->choice_bb_units); 
+                                                  bbox_->choice_bb_units);
 
                igp.bb = bb;
        }
@@ -382,7 +388,7 @@ void FormGraphics::apply()
 
        // the extra section
        igp.rotateAngle = strToDbl(getString(extra_->input_rotate_angle));
-       
+
        // map angle into -360 (clock-wise) to +360 (counter clock-wise)
        while (igp.rotateAngle <= -360.0) {
                igp.rotateAngle += 360.0;
@@ -393,10 +399,10 @@ void FormGraphics::apply()
        fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
 
        int const origin_pos = fl_get_choice(extra_->choice_origin);
-       if (origin_pos == 1) {
+       if (origin_pos == 0) {
                igp.rotateOrigin.erase();
        } else {
-               igp.rotateOrigin = origins_[origin_pos - 2];
+               igp.rotateOrigin = origins_[origin_pos - 1];
        }
 
        igp.subcaption = fl_get_button(extra_->check_subcaption);
@@ -432,7 +438,7 @@ void FormGraphics::update() {
        }
 
        // set width input fields according to scaling or width/height input
-       if (igp.scale) {
+       if (!lyx::float_equal(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, tostr(igp.scale).c_str());
@@ -448,10 +454,10 @@ void FormGraphics::update() {
                                igp.height, defaultUnit);
 
        // disable height input in case of scaling
-       bool const disable_height = igp.scale != 0.0;
+       bool const disable_height = !lyx::float_equal(igp.scale, 0.0, 0.05);
        setEnabled(file_->input_height, !disable_height);
        setEnabled(file_->choice_height, !disable_height);
-       
+
        fl_set_button(file_->check_aspectratio, igp.keepAspectRatio);
        fl_set_button(file_->check_draft, igp.draft);
        fl_set_button(file_->check_nounzip, igp.noUnzip);
@@ -477,7 +483,7 @@ void FormGraphics::update() {
        if (igp.rotateOrigin.empty()) {
                origin_pos = 1;
        } else {
-               origin_pos = 2 + findPos(origins_, igp.rotateOrigin);
+               origin_pos = 1 + findPos(origins_, igp.rotateOrigin);
        }
        fl_set_choice(extra_->choice_origin, origin_pos);
 
@@ -578,10 +584,10 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                bool const scaling = fl_get_choice(file_->choice_width) == 1;
                setEnabled(file_->input_height, !scaling);
                setEnabled(file_->choice_height, !scaling);
-               
+
                // allow only integer intput for scaling; float otherwise
                if (scaling) {
-                       fl_set_input_filter(file_->input_width, fl_unsigned_int_filter);
+                       fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
                        fl_set_input_maxchars(file_->input_width, 0);
                } else {
                        fl_set_input_filter(file_->input_width, NULL);