* 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.
#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/convert.h"
#include "lyx_forms.h"
-using namespace lyx::support;
+#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::token;
+
+namespace frontend {
namespace {
_("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.");
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
fl_set_input_filter(extra_->input_rotate_angle, fl_float_filter);
- using namespace frnt;
vector<RotationOriginPair> origindata = getRotationOriginData();
// Store the identifiers for later
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;
}
switch (fl_get_choice(file_->choice_display)) {
case 5:
- igp.display = lyx::graphics::NoDisplay;
+ igp.display = graphics::NoDisplay;
break;
case 4:
- igp.display = lyx::graphics::ColorDisplay;
+ igp.display = graphics::ColorDisplay;
break;
case 3:
- igp.display = lyx::graphics::GrayscaleDisplay;
+ igp.display = graphics::GrayscaleDisplay;
break;
case 2:
- igp.display = lyx::graphics::MonochromeDisplay;
+ igp.display = graphics::MonochromeDisplay;
break;
case 1:
- igp.display = lyx::graphics::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 (float_equal(igp.scale, 0.0, 0.05)) {
- igp.scale = 100.0;
+ igp.scale = getString(file_->input_width);
+ 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 = 0.0;
+ igp.scale.erase();
igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
file_->choice_width));
}
igp.clip = fl_get_button(bbox_->check_clip);
// the extra section
- igp.rotateAngle = strToDbl(getString(extra_->input_rotate_angle));
+ igp.rotateAngle = 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;
+ double rotAngle = convert<double>(igp.rotateAngle);
+ if (std::abs(rotAngle) > 360.0) {
+ rotAngle -= 360.0 * floor(rotAngle / 360.0);
+ igp.rotateAngle = convert<string>(rotAngle);
}
- while (igp.rotateAngle >= 360.0) {
- igp.rotateAngle -= 360.0;
- }
- fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
+
+ fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
int const origin_pos = fl_get_choice(extra_->choice_origin);
if (origin_pos == 0) {
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 lyx::graphics::NoDisplay:
+ case graphics::NoDisplay:
fl_set_choice(file_->choice_display, 5);
break;
- case lyx::graphics::ColorDisplay:
+ case graphics::ColorDisplay:
fl_set_choice(file_->choice_display, 4);
break;
- case lyx::graphics::GrayscaleDisplay:
+ case graphics::GrayscaleDisplay:
fl_set_choice(file_->choice_display, 3);
break;
- case lyx::graphics::MonochromeDisplay:
+ case graphics::MonochromeDisplay:
fl_set_choice(file_->choice_display, 2);
break;
- case lyx::graphics::DefaultDisplay:
+ case graphics::DefaultDisplay:
fl_set_choice(file_->choice_display, 1);
}
// set width input fields according to scaling or width/height input
- if (!float_equal(igp.scale, 0.0, 0.05)) {
+ 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, tostr(igp.scale).c_str());
+ fl_set_input(file_->input_width, igp.scale.c_str());
fl_set_choice(file_->choice_width, 1);
} else {
fl_set_input_filter(file_->input_width, NULL);
igp.height, defaultUnit);
// disable height input in case of scaling
- bool const disable_height = !float_equal(igp.scale, 0.0, 0.05);
+ 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);
fl_set_button(bbox_->check_clip, igp.clip);
// the extra section
- fl_set_input(extra_->input_rotate_angle,
- tostr(igp.rotateAngle).c_str());
+ 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);
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()) {
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