2002-03-11 17:00:41 +00:00
|
|
|
/**
|
2001-03-28 13:11:08 +00:00
|
|
|
* \file FormGraphics.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-11 17:00:41 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Baruch Even
|
|
|
|
* \author Herbert Voss
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2000-07-31 12:30:10 +00:00
|
|
|
*/
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <config.h>
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
2002-03-21 21:21:28 +00:00
|
|
|
#endif
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlGraphics.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "FormGraphics.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_graphics.h"
|
2002-03-08 11:05:48 +00:00
|
|
|
#include "Alert.h"
|
2002-07-22 12:36:41 +00:00
|
|
|
#include "Tooltips.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2001-09-13 12:37:40 +00:00
|
|
|
#include "xforms_helpers.h"
|
2002-05-01 09:25:51 +00:00
|
|
|
#include "helper_funcs.h"
|
2001-03-28 13:11:08 +00:00
|
|
|
#include "input_validators.h"
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "debug.h" // for lyxerr
|
2000-12-11 09:46:09 +00:00
|
|
|
#include "support/lstrings.h" // for strToDbl & tostr
|
2002-01-29 09:26:24 +00:00
|
|
|
#include "support/filetools.h" // for MakeAbsPath etc
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "insets/insetgraphicsParams.h"
|
2001-09-18 10:58:35 +00:00
|
|
|
#include "lyxrc.h" // for lyxrc.display_graphics
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-07-31 13:36:03 +00:00
|
|
|
using std::endl;
|
2002-05-01 09:25:51 +00:00
|
|
|
using std::vector;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-10-23 09:03:17 +00:00
|
|
|
namespace {
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
// Bound the number of input characters
|
2002-08-27 20:30:20 +00:00
|
|
|
int const SIZE_MAXDIGITS = 10;
|
2001-10-23 09:03:17 +00:00
|
|
|
int const FILENAME_MAXCHARS = 1024;
|
2002-08-24 22:02:30 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
string defaultUnit("cm");
|
|
|
|
|
2002-03-21 16:51:33 +00:00
|
|
|
/// Given input and choice widgets, create a LyXLength
|
|
|
|
LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
|
|
|
|
{
|
|
|
|
return LyXLength(getLengthFromWidgets(input, choice));
|
|
|
|
}
|
|
|
|
|
2001-10-23 09:03:17 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
typedef FormCB<ControlGraphics, FormDB<FD_graphics> > base_class;
|
2001-03-28 13:11:08 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
FormGraphics::FormGraphics()
|
|
|
|
: base_class(_("Graphics"), false)
|
2001-03-28 13:11:08 +00:00
|
|
|
{}
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
void FormGraphics::redraw()
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
if (form() && form()->visible)
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_redraw_form(form());
|
|
|
|
else
|
|
|
|
return;
|
2002-03-12 14:11:15 +00:00
|
|
|
FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
|
2002-01-29 09:26:24 +00:00
|
|
|
if (outer_form && outer_form->visible)
|
|
|
|
fl_redraw_form(outer_form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void FormGraphics::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_graphics(this));
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2002-03-20 17:53:39 +00:00
|
|
|
// Allow the base class to control messages
|
|
|
|
setMessageWidget(dialog_->text_warning);
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
2002-02-05 12:19:32 +00:00
|
|
|
bc().setApply(dialog_->button_apply);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2001-04-03 14:30:58 +00:00
|
|
|
bc().setRestore(dialog_->button_restore);
|
2001-03-15 13:37:04 +00:00
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
// the file section
|
2002-06-13 13:43:51 +00:00
|
|
|
file_.reset(build_graphics_file(this));
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(file_->input_filename);
|
2002-08-24 22:02:30 +00:00
|
|
|
setPrehandler(file_->input_lyxscale);
|
|
|
|
setPrehandler(file_->input_width);
|
|
|
|
setPrehandler(file_->input_height);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
|
|
|
|
fl_set_input_filter(file_->input_lyxscale, fl_unsigned_int_filter);
|
2002-05-01 09:25:51 +00:00
|
|
|
|
2002-09-12 08:44:23 +00:00
|
|
|
// width default is scaling, thus unsigned integer input
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input_filter(file_->input_width, fl_unsigned_int_filter);
|
2002-08-27 20:30:20 +00:00
|
|
|
fl_set_input_maxchars(file_->input_height, SIZE_MAXDIGITS);
|
2002-09-12 08:44:23 +00:00
|
|
|
|
2002-08-27 20:30:20 +00:00
|
|
|
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());
|
2002-07-02 19:23:10 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_addto_choice(file_->choice_height, choice_Length_All.c_str());
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
bc().addReadOnly(file_->button_browse);
|
|
|
|
bc().addReadOnly(file_->check_aspectratio);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().addReadOnly(file_->check_draft);
|
|
|
|
bc().addReadOnly(file_->check_nounzip);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
2002-07-22 12:36:41 +00:00
|
|
|
// set up the tooltips for the filesection
|
|
|
|
string str = _("The file you want to insert.");
|
|
|
|
tooltips().init(file_->input_filename, str);
|
|
|
|
str = _("Browse the directories.");
|
|
|
|
tooltips().init(file_->button_browse, str);
|
|
|
|
|
2002-09-12 08:44:23 +00:00
|
|
|
str = _("Scale the image to inserted percentage value.");
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-09-12 08:44:23 +00:00
|
|
|
str = _("Select unit for width; Scale% for scaling whole image.");
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-07-22 12:36:41 +00:00
|
|
|
|
|
|
|
str = _("Pass a filename like \"file.eps.gz\" to the LaTeX output. "
|
2002-09-12 08:44:23 +00:00
|
|
|
"Useful when LaTeX should unzip the file. Needs an additional file "
|
2002-08-24 22:02:30 +00:00
|
|
|
"like \"file.eps.bb\" which holds the values for the bounding box.");
|
2002-07-22 12:36:41 +00:00
|
|
|
tooltips().init(file_->check_nounzip, str);
|
|
|
|
|
|
|
|
str = _("Show image only as a rectangle of the original size.");
|
|
|
|
tooltips().init(file_->check_draft, str);
|
|
|
|
|
2002-01-30 14:55:27 +00:00
|
|
|
// the bounding box selection
|
2002-06-13 13:43:51 +00:00
|
|
|
bbox_.reset(build_graphics_bbox(this));
|
2002-01-30 18:49:41 +00:00
|
|
|
fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (bbox_->input_bb_y0, 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);
|
2002-01-30 14:55:27 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-03-11 18:24:31 +00:00
|
|
|
|
|
|
|
setPrehandler(bbox_->input_bb_x0);
|
|
|
|
setPrehandler(bbox_->input_bb_y0);
|
|
|
|
setPrehandler(bbox_->input_bb_x1);
|
|
|
|
setPrehandler(bbox_->input_bb_y1);
|
2002-02-26 10:50:48 +00:00
|
|
|
|
2002-04-11 18:39:17 +00:00
|
|
|
string const bb_units = "bp|cm|mm|in";
|
2002-02-11 10:42:11 +00:00
|
|
|
fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
|
2002-02-04 15:36:45 +00:00
|
|
|
bc().addReadOnly(bbox_->button_getBB);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().addReadOnly(bbox_->check_clip);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-07-22 12:36:41 +00:00
|
|
|
// set up the tooltips for the bounding-box-section
|
|
|
|
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");
|
|
|
|
tooltips().init(bbox_->input_bb_y0, str);
|
|
|
|
str = _("The upper right x-value of the bounding box");
|
|
|
|
tooltips().init(bbox_->input_bb_x1, str);
|
|
|
|
str = _("The upper right y-value of the bounding box");
|
|
|
|
tooltips().init(bbox_->input_bb_y1, str);
|
2002-08-24 22:02:30 +00:00
|
|
|
str = _("Select unit for the bounding box values");
|
2002-07-22 12:36:41 +00:00
|
|
|
tooltips().init(bbox_->choice_bb_units, str);
|
|
|
|
|
|
|
|
str = _("Read the image coordinates new from file. If it's an (e)ps-file "
|
2002-08-24 22:02:30 +00:00
|
|
|
"then the bounding box is read otherwise the imagesize in pixels. "
|
2002-09-12 08:44:23 +00:00
|
|
|
"Default unit is \"bp\", the PostScript's b(ig) p(oint).");
|
2002-07-22 12:36:41 +00:00
|
|
|
tooltips().init(bbox_->button_getBB, str);
|
|
|
|
|
2002-09-12 08:44:23 +00:00
|
|
|
str = _("Clip image to the bounding box values.");
|
2002-07-22 12:36:41 +00:00
|
|
|
tooltips().init(bbox_->check_clip, str);
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// 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);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input_filter(extra_->input_rotate_angle, fl_float_filter);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
setPrehandler(extra_->input_rotate_angle);
|
|
|
|
setPrehandler(extra_->input_subcaption);
|
|
|
|
setPrehandler(extra_->input_special);
|
|
|
|
|
|
|
|
bc().addReadOnly(extra_->check_subcaption);
|
|
|
|
|
|
|
|
using namespace frnt;
|
|
|
|
vector<RotationOriginPair> origindata = getRotationOriginData();
|
|
|
|
|
|
|
|
// Store the identifiers for later
|
|
|
|
origins_ = getSecond(origindata);
|
|
|
|
|
2002-09-11 18:37:50 +00:00
|
|
|
string const choice = "Default|" + getStringFromVector(getFirst(origindata), "|");
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_addto_choice(extra_->choice_origin, choice.c_str());
|
|
|
|
|
|
|
|
// set up the tooltips for the extra section
|
|
|
|
str = _("Insert the rotation angle in degrees. "
|
2002-09-12 08:44:23 +00:00
|
|
|
"Positive value rotates anti-clockwise, negative value clockwise.");
|
2002-08-24 22:02:30 +00:00
|
|
|
tooltips().init(extra_->input_rotate_angle, str);
|
2002-09-12 08:44:23 +00:00
|
|
|
str = _("Insert the point of origin for rotation.");
|
2002-08-24 22:02:30 +00:00
|
|
|
tooltips().init(extra_->choice_origin, str);
|
|
|
|
str = _("Enables use of subfigure with its own caption.");
|
|
|
|
tooltips().init(extra_->check_subcaption, str);
|
2002-09-12 08:44:23 +00:00
|
|
|
str = _("Insert the optional subfigure caption.");
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-07-22 12:36:41 +00:00
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
// add the different tabfolders
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
|
|
|
|
fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_addto_tabfolder(dialog_->tabfolder, _("Extra"), extra_->form);
|
2002-07-22 12:36:41 +00:00
|
|
|
|
2002-03-11 11:17:49 +00:00
|
|
|
// set the right default unit
|
2002-08-24 22:02:30 +00:00
|
|
|
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;
|
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormGraphics::apply()
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// Create the parameters structure and fill the data from the dialog.
|
2001-03-28 13:11:08 +00:00
|
|
|
InsetGraphicsParams & igp = controller().params();
|
2002-02-05 18:43:28 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the file section
|
2002-07-21 15:51:07 +00:00
|
|
|
igp.filename = getString(file_->input_filename);
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
igp.lyxscale = strToInt(getString(file_->input_lyxscale));
|
2002-08-27 20:30:20 +00:00
|
|
|
if (igp.lyxscale == 0) {
|
|
|
|
igp.lyxscale = 100;
|
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
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;
|
2002-02-04 15:36:45 +00:00
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
// first item in choice_width means scaling
|
|
|
|
if (fl_get_choice(file_->choice_width) == 1) {
|
|
|
|
igp.scale = strToInt(getString(file_->input_width));
|
2002-08-27 20:30:20 +00:00
|
|
|
if (igp.scale == 0) {
|
|
|
|
igp.scale = 100;
|
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
igp.width = LyXLength();
|
2002-08-27 20:30:20 +00:00
|
|
|
} else {
|
2002-08-24 22:02:30 +00:00
|
|
|
igp.scale = 0;
|
|
|
|
igp.width = getLyXLengthFromWidgets(file_->input_width,
|
|
|
|
file_->choice_width);
|
|
|
|
}
|
|
|
|
igp.height = getLyXLengthFromWidgets(file_->input_height,
|
|
|
|
file_->choice_height);
|
|
|
|
igp.keepAspectRatio = fl_get_button(file_->check_aspectratio);
|
2002-05-01 09:25:51 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
igp.draft = fl_get_button(file_->check_draft);
|
|
|
|
igp.noUnzip = fl_get_button(file_->check_nounzip);
|
2002-02-01 18:53:50 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the bb section
|
2002-08-27 20:30:20 +00:00
|
|
|
if (!controller().bbChanged) { // different to the original one?
|
|
|
|
igp.bb = string(); // don't write anything
|
|
|
|
} else {
|
2002-03-21 16:51:33 +00:00
|
|
|
string bb;
|
2002-07-21 15:51:07 +00:00
|
|
|
if (getString(bbox_->input_bb_x0).empty())
|
2002-03-21 16:51:33 +00:00
|
|
|
bb = "0 ";
|
|
|
|
else
|
|
|
|
bb = getLengthFromWidgets(bbox_->input_bb_x0,
|
|
|
|
bbox_->choice_bb_units)+" ";
|
2002-07-21 15:51:07 +00:00
|
|
|
if (getString(bbox_->input_bb_y0).empty())
|
2002-03-21 16:51:33 +00:00
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_y0,
|
|
|
|
bbox_->choice_bb_units)+" ");
|
2002-07-21 15:51:07 +00:00
|
|
|
if (getString(bbox_->input_bb_x1).empty())
|
2002-03-21 16:51:33 +00:00
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_x1,
|
|
|
|
bbox_->choice_bb_units)+" ");
|
2002-07-21 15:51:07 +00:00
|
|
|
if (getString(bbox_->input_bb_y1).empty())
|
2002-03-21 16:51:33 +00:00
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_y1,
|
|
|
|
bbox_->choice_bb_units)+" ");
|
|
|
|
igp.bb = bb;
|
2001-09-13 09:34:39 +00:00
|
|
|
}
|
2002-03-12 14:11:15 +00:00
|
|
|
igp.clip = fl_get_button(bbox_->check_clip);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// the extra section
|
|
|
|
igp.rotateAngle = strToDbl(getString(extra_->input_rotate_angle));
|
|
|
|
|
|
|
|
// map angle into -360 (clock-wise) to +360 (counter clock-wise)
|
2002-08-27 20:30:20 +00:00
|
|
|
while (igp.rotateAngle <= -360.0) {
|
|
|
|
igp.rotateAngle += 360.0;
|
|
|
|
}
|
|
|
|
while (igp.rotateAngle >= 360.0) {
|
|
|
|
igp.rotateAngle -= 360.0;
|
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
|
|
|
|
|
|
|
|
int const origin_pos = fl_get_choice(extra_->choice_origin);
|
2002-09-11 18:37:50 +00:00
|
|
|
if (origin_pos == 1) {
|
|
|
|
igp.rotateOrigin.erase();
|
|
|
|
} else {
|
|
|
|
igp.rotateOrigin = origins_[origin_pos - 2];
|
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
igp.subcaption = fl_get_button(extra_->check_subcaption);
|
|
|
|
igp.subcaptionText = getString(extra_->input_subcaption);
|
|
|
|
|
|
|
|
igp.special = getString(extra_->input_special);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:57:05 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
void FormGraphics::update() {
|
2000-08-14 09:44:53 +00:00
|
|
|
// Update dialog with details from inset
|
2001-03-28 13:11:08 +00:00
|
|
|
InsetGraphicsParams & igp = controller().params();
|
2002-02-04 15:36:45 +00:00
|
|
|
|
|
|
|
// the file section
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_set_input(file_->input_filename, igp.filename.c_str());
|
2002-08-24 22:02:30 +00:00
|
|
|
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);
|
2002-08-27 20:30:20 +00:00
|
|
|
fl_set_input_maxchars(file_->input_width, 0);
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input(file_->input_width, tostr(igp.scale).c_str());
|
|
|
|
fl_set_choice(file_->choice_width, 1);
|
2002-08-27 20:30:20 +00:00
|
|
|
} else {
|
|
|
|
fl_set_input_filter(file_->input_width, NULL);
|
|
|
|
fl_set_input_maxchars(file_->input_width, SIZE_MAXDIGITS);
|
2002-08-24 22:02:30 +00:00
|
|
|
updateWidgetsFromLength(file_->input_width,
|
|
|
|
file_->choice_width, igp.width, defaultUnit);
|
2002-05-01 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
updateWidgetsFromLength(file_->input_height,
|
|
|
|
file_->choice_height, igp.height, defaultUnit);
|
|
|
|
|
|
|
|
fl_set_button(file_->check_aspectratio, igp.keepAspectRatio);
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_set_button(file_->check_draft, igp.draft);
|
|
|
|
fl_set_button(file_->check_nounzip, igp.noUnzip);
|
2002-01-30 14:55:27 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// 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);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
// the bb section
|
2002-02-04 15:36:45 +00:00
|
|
|
// set the bounding box values, if exists. First we need the whole
|
|
|
|
// path, because the controller knows nothing about the doc-dir
|
2002-04-04 14:49:54 +00:00
|
|
|
updateBB(igp.filename, igp.bb);
|
|
|
|
fl_set_button(bbox_->check_clip, igp.clip);
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
// the extra section
|
|
|
|
fl_set_input(extra_->input_rotate_angle,
|
|
|
|
tostr(igp.rotateAngle).c_str());
|
2002-08-27 20:30:20 +00:00
|
|
|
|
2002-09-11 18:37:50 +00:00
|
|
|
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);
|
2002-08-27 20:30:20 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
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
|
2002-08-27 20:30:20 +00:00
|
|
|
if (igp.filename.empty()) {
|
|
|
|
fl_set_folder(dialog_->tabfolder, file_->form);
|
|
|
|
}
|
2002-04-04 14:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormGraphics::updateBB(string const & filename, string const & bb_inset)
|
|
|
|
{
|
|
|
|
// Update dialog with details from inset
|
|
|
|
// set the bounding box values, if exists. First we need the whole
|
|
|
|
// path, because the controller knows nothing about the doc-dir
|
2002-02-04 15:36:45 +00:00
|
|
|
controller().bbChanged = false;
|
2002-04-04 14:49:54 +00:00
|
|
|
if (bb_inset.empty()) {
|
2002-08-27 20:30:20 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "FormGraphics::updateBB() [no BoundingBox]" << endl;
|
2002-04-05 09:18:26 +00:00
|
|
|
string const bb = controller().readBB(filename);
|
2002-03-21 21:21:28 +00:00
|
|
|
if (!bb.empty()) {
|
2002-03-21 16:51:33 +00:00
|
|
|
// get the values from the file
|
|
|
|
// in this case we always have the point-unit
|
2002-04-04 14:49:54 +00:00
|
|
|
fl_set_input(bbox_->input_bb_x0,
|
|
|
|
token(bb,' ',0).c_str());
|
|
|
|
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());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// no bb from file
|
2002-03-21 16:51:33 +00:00
|
|
|
fl_set_input(bbox_->input_bb_x0, bb.c_str());
|
|
|
|
fl_set_input(bbox_->input_bb_y0, bb.c_str());
|
|
|
|
fl_set_input(bbox_->input_bb_x1, bb.c_str());
|
|
|
|
fl_set_input(bbox_->input_bb_y1, bb.c_str());
|
|
|
|
}
|
2002-04-05 14:10:56 +00:00
|
|
|
// "bp"
|
2002-04-04 14:49:54 +00:00
|
|
|
fl_set_choice(bbox_->choice_bb_units, 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// get the values from the inset
|
2002-08-27 20:30:20 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "FormGraphics::updateBB(): igp has BoundingBox"
|
|
|
|
<< " ["<< bb_inset << "]"
|
2002-04-04 14:49:54 +00:00
|
|
|
<< endl;
|
2002-03-21 16:51:33 +00:00
|
|
|
controller().bbChanged = true;
|
2002-08-27 20:30:20 +00:00
|
|
|
|
2002-03-21 16:51:33 +00:00
|
|
|
LyXLength anyLength;
|
2002-04-04 14:49:54 +00:00
|
|
|
anyLength = LyXLength(token(bb_inset,' ',0));
|
2002-03-21 16:51:33 +00:00
|
|
|
updateWidgetsFromLength(bbox_->input_bb_x0,
|
2002-04-05 14:10:56 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"bp");
|
2002-04-04 14:49:54 +00:00
|
|
|
anyLength = LyXLength(token(bb_inset,' ',1));
|
2002-03-21 16:51:33 +00:00
|
|
|
updateWidgetsFromLength(bbox_->input_bb_y0,
|
2002-04-05 14:10:56 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"bp");
|
2002-04-04 14:49:54 +00:00
|
|
|
anyLength = LyXLength(token(bb_inset,' ',2));
|
2002-03-21 16:51:33 +00:00
|
|
|
updateWidgetsFromLength(bbox_->input_bb_x1,
|
2002-04-05 14:10:56 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"bp");
|
2002-04-04 14:49:54 +00:00
|
|
|
anyLength = LyXLength(token(bb_inset,' ',3));
|
2002-03-21 16:51:33 +00:00
|
|
|
updateWidgetsFromLength(bbox_->input_bb_y1,
|
2002-04-05 14:10:56 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"bp");
|
2002-02-04 15:36:45 +00:00
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2002-08-27 20:30:20 +00:00
|
|
|
|
2002-01-30 18:49:41 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isValid(FL_OBJECT * ob)
|
|
|
|
{
|
2002-07-21 15:51:07 +00:00
|
|
|
string const input = getString(ob);
|
2002-01-30 18:49:41 +00:00
|
|
|
return input.empty() || isValidLength(input) || isStrDbl(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
|
2000-10-24 13:13:59 +00:00
|
|
|
{
|
2002-02-05 12:19:32 +00:00
|
|
|
// the file section
|
2002-01-29 09:26:24 +00:00
|
|
|
if (ob == file_->button_browse) {
|
2001-03-30 09:51:46 +00:00
|
|
|
// Get the filename from the dialog
|
2002-07-21 15:51:07 +00:00
|
|
|
string const in_name = getString(file_->input_filename);
|
2001-03-30 09:51:46 +00:00
|
|
|
string const out_name = controller().Browse(in_name);
|
2002-04-04 14:49:54 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
|
2001-03-30 09:51:46 +00:00
|
|
|
if (out_name != in_name && !out_name.empty()) {
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_set_input(file_->input_filename, out_name.c_str());
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2002-05-02 08:48:41 +00:00
|
|
|
if (controller().isFilenameValid(out_name) &&
|
2002-08-27 20:30:20 +00:00
|
|
|
!controller().bbChanged) {
|
2002-07-02 19:23:10 +00:00
|
|
|
updateBB(out_name, string());
|
2002-08-27 20:30:20 +00:00
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
} 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
|
2002-08-27 20:30:20 +00:00
|
|
|
if (scaling) {
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_input_filter(file_->input_width, fl_unsigned_int_filter);
|
2002-08-27 20:30:20 +00:00
|
|
|
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);
|
|
|
|
}
|
2002-02-05 12:19:32 +00:00
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// 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
|
2002-03-21 21:21:28 +00:00
|
|
|
} else if (!controller().bbChanged &&
|
2002-04-08 20:00:02 +00:00
|
|
|
(ob == bbox_->check_clip || ob == bbox_->choice_bb_units ||
|
2002-03-21 16:51:33 +00:00
|
|
|
ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
|
|
|
|
ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
|
2002-03-21 21:21:28 +00:00
|
|
|
controller().bbChanged = true;
|
2002-02-05 12:19:32 +00:00
|
|
|
} else if (ob == bbox_->button_getBB) {
|
2002-07-21 15:51:07 +00:00
|
|
|
string const filename = getString(file_->input_filename);
|
2002-03-21 16:51:33 +00:00
|
|
|
if (!filename.empty()) {
|
2002-04-05 09:18:26 +00:00
|
|
|
string bb = controller().readBB(filename);
|
2002-03-21 16:51:33 +00:00
|
|
|
if (!bb.empty()) {
|
|
|
|
fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
|
|
|
|
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());
|
2002-08-24 22:02:30 +00:00
|
|
|
fl_set_choice_text(bbox_->choice_bb_units, "bp");
|
2002-03-21 16:51:33 +00:00
|
|
|
}
|
|
|
|
controller().bbChanged = false;
|
|
|
|
} else {
|
|
|
|
fl_set_input(bbox_->input_bb_x0, "");
|
|
|
|
fl_set_input(bbox_->input_bb_y0, "");
|
|
|
|
fl_set_input(bbox_->input_bb_x1, "");
|
|
|
|
fl_set_input(bbox_->input_bb_y1, "");
|
2002-04-05 14:10:56 +00:00
|
|
|
fl_set_choice_text(bbox_->choice_bb_units, "bp");
|
2002-02-05 12:19:32 +00:00
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
// the extra section
|
|
|
|
} else if (ob == extra_->check_subcaption) {
|
|
|
|
setEnabled(extra_->input_subcaption,
|
|
|
|
fl_get_button(extra_->check_subcaption));
|
2002-02-05 12:19:32 +00:00
|
|
|
|
2002-01-30 14:55:27 +00:00
|
|
|
}
|
|
|
|
|
2002-08-27 20:30:20 +00:00
|
|
|
// check if the input is valid
|
|
|
|
bool const invalid = !isValid(file_->input_width) || !isValid(file_->input_height);
|
2002-01-30 19:36:39 +00:00
|
|
|
|
2002-08-27 20:30:20 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|