]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormGraphics.C
Tiny clean-ups.
[lyx.git] / src / frontends / xforms / FormGraphics.C
1 /**
2  * \file FormGraphics.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Baruch Even
7  * \author Herbert Voß
8  * \author Rob Lahaye
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "FormGraphics.h"
16 #include "ControlGraphics.h"
17 #include "forms/form_graphics.h"
18
19 #include "controllers/helper_funcs.h"
20
21 #include "checkedwidgets.h"
22 #include "input_validators.h"
23 #include "Tooltips.h"
24 #include "xforms_helpers.h"
25 #include "xformsBC.h"
26
27 #include "lyxrc.h" // for lyxrc.display_graphics
28
29 #include "insets/insetgraphicsParams.h"
30
31 #include "frontends/Alert.h"
32
33 #include "support/lyxlib.h"  // for float_equal
34 #include "support/tostr.h"
35
36 #include "lyx_forms.h"
37
38 using lyx::support::bformat;
39 using lyx::support::float_equal;
40 using lyx::support::getStringFromVector;
41 using lyx::support::strToDbl;
42 using lyx::support::strToInt;
43 using lyx::support::token;
44
45 using std::endl;
46
47 using std::vector;
48 using std::string;
49
50
51 namespace {
52
53 // Bound the number of input characters
54 int const SIZE_MAXDIGITS = 10;
55 int const FILENAME_MAXCHARS = 1024;
56
57 string defaultUnit("cm");
58
59 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
60 bool const scalableTabfolders = false;
61 #else
62 bool const scalableTabfolders = true;
63 #endif
64
65 } // namespace anon
66
67
68 typedef FormController<ControlGraphics, FormView<FD_graphics> > base_class;
69
70 FormGraphics::FormGraphics(Dialog & parent)
71         : base_class(parent, _("Graphics"), scalableTabfolders)
72 {}
73
74
75 void FormGraphics::redraw()
76 {
77         if (form() && form()->visible)
78                 fl_redraw_form(form());
79         else
80                 return;
81         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
82         if (outer_form && outer_form->visible)
83                 fl_redraw_form(outer_form);
84 }
85
86
87 void FormGraphics::build()
88 {
89         dialog_.reset(build_graphics(this));
90
91         // Manage the ok, apply, restore and cancel/close buttons
92         bcview().setOK(dialog_->button_ok);
93         bcview().setApply(dialog_->button_apply);
94         bcview().setCancel(dialog_->button_close);
95         bcview().setRestore(dialog_->button_restore);
96
97         // The file section.
98         file_.reset(build_graphics_file(this));
99
100         // Disable for read-only documents.
101         bcview().addReadOnly(file_->button_browse);
102         bcview().addReadOnly(file_->check_aspectratio);
103         bcview().addReadOnly(file_->check_draft);
104         bcview().addReadOnly(file_->check_nounzip);
105
106         // Check validity of "length + unit" input.
107         addCheckedGlueLength(bcview(), file_->input_width);
108         addCheckedGlueLength(bcview(), file_->input_height);
109
110         // Trigger an input event for cut&paste with middle mouse button.
111         setPrehandler(file_->input_filename);
112         setPrehandler(file_->input_lyxscale);
113         setPrehandler(file_->input_width);
114         setPrehandler(file_->input_height);
115
116         // Activate ok/apply immediately upon input.
117         fl_set_input_return(file_->input_filename, FL_RETURN_CHANGED);
118         fl_set_input_return(file_->input_lyxscale, FL_RETURN_CHANGED);
119         fl_set_input_return(file_->input_width, FL_RETURN_CHANGED);
120         fl_set_input_return(file_->input_height, FL_RETURN_CHANGED);
121
122         fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
123         fl_set_input_filter(file_->input_lyxscale, fl_unsigned_int_filter);
124
125         // Width default is scaling: use unsigned float filter.
126         fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
127         fl_set_input_maxchars(file_->input_height, SIZE_MAXDIGITS);
128
129         string const display_List =
130                 _("Default|Monochrome|Grayscale|Color|Do not display");
131         fl_addto_choice(file_->choice_display, display_List.c_str());
132
133         string const width_list = bformat(_("Scale%%%%|%1$s"), choice_Length_All);
134         fl_addto_choice(file_->choice_width, width_list.c_str());
135
136         fl_addto_choice(file_->choice_height, choice_Length_All.c_str());
137
138         // set up the tooltips for the filesection
139         string str = _("The file you want to insert.");
140         tooltips().init(file_->input_filename, str);
141         str = _("Browse the directories.");
142         tooltips().init(file_->button_browse, str);
143
144         str = _("Scale the image to inserted percentage value.");
145         tooltips().init(file_->input_lyxscale, str);
146         str = _("Select display mode for this image.");
147         tooltips().init(file_->choice_display, str);
148
149         str = _("Set the image width to the inserted value.");
150         tooltips().init(file_->input_width, str);
151         // xgettext:no-c-format
152         str = _("Select unit for width; Scale% for scaling whole image.");
153         tooltips().init(file_->choice_width, str);
154         str = _("Set the image height to the inserted value.");
155         tooltips().init(file_->input_height, str);
156         str = _("Select unit for height.");
157         tooltips().init(file_->choice_height, str);
158         str = _("Do not distort the image. "
159                 "Keep image within \"width\" by \"height\" and obey "
160                 "aspect ratio.");
161         tooltips().init(file_->check_aspectratio, str);
162         str = _("Pass a filename like \"file.eps.gz\" to the LaTeX output. "
163                 "Useful when LaTeX should unzip the file. Needs an additional "
164                 "file like \"file.eps.bb\" which holds the values for "
165                 "the bounding box.");
166         tooltips().init(file_->check_nounzip, str);
167         str = _("Show image only as a rectangle of the original size.");
168         tooltips().init(file_->check_draft, str);
169
170         // the bounding box selection
171         bbox_.reset(build_graphics_bbox(this));
172
173         // disable for read-only documents
174         bcview().addReadOnly(bbox_->button_getBB);
175         bcview().addReadOnly(bbox_->check_clip);
176
177         // check validity of "length + unit" input
178         addCheckedLyXLength(bcview(), bbox_->input_bb_x1, bbox_->text_X);
179
180         // trigger an input event for cut&paste with middle mouse button.
181         setPrehandler(bbox_->input_bb_x0);
182         setPrehandler(bbox_->input_bb_y0);
183         setPrehandler(bbox_->input_bb_x1);
184         setPrehandler(bbox_->input_bb_y1);
185
186         // for activate ok/apply immediately upon input
187         fl_set_input_return(bbox_->input_bb_x0, FL_RETURN_CHANGED);
188         fl_set_input_return(bbox_->input_bb_y0, FL_RETURN_CHANGED);
189         fl_set_input_return(bbox_->input_bb_x1, FL_RETURN_CHANGED);
190         fl_set_input_return(bbox_->input_bb_y1, FL_RETURN_CHANGED);
191
192         fl_set_input_filter(bbox_->input_bb_x0, fl_unsigned_float_filter);
193         fl_set_input_filter(bbox_->input_bb_y0, fl_unsigned_float_filter);
194         fl_set_input_filter(bbox_->input_bb_y1, fl_unsigned_float_filter);
195
196         string const bb_units = getStringFromVector(frnt::getBBUnits(), "|");
197         fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
198
199         // set up the tooltips for the bounding-box-section
200         str = _("The lower left x-value of the bounding box.");
201         tooltips().init(bbox_->input_bb_x0, str);
202         str = _("The lower left y-value of the bounding box.");
203         tooltips().init(bbox_->input_bb_y0, str);
204         str = _("The upper right x-value of the bounding box; "
205                 "only this input field allows length + unit, e.g. 5cm "
206                 "and sets the unit for the other input fields.");
207         tooltips().init(bbox_->input_bb_x1, str);
208         str = _("The upper right y-value of the bounding box.");
209         tooltips().init(bbox_->input_bb_y1, str);
210         str = _("Select unit for the bounding box values.");
211         tooltips().init(bbox_->choice_bb_units, str);
212
213         str = _("Read the image coordinates new from file. For (e)ps-file "
214                 "the bounding box is read, otherwise the imagesize in pixels. "
215                 "Default unit is \"bp\", the PostScript's b(ig) p(oint).");
216         tooltips().init(bbox_->button_getBB, str);
217
218         str = _("Clip image to the bounding box values.");
219         tooltips().init(bbox_->check_clip, str);
220
221         // the extra section
222         extra_.reset(build_graphics_extra(this));
223
224         // disable for read-only documents
225         bcview().addReadOnly(extra_->input_rotate_angle);
226         bcview().addReadOnly(extra_->choice_origin);
227         bcview().addReadOnly(extra_->check_subcaption);
228         bcview().addReadOnly(extra_->input_special);
229
230         // trigger an input event for cut&paste with middle mouse button.
231         setPrehandler(extra_->input_rotate_angle);
232         setPrehandler(extra_->input_subcaption);
233         setPrehandler(extra_->input_special);
234
235         fl_set_input_return(extra_->input_rotate_angle, FL_RETURN_CHANGED);
236         fl_set_input_return(extra_->input_subcaption, FL_RETURN_CHANGED);
237         fl_set_input_return(extra_->input_special, FL_RETURN_CHANGED);
238
239         fl_set_input_filter(extra_->input_rotate_angle, fl_float_filter);
240
241         using namespace frnt;
242         vector<RotationOriginPair> origindata = getRotationOriginData();
243
244         // Store the identifiers for later
245         origins_ = getSecond(origindata);
246
247         string const choice = getStringFromVector(getFirst(origindata), "|");
248         fl_addto_choice(extra_->choice_origin, choice.c_str());
249
250         // set up the tooltips for the extra section
251         str = _("Insert the rotation angle in degrees. "
252                 "Positive value rotates anti-clockwise, "
253                 "negative value clockwise.");
254         tooltips().init(extra_->input_rotate_angle, str);
255         str = _("Insert the point of origin for rotation.");
256         tooltips().init(extra_->choice_origin, str);
257         str = _("Enables use of subfigure with its own caption.");
258         tooltips().init(extra_->check_subcaption, str);
259         str = _("Insert the optional subfigure caption.");
260         tooltips().init(extra_->input_subcaption, str);
261         str = _("Add any additional LaTeX option, which is defined in the "
262                 "graphicx-package and not mentioned in the gui's tabfolders.");
263         tooltips().init(extra_->input_special, str);
264
265         // Enable the tabfolder to be rescaled correctly.
266         if (scalableTabfolders)
267                 fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
268
269         // Stack tabs
270         fl_addto_tabfolder(dialog_->tabfolder, _("File").c_str(),
271                            file_->form);
272         fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box").c_str(),
273                            bbox_->form);
274         fl_addto_tabfolder(dialog_->tabfolder, _("Extra").c_str(),
275                            extra_->form);
276
277         // set the right default unit
278         switch (lyxrc.default_papersize) {
279         case PAPER_DEFAULT: break;
280         case PAPER_USLETTER:
281         case PAPER_LEGALPAPER:
282         case PAPER_EXECUTIVEPAPER: defaultUnit = "in"; break;
283         case PAPER_A3PAPER:
284         case PAPER_A4PAPER:
285         case PAPER_A5PAPER:
286         case PAPER_B5PAPER: defaultUnit = "cm"; break;
287         }
288 }
289
290
291 void FormGraphics::apply()
292 {
293         // Create the parameters structure and fill the data from the dialog.
294         InsetGraphicsParams & igp = controller().params();
295
296         // the file section
297         igp.filename.set(getString(file_->input_filename),
298                          kernel().bufferFilepath());
299
300         igp.lyxscale = strToInt(getString(file_->input_lyxscale));
301         if (igp.lyxscale == 0) {
302                 igp.lyxscale = 100;
303         }
304
305         switch (fl_get_choice(file_->choice_display)) {
306         case 5:
307                 igp.display = lyx::graphics::NoDisplay;
308                 break;
309         case 4:
310                 igp.display = lyx::graphics::ColorDisplay;
311                 break;
312         case 3:
313                 igp.display = lyx::graphics::GrayscaleDisplay;
314                 break;
315         case 2:
316                 igp.display = lyx::graphics::MonochromeDisplay;
317                 break;
318         case 1:
319                 igp.display = lyx::graphics::DefaultDisplay;
320         }
321
322         // first item in choice_width means scaling
323         if (fl_get_choice(file_->choice_width) == 1) {
324                 igp.scale = strToDbl(getString(file_->input_width));
325                 if (float_equal(igp.scale, 0.0, 0.05)) {
326                         igp.scale = 100.0;
327                 }
328                 igp.width = LyXLength();
329         } else {
330                 igp.scale = 0.0;
331                 igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
332                                                            file_->choice_width));
333         }
334         igp.height = LyXLength(getLengthFromWidgets(file_->input_height,
335                                                     file_->choice_height));
336         igp.keepAspectRatio = fl_get_button(file_->check_aspectratio);
337
338         igp.draft = fl_get_button(file_->check_draft);
339         igp.noUnzip = fl_get_button(file_->check_nounzip);
340
341         // the bb section
342         if (!controller().bbChanged) {
343                 // don't write anything
344                 igp.bb.erase();
345         } else {
346                 // allow length + unit input only for x1 input field
347                 string x1_str = "0";
348                 if (!getString(bbox_->input_bb_x1).empty()) {
349                         x1_str = getLengthFromWidgets(bbox_->input_bb_x1,
350                                                       bbox_->choice_bb_units);
351                         LyXLength x1 = LyXLength(x1_str);
352                         x1_str = x1.asString();
353
354                         string unit;
355                         switch (x1.unit()) {
356                         case LyXLength::IN:
357                                 unit = "in";
358                                 break;
359                         case LyXLength::MM:
360                                 unit = "mm";
361                                 break;
362                         case LyXLength::CM:
363                                 unit = "cm";
364                                 break;
365                         case LyXLength::BP:
366                         default:
367                                 unit = "bp";
368                         }
369                         fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
370                 }
371
372                 string bb;
373                 if (getString(bbox_->input_bb_x0).empty())
374                         bb = "0";
375                 else
376                         bb = getLengthFromWidgets(bbox_->input_bb_x0,
377                                                   bbox_->choice_bb_units);
378
379                 bb += ' ';
380
381                 if (getString(bbox_->input_bb_y0).empty())
382                         bb += '0';
383                 else
384                         bb += getLengthFromWidgets(bbox_->input_bb_y0,
385                                                   bbox_->choice_bb_units);
386
387                 bb += ' ' + x1_str + ' ';
388
389                 if (getString(bbox_->input_bb_y1).empty())
390                         bb += '0';
391                 else
392                         bb += getLengthFromWidgets(bbox_->input_bb_y1,
393                                                    bbox_->choice_bb_units);
394
395                 igp.bb = bb;
396         }
397         igp.clip = fl_get_button(bbox_->check_clip);
398
399         // the extra section
400         igp.rotateAngle = strToDbl(getString(extra_->input_rotate_angle));
401
402         // map angle into -360 (clock-wise) to +360 (counter clock-wise)
403         while (igp.rotateAngle <= -360.0) {
404                 igp.rotateAngle += 360.0;
405         }
406         while (igp.rotateAngle >=  360.0) {
407                 igp.rotateAngle -= 360.0;
408         }
409         fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
410
411         int const origin_pos = fl_get_choice(extra_->choice_origin);
412         if (origin_pos == 0) {
413                 igp.rotateOrigin.erase();
414         } else {
415                 igp.rotateOrigin = origins_[origin_pos - 1];
416         }
417
418         igp.subcaption = fl_get_button(extra_->check_subcaption);
419         igp.subcaptionText = getString(extra_->input_subcaption);
420
421         igp.special = getString(extra_->input_special);
422 }
423
424
425 void FormGraphics::update() {
426         // Update dialog with details from inset
427         InsetGraphicsParams & igp = controller().params();
428
429         // the file section
430         string const name =
431                 igp.filename.outputFilename(kernel().bufferFilepath());
432         fl_set_input(file_->input_filename, name.c_str());
433         fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());
434
435         switch (igp.display) {
436         case lyx::graphics::NoDisplay:
437                 fl_set_choice(file_->choice_display, 5);
438                 break;
439         case lyx::graphics::ColorDisplay:
440                 fl_set_choice(file_->choice_display, 4);
441                 break;
442         case lyx::graphics::GrayscaleDisplay:
443                 fl_set_choice(file_->choice_display, 3);
444                 break;
445         case lyx::graphics::MonochromeDisplay:
446                 fl_set_choice(file_->choice_display, 2);
447                 break;
448         case lyx::graphics::DefaultDisplay:
449                 fl_set_choice(file_->choice_display, 1);
450         }
451
452         // set width input fields according to scaling or width/height input
453         if (!float_equal(igp.scale, 0.0, 0.05)) {
454                 fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
455                 fl_set_input_maxchars(file_->input_width, 0);
456                 fl_set_input(file_->input_width, tostr(igp.scale).c_str());
457                 fl_set_choice(file_->choice_width, 1);
458         } else {
459                 fl_set_input_filter(file_->input_width, NULL);
460                 fl_set_input_maxchars(file_->input_width, SIZE_MAXDIGITS);
461                 updateWidgetsFromLength(file_->input_width, file_->choice_width,
462                                         igp.width, defaultUnit);
463         }
464
465         updateWidgetsFromLength(file_->input_height, file_->choice_height,
466                                 igp.height, defaultUnit);
467
468         // disable height input in case of scaling
469         bool const disable_height = !float_equal(igp.scale, 0.0, 0.05);
470         setEnabled(file_->input_height, !disable_height);
471         setEnabled(file_->choice_height, !disable_height);
472
473         fl_set_button(file_->check_aspectratio, igp.keepAspectRatio);
474         fl_set_button(file_->check_draft, igp.draft);
475         fl_set_button(file_->check_nounzip, igp.noUnzip);
476
477         // disable aspectratio button in case of scaling or one of width/height
478         // is empty
479         bool const disable_aspectRatio = disable_height ||
480                                 getString(file_->input_width).empty() ||
481                                 getString(file_->input_height).empty();
482         setEnabled(file_->check_aspectratio, !disable_aspectRatio);
483
484         // the bb section
485         // set the bounding box values, if exists. First we need the whole
486         // path, because the controller knows nothing about the doc-dir
487         updateBB(igp.filename.absFilename(), igp.bb);
488         fl_set_button(bbox_->check_clip, igp.clip);
489
490         // the extra section
491         fl_set_input(extra_->input_rotate_angle,
492                      tostr(igp.rotateAngle).c_str());
493
494         int origin_pos;
495         if (igp.rotateOrigin.empty()) {
496                 origin_pos = 1;
497         } else {
498                 origin_pos = 1 + findPos(origins_, igp.rotateOrigin);
499         }
500         fl_set_choice(extra_->choice_origin, origin_pos);
501
502         fl_set_button(extra_->check_subcaption, igp.subcaption);
503         fl_set_input(extra_->input_subcaption, igp.subcaptionText.c_str());
504         setEnabled(extra_->input_subcaption,
505                    fl_get_button(extra_->check_subcaption));
506         fl_set_input(extra_->input_special, igp.special.c_str());
507
508         // open dialog in the file-tab, whenever filename is empty
509         if (igp.filename.empty()) {
510                 fl_set_folder(dialog_->tabfolder, file_->form);
511         }
512 }
513
514
515 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
516 {
517         // Update dialog with details from inset
518         // set the bounding box values, if exists. First we need the whole
519         // path, because the controller knows nothing about the doc-dir
520         controller().bbChanged = false;
521         if (bb_inset.empty()) {
522                 lyxerr[Debug::GRAPHICS]
523                         << "FormGraphics::updateBB() [no BoundingBox]" << endl;
524                 string const bb = controller().readBB(filename);
525                 if (!bb.empty()) {
526                         // get the values from the file
527                         // in this case we always have the point-unit
528                         fl_set_input(bbox_->input_bb_x0,
529                                      token(bb,' ',0).c_str());
530                         fl_set_input(bbox_->input_bb_y0,
531                                      token(bb,' ',1).c_str());
532                         fl_set_input(bbox_->input_bb_x1,
533                                      token(bb,' ',2).c_str());
534                         fl_set_input(bbox_->input_bb_y1,
535                                      token(bb,' ',3).c_str());
536
537                 } else {
538                         // no bb from file
539                         fl_set_input(bbox_->input_bb_x0, bb.c_str());
540                         fl_set_input(bbox_->input_bb_y0, bb.c_str());
541                         fl_set_input(bbox_->input_bb_x1, bb.c_str());
542                         fl_set_input(bbox_->input_bb_y1, bb.c_str());
543                 }
544                 // "bp"
545                 fl_set_choice(bbox_->choice_bb_units, 1);
546
547         } else {
548                 // get the values from the inset
549                 lyxerr[Debug::GRAPHICS]
550                         << "FormGraphics::updateBB(): igp has BoundingBox"
551                         << " ["<< bb_inset << "]" << endl;
552                 controller().bbChanged = true;
553
554                 LyXLength anyLength;
555                 anyLength = LyXLength(token(bb_inset,' ',0));
556                 updateWidgetsFromLength(bbox_->input_bb_x0,
557                                         bbox_->choice_bb_units,anyLength,"bp");
558                 anyLength = LyXLength(token(bb_inset,' ',1));
559                 updateWidgetsFromLength(bbox_->input_bb_y0,
560                                         bbox_->choice_bb_units,anyLength,"bp");
561                 anyLength = LyXLength(token(bb_inset,' ',2));
562                 updateWidgetsFromLength(bbox_->input_bb_x1,
563                                         bbox_->choice_bb_units,anyLength,"bp");
564                 anyLength = LyXLength(token(bb_inset,' ',3));
565                 updateWidgetsFromLength(bbox_->input_bb_y1,
566                                         bbox_->choice_bb_units,anyLength,"bp");
567         }
568 }
569
570
571 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
572 {
573         // the file section
574         if (ob == file_->button_browse) {
575                 // Get the filename from the dialog
576                 string const in_name = getString(file_->input_filename);
577                 string const out_name = controller().Browse(in_name);
578                 lyxerr[Debug::GRAPHICS]
579                         << "[FormGraphics]out_name: " << out_name << endl;
580                 if (out_name != in_name && !out_name.empty()) {
581                         fl_set_input(file_->input_filename, out_name.c_str());
582                 }
583                 if (controller().isFilenameValid(out_name) &&
584                     !controller().bbChanged) {
585                         updateBB(out_name, string());
586                 }
587         } else if (ob == file_->input_width || ob == file_->input_height) {
588                 // disable aspectratio button in case of scaling or one of
589                 // width/height is empty
590                 bool const disable = fl_get_choice(file_->choice_width) == 1 ||
591                                     getString(file_->input_width).empty() ||
592                                     getString(file_->input_height).empty();
593                 setEnabled(file_->check_aspectratio, !disable);
594         } else if (ob == file_->choice_width) {
595                 // disable height input in case of scaling
596                 bool const scaling = fl_get_choice(file_->choice_width) == 1;
597                 setEnabled(file_->input_height, !scaling);
598                 setEnabled(file_->choice_height, !scaling);
599
600                 // allow only integer intput for scaling; float otherwise
601                 if (scaling) {
602                         fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
603                         fl_set_input_maxchars(file_->input_width, 0);
604                 } else {
605                         fl_set_input_filter(file_->input_width, NULL);
606                         fl_set_input_maxchars(file_->input_width, SIZE_MAXDIGITS);
607                 }
608
609                 // disable aspectratio button in case of scaling or height
610                 // input is empty
611                 bool const disable_aspectratio =
612                         scaling || getString(file_->input_height).empty();
613                 setEnabled(file_->check_aspectratio, !disable_aspectratio);
614         // the bb section
615         } else if (!controller().bbChanged &&
616                    (ob == bbox_->check_clip  || ob == bbox_->choice_bb_units ||
617                     ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
618                     ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
619                 controller().bbChanged = true;
620         } else if (ob == bbox_->button_getBB) {
621                 string const filename = getString(file_->input_filename);
622                 if (!filename.empty()) {
623                         string bb = controller().readBB(filename);
624                         if (!bb.empty()) {
625                                 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
626                                 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
627                                 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
628                                 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
629                                 fl_set_choice_text(bbox_->choice_bb_units, "bp");
630                         }
631                         controller().bbChanged = false;
632                 } else {
633                         fl_set_input(bbox_->input_bb_x0, "");
634                         fl_set_input(bbox_->input_bb_y0, "");
635                         fl_set_input(bbox_->input_bb_x1, "");
636                         fl_set_input(bbox_->input_bb_y1, "");
637                         fl_set_choice_text(bbox_->choice_bb_units, "bp");
638                 }
639         // the extra section
640         } else if (ob == extra_->check_subcaption) {
641                 setEnabled(extra_->input_subcaption,
642                            fl_get_button(extra_->check_subcaption));
643
644         }
645
646         return ButtonPolicy::SMI_VALID;
647 }