3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Baruch Even, baruch.even@writeme.com
7 * \author Herbert Voss, voss@perce.de
13 #pragma implementation
17 #include "ControlGraphics.h"
18 #include "FormGraphics.h"
19 #include "form_graphics.h"
22 #include "xforms_helpers.h"
23 #include "input_validators.h"
24 #include "debug.h" // for lyxerr
25 #include "support/lstrings.h" // for strToDbl & tostr
26 #include "support/filetools.h" // for MakeAbsPath etc
27 #include "insets/insetgraphicsParams.h"
28 #include "lyxrc.h" // for lyxrc.display_graphics
34 // Bound the number of input characters
35 int const SCALE_MAXDIGITS = 3;
36 int const WIDTH_MAXDIGITS = 10;
37 int const HEIGHT_MAXDIGITS = 10;
38 int const ROTATE_MAXCHARS = 4;
39 int const FILENAME_MAXCHARS = 1024;
40 string defaultUnit("cm");
45 typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
47 FormGraphics::FormGraphics(ControlGraphics & c)
48 : base_class(c, _("Graphics"), false)
52 void FormGraphics::redraw()
54 if (form() && form()->visible)
55 fl_redraw_form(form());
58 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
59 if (outer_form && outer_form->visible)
60 fl_redraw_form(outer_form);
64 void FormGraphics::build()
66 dialog_.reset(build_graphics());
68 // Manage the ok, apply, restore and cancel/close buttons
69 bc().setOK(dialog_->button_ok);
70 bc().setApply(dialog_->button_apply);
71 bc().setCancel(dialog_->button_cancel);
72 bc().setRestore(dialog_->button_restore);
75 file_.reset(build_file());
77 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
78 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
79 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
80 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
81 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
82 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
84 string const choice_origin =
86 "leftTop|leftBottom|leftBaseline|" // lt lb lB
87 "centerTop|centerBottom|centerBaseline|" // ct cb cB
88 "rightTop|rightBottom|rightBaseline"; // rt rb rB
89 fl_addto_choice(file_->choice_origin, choice_origin.c_str());
91 bc().addReadOnly(file_->button_browse);
92 bc().addReadOnly(file_->check_subcaption);
93 bc().addReadOnly(file_->check_rotate);
94 bc().addReadOnly(file_->button_draft);
95 bc().addReadOnly(file_->button_nounzip);
97 // the lyxview section
98 lyxview_.reset(build_lyxview());
100 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
101 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
102 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
104 fl_addto_choice(lyxview_->choice_width_lyxwidth, choice_Length_WithUnit.c_str());
105 fl_addto_choice(lyxview_->choice_width_lyxheight, choice_Length_WithUnit.c_str());
107 bc().addReadOnly(lyxview_->radio_pref);
108 bc().addReadOnly(lyxview_->radio_mono);
109 bc().addReadOnly(lyxview_->radio_gray);
110 bc().addReadOnly(lyxview_->radio_color);
111 bc().addReadOnly(lyxview_->radio_nodisplay);
114 size_.reset(build_size());
116 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
117 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
118 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
120 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
121 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
122 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
124 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
126 fl_addto_choice(size_->choice_width_units, choice_Length_All.c_str());
127 fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
129 bc().addReadOnly(size_->button_asis);
130 bc().addReadOnly(size_->button_wh);
131 bc().addReadOnly(size_->button_scale);
132 bc().addReadOnly(size_->check_aspectratio);
134 // the bounding box selection
135 bbox_.reset(build_bbox());
136 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
137 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
138 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
139 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
141 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
142 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
143 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
145 string const bb_units = "pt|cm|in";
146 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
147 bc().addReadOnly(bbox_->button_getBB);
148 bc().addReadOnly(bbox_->button_clip);
150 // the rotate section
151 special_.reset(build_special());
153 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
155 // add the different tabfolders
156 fl_addto_tabfolder(dialog_->tabFolder, _("File"), file_->form);
157 fl_addto_tabfolder(dialog_->tabFolder, _("LyX View"), lyxview_->form);
158 fl_addto_tabfolder(dialog_->tabFolder, _("LaTeX Size"), size_->form);
159 fl_addto_tabfolder(dialog_->tabFolder, _("Bounding Box"), bbox_->form);
160 fl_addto_tabfolder(dialog_->tabFolder, _("Extras"), special_->form);
161 // set the right default unit
162 if (lyxrc.default_papersize < 3)
167 void FormGraphics::apply()
169 // Create the parameters structure and fill the data from the dialog.
170 InsetGraphicsParams & igp = controller().params();
173 igp.filename = getStringFromInput(file_->input_filename);
174 controller().checkFilename(igp.filename);
175 igp.subcaption = fl_get_button(file_->check_subcaption);
176 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
177 igp.rotate = fl_get_button(file_->check_rotate);
179 strToDbl(getStringFromInput(file_->input_rotate_angle));
180 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
181 if (igp.rotateAngle < 0.0) {
182 igp.rotateAngle += 360.0;
183 } else if (igp.rotateAngle > 360.0) {
184 igp.rotateAngle -= 360.0;
187 if (fl_get_choice(file_->choice_origin) > 0)
188 igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
190 igp.rotateOrigin = string();
191 igp.draft = fl_get_button(file_->button_draft);
192 igp.noUnzip = fl_get_button(file_->button_nounzip);
194 // the lyxview section
195 if (fl_get_button(lyxview_->radio_pref))
196 igp.display = InsetGraphicsParams::DEFAULT;
197 else if (fl_get_button(lyxview_->radio_mono))
198 igp.display = InsetGraphicsParams::MONOCHROME;
199 else if (fl_get_button(lyxview_->radio_gray))
200 igp.display = InsetGraphicsParams::GRAYSCALE;
201 else if (fl_get_button(lyxview_->radio_color))
202 igp.display = InsetGraphicsParams::COLOR;
203 else if (fl_get_button(lyxview_->radio_nodisplay))
204 igp.display = InsetGraphicsParams::NONE;
206 if (fl_get_button(lyxview_->button_lyxasis))
207 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
208 else if (fl_get_button(lyxview_->button_lyxwh))
209 igp.lyxsize_type = InsetGraphicsParams::WH;
211 igp.lyxsize_type = InsetGraphicsParams::SCALE;
212 igp.lyxwidth = LyXLength(getLengthFromWidgets(lyxview_->input_lyxwidth,
213 lyxview_->choice_width_lyxwidth));
214 igp.lyxheight = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
215 lyxview_->choice_width_lyxheight));
216 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
219 if (fl_get_button(size_->button_asis))
220 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
221 else if (fl_get_button(size_->button_wh))
222 igp.size_type = InsetGraphicsParams::WH;
224 igp.size_type = InsetGraphicsParams::SCALE;
225 igp.width = LyXLength(getLengthFromWidgets(size_->input_width,
226 size_->choice_width_units));
227 igp.height = LyXLength(getLengthFromWidgets(size_->input_height,
228 size_->choice_height_units));
229 igp.scale = strToInt(getStringFromInput(size_->input_scale));
230 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
233 if (!controller().bbChanged) // different to the original one?
234 igp.bb = string(); // don't write anything
237 if (getStringFromInput(bbox_->input_bb_x0).empty())
240 bb = getLengthFromWidgets(bbox_->input_bb_x0,
241 bbox_->choice_bb_units)+" ";
242 if (getStringFromInput(bbox_->input_bb_y0).empty())
245 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
246 bbox_->choice_bb_units)+" ");
247 if (getStringFromInput(bbox_->input_bb_x1).empty())
250 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
251 bbox_->choice_bb_units)+" ");
252 if (getStringFromInput(bbox_->input_bb_y1).empty())
255 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
256 bbox_->choice_bb_units)+" ");
259 igp.clip = fl_get_button(bbox_->button_clip);
261 // the special section
262 igp.special = getStringFromInput(special_->input_special);
266 void FormGraphics::update() {
267 // Update dialog with details from inset
268 InsetGraphicsParams & igp = controller().params();
271 fl_set_input(file_->input_filename, igp.filename.c_str());
272 fl_set_button(file_->check_subcaption, igp.subcaption);
273 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
274 setEnabled(file_->input_subcaption,
275 fl_get_button(file_->check_subcaption));
276 fl_set_button(file_->check_rotate, igp.rotate);
277 fl_set_input(file_->input_rotate_angle,
278 tostr(igp.rotateAngle).c_str());
279 if (igp.rotateOrigin.empty())
280 fl_set_choice(file_->choice_origin,1);
282 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
283 setEnabled(file_->input_rotate_angle,
284 fl_get_button(file_->check_rotate));
285 setEnabled(file_->choice_origin,
286 fl_get_button(file_->check_rotate));
287 fl_set_button(file_->button_draft, igp.draft);
288 fl_set_button(file_->button_nounzip, igp.noUnzip);
290 // the lyxview section
291 switch (igp.display) {
292 case InsetGraphicsParams::DEFAULT:
293 fl_set_button(lyxview_->radio_pref, 1);
295 case InsetGraphicsParams::MONOCHROME:
296 fl_set_button(lyxview_->radio_mono, 1);
298 case InsetGraphicsParams::GRAYSCALE:
299 fl_set_button(lyxview_->radio_gray, 1);
301 case InsetGraphicsParams::COLOR:
302 fl_set_button(lyxview_->radio_color, 1);
304 case InsetGraphicsParams::NONE:
305 fl_set_button(lyxview_->radio_nodisplay, 1);
308 updateWidgetsFromLength(lyxview_->input_lyxwidth,
309 lyxview_->choice_width_lyxwidth, igp.lyxwidth, defaultUnit);
310 updateWidgetsFromLength(lyxview_->input_lyxheight,
311 lyxview_->choice_width_lyxheight, igp.lyxheight, defaultUnit);
312 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
313 switch (igp.lyxsize_type) {
314 case InsetGraphicsParams::DEFAULT_SIZE: {
315 fl_set_button(lyxview_->button_lyxasis,1);
316 setEnabled(lyxview_->input_lyxwidth, 0);
317 setEnabled(lyxview_->choice_width_lyxwidth, 0);
318 setEnabled(lyxview_->input_lyxheight, 0);
319 setEnabled(lyxview_->choice_width_lyxheight, 0);
320 setEnabled(lyxview_->input_lyxscale, 0);
323 case InsetGraphicsParams::WH: {
324 fl_set_button(lyxview_->button_lyxwh, 1);
325 setEnabled(lyxview_->input_lyxwidth, 1);
326 setEnabled(lyxview_->choice_width_lyxwidth, 1);
327 setEnabled(lyxview_->input_lyxheight, 1);
328 setEnabled(lyxview_->choice_width_lyxheight, 1);
329 setEnabled(lyxview_->input_lyxscale, 0);
332 case InsetGraphicsParams::SCALE: {
333 fl_set_button(lyxview_->button_lyxscale, 1);
334 setEnabled(lyxview_->input_lyxwidth, 0);
335 setEnabled(lyxview_->choice_width_lyxwidth, 0);
336 setEnabled(lyxview_->input_lyxheight, 0);
337 setEnabled(lyxview_->choice_width_lyxheight, 0);
338 setEnabled(lyxview_->input_lyxscale, 1);
344 // Update the draft and clip mode
345 updateWidgetsFromLength(size_->input_width,
346 size_->choice_width_units, igp.width, defaultUnit);
347 updateWidgetsFromLength(size_->input_height,
348 size_->choice_height_units, igp.height, defaultUnit);
349 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
350 switch (igp.size_type) {
351 case InsetGraphicsParams::DEFAULT_SIZE: {
352 fl_set_button(size_->button_asis,1);
353 setEnabled(size_->input_width, 0);
354 setEnabled(size_->choice_width_units, 0);
355 setEnabled(size_->input_height, 0);
356 setEnabled(size_->choice_height_units, 0);
357 setEnabled(size_->check_aspectratio, 0);
358 setEnabled(size_->input_scale, 0);
361 case InsetGraphicsParams::WH: {
362 fl_set_button(size_->button_wh, 1);
363 setEnabled(size_->input_width, 1);
364 setEnabled(size_->choice_width_units, 1);
365 setEnabled(size_->input_height, 1);
366 setEnabled(size_->choice_height_units, 1);
367 setEnabled(size_->check_aspectratio, 1);
368 setEnabled(size_->input_scale, 0);
371 case InsetGraphicsParams::SCALE: {
372 fl_set_button(size_->button_scale, 1);
373 setEnabled(size_->input_width, 0);
374 setEnabled(size_->choice_width_units, 0);
375 setEnabled(size_->input_height, 0);
376 setEnabled(size_->choice_height_units, 0);
377 setEnabled(size_->check_aspectratio, 0);
378 setEnabled(size_->input_scale, 1);
382 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
385 // set the bounding box values, if exists. First we need the whole
386 // path, because the controller knows nothing about the doc-dir
387 controller().bbChanged = false;
388 if (igp.bb.empty()) {
389 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
390 string const fileWithAbsPath =
391 MakeAbsPath(igp.filename, OnlyPath(igp.filename));
392 string const bb = controller().readBB(fileWithAbsPath);
394 // get the values from the file
395 // in this case we always have the point-unit
396 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
397 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
398 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
399 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
400 } else { // no bb from file
401 fl_set_input(bbox_->input_bb_x0, bb.c_str());
402 fl_set_input(bbox_->input_bb_y0, bb.c_str());
403 fl_set_input(bbox_->input_bb_x1, bb.c_str());
404 fl_set_input(bbox_->input_bb_y1, bb.c_str());
406 fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
407 } else { // get the values from the inset
408 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
409 controller().bbChanged = true;
411 anyLength = LyXLength(token(igp.bb,' ',0));
412 updateWidgetsFromLength(bbox_->input_bb_x0,
413 bbox_->choice_bb_units,anyLength,"pt");
414 anyLength = LyXLength(token(igp.bb,' ',1));
415 updateWidgetsFromLength(bbox_->input_bb_y0,
416 bbox_->choice_bb_units,anyLength,"pt");
417 anyLength = LyXLength(token(igp.bb,' ',2));
418 updateWidgetsFromLength(bbox_->input_bb_x1,
419 bbox_->choice_bb_units,anyLength,"pt");
420 anyLength = LyXLength(token(igp.bb,' ',3));
421 updateWidgetsFromLength(bbox_->input_bb_y1,
422 bbox_->choice_bb_units,anyLength,"pt");
424 fl_set_button(bbox_->button_clip, igp.clip);
426 // the special section
427 fl_set_input(special_->input_special, igp.special.c_str());
433 bool isValid(FL_OBJECT * ob)
435 string const input = getStringFromInput(ob);
436 return input.empty() || isValidLength(input) || isStrDbl(input);
443 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
446 if (ob == file_->button_browse) {
447 // Get the filename from the dialog
448 string const in_name = getStringFromInput(file_->input_filename);
449 string const out_name = controller().Browse(in_name);
450 if (out_name != in_name && !out_name.empty()) {
451 fl_set_input(file_->input_filename, out_name.c_str());
453 } else if (ob == file_->check_subcaption) {
454 setEnabled(file_->input_subcaption,
455 fl_get_button(file_->check_subcaption));
456 } else if (ob == file_->check_rotate) {
457 setEnabled(file_->input_rotate_angle,
458 fl_get_button(file_->check_rotate));
459 setEnabled(file_->choice_origin,
460 fl_get_button(file_->check_rotate));
462 // the lyxview section
463 } else if (ob == lyxview_->button_lyxasis) {
464 setEnabled(lyxview_->input_lyxwidth, 0);
465 setEnabled(lyxview_->choice_width_lyxwidth, 0);
466 setEnabled(lyxview_->input_lyxheight, 0);
467 setEnabled(lyxview_->choice_width_lyxheight, 0);
468 setEnabled(lyxview_->input_lyxscale, 0);
469 } else if (ob == lyxview_->button_lyxwh) {
470 setEnabled(lyxview_->input_lyxwidth, 1);
471 setEnabled(lyxview_->choice_width_lyxwidth, 1);
472 setEnabled(lyxview_->input_lyxheight, 1);
473 setEnabled(lyxview_->choice_width_lyxheight, 1);
474 setEnabled(lyxview_->input_lyxscale, 0);
475 } else if (ob == lyxview_->button_lyxscale) {
476 setEnabled(lyxview_->input_lyxwidth, 0);
477 setEnabled(lyxview_->choice_width_lyxwidth, 0);
478 setEnabled(lyxview_->input_lyxheight, 0);
479 setEnabled(lyxview_->choice_width_lyxheight, 0);
480 setEnabled(lyxview_->input_lyxscale, 1);
481 } else if (ob == lyxview_->button_latex_values) {
482 if (contains(fl_get_choice_text(size_->choice_width_units),'%'))
483 Alert::alert(_("Warning!"),
484 _("The units t%, p%, c% and l% are not allowed here."),
485 _("Cannot use the values from LaTeX size!"));
487 LyXLength dummy = LyXLength(getLengthFromWidgets(size_->input_width,
488 size_->choice_width_units));
489 updateWidgetsFromLength(lyxview_->input_lyxwidth,
490 lyxview_->choice_width_lyxwidth, dummy, defaultUnit);
491 dummy = LyXLength(getLengthFromWidgets(size_->input_height,
492 size_->choice_height_units));
493 updateWidgetsFromLength(lyxview_->input_lyxheight,
494 lyxview_->choice_width_lyxheight, dummy, defaultUnit);
495 string const scale = getStringFromInput(size_->input_scale);
496 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
497 if (fl_get_button (size_->button_asis) == 1) {
498 fl_set_button (lyxview_->button_lyxasis, 1);
499 setEnabled(lyxview_->input_lyxwidth, 0);
500 setEnabled(lyxview_->choice_width_lyxwidth, 0);
501 setEnabled(lyxview_->input_lyxheight, 0);
502 setEnabled(lyxview_->choice_width_lyxheight, 0);
503 setEnabled(lyxview_->input_lyxscale, 0);
504 } else if (fl_get_button (size_->button_wh) == 1) {
505 fl_set_button (lyxview_->button_lyxwh, 1);
506 setEnabled(lyxview_->input_lyxwidth, 1);
507 setEnabled(lyxview_->choice_width_lyxwidth, 1);
508 setEnabled(lyxview_->input_lyxheight, 1);
509 setEnabled(lyxview_->choice_width_lyxheight, 1);
510 setEnabled(lyxview_->input_lyxscale, 0);
511 } else if (fl_get_button (size_->button_scale) ==1) {
512 fl_set_button (lyxview_->button_lyxscale, 1);
513 setEnabled(lyxview_->input_lyxwidth, 0);
514 setEnabled(lyxview_->choice_width_lyxwidth, 0);
515 setEnabled(lyxview_->input_lyxheight, 0);
516 setEnabled(lyxview_->choice_width_lyxheight, 0);
517 setEnabled(lyxview_->input_lyxscale, 1);
522 } else if (!controller().bbChanged &&
523 (ob == bbox_->choice_bb_units ||
524 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
525 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
526 controller().bbChanged = true;
527 } else if (ob == bbox_->button_getBB) {
528 string const filename = getStringFromInput(file_->input_filename);
529 if (!filename.empty()) {
530 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
531 string bb = controller().readBB(fileWithAbsPath);
533 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
534 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
535 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
536 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
537 string const unit("pt");
538 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
540 controller().bbChanged = false;
542 fl_set_input(bbox_->input_bb_x0, "");
543 fl_set_input(bbox_->input_bb_y0, "");
544 fl_set_input(bbox_->input_bb_x1, "");
545 fl_set_input(bbox_->input_bb_y1, "");
546 fl_set_choice_text(bbox_->choice_bb_units, "pt");
550 } else if (ob == size_->button_asis) {
551 setEnabled(size_->input_width, 0);
552 setEnabled(size_->choice_width_units, 0);
553 setEnabled(size_->input_height, 0);
554 setEnabled(size_->choice_height_units, 0);
555 setEnabled(size_->check_aspectratio, 0);
556 setEnabled(size_->input_scale, 0);
557 } else if (ob == size_->button_wh) {
558 setEnabled(size_->input_width, 1);
559 setEnabled(size_->choice_width_units, 1);
560 setEnabled(size_->input_height, 1);
561 setEnabled(size_->choice_height_units, 1);
562 setEnabled(size_->check_aspectratio, 1);
563 setEnabled(size_->input_scale, 0);
564 } else if (ob == size_->button_scale) {
565 setEnabled(size_->input_width, 0);
566 setEnabled(size_->choice_width_units, 0);
567 setEnabled(size_->input_height, 0);
568 setEnabled(size_->choice_height_units, 0);
569 setEnabled(size_->check_aspectratio, 0);
570 setEnabled(size_->input_scale, 1);
571 } else if (ob == size_->button_lyx_values) {
572 LyXLength dummy = LyXLength(getLengthFromWidgets(
573 lyxview_->input_lyxwidth, lyxview_->choice_width_lyxwidth));
574 updateWidgetsFromLength(size_->input_width,
575 size_->choice_width_units, dummy, defaultUnit);
576 dummy = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
577 lyxview_->choice_width_lyxheight));
578 updateWidgetsFromLength(size_->input_height,
579 size_->choice_height_units, dummy, defaultUnit);
580 string const scale = getStringFromInput(lyxview_->input_lyxscale);
581 fl_set_input(size_->input_scale, scale.c_str());
582 if (fl_get_button (lyxview_->button_lyxasis) == 1) {
583 fl_set_button (size_->button_asis, 1);
584 setEnabled(size_->input_width, 0);
585 setEnabled(size_->choice_width_units, 0);
586 setEnabled(size_->input_height, 0);
587 setEnabled(size_->choice_height_units, 0);
588 setEnabled(size_->check_aspectratio, 0);
589 setEnabled(size_->input_scale, 0);
590 } else if (fl_get_button (lyxview_->button_lyxwh) == 1) {
591 fl_set_button (size_->button_wh, 1);
592 setEnabled(size_->input_width, 1);
593 setEnabled(size_->choice_width_units, 1);
594 setEnabled(size_->input_height, 1);
595 setEnabled(size_->choice_height_units, 1);
596 setEnabled(size_->check_aspectratio, 1);
597 setEnabled(size_->input_scale, 0);
598 } else if (fl_get_button (lyxview_->button_lyxscale) ==1) {
599 fl_set_button (size_->button_scale, 1);
600 setEnabled(size_->input_width, 0);
601 setEnabled(size_->choice_width_units, 0);
602 setEnabled(size_->input_height, 0);
603 setEnabled(size_->choice_height_units, 0);
604 setEnabled(size_->check_aspectratio, 0);
605 setEnabled(size_->input_scale, 1);
609 // check if the input is valid
610 bool invalid = !isValid(bbox_->input_bb_x0);
611 invalid = invalid || !isValid(bbox_->input_bb_x1);
612 invalid = invalid || !isValid(bbox_->input_bb_y0);
613 invalid = invalid || !isValid(bbox_->input_bb_y1);
614 invalid = invalid || !isValid(size_->input_width);
615 invalid = invalid || !isValid(size_->input_height);
616 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
617 invalid = invalid || !isValid(lyxview_->input_lyxheight);
619 // deactivate OK/ Apply buttons and
620 // spit out warnings if invalid
621 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
622 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
623 ob == size_->input_width || ob == size_->input_height ||
624 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
626 fl_set_object_label(dialog_->text_warning,
627 _("Warning: Invalid Length!"));
628 fl_show_object(dialog_->text_warning);
629 return ButtonPolicy::SMI_INVALID;
631 fl_hide_object(dialog_->text_warning);
635 return ButtonPolicy::SMI_VALID;