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