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, Dialogs & d)
57 : base_class(c, d, _("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);
135 bc().addReadOnly(lyxview_->check_lyxaspectratio);
138 size_.reset(build_graphics_size(this));
140 fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
141 fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
142 fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
144 setPrehandler(size_->input_scale);
145 setPrehandler(size_->input_width);
146 setPrehandler(size_->input_height);
148 fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
149 fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
150 fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
152 fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
154 fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
155 fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
157 bc().addReadOnly(size_->radio_asis);
158 bc().addReadOnly(size_->radio_wh);
159 bc().addReadOnly(size_->radio_scale);
160 bc().addReadOnly(size_->check_aspectratio);
162 // the bounding box selection
163 bbox_.reset(build_graphics_bbox(this));
164 fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
165 fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
166 fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
167 fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
169 fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
170 fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
171 fl_set_input_filter(bbox_->input_bb_x1, fl_unsigned_float_filter);
172 fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
174 setPrehandler(bbox_->input_bb_x0);
175 setPrehandler(bbox_->input_bb_y0);
176 setPrehandler(bbox_->input_bb_x1);
177 setPrehandler(bbox_->input_bb_y1);
179 string const bb_units = "bp|cm|mm|in";
180 fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
181 bc().addReadOnly(bbox_->button_getBB);
182 bc().addReadOnly(bbox_->check_clip);
184 // the rotate section
185 special_.reset(build_graphics_special(this));
187 fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
188 setPrehandler(special_->input_special);
190 // add the different tabfolders
191 fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
192 fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
193 fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
194 fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
195 fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
196 // set the right default unit
197 if (lyxrc.default_papersize < 3)
202 void FormGraphics::apply()
204 // Create the parameters structure and fill the data from the dialog.
205 InsetGraphicsParams & igp = controller().params();
208 igp.filename = getString(file_->input_filename);
209 igp.subcaption = fl_get_button(file_->check_subcaption);
210 igp.subcaptionText = getString(file_->input_subcaption);
211 igp.rotate = fl_get_button(file_->check_rotate);
213 strToDbl(getString(file_->input_rotate_angle));
214 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
215 if (igp.rotateAngle < 0.0) {
216 igp.rotateAngle += 360.0;
217 } else if (igp.rotateAngle > 360.0) {
218 igp.rotateAngle -= 360.0;
221 int const pos = fl_get_choice(file_->choice_origin);
223 igp.rotateOrigin = origins_[pos-1];
225 igp.rotateOrigin = string();
227 igp.draft = fl_get_button(file_->check_draft);
228 igp.noUnzip = fl_get_button(file_->check_nounzip);
230 // the lyxview section
231 if (fl_get_button(lyxview_->radio_pref))
232 igp.display = InsetGraphicsParams::DEFAULT;
233 else if (fl_get_button(lyxview_->radio_mono))
234 igp.display = InsetGraphicsParams::MONOCHROME;
235 else if (fl_get_button(lyxview_->radio_gray))
236 igp.display = InsetGraphicsParams::GRAYSCALE;
237 else if (fl_get_button(lyxview_->radio_color))
238 igp.display = InsetGraphicsParams::COLOR;
239 else if (fl_get_button(lyxview_->radio_nodisplay))
240 igp.display = InsetGraphicsParams::NONE;
242 if (fl_get_button(lyxview_->radio_lyxasis))
243 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
244 else if (fl_get_button(lyxview_->radio_lyxwh))
245 igp.lyxsize_type = InsetGraphicsParams::WH;
247 igp.lyxsize_type = InsetGraphicsParams::SCALE;
249 igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
250 lyxview_->choice_lyxwidth);
252 igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
253 lyxview_->choice_lyxheight);
255 igp.lyxscale = strToInt(getString(lyxview_->input_lyxscale));
256 igp.keepLyXAspectRatio = fl_get_button(lyxview_->check_lyxaspectratio);
259 if (fl_get_button(size_->radio_asis))
260 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
261 else if (fl_get_button(size_->radio_wh))
262 igp.size_type = InsetGraphicsParams::WH;
264 igp.size_type = InsetGraphicsParams::SCALE;
266 igp.width = getLyXLengthFromWidgets(size_->input_width,
267 size_->choice_width);
269 igp.height = getLyXLengthFromWidgets(size_->input_height,
270 size_->choice_height);
272 igp.scale = strToInt(getString(size_->input_scale));
273 igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
276 if (!controller().bbChanged) // different to the original one?
277 igp.bb = string(); // don't write anything
280 if (getString(bbox_->input_bb_x0).empty())
283 bb = getLengthFromWidgets(bbox_->input_bb_x0,
284 bbox_->choice_bb_units)+" ";
285 if (getString(bbox_->input_bb_y0).empty())
288 bb += (getLengthFromWidgets(bbox_->input_bb_y0,
289 bbox_->choice_bb_units)+" ");
290 if (getString(bbox_->input_bb_x1).empty())
293 bb += (getLengthFromWidgets(bbox_->input_bb_x1,
294 bbox_->choice_bb_units)+" ");
295 if (getString(bbox_->input_bb_y1).empty())
298 bb += (getLengthFromWidgets(bbox_->input_bb_y1,
299 bbox_->choice_bb_units)+" ");
302 igp.clip = fl_get_button(bbox_->check_clip);
304 // the special section
305 igp.special = getString(special_->input_special);
309 void FormGraphics::update() {
310 // Update dialog with details from inset
311 InsetGraphicsParams & igp = controller().params();
314 fl_set_input(file_->input_filename, igp.filename.c_str());
315 fl_set_button(file_->check_subcaption, igp.subcaption);
316 fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
317 setEnabled(file_->input_subcaption,
318 fl_get_button(file_->check_subcaption));
319 fl_set_button(file_->check_rotate, igp.rotate);
320 fl_set_input(file_->input_rotate_angle,
321 tostr(igp.rotateAngle).c_str());
322 if (igp.rotateOrigin.empty())
323 fl_set_choice(file_->choice_origin,1);
325 int pos = int(findPos(origins_, igp.rotateOrigin));
326 fl_set_choice(file_->choice_origin, pos+1);
329 setEnabled(file_->input_rotate_angle,
330 fl_get_button(file_->check_rotate));
331 setEnabled(file_->choice_origin,
332 fl_get_button(file_->check_rotate));
333 fl_set_button(file_->check_draft, igp.draft);
334 fl_set_button(file_->check_nounzip, igp.noUnzip);
336 // the lyxview section
337 switch (igp.display) {
338 case InsetGraphicsParams::DEFAULT:
339 fl_set_button(lyxview_->radio_pref, 1);
341 case InsetGraphicsParams::MONOCHROME:
342 fl_set_button(lyxview_->radio_mono, 1);
344 case InsetGraphicsParams::GRAYSCALE:
345 fl_set_button(lyxview_->radio_gray, 1);
347 case InsetGraphicsParams::COLOR:
348 fl_set_button(lyxview_->radio_color, 1);
350 case InsetGraphicsParams::NONE:
351 fl_set_button(lyxview_->radio_nodisplay, 1);
354 updateWidgetsFromLength(lyxview_->input_lyxwidth,
355 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
356 updateWidgetsFromLength(lyxview_->input_lyxheight,
357 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
358 fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
359 switch (igp.lyxsize_type) {
360 case InsetGraphicsParams::DEFAULT_SIZE: {
361 fl_set_button(lyxview_->radio_lyxasis,1);
362 setEnabled(lyxview_->input_lyxwidth, 0);
363 setEnabled(lyxview_->choice_lyxwidth, 0);
364 setEnabled(lyxview_->input_lyxheight, 0);
365 setEnabled(lyxview_->choice_lyxheight, 0);
366 setEnabled(lyxview_->check_lyxaspectratio, 0);
367 setEnabled(lyxview_->input_lyxscale, 0);
370 case InsetGraphicsParams::WH: {
371 fl_set_button(lyxview_->radio_lyxwh, 1);
372 setEnabled(lyxview_->input_lyxwidth, 1);
373 setEnabled(lyxview_->choice_lyxwidth, 1);
374 setEnabled(lyxview_->input_lyxheight, 1);
375 setEnabled(lyxview_->choice_lyxheight, 1);
376 setEnabled(lyxview_->check_lyxaspectratio, 1);
377 setEnabled(lyxview_->input_lyxscale, 0);
380 case InsetGraphicsParams::SCALE: {
381 fl_set_button(lyxview_->radio_lyxscale, 1);
382 setEnabled(lyxview_->input_lyxwidth, 0);
383 setEnabled(lyxview_->choice_lyxwidth, 0);
384 setEnabled(lyxview_->input_lyxheight, 0);
385 setEnabled(lyxview_->choice_lyxheight, 0);
386 setEnabled(lyxview_->check_lyxaspectratio, 0);
387 setEnabled(lyxview_->input_lyxscale, 1);
392 fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
395 // Update the draft and clip mode
396 updateWidgetsFromLength(size_->input_width,
397 size_->choice_width, igp.width, defaultUnit);
398 updateWidgetsFromLength(size_->input_height,
399 size_->choice_height, igp.height, defaultUnit);
400 fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
401 switch (igp.size_type) {
402 case InsetGraphicsParams::DEFAULT_SIZE: {
403 fl_set_button(size_->radio_asis,1);
404 setEnabled(size_->input_width, 0);
405 setEnabled(size_->choice_width, 0);
406 setEnabled(size_->input_height, 0);
407 setEnabled(size_->choice_height, 0);
408 setEnabled(size_->check_aspectratio, 0);
409 setEnabled(size_->input_scale, 0);
412 case InsetGraphicsParams::WH: {
413 fl_set_button(size_->radio_wh, 1);
414 setEnabled(size_->input_width, 1);
415 setEnabled(size_->choice_width, 1);
416 setEnabled(size_->input_height, 1);
417 setEnabled(size_->choice_height, 1);
418 setEnabled(size_->check_aspectratio, 1);
419 setEnabled(size_->input_scale, 0);
422 case InsetGraphicsParams::SCALE: {
423 fl_set_button(size_->radio_scale, 1);
424 setEnabled(size_->input_width, 0);
425 setEnabled(size_->choice_width, 0);
426 setEnabled(size_->input_height, 0);
427 setEnabled(size_->choice_height, 0);
428 setEnabled(size_->check_aspectratio, 0);
429 setEnabled(size_->input_scale, 1);
433 fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
436 // set the bounding box values, if exists. First we need the whole
437 // path, because the controller knows nothing about the doc-dir
438 updateBB(igp.filename, igp.bb);
439 fl_set_button(bbox_->check_clip, igp.clip);
441 // the special section
442 fl_set_input(special_->input_special, igp.special.c_str());
446 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
448 // Update dialog with details from inset
449 // set the bounding box values, if exists. First we need the whole
450 // path, because the controller knows nothing about the doc-dir
451 controller().bbChanged = false;
452 if (bb_inset.empty()) {
453 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
454 string const bb = controller().readBB(filename);
456 // get the values from the file
457 // in this case we always have the point-unit
458 fl_set_input(bbox_->input_bb_x0,
459 token(bb,' ',0).c_str());
460 fl_set_input(bbox_->input_bb_y0,
461 token(bb,' ',1).c_str());
462 fl_set_input(bbox_->input_bb_x1,
463 token(bb,' ',2).c_str());
464 fl_set_input(bbox_->input_bb_y1,
465 token(bb,' ',3).c_str());
469 fl_set_input(bbox_->input_bb_x0, bb.c_str());
470 fl_set_input(bbox_->input_bb_y0, bb.c_str());
471 fl_set_input(bbox_->input_bb_x1, bb.c_str());
472 fl_set_input(bbox_->input_bb_y1, bb.c_str());
475 fl_set_choice(bbox_->choice_bb_units, 1);
478 // get the values from the inset
479 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
481 controller().bbChanged = true;
483 anyLength = LyXLength(token(bb_inset,' ',0));
484 updateWidgetsFromLength(bbox_->input_bb_x0,
485 bbox_->choice_bb_units,anyLength,"bp");
486 anyLength = LyXLength(token(bb_inset,' ',1));
487 updateWidgetsFromLength(bbox_->input_bb_y0,
488 bbox_->choice_bb_units,anyLength,"bp");
489 anyLength = LyXLength(token(bb_inset,' ',2));
490 updateWidgetsFromLength(bbox_->input_bb_x1,
491 bbox_->choice_bb_units,anyLength,"bp");
492 anyLength = LyXLength(token(bb_inset,' ',3));
493 updateWidgetsFromLength(bbox_->input_bb_y1,
494 bbox_->choice_bb_units,anyLength,"bp");
500 bool isValid(FL_OBJECT * ob)
502 string const input = getString(ob);
503 return input.empty() || isValidLength(input) || isStrDbl(input);
510 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
513 if (ob == file_->button_browse) {
514 // Get the filename from the dialog
515 string const in_name = getString(file_->input_filename);
516 string const out_name = controller().Browse(in_name);
517 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
518 if (out_name != in_name && !out_name.empty()) {
519 fl_set_input(file_->input_filename, out_name.c_str());
521 if (controller().isFilenameValid(out_name) &&
522 !controller().bbChanged)
523 updateBB(out_name, string());
525 } else if (ob == file_->check_subcaption) {
526 setEnabled(file_->input_subcaption,
527 fl_get_button(file_->check_subcaption));
528 } else if (ob == file_->check_rotate) {
529 setEnabled(file_->input_rotate_angle,
530 fl_get_button(file_->check_rotate));
531 setEnabled(file_->choice_origin,
532 fl_get_button(file_->check_rotate));
534 // the lyxview section
535 } else if (ob == lyxview_->radio_lyxasis) {
536 setEnabled(lyxview_->input_lyxwidth, 0);
537 setEnabled(lyxview_->choice_lyxwidth, 0);
538 setEnabled(lyxview_->input_lyxheight, 0);
539 setEnabled(lyxview_->choice_lyxheight, 0);
540 setEnabled(lyxview_->check_lyxaspectratio, 0);
541 setEnabled(lyxview_->input_lyxscale, 0);
542 } else if (ob == lyxview_->radio_lyxwh) {
543 setEnabled(lyxview_->input_lyxwidth, 1);
544 setEnabled(lyxview_->choice_lyxwidth, 1);
545 setEnabled(lyxview_->input_lyxheight, 1);
546 setEnabled(lyxview_->choice_lyxheight, 1);
547 setEnabled(lyxview_->check_lyxaspectratio, 1);
548 setEnabled(lyxview_->input_lyxscale, 0);
549 } else if (ob == lyxview_->radio_lyxscale) {
550 setEnabled(lyxview_->input_lyxwidth, 0);
551 setEnabled(lyxview_->choice_lyxwidth, 0);
552 setEnabled(lyxview_->input_lyxheight, 0);
553 setEnabled(lyxview_->choice_lyxheight, 0);
554 setEnabled(lyxview_->check_lyxaspectratio, 0);
555 setEnabled(lyxview_->input_lyxscale, 1);
556 } else if (ob == lyxview_->button_latex_values) {
557 if (contains(fl_get_choice_text(size_->choice_width),'%') ||
558 contains(fl_get_choice_text(size_->choice_height),'%'))
559 Alert::alert(_("Warning!"),
560 _("The %-units are not allowed here."),
561 _("Cannot use the values from LaTeX size!"));
564 getLyXLengthFromWidgets(size_->input_width,
565 size_->choice_width);
566 updateWidgetsFromLength(lyxview_->input_lyxwidth,
567 lyxview_->choice_lyxwidth,
570 dummy = getLyXLengthFromWidgets(size_->input_height,
571 size_->choice_height);
572 updateWidgetsFromLength(lyxview_->input_lyxheight,
573 lyxview_->choice_lyxheight,
575 string const scale = getString(size_->input_scale);
576 fl_set_input(lyxview_->input_lyxscale, scale.c_str());
577 if (fl_get_button (size_->radio_asis) == 1) {
578 fl_set_button (lyxview_->radio_lyxasis, 1);
579 setEnabled(lyxview_->input_lyxwidth, 0);
580 setEnabled(lyxview_->choice_lyxwidth, 0);
581 setEnabled(lyxview_->input_lyxheight, 0);
582 setEnabled(lyxview_->choice_lyxheight, 0);
583 setEnabled(lyxview_->check_lyxaspectratio, 0);
584 setEnabled(lyxview_->input_lyxscale, 0);
585 } else if (fl_get_button (size_->radio_wh) == 1) {
586 fl_set_button (lyxview_->radio_lyxwh, 1);
587 setEnabled(lyxview_->input_lyxwidth, 1);
588 setEnabled(lyxview_->choice_lyxwidth, 1);
589 setEnabled(lyxview_->input_lyxheight, 1);
590 setEnabled(lyxview_->choice_lyxheight, 1);
591 setEnabled(lyxview_->check_lyxaspectratio, 1);
592 setEnabled(lyxview_->input_lyxscale, 0);
593 } else if (fl_get_button (size_->radio_scale) ==1) {
594 fl_set_button (lyxview_->radio_lyxscale, 1);
595 setEnabled(lyxview_->input_lyxwidth, 0);
596 setEnabled(lyxview_->choice_lyxwidth, 0);
597 setEnabled(lyxview_->input_lyxheight, 0);
598 setEnabled(lyxview_->choice_lyxheight, 0);
599 setEnabled(lyxview_->check_lyxaspectratio, 0);
600 setEnabled(lyxview_->input_lyxscale, 1);
603 fl_set_button(lyxview_->check_lyxaspectratio,
604 fl_get_button(size_->check_aspectratio));
607 } else if (!controller().bbChanged &&
608 (ob == bbox_->check_clip || ob == bbox_->choice_bb_units ||
609 ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
610 ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
611 controller().bbChanged = true;
612 } else if (ob == bbox_->button_getBB) {
613 string const filename = getString(file_->input_filename);
614 if (!filename.empty()) {
615 string bb = controller().readBB(filename);
617 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
618 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
619 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
620 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
621 string const unit("bp");
622 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
624 controller().bbChanged = false;
626 fl_set_input(bbox_->input_bb_x0, "");
627 fl_set_input(bbox_->input_bb_y0, "");
628 fl_set_input(bbox_->input_bb_x1, "");
629 fl_set_input(bbox_->input_bb_y1, "");
630 fl_set_choice_text(bbox_->choice_bb_units, "bp");
634 } else if (ob == size_->radio_asis) {
635 setEnabled(size_->input_width, 0);
636 setEnabled(size_->choice_width, 0);
637 setEnabled(size_->input_height, 0);
638 setEnabled(size_->choice_height, 0);
639 setEnabled(size_->check_aspectratio, 0);
640 setEnabled(size_->input_scale, 0);
641 } else if (ob == size_->radio_wh) {
642 setEnabled(size_->input_width, 1);
643 setEnabled(size_->choice_width, 1);
644 setEnabled(size_->input_height, 1);
645 setEnabled(size_->choice_height, 1);
646 setEnabled(size_->check_aspectratio, 1);
647 setEnabled(size_->input_scale, 0);
648 } else if (ob == size_->radio_scale) {
649 setEnabled(size_->input_width, 0);
650 setEnabled(size_->choice_width, 0);
651 setEnabled(size_->input_height, 0);
652 setEnabled(size_->choice_height, 0);
653 setEnabled(size_->check_aspectratio, 0);
654 setEnabled(size_->input_scale, 1);
655 } else if (ob == size_->button_lyx_values) {
656 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
657 lyxview_->choice_lyxwidth);
658 updateWidgetsFromLength(size_->input_width,
661 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
662 lyxview_->choice_lyxheight);
663 updateWidgetsFromLength(size_->input_height,
664 size_->choice_height,
666 string const scale = getString(lyxview_->input_lyxscale);
667 fl_set_input(size_->input_scale, scale.c_str());
668 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
669 fl_set_button (size_->radio_asis, 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, 0);
676 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
677 fl_set_button (size_->radio_wh, 1);
678 setEnabled(size_->input_width, 1);
679 setEnabled(size_->choice_width, 1);
680 setEnabled(size_->input_height, 1);
681 setEnabled(size_->choice_height, 1);
682 setEnabled(size_->check_aspectratio, 1);
683 setEnabled(size_->input_scale, 0);
684 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
685 fl_set_button (size_->radio_scale, 1);
686 setEnabled(size_->input_width, 0);
687 setEnabled(size_->choice_width, 0);
688 setEnabled(size_->input_height, 0);
689 setEnabled(size_->choice_height, 0);
690 setEnabled(size_->check_aspectratio, 0);
691 setEnabled(size_->input_scale, 1);
693 fl_set_button(size_->check_aspectratio,
694 fl_get_button(lyxview_->check_lyxaspectratio));
697 // check if the input is valid
698 bool invalid = !isValid(bbox_->input_bb_x0);
699 invalid = invalid || !isValid(bbox_->input_bb_x1);
700 invalid = invalid || !isValid(bbox_->input_bb_y0);
701 invalid = invalid || !isValid(bbox_->input_bb_y1);
702 invalid = invalid || !isValid(size_->input_width);
703 invalid = invalid || !isValid(size_->input_height);
704 invalid = invalid || !isValid(lyxview_->input_lyxwidth);
705 invalid = invalid || !isValid(lyxview_->input_lyxheight);
707 // deactivate OK/ Apply buttons and
708 // spit out warnings if invalid
709 if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
710 ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
711 ob == size_->input_width || ob == size_->input_height ||
712 ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
714 postWarning(_("Invalid Length!"));
715 return ButtonPolicy::SMI_INVALID;
721 return ButtonPolicy::SMI_VALID;