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
|
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-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
|
|
|
|
#include "support/FileInfo.h" // for FileInfo
|
2000-07-31 12:30:10 +00:00
|
|
|
#include "insets/insetgraphicsParams.h"
|
|
|
|
|
2000-07-31 13:36:03 +00:00
|
|
|
using std::endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
static double const tol = 1.0e-08;
|
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
|
|
|
|
|
|
|
|
FormGraphics::FormGraphics(ControlGraphics & c)
|
2001-09-13 09:34:39 +00:00
|
|
|
: base_class(c, _("Graphics"))
|
2001-03-28 13:11:08 +00:00
|
|
|
{}
|
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
|
|
|
|
|
|
|
// This is the place to add settings of the dialog that did not go
|
|
|
|
// to the .fd file.
|
|
|
|
|
|
|
|
// Set the input widgets to issue a callback to input() whenever
|
|
|
|
// they change, so we can verify their content.
|
2001-09-13 09:34:39 +00:00
|
|
|
fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (dialog_->input_scale, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (dialog_->input_width, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (dialog_->input_height, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (dialog_->input_rotate_angle, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return (dialog_->input_subcaption, FL_RETURN_CHANGED);
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Set the maximum characters that can be written in the input texts.
|
2001-09-13 09:34:39 +00:00
|
|
|
fl_set_input_maxchars(dialog_->input_width, WIDTH_MAXDIGITS);
|
|
|
|
fl_set_input_maxchars(dialog_->input_height, HEIGHT_MAXDIGITS);
|
|
|
|
fl_set_input_maxchars(dialog_->input_filename, FILENAME_MAXCHARS);
|
2000-08-14 09:44:53 +00:00
|
|
|
fl_set_input_maxchars(dialog_->input_rotate_angle, ROTATE_MAXCHARS);
|
|
|
|
|
|
|
|
// Set input filter on width and height to make them accept only
|
|
|
|
// unsigned numbers.
|
2001-09-13 09:34:39 +00:00
|
|
|
fl_set_input_filter(dialog_->input_scale, fl_unsigned_float_filter);
|
|
|
|
fl_set_input_filter(dialog_->input_width, fl_unsigned_float_filter);
|
|
|
|
fl_set_input_filter(dialog_->input_height, fl_unsigned_float_filter);
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
// Set input filter on rotate_angle to make it accept only
|
|
|
|
// floating point numbers.
|
|
|
|
fl_set_input_filter(dialog_->input_rotate_angle, fl_float_filter);
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
// Create the contents of the choices
|
|
|
|
string const width = " cm | inch | page %% | column %% ";
|
|
|
|
fl_addto_choice(dialog_->choice_width_units, width.c_str());
|
|
|
|
|
|
|
|
string const height = " cm | inch | page %% ";
|
|
|
|
fl_addto_choice(dialog_->choice_height_units, height.c_str());
|
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);
|
|
|
|
bc().setApply(dialog_->button_apply);
|
|
|
|
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
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->input_filename);
|
|
|
|
bc().addReadOnly(dialog_->button_browse);
|
2001-09-13 09:34:39 +00:00
|
|
|
bc().addReadOnly(dialog_->check_display);
|
|
|
|
bc().addReadOnly(dialog_->input_scale);
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().addReadOnly(dialog_->input_width);
|
2001-09-13 09:34:39 +00:00
|
|
|
bc().addReadOnly(dialog_->choice_width_units);
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().addReadOnly(dialog_->input_height);
|
2001-09-13 09:34:39 +00:00
|
|
|
bc().addReadOnly(dialog_->choice_height_units);
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().addReadOnly(dialog_->input_rotate_angle);
|
|
|
|
bc().addReadOnly(dialog_->input_subcaption);
|
|
|
|
bc().addReadOnly(dialog_->check_subcaption);
|
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();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
igp.filename = fl_get_input(dialog_->input_filename);
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
if (fl_get_button(dialog_->check_display)) {
|
|
|
|
igp.display = InsetGraphicsParams::COLOR;
|
|
|
|
} else {
|
|
|
|
igp.display = InsetGraphicsParams::NONE;
|
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
double const scale = strToDbl(fl_get_input(dialog_->input_scale));
|
|
|
|
if (scale < tol) {
|
|
|
|
double const width =
|
|
|
|
strToDbl(fl_get_input(dialog_->input_width));
|
|
|
|
|
|
|
|
if (width < tol) {
|
|
|
|
igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
igp.widthSize = 0.0;
|
|
|
|
} else {
|
|
|
|
switch (fl_get_choice(dialog_->choice_width_units)) {
|
|
|
|
case 2:
|
|
|
|
igp.widthResize = InsetGraphicsParams::INCH;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
igp.widthResize =
|
|
|
|
InsetGraphicsParams::PERCENT_PAGE;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
igp.widthResize =
|
|
|
|
InsetGraphicsParams::PERCENT_COLUMN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
igp.widthResize = InsetGraphicsParams::CM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
igp.widthSize = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
double const height =
|
|
|
|
strToDbl(fl_get_input(dialog_->input_height));
|
|
|
|
|
|
|
|
if (height < tol) {
|
|
|
|
igp.heightResize = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
igp.heightSize = 0.0;
|
|
|
|
} else {
|
|
|
|
switch (fl_get_choice(dialog_->choice_height_units)) {
|
|
|
|
case 2:
|
|
|
|
igp.heightResize = InsetGraphicsParams::INCH;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
igp.heightResize =
|
|
|
|
InsetGraphicsParams::PERCENT_PAGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
igp.heightResize = InsetGraphicsParams::CM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
igp.heightSize = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
|
|
|
|
igp.widthSize = 0.0;
|
|
|
|
igp.heightResize = InsetGraphicsParams::SCALE;
|
|
|
|
igp.heightSize = scale;
|
|
|
|
}
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
igp.rotateAngle = strToDbl(fl_get_input(dialog_->input_rotate_angle));
|
2001-09-13 09:34:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
igp.subcaption = fl_get_button(dialog_->check_subcaption);
|
|
|
|
igp.subcaptionText = fl_get_input(dialog_->input_subcaption);
|
|
|
|
|
|
|
|
igp.testInvariant();
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 05:57:05 +00:00
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
void FormGraphics::update()
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
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();
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Update the filename input field
|
|
|
|
fl_set_input(dialog_->input_filename,
|
|
|
|
igp.filename.c_str());
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
// To display or not to display
|
|
|
|
if (igp.display == InsetGraphicsParams::NONE) {
|
|
|
|
fl_set_button(dialog_->check_display, 0);
|
|
|
|
} else {
|
|
|
|
fl_set_button(dialog_->check_display, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (igp.heightResize == InsetGraphicsParams::SCALE) {
|
|
|
|
string number = tostr(igp.heightSize);
|
|
|
|
fl_set_input(dialog_->input_scale, number.c_str());
|
|
|
|
fl_set_input(dialog_->input_width, "");
|
|
|
|
fl_set_choice(dialog_->choice_width_units, 1);
|
|
|
|
fl_set_input(dialog_->input_height, "");
|
|
|
|
fl_set_choice(dialog_->choice_height_units, 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
fl_set_input(dialog_->input_scale, "");
|
|
|
|
|
|
|
|
string number;
|
|
|
|
if (igp.widthResize != InsetGraphicsParams::DEFAULT_SIZE) {
|
|
|
|
number = tostr(igp.widthSize);
|
|
|
|
}
|
|
|
|
fl_set_input(dialog_->input_width, number.c_str());
|
|
|
|
|
|
|
|
int pos = 1;
|
|
|
|
switch (igp.widthResize) {
|
|
|
|
case InsetGraphicsParams::INCH:
|
|
|
|
pos = 2; break;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
case InsetGraphicsParams::PERCENT_PAGE:
|
|
|
|
pos = 3; break;
|
|
|
|
|
|
|
|
case InsetGraphicsParams::PERCENT_COLUMN:
|
|
|
|
pos = 4; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fl_set_choice(dialog_->choice_width_units, pos);
|
|
|
|
|
|
|
|
number.erase();
|
|
|
|
if (igp.heightResize != InsetGraphicsParams::DEFAULT_SIZE) {
|
|
|
|
number = tostr(igp.heightSize);
|
|
|
|
}
|
|
|
|
fl_set_input(dialog_->input_height, number.c_str());
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
pos = 1;
|
|
|
|
switch (igp.heightResize) {
|
|
|
|
case InsetGraphicsParams::INCH:
|
|
|
|
pos = 2; break;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
case InsetGraphicsParams::PERCENT_PAGE:
|
|
|
|
pos = 3; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fl_set_choice(dialog_->choice_width_units, pos);
|
|
|
|
}
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
// Update the rotate angle
|
|
|
|
fl_set_input(dialog_->input_rotate_angle,
|
|
|
|
tostr(igp.rotateAngle).c_str());
|
|
|
|
|
|
|
|
// Update the subcaption check button and input field
|
|
|
|
fl_set_button(dialog_->check_subcaption,
|
|
|
|
igp.subcaption);
|
|
|
|
fl_set_input(dialog_->input_subcaption,
|
2001-09-13 09:34:39 +00:00
|
|
|
igp.subcaptionText.c_str());
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// Now make sure that the buttons are set correctly.
|
2000-10-24 13:13:59 +00:00
|
|
|
input(0, 0);
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 13:13:59 +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
|
|
|
{
|
2001-09-13 09:34:39 +00:00
|
|
|
if (ob == dialog_->button_browse) {
|
2001-03-30 09:51:46 +00:00
|
|
|
// Get the filename from the dialog
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
|
|
|
string const out_name = controller().Browse(in_name);
|
|
|
|
|
|
|
|
if (out_name != in_name && !out_name.empty()) {
|
|
|
|
fl_set_input(dialog_->input_filename, out_name.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-13 09:34:39 +00:00
|
|
|
if (ob == dialog_->input_scale) {
|
|
|
|
double const scale =
|
|
|
|
strToDbl(fl_get_input(dialog_->input_scale));
|
|
|
|
if (scale > tol) {
|
|
|
|
fl_set_input(dialog_->input_width, "");
|
|
|
|
fl_set_choice(dialog_->choice_width_units, 1);
|
|
|
|
fl_set_input(dialog_->input_height, "");
|
|
|
|
fl_set_choice(dialog_->choice_height_units, 1);
|
|
|
|
}
|
2000-10-24 13:13:59 +00:00
|
|
|
}
|
2001-09-13 09:34:39 +00:00
|
|
|
|
|
|
|
if (ob == dialog_->input_width || ob == dialog_->input_height) {
|
|
|
|
double const width =
|
|
|
|
strToDbl(fl_get_input(dialog_->input_width));
|
|
|
|
double const height =
|
|
|
|
strToDbl(fl_get_input(dialog_->input_height));
|
|
|
|
|
|
|
|
if (width > tol || height > tol) {
|
|
|
|
fl_set_input(dialog_->input_scale, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkInput();
|
2000-10-24 13:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
ButtonPolicy::SMInput FormGraphics::checkInput()
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// Put verifications that the dialog shows some sane values,
|
|
|
|
// if not disallow clicking on ok/apply.
|
|
|
|
// Possibly use a label in the bottom of the dialog to give the reason.
|
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
|
|
|
// We verify now that there is a filename, it exists, it's a file
|
|
|
|
// and it's readable.
|
|
|
|
string filename = fl_get_input(dialog_->input_filename);
|
|
|
|
FileInfo file(filename);
|
|
|
|
if (filename.empty()
|
|
|
|
|| !file.isOK()
|
|
|
|
|| !file.exist()
|
|
|
|
|| !file.isRegular()
|
|
|
|
|| !file.readable()
|
|
|
|
)
|
2001-09-13 09:34:39 +00:00
|
|
|
activate = ButtonPolicy::SMI_INVALID;
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
return activate;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|