]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / FormGraphics.C
index 9cb2b5ddcb6fc8131a97e5b55a4b04a91ee86542..026676d19438b6cda9bab2c9e0867ceb6490206f 100644 (file)
@@ -4,45 +4,58 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Baruch Even
- * \author Herbert Voss
+ * \author Herbert Voß
  * \author Rob Lahaye
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "xformsBC.h"
-#include "ControlGraphics.h"
 #include "FormGraphics.h"
+#include "ControlGraphics.h"
 #include "forms/form_graphics.h"
 
+#include "controllers/helper_funcs.h"
+
 #include "checkedwidgets.h"
 #include "input_validators.h"
 #include "Tooltips.h"
 #include "xforms_helpers.h"
+#include "xformsBC.h"
 
-#include "debug.h" // for lyxerr
 #include "lyxrc.h" // for lyxrc.display_graphics
 
 #include "insets/insetgraphicsParams.h"
 
-#include "controllers/helper_funcs.h" // for getStringFromVector
-
 #include "frontends/Alert.h"
 
-#include "support/tostr.h"
-#include "support/lstrings.h"  // for strToDbl
 #include "support/lyxlib.h"  // for float_equal
-#include "support/filetools.h"  // for MakeAbsPath etc
-
-#include "support/BoostFormat.h"
+#include "support/tostr.h"
 
 #include "lyx_forms.h"
 
+#include <cmath>
+
+#ifndef CXX_GLOBAL_CSTD
+using std::floor;
+#endif
+
 using std::endl;
+
 using std::vector;
+using std::string;
+
+namespace lyx {
+
+using support::bformat;
+using support::float_equal;
+using support::getStringFromVector;
+using support::strToDbl;
+using support::strToInt;
+using support::token;
 
+namespace frontend {
 
 namespace {
 
@@ -90,26 +103,26 @@ void FormGraphics::build()
        bcview().setCancel(dialog_->button_close);
        bcview().setRestore(dialog_->button_restore);
 
-       // the file section
+       // The file section.
        file_.reset(build_graphics_file(this));
 
-       // disable for read-only documents
+       // Disable for read-only documents.
        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
+       // Check validity of "length + unit" input.
        addCheckedGlueLength(bcview(), file_->input_width);
        addCheckedGlueLength(bcview(), file_->input_height);
 
-       // trigger an input event for cut&paste with middle mouse button.
+       // Trigger an input event for cut&paste with middle mouse button.
        setPrehandler(file_->input_filename);
        setPrehandler(file_->input_lyxscale);
        setPrehandler(file_->input_width);
        setPrehandler(file_->input_height);
 
-       // for activate ok/apply immediately upon input
+       // Activate ok/apply immediately upon input.
        fl_set_input_return(file_->input_filename, FL_RETURN_CHANGED);
        fl_set_input_return(file_->input_lyxscale, FL_RETURN_CHANGED);
        fl_set_input_return(file_->input_width, FL_RETURN_CHANGED);
@@ -118,7 +131,7 @@ void FormGraphics::build()
        fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
        fl_set_input_filter(file_->input_lyxscale, fl_unsigned_int_filter);
 
-       // width default is scaling: use unsigned float 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);
 
@@ -126,10 +139,11 @@ void FormGraphics::build()
                _("Default|Monochrome|Grayscale|Color|Do not display");
        fl_addto_choice(file_->choice_display, display_List.c_str());
 
-       string const width_list = bformat(_("Scale%%%%|%1$s"), choice_Length_All);
-       fl_addto_choice(file_->choice_width, width_list.c_str());
+       string const height_list = buildChoiceLengthString();
+       string const width_list = bformat(_("Scale%%%%|%1$s"), height_list);
 
-       fl_addto_choice(file_->choice_height, choice_Length_All.c_str());
+       fl_addto_choice(file_->choice_width, width_list.c_str());
+       fl_addto_choice(file_->choice_height, height_list.c_str());
 
        // set up the tooltips for the filesection
        string str = _("The file you want to insert.");
@@ -189,7 +203,7 @@ 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 = getStringFromVector(frnt::getBBUnits(), "|");
+       string const bb_units = getStringFromVector(getBBUnits(), "|");
        fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
 
        // set up the tooltips for the bounding-box-section
@@ -234,7 +248,6 @@ void FormGraphics::build()
 
        fl_set_input_filter(extra_->input_rotate_angle, fl_float_filter);
 
-       using namespace frnt;
        vector<RotationOriginPair> origindata = getRotationOriginData();
 
        // Store the identifiers for later
@@ -272,14 +285,14 @@ void FormGraphics::build()
 
        // set the right default unit
        switch (lyxrc.default_papersize) {
-       case BufferParams::PAPER_DEFAULT: break;
-       case BufferParams::PAPER_USLETTER:
-       case BufferParams::PAPER_LEGALPAPER:
-       case BufferParams::PAPER_EXECUTIVEPAPER: defaultUnit = "in"; break;
-       case BufferParams::PAPER_A3PAPER:
-       case BufferParams::PAPER_A4PAPER:
-       case BufferParams::PAPER_A5PAPER:
-       case BufferParams::PAPER_B5PAPER: defaultUnit = "cm"; break;
+       case PAPER_DEFAULT: break;
+       case PAPER_USLETTER:
+       case PAPER_LEGALPAPER:
+       case PAPER_EXECUTIVEPAPER: defaultUnit = "in"; break;
+       case PAPER_A3PAPER:
+       case PAPER_A4PAPER:
+       case PAPER_A5PAPER:
+       case PAPER_B5PAPER: defaultUnit = "cm"; break;
        }
 }
 
@@ -290,7 +303,8 @@ void FormGraphics::apply()
        InsetGraphicsParams & igp = controller().params();
 
        // the file section
-       igp.filename = getString(file_->input_filename);
+       igp.filename.set(getString(file_->input_filename),
+                        kernel().bufferFilepath());
 
        igp.lyxscale = strToInt(getString(file_->input_lyxscale));
        if (igp.lyxscale == 0) {
@@ -299,25 +313,25 @@ void FormGraphics::apply()
 
        switch (fl_get_choice(file_->choice_display)) {
        case 5:
-               igp.display = grfx::NoDisplay;
+               igp.display = graphics::NoDisplay;
                break;
        case 4:
-               igp.display = grfx::ColorDisplay;
+               igp.display = graphics::ColorDisplay;
                break;
        case 3:
-               igp.display = grfx::GrayscaleDisplay;
+               igp.display = graphics::GrayscaleDisplay;
                break;
        case 2:
-               igp.display = grfx::MonochromeDisplay;
+               igp.display = graphics::MonochromeDisplay;
                break;
        case 1:
-               igp.display = grfx::DefaultDisplay;
+               igp.display = graphics::DefaultDisplay;
        }
 
        // first item in choice_width means scaling
        if (fl_get_choice(file_->choice_width) == 1) {
                igp.scale = strToDbl(getString(file_->input_width));
-               if (lyx::float_equal(igp.scale, 0.0, 0.05)) {
+               if (float_equal(igp.scale, 0.0, 0.05)) {
                        igp.scale = 100.0;
                }
                igp.width = LyXLength();
@@ -395,12 +409,9 @@ void FormGraphics::apply()
        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;
-       }
-       while (igp.rotateAngle >=  360.0) {
-               igp.rotateAngle -= 360.0;
-       }
+       if (std::abs(igp.rotateAngle) > 360.0)
+               igp.rotateAngle -= 360.0 * floor(igp.rotateAngle / 360.0);
+
        fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
 
        int const origin_pos = fl_get_choice(extra_->choice_origin);
@@ -422,28 +433,30 @@ void FormGraphics::update() {
        InsetGraphicsParams & igp = controller().params();
 
        // the file section
-       fl_set_input(file_->input_filename, igp.filename.c_str());
+       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());
 
        switch (igp.display) {
-       case grfx::NoDisplay:
+       case graphics::NoDisplay:
                fl_set_choice(file_->choice_display, 5);
                break;
-       case grfx::ColorDisplay:
+       case graphics::ColorDisplay:
                fl_set_choice(file_->choice_display, 4);
                break;
-       case grfx::GrayscaleDisplay:
+       case graphics::GrayscaleDisplay:
                fl_set_choice(file_->choice_display, 3);
                break;
-       case grfx::MonochromeDisplay:
+       case graphics::MonochromeDisplay:
                fl_set_choice(file_->choice_display, 2);
                break;
-       case grfx::DefaultDisplay:
+       case graphics::DefaultDisplay:
                fl_set_choice(file_->choice_display, 1);
        }
 
        // set width input fields according to scaling or width/height input
-       if (!lyx::float_equal(igp.scale, 0.0, 0.05)) {
+       if (!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());
@@ -459,7 +472,7 @@ void FormGraphics::update() {
                                igp.height, defaultUnit);
 
        // disable height input in case of scaling
-       bool const disable_height = !lyx::float_equal(igp.scale, 0.0, 0.05);
+       bool const disable_height = !float_equal(igp.scale, 0.0, 0.05);
        setEnabled(file_->input_height, !disable_height);
        setEnabled(file_->choice_height, !disable_height);
 
@@ -477,7 +490,7 @@ void FormGraphics::update() {
        // the bb section
        // set the bounding box values, if exists. First we need the whole
        // path, because the controller knows nothing about the doc-dir
-       updateBB(igp.filename, igp.bb);
+       updateBB(igp.filename.absFilename(), igp.bb);
        fl_set_button(bbox_->check_clip, igp.clip);
 
        // the extra section
@@ -563,11 +576,15 @@ void FormGraphics::updateBB(string const & filename, string const & bb_inset)
 
 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
 {
+       ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
+
        // the file section
        if (ob == file_->button_browse) {
+               activate = ButtonPolicy::SMI_NOOP;
+
                // Get the filename from the dialog
                string const in_name = getString(file_->input_filename);
-               string const out_name = controller().Browse(in_name);
+               string const out_name = controller().browse(in_name);
                lyxerr[Debug::GRAPHICS]
                        << "[FormGraphics]out_name: " << out_name << endl;
                if (out_name != in_name && !out_name.empty()) {
@@ -634,7 +651,14 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                setEnabled(extra_->input_subcaption,
                           fl_get_button(extra_->check_subcaption));
 
+       } else if (ob == file_->button_edit) {
+               activate = ButtonPolicy::SMI_NOOP;
+               controller().editGraphics();
        }
 
-       return ButtonPolicy::SMI_VALID;
+
+       return activate;
 }
+
+} // namespace frontend
+} // namespace lyx