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