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 "helper_funcs.h"
24 #include "input_validators.h"
25 #include "debug.h" // for lyxerr
26 #include "support/lstrings.h" // for strToDbl & tostr
27 #include "support/filetools.h" // for MakeAbsPath etc
28 #include "insets/insetgraphicsParams.h"
29 #include "lyxrc.h" // for lyxrc.display_graphics
36 // Bound the number of input characters
37 int const SCALE_MAXDIGITS = 3; // %-value
38 int const WIDTH_MAXDIGITS = 10;
39 int const HEIGHT_MAXDIGITS = 10;
40 int const ROTATE_MAXCHARS = 5; // like 270.1
41 int const FILENAME_MAXCHARS = 1024;
42 string defaultUnit("cm");
44 /// Given input and choice widgets, create a LyXLength
45 LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
47 return LyXLength(getLengthFromWidgets(input, choice));
53 typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
55 FormGraphics::FormGraphics(ControlGraphics & c)
56 : base_class(c, _("Graphics"), false)
60 void FormGraphics::redraw()
62 if (form() && form()->visible)
63 fl_redraw_form(form());
66 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
67 if (outer_form && outer_form->visible)
68 fl_redraw_form(outer_form);
72 void FormGraphics::build()
74 dialog_.reset(build_graphics());
76 // Allow the base class to control messages
77 setMessageWidget(dialog_->text_warning);
79 // Manage the ok, apply, restore and cancel/close buttons
80 bc().setOK(dialog_->button_ok);
81 bc().setApply(dialog_->button_apply);
82 bc().setCancel(dialog_->button_close);
83 bc().setRestore(dialog_->button_restore);
86 file_.reset(build_file());
88 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
89 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
90 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
91 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
92 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
93 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
95 setPrehandler(file_->input_filename);
96 setPrehandler(file_->input_subcaption);
97 setPrehandler(file_->input_rotate_angle);
100 vector<RotationOriginPair> origindata = getRotationOriginData();
102 // Store the identifiers for later
103 origins_ = getSecond(origindata);
105 string const choice =
106 " " + getStringFromVector(getFirst(origindata), " | ") +" ";
107 fl_addto_choice(file_->choice_origin, choice.c_str());
109 bc().addReadOnly(file_->button_browse);
110 bc().addReadOnly(file_->check_subcaption);
111 bc().addReadOnly(file_->check_rotate);
112 bc().addReadOnly(file_->check_draft);
113 bc().addReadOnly(file_->check_nounzip);
115 // the lyxview section
116 lyxview_.reset(build_lyxview());
118 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
119 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
120 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
122 setPrehandler(lyxview_->input_lyxwidth);
123 setPrehandler(lyxview_->input_lyxheight);
124 setPrehandler(lyxview_->input_lyxscale);
126 fl_addto_choice(lyxview_->choice_lyxwidth, choice_Length_WithUnit.c_str());
127 fl_addto_choice(lyxview_->choice_lyxheight, choice_Length_WithUnit.c_str());
129 bc().addReadOnly(lyxview_->radio_pref);
130 bc().addReadOnly(lyxview_->radio_mono);
131 bc().addReadOnly(lyxview_->radio_gray);
132 bc().addReadOnly(lyxview_->radio_color);
133 bc().addReadOnly(lyxview_->radio_nodisplay);
136 size_.reset(build_size());
138 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
139 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
140 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
142 setPrehandler(size_->input_scale);
143 setPrehandler(size_->input_width);
144 setPrehandler(size_->input_height);
146 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
147 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
148 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
150 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
152 fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
153 fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
155 bc().addReadOnly(size_->radio_asis);
156 bc().addReadOnly(size_->radio_wh);
157 bc().addReadOnly(size_->radio_scale);
158 bc().addReadOnly(size_->check_aspectratio);
160 // the bounding box selection
161 bbox_.reset(build_bbox());
162 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
163 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
164 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
165 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
167 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
168 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
169 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
170 fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
172 setPrehandler(bbox_->input_bb_x0);
173 setPrehandler(bbox_->input_bb_y0);
174 setPrehandler(bbox_->input_bb_x1);
175 setPrehandler(bbox_->input_bb_y1);
177 string const bb_units = "bp|cm|mm|in";
178 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
179 bc().addReadOnly(bbox_->button_getBB);
180 bc().addReadOnly(bbox_->check_clip);
182 // the rotate section
183 special_.reset(build_special());
185 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
186 setPrehandler(special_->input_special);
188 // add the different tabfolders
189 fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
190 fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
191 fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
192 fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
193 fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
194 // set the right default unit
195 if (lyxrc.default_papersize < 3)
200 void FormGraphics::apply()
202 // Create the parameters structure and fill the data from the dialog.
203 InsetGraphicsParams & igp = controller().params();
206 igp.filename = getStringFromInput(file_->input_filename);
207 igp.subcaption = fl_get_button(file_->check_subcaption);
208 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
209 igp.rotate = fl_get_button(file_->check_rotate);
211 strToDbl(getStringFromInput(file_->input_rotate_angle));
212 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
213 if (igp.rotateAngle < 0.0) {
214 igp.rotateAngle += 360.0;
215 } else if (igp.rotateAngle > 360.0) {
216 igp.rotateAngle -= 360.0;
219 int const pos = fl_get_choice(file_->choice_origin);
221 igp.rotateOrigin = origins_[pos-1];
223 igp.rotateOrigin = string();
225 igp.draft = fl_get_button(file_->check_draft);
226 igp.noUnzip = fl_get_button(file_->check_nounzip);
228 // the lyxview section
229 if (fl_get_button(lyxview_->radio_pref))
230 igp.display = InsetGraphicsParams::DEFAULT;
231 else if (fl_get_button(lyxview_->radio_mono))
232 igp.display = InsetGraphicsParams::MONOCHROME;
233 else if (fl_get_button(lyxview_->radio_gray))
234 igp.display = InsetGraphicsParams::GRAYSCALE;
235 else if (fl_get_button(lyxview_->radio_color))
236 igp.display = InsetGraphicsParams::COLOR;
237 else if (fl_get_button(lyxview_->radio_nodisplay))
238 igp.display = InsetGraphicsParams::NONE;
240 if (fl_get_button(lyxview_->radio_lyxasis))
241 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
242 else if (fl_get_button(lyxview_->radio_lyxwh))
243 igp.lyxsize_type = InsetGraphicsParams::WH;
245 igp.lyxsize_type = InsetGraphicsParams::SCALE;
247 igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
248 lyxview_->choice_lyxwidth);
250 igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
251 lyxview_->choice_lyxheight);
253 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
256 if (fl_get_button(size_->radio_asis))
257 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
258 else if (fl_get_button(size_->radio_wh))
259 igp.size_type = InsetGraphicsParams::WH;
261 igp.size_type = InsetGraphicsParams::SCALE;
263 igp.width = getLyXLengthFromWidgets(size_->input_width,
264 size_->choice_width);
266 igp.height = getLyXLengthFromWidgets(size_->input_height,
267 size_->choice_height);
269 igp.scale = strToInt(getStringFromInput(size_->input_scale));
270 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
273 if (!controller().bbChanged) // different to the original one?
274 igp.bb = string(); // don't write anything
277 if (getStringFromInput(bbox_->input_bb_x0).empty())
280 bb = getLengthFromWidgets(bbox_->input_bb_x0,
281 bbox_->choice_bb_units)+" ";
282 if (getStringFromInput(bbox_->input_bb_y0).empty())
285 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
286 bbox_->choice_bb_units)+" ");
287 if (getStringFromInput(bbox_->input_bb_x1).empty())
290 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
291 bbox_->choice_bb_units)+" ");
292 if (getStringFromInput(bbox_->input_bb_y1).empty())
295 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
296 bbox_->choice_bb_units)+" ");
299 igp.clip = fl_get_button(bbox_->check_clip);
301 // the special section
302 igp.special = getStringFromInput(special_->input_special);
306 void FormGraphics::update() {
307 // Update dialog with details from inset
308 InsetGraphicsParams & igp = controller().params();
311 fl_set_input(file_->input_filename, igp.filename.c_str());
312 fl_set_button(file_->check_subcaption, igp.subcaption);
313 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
314 setEnabled(file_->input_subcaption,
315 fl_get_button(file_->check_subcaption));
316 fl_set_button(file_->check_rotate, igp.rotate);
317 fl_set_input(file_->input_rotate_angle,
318 tostr(igp.rotateAngle).c_str());
319 if (igp.rotateOrigin.empty())
320 fl_set_choice(file_->choice_origin,1);
322 int pos = int(findPos(origins_, igp.rotateOrigin));
323 fl_set_choice(file_->choice_origin, pos+1);
326 setEnabled(file_->input_rotate_angle,
327 fl_get_button(file_->check_rotate));
328 setEnabled(file_->choice_origin,
329 fl_get_button(file_->check_rotate));
330 fl_set_button(file_->check_draft, igp.draft);
331 fl_set_button(file_->check_nounzip, igp.noUnzip);
333 // the lyxview section
334 switch (igp.display) {
335 case InsetGraphicsParams::DEFAULT:
336 fl_set_button(lyxview_->radio_pref, 1);
338 case InsetGraphicsParams::MONOCHROME:
339 fl_set_button(lyxview_->radio_mono, 1);
341 case InsetGraphicsParams::GRAYSCALE:
342 fl_set_button(lyxview_->radio_gray, 1);
344 case InsetGraphicsParams::COLOR:
345 fl_set_button(lyxview_->radio_color, 1);
347 case InsetGraphicsParams::NONE:
348 fl_set_button(lyxview_->radio_nodisplay, 1);
351 updateWidgetsFromLength(lyxview_->input_lyxwidth,
352 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
353 updateWidgetsFromLength(lyxview_->input_lyxheight,
354 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
355 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
356 switch (igp.lyxsize_type) {
357 case InsetGraphicsParams::DEFAULT_SIZE: {
358 fl_set_button(lyxview_->radio_lyxasis,1);
359 setEnabled(lyxview_->input_lyxwidth, 0);
360 setEnabled(lyxview_->choice_lyxwidth, 0);
361 setEnabled(lyxview_->input_lyxheight, 0);
362 setEnabled(lyxview_->choice_lyxheight, 0);
363 setEnabled(lyxview_->input_lyxscale, 0);
366 case InsetGraphicsParams::WH: {
367 fl_set_button(lyxview_->radio_lyxwh, 1);
368 setEnabled(lyxview_->input_lyxwidth, 1);
369 setEnabled(lyxview_->choice_lyxwidth, 1);
370 setEnabled(lyxview_->input_lyxheight, 1);
371 setEnabled(lyxview_->choice_lyxheight, 1);
372 setEnabled(lyxview_->input_lyxscale, 0);
375 case InsetGraphicsParams::SCALE: {
376 fl_set_button(lyxview_->radio_lyxscale, 1);
377 setEnabled(lyxview_->input_lyxwidth, 0);
378 setEnabled(lyxview_->choice_lyxwidth, 0);
379 setEnabled(lyxview_->input_lyxheight, 0);
380 setEnabled(lyxview_->choice_lyxheight, 0);
381 setEnabled(lyxview_->input_lyxscale, 1);
387 // Update the draft and clip mode
388 updateWidgetsFromLength(size_->input_width,
389 size_->choice_width, igp.width, defaultUnit);
390 updateWidgetsFromLength(size_->input_height,
391 size_->choice_height, igp.height, defaultUnit);
392 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
393 switch (igp.size_type) {
394 case InsetGraphicsParams::DEFAULT_SIZE: {
395 fl_set_button(size_->radio_asis,1);
396 setEnabled(size_->input_width, 0);
397 setEnabled(size_->choice_width, 0);
398 setEnabled(size_->input_height, 0);
399 setEnabled(size_->choice_height, 0);
400 setEnabled(size_->check_aspectratio, 0);
401 setEnabled(size_->input_scale, 0);
404 case InsetGraphicsParams::WH: {
405 fl_set_button(size_->radio_wh, 1);
406 setEnabled(size_->input_width, 1);
407 setEnabled(size_->choice_width, 1);
408 setEnabled(size_->input_height, 1);
409 setEnabled(size_->choice_height, 1);
410 setEnabled(size_->check_aspectratio, 1);
411 setEnabled(size_->input_scale, 0);
414 case InsetGraphicsParams::SCALE: {
415 fl_set_button(size_->radio_scale, 1);
416 setEnabled(size_->input_width, 0);
417 setEnabled(size_->choice_width, 0);
418 setEnabled(size_->input_height, 0);
419 setEnabled(size_->choice_height, 0);
420 setEnabled(size_->check_aspectratio, 0);
421 setEnabled(size_->input_scale, 1);
425 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
428 // set the bounding box values, if exists. First we need the whole
429 // path, because the controller knows nothing about the doc-dir
430 updateBB(igp.filename, igp.bb);
431 fl_set_button(bbox_->check_clip, igp.clip);
433 // the special section
434 fl_set_input(special_->input_special, igp.special.c_str());
438 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
440 // Update dialog with details from inset
441 // set the bounding box values, if exists. First we need the whole
442 // path, because the controller knows nothing about the doc-dir
443 controller().bbChanged = false;
444 if (bb_inset.empty()) {
445 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
446 string const bb = controller().readBB(filename);
448 // get the values from the file
449 // in this case we always have the point-unit
450 fl_set_input(bbox_->input_bb_x0,
451 token(bb,' ',0).c_str());
452 fl_set_input(bbox_->input_bb_y0,
453 token(bb,' ',1).c_str());
454 fl_set_input(bbox_->input_bb_x1,
455 token(bb,' ',2).c_str());
456 fl_set_input(bbox_->input_bb_y1,
457 token(bb,' ',3).c_str());
461 fl_set_input(bbox_->input_bb_x0, bb.c_str());
462 fl_set_input(bbox_->input_bb_y0, bb.c_str());
463 fl_set_input(bbox_->input_bb_x1, bb.c_str());
464 fl_set_input(bbox_->input_bb_y1, bb.c_str());
467 fl_set_choice(bbox_->choice_bb_units, 1);
470 // get the values from the inset
471 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
473 controller().bbChanged = true;
475 anyLength = LyXLength(token(bb_inset,' ',0));
476 updateWidgetsFromLength(bbox_->input_bb_x0,
477 bbox_->choice_bb_units,anyLength,"bp");
478 anyLength = LyXLength(token(bb_inset,' ',1));
479 updateWidgetsFromLength(bbox_->input_bb_y0,
480 bbox_->choice_bb_units,anyLength,"bp");
481 anyLength = LyXLength(token(bb_inset,' ',2));
482 updateWidgetsFromLength(bbox_->input_bb_x1,
483 bbox_->choice_bb_units,anyLength,"bp");
484 anyLength = LyXLength(token(bb_inset,' ',3));
485 updateWidgetsFromLength(bbox_->input_bb_y1,
486 bbox_->choice_bb_units,anyLength,"bp");
492 bool isValid(FL_OBJECT * ob)
494 string const input = getStringFromInput(ob);
495 return input.empty() || isValidLength(input) || isStrDbl(input);
502 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
505 if (ob == file_->button_browse) {
506 // Get the filename from the dialog
507 string const in_name = getStringFromInput(file_->input_filename);
508 string const out_name = controller().Browse(in_name);
509 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
510 if (out_name != in_name && !out_name.empty()) {
511 fl_set_input(file_->input_filename, out_name.c_str());
513 if (controller().isFilenameValid(out_name) &&
514 !controller().bbChanged)
515 updateBB(out_name, string());
517 } else if (ob == file_->check_subcaption) {
518 setEnabled(file_->input_subcaption,
519 fl_get_button(file_->check_subcaption));
520 } else if (ob == file_->check_rotate) {
521 setEnabled(file_->input_rotate_angle,
522 fl_get_button(file_->check_rotate));
523 setEnabled(file_->choice_origin,
524 fl_get_button(file_->check_rotate));
526 // the lyxview section
527 } else if (ob == lyxview_->radio_lyxasis) {
528 setEnabled(lyxview_->input_lyxwidth, 0);
529 setEnabled(lyxview_->choice_lyxwidth, 0);
530 setEnabled(lyxview_->input_lyxheight, 0);
531 setEnabled(lyxview_->choice_lyxheight, 0);
532 setEnabled(lyxview_->input_lyxscale, 0);
533 } else if (ob == lyxview_->radio_lyxwh) {
534 setEnabled(lyxview_->input_lyxwidth, 1);
535 setEnabled(lyxview_->choice_lyxwidth, 1);
536 setEnabled(lyxview_->input_lyxheight, 1);
537 setEnabled(lyxview_->choice_lyxheight, 1);
538 setEnabled(lyxview_->input_lyxscale, 0);
539 } else if (ob == lyxview_->radio_lyxscale) {
540 setEnabled(lyxview_->input_lyxwidth, 0);
541 setEnabled(lyxview_->choice_lyxwidth, 0);
542 setEnabled(lyxview_->input_lyxheight, 0);
543 setEnabled(lyxview_->choice_lyxheight, 0);
544 setEnabled(lyxview_->input_lyxscale, 1);
545 } else if (ob == lyxview_->button_latex_values) {
546 if (contains(fl_get_choice_text(size_->choice_width),'%'))
547 Alert::alert(_("Warning!"),
548 _("The units text%, page%, col% and line% are not allowed here."),
549 _("Cannot use the values from LaTeX size!"));
552 getLyXLengthFromWidgets(size_->input_width,
553 size_->choice_width);
554 updateWidgetsFromLength(lyxview_->input_lyxwidth,
555 lyxview_->choice_lyxwidth,
558 dummy = getLyXLengthFromWidgets(size_->input_height,
559 size_->choice_height);
560 updateWidgetsFromLength(lyxview_->input_lyxheight,
561 lyxview_->choice_lyxheight,
563 string const scale = getStringFromInput(size_->input_scale);
564 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
565 if (fl_get_button (size_->radio_asis) == 1) {
566 fl_set_button (lyxview_->radio_lyxasis, 1);
567 setEnabled(lyxview_->input_lyxwidth, 0);
568 setEnabled(lyxview_->choice_lyxwidth, 0);
569 setEnabled(lyxview_->input_lyxheight, 0);
570 setEnabled(lyxview_->choice_lyxheight, 0);
571 setEnabled(lyxview_->input_lyxscale, 0);
572 } else if (fl_get_button (size_->radio_wh) == 1) {
573 fl_set_button (lyxview_->radio_lyxwh, 1);
574 setEnabled(lyxview_->input_lyxwidth, 1);
575 setEnabled(lyxview_->choice_lyxwidth, 1);
576 setEnabled(lyxview_->input_lyxheight, 1);
577 setEnabled(lyxview_->choice_lyxheight, 1);
578 setEnabled(lyxview_->input_lyxscale, 0);
579 } else if (fl_get_button (size_->radio_scale) ==1) {
580 fl_set_button (lyxview_->radio_lyxscale, 1);
581 setEnabled(lyxview_->input_lyxwidth, 0);
582 setEnabled(lyxview_->choice_lyxwidth, 0);
583 setEnabled(lyxview_->input_lyxheight, 0);
584 setEnabled(lyxview_->choice_lyxheight, 0);
585 setEnabled(lyxview_->input_lyxscale, 1);
590 } else if (!controller().bbChanged &&
591 (ob == bbox_->check_clip || ob == bbox_->choice_bb_units ||
592 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
593 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
594 controller().bbChanged = true;
595 } else if (ob == bbox_->button_getBB) {
596 string const filename = getStringFromInput(file_->input_filename);
597 if (!filename.empty()) {
598 string bb = controller().readBB(filename);
600 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
601 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
602 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
603 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
604 string const unit("bp");
605 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
607 controller().bbChanged = false;
609 fl_set_input(bbox_->input_bb_x0, "");
610 fl_set_input(bbox_->input_bb_y0, "");
611 fl_set_input(bbox_->input_bb_x1, "");
612 fl_set_input(bbox_->input_bb_y1, "");
613 fl_set_choice_text(bbox_->choice_bb_units, "bp");
617 } else if (ob == size_->radio_asis) {
618 setEnabled(size_->input_width, 0);
619 setEnabled(size_->choice_width, 0);
620 setEnabled(size_->input_height, 0);
621 setEnabled(size_->choice_height, 0);
622 setEnabled(size_->check_aspectratio, 0);
623 setEnabled(size_->input_scale, 0);
624 } else if (ob == size_->radio_wh) {
625 setEnabled(size_->input_width, 1);
626 setEnabled(size_->choice_width, 1);
627 setEnabled(size_->input_height, 1);
628 setEnabled(size_->choice_height, 1);
629 setEnabled(size_->check_aspectratio, 1);
630 setEnabled(size_->input_scale, 0);
631 } else if (ob == size_->radio_scale) {
632 setEnabled(size_->input_width, 0);
633 setEnabled(size_->choice_width, 0);
634 setEnabled(size_->input_height, 0);
635 setEnabled(size_->choice_height, 0);
636 setEnabled(size_->check_aspectratio, 0);
637 setEnabled(size_->input_scale, 1);
638 } else if (ob == size_->button_lyx_values) {
639 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
640 lyxview_->choice_lyxwidth);
641 updateWidgetsFromLength(size_->input_width,
644 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
645 lyxview_->choice_lyxheight);
646 updateWidgetsFromLength(size_->input_height,
647 size_->choice_height,
649 string const scale = getStringFromInput(lyxview_->input_lyxscale);
650 fl_set_input(size_->input_scale, scale.c_str());
651 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
652 fl_set_button (size_->radio_asis, 1);
653 setEnabled(size_->input_width, 0);
654 setEnabled(size_->choice_width, 0);
655 setEnabled(size_->input_height, 0);
656 setEnabled(size_->choice_height, 0);
657 setEnabled(size_->check_aspectratio, 0);
658 setEnabled(size_->input_scale, 0);
659 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
660 fl_set_button (size_->radio_wh, 1);
661 setEnabled(size_->input_width, 1);
662 setEnabled(size_->choice_width, 1);
663 setEnabled(size_->input_height, 1);
664 setEnabled(size_->choice_height, 1);
665 setEnabled(size_->check_aspectratio, 1);
666 setEnabled(size_->input_scale, 0);
667 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
668 fl_set_button (size_->radio_scale, 1);
669 setEnabled(size_->input_width, 0);
670 setEnabled(size_->choice_width, 0);
671 setEnabled(size_->input_height, 0);
672 setEnabled(size_->choice_height, 0);
673 setEnabled(size_->check_aspectratio, 0);
674 setEnabled(size_->input_scale, 1);
678 // check if the input is valid
679 bool invalid = !isValid(bbox_->input_bb_x0);
680 invalid = invalid || !isValid(bbox_->input_bb_x1);
681 invalid = invalid || !isValid(bbox_->input_bb_y0);
682 invalid = invalid || !isValid(bbox_->input_bb_y1);
683 invalid = invalid || !isValid(size_->input_width);
684 invalid = invalid || !isValid(size_->input_height);
685 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
686 invalid = invalid || !isValid(lyxview_->input_lyxheight);
688 // deactivate OK/ Apply buttons and
689 // spit out warnings if invalid
690 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
691 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
692 ob == size_->input_width || ob == size_->input_height ||
693 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
695 postWarning(_("Invalid Length!"));
696 return ButtonPolicy::SMI_INVALID;
702 return ButtonPolicy::SMI_VALID;