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 bb = controller().readBB(filename);
438 // get the values from the file
439 // in this case we always have the point-unit
440 fl_set_input(bbox_->input_bb_x0,
441 token(bb,' ',0).c_str());
442 fl_set_input(bbox_->input_bb_y0,
443 token(bb,' ',1).c_str());
444 fl_set_input(bbox_->input_bb_x1,
445 token(bb,' ',2).c_str());
446 fl_set_input(bbox_->input_bb_y1,
447 token(bb,' ',3).c_str());
451 fl_set_input(bbox_->input_bb_x0, bb.c_str());
452 fl_set_input(bbox_->input_bb_y0, bb.c_str());
453 fl_set_input(bbox_->input_bb_x1, bb.c_str());
454 fl_set_input(bbox_->input_bb_y1, bb.c_str());
457 fl_set_choice(bbox_->choice_bb_units, 1);
460 // get the values from the inset
461 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
463 controller().bbChanged = true;
465 anyLength = LyXLength(token(bb_inset,' ',0));
466 updateWidgetsFromLength(bbox_->input_bb_x0,
467 bbox_->choice_bb_units,anyLength,"pt");
468 anyLength = LyXLength(token(bb_inset,' ',1));
469 updateWidgetsFromLength(bbox_->input_bb_y0,
470 bbox_->choice_bb_units,anyLength,"pt");
471 anyLength = LyXLength(token(bb_inset,' ',2));
472 updateWidgetsFromLength(bbox_->input_bb_x1,
473 bbox_->choice_bb_units,anyLength,"pt");
474 anyLength = LyXLength(token(bb_inset,' ',3));
475 updateWidgetsFromLength(bbox_->input_bb_y1,
476 bbox_->choice_bb_units,anyLength,"pt");
482 bool isValid(FL_OBJECT * ob)
484 string const input = getStringFromInput(ob);
485 return input.empty() || isValidLength(input) || isStrDbl(input);
492 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
495 if (ob == file_->button_browse) {
496 // Get the filename from the dialog
497 string const in_name = getStringFromInput(file_->input_filename);
498 string const out_name = controller().Browse(in_name);
499 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
500 if (out_name != in_name && !out_name.empty()) {
501 fl_set_input(file_->input_filename, out_name.c_str());
503 if (controller().isFilenameValid(out_name))
504 updateBB(out_name, string());
506 } else if (ob == file_->check_subcaption) {
507 setEnabled(file_->input_subcaption,
508 fl_get_button(file_->check_subcaption));
509 } else if (ob == file_->check_rotate) {
510 setEnabled(file_->input_rotate_angle,
511 fl_get_button(file_->check_rotate));
512 setEnabled(file_->choice_origin,
513 fl_get_button(file_->check_rotate));
515 // the lyxview section
516 } else if (ob == lyxview_->radio_lyxasis) {
517 setEnabled(lyxview_->input_lyxwidth, 0);
518 setEnabled(lyxview_->choice_lyxwidth, 0);
519 setEnabled(lyxview_->input_lyxheight, 0);
520 setEnabled(lyxview_->choice_lyxheight, 0);
521 setEnabled(lyxview_->input_lyxscale, 0);
522 } else if (ob == lyxview_->radio_lyxwh) {
523 setEnabled(lyxview_->input_lyxwidth, 1);
524 setEnabled(lyxview_->choice_lyxwidth, 1);
525 setEnabled(lyxview_->input_lyxheight, 1);
526 setEnabled(lyxview_->choice_lyxheight, 1);
527 setEnabled(lyxview_->input_lyxscale, 0);
528 } else if (ob == lyxview_->radio_lyxscale) {
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, 1);
534 } else if (ob == lyxview_->button_latex_values) {
535 if (contains(fl_get_choice_text(size_->choice_width),'%'))
536 Alert::alert(_("Warning!"),
537 _("The units text%, page%, col% and line% are not allowed here."),
538 _("Cannot use the values from LaTeX size!"));
541 getLyXLengthFromWidgets(size_->input_width,
542 size_->choice_width);
543 updateWidgetsFromLength(lyxview_->input_lyxwidth,
544 lyxview_->choice_lyxwidth,
547 dummy = getLyXLengthFromWidgets(size_->input_height,
548 size_->choice_height);
549 updateWidgetsFromLength(lyxview_->input_lyxheight,
550 lyxview_->choice_lyxheight,
552 string const scale = getStringFromInput(size_->input_scale);
553 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
554 if (fl_get_button (size_->radio_asis) == 1) {
555 fl_set_button (lyxview_->radio_lyxasis, 1);
556 setEnabled(lyxview_->input_lyxwidth, 0);
557 setEnabled(lyxview_->choice_lyxwidth, 0);
558 setEnabled(lyxview_->input_lyxheight, 0);
559 setEnabled(lyxview_->choice_lyxheight, 0);
560 setEnabled(lyxview_->input_lyxscale, 0);
561 } else if (fl_get_button (size_->radio_wh) == 1) {
562 fl_set_button (lyxview_->radio_lyxwh, 1);
563 setEnabled(lyxview_->input_lyxwidth, 1);
564 setEnabled(lyxview_->choice_lyxwidth, 1);
565 setEnabled(lyxview_->input_lyxheight, 1);
566 setEnabled(lyxview_->choice_lyxheight, 1);
567 setEnabled(lyxview_->input_lyxscale, 0);
568 } else if (fl_get_button (size_->radio_scale) ==1) {
569 fl_set_button (lyxview_->radio_lyxscale, 1);
570 setEnabled(lyxview_->input_lyxwidth, 0);
571 setEnabled(lyxview_->choice_lyxwidth, 0);
572 setEnabled(lyxview_->input_lyxheight, 0);
573 setEnabled(lyxview_->choice_lyxheight, 0);
574 setEnabled(lyxview_->input_lyxscale, 1);
579 } else if (!controller().bbChanged &&
580 (ob == bbox_->choice_bb_units ||
581 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
582 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
583 controller().bbChanged = true;
584 } else if (ob == bbox_->button_getBB) {
585 string const filename = getStringFromInput(file_->input_filename);
586 if (!filename.empty()) {
587 string bb = controller().readBB(filename);
589 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
590 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
591 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
592 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
593 string const unit("pt");
594 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
596 controller().bbChanged = false;
598 fl_set_input(bbox_->input_bb_x0, "");
599 fl_set_input(bbox_->input_bb_y0, "");
600 fl_set_input(bbox_->input_bb_x1, "");
601 fl_set_input(bbox_->input_bb_y1, "");
602 fl_set_choice_text(bbox_->choice_bb_units, "pt");
606 } else if (ob == size_->radio_asis) {
607 setEnabled(size_->input_width, 0);
608 setEnabled(size_->choice_width, 0);
609 setEnabled(size_->input_height, 0);
610 setEnabled(size_->choice_height, 0);
611 setEnabled(size_->check_aspectratio, 0);
612 setEnabled(size_->input_scale, 0);
613 } else if (ob == size_->radio_wh) {
614 setEnabled(size_->input_width, 1);
615 setEnabled(size_->choice_width, 1);
616 setEnabled(size_->input_height, 1);
617 setEnabled(size_->choice_height, 1);
618 setEnabled(size_->check_aspectratio, 1);
619 setEnabled(size_->input_scale, 0);
620 } else if (ob == size_->radio_scale) {
621 setEnabled(size_->input_width, 0);
622 setEnabled(size_->choice_width, 0);
623 setEnabled(size_->input_height, 0);
624 setEnabled(size_->choice_height, 0);
625 setEnabled(size_->check_aspectratio, 0);
626 setEnabled(size_->input_scale, 1);
627 } else if (ob == size_->button_lyx_values) {
628 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
629 lyxview_->choice_lyxwidth);
630 updateWidgetsFromLength(size_->input_width,
633 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
634 lyxview_->choice_lyxheight);
635 updateWidgetsFromLength(size_->input_height,
636 size_->choice_height,
638 string const scale = getStringFromInput(lyxview_->input_lyxscale);
639 fl_set_input(size_->input_scale, scale.c_str());
640 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
641 fl_set_button (size_->radio_asis, 1);
642 setEnabled(size_->input_width, 0);
643 setEnabled(size_->choice_width, 0);
644 setEnabled(size_->input_height, 0);
645 setEnabled(size_->choice_height, 0);
646 setEnabled(size_->check_aspectratio, 0);
647 setEnabled(size_->input_scale, 0);
648 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
649 fl_set_button (size_->radio_wh, 1);
650 setEnabled(size_->input_width, 1);
651 setEnabled(size_->choice_width, 1);
652 setEnabled(size_->input_height, 1);
653 setEnabled(size_->choice_height, 1);
654 setEnabled(size_->check_aspectratio, 1);
655 setEnabled(size_->input_scale, 0);
656 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
657 fl_set_button (size_->radio_scale, 1);
658 setEnabled(size_->input_width, 0);
659 setEnabled(size_->choice_width, 0);
660 setEnabled(size_->input_height, 0);
661 setEnabled(size_->choice_height, 0);
662 setEnabled(size_->check_aspectratio, 0);
663 setEnabled(size_->input_scale, 1);
667 // check if the input is valid
668 bool invalid = !isValid(bbox_->input_bb_x0);
669 invalid = invalid || !isValid(bbox_->input_bb_x1);
670 invalid = invalid || !isValid(bbox_->input_bb_y0);
671 invalid = invalid || !isValid(bbox_->input_bb_y1);
672 invalid = invalid || !isValid(size_->input_width);
673 invalid = invalid || !isValid(size_->input_height);
674 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
675 invalid = invalid || !isValid(lyxview_->input_lyxheight);
677 // deactivate OK/ Apply buttons and
678 // spit out warnings if invalid
679 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
680 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
681 ob == size_->input_width || ob == size_->input_height ||
682 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
684 postWarning(_("Invalid Length!"));
685 return ButtonPolicy::SMI_INVALID;
691 return ButtonPolicy::SMI_VALID;