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