1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
10 * \file FormGraphics.C
11 * \author Baruch Even, baruch.even@writeme.com
12 * \author Herbert Voss, voss@perce.de
18 #pragma implementation
22 #include "ControlGraphics.h"
23 #include "FormGraphics.h"
24 #include "form_graphics.h"
27 #include "xforms_helpers.h"
28 #include "input_validators.h"
29 #include "debug.h" // for lyxerr
30 #include "support/lstrings.h" // for strToDbl & tostr
31 #include "support/FileInfo.h"
32 #include "support/filetools.h" // for MakeAbsPath etc
33 #include "insets/insetgraphicsParams.h"
34 #include "lyxrc.h" // for lyxrc.display_graphics
40 // Bound the number of input characters
41 int const SCALE_MAXDIGITS = 3;
42 int const WIDTH_MAXDIGITS = 10;
43 int const HEIGHT_MAXDIGITS = 10;
44 int const ROTATE_MAXCHARS = 4;
45 int const FILENAME_MAXCHARS = 1024;
46 string defaultUnit = "cm";
51 typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
53 FormGraphics::FormGraphics(ControlGraphics & c)
54 : base_class(c, _("Graphics"), false)
58 void FormGraphics::redraw()
60 if (form() && form()->visible)
61 fl_redraw_form(form());
64 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
65 if (outer_form && outer_form->visible)
66 fl_redraw_form(outer_form);
70 void FormGraphics::build()
72 dialog_.reset(build_graphics());
74 // Manage the ok, apply, restore and cancel/close buttons
75 bc().setOK(dialog_->button_ok);
76 bc().setApply(dialog_->button_apply);
77 bc().setCancel(dialog_->button_cancel);
78 bc().setRestore(dialog_->button_restore);
81 file_.reset(build_file());
83 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
84 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
85 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
86 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
87 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
88 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
90 string const choice_origin =
92 "leftTop|leftBottom|leftBaseline|" // lt lb lB
93 "centerTop|centerBottom|centerBaseline|" // ct cb cB
94 "rightTop|rightBottom|rightBaseline"; // rt rb rB
95 fl_addto_choice(file_->choice_origin, choice_origin.c_str());
97 bc().addReadOnly(file_->button_browse);
98 bc().addReadOnly(file_->check_subcaption);
99 bc().addReadOnly(file_->check_rotate);
100 bc().addReadOnly(file_->button_draft);
101 bc().addReadOnly(file_->button_nounzip);
103 // the lyxview section
104 lyxview_.reset(build_lyxview());
106 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
107 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
108 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
110 fl_addto_choice(lyxview_->choice_width_lyxwidth, choice_Length_WithUnit.c_str());
111 fl_addto_choice(lyxview_->choice_width_lyxheight, choice_Length_WithUnit.c_str());
113 bc().addReadOnly(lyxview_->radio_pref);
114 bc().addReadOnly(lyxview_->radio_mono);
115 bc().addReadOnly(lyxview_->radio_gray);
116 bc().addReadOnly(lyxview_->radio_color);
117 bc().addReadOnly(lyxview_->radio_nodisplay);
120 size_.reset(build_size());
122 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
123 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
124 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
126 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
127 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
128 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
130 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
132 fl_addto_choice(size_->choice_width_units, choice_Length_All.c_str());
133 fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
135 bc().addReadOnly(size_->button_asis);
136 bc().addReadOnly(size_->button_wh);
137 bc().addReadOnly(size_->button_scale);
138 bc().addReadOnly(size_->check_aspectratio);
140 // the bounding box selection
141 bbox_.reset(build_bbox());
142 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
143 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
144 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
145 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
147 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
148 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
149 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
151 string const bb_units = "pt|cm|in";
152 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
153 bc().addReadOnly(bbox_->button_getBB);
154 bc().addReadOnly(bbox_->button_clip);
156 // the rotate section
157 special_.reset(build_special());
159 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
161 // add the different tabfolders
162 fl_addto_tabfolder(dialog_->tabFolder, _("File"), file_->form);
163 fl_addto_tabfolder(dialog_->tabFolder, _("LyX View"), lyxview_->form);
164 fl_addto_tabfolder(dialog_->tabFolder, _("LaTeX Size"), size_->form);
165 fl_addto_tabfolder(dialog_->tabFolder, _("Bounding Box"), bbox_->form);
166 fl_addto_tabfolder(dialog_->tabFolder, _("Extras"), special_->form);
170 void FormGraphics::apply()
172 // Create the parameters structure and fill the data from the dialog.
173 InsetGraphicsParams & igp = controller().params();
176 igp.filename = getStringFromInput(file_->input_filename);
177 igp.subcaption = fl_get_button(file_->check_subcaption);
178 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
179 igp.rotate = fl_get_button(file_->check_rotate);
181 strToDbl(getStringFromInput(file_->input_rotate_angle));
182 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
183 if (igp.rotateAngle < 0.0) {
184 igp.rotateAngle += 360.0;
185 } else if (igp.rotateAngle > 360.0) {
186 igp.rotateAngle -= 360.0;
189 if (fl_get_choice(file_->choice_origin) > 0)
190 igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
192 igp.rotateOrigin = string();
193 igp.draft = fl_get_button(file_->button_draft);
194 igp.noUnzip = fl_get_button(file_->button_nounzip);
196 // the lyxview section
197 if (fl_get_button(lyxview_->radio_pref))
198 igp.display = InsetGraphicsParams::DEFAULT;
199 else if (fl_get_button(lyxview_->radio_mono))
200 igp.display = InsetGraphicsParams::MONOCHROME;
201 else if (fl_get_button(lyxview_->radio_gray))
202 igp.display = InsetGraphicsParams::GRAYSCALE;
203 else if (fl_get_button(lyxview_->radio_color))
204 igp.display = InsetGraphicsParams::COLOR;
205 else if (fl_get_button(lyxview_->radio_nodisplay))
206 igp.display = InsetGraphicsParams::NONE;
208 if (fl_get_button(lyxview_->button_lyxasis))
209 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
210 else if (fl_get_button(lyxview_->button_lyxwh))
211 igp.lyxsize_type = InsetGraphicsParams::WH;
213 igp.lyxsize_type = InsetGraphicsParams::SCALE;
214 igp.lyxwidth = LyXLength(getLengthFromWidgets(lyxview_->input_lyxwidth,
215 lyxview_->choice_width_lyxwidth));
216 igp.lyxheight = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
217 lyxview_->choice_width_lyxheight));
218 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
221 if (fl_get_button(size_->button_asis))
222 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
223 else if (fl_get_button(size_->button_wh))
224 igp.size_type = InsetGraphicsParams::WH;
226 igp.size_type = InsetGraphicsParams::SCALE;
227 igp.width = LyXLength(getLengthFromWidgets(size_->input_width,
228 size_->choice_width_units));
229 igp.height = LyXLength(getLengthFromWidgets(size_->input_height,
230 size_->choice_height_units));
231 igp.scale = strToInt(getStringFromInput(size_->input_scale));
232 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
235 if (!controller().bbChanged) // different to the original one?
236 igp.bb = string(); // don't write anything
239 if (getStringFromInput(bbox_->input_bb_x0).empty())
242 bb = getLengthFromWidgets(bbox_->input_bb_x0,
243 bbox_->choice_bb_units)+" ";
244 if (getStringFromInput(bbox_->input_bb_y0).empty())
247 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
248 bbox_->choice_bb_units)+" ");
249 if (getStringFromInput(bbox_->input_bb_x1).empty())
252 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
253 bbox_->choice_bb_units)+" ");
254 if (getStringFromInput(bbox_->input_bb_y1).empty())
257 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
258 bbox_->choice_bb_units)+" ");
261 igp.clip = fl_get_button(bbox_->button_clip);
263 // the special section
264 igp.special = getStringFromInput(special_->input_special);
268 void FormGraphics::update() {
269 if (lyxrc.default_papersize < 3)
270 defaultUnit = string("in");
271 // Update dialog with details from inset
272 InsetGraphicsParams & igp = controller().params();
275 fl_set_input(file_->input_filename, igp.filename.c_str());
276 fl_set_button(file_->check_subcaption, igp.subcaption);
277 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
278 setEnabled(file_->input_subcaption,
279 fl_get_button(file_->check_subcaption));
280 fl_set_button(file_->check_rotate, igp.rotate);
281 fl_set_input(file_->input_rotate_angle,
282 tostr(igp.rotateAngle).c_str());
283 if (igp.rotateOrigin.empty())
284 fl_set_choice(file_->choice_origin,0);
286 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
287 setEnabled(file_->input_rotate_angle,
288 fl_get_button(file_->check_rotate));
289 setEnabled(file_->choice_origin,
290 fl_get_button(file_->check_rotate));
291 fl_set_button(file_->button_draft, igp.draft);
292 fl_set_button(file_->button_nounzip, igp.noUnzip);
294 // the lyxview section
295 switch (igp.display) {
296 case InsetGraphicsParams::DEFAULT:
297 fl_set_button(lyxview_->radio_pref, 1);
299 case InsetGraphicsParams::MONOCHROME:
300 fl_set_button(lyxview_->radio_mono, 1);
302 case InsetGraphicsParams::GRAYSCALE:
303 fl_set_button(lyxview_->radio_gray, 1);
305 case InsetGraphicsParams::COLOR:
306 fl_set_button(lyxview_->radio_color, 1);
308 case InsetGraphicsParams::NONE:
309 fl_set_button(lyxview_->radio_nodisplay, 1);
312 updateWidgetsFromLength(lyxview_->input_lyxwidth,
313 lyxview_->choice_width_lyxwidth, igp.lyxwidth,defaultUnit);
314 updateWidgetsFromLength(lyxview_->input_lyxheight,
315 lyxview_->choice_width_lyxheight, igp.lyxheight,defaultUnit);
316 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
317 switch (igp.lyxsize_type) {
318 case InsetGraphicsParams::DEFAULT_SIZE: {
319 fl_set_button(lyxview_->button_lyxasis,1);
320 setEnabled(lyxview_->input_lyxwidth, 0);
321 setEnabled(lyxview_->choice_width_lyxwidth, 0);
322 setEnabled(lyxview_->input_lyxheight, 0);
323 setEnabled(lyxview_->choice_width_lyxheight, 0);
324 setEnabled(lyxview_->input_lyxscale, 0);
327 case InsetGraphicsParams::WH: {
328 fl_set_button(lyxview_->button_lyxwh, 1);
329 setEnabled(lyxview_->input_lyxwidth, 1);
330 setEnabled(lyxview_->choice_width_lyxwidth, 1);
331 setEnabled(lyxview_->input_lyxheight, 1);
332 setEnabled(lyxview_->choice_width_lyxheight, 1);
333 setEnabled(lyxview_->input_lyxscale, 0);
336 case InsetGraphicsParams::SCALE: {
337 fl_set_button(lyxview_->button_lyxscale, 1);
338 setEnabled(lyxview_->input_lyxwidth, 0);
339 setEnabled(lyxview_->choice_width_lyxwidth, 0);
340 setEnabled(lyxview_->input_lyxheight, 0);
341 setEnabled(lyxview_->choice_width_lyxheight, 0);
342 setEnabled(lyxview_->input_lyxscale, 1);
348 // Update the draft and clip mode
349 updateWidgetsFromLength(size_->input_width,
350 size_->choice_width_units,igp.width,defaultUnit);
351 updateWidgetsFromLength(size_->input_height,
352 size_->choice_height_units,igp.height,defaultUnit);
353 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
354 switch (igp.size_type) {
355 case InsetGraphicsParams::DEFAULT_SIZE: {
356 fl_set_button(size_->button_asis,1);
357 setEnabled(size_->input_width, 0);
358 setEnabled(size_->choice_width_units, 0);
359 setEnabled(size_->input_height, 0);
360 setEnabled(size_->choice_height_units, 0);
361 setEnabled(size_->check_aspectratio, 0);
362 setEnabled(size_->input_scale, 0);
365 case InsetGraphicsParams::WH: {
366 fl_set_button(size_->button_wh, 1);
367 setEnabled(size_->input_width, 1);
368 setEnabled(size_->choice_width_units, 1);
369 setEnabled(size_->input_height, 1);
370 setEnabled(size_->choice_height_units, 1);
371 setEnabled(size_->check_aspectratio, 1);
372 setEnabled(size_->input_scale, 0);
375 case InsetGraphicsParams::SCALE: {
376 fl_set_button(size_->button_scale, 1);
377 setEnabled(size_->input_width, 0);
378 setEnabled(size_->choice_width_units, 0);
379 setEnabled(size_->input_height, 0);
380 setEnabled(size_->choice_height_units, 0);
381 setEnabled(size_->check_aspectratio, 0);
382 setEnabled(size_->input_scale, 1);
386 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
389 // set the bounding box values, if exists. First we need the whole
390 // path, because the controller knows nothing about the doc-dir
391 controller().bbChanged = false;
392 if (igp.bb.empty()) {
393 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
394 string const fileWithAbsPath =
395 MakeAbsPath(igp.filename, OnlyPath(igp.filename));
396 string const bb = controller().readBB(fileWithAbsPath);
398 // get the values from the file
399 // in this case we always have the point-unit
400 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
401 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
402 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
403 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
404 } else { // no bb from file
405 fl_set_input(bbox_->input_bb_x0, bb.c_str());
406 fl_set_input(bbox_->input_bb_y0, bb.c_str());
407 fl_set_input(bbox_->input_bb_x1, bb.c_str());
408 fl_set_input(bbox_->input_bb_y1, bb.c_str());
410 fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
411 } else { // get the values from the inset
412 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
413 controller().bbChanged = true;
415 anyLength = LyXLength(token(igp.bb,' ',0));
416 updateWidgetsFromLength(bbox_->input_bb_x0,
417 bbox_->choice_bb_units,anyLength,"pt");
418 anyLength = LyXLength(token(igp.bb,' ',1));
419 updateWidgetsFromLength(bbox_->input_bb_y0,
420 bbox_->choice_bb_units,anyLength,"pt");
421 anyLength = LyXLength(token(igp.bb,' ',2));
422 updateWidgetsFromLength(bbox_->input_bb_x1,
423 bbox_->choice_bb_units,anyLength,"pt");
424 anyLength = LyXLength(token(igp.bb,' ',3));
425 updateWidgetsFromLength(bbox_->input_bb_y1,
426 bbox_->choice_bb_units,anyLength,"pt");
428 fl_set_button(bbox_->button_clip, igp.clip);
430 // the special section
431 fl_set_input(special_->input_special, igp.special.c_str());
437 bool isValid(FL_OBJECT * ob)
439 string const input = getStringFromInput(ob);
440 return input.empty() || isValidLength(input) || isStrDbl(input);
447 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
450 if (ob == file_->button_browse) {
451 // Get the filename from the dialog
452 string const in_name = getStringFromInput(file_->input_filename);
453 string const out_name = controller().Browse(in_name);
454 if (out_name != in_name && !out_name.empty()) {
455 fl_set_input(file_->input_filename, out_name.c_str());
457 } else if (ob == file_->check_subcaption) {
458 setEnabled(file_->input_subcaption,
459 fl_get_button(file_->check_subcaption));
460 } else if (ob == file_->check_rotate) {
461 setEnabled(file_->input_rotate_angle,
462 fl_get_button(file_->check_rotate));
463 setEnabled(file_->choice_origin,
464 fl_get_button(file_->check_rotate));
466 // the lyxview section
467 } else if (ob == lyxview_->button_lyxasis) {
468 setEnabled(lyxview_->input_lyxwidth, 0);
469 setEnabled(lyxview_->choice_width_lyxwidth, 0);
470 setEnabled(lyxview_->input_lyxheight, 0);
471 setEnabled(lyxview_->choice_width_lyxheight, 0);
472 setEnabled(lyxview_->input_lyxscale, 0);
473 } else if (ob == lyxview_->button_lyxwh) {
474 setEnabled(lyxview_->input_lyxwidth, 1);
475 setEnabled(lyxview_->choice_width_lyxwidth, 1);
476 setEnabled(lyxview_->input_lyxheight, 1);
477 setEnabled(lyxview_->choice_width_lyxheight, 1);
478 setEnabled(lyxview_->input_lyxscale, 0);
479 } else if (ob == lyxview_->button_lyxscale) {
480 setEnabled(lyxview_->input_lyxwidth, 0);
481 setEnabled(lyxview_->choice_width_lyxwidth, 0);
482 setEnabled(lyxview_->input_lyxheight, 0);
483 setEnabled(lyxview_->choice_width_lyxheight, 0);
484 setEnabled(lyxview_->input_lyxscale, 1);
485 } else if (ob == lyxview_->button_latex_values) {
486 if (fl_get_choice(size_->choice_width_units) > 3
487 && fl_get_choice(size_->choice_width_units) < 8
488 || fl_get_choice(size_->choice_height_units) > 3
489 && fl_get_choice(size_->choice_height_units) < 8)
490 Alert::alert(_("Warning!"),
491 _("The units t%, p%, c% and l% are not allowed here."),
492 _("Cannot use the values from LaTeX size!"));
494 LyXLength dummy = LyXLength(getLengthFromWidgets(size_->input_width,
495 size_->choice_width_units));
496 updateWidgetsFromLength(lyxview_->input_lyxwidth,
497 lyxview_->choice_width_lyxwidth, dummy, defaultUnit);
498 dummy = LyXLength(getLengthFromWidgets(size_->input_height,
499 size_->choice_height_units));
500 updateWidgetsFromLength(lyxview_->input_lyxheight,
501 lyxview_->choice_width_lyxheight, dummy, defaultUnit);
502 string const scale = getStringFromInput(size_->input_scale);
503 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
504 if (fl_get_button (size_->button_asis) == 1) {
505 fl_set_button (lyxview_->button_lyxasis, 1);
506 setEnabled(lyxview_->input_lyxwidth, 0);
507 setEnabled(lyxview_->choice_width_lyxwidth, 0);
508 setEnabled(lyxview_->input_lyxheight, 0);
509 setEnabled(lyxview_->choice_width_lyxheight, 0);
510 setEnabled(lyxview_->input_lyxscale, 0);
511 } else if (fl_get_button (size_->button_wh) == 1) {
512 fl_set_button (lyxview_->button_lyxwh, 1);
513 setEnabled(lyxview_->input_lyxwidth, 1);
514 setEnabled(lyxview_->choice_width_lyxwidth, 1);
515 setEnabled(lyxview_->input_lyxheight, 1);
516 setEnabled(lyxview_->choice_width_lyxheight, 1);
517 setEnabled(lyxview_->input_lyxscale, 0);
518 } else if (fl_get_button (size_->button_scale) ==1) {
519 fl_set_button (lyxview_->button_lyxscale, 1);
520 setEnabled(lyxview_->input_lyxwidth, 0);
521 setEnabled(lyxview_->choice_width_lyxwidth, 0);
522 setEnabled(lyxview_->input_lyxheight, 0);
523 setEnabled(lyxview_->choice_width_lyxheight, 0);
524 setEnabled(lyxview_->input_lyxscale, 1);
529 } else if (!controller().bbChanged &&
530 (ob == bbox_->choice_bb_units ||
531 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
532 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
533 controller().bbChanged = true;
534 } else if (ob == bbox_->button_getBB) {
535 string const filename = getStringFromInput(file_->input_filename);
536 if (!filename.empty()) {
537 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
538 string bb = controller().readBB(fileWithAbsPath);
540 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
541 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
542 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
543 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
544 string const unit("pt");
545 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
547 controller().bbChanged = false;
549 fl_set_input(bbox_->input_bb_x0, "");
550 fl_set_input(bbox_->input_bb_y0, "");
551 fl_set_input(bbox_->input_bb_x1, "");
552 fl_set_input(bbox_->input_bb_y1, "");
553 fl_set_choice_text(bbox_->choice_bb_units, "pt");
557 } else if (ob == size_->button_asis) {
558 setEnabled(size_->input_width, 0);
559 setEnabled(size_->choice_width_units, 0);
560 setEnabled(size_->input_height, 0);
561 setEnabled(size_->choice_height_units, 0);
562 setEnabled(size_->check_aspectratio, 0);
563 setEnabled(size_->input_scale, 0);
564 } else if (ob == size_->button_wh) {
565 setEnabled(size_->input_width, 1);
566 setEnabled(size_->choice_width_units, 1);
567 setEnabled(size_->input_height, 1);
568 setEnabled(size_->choice_height_units, 1);
569 setEnabled(size_->check_aspectratio, 1);
570 setEnabled(size_->input_scale, 0);
571 } else if (ob == size_->button_scale) {
572 setEnabled(size_->input_width, 0);
573 setEnabled(size_->choice_width_units, 0);
574 setEnabled(size_->input_height, 0);
575 setEnabled(size_->choice_height_units, 0);
576 setEnabled(size_->check_aspectratio, 0);
577 setEnabled(size_->input_scale, 1);
578 } else if (ob == size_->button_lyx_values) {
579 LyXLength dummy = LyXLength(getLengthFromWidgets(
580 lyxview_->input_lyxwidth, lyxview_->choice_width_lyxwidth));
581 updateWidgetsFromLength(size_->input_width,
582 size_->choice_width_units, dummy, defaultUnit);
583 dummy = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
584 lyxview_->choice_width_lyxheight));
585 updateWidgetsFromLength(size_->input_height,
586 size_->choice_height_units, dummy, defaultUnit);
587 string const scale = getStringFromInput(lyxview_->input_lyxscale);
588 fl_set_input(size_->input_scale, scale.c_str());
589 if (fl_get_button (lyxview_->button_lyxasis) == 1) {
590 fl_set_button (size_->button_asis, 1);
591 setEnabled(size_->input_width, 0);
592 setEnabled(size_->choice_width_units, 0);
593 setEnabled(size_->input_height, 0);
594 setEnabled(size_->choice_height_units, 0);
595 setEnabled(size_->check_aspectratio, 0);
596 setEnabled(size_->input_scale, 0);
597 } else if (fl_get_button (lyxview_->button_lyxwh) == 1) {
598 fl_set_button (size_->button_wh, 1);
599 setEnabled(size_->input_width, 1);
600 setEnabled(size_->choice_width_units, 1);
601 setEnabled(size_->input_height, 1);
602 setEnabled(size_->choice_height_units, 1);
603 setEnabled(size_->check_aspectratio, 1);
604 setEnabled(size_->input_scale, 0);
605 } else if (fl_get_button (lyxview_->button_lyxscale) ==1) {
606 fl_set_button (size_->button_scale, 1);
607 setEnabled(size_->input_width, 0);
608 setEnabled(size_->choice_width_units, 0);
609 setEnabled(size_->input_height, 0);
610 setEnabled(size_->choice_height_units, 0);
611 setEnabled(size_->check_aspectratio, 0);
612 setEnabled(size_->input_scale, 1);
616 // check if the input is valid
617 bool invalid = !isValid(bbox_->input_bb_x0);
618 invalid = invalid || !isValid(bbox_->input_bb_x1);
619 invalid = invalid || !isValid(bbox_->input_bb_y0);
620 invalid = invalid || !isValid(bbox_->input_bb_y1);
621 invalid = invalid || !isValid(size_->input_width);
622 invalid = invalid || !isValid(size_->input_height);
623 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
624 invalid = invalid || !isValid(lyxview_->input_lyxheight);
626 // deactivate OK/ Apply buttons and
627 // spit out warnings if invalid
628 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
629 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
630 ob == size_->input_width || ob == size_->input_height ||
631 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
633 fl_set_object_label(dialog_->text_warning,
634 _("Warning: Invalid Length!"));
635 fl_show_object(dialog_->text_warning);
636 return ButtonPolicy::SMI_INVALID;
638 fl_hide_object(dialog_->text_warning);
642 return ButtonPolicy::SMI_VALID;