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 "forms/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
30 #include FORMS_H_LOCATION
37 // Bound the number of input characters
38 int const SCALE_MAXDIGITS = 3; // %-value
39 int const WIDTH_MAXDIGITS = 10;
40 int const HEIGHT_MAXDIGITS = 10;
41 int const ROTATE_MAXCHARS = 5; // like 270.1
42 int const FILENAME_MAXCHARS = 1024;
43 string defaultUnit("cm");
45 /// Given input and choice widgets, create a LyXLength
46 LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
48 return LyXLength(getLengthFromWidgets(input, choice));
54 typedef FormCB<ControlGraphics, FormDB<FD_graphics> > base_class;
56 FormGraphics::FormGraphics(ControlGraphics & c)
57 : base_class(c, _("Graphics"), false)
61 void FormGraphics::redraw()
63 if (form() && form()->visible)
64 fl_redraw_form(form());
67 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
68 if (outer_form && outer_form->visible)
69 fl_redraw_form(outer_form);
73 void FormGraphics::build()
75 dialog_.reset(build_graphics(this));
77 // Allow the base class to control messages
78 setMessageWidget(dialog_->text_warning);
80 // Manage the ok, apply, restore and cancel/close buttons
81 bc().setOK(dialog_->button_ok);
82 bc().setApply(dialog_->button_apply);
83 bc().setCancel(dialog_->button_close);
84 bc().setRestore(dialog_->button_restore);
87 file_.reset(build_graphics_file(this));
89 fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
90 fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
91 fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
92 fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
93 fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
94 fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
96 setPrehandler(file_->input_filename);
97 setPrehandler(file_->input_subcaption);
98 setPrehandler(file_->input_rotate_angle);
100 using namespace frnt;
101 vector<RotationOriginPair> origindata = getRotationOriginData();
103 // Store the identifiers for later
104 origins_ = getSecond(origindata);
106 string const choice =
107 " " + getStringFromVector(getFirst(origindata), " | ") +" ";
108 fl_addto_choice(file_->choice_origin, choice.c_str());
110 bc().addReadOnly(file_->button_browse);
111 bc().addReadOnly(file_->check_subcaption);
112 bc().addReadOnly(file_->check_rotate);
113 bc().addReadOnly(file_->check_draft);
114 bc().addReadOnly(file_->check_nounzip);
116 // the lyxview section
117 lyxview_.reset(build_graphics_lyxview(this));
119 fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
120 fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
121 fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
123 setPrehandler(lyxview_->input_lyxwidth);
124 setPrehandler(lyxview_->input_lyxheight);
125 setPrehandler(lyxview_->input_lyxscale);
127 fl_addto_choice(lyxview_->choice_lyxwidth, choice_Length_WithUnit.c_str());
128 fl_addto_choice(lyxview_->choice_lyxheight, choice_Length_WithUnit.c_str());
130 bc().addReadOnly(lyxview_->radio_pref);
131 bc().addReadOnly(lyxview_->radio_mono);
132 bc().addReadOnly(lyxview_->radio_gray);
133 bc().addReadOnly(lyxview_->radio_color);
134 bc().addReadOnly(lyxview_->radio_nodisplay);
137 size_.reset(build_graphics_size(this));
139 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
140 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
141 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
143 setPrehandler(size_->input_scale);
144 setPrehandler(size_->input_width);
145 setPrehandler(size_->input_height);
147 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
148 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
149 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
151 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
153 fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
154 fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
156 bc().addReadOnly(size_->radio_asis);
157 bc().addReadOnly(size_->radio_wh);
158 bc().addReadOnly(size_->radio_scale);
159 bc().addReadOnly(size_->check_aspectratio);
161 // the bounding box selection
162 bbox_.reset(build_graphics_bbox(this));
163 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
164 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
165 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
166 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
168 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
169 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
170 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
171 fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
173 setPrehandler(bbox_->input_bb_x0);
174 setPrehandler(bbox_->input_bb_y0);
175 setPrehandler(bbox_->input_bb_x1);
176 setPrehandler(bbox_->input_bb_y1);
178 string const bb_units = "bp|cm|mm|in";
179 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
180 bc().addReadOnly(bbox_->button_getBB);
181 bc().addReadOnly(bbox_->check_clip);
183 // the rotate section
184 special_.reset(build_graphics_special(this));
186 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
187 setPrehandler(special_->input_special);
189 // add the different tabfolders
190 fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
191 fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
192 fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
193 fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
194 fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
195 // set the right default unit
196 if (lyxrc.default_papersize < 3)
201 void FormGraphics::apply()
203 // Create the parameters structure and fill the data from the dialog.
204 InsetGraphicsParams & igp = controller().params();
207 igp.filename = getStringFromInput(file_->input_filename);
208 igp.subcaption = fl_get_button(file_->check_subcaption);
209 igp.subcaptionText = getStringFromInput(file_->input_subcaption);
210 igp.rotate = fl_get_button(file_->check_rotate);
212 strToDbl(getStringFromInput(file_->input_rotate_angle));
213 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
214 if (igp.rotateAngle < 0.0) {
215 igp.rotateAngle += 360.0;
216 } else if (igp.rotateAngle > 360.0) {
217 igp.rotateAngle -= 360.0;
220 int const pos = fl_get_choice(file_->choice_origin);
222 igp.rotateOrigin = origins_[pos-1];
224 igp.rotateOrigin = string();
226 igp.draft = fl_get_button(file_->check_draft);
227 igp.noUnzip = fl_get_button(file_->check_nounzip);
229 // the lyxview section
230 if (fl_get_button(lyxview_->radio_pref))
231 igp.display = InsetGraphicsParams::DEFAULT;
232 else if (fl_get_button(lyxview_->radio_mono))
233 igp.display = InsetGraphicsParams::MONOCHROME;
234 else if (fl_get_button(lyxview_->radio_gray))
235 igp.display = InsetGraphicsParams::GRAYSCALE;
236 else if (fl_get_button(lyxview_->radio_color))
237 igp.display = InsetGraphicsParams::COLOR;
238 else if (fl_get_button(lyxview_->radio_nodisplay))
239 igp.display = InsetGraphicsParams::NONE;
241 if (fl_get_button(lyxview_->radio_lyxasis))
242 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
243 else if (fl_get_button(lyxview_->radio_lyxwh))
244 igp.lyxsize_type = InsetGraphicsParams::WH;
246 igp.lyxsize_type = InsetGraphicsParams::SCALE;
248 igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
249 lyxview_->choice_lyxwidth);
251 igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
252 lyxview_->choice_lyxheight);
254 igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
257 if (fl_get_button(size_->radio_asis))
258 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
259 else if (fl_get_button(size_->radio_wh))
260 igp.size_type = InsetGraphicsParams::WH;
262 igp.size_type = InsetGraphicsParams::SCALE;
264 igp.width = getLyXLengthFromWidgets(size_->input_width,
265 size_->choice_width);
267 igp.height = getLyXLengthFromWidgets(size_->input_height,
268 size_->choice_height);
270 igp.scale = strToInt(getStringFromInput(size_->input_scale));
271 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
274 if (!controller().bbChanged) // different to the original one?
275 igp.bb = string(); // don't write anything
278 if (getStringFromInput(bbox_->input_bb_x0).empty())
281 bb = getLengthFromWidgets(bbox_->input_bb_x0,
282 bbox_->choice_bb_units)+" ";
283 if (getStringFromInput(bbox_->input_bb_y0).empty())
286 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
287 bbox_->choice_bb_units)+" ");
288 if (getStringFromInput(bbox_->input_bb_x1).empty())
291 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
292 bbox_->choice_bb_units)+" ");
293 if (getStringFromInput(bbox_->input_bb_y1).empty())
296 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
297 bbox_->choice_bb_units)+" ");
300 igp.clip = fl_get_button(bbox_->check_clip);
302 // the special section
303 igp.special = getStringFromInput(special_->input_special);
307 void FormGraphics::update() {
308 // Update dialog with details from inset
309 InsetGraphicsParams & igp = controller().params();
312 fl_set_input(file_->input_filename, igp.filename.c_str());
313 fl_set_button(file_->check_subcaption, igp.subcaption);
314 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
315 setEnabled(file_->input_subcaption,
316 fl_get_button(file_->check_subcaption));
317 fl_set_button(file_->check_rotate, igp.rotate);
318 fl_set_input(file_->input_rotate_angle,
319 tostr(igp.rotateAngle).c_str());
320 if (igp.rotateOrigin.empty())
321 fl_set_choice(file_->choice_origin,1);
323 int pos = int(findPos(origins_, igp.rotateOrigin));
324 fl_set_choice(file_->choice_origin, pos+1);
327 setEnabled(file_->input_rotate_angle,
328 fl_get_button(file_->check_rotate));
329 setEnabled(file_->choice_origin,
330 fl_get_button(file_->check_rotate));
331 fl_set_button(file_->check_draft, igp.draft);
332 fl_set_button(file_->check_nounzip, igp.noUnzip);
334 // the lyxview section
335 switch (igp.display) {
336 case InsetGraphicsParams::DEFAULT:
337 fl_set_button(lyxview_->radio_pref, 1);
339 case InsetGraphicsParams::MONOCHROME:
340 fl_set_button(lyxview_->radio_mono, 1);
342 case InsetGraphicsParams::GRAYSCALE:
343 fl_set_button(lyxview_->radio_gray, 1);
345 case InsetGraphicsParams::COLOR:
346 fl_set_button(lyxview_->radio_color, 1);
348 case InsetGraphicsParams::NONE:
349 fl_set_button(lyxview_->radio_nodisplay, 1);
352 updateWidgetsFromLength(lyxview_->input_lyxwidth,
353 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
354 updateWidgetsFromLength(lyxview_->input_lyxheight,
355 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
356 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
357 switch (igp.lyxsize_type) {
358 case InsetGraphicsParams::DEFAULT_SIZE: {
359 fl_set_button(lyxview_->radio_lyxasis,1);
360 setEnabled(lyxview_->input_lyxwidth, 0);
361 setEnabled(lyxview_->choice_lyxwidth, 0);
362 setEnabled(lyxview_->input_lyxheight, 0);
363 setEnabled(lyxview_->choice_lyxheight, 0);
364 setEnabled(lyxview_->input_lyxscale, 0);
367 case InsetGraphicsParams::WH: {
368 fl_set_button(lyxview_->radio_lyxwh, 1);
369 setEnabled(lyxview_->input_lyxwidth, 1);
370 setEnabled(lyxview_->choice_lyxwidth, 1);
371 setEnabled(lyxview_->input_lyxheight, 1);
372 setEnabled(lyxview_->choice_lyxheight, 1);
373 setEnabled(lyxview_->input_lyxscale, 0);
376 case InsetGraphicsParams::SCALE: {
377 fl_set_button(lyxview_->radio_lyxscale, 1);
378 setEnabled(lyxview_->input_lyxwidth, 0);
379 setEnabled(lyxview_->choice_lyxwidth, 0);
380 setEnabled(lyxview_->input_lyxheight, 0);
381 setEnabled(lyxview_->choice_lyxheight, 0);
382 setEnabled(lyxview_->input_lyxscale, 1);
388 // Update the draft and clip mode
389 updateWidgetsFromLength(size_->input_width,
390 size_->choice_width, igp.width, defaultUnit);
391 updateWidgetsFromLength(size_->input_height,
392 size_->choice_height, igp.height, defaultUnit);
393 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
394 switch (igp.size_type) {
395 case InsetGraphicsParams::DEFAULT_SIZE: {
396 fl_set_button(size_->radio_asis,1);
397 setEnabled(size_->input_width, 0);
398 setEnabled(size_->choice_width, 0);
399 setEnabled(size_->input_height, 0);
400 setEnabled(size_->choice_height, 0);
401 setEnabled(size_->check_aspectratio, 0);
402 setEnabled(size_->input_scale, 0);
405 case InsetGraphicsParams::WH: {
406 fl_set_button(size_->radio_wh, 1);
407 setEnabled(size_->input_width, 1);
408 setEnabled(size_->choice_width, 1);
409 setEnabled(size_->input_height, 1);
410 setEnabled(size_->choice_height, 1);
411 setEnabled(size_->check_aspectratio, 1);
412 setEnabled(size_->input_scale, 0);
415 case InsetGraphicsParams::SCALE: {
416 fl_set_button(size_->radio_scale, 1);
417 setEnabled(size_->input_width, 0);
418 setEnabled(size_->choice_width, 0);
419 setEnabled(size_->input_height, 0);
420 setEnabled(size_->choice_height, 0);
421 setEnabled(size_->check_aspectratio, 0);
422 setEnabled(size_->input_scale, 1);
426 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
429 // set the bounding box values, if exists. First we need the whole
430 // path, because the controller knows nothing about the doc-dir
431 updateBB(igp.filename, igp.bb);
432 fl_set_button(bbox_->check_clip, igp.clip);
434 // the special section
435 fl_set_input(special_->input_special, igp.special.c_str());
439 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
441 // Update dialog with details from inset
442 // set the bounding box values, if exists. First we need the whole
443 // path, because the controller knows nothing about the doc-dir
444 controller().bbChanged = false;
445 if (bb_inset.empty()) {
446 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
447 string const bb = controller().readBB(filename);
449 // get the values from the file
450 // in this case we always have the point-unit
451 fl_set_input(bbox_->input_bb_x0,
452 token(bb,' ',0).c_str());
453 fl_set_input(bbox_->input_bb_y0,
454 token(bb,' ',1).c_str());
455 fl_set_input(bbox_->input_bb_x1,
456 token(bb,' ',2).c_str());
457 fl_set_input(bbox_->input_bb_y1,
458 token(bb,' ',3).c_str());
462 fl_set_input(bbox_->input_bb_x0, bb.c_str());
463 fl_set_input(bbox_->input_bb_y0, bb.c_str());
464 fl_set_input(bbox_->input_bb_x1, bb.c_str());
465 fl_set_input(bbox_->input_bb_y1, bb.c_str());
468 fl_set_choice(bbox_->choice_bb_units, 1);
471 // get the values from the inset
472 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
474 controller().bbChanged = true;
476 anyLength = LyXLength(token(bb_inset,' ',0));
477 updateWidgetsFromLength(bbox_->input_bb_x0,
478 bbox_->choice_bb_units,anyLength,"bp");
479 anyLength = LyXLength(token(bb_inset,' ',1));
480 updateWidgetsFromLength(bbox_->input_bb_y0,
481 bbox_->choice_bb_units,anyLength,"bp");
482 anyLength = LyXLength(token(bb_inset,' ',2));
483 updateWidgetsFromLength(bbox_->input_bb_x1,
484 bbox_->choice_bb_units,anyLength,"bp");
485 anyLength = LyXLength(token(bb_inset,' ',3));
486 updateWidgetsFromLength(bbox_->input_bb_y1,
487 bbox_->choice_bb_units,anyLength,"bp");
493 bool isValid(FL_OBJECT * ob)
495 string const input = getStringFromInput(ob);
496 return input.empty() || isValidLength(input) || isStrDbl(input);
503 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
506 if (ob == file_->button_browse) {
507 // Get the filename from the dialog
508 string const in_name = getStringFromInput(file_->input_filename);
509 string const out_name = controller().Browse(in_name);
510 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
511 if (out_name != in_name && !out_name.empty()) {
512 fl_set_input(file_->input_filename, out_name.c_str());
514 if (controller().isFilenameValid(out_name) &&
515 !controller().bbChanged)
516 updateBB(out_name, string());
518 } else if (ob == file_->check_subcaption) {
519 setEnabled(file_->input_subcaption,
520 fl_get_button(file_->check_subcaption));
521 } else if (ob == file_->check_rotate) {
522 setEnabled(file_->input_rotate_angle,
523 fl_get_button(file_->check_rotate));
524 setEnabled(file_->choice_origin,
525 fl_get_button(file_->check_rotate));
527 // the lyxview section
528 } else if (ob == lyxview_->radio_lyxasis) {
529 setEnabled(lyxview_->input_lyxwidth, 0);
530 setEnabled(lyxview_->choice_lyxwidth, 0);
531 setEnabled(lyxview_->input_lyxheight, 0);
532 setEnabled(lyxview_->choice_lyxheight, 0);
533 setEnabled(lyxview_->input_lyxscale, 0);
534 } else if (ob == lyxview_->radio_lyxwh) {
535 setEnabled(lyxview_->input_lyxwidth, 1);
536 setEnabled(lyxview_->choice_lyxwidth, 1);
537 setEnabled(lyxview_->input_lyxheight, 1);
538 setEnabled(lyxview_->choice_lyxheight, 1);
539 setEnabled(lyxview_->input_lyxscale, 0);
540 } else if (ob == lyxview_->radio_lyxscale) {
541 setEnabled(lyxview_->input_lyxwidth, 0);
542 setEnabled(lyxview_->choice_lyxwidth, 0);
543 setEnabled(lyxview_->input_lyxheight, 0);
544 setEnabled(lyxview_->choice_lyxheight, 0);
545 setEnabled(lyxview_->input_lyxscale, 1);
546 } else if (ob == lyxview_->button_latex_values) {
547 if (contains(fl_get_choice_text(size_->choice_width),'%'))
548 Alert::alert(_("Warning!"),
549 _("The units text%, page%, col% and line% are not allowed here."),
550 _("Cannot use the values from LaTeX size!"));
553 getLyXLengthFromWidgets(size_->input_width,
554 size_->choice_width);
555 updateWidgetsFromLength(lyxview_->input_lyxwidth,
556 lyxview_->choice_lyxwidth,
559 dummy = getLyXLengthFromWidgets(size_->input_height,
560 size_->choice_height);
561 updateWidgetsFromLength(lyxview_->input_lyxheight,
562 lyxview_->choice_lyxheight,
564 string const scale = getStringFromInput(size_->input_scale);
565 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
566 if (fl_get_button (size_->radio_asis) == 1) {
567 fl_set_button (lyxview_->radio_lyxasis, 1);
568 setEnabled(lyxview_->input_lyxwidth, 0);
569 setEnabled(lyxview_->choice_lyxwidth, 0);
570 setEnabled(lyxview_->input_lyxheight, 0);
571 setEnabled(lyxview_->choice_lyxheight, 0);
572 setEnabled(lyxview_->input_lyxscale, 0);
573 } else if (fl_get_button (size_->radio_wh) == 1) {
574 fl_set_button (lyxview_->radio_lyxwh, 1);
575 setEnabled(lyxview_->input_lyxwidth, 1);
576 setEnabled(lyxview_->choice_lyxwidth, 1);
577 setEnabled(lyxview_->input_lyxheight, 1);
578 setEnabled(lyxview_->choice_lyxheight, 1);
579 setEnabled(lyxview_->input_lyxscale, 0);
580 } else if (fl_get_button (size_->radio_scale) ==1) {
581 fl_set_button (lyxview_->radio_lyxscale, 1);
582 setEnabled(lyxview_->input_lyxwidth, 0);
583 setEnabled(lyxview_->choice_lyxwidth, 0);
584 setEnabled(lyxview_->input_lyxheight, 0);
585 setEnabled(lyxview_->choice_lyxheight, 0);
586 setEnabled(lyxview_->input_lyxscale, 1);
591 } else if (!controller().bbChanged &&
592 (ob == bbox_->check_clip || ob == bbox_->choice_bb_units ||
593 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
594 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
595 controller().bbChanged = true;
596 } else if (ob == bbox_->button_getBB) {
597 string const filename = getStringFromInput(file_->input_filename);
598 if (!filename.empty()) {
599 string bb = controller().readBB(filename);
601 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
602 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
603 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
604 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
605 string const unit("bp");
606 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
608 controller().bbChanged = false;
610 fl_set_input(bbox_->input_bb_x0, "");
611 fl_set_input(bbox_->input_bb_y0, "");
612 fl_set_input(bbox_->input_bb_x1, "");
613 fl_set_input(bbox_->input_bb_y1, "");
614 fl_set_choice_text(bbox_->choice_bb_units, "bp");
618 } else if (ob == size_->radio_asis) {
619 setEnabled(size_->input_width, 0);
620 setEnabled(size_->choice_width, 0);
621 setEnabled(size_->input_height, 0);
622 setEnabled(size_->choice_height, 0);
623 setEnabled(size_->check_aspectratio, 0);
624 setEnabled(size_->input_scale, 0);
625 } else if (ob == size_->radio_wh) {
626 setEnabled(size_->input_width, 1);
627 setEnabled(size_->choice_width, 1);
628 setEnabled(size_->input_height, 1);
629 setEnabled(size_->choice_height, 1);
630 setEnabled(size_->check_aspectratio, 1);
631 setEnabled(size_->input_scale, 0);
632 } else if (ob == size_->radio_scale) {
633 setEnabled(size_->input_width, 0);
634 setEnabled(size_->choice_width, 0);
635 setEnabled(size_->input_height, 0);
636 setEnabled(size_->choice_height, 0);
637 setEnabled(size_->check_aspectratio, 0);
638 setEnabled(size_->input_scale, 1);
639 } else if (ob == size_->button_lyx_values) {
640 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
641 lyxview_->choice_lyxwidth);
642 updateWidgetsFromLength(size_->input_width,
645 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
646 lyxview_->choice_lyxheight);
647 updateWidgetsFromLength(size_->input_height,
648 size_->choice_height,
650 string const scale = getStringFromInput(lyxview_->input_lyxscale);
651 fl_set_input(size_->input_scale, scale.c_str());
652 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
653 fl_set_button (size_->radio_asis, 1);
654 setEnabled(size_->input_width, 0);
655 setEnabled(size_->choice_width, 0);
656 setEnabled(size_->input_height, 0);
657 setEnabled(size_->choice_height, 0);
658 setEnabled(size_->check_aspectratio, 0);
659 setEnabled(size_->input_scale, 0);
660 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
661 fl_set_button (size_->radio_wh, 1);
662 setEnabled(size_->input_width, 1);
663 setEnabled(size_->choice_width, 1);
664 setEnabled(size_->input_height, 1);
665 setEnabled(size_->choice_height, 1);
666 setEnabled(size_->check_aspectratio, 1);
667 setEnabled(size_->input_scale, 0);
668 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
669 fl_set_button (size_->radio_scale, 1);
670 setEnabled(size_->input_width, 0);
671 setEnabled(size_->choice_width, 0);
672 setEnabled(size_->input_height, 0);
673 setEnabled(size_->choice_height, 0);
674 setEnabled(size_->check_aspectratio, 0);
675 setEnabled(size_->input_scale, 1);
679 // check if the input is valid
680 bool invalid = !isValid(bbox_->input_bb_x0);
681 invalid = invalid || !isValid(bbox_->input_bb_x1);
682 invalid = invalid || !isValid(bbox_->input_bb_y0);
683 invalid = invalid || !isValid(bbox_->input_bb_y1);
684 invalid = invalid || !isValid(size_->input_width);
685 invalid = invalid || !isValid(size_->input_height);
686 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
687 invalid = invalid || !isValid(lyxview_->input_lyxheight);
689 // deactivate OK/ Apply buttons and
690 // spit out warnings if invalid
691 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
692 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
693 ob == size_->input_width || ob == size_->input_height ||
694 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
696 postWarning(_("Invalid Length!"));
697 return ButtonPolicy::SMI_INVALID;
703 return ButtonPolicy::SMI_VALID;