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_lyxwidth, choice_Length_WithUnit.c_str());
122 fl_addto_choice(lyxview_->choice_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, choice_Length_All.c_str());
148 fl_addto_choice(size_->choice_height, 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_lyxwidth);
243 igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
244 lyxview_->choice_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);
259 igp.height = getLyXLengthFromWidgets(size_->input_height,
260 size_->choice_height);
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_lyxwidth, igp.lyxwidth, defaultUnit);
343 updateWidgetsFromLength(lyxview_->input_lyxheight,
344 lyxview_->choice_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_lyxwidth, 0);
351 setEnabled(lyxview_->input_lyxheight, 0);
352 setEnabled(lyxview_->choice_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_lyxwidth, 1);
360 setEnabled(lyxview_->input_lyxheight, 1);
361 setEnabled(lyxview_->choice_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_lyxwidth, 0);
369 setEnabled(lyxview_->input_lyxheight, 0);
370 setEnabled(lyxview_->choice_lyxheight, 0);
371 setEnabled(lyxview_->input_lyxscale, 1);
377 // Update the draft and clip mode
378 updateWidgetsFromLength(size_->input_width,
379 size_->choice_width, igp.width, defaultUnit);
380 updateWidgetsFromLength(size_->input_height,
381 size_->choice_height, 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, 0);
388 setEnabled(size_->input_height, 0);
389 setEnabled(size_->choice_height, 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, 1);
398 setEnabled(size_->input_height, 1);
399 setEnabled(size_->choice_height, 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, 0);
408 setEnabled(size_->input_height, 0);
409 setEnabled(size_->choice_height, 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 updateBB(igp.filename, igp.bb);
421 fl_set_button(bbox_->check_clip, igp.clip);
423 // the special section
424 fl_set_input(special_->input_special, igp.special.c_str());
428 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
430 // Update dialog with details from inset
431 // set the bounding box values, if exists. First we need the whole
432 // path, because the controller knows nothing about the doc-dir
433 controller().bbChanged = false;
434 if (bb_inset.empty()) {
435 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
436 string const fileWithAbsPath =
437 MakeAbsPath(filename, OnlyPath(filename));
438 string const bb = controller().readBB(fileWithAbsPath);
440 // get the values from the file
441 // in this case we always have the point-unit
442 fl_set_input(bbox_->input_bb_x0,
443 token(bb,' ',0).c_str());
444 fl_set_input(bbox_->input_bb_y0,
445 token(bb,' ',1).c_str());
446 fl_set_input(bbox_->input_bb_x1,
447 token(bb,' ',2).c_str());
448 fl_set_input(bbox_->input_bb_y1,
449 token(bb,' ',3).c_str());
453 fl_set_input(bbox_->input_bb_x0, bb.c_str());
454 fl_set_input(bbox_->input_bb_y0, bb.c_str());
455 fl_set_input(bbox_->input_bb_x1, bb.c_str());
456 fl_set_input(bbox_->input_bb_y1, bb.c_str());
459 fl_set_choice(bbox_->choice_bb_units, 1);
462 // get the values from the inset
463 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
465 controller().bbChanged = true;
467 anyLength = LyXLength(token(bb_inset,' ',0));
468 updateWidgetsFromLength(bbox_->input_bb_x0,
469 bbox_->choice_bb_units,anyLength,"pt");
470 anyLength = LyXLength(token(bb_inset,' ',1));
471 updateWidgetsFromLength(bbox_->input_bb_y0,
472 bbox_->choice_bb_units,anyLength,"pt");
473 anyLength = LyXLength(token(bb_inset,' ',2));
474 updateWidgetsFromLength(bbox_->input_bb_x1,
475 bbox_->choice_bb_units,anyLength,"pt");
476 anyLength = LyXLength(token(bb_inset,' ',3));
477 updateWidgetsFromLength(bbox_->input_bb_y1,
478 bbox_->choice_bb_units,anyLength,"pt");
484 bool isValid(FL_OBJECT * ob)
486 string const input = getStringFromInput(ob);
487 return input.empty() || isValidLength(input) || isStrDbl(input);
494 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
497 if (ob == file_->button_browse) {
498 // Get the filename from the dialog
499 string const in_name = getStringFromInput(file_->input_filename);
500 string const out_name = controller().Browse(in_name);
501 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
502 if (out_name != in_name && !out_name.empty()) {
503 fl_set_input(file_->input_filename, out_name.c_str());
505 if (controller().isFilenameValid(out_name))
506 updateBB(out_name, string());
508 } else if (ob == file_->check_subcaption) {
509 setEnabled(file_->input_subcaption,
510 fl_get_button(file_->check_subcaption));
511 } else if (ob == file_->check_rotate) {
512 setEnabled(file_->input_rotate_angle,
513 fl_get_button(file_->check_rotate));
514 setEnabled(file_->choice_origin,
515 fl_get_button(file_->check_rotate));
517 // the lyxview section
518 } else if (ob == lyxview_->radio_lyxasis) {
519 setEnabled(lyxview_->input_lyxwidth, 0);
520 setEnabled(lyxview_->choice_lyxwidth, 0);
521 setEnabled(lyxview_->input_lyxheight, 0);
522 setEnabled(lyxview_->choice_lyxheight, 0);
523 setEnabled(lyxview_->input_lyxscale, 0);
524 } else if (ob == lyxview_->radio_lyxwh) {
525 setEnabled(lyxview_->input_lyxwidth, 1);
526 setEnabled(lyxview_->choice_lyxwidth, 1);
527 setEnabled(lyxview_->input_lyxheight, 1);
528 setEnabled(lyxview_->choice_lyxheight, 1);
529 setEnabled(lyxview_->input_lyxscale, 0);
530 } else if (ob == lyxview_->radio_lyxscale) {
531 setEnabled(lyxview_->input_lyxwidth, 0);
532 setEnabled(lyxview_->choice_lyxwidth, 0);
533 setEnabled(lyxview_->input_lyxheight, 0);
534 setEnabled(lyxview_->choice_lyxheight, 0);
535 setEnabled(lyxview_->input_lyxscale, 1);
536 } else if (ob == lyxview_->button_latex_values) {
537 if (contains(fl_get_choice_text(size_->choice_width),'%'))
538 Alert::alert(_("Warning!"),
539 _("The units text%, page%, col% and line% are not allowed here."),
540 _("Cannot use the values from LaTeX size!"));
543 getLyXLengthFromWidgets(size_->input_width,
544 size_->choice_width);
545 updateWidgetsFromLength(lyxview_->input_lyxwidth,
546 lyxview_->choice_lyxwidth,
549 dummy = getLyXLengthFromWidgets(size_->input_height,
550 size_->choice_height);
551 updateWidgetsFromLength(lyxview_->input_lyxheight,
552 lyxview_->choice_lyxheight,
554 string const scale = getStringFromInput(size_->input_scale);
555 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
556 if (fl_get_button (size_->radio_asis) == 1) {
557 fl_set_button (lyxview_->radio_lyxasis, 1);
558 setEnabled(lyxview_->input_lyxwidth, 0);
559 setEnabled(lyxview_->choice_lyxwidth, 0);
560 setEnabled(lyxview_->input_lyxheight, 0);
561 setEnabled(lyxview_->choice_lyxheight, 0);
562 setEnabled(lyxview_->input_lyxscale, 0);
563 } else if (fl_get_button (size_->radio_wh) == 1) {
564 fl_set_button (lyxview_->radio_lyxwh, 1);
565 setEnabled(lyxview_->input_lyxwidth, 1);
566 setEnabled(lyxview_->choice_lyxwidth, 1);
567 setEnabled(lyxview_->input_lyxheight, 1);
568 setEnabled(lyxview_->choice_lyxheight, 1);
569 setEnabled(lyxview_->input_lyxscale, 0);
570 } else if (fl_get_button (size_->radio_scale) ==1) {
571 fl_set_button (lyxview_->radio_lyxscale, 1);
572 setEnabled(lyxview_->input_lyxwidth, 0);
573 setEnabled(lyxview_->choice_lyxwidth, 0);
574 setEnabled(lyxview_->input_lyxheight, 0);
575 setEnabled(lyxview_->choice_lyxheight, 0);
576 setEnabled(lyxview_->input_lyxscale, 1);
581 } else if (!controller().bbChanged &&
582 (ob == bbox_->choice_bb_units ||
583 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
584 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
585 controller().bbChanged = true;
586 } else if (ob == bbox_->button_getBB) {
587 string const filename = getStringFromInput(file_->input_filename);
588 if (!filename.empty()) {
589 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
590 string bb = controller().readBB(fileWithAbsPath);
592 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
593 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
594 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
595 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
596 string const unit("pt");
597 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
599 controller().bbChanged = false;
601 fl_set_input(bbox_->input_bb_x0, "");
602 fl_set_input(bbox_->input_bb_y0, "");
603 fl_set_input(bbox_->input_bb_x1, "");
604 fl_set_input(bbox_->input_bb_y1, "");
605 fl_set_choice_text(bbox_->choice_bb_units, "pt");
609 } else if (ob == size_->radio_asis) {
610 setEnabled(size_->input_width, 0);
611 setEnabled(size_->choice_width, 0);
612 setEnabled(size_->input_height, 0);
613 setEnabled(size_->choice_height, 0);
614 setEnabled(size_->check_aspectratio, 0);
615 setEnabled(size_->input_scale, 0);
616 } else if (ob == size_->radio_wh) {
617 setEnabled(size_->input_width, 1);
618 setEnabled(size_->choice_width, 1);
619 setEnabled(size_->input_height, 1);
620 setEnabled(size_->choice_height, 1);
621 setEnabled(size_->check_aspectratio, 1);
622 setEnabled(size_->input_scale, 0);
623 } else if (ob == size_->radio_scale) {
624 setEnabled(size_->input_width, 0);
625 setEnabled(size_->choice_width, 0);
626 setEnabled(size_->input_height, 0);
627 setEnabled(size_->choice_height, 0);
628 setEnabled(size_->check_aspectratio, 0);
629 setEnabled(size_->input_scale, 1);
630 } else if (ob == size_->button_lyx_values) {
631 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
632 lyxview_->choice_lyxwidth);
633 updateWidgetsFromLength(size_->input_width,
636 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
637 lyxview_->choice_lyxheight);
638 updateWidgetsFromLength(size_->input_height,
639 size_->choice_height,
641 string const scale = getStringFromInput(lyxview_->input_lyxscale);
642 fl_set_input(size_->input_scale, scale.c_str());
643 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
644 fl_set_button (size_->radio_asis, 1);
645 setEnabled(size_->input_width, 0);
646 setEnabled(size_->choice_width, 0);
647 setEnabled(size_->input_height, 0);
648 setEnabled(size_->choice_height, 0);
649 setEnabled(size_->check_aspectratio, 0);
650 setEnabled(size_->input_scale, 0);
651 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
652 fl_set_button (size_->radio_wh, 1);
653 setEnabled(size_->input_width, 1);
654 setEnabled(size_->choice_width, 1);
655 setEnabled(size_->input_height, 1);
656 setEnabled(size_->choice_height, 1);
657 setEnabled(size_->check_aspectratio, 1);
658 setEnabled(size_->input_scale, 0);
659 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
660 fl_set_button (size_->radio_scale, 1);
661 setEnabled(size_->input_width, 0);
662 setEnabled(size_->choice_width, 0);
663 setEnabled(size_->input_height, 0);
664 setEnabled(size_->choice_height, 0);
665 setEnabled(size_->check_aspectratio, 0);
666 setEnabled(size_->input_scale, 1);
670 // check if the input is valid
671 bool invalid = !isValid(bbox_->input_bb_x0);
672 invalid = invalid || !isValid(bbox_->input_bb_x1);
673 invalid = invalid || !isValid(bbox_->input_bb_y0);
674 invalid = invalid || !isValid(bbox_->input_bb_y1);
675 invalid = invalid || !isValid(size_->input_width);
676 invalid = invalid || !isValid(size_->input_height);
677 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
678 invalid = invalid || !isValid(lyxview_->input_lyxheight);
680 // deactivate OK/ Apply buttons and
681 // spit out warnings if invalid
682 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
683 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
684 ob == size_->input_width || ob == size_->input_height ||
685 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
687 postWarning(_("Invalid Length!"));
688 return ButtonPolicy::SMI_INVALID;
694 return ButtonPolicy::SMI_VALID;