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");
42 /// Given input and choice widgets, create a LyXLength
43 LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
45 return LyXLength(getLengthFromWidgets(input, choice));
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 // Allow the base class to control messages
75 setMessageWidget(dialog_->text_warning);
77 // Manage the ok, apply, restore and cancel/close buttons
78 bc().setOK(dialog_->button_ok);
79 bc().setApply(dialog_->button_apply);
80 bc().setCancel(dialog_->button_close);
81 bc().setRestore(dialog_->button_restore);
84 file_.reset(build_file());
86 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
87 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
88 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
89 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
90 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
91 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
93 setPrehandler(file_->input_filename);
94 setPrehandler(file_->input_subcaption);
95 setPrehandler(file_->input_rotate_angle);
97 string const choice_origin =
99 "leftTop|leftBottom|leftBaseline|" // lt lb lB
100 "centerTop|centerBottom|centerBaseline|" // ct cb cB
101 "rightTop|rightBottom|rightBaseline"; // rt rb rB
102 fl_addto_choice(file_->choice_origin, choice_origin.c_str());
104 bc().addReadOnly(file_->button_browse);
105 bc().addReadOnly(file_->check_subcaption);
106 bc().addReadOnly(file_->check_rotate);
107 bc().addReadOnly(file_->check_draft);
108 bc().addReadOnly(file_->check_nounzip);
110 // the lyxview section
111 lyxview_.reset(build_lyxview());
113 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
114 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
115 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
117 setPrehandler(lyxview_->input_lyxwidth);
118 setPrehandler(lyxview_->input_lyxheight);
119 setPrehandler(lyxview_->input_lyxscale);
121 fl_addto_choice(lyxview_->choice_width_lyxwidth, choice_Length_WithUnit.c_str());
122 fl_addto_choice(lyxview_->choice_width_lyxheight, choice_Length_WithUnit.c_str());
124 bc().addReadOnly(lyxview_->radio_pref);
125 bc().addReadOnly(lyxview_->radio_mono);
126 bc().addReadOnly(lyxview_->radio_gray);
127 bc().addReadOnly(lyxview_->radio_color);
128 bc().addReadOnly(lyxview_->radio_nodisplay);
131 size_.reset(build_size());
133 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
134 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
135 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
137 setPrehandler(size_->input_scale);
138 setPrehandler(size_->input_width);
139 setPrehandler(size_->input_height);
141 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
142 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
143 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
145 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
147 fl_addto_choice(size_->choice_width_units, choice_Length_All.c_str());
148 fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
150 bc().addReadOnly(size_->radio_asis);
151 bc().addReadOnly(size_->radio_wh);
152 bc().addReadOnly(size_->radio_scale);
153 bc().addReadOnly(size_->check_aspectratio);
155 // the bounding box selection
156 bbox_.reset(build_bbox());
157 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
158 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
159 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
160 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
162 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
163 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
164 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
165 fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
167 setPrehandler(bbox_->input_bb_x0);
168 setPrehandler(bbox_->input_bb_y0);
169 setPrehandler(bbox_->input_bb_x1);
170 setPrehandler(bbox_->input_bb_y1);
172 string const bb_units = "pt|cm|in";
173 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
174 bc().addReadOnly(bbox_->button_getBB);
175 bc().addReadOnly(bbox_->check_clip);
177 // the rotate section
178 special_.reset(build_special());
180 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
181 setPrehandler(special_->input_special);
183 // add the different tabfolders
184 fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
185 fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
186 fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
187 fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
188 fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
189 // set the right default unit
190 if (lyxrc.default_papersize < 3)
195 void FormGraphics::apply()
197 // Create the parameters structure and fill the data from the dialog.
198 InsetGraphicsParams & igp = controller().params();
201 igp.filename = getStringFromInput(file_->input_filename);
202 igp.subcaption = fl_get_button(file_->check_subcaption);
203 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
204 igp.rotate = fl_get_button(file_->check_rotate);
206 strToDbl(getStringFromInput(file_->input_rotate_angle));
207 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
208 if (igp.rotateAngle < 0.0) {
209 igp.rotateAngle += 360.0;
210 } else if (igp.rotateAngle > 360.0) {
211 igp.rotateAngle -= 360.0;
214 if (fl_get_choice(file_->choice_origin) > 0)
215 igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
217 igp.rotateOrigin = string();
218 igp.draft = fl_get_button(file_->check_draft);
219 igp.noUnzip = fl_get_button(file_->check_nounzip);
221 // the lyxview section
222 if (fl_get_button(lyxview_->radio_pref))
223 igp.display = InsetGraphicsParams::DEFAULT;
224 else if (fl_get_button(lyxview_->radio_mono))
225 igp.display = InsetGraphicsParams::MONOCHROME;
226 else if (fl_get_button(lyxview_->radio_gray))
227 igp.display = InsetGraphicsParams::GRAYSCALE;
228 else if (fl_get_button(lyxview_->radio_color))
229 igp.display = InsetGraphicsParams::COLOR;
230 else if (fl_get_button(lyxview_->radio_nodisplay))
231 igp.display = InsetGraphicsParams::NONE;
233 if (fl_get_button(lyxview_->radio_lyxasis))
234 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
235 else if (fl_get_button(lyxview_->radio_lyxwh))
236 igp.lyxsize_type = InsetGraphicsParams::WH;
238 igp.lyxsize_type = InsetGraphicsParams::SCALE;
240 igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
241 lyxview_->choice_width_lyxwidth);
243 igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
244 lyxview_->choice_width_lyxheight);
246 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
249 if (fl_get_button(size_->radio_asis))
250 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
251 else if (fl_get_button(size_->radio_wh))
252 igp.size_type = InsetGraphicsParams::WH;
254 igp.size_type = InsetGraphicsParams::SCALE;
256 igp.width = getLyXLengthFromWidgets(size_->input_width,
257 size_->choice_width_units);
259 igp.height = getLyXLengthFromWidgets(size_->input_height,
260 size_->choice_height_units);
262 igp.scale = strToInt(getStringFromInput(size_->input_scale));
263 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
266 if (!controller().bbChanged) // different to the original one?
267 igp.bb = string(); // don't write anything
270 if (getStringFromInput(bbox_->input_bb_x0).empty())
273 bb = getLengthFromWidgets(bbox_->input_bb_x0,
274 bbox_->choice_bb_units)+" ";
275 if (getStringFromInput(bbox_->input_bb_y0).empty())
278 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
279 bbox_->choice_bb_units)+" ");
280 if (getStringFromInput(bbox_->input_bb_x1).empty())
283 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
284 bbox_->choice_bb_units)+" ");
285 if (getStringFromInput(bbox_->input_bb_y1).empty())
288 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
289 bbox_->choice_bb_units)+" ");
292 igp.clip = fl_get_button(bbox_->check_clip);
294 // the special section
295 igp.special = getStringFromInput(special_->input_special);
299 void FormGraphics::update() {
300 // Update dialog with details from inset
301 InsetGraphicsParams & igp = controller().params();
304 fl_set_input(file_->input_filename, igp.filename.c_str());
305 fl_set_button(file_->check_subcaption, igp.subcaption);
306 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
307 setEnabled(file_->input_subcaption,
308 fl_get_button(file_->check_subcaption));
309 fl_set_button(file_->check_rotate, igp.rotate);
310 fl_set_input(file_->input_rotate_angle,
311 tostr(igp.rotateAngle).c_str());
312 if (igp.rotateOrigin.empty())
313 fl_set_choice(file_->choice_origin,1);
315 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
316 setEnabled(file_->input_rotate_angle,
317 fl_get_button(file_->check_rotate));
318 setEnabled(file_->choice_origin,
319 fl_get_button(file_->check_rotate));
320 fl_set_button(file_->check_draft, igp.draft);
321 fl_set_button(file_->check_nounzip, igp.noUnzip);
323 // the lyxview section
324 switch (igp.display) {
325 case InsetGraphicsParams::DEFAULT:
326 fl_set_button(lyxview_->radio_pref, 1);
328 case InsetGraphicsParams::MONOCHROME:
329 fl_set_button(lyxview_->radio_mono, 1);
331 case InsetGraphicsParams::GRAYSCALE:
332 fl_set_button(lyxview_->radio_gray, 1);
334 case InsetGraphicsParams::COLOR:
335 fl_set_button(lyxview_->radio_color, 1);
337 case InsetGraphicsParams::NONE:
338 fl_set_button(lyxview_->radio_nodisplay, 1);
341 updateWidgetsFromLength(lyxview_->input_lyxwidth,
342 lyxview_->choice_width_lyxwidth, igp.lyxwidth, defaultUnit);
343 updateWidgetsFromLength(lyxview_->input_lyxheight,
344 lyxview_->choice_width_lyxheight, igp.lyxheight, defaultUnit);
345 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
346 switch (igp.lyxsize_type) {
347 case InsetGraphicsParams::DEFAULT_SIZE: {
348 fl_set_button(lyxview_->radio_lyxasis,1);
349 setEnabled(lyxview_->input_lyxwidth, 0);
350 setEnabled(lyxview_->choice_width_lyxwidth, 0);
351 setEnabled(lyxview_->input_lyxheight, 0);
352 setEnabled(lyxview_->choice_width_lyxheight, 0);
353 setEnabled(lyxview_->input_lyxscale, 0);
356 case InsetGraphicsParams::WH: {
357 fl_set_button(lyxview_->radio_lyxwh, 1);
358 setEnabled(lyxview_->input_lyxwidth, 1);
359 setEnabled(lyxview_->choice_width_lyxwidth, 1);
360 setEnabled(lyxview_->input_lyxheight, 1);
361 setEnabled(lyxview_->choice_width_lyxheight, 1);
362 setEnabled(lyxview_->input_lyxscale, 0);
365 case InsetGraphicsParams::SCALE: {
366 fl_set_button(lyxview_->radio_lyxscale, 1);
367 setEnabled(lyxview_->input_lyxwidth, 0);
368 setEnabled(lyxview_->choice_width_lyxwidth, 0);
369 setEnabled(lyxview_->input_lyxheight, 0);
370 setEnabled(lyxview_->choice_width_lyxheight, 0);
371 setEnabled(lyxview_->input_lyxscale, 1);
377 // Update the draft and clip mode
378 updateWidgetsFromLength(size_->input_width,
379 size_->choice_width_units, igp.width, defaultUnit);
380 updateWidgetsFromLength(size_->input_height,
381 size_->choice_height_units, igp.height, defaultUnit);
382 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
383 switch (igp.size_type) {
384 case InsetGraphicsParams::DEFAULT_SIZE: {
385 fl_set_button(size_->radio_asis,1);
386 setEnabled(size_->input_width, 0);
387 setEnabled(size_->choice_width_units, 0);
388 setEnabled(size_->input_height, 0);
389 setEnabled(size_->choice_height_units, 0);
390 setEnabled(size_->check_aspectratio, 0);
391 setEnabled(size_->input_scale, 0);
394 case InsetGraphicsParams::WH: {
395 fl_set_button(size_->radio_wh, 1);
396 setEnabled(size_->input_width, 1);
397 setEnabled(size_->choice_width_units, 1);
398 setEnabled(size_->input_height, 1);
399 setEnabled(size_->choice_height_units, 1);
400 setEnabled(size_->check_aspectratio, 1);
401 setEnabled(size_->input_scale, 0);
404 case InsetGraphicsParams::SCALE: {
405 fl_set_button(size_->radio_scale, 1);
406 setEnabled(size_->input_width, 0);
407 setEnabled(size_->choice_width_units, 0);
408 setEnabled(size_->input_height, 0);
409 setEnabled(size_->choice_height_units, 0);
410 setEnabled(size_->check_aspectratio, 0);
411 setEnabled(size_->input_scale, 1);
415 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
418 // set the bounding box values, if exists. First we need the whole
419 // path, because the controller knows nothing about the doc-dir
420 controller().bbChanged = false;
421 if (igp.bb.empty()) {
422 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
423 string const fileWithAbsPath =
424 MakeAbsPath(igp.filename, OnlyPath(igp.filename));
425 string const bb = controller().readBB(fileWithAbsPath);
427 // get the values from the file
428 // in this case we always have the point-unit
429 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
430 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
431 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
432 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
433 } else { // no bb from file
434 fl_set_input(bbox_->input_bb_x0, bb.c_str());
435 fl_set_input(bbox_->input_bb_y0, bb.c_str());
436 fl_set_input(bbox_->input_bb_x1, bb.c_str());
437 fl_set_input(bbox_->input_bb_y1, bb.c_str());
439 fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
440 } else { // get the values from the inset
441 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
442 controller().bbChanged = true;
444 anyLength = LyXLength(token(igp.bb,' ',0));
445 updateWidgetsFromLength(bbox_->input_bb_x0,
446 bbox_->choice_bb_units,anyLength,"pt");
447 anyLength = LyXLength(token(igp.bb,' ',1));
448 updateWidgetsFromLength(bbox_->input_bb_y0,
449 bbox_->choice_bb_units,anyLength,"pt");
450 anyLength = LyXLength(token(igp.bb,' ',2));
451 updateWidgetsFromLength(bbox_->input_bb_x1,
452 bbox_->choice_bb_units,anyLength,"pt");
453 anyLength = LyXLength(token(igp.bb,' ',3));
454 updateWidgetsFromLength(bbox_->input_bb_y1,
455 bbox_->choice_bb_units,anyLength,"pt");
457 fl_set_button(bbox_->check_clip, igp.clip);
459 // the special section
460 fl_set_input(special_->input_special, igp.special.c_str());
466 bool isValid(FL_OBJECT * ob)
468 string const input = getStringFromInput(ob);
469 return input.empty() || isValidLength(input) || isStrDbl(input);
476 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
479 if (ob == file_->button_browse) {
480 // Get the filename from the dialog
481 string const in_name = getStringFromInput(file_->input_filename);
482 string const out_name = controller().Browse(in_name);
483 if (out_name != in_name && !out_name.empty()) {
484 fl_set_input(file_->input_filename, out_name.c_str());
486 if (!controller().isFilenameValid(out_name))
487 return ButtonPolicy::SMI_INVALID;
489 } else if (ob == file_->input_filename) {
490 string name = getStringFromInput(file_->input_filename);
491 if (!controller().isFilenameValid(name))
492 return ButtonPolicy::SMI_INVALID;
494 } else if (ob == file_->check_subcaption) {
495 setEnabled(file_->input_subcaption,
496 fl_get_button(file_->check_subcaption));
497 } else if (ob == file_->check_rotate) {
498 setEnabled(file_->input_rotate_angle,
499 fl_get_button(file_->check_rotate));
500 setEnabled(file_->choice_origin,
501 fl_get_button(file_->check_rotate));
503 // the lyxview section
504 } else if (ob == lyxview_->radio_lyxasis) {
505 setEnabled(lyxview_->input_lyxwidth, 0);
506 setEnabled(lyxview_->choice_width_lyxwidth, 0);
507 setEnabled(lyxview_->input_lyxheight, 0);
508 setEnabled(lyxview_->choice_width_lyxheight, 0);
509 setEnabled(lyxview_->input_lyxscale, 0);
510 } else if (ob == lyxview_->radio_lyxwh) {
511 setEnabled(lyxview_->input_lyxwidth, 1);
512 setEnabled(lyxview_->choice_width_lyxwidth, 1);
513 setEnabled(lyxview_->input_lyxheight, 1);
514 setEnabled(lyxview_->choice_width_lyxheight, 1);
515 setEnabled(lyxview_->input_lyxscale, 0);
516 } else if (ob == lyxview_->radio_lyxscale) {
517 setEnabled(lyxview_->input_lyxwidth, 0);
518 setEnabled(lyxview_->choice_width_lyxwidth, 0);
519 setEnabled(lyxview_->input_lyxheight, 0);
520 setEnabled(lyxview_->choice_width_lyxheight, 0);
521 setEnabled(lyxview_->input_lyxscale, 1);
522 } else if (ob == lyxview_->button_latex_values) {
523 if (contains(fl_get_choice_text(size_->choice_width_units),'%'))
524 Alert::alert(_("Warning!"),
525 _("The units t%, p%, c% and l% are not allowed here."),
526 _("Cannot use the values from LaTeX size!"));
529 getLyXLengthFromWidgets(size_->input_width,
530 size_->choice_width_units);
531 updateWidgetsFromLength(lyxview_->input_lyxwidth,
532 lyxview_->choice_width_lyxwidth,
535 dummy = getLyXLengthFromWidgets(size_->input_height,
536 size_->choice_height_units);
537 updateWidgetsFromLength(lyxview_->input_lyxheight,
538 lyxview_->choice_width_lyxheight,
540 string const scale = getStringFromInput(size_->input_scale);
541 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
542 if (fl_get_button (size_->radio_asis) == 1) {
543 fl_set_button (lyxview_->radio_lyxasis, 1);
544 setEnabled(lyxview_->input_lyxwidth, 0);
545 setEnabled(lyxview_->choice_width_lyxwidth, 0);
546 setEnabled(lyxview_->input_lyxheight, 0);
547 setEnabled(lyxview_->choice_width_lyxheight, 0);
548 setEnabled(lyxview_->input_lyxscale, 0);
549 } else if (fl_get_button (size_->radio_wh) == 1) {
550 fl_set_button (lyxview_->radio_lyxwh, 1);
551 setEnabled(lyxview_->input_lyxwidth, 1);
552 setEnabled(lyxview_->choice_width_lyxwidth, 1);
553 setEnabled(lyxview_->input_lyxheight, 1);
554 setEnabled(lyxview_->choice_width_lyxheight, 1);
555 setEnabled(lyxview_->input_lyxscale, 0);
556 } else if (fl_get_button (size_->radio_scale) ==1) {
557 fl_set_button (lyxview_->radio_lyxscale, 1);
558 setEnabled(lyxview_->input_lyxwidth, 0);
559 setEnabled(lyxview_->choice_width_lyxwidth, 0);
560 setEnabled(lyxview_->input_lyxheight, 0);
561 setEnabled(lyxview_->choice_width_lyxheight, 0);
562 setEnabled(lyxview_->input_lyxscale, 1);
567 } else if (!controller().bbChanged &&
568 (ob == bbox_->choice_bb_units ||
569 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
570 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
571 controller().bbChanged = true;
572 } else if (ob == bbox_->button_getBB) {
573 string const filename = getStringFromInput(file_->input_filename);
574 if (!filename.empty()) {
575 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
576 string bb = controller().readBB(fileWithAbsPath);
578 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
579 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
580 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
581 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
582 string const unit("pt");
583 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
585 controller().bbChanged = false;
587 fl_set_input(bbox_->input_bb_x0, "");
588 fl_set_input(bbox_->input_bb_y0, "");
589 fl_set_input(bbox_->input_bb_x1, "");
590 fl_set_input(bbox_->input_bb_y1, "");
591 fl_set_choice_text(bbox_->choice_bb_units, "pt");
595 } else if (ob == size_->radio_asis) {
596 setEnabled(size_->input_width, 0);
597 setEnabled(size_->choice_width_units, 0);
598 setEnabled(size_->input_height, 0);
599 setEnabled(size_->choice_height_units, 0);
600 setEnabled(size_->check_aspectratio, 0);
601 setEnabled(size_->input_scale, 0);
602 } else if (ob == size_->radio_wh) {
603 setEnabled(size_->input_width, 1);
604 setEnabled(size_->choice_width_units, 1);
605 setEnabled(size_->input_height, 1);
606 setEnabled(size_->choice_height_units, 1);
607 setEnabled(size_->check_aspectratio, 1);
608 setEnabled(size_->input_scale, 0);
609 } else if (ob == size_->radio_scale) {
610 setEnabled(size_->input_width, 0);
611 setEnabled(size_->choice_width_units, 0);
612 setEnabled(size_->input_height, 0);
613 setEnabled(size_->choice_height_units, 0);
614 setEnabled(size_->check_aspectratio, 0);
615 setEnabled(size_->input_scale, 1);
616 } else if (ob == size_->button_lyx_values) {
617 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
618 lyxview_->choice_width_lyxwidth);
619 updateWidgetsFromLength(size_->input_width,
620 size_->choice_width_units,
622 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
623 lyxview_->choice_width_lyxheight);
624 updateWidgetsFromLength(size_->input_height,
625 size_->choice_height_units,
627 string const scale = getStringFromInput(lyxview_->input_lyxscale);
628 fl_set_input(size_->input_scale, scale.c_str());
629 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
630 fl_set_button (size_->radio_asis, 1);
631 setEnabled(size_->input_width, 0);
632 setEnabled(size_->choice_width_units, 0);
633 setEnabled(size_->input_height, 0);
634 setEnabled(size_->choice_height_units, 0);
635 setEnabled(size_->check_aspectratio, 0);
636 setEnabled(size_->input_scale, 0);
637 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
638 fl_set_button (size_->radio_wh, 1);
639 setEnabled(size_->input_width, 1);
640 setEnabled(size_->choice_width_units, 1);
641 setEnabled(size_->input_height, 1);
642 setEnabled(size_->choice_height_units, 1);
643 setEnabled(size_->check_aspectratio, 1);
644 setEnabled(size_->input_scale, 0);
645 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
646 fl_set_button (size_->radio_scale, 1);
647 setEnabled(size_->input_width, 0);
648 setEnabled(size_->choice_width_units, 0);
649 setEnabled(size_->input_height, 0);
650 setEnabled(size_->choice_height_units, 0);
651 setEnabled(size_->check_aspectratio, 0);
652 setEnabled(size_->input_scale, 1);
656 // check if the input is valid
657 bool invalid = !isValid(bbox_->input_bb_x0);
658 invalid = invalid || !isValid(bbox_->input_bb_x1);
659 invalid = invalid || !isValid(bbox_->input_bb_y0);
660 invalid = invalid || !isValid(bbox_->input_bb_y1);
661 invalid = invalid || !isValid(size_->input_width);
662 invalid = invalid || !isValid(size_->input_height);
663 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
664 invalid = invalid || !isValid(lyxview_->input_lyxheight);
666 // deactivate OK/ Apply buttons and
667 // spit out warnings if invalid
668 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
669 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
670 ob == size_->input_width || ob == size_->input_height ||
671 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
673 postWarning(_("Invalid Length!"));
674 return ButtonPolicy::SMI_INVALID;
680 return ButtonPolicy::SMI_VALID;