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