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 // Allow the base class to control messages
69 setMessageWidget(dialog_->text_warning);
71 // Manage the ok, apply, restore and cancel/close buttons
72 bc().setOK(dialog_->button_ok);
73 bc().setApply(dialog_->button_apply);
74 bc().setCancel(dialog_->button_close);
75 bc().setRestore(dialog_->button_restore);
78 file_.reset(build_file());
80 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
81 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
82 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
83 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
84 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
85 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
87 setPrehandler(file_->input_filename);
88 setPrehandler(file_->input_subcaption);
89 setPrehandler(file_->input_rotate_angle);
91 string const choice_origin =
93 "leftTop|leftBottom|leftBaseline|" // lt lb lB
94 "centerTop|centerBottom|centerBaseline|" // ct cb cB
95 "rightTop|rightBottom|rightBaseline"; // rt rb rB
96 fl_addto_choice(file_->choice_origin, choice_origin.c_str());
98 bc().addReadOnly(file_->button_browse);
99 bc().addReadOnly(file_->check_subcaption);
100 bc().addReadOnly(file_->check_rotate);
101 bc().addReadOnly(file_->check_draft);
102 bc().addReadOnly(file_->check_nounzip);
104 // the lyxview section
105 lyxview_.reset(build_lyxview());
107 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
108 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
109 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
111 setPrehandler(lyxview_->input_lyxwidth);
112 setPrehandler(lyxview_->input_lyxheight);
113 setPrehandler(lyxview_->input_lyxscale);
115 fl_addto_choice(lyxview_->choice_width_lyxwidth, choice_Length_WithUnit.c_str());
116 fl_addto_choice(lyxview_->choice_width_lyxheight, choice_Length_WithUnit.c_str());
118 bc().addReadOnly(lyxview_->radio_pref);
119 bc().addReadOnly(lyxview_->radio_mono);
120 bc().addReadOnly(lyxview_->radio_gray);
121 bc().addReadOnly(lyxview_->radio_color);
122 bc().addReadOnly(lyxview_->radio_nodisplay);
125 size_.reset(build_size());
127 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
128 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
129 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
131 setPrehandler(size_->input_scale);
132 setPrehandler(size_->input_width);
133 setPrehandler(size_->input_height);
135 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
136 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
137 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
139 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
141 fl_addto_choice(size_->choice_width_units, choice_Length_All.c_str());
142 fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
144 bc().addReadOnly(size_->radio_asis);
145 bc().addReadOnly(size_->radio_wh);
146 bc().addReadOnly(size_->radio_scale);
147 bc().addReadOnly(size_->check_aspectratio);
149 // the bounding box selection
150 bbox_.reset(build_bbox());
151 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
152 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
153 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
154 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
156 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
157 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
158 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
159 fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
161 setPrehandler(bbox_->input_bb_x0);
162 setPrehandler(bbox_->input_bb_y0);
163 setPrehandler(bbox_->input_bb_x1);
164 setPrehandler(bbox_->input_bb_y1);
166 string const bb_units = "pt|cm|in";
167 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
168 bc().addReadOnly(bbox_->button_getBB);
169 bc().addReadOnly(bbox_->check_clip);
171 // the rotate section
172 special_.reset(build_special());
174 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
175 setPrehandler(special_->input_special);
177 // add the different tabfolders
178 fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
179 fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
180 fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
181 fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
182 fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
183 // set the right default unit
184 if (lyxrc.default_papersize < 3)
189 void FormGraphics::apply()
191 // Create the parameters structure and fill the data from the dialog.
192 InsetGraphicsParams & igp = controller().params();
195 igp.filename = getStringFromInput(file_->input_filename);
196 controller().checkFilename(igp.filename);
197 igp.subcaption = fl_get_button(file_->check_subcaption);
198 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
199 igp.rotate = fl_get_button(file_->check_rotate);
201 strToDbl(getStringFromInput(file_->input_rotate_angle));
202 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
203 if (igp.rotateAngle < 0.0) {
204 igp.rotateAngle += 360.0;
205 } else if (igp.rotateAngle > 360.0) {
206 igp.rotateAngle -= 360.0;
209 if (fl_get_choice(file_->choice_origin) > 0)
210 igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
212 igp.rotateOrigin = string();
213 igp.draft = fl_get_button(file_->check_draft);
214 igp.noUnzip = fl_get_button(file_->check_nounzip);
216 // the lyxview section
217 if (fl_get_button(lyxview_->radio_pref))
218 igp.display = InsetGraphicsParams::DEFAULT;
219 else if (fl_get_button(lyxview_->radio_mono))
220 igp.display = InsetGraphicsParams::MONOCHROME;
221 else if (fl_get_button(lyxview_->radio_gray))
222 igp.display = InsetGraphicsParams::GRAYSCALE;
223 else if (fl_get_button(lyxview_->radio_color))
224 igp.display = InsetGraphicsParams::COLOR;
225 else if (fl_get_button(lyxview_->radio_nodisplay))
226 igp.display = InsetGraphicsParams::NONE;
228 if (fl_get_button(lyxview_->radio_lyxasis))
229 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
230 else if (fl_get_button(lyxview_->radio_lyxwh))
231 igp.lyxsize_type = InsetGraphicsParams::WH;
233 igp.lyxsize_type = InsetGraphicsParams::SCALE;
234 igp.lyxwidth = LyXLength(getLengthFromWidgets(lyxview_->input_lyxwidth,
235 lyxview_->choice_width_lyxwidth));
236 igp.lyxheight = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
237 lyxview_->choice_width_lyxheight));
238 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
241 if (fl_get_button(size_->radio_asis))
242 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
243 else if (fl_get_button(size_->radio_wh))
244 igp.size_type = InsetGraphicsParams::WH;
246 igp.size_type = InsetGraphicsParams::SCALE;
247 igp.width = LyXLength(getLengthFromWidgets(size_->input_width,
248 size_->choice_width_units));
249 igp.height = LyXLength(getLengthFromWidgets(size_->input_height,
250 size_->choice_height_units));
251 igp.scale = strToInt(getStringFromInput(size_->input_scale));
252 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
255 if (!controller().bbChanged) // different to the original one?
256 igp.bb = string(); // don't write anything
259 if (getStringFromInput(bbox_->input_bb_x0).empty())
262 bb = getLengthFromWidgets(bbox_->input_bb_x0,
263 bbox_->choice_bb_units)+" ";
264 if (getStringFromInput(bbox_->input_bb_y0).empty())
267 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
268 bbox_->choice_bb_units)+" ");
269 if (getStringFromInput(bbox_->input_bb_x1).empty())
272 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
273 bbox_->choice_bb_units)+" ");
274 if (getStringFromInput(bbox_->input_bb_y1).empty())
277 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
278 bbox_->choice_bb_units)+" ");
281 igp.clip = fl_get_button(bbox_->check_clip);
283 // the special section
284 igp.special = getStringFromInput(special_->input_special);
288 void FormGraphics::update() {
289 // Update dialog with details from inset
290 InsetGraphicsParams & igp = controller().params();
293 fl_set_input(file_->input_filename, igp.filename.c_str());
294 fl_set_button(file_->check_subcaption, igp.subcaption);
295 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
296 setEnabled(file_->input_subcaption,
297 fl_get_button(file_->check_subcaption));
298 fl_set_button(file_->check_rotate, igp.rotate);
299 fl_set_input(file_->input_rotate_angle,
300 tostr(igp.rotateAngle).c_str());
301 if (igp.rotateOrigin.empty())
302 fl_set_choice(file_->choice_origin,1);
304 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
305 setEnabled(file_->input_rotate_angle,
306 fl_get_button(file_->check_rotate));
307 setEnabled(file_->choice_origin,
308 fl_get_button(file_->check_rotate));
309 fl_set_button(file_->check_draft, igp.draft);
310 fl_set_button(file_->check_nounzip, igp.noUnzip);
312 // the lyxview section
313 switch (igp.display) {
314 case InsetGraphicsParams::DEFAULT:
315 fl_set_button(lyxview_->radio_pref, 1);
317 case InsetGraphicsParams::MONOCHROME:
318 fl_set_button(lyxview_->radio_mono, 1);
320 case InsetGraphicsParams::GRAYSCALE:
321 fl_set_button(lyxview_->radio_gray, 1);
323 case InsetGraphicsParams::COLOR:
324 fl_set_button(lyxview_->radio_color, 1);
326 case InsetGraphicsParams::NONE:
327 fl_set_button(lyxview_->radio_nodisplay, 1);
330 updateWidgetsFromLength(lyxview_->input_lyxwidth,
331 lyxview_->choice_width_lyxwidth, igp.lyxwidth, defaultUnit);
332 updateWidgetsFromLength(lyxview_->input_lyxheight,
333 lyxview_->choice_width_lyxheight, igp.lyxheight, defaultUnit);
334 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
335 switch (igp.lyxsize_type) {
336 case InsetGraphicsParams::DEFAULT_SIZE: {
337 fl_set_button(lyxview_->radio_lyxasis,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, 0);
345 case InsetGraphicsParams::WH: {
346 fl_set_button(lyxview_->radio_lyxwh, 1);
347 setEnabled(lyxview_->input_lyxwidth, 1);
348 setEnabled(lyxview_->choice_width_lyxwidth, 1);
349 setEnabled(lyxview_->input_lyxheight, 1);
350 setEnabled(lyxview_->choice_width_lyxheight, 1);
351 setEnabled(lyxview_->input_lyxscale, 0);
354 case InsetGraphicsParams::SCALE: {
355 fl_set_button(lyxview_->radio_lyxscale, 1);
356 setEnabled(lyxview_->input_lyxwidth, 0);
357 setEnabled(lyxview_->choice_width_lyxwidth, 0);
358 setEnabled(lyxview_->input_lyxheight, 0);
359 setEnabled(lyxview_->choice_width_lyxheight, 0);
360 setEnabled(lyxview_->input_lyxscale, 1);
366 // Update the draft and clip mode
367 updateWidgetsFromLength(size_->input_width,
368 size_->choice_width_units, igp.width, defaultUnit);
369 updateWidgetsFromLength(size_->input_height,
370 size_->choice_height_units, igp.height, defaultUnit);
371 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
372 switch (igp.size_type) {
373 case InsetGraphicsParams::DEFAULT_SIZE: {
374 fl_set_button(size_->radio_asis,1);
375 setEnabled(size_->input_width, 0);
376 setEnabled(size_->choice_width_units, 0);
377 setEnabled(size_->input_height, 0);
378 setEnabled(size_->choice_height_units, 0);
379 setEnabled(size_->check_aspectratio, 0);
380 setEnabled(size_->input_scale, 0);
383 case InsetGraphicsParams::WH: {
384 fl_set_button(size_->radio_wh, 1);
385 setEnabled(size_->input_width, 1);
386 setEnabled(size_->choice_width_units, 1);
387 setEnabled(size_->input_height, 1);
388 setEnabled(size_->choice_height_units, 1);
389 setEnabled(size_->check_aspectratio, 1);
390 setEnabled(size_->input_scale, 0);
393 case InsetGraphicsParams::SCALE: {
394 fl_set_button(size_->radio_scale, 1);
395 setEnabled(size_->input_width, 0);
396 setEnabled(size_->choice_width_units, 0);
397 setEnabled(size_->input_height, 0);
398 setEnabled(size_->choice_height_units, 0);
399 setEnabled(size_->check_aspectratio, 0);
400 setEnabled(size_->input_scale, 1);
404 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
407 // set the bounding box values, if exists. First we need the whole
408 // path, because the controller knows nothing about the doc-dir
409 controller().bbChanged = false;
410 if (igp.bb.empty()) {
411 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
412 string const fileWithAbsPath =
413 MakeAbsPath(igp.filename, OnlyPath(igp.filename));
414 string const bb = controller().readBB(fileWithAbsPath);
416 // get the values from the file
417 // in this case we always have the point-unit
418 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
419 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
420 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
421 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
422 } else { // no bb from file
423 fl_set_input(bbox_->input_bb_x0, bb.c_str());
424 fl_set_input(bbox_->input_bb_y0, bb.c_str());
425 fl_set_input(bbox_->input_bb_x1, bb.c_str());
426 fl_set_input(bbox_->input_bb_y1, bb.c_str());
428 fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
429 } else { // get the values from the inset
430 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
431 controller().bbChanged = true;
433 anyLength = LyXLength(token(igp.bb,' ',0));
434 updateWidgetsFromLength(bbox_->input_bb_x0,
435 bbox_->choice_bb_units,anyLength,"pt");
436 anyLength = LyXLength(token(igp.bb,' ',1));
437 updateWidgetsFromLength(bbox_->input_bb_y0,
438 bbox_->choice_bb_units,anyLength,"pt");
439 anyLength = LyXLength(token(igp.bb,' ',2));
440 updateWidgetsFromLength(bbox_->input_bb_x1,
441 bbox_->choice_bb_units,anyLength,"pt");
442 anyLength = LyXLength(token(igp.bb,' ',3));
443 updateWidgetsFromLength(bbox_->input_bb_y1,
444 bbox_->choice_bb_units,anyLength,"pt");
446 fl_set_button(bbox_->check_clip, igp.clip);
448 // the special section
449 fl_set_input(special_->input_special, igp.special.c_str());
455 bool isValid(FL_OBJECT * ob)
457 string const input = getStringFromInput(ob);
458 return input.empty() || isValidLength(input) || isStrDbl(input);
465 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
468 if (ob == file_->button_browse) {
469 // Get the filename from the dialog
470 string const in_name = getStringFromInput(file_->input_filename);
471 string const out_name = controller().Browse(in_name);
472 if (out_name != in_name && !out_name.empty()) {
473 fl_set_input(file_->input_filename, out_name.c_str());
475 } else if (ob == file_->check_subcaption) {
476 setEnabled(file_->input_subcaption,
477 fl_get_button(file_->check_subcaption));
478 } else if (ob == file_->check_rotate) {
479 setEnabled(file_->input_rotate_angle,
480 fl_get_button(file_->check_rotate));
481 setEnabled(file_->choice_origin,
482 fl_get_button(file_->check_rotate));
484 // the lyxview section
485 } else if (ob == lyxview_->radio_lyxasis) {
486 setEnabled(lyxview_->input_lyxwidth, 0);
487 setEnabled(lyxview_->choice_width_lyxwidth, 0);
488 setEnabled(lyxview_->input_lyxheight, 0);
489 setEnabled(lyxview_->choice_width_lyxheight, 0);
490 setEnabled(lyxview_->input_lyxscale, 0);
491 } else if (ob == lyxview_->radio_lyxwh) {
492 setEnabled(lyxview_->input_lyxwidth, 1);
493 setEnabled(lyxview_->choice_width_lyxwidth, 1);
494 setEnabled(lyxview_->input_lyxheight, 1);
495 setEnabled(lyxview_->choice_width_lyxheight, 1);
496 setEnabled(lyxview_->input_lyxscale, 0);
497 } else if (ob == lyxview_->radio_lyxscale) {
498 setEnabled(lyxview_->input_lyxwidth, 0);
499 setEnabled(lyxview_->choice_width_lyxwidth, 0);
500 setEnabled(lyxview_->input_lyxheight, 0);
501 setEnabled(lyxview_->choice_width_lyxheight, 0);
502 setEnabled(lyxview_->input_lyxscale, 1);
503 } else if (ob == lyxview_->button_latex_values) {
504 if (contains(fl_get_choice_text(size_->choice_width_units),'%'))
505 Alert::alert(_("Warning!"),
506 _("The units t%, p%, c% and l% are not allowed here."),
507 _("Cannot use the values from LaTeX size!"));
509 LyXLength dummy = LyXLength(getLengthFromWidgets(size_->input_width,
510 size_->choice_width_units));
511 updateWidgetsFromLength(lyxview_->input_lyxwidth,
512 lyxview_->choice_width_lyxwidth, dummy, defaultUnit);
513 dummy = LyXLength(getLengthFromWidgets(size_->input_height,
514 size_->choice_height_units));
515 updateWidgetsFromLength(lyxview_->input_lyxheight,
516 lyxview_->choice_width_lyxheight, dummy, defaultUnit);
517 string const scale = getStringFromInput(size_->input_scale);
518 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
519 if (fl_get_button (size_->radio_asis) == 1) {
520 fl_set_button (lyxview_->radio_lyxasis, 1);
521 setEnabled(lyxview_->input_lyxwidth, 0);
522 setEnabled(lyxview_->choice_width_lyxwidth, 0);
523 setEnabled(lyxview_->input_lyxheight, 0);
524 setEnabled(lyxview_->choice_width_lyxheight, 0);
525 setEnabled(lyxview_->input_lyxscale, 0);
526 } else if (fl_get_button (size_->radio_wh) == 1) {
527 fl_set_button (lyxview_->radio_lyxwh, 1);
528 setEnabled(lyxview_->input_lyxwidth, 1);
529 setEnabled(lyxview_->choice_width_lyxwidth, 1);
530 setEnabled(lyxview_->input_lyxheight, 1);
531 setEnabled(lyxview_->choice_width_lyxheight, 1);
532 setEnabled(lyxview_->input_lyxscale, 0);
533 } else if (fl_get_button (size_->radio_scale) ==1) {
534 fl_set_button (lyxview_->radio_lyxscale, 1);
535 setEnabled(lyxview_->input_lyxwidth, 0);
536 setEnabled(lyxview_->choice_width_lyxwidth, 0);
537 setEnabled(lyxview_->input_lyxheight, 0);
538 setEnabled(lyxview_->choice_width_lyxheight, 0);
539 setEnabled(lyxview_->input_lyxscale, 1);
544 } else if (!controller().bbChanged &&
545 (ob == bbox_->choice_bb_units ||
546 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
547 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
548 controller().bbChanged = true;
549 } else if (ob == bbox_->button_getBB) {
550 string const filename = getStringFromInput(file_->input_filename);
551 if (!filename.empty()) {
552 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
553 string bb = controller().readBB(fileWithAbsPath);
555 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
556 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
557 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
558 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
559 string const unit("pt");
560 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
562 controller().bbChanged = false;
564 fl_set_input(bbox_->input_bb_x0, "");
565 fl_set_input(bbox_->input_bb_y0, "");
566 fl_set_input(bbox_->input_bb_x1, "");
567 fl_set_input(bbox_->input_bb_y1, "");
568 fl_set_choice_text(bbox_->choice_bb_units, "pt");
572 } else if (ob == size_->radio_asis) {
573 setEnabled(size_->input_width, 0);
574 setEnabled(size_->choice_width_units, 0);
575 setEnabled(size_->input_height, 0);
576 setEnabled(size_->choice_height_units, 0);
577 setEnabled(size_->check_aspectratio, 0);
578 setEnabled(size_->input_scale, 0);
579 } else if (ob == size_->radio_wh) {
580 setEnabled(size_->input_width, 1);
581 setEnabled(size_->choice_width_units, 1);
582 setEnabled(size_->input_height, 1);
583 setEnabled(size_->choice_height_units, 1);
584 setEnabled(size_->check_aspectratio, 1);
585 setEnabled(size_->input_scale, 0);
586 } else if (ob == size_->radio_scale) {
587 setEnabled(size_->input_width, 0);
588 setEnabled(size_->choice_width_units, 0);
589 setEnabled(size_->input_height, 0);
590 setEnabled(size_->choice_height_units, 0);
591 setEnabled(size_->check_aspectratio, 0);
592 setEnabled(size_->input_scale, 1);
593 } else if (ob == size_->button_lyx_values) {
594 LyXLength dummy = LyXLength(getLengthFromWidgets(
595 lyxview_->input_lyxwidth, lyxview_->choice_width_lyxwidth));
596 updateWidgetsFromLength(size_->input_width,
597 size_->choice_width_units, dummy, defaultUnit);
598 dummy = LyXLength(getLengthFromWidgets(lyxview_->input_lyxheight,
599 lyxview_->choice_width_lyxheight));
600 updateWidgetsFromLength(size_->input_height,
601 size_->choice_height_units, dummy, defaultUnit);
602 string const scale = getStringFromInput(lyxview_->input_lyxscale);
603 fl_set_input(size_->input_scale, scale.c_str());
604 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
605 fl_set_button (size_->radio_asis, 1);
606 setEnabled(size_->input_width, 0);
607 setEnabled(size_->choice_width_units, 0);
608 setEnabled(size_->input_height, 0);
609 setEnabled(size_->choice_height_units, 0);
610 setEnabled(size_->check_aspectratio, 0);
611 setEnabled(size_->input_scale, 0);
612 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
613 fl_set_button (size_->radio_wh, 1);
614 setEnabled(size_->input_width, 1);
615 setEnabled(size_->choice_width_units, 1);
616 setEnabled(size_->input_height, 1);
617 setEnabled(size_->choice_height_units, 1);
618 setEnabled(size_->check_aspectratio, 1);
619 setEnabled(size_->input_scale, 0);
620 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
621 fl_set_button (size_->radio_scale, 1);
622 setEnabled(size_->input_width, 0);
623 setEnabled(size_->choice_width_units, 0);
624 setEnabled(size_->input_height, 0);
625 setEnabled(size_->choice_height_units, 0);
626 setEnabled(size_->check_aspectratio, 0);
627 setEnabled(size_->input_scale, 1);
631 // check if the input is valid
632 bool invalid = !isValid(bbox_->input_bb_x0);
633 invalid = invalid || !isValid(bbox_->input_bb_x1);
634 invalid = invalid || !isValid(bbox_->input_bb_y0);
635 invalid = invalid || !isValid(bbox_->input_bb_y1);
636 invalid = invalid || !isValid(size_->input_width);
637 invalid = invalid || !isValid(size_->input_height);
638 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
639 invalid = invalid || !isValid(lyxview_->input_lyxheight);
641 // deactivate OK/ Apply buttons and
642 // spit out warnings if invalid
643 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
644 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
645 ob == size_->input_width || ob == size_->input_height ||
646 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
648 postWarning(_("Invalid Length!"));
649 return ButtonPolicy::SMI_INVALID;
655 return ButtonPolicy::SMI_VALID;