2001-03-28 13:11:08 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000-2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file FormGraphics.C
|
|
|
|
* \author Baruch Even, baruch.even@writeme.com
|
2002-02-04 15:36:45 +00:00
|
|
|
* \author Herbert Voss, voss@perce.de
|
2000-07-31 12:30:10 +00:00
|
|
|
*/
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
2000-08-14 09:44:53 +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"
|
|
|
|
#include "form_graphics.h"
|
|
|
|
|
2001-09-13 12:37:40 +00:00
|
|
|
#include "xforms_helpers.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/FileInfo.h"
|
|
|
|
#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
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-07-31 13:36:03 +00:00
|
|
|
using std::endl;
|
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
|
2001-10-23 09:03:17 +00:00
|
|
|
int const SCALE_MAXDIGITS = 3;
|
2002-01-30 19:36:39 +00:00
|
|
|
int const WIDTH_MAXDIGITS = 10;
|
|
|
|
int const HEIGHT_MAXDIGITS = 10;
|
2001-10-23 09:03:17 +00:00
|
|
|
int const ROTATE_MAXCHARS = 4;
|
|
|
|
int const FILENAME_MAXCHARS = 1024;
|
2002-02-11 10:42:11 +00:00
|
|
|
string defaultUnit = "cm";
|
2001-10-23 09:03:17 +00:00
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
|
|
|
|
|
|
|
|
FormGraphics::FormGraphics(ControlGraphics & c)
|
2002-02-04 17:14:25 +00:00
|
|
|
: base_class(c, _("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;
|
|
|
|
FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
|
|
|
|
if (outer_form && outer_form->visible)
|
|
|
|
fl_redraw_form(outer_form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
void FormGraphics::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_graphics());
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2000-11-28 06:46:06 +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);
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().setCancel(dialog_->button_cancel);
|
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
|
|
|
|
file_.reset(build_file());
|
|
|
|
|
|
|
|
fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
|
2002-02-04 15:36:45 +00:00
|
|
|
fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
|
2002-02-04 15:36:45 +00:00
|
|
|
fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
|
|
|
|
fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
string const choice_origin =
|
|
|
|
"center|" // c
|
|
|
|
"leftTop|leftBottom|leftBaseline|" // lt lb lB
|
|
|
|
"centerTop|centerBottom|centerBaseline|" // ct cb cB
|
|
|
|
"rightTop|rightBottom|rightBaseline"; // rt rb rB
|
|
|
|
fl_addto_choice(file_->choice_origin, choice_origin.c_str());
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
bc().addReadOnly(file_->button_browse);
|
|
|
|
bc().addReadOnly(file_->check_subcaption);
|
2002-02-05 18:43:28 +00:00
|
|
|
bc().addReadOnly(file_->check_rotate);
|
2002-02-04 15:36:45 +00:00
|
|
|
bc().addReadOnly(file_->button_draft);
|
2002-02-11 10:42:11 +00:00
|
|
|
bc().addReadOnly(file_->button_nounzip);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
|
|
|
// the lyxview section
|
|
|
|
lyxview_.reset(build_lyxview());
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-02-20 16:34:53 +00:00
|
|
|
fl_addto_choice(lyxview_->choice_width_lyxwidth, choice_Length_All.c_str());
|
|
|
|
fl_addto_choice(lyxview_->choice_width_lyxheight, choice_Length_All.c_str());
|
2002-02-04 15:36:45 +00:00
|
|
|
|
2002-02-05 18:43:28 +00:00
|
|
|
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);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
// the size section
|
|
|
|
size_.reset(build_size());
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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_units, choice_Length_All.c_str());
|
|
|
|
fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
|
|
|
|
|
2002-02-05 18:43:28 +00:00
|
|
|
bc().addReadOnly(size_->button_asis);
|
2002-01-29 09:26:24 +00:00
|
|
|
bc().addReadOnly(size_->button_wh);
|
|
|
|
bc().addReadOnly(size_->button_scale);
|
|
|
|
bc().addReadOnly(size_->check_aspectratio);
|
2002-01-30 14:55:27 +00:00
|
|
|
|
|
|
|
// the bounding box selection
|
|
|
|
bbox_.reset(build_bbox());
|
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-02-26 10:50:48 +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);
|
|
|
|
|
2002-01-30 14:55:27 +00:00
|
|
|
string const bb_units = "pt|cm|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-02-13 18:07:43 +00:00
|
|
|
bc().addReadOnly(bbox_->button_clip);
|
2002-01-29 09:26:24 +00:00
|
|
|
|
|
|
|
// the rotate section
|
|
|
|
special_.reset(build_special());
|
|
|
|
|
|
|
|
fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
// add the different tabfolders
|
2002-01-30 14:55:27 +00:00
|
|
|
fl_addto_tabfolder(dialog_->tabFolder, _("File"), file_->form);
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_addto_tabfolder(dialog_->tabFolder, _("LyX View"), lyxview_->form);
|
|
|
|
fl_addto_tabfolder(dialog_->tabFolder, _("LaTeX Size"), size_->form);
|
2002-01-30 14:55:27 +00:00
|
|
|
fl_addto_tabfolder(dialog_->tabFolder, _("Bounding Box"), bbox_->form);
|
|
|
|
fl_addto_tabfolder(dialog_->tabFolder, _("Extras"), special_->form);
|
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-01-29 09:26:24 +00:00
|
|
|
igp.filename = getStringFromInput(file_->input_filename);
|
|
|
|
igp.subcaption = fl_get_button(file_->check_subcaption);
|
|
|
|
igp.subcaptionText = getStringFromInput(file_->input_subcaption);
|
2002-02-05 18:43:28 +00:00
|
|
|
igp.rotate = fl_get_button(file_->check_rotate);
|
2002-02-04 15:36:45 +00:00
|
|
|
igp.rotateAngle =
|
|
|
|
strToDbl(getStringFromInput(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fl_get_choice(file_->choice_origin) > 0)
|
|
|
|
igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
|
|
|
|
else
|
|
|
|
igp.rotateOrigin = string();
|
2002-02-05 12:19:32 +00:00
|
|
|
igp.draft = fl_get_button(file_->button_draft);
|
2002-02-11 10:42:11 +00:00
|
|
|
igp.noUnzip = fl_get_button(file_->button_nounzip);
|
2002-02-01 18:53:50 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the lyxview section
|
2002-02-05 18:43:28 +00:00
|
|
|
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_->button_lyxasis))
|
2002-02-05 12:19:32 +00:00
|
|
|
igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
else if (fl_get_button(lyxview_->button_lyxwh))
|
|
|
|
igp.lyxsize_type = InsetGraphicsParams::WH;
|
|
|
|
else
|
|
|
|
igp.lyxsize_type = InsetGraphicsParams::SCALE;
|
2002-02-04 15:36:45 +00:00
|
|
|
igp.lyxwidth = LyXLength(getLengthFromWidgets(lyxview_->input_lyxwidth,
|
|
|
|
lyxview_->choice_width_lyxwidth));
|
|
|
|
igp.lyxheight = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
|
|
|
|
lyxview_->choice_width_lyxheight));
|
2002-02-05 12:19:32 +00:00
|
|
|
igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
|
2002-02-01 18:53:50 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the size section
|
2002-02-05 18:43:28 +00:00
|
|
|
if (fl_get_button(size_->button_asis))
|
2002-01-29 09:26:24 +00:00
|
|
|
igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
else if (fl_get_button(size_->button_wh))
|
|
|
|
igp.size_type = InsetGraphicsParams::WH;
|
|
|
|
else
|
|
|
|
igp.size_type = InsetGraphicsParams::SCALE;
|
2002-01-30 14:55:27 +00:00
|
|
|
igp.width = LyXLength(getLengthFromWidgets(size_->input_width,
|
|
|
|
size_->choice_width_units));
|
|
|
|
igp.height = LyXLength(getLengthFromWidgets(size_->input_height,
|
|
|
|
size_->choice_height_units));
|
2002-02-05 12:19:32 +00:00
|
|
|
igp.scale = strToInt(getStringFromInput(size_->input_scale));
|
|
|
|
igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the bb section
|
|
|
|
if (!controller().bbChanged) // different to the original one?
|
|
|
|
igp.bb = string(); // don't write anything
|
|
|
|
else {
|
|
|
|
string bb;
|
|
|
|
if (getStringFromInput(bbox_->input_bb_x0).empty())
|
|
|
|
bb = "0 ";
|
|
|
|
else
|
|
|
|
bb = getLengthFromWidgets(bbox_->input_bb_x0,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units)+" ";
|
2002-02-04 15:36:45 +00:00
|
|
|
if (getStringFromInput(bbox_->input_bb_y0).empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_y0,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units)+" ");
|
2002-02-04 15:36:45 +00:00
|
|
|
if (getStringFromInput(bbox_->input_bb_x1).empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_x1,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units)+" ");
|
2002-02-04 15:36:45 +00:00
|
|
|
if (getStringFromInput(bbox_->input_bb_y1).empty())
|
|
|
|
bb += "0 ";
|
|
|
|
else
|
|
|
|
bb += (getLengthFromWidgets(bbox_->input_bb_y1,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units)+" ");
|
2002-02-04 15:36:45 +00:00
|
|
|
igp.bb = bb;
|
2001-09-13 09:34:39 +00:00
|
|
|
}
|
2002-02-13 18:07:43 +00:00
|
|
|
igp.clip = fl_get_button(bbox_->button_clip);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
|
|
|
// the special section
|
2002-01-29 09:26:24 +00:00
|
|
|
igp.special = getStringFromInput(special_->input_special);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:57:05 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
void FormGraphics::update() {
|
2002-01-29 09:26:24 +00:00
|
|
|
if (lyxrc.default_papersize < 3)
|
2002-02-11 10:42:11 +00:00
|
|
|
defaultUnit = string("in");
|
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());
|
|
|
|
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));
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(file_->check_rotate, igp.rotate);
|
2002-02-04 15:36:45 +00:00
|
|
|
fl_set_input(file_->input_rotate_angle,
|
|
|
|
tostr(igp.rotateAngle).c_str());
|
|
|
|
if (igp.rotateOrigin.empty())
|
|
|
|
fl_set_choice(file_->choice_origin,0);
|
|
|
|
else
|
|
|
|
fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
|
2002-02-05 18:43:28 +00:00
|
|
|
setEnabled(file_->input_rotate_angle,
|
|
|
|
fl_get_button(file_->check_rotate));
|
|
|
|
setEnabled(file_->choice_origin,
|
|
|
|
fl_get_button(file_->check_rotate));
|
2002-02-04 15:36:45 +00:00
|
|
|
fl_set_button(file_->button_draft, igp.draft);
|
2002-02-11 10:42:11 +00:00
|
|
|
fl_set_button(file_->button_nounzip, igp.noUnzip);
|
2002-01-30 14:55:27 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the lyxview section
|
2002-01-29 09:26:24 +00:00
|
|
|
switch (igp.display) {
|
2002-02-01 18:53:50 +00:00
|
|
|
case InsetGraphicsParams::DEFAULT:
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->radio_pref, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
break;
|
2002-02-01 18:53:50 +00:00
|
|
|
case InsetGraphicsParams::MONOCHROME:
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->radio_mono, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
break;
|
2002-02-01 18:53:50 +00:00
|
|
|
case InsetGraphicsParams::GRAYSCALE:
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->radio_gray, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
break;
|
2002-02-01 18:53:50 +00:00
|
|
|
case InsetGraphicsParams::COLOR:
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->radio_color, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
break;
|
2002-02-01 18:53:50 +00:00
|
|
|
case InsetGraphicsParams::NONE:
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->radio_nodisplay, 1);
|
2002-02-01 18:53:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-02-04 15:36:45 +00:00
|
|
|
updateWidgetsFromLength(lyxview_->input_lyxwidth,
|
|
|
|
lyxview_->choice_width_lyxwidth, igp.lyxwidth,defaultUnit);
|
|
|
|
updateWidgetsFromLength(lyxview_->input_lyxheight,
|
|
|
|
lyxview_->choice_width_lyxheight, igp.lyxheight,defaultUnit);
|
2002-02-05 12:19:32 +00:00
|
|
|
fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
|
|
|
|
switch (igp.lyxsize_type) {
|
|
|
|
case InsetGraphicsParams::DEFAULT_SIZE: {
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(lyxview_->button_lyxasis,1);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(lyxview_->input_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::WH: {
|
|
|
|
fl_set_button(lyxview_->button_lyxwh, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxwidth, 1);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 1);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::SCALE: {
|
|
|
|
fl_set_button(lyxview_->button_lyxscale, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-02-01 18:53:50 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
// the size section
|
|
|
|
// Update the draft and clip mode
|
2002-01-30 14:55:27 +00:00
|
|
|
updateWidgetsFromLength(size_->input_width,
|
|
|
|
size_->choice_width_units,igp.width,defaultUnit);
|
|
|
|
updateWidgetsFromLength(size_->input_height,
|
|
|
|
size_->choice_height_units,igp.height,defaultUnit);
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
|
|
|
|
switch (igp.size_type) {
|
|
|
|
case InsetGraphicsParams::DEFAULT_SIZE: {
|
2002-02-05 18:43:28 +00:00
|
|
|
fl_set_button(size_->button_asis,1);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_width, 0);
|
|
|
|
setEnabled(size_->choice_width_units, 0);
|
|
|
|
setEnabled(size_->input_height, 0);
|
|
|
|
setEnabled(size_->choice_height_units, 0);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 0);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::WH: {
|
|
|
|
fl_set_button(size_->button_wh, 1);
|
|
|
|
setEnabled(size_->input_width, 1);
|
|
|
|
setEnabled(size_->choice_width_units, 1);
|
|
|
|
setEnabled(size_->input_height, 1);
|
|
|
|
setEnabled(size_->choice_height_units, 1);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InsetGraphicsParams::SCALE: {
|
|
|
|
fl_set_button(size_->button_scale, 1);
|
|
|
|
setEnabled(size_->input_width, 0);
|
|
|
|
setEnabled(size_->choice_width_units, 0);
|
|
|
|
setEnabled(size_->input_height, 0);
|
|
|
|
setEnabled(size_->choice_height_units, 0);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 0);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-01-30 14:55:27 +00:00
|
|
|
fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
controller().bbChanged = false;
|
|
|
|
if (igp.bb.empty()) {
|
2002-02-20 16:34:53 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
|
|
|
|
string const fileWithAbsPath =
|
2002-02-13 18:07:43 +00:00
|
|
|
MakeAbsPath(igp.filename, OnlyPath(igp.filename));
|
2002-02-20 16:34:53 +00:00
|
|
|
string const bb = controller().readBB(fileWithAbsPath);
|
2002-02-04 15:36:45 +00:00
|
|
|
if (!bb.empty()) {
|
|
|
|
// get the values from the file
|
|
|
|
// in this case we always have the point-unit
|
|
|
|
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-02-13 18:07:43 +00:00
|
|
|
} else { // no bb from file
|
|
|
|
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-02-04 15:36:45 +00:00
|
|
|
}
|
2002-02-20 16:34:53 +00:00
|
|
|
fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
|
2002-02-04 15:36:45 +00:00
|
|
|
} else { // get the values from the inset
|
2002-02-20 16:34:53 +00:00
|
|
|
lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
|
2002-02-04 15:36:45 +00:00
|
|
|
controller().bbChanged = true;
|
|
|
|
LyXLength anyLength;
|
|
|
|
anyLength = LyXLength(token(igp.bb,' ',0));
|
|
|
|
updateWidgetsFromLength(bbox_->input_bb_x0,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"pt");
|
2002-02-04 15:36:45 +00:00
|
|
|
anyLength = LyXLength(token(igp.bb,' ',1));
|
|
|
|
updateWidgetsFromLength(bbox_->input_bb_y0,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"pt");
|
2002-02-04 15:36:45 +00:00
|
|
|
anyLength = LyXLength(token(igp.bb,' ',2));
|
|
|
|
updateWidgetsFromLength(bbox_->input_bb_x1,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"pt");
|
2002-02-04 15:36:45 +00:00
|
|
|
anyLength = LyXLength(token(igp.bb,' ',3));
|
|
|
|
updateWidgetsFromLength(bbox_->input_bb_y1,
|
2002-02-11 10:42:11 +00:00
|
|
|
bbox_->choice_bb_units,anyLength,"pt");
|
2002-02-04 15:36:45 +00:00
|
|
|
}
|
2002-02-13 18:07:43 +00:00
|
|
|
fl_set_button(bbox_->button_clip, igp.clip);
|
2002-02-04 15:36:45 +00:00
|
|
|
|
|
|
|
// the special section
|
2002-01-29 09:26:24 +00:00
|
|
|
fl_set_input(special_->input_special, igp.special.c_str());
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
|
2002-01-30 18:49:41 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isValid(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
string const input = getStringFromInput(ob);
|
|
|
|
return input.empty() || isValidLength(input) || isStrDbl(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
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-01-29 09:26:24 +00:00
|
|
|
string const in_name = getStringFromInput(file_->input_filename);
|
2001-03-30 09:51:46 +00:00
|
|
|
string const out_name = controller().Browse(in_name);
|
|
|
|
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-02-05 12:19:32 +00:00
|
|
|
} else if (ob == file_->check_subcaption) {
|
|
|
|
setEnabled(file_->input_subcaption,
|
|
|
|
fl_get_button(file_->check_subcaption));
|
2002-02-05 18:43:28 +00:00
|
|
|
} 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));
|
2002-02-05 12:19:32 +00:00
|
|
|
|
|
|
|
// the lyxview section
|
2002-02-05 18:43:28 +00:00
|
|
|
} else if (ob == lyxview_->button_lyxasis) {
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(lyxview_->input_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 0);
|
|
|
|
} else if (ob == lyxview_->button_lyxwh) {
|
|
|
|
setEnabled(lyxview_->input_lyxwidth, 1);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 1);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 1);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 0);
|
|
|
|
} else if (ob == lyxview_->button_lyxscale) {
|
|
|
|
setEnabled(lyxview_->input_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxwidth, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->choice_width_lyxheight, 0);
|
|
|
|
setEnabled(lyxview_->input_lyxscale, 1);
|
2002-02-11 10:42:11 +00:00
|
|
|
} else if (ob == lyxview_->button_latex_values) {
|
|
|
|
LyXLength dummy = LyXLength(getLengthFromWidgets(size_->input_width,
|
|
|
|
size_->choice_width_units));
|
|
|
|
updateWidgetsFromLength(lyxview_->input_lyxwidth,
|
|
|
|
lyxview_->choice_width_lyxwidth, dummy, defaultUnit);
|
|
|
|
dummy = LyXLength(getLengthFromWidgets(size_->input_height,
|
|
|
|
size_->choice_width_units));
|
|
|
|
updateWidgetsFromLength(lyxview_->input_lyxheight,
|
|
|
|
lyxview_->choice_width_lyxheight, dummy, defaultUnit);
|
2002-02-13 18:07:43 +00:00
|
|
|
string const scale = getStringFromInput(size_->input_scale);
|
2002-02-11 10:42:11 +00:00
|
|
|
fl_set_input(lyxview_->input_lyxscale, scale.c_str());
|
2002-02-05 12:19:32 +00:00
|
|
|
|
|
|
|
// the bb section
|
2002-01-29 09:26:24 +00:00
|
|
|
} else if (!controller().bbChanged &&
|
2002-02-11 10:42:11 +00:00
|
|
|
(ob == bbox_->choice_bb_units ||
|
|
|
|
ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
|
|
|
|
ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
|
2002-01-29 09:26:24 +00:00
|
|
|
controller().bbChanged = true;
|
2002-02-05 12:19:32 +00:00
|
|
|
} else if (ob == bbox_->button_getBB) {
|
|
|
|
string const filename = getStringFromInput(file_->input_filename);
|
|
|
|
if (!filename.empty()) {
|
|
|
|
string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
|
|
|
|
string bb = controller().readBB(fileWithAbsPath);
|
2002-02-11 10:42:11 +00:00
|
|
|
if (!bb.empty()) {
|
2002-02-13 18:07:43 +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());
|
|
|
|
string const unit("pt");
|
|
|
|
fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
|
2002-02-05 12:19:32 +00:00
|
|
|
}
|
|
|
|
controller().bbChanged = false;
|
2002-02-13 18:07:43 +00:00
|
|
|
} 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, "");
|
|
|
|
fl_set_choice_text(bbox_->choice_bb_units, "pt");
|
2002-02-05 12:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the size section
|
2002-02-05 18:43:28 +00:00
|
|
|
} else if (ob == size_->button_asis) {
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_width, 0);
|
|
|
|
setEnabled(size_->choice_width_units, 0);
|
|
|
|
setEnabled(size_->input_height, 0);
|
|
|
|
setEnabled(size_->choice_height_units, 0);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 0);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 0);
|
|
|
|
} else if (ob == size_->button_wh) {
|
|
|
|
setEnabled(size_->input_width, 1);
|
|
|
|
setEnabled(size_->choice_width_units, 1);
|
|
|
|
setEnabled(size_->input_height, 1);
|
|
|
|
setEnabled(size_->choice_height_units, 1);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 1);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 0);
|
|
|
|
} else if (ob == size_->button_scale) {
|
|
|
|
setEnabled(size_->input_width, 0);
|
|
|
|
setEnabled(size_->choice_width_units, 0);
|
|
|
|
setEnabled(size_->input_height, 0);
|
|
|
|
setEnabled(size_->choice_height_units, 0);
|
2002-02-05 12:19:32 +00:00
|
|
|
setEnabled(size_->check_aspectratio, 0);
|
2002-01-29 09:26:24 +00:00
|
|
|
setEnabled(size_->input_scale, 1);
|
2002-02-11 10:42:11 +00:00
|
|
|
} else if (ob == size_->button_lyx_values) {
|
|
|
|
LyXLength dummy = LyXLength(getLengthFromWidgets(
|
|
|
|
lyxview_->input_lyxwidth, lyxview_->choice_width_lyxwidth));
|
|
|
|
updateWidgetsFromLength(size_->input_width,
|
|
|
|
size_->choice_width_units, dummy, defaultUnit);
|
|
|
|
dummy = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
|
|
|
|
lyxview_->choice_width_lyxheight));
|
|
|
|
updateWidgetsFromLength(size_->input_height,
|
|
|
|
size_->choice_height_units, dummy, defaultUnit);
|
2002-02-13 18:07:43 +00:00
|
|
|
string const scale = getStringFromInput(lyxview_->input_lyxscale);
|
2002-02-11 10:42:11 +00:00
|
|
|
fl_set_input(size_->input_scale, scale.c_str());
|
2002-01-30 14:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if the input is valid
|
2002-01-30 18:49:41 +00:00
|
|
|
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);
|
2002-02-04 15:36:45 +00:00
|
|
|
invalid = invalid || !isValid(lyxview_->input_lyxwidth);
|
|
|
|
invalid = invalid || !isValid(lyxview_->input_lyxheight);
|
2002-01-30 14:55:27 +00:00
|
|
|
|
|
|
|
// deactivate OK/ Apply buttons and
|
|
|
|
// spit out warnings if invalid
|
2002-02-04 15:36:45 +00:00
|
|
|
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) {
|
2002-01-30 14:55:27 +00:00
|
|
|
if (invalid) {
|
|
|
|
fl_set_object_label(dialog_->text_warning,
|
|
|
|
_("Warning: Invalid Length!"));
|
|
|
|
fl_show_object(dialog_->text_warning);
|
2002-01-30 19:36:39 +00:00
|
|
|
return ButtonPolicy::SMI_INVALID;
|
2002-01-30 14:55:27 +00:00
|
|
|
} else {
|
|
|
|
fl_hide_object(dialog_->text_warning);
|
|
|
|
}
|
2001-09-13 09:34:39 +00:00
|
|
|
}
|
2002-01-30 19:36:39 +00:00
|
|
|
|
2002-02-04 15:36:45 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
2002-01-29 09:26:24 +00:00
|
|
|
|