/**
* \file FormGraphics.C
- * Copyright 2000-2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Baruch Even, baruch.even@writeme.com
- * \author Herbert Voss, voss@perce.de
+ * \author Baruch Even
+ * \author Herbert Voss
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
namespace {
// Bound the number of input characters
-int const SCALE_MAXDIGITS = 3; // %-value
-int const WIDTH_MAXDIGITS = 10;
-int const HEIGHT_MAXDIGITS = 10;
-int const ROTATE_MAXCHARS = 5; // like 270.1
+int const SIZE_MAXDIGITS = 10;
int const FILENAME_MAXCHARS = 1024;
+
string defaultUnit("cm");
/// Given input and choice widgets, create a LyXLength
typedef FormCB<ControlGraphics, FormDB<FD_graphics> > base_class;
-FormGraphics::FormGraphics(ControlGraphics & c, Dialogs & d)
- : base_class(c, d, _("Graphics"), false)
+FormGraphics::FormGraphics()
+ : base_class(_("Graphics"), false)
{}
file_.reset(build_graphics_file(this));
fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
- fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
- fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
- fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
- fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
- fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
+ fl_set_input_return (file_->input_lyxscale, FL_RETURN_CHANGED);
+ fl_set_input_return (file_->input_width, FL_RETURN_CHANGED);
+ fl_set_input_return (file_->input_height, FL_RETURN_CHANGED);
setPrehandler(file_->input_filename);
- setPrehandler(file_->input_subcaption);
- setPrehandler(file_->input_rotate_angle);
-
- using namespace frnt;
- vector<RotationOriginPair> origindata = getRotationOriginData();
-
- // Store the identifiers for later
- origins_ = getSecond(origindata);
-
- string const choice =
- " " + getStringFromVector(getFirst(origindata), " | ") +" ";
- fl_addto_choice(file_->choice_origin, choice.c_str());
-
- bc().addReadOnly(file_->button_browse);
- bc().addReadOnly(file_->check_subcaption);
- bc().addReadOnly(file_->check_rotate);
+ setPrehandler(file_->input_lyxscale);
+ setPrehandler(file_->input_width);
+ setPrehandler(file_->input_height);
+
+ fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
+ 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);
+ 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());
+
+ string const width_list = _("Scale%%|") + choice_Length_All;
+ fl_addto_choice(file_->choice_width, width_list.c_str());
+
+ fl_addto_choice(file_->choice_height, choice_Length_All.c_str());
+
+ bc().addReadOnly(file_->button_browse);
+ bc().addReadOnly(file_->check_aspectratio);
bc().addReadOnly(file_->check_draft);
bc().addReadOnly(file_->check_nounzip);
str = _("Browse the directories.");
tooltips().init(file_->button_browse, str);
- str = _("Enables use of subfigure with an own caption.");
- tooltips().init(file_->check_subcaption, str);
- str = _("Insert the an optional subfigure caption");
- tooltips().init(file_->input_subcaption, str);
-
- str = _("Enables use of rotating for the image.");
- tooltips().init(file_->check_rotate, str);
- str = _("Insert the rotating angle in degrees (max 5 characters like 270.1)");
- tooltips().init(file_->input_rotate_angle, str);
-
- str = _("Insert the rotating origin point.");
- tooltips().init(file_->choice_origin, str);
+ str = _("Scale the image to inserted percentage value.");
+ tooltips().init(file_->input_lyxscale, str);
+ str = _("Select display mode for this image.");
+ tooltips().init(file_->choice_display, str);
+
+ 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.");
+ tooltips().init(file_->choice_width, str);
+ str = _("Set the image height to the inserted value.");
+ tooltips().init(file_->input_height, str);
+ 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.");
+ tooltips().init(file_->check_aspectratio, str);
str = _("Pass a filename like \"file.eps.gz\" to the LaTeX output. "
- "This is 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.");
tooltips().init(file_->check_draft, str);
- // the lyxview section
- lyxview_.reset(build_graphics_lyxview(this));
-
- fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
- fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
- fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
-
- setPrehandler(lyxview_->input_lyxwidth);
- setPrehandler(lyxview_->input_lyxheight);
- setPrehandler(lyxview_->input_lyxscale);
-
- fl_addto_choice(lyxview_->choice_lyxwidth, choice_Length_WithUnit.c_str());
- fl_addto_choice(lyxview_->choice_lyxheight, choice_Length_WithUnit.c_str());
-
- bc().addReadOnly(lyxview_->radio_pref);
- bc().addReadOnly(lyxview_->radio_mono);
- bc().addReadOnly(lyxview_->radio_gray);
- bc().addReadOnly(lyxview_->radio_color);
- bc().addReadOnly(lyxview_->radio_nodisplay);
- bc().addReadOnly(lyxview_->check_lyxaspectratio);
-
- // set up the tooltips for the lyxview section
- str = _("Take the definition from the Preferences->Look&Feel->Misc as default.");
- tooltips().init(lyxview_->radio_pref, str);
- str = _("Show this image in black and white (monochrome).");
- tooltips().init(lyxview_->radio_mono, str);
- str = _("Show this image in grayscale.");
- tooltips().init(lyxview_->radio_gray, str);
- str = _("Show this image in color.");
- tooltips().init(lyxview_->radio_color, str);
- str = _("Do not display this image.");
- tooltips().init(lyxview_->radio_nodisplay, str);
-
- str = _("Copies all values from the LaTeX tab");
- tooltips().init(lyxview_->button_latex_values, str);
-
- str = _("Show this image in it's original size.");
- tooltips().init(lyxview_->radio_lyxasis, str);
- str = _("Scale the image down to the inserted values.");
- tooltips().init(lyxview_->radio_lyxwh, str);
- str = _("Scale the image down to the inserted value and keep aspectratio.");
- tooltips().init(lyxview_->radio_lyxscale, str);
-
- str = _("Insert a width in any valid unit to which the image in the LyX-view "
- "should be scaled up/down");
- tooltips().init(lyxview_->input_lyxwidth, str);
- str = _("Insert a height in any valid unit to which the image in the LyX-view "
- "should be scaled up/down");
- tooltips().init(lyxview_->input_lyxheight, str);
- str = _("Insert a value > 0 in persent to which the image should be scaled up/down");
- tooltips().init(lyxview_->input_lyxscale, str);
- str = _("Shows all possible units for the length");
- tooltips().init(lyxview_->choice_lyxwidth, str);
- tooltips().init(lyxview_->choice_lyxheight, str);
- str = _("Modifies the meaning of the \"width\" and \"height\" (and "
- "\"totalheight\") keys such that if both are specified then rather than "
- "distort the figure the figure is scaled such that neither dimension "
- "exceeds the stated dimensions.");
- tooltips().init(lyxview_->check_lyxaspectratio, str);
-
- // the size section
- size_.reset(build_graphics_size(this));
-
- fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
- fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
- fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
-
- setPrehandler(size_->input_scale);
- setPrehandler(size_->input_width);
- setPrehandler(size_->input_height);
-
- fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
- fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
- fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
-
- fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
-
- fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
- fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
-
- bc().addReadOnly(size_->radio_asis);
- bc().addReadOnly(size_->radio_wh);
- bc().addReadOnly(size_->radio_scale);
- bc().addReadOnly(size_->check_aspectratio);
-
- // set up the tooltips for the size section
- str = _("Copies all values from the LyX tab");
- tooltips().init(size_->button_lyx_values, str);
-
- str = _("Show this image in it's original size.");
- tooltips().init(size_->radio_asis, str);
- str = _("Scale the image down to the inserted values.");
- tooltips().init(size_->radio_wh, str);
- str = _("Scale the image down to the inserted value and keep aspectratio.");
- tooltips().init(size_->radio_scale, str);
-
- str = _("Modifies the meaning of the \"width\" and \"height\" (and "
- "\"totalheight\") keys such that if both are specified then rather than "
- "distort the figure the figure is scaled such that neither dimension "
- "exceeds the stated dimensions.");
- tooltips().init(size_->check_aspectratio, str);
-
- str = _("Insert a width in any valid unit to which the image in the LyX-view "
- "should be scaled up/down");
- tooltips().init(lyxview_->input_lyxwidth, str);
- str = _("Insert a height in any valid unit to which the image in the LyX-view "
- "should be scaled up/down");
- tooltips().init(lyxview_->input_lyxheight, str);
- str = _("Insert a value > 0 in persent to which the image should be scaled up/down");
- tooltips().init(lyxview_->input_lyxscale, str);
- str = _("Shows all possible units for the length");
- tooltips().init(lyxview_->choice_lyxwidth, str);
- tooltips().init(lyxview_->choice_lyxheight, str);
-
// the bounding box selection
bbox_.reset(build_graphics_bbox(this));
fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
- fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
- fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
- fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
- fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
+ fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
+ fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
+ fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
+ fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
setPrehandler(bbox_->input_bb_x0);
setPrehandler(bbox_->input_bb_y0);
tooltips().init(bbox_->input_bb_x1, str);
str = _("The upper right y-value of the bounding box");
tooltips().init(bbox_->input_bb_y1, str);
- str = _("Shows all possible units 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. If it's an (e)ps-file "
- "than the bounding box is read otherwise the imagesize in pixels. "
- "The default unit is \"bp\" the PostScript b)ig p)oint.");
+ "then the bounding box is read otherwise the imagesize in pixels. "
+ "Default unit is \"bp\", the PostScript's b(ig) p(oint).");
tooltips().init(bbox_->button_getBB, str);
- str = _("Enable this checkbox when the image should be clipped to the "
- "bounding box values.");
+ str = _("Clip image to the bounding box values.");
tooltips().init(bbox_->check_clip, str);
- // the rotate section
- special_.reset(build_graphics_special(this));
+ // the extra section
+ extra_.reset(build_graphics_extra(this));
+
+ fl_set_input_return (extra_->input_rotate_angle, FL_RETURN_CHANGED);
+ fl_set_input_return (extra_->input_subcaption, FL_RETURN_CHANGED);
+ fl_set_input_return (extra_->input_special, FL_RETURN_CHANGED);
+
+ fl_set_input_filter(extra_->input_rotate_angle, fl_float_filter);
+
+ setPrehandler(extra_->input_rotate_angle);
+ setPrehandler(extra_->input_subcaption);
+ setPrehandler(extra_->input_special);
+
+ bc().addReadOnly(extra_->check_subcaption);
- fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
- setPrehandler(special_->input_special);
+ using namespace frnt;
+ vector<RotationOriginPair> origindata = getRotationOriginData();
+
+ // Store the identifiers for later
+ origins_ = getSecond(origindata);
- // set up the tooltips for the special section
- str = _("Any additional option, which is defined in the graphicx-package "
- "and not mentioned in the gui's tabfolders can be defined.");
- tooltips().init(special_->input_special, str);
+ string const choice = "Default|" + 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.");
+ tooltips().init(extra_->input_rotate_angle, str);
+ str = _("Insert the point of origin for rotation.");
+ tooltips().init(extra_->choice_origin, str);
+ str = _("Enables use of subfigure with its own caption.");
+ tooltips().init(extra_->check_subcaption, str);
+ 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.");
+ tooltips().init(extra_->input_special, str);
// add the different tabfolders
fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
- fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
- fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
- fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
+ fl_addto_tabfolder(dialog_->tabfolder, _("Extra"), extra_->form);
// set the right default unit
- if (lyxrc.default_papersize < 3)
- defaultUnit = "in";
+ 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;
+ }
}
// the file section
igp.filename = getString(file_->input_filename);
- igp.subcaption = fl_get_button(file_->check_subcaption);
- igp.subcaptionText = getString(file_->input_subcaption);
- igp.rotate = fl_get_button(file_->check_rotate);
- igp.rotateAngle =
- strToDbl(getString(file_->input_rotate_angle));
- while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
- if (igp.rotateAngle < 0.0) {
- igp.rotateAngle += 360.0;
- } else if (igp.rotateAngle > 360.0) {
- igp.rotateAngle -= 360.0;
+
+ igp.lyxscale = strToInt(getString(file_->input_lyxscale));
+ if (igp.lyxscale == 0) {
+ igp.lyxscale = 100;
+ }
+
+ switch (fl_get_choice(file_->choice_display)) {
+ case 5: igp.display = grfx::NoDisplay; break;
+ case 4: igp.display = grfx::ColorDisplay; break;
+ case 3: igp.display = grfx::GrayscaleDisplay; break;
+ case 2: igp.display = grfx::MonochromeDisplay; break;
+ case 1:
+ default: igp.display = grfx::DefaultDisplay;
+ }
+
+ // first item in choice_width means scaling
+ if (fl_get_choice(file_->choice_width) == 1) {
+ igp.scale = strToInt(getString(file_->input_width));
+ if (igp.scale == 0) {
+ igp.scale = 100;
}
+ igp.width = LyXLength();
+ } else {
+ igp.scale = 0;
+ igp.width = getLyXLengthFromWidgets(file_->input_width,
+ file_->choice_width);
}
- int const pos = fl_get_choice(file_->choice_origin);
- if (pos > 0)
- igp.rotateOrigin = origins_[pos-1];
- else
- igp.rotateOrigin = string();
+ igp.height = getLyXLengthFromWidgets(file_->input_height,
+ file_->choice_height);
+ igp.keepAspectRatio = fl_get_button(file_->check_aspectratio);
igp.draft = fl_get_button(file_->check_draft);
igp.noUnzip = fl_get_button(file_->check_nounzip);
- // the lyxview section
- if (fl_get_button(lyxview_->radio_pref))
- igp.display = InsetGraphicsParams::DEFAULT;
- else if (fl_get_button(lyxview_->radio_mono))
- igp.display = InsetGraphicsParams::MONOCHROME;
- else if (fl_get_button(lyxview_->radio_gray))
- igp.display = InsetGraphicsParams::GRAYSCALE;
- else if (fl_get_button(lyxview_->radio_color))
- igp.display = InsetGraphicsParams::COLOR;
- else if (fl_get_button(lyxview_->radio_nodisplay))
- igp.display = InsetGraphicsParams::NONE;
-
- if (fl_get_button(lyxview_->radio_lyxasis))
- igp.lyxsize_kind = InsetGraphicsParams::DEFAULT_SIZE;
- else if (fl_get_button(lyxview_->radio_lyxwh))
- igp.lyxsize_kind = InsetGraphicsParams::WH;
- else
- igp.lyxsize_kind = InsetGraphicsParams::SCALE;
-
- igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
- lyxview_->choice_lyxwidth);
-
- igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
- lyxview_->choice_lyxheight);
-
- igp.lyxscale = strToInt(getString(lyxview_->input_lyxscale));
- igp.keepLyXAspectRatio = fl_get_button(lyxview_->check_lyxaspectratio);
-
- // the size section
- if (fl_get_button(size_->radio_asis))
- igp.size_kind = InsetGraphicsParams::DEFAULT_SIZE;
- else if (fl_get_button(size_->radio_wh))
- igp.size_kind = InsetGraphicsParams::WH;
- else
- igp.size_kind = InsetGraphicsParams::SCALE;
-
- igp.width = getLyXLengthFromWidgets(size_->input_width,
- size_->choice_width);
-
- igp.height = getLyXLengthFromWidgets(size_->input_height,
- size_->choice_height);
-
- igp.scale = strToInt(getString(size_->input_scale));
- igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
-
// the bb section
- if (!controller().bbChanged) // different to the original one?
- igp.bb = string(); // don't write anything
- else {
+ if (!controller().bbChanged) { // different to the original one?
+ igp.bb = string(); // don't write anything
+ } else {
string bb;
if (getString(bbox_->input_bb_x0).empty())
bb = "0 ";
}
igp.clip = fl_get_button(bbox_->check_clip);
- // the special section
- igp.special = getString(special_->input_special);
+ // 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;
+ }
+ while (igp.rotateAngle >= 360.0) {
+ 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);
+ if (origin_pos == 1) {
+ igp.rotateOrigin.erase();
+ } else {
+ igp.rotateOrigin = origins_[origin_pos - 2];
+ }
+
+ igp.subcaption = fl_get_button(extra_->check_subcaption);
+ igp.subcaptionText = getString(extra_->input_subcaption);
+
+ igp.special = getString(extra_->input_special);
}
// the file section
fl_set_input(file_->input_filename, igp.filename.c_str());
- fl_set_button(file_->check_subcaption, igp.subcaption);
- fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
- setEnabled(file_->input_subcaption,
- fl_get_button(file_->check_subcaption));
- fl_set_button(file_->check_rotate, igp.rotate);
- fl_set_input(file_->input_rotate_angle,
- tostr(igp.rotateAngle).c_str());
- if (igp.rotateOrigin.empty())
- fl_set_choice(file_->choice_origin,1);
- else {
- int pos = int(findPos(origins_, igp.rotateOrigin));
- fl_set_choice(file_->choice_origin, pos+1);
+ fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());
+
+ switch (igp.display) {
+ case grfx::NoDisplay: fl_set_choice(file_->choice_display, 5); break;
+ case grfx::ColorDisplay: fl_set_choice(file_->choice_display, 4); break;
+ case grfx::GrayscaleDisplay: fl_set_choice(file_->choice_display, 3); break;
+ case grfx::MonochromeDisplay: fl_set_choice(file_->choice_display, 2); break;
+ case grfx::DefaultDisplay:
+ default: fl_set_choice(file_->choice_display, 1);
+ }
+
+ // disable height input in case of scaling
+ setEnabled(file_->input_height, !igp.scale);
+ setEnabled(file_->choice_height, !igp.scale);
+
+ // set width input fields according to scaling or width/height input
+ if (igp.scale) {
+ fl_set_input_filter(file_->input_width, fl_unsigned_int_filter);
+ fl_set_input_maxchars(file_->input_width, 0);
+ fl_set_input(file_->input_width, tostr(igp.scale).c_str());
+ fl_set_choice(file_->choice_width, 1);
+ } else {
+ fl_set_input_filter(file_->input_width, NULL);
+ fl_set_input_maxchars(file_->input_width, SIZE_MAXDIGITS);
+ updateWidgetsFromLength(file_->input_width,
+ file_->choice_width, igp.width, defaultUnit);
}
- setEnabled(file_->input_rotate_angle,
- fl_get_button(file_->check_rotate));
- setEnabled(file_->choice_origin,
- fl_get_button(file_->check_rotate));
+ updateWidgetsFromLength(file_->input_height,
+ file_->choice_height, igp.height, defaultUnit);
+
+ fl_set_button(file_->check_aspectratio, igp.keepAspectRatio);
fl_set_button(file_->check_draft, igp.draft);
fl_set_button(file_->check_nounzip, igp.noUnzip);
- // the lyxview section
- switch (igp.display) {
- case InsetGraphicsParams::DEFAULT:
- fl_set_button(lyxview_->radio_pref, 1);
- break;
- case InsetGraphicsParams::MONOCHROME:
- fl_set_button(lyxview_->radio_mono, 1);
- break;
- case InsetGraphicsParams::GRAYSCALE:
- fl_set_button(lyxview_->radio_gray, 1);
- break;
- case InsetGraphicsParams::COLOR:
- fl_set_button(lyxview_->radio_color, 1);
- break;
- case InsetGraphicsParams::NONE:
- fl_set_button(lyxview_->radio_nodisplay, 1);
- break;
- }
- updateWidgetsFromLength(lyxview_->input_lyxwidth,
- lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
- updateWidgetsFromLength(lyxview_->input_lyxheight,
- lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
- fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
- switch (igp.lyxsize_kind) {
- case InsetGraphicsParams::DEFAULT_SIZE: {
- fl_set_button(lyxview_->radio_lyxasis,1);
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 0);
- setEnabled(lyxview_->input_lyxscale, 0);
- break;
- }
- case InsetGraphicsParams::SCALE: {
- fl_set_button(lyxview_->radio_lyxscale, 1);
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->input_lyxscale, 1);
- break;
- }
- case InsetGraphicsParams::WH: {
- fl_set_button(lyxview_->radio_lyxwh, 1);
- setEnabled(lyxview_->input_lyxwidth, 1);
- setEnabled(lyxview_->choice_lyxwidth, 1);
- setEnabled(lyxview_->input_lyxheight, 1);
- setEnabled(lyxview_->choice_lyxheight, 1);
- setEnabled(lyxview_->check_lyxaspectratio, 1);
- setEnabled(lyxview_->input_lyxscale, 0);
- break;
- }
- }
- fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
-
- fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
-
- // the size section
- // Update the draft and clip mode
- updateWidgetsFromLength(size_->input_width,
- size_->choice_width, igp.width, defaultUnit);
- updateWidgetsFromLength(size_->input_height,
- size_->choice_height, igp.height, defaultUnit);
- fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
- lyxerr[Debug::GRAPHICS] << "FormGraphics::update: igp.size_kind = "
- << igp.size_kind << endl;
- switch (igp.size_kind) {
- case InsetGraphicsParams::DEFAULT_SIZE: {
- fl_set_button(size_->radio_asis,1);
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 0);
- break;
- }
- case InsetGraphicsParams::SCALE: {
- fl_set_button(size_->radio_scale, 1);
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 1);
- break;
- }
- case InsetGraphicsParams::WH: {
- fl_set_button(size_->radio_wh, 1);
- setEnabled(size_->input_width, 1);
- setEnabled(size_->choice_width, 1);
- setEnabled(size_->input_height, 1);
- setEnabled(size_->choice_height, 1);
- setEnabled(size_->check_aspectratio, 1);
- setEnabled(size_->input_scale, 0);
- break;
- }
- }
- fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
+ // disable aspectratio button in case of scaling or one of width/height is empty
+ bool const disable_aspectRatio = igp.scale ||
+ getString(file_->input_width).empty() ||
+ getString(file_->input_height).empty();
+ setEnabled(file_->check_aspectratio, !disable_aspectRatio);
// the bb section
// set the bounding box values, if exists. First we need the whole
updateBB(igp.filename, igp.bb);
fl_set_button(bbox_->check_clip, igp.clip);
- // the special section
- fl_set_input(special_->input_special, igp.special.c_str());
+
+ // the extra section
+ fl_set_input(extra_->input_rotate_angle,
+ tostr(igp.rotateAngle).c_str());
+
+ int origin_pos;
+ if (igp.rotateOrigin.empty()) {
+ origin_pos = 1;
+ } else {
+ origin_pos = 2 + findPos(origins_, igp.rotateOrigin);
+ }
+ fl_set_choice(extra_->choice_origin, origin_pos);
+
+ fl_set_button(extra_->check_subcaption, igp.subcaption);
+ fl_set_input(extra_->input_subcaption, igp.subcaptionText.c_str());
+ setEnabled(extra_->input_subcaption,
+ fl_get_button(extra_->check_subcaption));
+ fl_set_input(extra_->input_special, igp.special.c_str());
+
+ // open dialog in the file-tab, whenever filename is empty
+ if (igp.filename.empty()) {
+ fl_set_folder(dialog_->tabfolder, file_->form);
+ }
}
// path, because the controller knows nothing about the doc-dir
controller().bbChanged = false;
if (bb_inset.empty()) {
- lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
+ lyxerr[Debug::GRAPHICS] << "FormGraphics::updateBB() [no BoundingBox]" << endl;
string const bb = controller().readBB(filename);
if (!bb.empty()) {
// get the values from the file
} else {
// get the values from the inset
- lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
+ lyxerr[Debug::GRAPHICS] << "FormGraphics::updateBB(): igp has BoundingBox"
+ << " ["<< bb_inset << "]"
<< endl;
controller().bbChanged = true;
+
LyXLength anyLength;
anyLength = LyXLength(token(bb_inset,' ',0));
updateWidgetsFromLength(bbox_->input_bb_x0,
}
}
+
namespace {
bool isValid(FL_OBJECT * ob)
fl_set_input(file_->input_filename, out_name.c_str());
}
if (controller().isFilenameValid(out_name) &&
- !controller().bbChanged)
+ !controller().bbChanged) {
updateBB(out_name, string());
-
- } else if (ob == file_->check_subcaption) {
- setEnabled(file_->input_subcaption,
- fl_get_button(file_->check_subcaption));
- } else if (ob == file_->check_rotate) {
- setEnabled(file_->input_rotate_angle,
- fl_get_button(file_->check_rotate));
- setEnabled(file_->choice_origin,
- fl_get_button(file_->check_rotate));
-
- // the lyxview section
- } else if (ob == lyxview_->radio_lyxasis) {
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 0);
- setEnabled(lyxview_->input_lyxscale, 0);
- } else if (ob == lyxview_->radio_lyxscale) {
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 0);
- setEnabled(lyxview_->input_lyxscale, 1);
- } else if (ob == lyxview_->radio_lyxwh) {
- setEnabled(lyxview_->input_lyxwidth, 1);
- setEnabled(lyxview_->choice_lyxwidth, 1);
- setEnabled(lyxview_->input_lyxheight, 1);
- setEnabled(lyxview_->choice_lyxheight, 1);
- setEnabled(lyxview_->check_lyxaspectratio, 1);
- setEnabled(lyxview_->input_lyxscale, 0);
- } else if (ob == lyxview_->button_latex_values) {
- if (contains(fl_get_choice_text(size_->choice_width),'%') ||
- contains(fl_get_choice_text(size_->choice_height),'%'))
- Alert::alert(_("Warning!"),
- _("The %-units are not allowed here."),
- _("Cannot use the values from LaTeX size!"));
- else {
- LyXLength dummy =
- getLyXLengthFromWidgets(size_->input_width,
- size_->choice_width);
- updateWidgetsFromLength(lyxview_->input_lyxwidth,
- lyxview_->choice_lyxwidth,
- dummy, defaultUnit);
-
- dummy = getLyXLengthFromWidgets(size_->input_height,
- size_->choice_height);
- updateWidgetsFromLength(lyxview_->input_lyxheight,
- lyxview_->choice_lyxheight,
- dummy, defaultUnit);
- string const scale = getString(size_->input_scale);
- fl_set_input(lyxview_->input_lyxscale, scale.c_str());
- if (fl_get_button (size_->radio_asis) == 1) {
- fl_set_button (lyxview_->radio_lyxasis, 1);
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 0);
- setEnabled(lyxview_->input_lyxscale, 0);
- } else if (fl_get_button (size_->radio_scale) ==1) {
- fl_set_button (lyxview_->radio_lyxscale, 1);
- setEnabled(lyxview_->input_lyxwidth, 0);
- setEnabled(lyxview_->choice_lyxwidth, 0);
- setEnabled(lyxview_->input_lyxheight, 0);
- setEnabled(lyxview_->choice_lyxheight, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 0);
- setEnabled(lyxview_->input_lyxscale, 1);
- } else if (fl_get_button (size_->radio_wh) == 1) {
- fl_set_button (lyxview_->radio_lyxwh, 1);
- setEnabled(lyxview_->input_lyxwidth, 1);
- setEnabled(lyxview_->choice_lyxwidth, 1);
- setEnabled(lyxview_->input_lyxheight, 1);
- setEnabled(lyxview_->choice_lyxheight, 1);
- setEnabled(lyxview_->check_lyxaspectratio, 1);
- setEnabled(lyxview_->input_lyxscale, 0);
- setEnabled(lyxview_->check_lyxaspectratio, 1);
- }
}
- fl_set_button(lyxview_->check_lyxaspectratio,
- fl_get_button(size_->check_aspectratio));
+ } else if (ob == file_->input_width || ob == file_->input_height) {
+ // disable aspectratio button in case of scaling or one of width/height is empty
+ bool const disable = fl_get_choice(file_->choice_width) == 1 ||
+ getString(file_->input_width).empty() ||
+ getString(file_->input_height).empty();
+ setEnabled(file_->check_aspectratio, !disable);
+ } else if (ob == file_->choice_width) {
+ // disable height input in case of scaling
+ 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_maxchars(file_->input_width, 0);
+ } else {
+ fl_set_input_filter(file_->input_width, NULL);
+ fl_set_input_maxchars(file_->input_width, SIZE_MAXDIGITS);
+ }
- // the bb section
+ // disable aspectratio button in case of scaling or height input is empty
+ bool const disable_aspectratio = scaling || getString(file_->input_height).empty();
+ setEnabled(file_->check_aspectratio, !disable_aspectratio);
+ // the bb section
} else if (!controller().bbChanged &&
(ob == bbox_->check_clip || ob == bbox_->choice_bb_units ||
ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
- string const unit("bp");
- fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
+ fl_set_choice_text(bbox_->choice_bb_units, "bp");
}
controller().bbChanged = false;
} else {
fl_set_input(bbox_->input_bb_y1, "");
fl_set_choice_text(bbox_->choice_bb_units, "bp");
}
+ // the extra section
+ } else if (ob == extra_->check_subcaption) {
+ setEnabled(extra_->input_subcaption,
+ fl_get_button(extra_->check_subcaption));
- // the size section
- } else if (ob == size_->radio_asis) {
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 0);
- } else if (ob == size_->radio_scale) {
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 1);
- } else if (ob == size_->radio_wh) {
- setEnabled(size_->input_width, 1);
- setEnabled(size_->choice_width, 1);
- setEnabled(size_->input_height, 1);
- setEnabled(size_->choice_height, 1);
- setEnabled(size_->check_aspectratio, 1);
- setEnabled(size_->input_scale, 0);
- } else if (ob == size_->button_lyx_values) {
- LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
- lyxview_->choice_lyxwidth);
- updateWidgetsFromLength(size_->input_width,
- size_->choice_width,
- dummy, defaultUnit);
- dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
- lyxview_->choice_lyxheight);
- updateWidgetsFromLength(size_->input_height,
- size_->choice_height,
- dummy, defaultUnit);
- string const scale = getString(lyxview_->input_lyxscale);
- fl_set_input(size_->input_scale, scale.c_str());
- if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
- fl_set_button (size_->radio_asis, 1);
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 0);
- } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
- fl_set_button (size_->radio_scale, 1);
- setEnabled(size_->input_width, 0);
- setEnabled(size_->choice_width, 0);
- setEnabled(size_->input_height, 0);
- setEnabled(size_->choice_height, 0);
- setEnabled(size_->check_aspectratio, 0);
- setEnabled(size_->input_scale, 1);
- } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
- fl_set_button (size_->radio_wh, 1);
- setEnabled(size_->input_width, 1);
- setEnabled(size_->choice_width, 1);
- setEnabled(size_->input_height, 1);
- setEnabled(size_->choice_height, 1);
- setEnabled(size_->check_aspectratio, 1);
- setEnabled(size_->input_scale, 0);
- }
- fl_set_button(size_->check_aspectratio,
- fl_get_button(lyxview_->check_lyxaspectratio));
}
// check if the input is valid
- bool invalid = !isValid(bbox_->input_bb_x0);
- invalid = invalid || !isValid(bbox_->input_bb_x1);
- invalid = invalid || !isValid(bbox_->input_bb_y0);
- invalid = invalid || !isValid(bbox_->input_bb_y1);
- invalid = invalid || !isValid(size_->input_width);
- invalid = invalid || !isValid(size_->input_height);
- invalid = invalid || !isValid(lyxview_->input_lyxwidth);
- invalid = invalid || !isValid(lyxview_->input_lyxheight);
-
- // deactivate OK/ Apply buttons and
- // spit out warnings if invalid
- if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
- ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
- ob == size_->input_width || ob == size_->input_height ||
- ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
- if (invalid) {
- postWarning(_("Invalid Length!"));
- return ButtonPolicy::SMI_INVALID;
- } else {
- clearMessage();
- }
- }
+ bool const invalid = !isValid(file_->input_width) || !isValid(file_->input_height);
- return ButtonPolicy::SMI_VALID;
+ // deactivate OK / Apply buttons and spit out warnings if invalid
+ if (invalid) {
+ postWarning(_("Invalid Length in Output size!"));
+ return ButtonPolicy::SMI_INVALID;
+ } else {
+ clearMessage();
+ return ButtonPolicy::SMI_VALID;
+ }
}