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 = "bp|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);
300 void FormGraphics::update() {
301 // Update dialog with details from inset
302 InsetGraphicsParams & igp = controller().params();
305 fl_set_input(file_->input_filename, igp.filename.c_str());
306 fl_set_button(file_->check_subcaption, igp.subcaption);
307 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
308 setEnabled(file_->input_subcaption,
309 fl_get_button(file_->check_subcaption));
310 fl_set_button(file_->check_rotate, igp.rotate);
311 fl_set_input(file_->input_rotate_angle,
312 tostr(igp.rotateAngle).c_str());
313 if (igp.rotateOrigin.empty())
314 fl_set_choice(file_->choice_origin,1);
316 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
317 setEnabled(file_->input_rotate_angle,
318 fl_get_button(file_->check_rotate));
319 setEnabled(file_->choice_origin,
320 fl_get_button(file_->check_rotate));
321 fl_set_button(file_->check_draft, igp.draft);
322 fl_set_button(file_->check_nounzip, igp.noUnzip);
324 // the lyxview section
325 switch (igp.display) {
326 case InsetGraphicsParams::DEFAULT:
327 fl_set_button(lyxview_->radio_pref, 1);
329 case InsetGraphicsParams::MONOCHROME:
330 fl_set_button(lyxview_->radio_mono, 1);
332 case InsetGraphicsParams::GRAYSCALE:
333 fl_set_button(lyxview_->radio_gray, 1);
335 case InsetGraphicsParams::COLOR:
336 fl_set_button(lyxview_->radio_color, 1);
338 case InsetGraphicsParams::NONE:
339 fl_set_button(lyxview_->radio_nodisplay, 1);
342 updateWidgetsFromLength(lyxview_->input_lyxwidth,
343 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
344 updateWidgetsFromLength(lyxview_->input_lyxheight,
345 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
346 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
347 switch (igp.lyxsize_type) {
348 case InsetGraphicsParams::DEFAULT_SIZE: {
349 fl_set_button(lyxview_->radio_lyxasis,1);
350 setEnabled(lyxview_->input_lyxwidth, 0);
351 setEnabled(lyxview_->choice_lyxwidth, 0);
352 setEnabled(lyxview_->input_lyxheight, 0);
353 setEnabled(lyxview_->choice_lyxheight, 0);
354 setEnabled(lyxview_->input_lyxscale, 0);
357 case InsetGraphicsParams::WH: {
358 fl_set_button(lyxview_->radio_lyxwh, 1);
359 setEnabled(lyxview_->input_lyxwidth, 1);
360 setEnabled(lyxview_->choice_lyxwidth, 1);
361 setEnabled(lyxview_->input_lyxheight, 1);
362 setEnabled(lyxview_->choice_lyxheight, 1);
363 setEnabled(lyxview_->input_lyxscale, 0);
366 case InsetGraphicsParams::SCALE: {
367 fl_set_button(lyxview_->radio_lyxscale, 1);
368 setEnabled(lyxview_->input_lyxwidth, 0);
369 setEnabled(lyxview_->choice_lyxwidth, 0);
370 setEnabled(lyxview_->input_lyxheight, 0);
371 setEnabled(lyxview_->choice_lyxheight, 0);
372 setEnabled(lyxview_->input_lyxscale, 1);
378 // Update the draft and clip mode
379 updateWidgetsFromLength(size_->input_width,
380 size_->choice_width, igp.width, defaultUnit);
381 updateWidgetsFromLength(size_->input_height,
382 size_->choice_height, igp.height, defaultUnit);
383 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
384 switch (igp.size_type) {
385 case InsetGraphicsParams::DEFAULT_SIZE: {
386 fl_set_button(size_->radio_asis,1);
387 setEnabled(size_->input_width, 0);
388 setEnabled(size_->choice_width, 0);
389 setEnabled(size_->input_height, 0);
390 setEnabled(size_->choice_height, 0);
391 setEnabled(size_->check_aspectratio, 0);
392 setEnabled(size_->input_scale, 0);
395 case InsetGraphicsParams::WH: {
396 fl_set_button(size_->radio_wh, 1);
397 setEnabled(size_->input_width, 1);
398 setEnabled(size_->choice_width, 1);
399 setEnabled(size_->input_height, 1);
400 setEnabled(size_->choice_height, 1);
401 setEnabled(size_->check_aspectratio, 1);
402 setEnabled(size_->input_scale, 0);
405 case InsetGraphicsParams::SCALE: {
406 fl_set_button(size_->radio_scale, 1);
407 setEnabled(size_->input_width, 0);
408 setEnabled(size_->choice_width, 0);
409 setEnabled(size_->input_height, 0);
410 setEnabled(size_->choice_height, 0);
411 setEnabled(size_->check_aspectratio, 0);
412 setEnabled(size_->input_scale, 1);
416 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
419 // set the bounding box values, if exists. First we need the whole
420 // path, because the controller knows nothing about the doc-dir
421 updateBB(igp.filename, igp.bb);
422 fl_set_button(bbox_->check_clip, igp.clip);
424 // the special section
425 fl_set_input(special_->input_special, igp.special.c_str());
429 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
431 // Update dialog with details from inset
432 // set the bounding box values, if exists. First we need the whole
433 // path, because the controller knows nothing about the doc-dir
434 controller().bbChanged = false;
435 if (bb_inset.empty()) {
436 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
437 string const bb = controller().readBB(filename);
439 // get the values from the file
440 // in this case we always have the point-unit
441 fl_set_input(bbox_->input_bb_x0,
442 token(bb,' ',0).c_str());
443 fl_set_input(bbox_->input_bb_y0,
444 token(bb,' ',1).c_str());
445 fl_set_input(bbox_->input_bb_x1,
446 token(bb,' ',2).c_str());
447 fl_set_input(bbox_->input_bb_y1,
448 token(bb,' ',3).c_str());
452 fl_set_input(bbox_->input_bb_x0, bb.c_str());
453 fl_set_input(bbox_->input_bb_y0, bb.c_str());
454 fl_set_input(bbox_->input_bb_x1, bb.c_str());
455 fl_set_input(bbox_->input_bb_y1, bb.c_str());
458 fl_set_choice(bbox_->choice_bb_units, 1);
461 // get the values from the inset
462 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
464 controller().bbChanged = true;
466 anyLength = LyXLength(token(bb_inset,' ',0));
467 updateWidgetsFromLength(bbox_->input_bb_x0,
468 bbox_->choice_bb_units,anyLength,"bp");
469 anyLength = LyXLength(token(bb_inset,' ',1));
470 updateWidgetsFromLength(bbox_->input_bb_y0,
471 bbox_->choice_bb_units,anyLength,"bp");
472 anyLength = LyXLength(token(bb_inset,' ',2));
473 updateWidgetsFromLength(bbox_->input_bb_x1,
474 bbox_->choice_bb_units,anyLength,"bp");
475 anyLength = LyXLength(token(bb_inset,' ',3));
476 updateWidgetsFromLength(bbox_->input_bb_y1,
477 bbox_->choice_bb_units,anyLength,"bp");
483 bool isValid(FL_OBJECT * ob)
485 string const input = getStringFromInput(ob);
486 return input.empty() || isValidLength(input) || isStrDbl(input);
493 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
496 if (ob == file_->button_browse) {
497 // Get the filename from the dialog
498 string const in_name = getStringFromInput(file_->input_filename);
499 string const out_name = controller().Browse(in_name);
500 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
501 if (out_name != in_name && !out_name.empty()) {
502 fl_set_input(file_->input_filename, out_name.c_str());
504 if (controller().isFilenameValid(out_name))
505 updateBB(out_name, string());
507 } else if (ob == file_->check_subcaption) {
508 setEnabled(file_->input_subcaption,
509 fl_get_button(file_->check_subcaption));
510 } else if (ob == file_->check_rotate) {
511 setEnabled(file_->input_rotate_angle,
512 fl_get_button(file_->check_rotate));
513 setEnabled(file_->choice_origin,
514 fl_get_button(file_->check_rotate));
516 // the lyxview section
517 } else if (ob == lyxview_->radio_lyxasis) {
518 setEnabled(lyxview_->input_lyxwidth, 0);
519 setEnabled(lyxview_->choice_lyxwidth, 0);
520 setEnabled(lyxview_->input_lyxheight, 0);
521 setEnabled(lyxview_->choice_lyxheight, 0);
522 setEnabled(lyxview_->input_lyxscale, 0);
523 } else if (ob == lyxview_->radio_lyxwh) {
524 setEnabled(lyxview_->input_lyxwidth, 1);
525 setEnabled(lyxview_->choice_lyxwidth, 1);
526 setEnabled(lyxview_->input_lyxheight, 1);
527 setEnabled(lyxview_->choice_lyxheight, 1);
528 setEnabled(lyxview_->input_lyxscale, 0);
529 } else if (ob == lyxview_->radio_lyxscale) {
530 setEnabled(lyxview_->input_lyxwidth, 0);
531 setEnabled(lyxview_->choice_lyxwidth, 0);
532 setEnabled(lyxview_->input_lyxheight, 0);
533 setEnabled(lyxview_->choice_lyxheight, 0);
534 setEnabled(lyxview_->input_lyxscale, 1);
535 } else if (ob == lyxview_->button_latex_values) {
536 if (contains(fl_get_choice_text(size_->choice_width),'%'))
537 Alert::alert(_("Warning!"),
538 _("The units text%, page%, col% and line% are not allowed here."),
539 _("Cannot use the values from LaTeX size!"));
542 getLyXLengthFromWidgets(size_->input_width,
543 size_->choice_width);
544 updateWidgetsFromLength(lyxview_->input_lyxwidth,
545 lyxview_->choice_lyxwidth,
548 dummy = getLyXLengthFromWidgets(size_->input_height,
549 size_->choice_height);
550 updateWidgetsFromLength(lyxview_->input_lyxheight,
551 lyxview_->choice_lyxheight,
553 string const scale = getStringFromInput(size_->input_scale);
554 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
555 if (fl_get_button (size_->radio_asis) == 1) {
556 fl_set_button (lyxview_->radio_lyxasis, 1);
557 setEnabled(lyxview_->input_lyxwidth, 0);
558 setEnabled(lyxview_->choice_lyxwidth, 0);
559 setEnabled(lyxview_->input_lyxheight, 0);
560 setEnabled(lyxview_->choice_lyxheight, 0);
561 setEnabled(lyxview_->input_lyxscale, 0);
562 } else if (fl_get_button (size_->radio_wh) == 1) {
563 fl_set_button (lyxview_->radio_lyxwh, 1);
564 setEnabled(lyxview_->input_lyxwidth, 1);
565 setEnabled(lyxview_->choice_lyxwidth, 1);
566 setEnabled(lyxview_->input_lyxheight, 1);
567 setEnabled(lyxview_->choice_lyxheight, 1);
568 setEnabled(lyxview_->input_lyxscale, 0);
569 } else if (fl_get_button (size_->radio_scale) ==1) {
570 fl_set_button (lyxview_->radio_lyxscale, 1);
571 setEnabled(lyxview_->input_lyxwidth, 0);
572 setEnabled(lyxview_->choice_lyxwidth, 0);
573 setEnabled(lyxview_->input_lyxheight, 0);
574 setEnabled(lyxview_->choice_lyxheight, 0);
575 setEnabled(lyxview_->input_lyxscale, 1);
580 } else if (!controller().bbChanged &&
581 (ob == bbox_->choice_bb_units ||
582 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
583 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
584 controller().bbChanged = true;
585 } else if (ob == bbox_->button_getBB) {
586 string const filename = getStringFromInput(file_->input_filename);
587 if (!filename.empty()) {
588 string bb = controller().readBB(filename);
590 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
591 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
592 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
593 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
594 string const unit("bp");
595 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
597 controller().bbChanged = false;
599 fl_set_input(bbox_->input_bb_x0, "");
600 fl_set_input(bbox_->input_bb_y0, "");
601 fl_set_input(bbox_->input_bb_x1, "");
602 fl_set_input(bbox_->input_bb_y1, "");
603 fl_set_choice_text(bbox_->choice_bb_units, "bp");
607 } else if (ob == size_->radio_asis) {
608 setEnabled(size_->input_width, 0);
609 setEnabled(size_->choice_width, 0);
610 setEnabled(size_->input_height, 0);
611 setEnabled(size_->choice_height, 0);
612 setEnabled(size_->check_aspectratio, 0);
613 setEnabled(size_->input_scale, 0);
614 } else if (ob == size_->radio_wh) {
615 setEnabled(size_->input_width, 1);
616 setEnabled(size_->choice_width, 1);
617 setEnabled(size_->input_height, 1);
618 setEnabled(size_->choice_height, 1);
619 setEnabled(size_->check_aspectratio, 1);
620 setEnabled(size_->input_scale, 0);
621 } else if (ob == size_->radio_scale) {
622 setEnabled(size_->input_width, 0);
623 setEnabled(size_->choice_width, 0);
624 setEnabled(size_->input_height, 0);
625 setEnabled(size_->choice_height, 0);
626 setEnabled(size_->check_aspectratio, 0);
627 setEnabled(size_->input_scale, 1);
628 } else if (ob == size_->button_lyx_values) {
629 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
630 lyxview_->choice_lyxwidth);
631 updateWidgetsFromLength(size_->input_width,
634 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
635 lyxview_->choice_lyxheight);
636 updateWidgetsFromLength(size_->input_height,
637 size_->choice_height,
639 string const scale = getStringFromInput(lyxview_->input_lyxscale);
640 fl_set_input(size_->input_scale, scale.c_str());
641 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
642 fl_set_button (size_->radio_asis, 1);
643 setEnabled(size_->input_width, 0);
644 setEnabled(size_->choice_width, 0);
645 setEnabled(size_->input_height, 0);
646 setEnabled(size_->choice_height, 0);
647 setEnabled(size_->check_aspectratio, 0);
648 setEnabled(size_->input_scale, 0);
649 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
650 fl_set_button (size_->radio_wh, 1);
651 setEnabled(size_->input_width, 1);
652 setEnabled(size_->choice_width, 1);
653 setEnabled(size_->input_height, 1);
654 setEnabled(size_->choice_height, 1);
655 setEnabled(size_->check_aspectratio, 1);
656 setEnabled(size_->input_scale, 0);
657 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
658 fl_set_button (size_->radio_scale, 1);
659 setEnabled(size_->input_width, 0);
660 setEnabled(size_->choice_width, 0);
661 setEnabled(size_->input_height, 0);
662 setEnabled(size_->choice_height, 0);
663 setEnabled(size_->check_aspectratio, 0);
664 setEnabled(size_->input_scale, 1);
668 // check if the input is valid
669 bool invalid = !isValid(bbox_->input_bb_x0);
670 invalid = invalid || !isValid(bbox_->input_bb_x1);
671 invalid = invalid || !isValid(bbox_->input_bb_y0);
672 invalid = invalid || !isValid(bbox_->input_bb_y1);
673 invalid = invalid || !isValid(size_->input_width);
674 invalid = invalid || !isValid(size_->input_height);
675 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
676 invalid = invalid || !isValid(lyxview_->input_lyxheight);
678 // deactivate OK/ Apply buttons and
679 // spit out warnings if invalid
680 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
681 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
682 ob == size_->input_width || ob == size_->input_height ||
683 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
685 postWarning(_("Invalid Length!"));
686 return ButtonPolicy::SMI_INVALID;
692 return ButtonPolicy::SMI_VALID;