]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormGraphics.C
38866c2af45afe07bd97621f87f08817541a05c1
[lyx.git] / src / frontends / xforms / FormGraphics.C
1 /**
2  * \file FormGraphics.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Baruch Even, baruch.even@writeme.com
7  * \author Herbert Voss, voss@perce.de
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "xformsBC.h"
17 #include "ControlGraphics.h"
18 #include "FormGraphics.h"
19 #include "form_graphics.h"
20 #include "Alert.h"
21
22 #include "xforms_helpers.h"
23 #include "input_validators.h"
24 #include "debug.h" // for lyxerr
25 #include "support/lstrings.h"  // for strToDbl & tostr
26 #include "support/filetools.h"  // for MakeAbsPath etc
27 #include "insets/insetgraphicsParams.h"
28 #include "lyxrc.h" // for lyxrc.display_graphics
29
30 using std::endl;
31
32 namespace {
33
34 // Bound the number of input characters
35 int const SCALE_MAXDIGITS = 3;
36 int const WIDTH_MAXDIGITS = 10;
37 int const HEIGHT_MAXDIGITS = 10;
38 int const ROTATE_MAXCHARS = 4;
39 int const FILENAME_MAXCHARS = 1024;
40 string defaultUnit("cm");
41
42 /// Given input and choice widgets, create a LyXLength
43 LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
44 {
45         return LyXLength(getLengthFromWidgets(input, choice));
46 }
47
48 } // namespace anon
49
50
51 typedef FormCB<ControlGraphics, FormDB<FD_form_graphics> > base_class;
52
53 FormGraphics::FormGraphics(ControlGraphics & c)
54         : base_class(c, _("Graphics"), false)
55 {}
56
57
58 void FormGraphics::redraw()
59 {
60         if (form() && form()->visible)
61                 fl_redraw_form(form());
62         else
63                 return;
64         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
65         if (outer_form && outer_form->visible)
66                 fl_redraw_form(outer_form);
67 }
68
69
70 void FormGraphics::build()
71 {
72         dialog_.reset(build_graphics());
73
74         // Allow the base class to control messages
75         setMessageWidget(dialog_->text_warning);
76
77         // Manage the ok, apply, restore and cancel/close buttons
78         bc().setOK(dialog_->button_ok);
79         bc().setApply(dialog_->button_apply);
80         bc().setCancel(dialog_->button_close);
81         bc().setRestore(dialog_->button_restore);
82
83         // the file section
84         file_.reset(build_file());
85
86         fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
87         fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
88         fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
89         fl_set_input_maxchars(file_->input_filename,  FILENAME_MAXCHARS);
90         fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
91         fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
92
93         setPrehandler(file_->input_filename);
94         setPrehandler(file_->input_subcaption);
95         setPrehandler(file_->input_rotate_angle);
96
97         string const choice_origin =
98                 "center|"                                       // c
99                 "leftTop|leftBottom|leftBaseline|"              // lt lb lB
100                 "centerTop|centerBottom|centerBaseline|"        // ct cb cB
101                 "rightTop|rightBottom|rightBaseline";   // rt rb rB
102         fl_addto_choice(file_->choice_origin, choice_origin.c_str());
103
104         bc().addReadOnly(file_->button_browse);
105         bc().addReadOnly(file_->check_subcaption);
106         bc().addReadOnly(file_->check_rotate);
107         bc().addReadOnly(file_->check_draft);
108         bc().addReadOnly(file_->check_nounzip);
109
110         // the lyxview section
111         lyxview_.reset(build_lyxview());
112
113         fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
114         fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
115         fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
116
117         setPrehandler(lyxview_->input_lyxwidth);
118         setPrehandler(lyxview_->input_lyxheight);
119         setPrehandler(lyxview_->input_lyxscale);
120
121         fl_addto_choice(lyxview_->choice_lyxwidth, choice_Length_WithUnit.c_str());
122         fl_addto_choice(lyxview_->choice_lyxheight, choice_Length_WithUnit.c_str());
123
124         bc().addReadOnly(lyxview_->radio_pref);
125         bc().addReadOnly(lyxview_->radio_mono);
126         bc().addReadOnly(lyxview_->radio_gray);
127         bc().addReadOnly(lyxview_->radio_color);
128         bc().addReadOnly(lyxview_->radio_nodisplay);
129
130         // the size section
131         size_.reset(build_size());
132
133         fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
134         fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
135         fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
136
137         setPrehandler(size_->input_scale);
138         setPrehandler(size_->input_width);
139         setPrehandler(size_->input_height);
140
141         fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
142         fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
143         fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
144
145         fl_set_input_filter(size_->input_scale,  fl_unsigned_float_filter);
146
147         fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
148         fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
149
150         bc().addReadOnly(size_->radio_asis);
151         bc().addReadOnly(size_->radio_wh);
152         bc().addReadOnly(size_->radio_scale);
153         bc().addReadOnly(size_->check_aspectratio);
154
155         // the bounding box selection
156         bbox_.reset(build_bbox());
157         fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
158         fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
159         fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
160         fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
161
162         fl_set_input_filter(bbox_->input_bb_x0,  fl_unsigned_float_filter);
163         fl_set_input_filter(bbox_->input_bb_y0,  fl_unsigned_float_filter);
164         fl_set_input_filter(bbox_->input_bb_x1,  fl_unsigned_float_filter);
165         fl_set_input_filter(bbox_->input_bb_y1,  fl_unsigned_float_filter);
166
167         setPrehandler(bbox_->input_bb_x0);
168         setPrehandler(bbox_->input_bb_y0);
169         setPrehandler(bbox_->input_bb_x1);
170         setPrehandler(bbox_->input_bb_y1);
171
172         string const bb_units = "bp|cm|in";
173         fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
174         bc().addReadOnly(bbox_->button_getBB);
175         bc().addReadOnly(bbox_->check_clip);
176
177         // the rotate section
178         special_.reset(build_special());
179
180         fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
181         setPrehandler(special_->input_special);
182
183         // add the different tabfolders
184         fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
185         fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
186         fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
187         fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
188         fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
189         // set the right default unit
190         if (lyxrc.default_papersize < 3)
191                 defaultUnit = "in";
192 }
193
194
195 void FormGraphics::apply()
196 {
197         // Create the parameters structure and fill the data from the dialog.
198         InsetGraphicsParams & igp = controller().params();
199
200         // the file section
201         igp.filename = getStringFromInput(file_->input_filename);
202         igp.subcaption = fl_get_button(file_->check_subcaption);
203         igp.subcaptionText = getStringFromInput(file_->input_subcaption);
204         igp.rotate = fl_get_button(file_->check_rotate);
205         igp.rotateAngle =
206                 strToDbl(getStringFromInput(file_->input_rotate_angle));
207         while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
208                 if (igp.rotateAngle < 0.0) {
209                         igp.rotateAngle += 360.0;
210                 } else if (igp.rotateAngle > 360.0) {
211                         igp.rotateAngle -= 360.0;
212                 }
213         }
214         if (fl_get_choice(file_->choice_origin) > 0)
215                 igp.rotateOrigin = fl_get_choice_text(file_->choice_origin);
216         else
217                 igp.rotateOrigin = string();
218         igp.draft = fl_get_button(file_->check_draft);
219         igp.noUnzip = fl_get_button(file_->check_nounzip);
220
221         // the lyxview section
222         if (fl_get_button(lyxview_->radio_pref))
223                 igp.display = InsetGraphicsParams::DEFAULT;
224         else if (fl_get_button(lyxview_->radio_mono))
225                 igp.display = InsetGraphicsParams::MONOCHROME;
226         else if (fl_get_button(lyxview_->radio_gray))
227                 igp.display = InsetGraphicsParams::GRAYSCALE;
228         else if (fl_get_button(lyxview_->radio_color))
229                 igp.display = InsetGraphicsParams::COLOR;
230         else if (fl_get_button(lyxview_->radio_nodisplay))
231                 igp.display = InsetGraphicsParams::NONE;
232
233         if (fl_get_button(lyxview_->radio_lyxasis))
234                 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
235         else if (fl_get_button(lyxview_->radio_lyxwh))
236                 igp.lyxsize_type = InsetGraphicsParams::WH;
237         else
238                 igp.lyxsize_type = InsetGraphicsParams::SCALE;
239
240         igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
241                                                lyxview_->choice_lyxwidth);
242
243         igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
244                                                 lyxview_->choice_lyxheight);
245
246         igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
247
248         // the size section
249         if (fl_get_button(size_->radio_asis))
250                 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
251         else if (fl_get_button(size_->radio_wh))
252                 igp.size_type = InsetGraphicsParams::WH;
253         else
254                 igp.size_type = InsetGraphicsParams::SCALE;
255
256         igp.width = getLyXLengthFromWidgets(size_->input_width,
257                                             size_->choice_width);
258
259         igp.height = getLyXLengthFromWidgets(size_->input_height,
260                                    size_->choice_height);
261
262         igp.scale = strToInt(getStringFromInput(size_->input_scale));
263         igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
264
265         // the bb section
266         if (!controller().bbChanged)            // different to the original one?
267                 igp.bb = string();                      // don't write anything
268         else {
269                 string bb;
270                 if (getStringFromInput(bbox_->input_bb_x0).empty())
271                         bb = "0 ";
272                 else
273                         bb = getLengthFromWidgets(bbox_->input_bb_x0,
274                                                   bbox_->choice_bb_units)+" ";
275                 if (getStringFromInput(bbox_->input_bb_y0).empty())
276                         bb += "0 ";
277                 else
278                         bb += (getLengthFromWidgets(bbox_->input_bb_y0,
279                                                     bbox_->choice_bb_units)+" ");
280                 if (getStringFromInput(bbox_->input_bb_x1).empty())
281                         bb += "0 ";
282                 else
283                         bb += (getLengthFromWidgets(bbox_->input_bb_x1,
284                                                     bbox_->choice_bb_units)+" ");
285                 if (getStringFromInput(bbox_->input_bb_y1).empty())
286                         bb += "0 ";
287                 else
288                         bb += (getLengthFromWidgets(bbox_->input_bb_y1,
289                                                     bbox_->choice_bb_units)+" ");
290                 igp.bb = bb;
291         }
292         igp.clip = fl_get_button(bbox_->check_clip);
293
294         // the special section
295         igp.special = getStringFromInput(special_->input_special);
296 }
297
298
299
300 void FormGraphics::update() {
301         // Update dialog with details from inset
302         InsetGraphicsParams & igp = controller().params();
303
304         // the file section
305         fl_set_input(file_->input_filename, igp.filename.c_str());
306         fl_set_button(file_->check_subcaption, igp.subcaption);
307         fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
308         setEnabled(file_->input_subcaption,
309                    fl_get_button(file_->check_subcaption));
310         fl_set_button(file_->check_rotate, igp.rotate);
311         fl_set_input(file_->input_rotate_angle,
312                      tostr(igp.rotateAngle).c_str());
313         if (igp.rotateOrigin.empty())
314                 fl_set_choice(file_->choice_origin,1);
315         else
316                 fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str());
317         setEnabled(file_->input_rotate_angle,
318                    fl_get_button(file_->check_rotate));
319         setEnabled(file_->choice_origin,
320                    fl_get_button(file_->check_rotate));
321         fl_set_button(file_->check_draft, igp.draft);
322         fl_set_button(file_->check_nounzip, igp.noUnzip);
323
324         // the lyxview section
325         switch (igp.display) {
326         case InsetGraphicsParams::DEFAULT:
327                 fl_set_button(lyxview_->radio_pref, 1);
328                 break;
329         case InsetGraphicsParams::MONOCHROME:
330                 fl_set_button(lyxview_->radio_mono, 1);
331                 break;
332         case InsetGraphicsParams::GRAYSCALE:
333                 fl_set_button(lyxview_->radio_gray, 1);
334                 break;
335         case InsetGraphicsParams::COLOR:
336                 fl_set_button(lyxview_->radio_color, 1);
337                 break;
338         case InsetGraphicsParams::NONE:
339                 fl_set_button(lyxview_->radio_nodisplay, 1);
340                 break;
341         }
342         updateWidgetsFromLength(lyxview_->input_lyxwidth,
343                                 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
344         updateWidgetsFromLength(lyxview_->input_lyxheight,
345                                 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
346         fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
347         switch (igp.lyxsize_type) {
348         case InsetGraphicsParams::DEFAULT_SIZE: {
349                 fl_set_button(lyxview_->radio_lyxasis,1);
350                 setEnabled(lyxview_->input_lyxwidth, 0);
351                 setEnabled(lyxview_->choice_lyxwidth, 0);
352                 setEnabled(lyxview_->input_lyxheight, 0);
353                 setEnabled(lyxview_->choice_lyxheight, 0);
354                 setEnabled(lyxview_->input_lyxscale, 0);
355                 break;
356         }
357         case InsetGraphicsParams::WH: {
358                 fl_set_button(lyxview_->radio_lyxwh, 1);
359                 setEnabled(lyxview_->input_lyxwidth, 1);
360                 setEnabled(lyxview_->choice_lyxwidth, 1);
361                 setEnabled(lyxview_->input_lyxheight, 1);
362                 setEnabled(lyxview_->choice_lyxheight, 1);
363                 setEnabled(lyxview_->input_lyxscale, 0);
364                 break;
365         }
366         case InsetGraphicsParams::SCALE: {
367                 fl_set_button(lyxview_->radio_lyxscale, 1);
368                 setEnabled(lyxview_->input_lyxwidth, 0);
369                 setEnabled(lyxview_->choice_lyxwidth, 0);
370                 setEnabled(lyxview_->input_lyxheight, 0);
371                 setEnabled(lyxview_->choice_lyxheight, 0);
372                 setEnabled(lyxview_->input_lyxscale, 1);
373                 break;
374         }
375         }
376
377         // the size section
378         // Update the draft and clip mode
379         updateWidgetsFromLength(size_->input_width,
380                                 size_->choice_width, igp.width, defaultUnit);
381         updateWidgetsFromLength(size_->input_height,
382                                 size_->choice_height, igp.height, defaultUnit);
383         fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
384         switch (igp.size_type) {
385         case InsetGraphicsParams::DEFAULT_SIZE: {
386                 fl_set_button(size_->radio_asis,1);
387                 setEnabled(size_->input_width, 0);
388                 setEnabled(size_->choice_width, 0);
389                 setEnabled(size_->input_height, 0);
390                 setEnabled(size_->choice_height, 0);
391                 setEnabled(size_->check_aspectratio, 0);
392                 setEnabled(size_->input_scale, 0);
393                 break;
394         }
395         case InsetGraphicsParams::WH: {
396                 fl_set_button(size_->radio_wh, 1);
397                 setEnabled(size_->input_width, 1);
398                 setEnabled(size_->choice_width, 1);
399                 setEnabled(size_->input_height, 1);
400                 setEnabled(size_->choice_height, 1);
401                 setEnabled(size_->check_aspectratio, 1);
402                 setEnabled(size_->input_scale, 0);
403                 break;
404         }
405         case InsetGraphicsParams::SCALE: {
406                 fl_set_button(size_->radio_scale, 1);
407                 setEnabled(size_->input_width, 0);
408                 setEnabled(size_->choice_width, 0);
409                 setEnabled(size_->input_height, 0);
410                 setEnabled(size_->choice_height, 0);
411                 setEnabled(size_->check_aspectratio, 0);
412                 setEnabled(size_->input_scale, 1);
413                 break;
414         }
415         }
416         fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
417
418         // the bb section
419         // set the bounding box values, if exists. First we need the whole
420         // path, because the controller knows nothing about the doc-dir
421         updateBB(igp.filename, igp.bb);
422         fl_set_button(bbox_->check_clip, igp.clip);
423
424         // the special section
425         fl_set_input(special_->input_special, igp.special.c_str());
426 }
427
428
429 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
430 {
431         // Update dialog with details from inset
432         // set the bounding box values, if exists. First we need the whole
433         // path, because the controller knows nothing about the doc-dir
434         controller().bbChanged = false;
435         if (bb_inset.empty()) {
436                 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
437                 string const bb = controller().readBB(filename);
438                 if (!bb.empty()) {
439                         // get the values from the file
440                         // in this case we always have the point-unit
441                         fl_set_input(bbox_->input_bb_x0,
442                                      token(bb,' ',0).c_str());
443                         fl_set_input(bbox_->input_bb_y0,
444                                      token(bb,' ',1).c_str());
445                         fl_set_input(bbox_->input_bb_x1,
446                                      token(bb,' ',2).c_str());
447                         fl_set_input(bbox_->input_bb_y1,
448                                      token(bb,' ',3).c_str());
449
450                 } else {
451                         // no bb from file
452                         fl_set_input(bbox_->input_bb_x0, bb.c_str());
453                         fl_set_input(bbox_->input_bb_y0, bb.c_str());
454                         fl_set_input(bbox_->input_bb_x1, bb.c_str());
455                         fl_set_input(bbox_->input_bb_y1, bb.c_str());
456                 }
457                 // "bp"
458                 fl_set_choice(bbox_->choice_bb_units, 1);
459
460         } else {
461                 // get the values from the inset
462                 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
463                                         << endl;
464                 controller().bbChanged = true;
465                 LyXLength anyLength;
466                 anyLength = LyXLength(token(bb_inset,' ',0));
467                 updateWidgetsFromLength(bbox_->input_bb_x0,
468                                         bbox_->choice_bb_units,anyLength,"bp");
469                 anyLength = LyXLength(token(bb_inset,' ',1));
470                 updateWidgetsFromLength(bbox_->input_bb_y0,
471                                         bbox_->choice_bb_units,anyLength,"bp");
472                 anyLength = LyXLength(token(bb_inset,' ',2));
473                 updateWidgetsFromLength(bbox_->input_bb_x1,
474                                         bbox_->choice_bb_units,anyLength,"bp");
475                 anyLength = LyXLength(token(bb_inset,' ',3));
476                 updateWidgetsFromLength(bbox_->input_bb_y1,
477                                         bbox_->choice_bb_units,anyLength,"bp");
478         }
479 }
480
481 namespace {
482
483 bool isValid(FL_OBJECT * ob)
484 {
485         string const input = getStringFromInput(ob);
486         return input.empty() || isValidLength(input) || isStrDbl(input);
487 }
488
489 } // namespace anon
490
491
492
493 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
494 {
495         // the file section
496         if (ob == file_->button_browse) {
497                 // Get the filename from the dialog
498                 string const in_name = getStringFromInput(file_->input_filename);
499                 string const out_name = controller().Browse(in_name);
500                 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
501                 if (out_name != in_name && !out_name.empty()) {
502                         fl_set_input(file_->input_filename, out_name.c_str());
503                 }
504                 if (controller().isFilenameValid(out_name))
505                         updateBB(out_name, string());
506
507         } else if (ob == file_->check_subcaption) {
508                 setEnabled(file_->input_subcaption,
509                            fl_get_button(file_->check_subcaption));
510         } else if (ob == file_->check_rotate) {
511                 setEnabled(file_->input_rotate_angle,
512                            fl_get_button(file_->check_rotate));
513                 setEnabled(file_->choice_origin,
514                            fl_get_button(file_->check_rotate));
515
516                 // the lyxview section
517         } else if (ob == lyxview_->radio_lyxasis) {
518                 setEnabled(lyxview_->input_lyxwidth, 0);
519                 setEnabled(lyxview_->choice_lyxwidth, 0);
520                 setEnabled(lyxview_->input_lyxheight, 0);
521                 setEnabled(lyxview_->choice_lyxheight, 0);
522                 setEnabled(lyxview_->input_lyxscale, 0);
523         } else if (ob == lyxview_->radio_lyxwh) {
524                 setEnabled(lyxview_->input_lyxwidth, 1);
525                 setEnabled(lyxview_->choice_lyxwidth, 1);
526                 setEnabled(lyxview_->input_lyxheight, 1);
527                 setEnabled(lyxview_->choice_lyxheight, 1);
528                 setEnabled(lyxview_->input_lyxscale, 0);
529         } else if (ob == lyxview_->radio_lyxscale) {
530                 setEnabled(lyxview_->input_lyxwidth, 0);
531                 setEnabled(lyxview_->choice_lyxwidth, 0);
532                 setEnabled(lyxview_->input_lyxheight, 0);
533                 setEnabled(lyxview_->choice_lyxheight, 0);
534                 setEnabled(lyxview_->input_lyxscale, 1);
535         } else if (ob == lyxview_->button_latex_values) {
536                 if (contains(fl_get_choice_text(size_->choice_width),'%'))
537                         Alert::alert(_("Warning!"),
538                                      _("The units text%, page%, col% and line% are not allowed here."),
539                                      _("Cannot use the values from LaTeX size!"));
540                 else {
541                         LyXLength dummy =
542                                 getLyXLengthFromWidgets(size_->input_width,
543                                                         size_->choice_width);
544                         updateWidgetsFromLength(lyxview_->input_lyxwidth,
545                                                 lyxview_->choice_lyxwidth,
546                                                 dummy, defaultUnit);
547
548                         dummy = getLyXLengthFromWidgets(size_->input_height,
549                                                         size_->choice_height);
550                         updateWidgetsFromLength(lyxview_->input_lyxheight,
551                                                 lyxview_->choice_lyxheight,
552                                                 dummy, defaultUnit);
553                         string const scale = getStringFromInput(size_->input_scale);
554                         fl_set_input(lyxview_->input_lyxscale, scale.c_str());
555                         if (fl_get_button (size_->radio_asis) == 1) {
556                                 fl_set_button (lyxview_->radio_lyxasis, 1);
557                                 setEnabled(lyxview_->input_lyxwidth, 0);
558                                 setEnabled(lyxview_->choice_lyxwidth, 0);
559                                 setEnabled(lyxview_->input_lyxheight, 0);
560                                 setEnabled(lyxview_->choice_lyxheight, 0);
561                                 setEnabled(lyxview_->input_lyxscale, 0);
562                         } else if (fl_get_button (size_->radio_wh) == 1) {
563                                 fl_set_button (lyxview_->radio_lyxwh, 1);
564                                 setEnabled(lyxview_->input_lyxwidth, 1);
565                                 setEnabled(lyxview_->choice_lyxwidth, 1);
566                                 setEnabled(lyxview_->input_lyxheight, 1);
567                                 setEnabled(lyxview_->choice_lyxheight, 1);
568                                 setEnabled(lyxview_->input_lyxscale, 0);
569                         } else if (fl_get_button (size_->radio_scale) ==1) {
570                                 fl_set_button (lyxview_->radio_lyxscale, 1);
571                                 setEnabled(lyxview_->input_lyxwidth, 0);
572                                 setEnabled(lyxview_->choice_lyxwidth, 0);
573                                 setEnabled(lyxview_->input_lyxheight, 0);
574                                 setEnabled(lyxview_->choice_lyxheight, 0);
575                                 setEnabled(lyxview_->input_lyxscale, 1);
576                         }
577                 }
578
579                 // the bb section
580         } else if (!controller().bbChanged &&
581                    (ob == bbox_->check_clip  || ob == bbox_->choice_bb_units ||
582                     ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
583                     ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
584                 controller().bbChanged = true;
585         } else if (ob == bbox_->button_getBB) {
586                 string const filename = getStringFromInput(file_->input_filename);
587                 if (!filename.empty()) {
588                         string bb = controller().readBB(filename);
589                         if (!bb.empty()) {
590                                 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
591                                 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
592                                 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
593                                 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
594                                 string const unit("bp");
595                                 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
596                         }
597                         controller().bbChanged = false;
598                 } else {
599                         fl_set_input(bbox_->input_bb_x0, "");
600                         fl_set_input(bbox_->input_bb_y0, "");
601                         fl_set_input(bbox_->input_bb_x1, "");
602                         fl_set_input(bbox_->input_bb_y1, "");
603                         fl_set_choice_text(bbox_->choice_bb_units, "bp");
604                 }
605
606                 // the size section
607         } else if (ob == size_->radio_asis) {
608                 setEnabled(size_->input_width, 0);
609                 setEnabled(size_->choice_width, 0);
610                 setEnabled(size_->input_height, 0);
611                 setEnabled(size_->choice_height, 0);
612                 setEnabled(size_->check_aspectratio, 0);
613                 setEnabled(size_->input_scale, 0);
614         } else if (ob == size_->radio_wh) {
615                 setEnabled(size_->input_width, 1);
616                 setEnabled(size_->choice_width, 1);
617                 setEnabled(size_->input_height, 1);
618                 setEnabled(size_->choice_height, 1);
619                 setEnabled(size_->check_aspectratio, 1);
620                 setEnabled(size_->input_scale, 0);
621         } else if (ob == size_->radio_scale) {
622                 setEnabled(size_->input_width, 0);
623                 setEnabled(size_->choice_width, 0);
624                 setEnabled(size_->input_height, 0);
625                 setEnabled(size_->choice_height, 0);
626                 setEnabled(size_->check_aspectratio, 0);
627                 setEnabled(size_->input_scale, 1);
628         } else if (ob == size_->button_lyx_values) {
629                 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
630                                                           lyxview_->choice_lyxwidth);
631                 updateWidgetsFromLength(size_->input_width,
632                                         size_->choice_width,
633                                         dummy, defaultUnit);
634                 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
635                                                 lyxview_->choice_lyxheight);
636                 updateWidgetsFromLength(size_->input_height,
637                                         size_->choice_height,
638                                         dummy, defaultUnit);
639                 string const scale = getStringFromInput(lyxview_->input_lyxscale);
640                 fl_set_input(size_->input_scale, scale.c_str());
641                 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
642                         fl_set_button (size_->radio_asis, 1);
643                         setEnabled(size_->input_width, 0);
644                         setEnabled(size_->choice_width, 0);
645                         setEnabled(size_->input_height, 0);
646                         setEnabled(size_->choice_height, 0);
647                         setEnabled(size_->check_aspectratio, 0);
648                         setEnabled(size_->input_scale, 0);
649                 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
650                         fl_set_button (size_->radio_wh, 1);
651                         setEnabled(size_->input_width, 1);
652                         setEnabled(size_->choice_width, 1);
653                         setEnabled(size_->input_height, 1);
654                         setEnabled(size_->choice_height, 1);
655                         setEnabled(size_->check_aspectratio, 1);
656                         setEnabled(size_->input_scale, 0);
657                 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
658                         fl_set_button (size_->radio_scale, 1);
659                         setEnabled(size_->input_width, 0);
660                         setEnabled(size_->choice_width, 0);
661                         setEnabled(size_->input_height, 0);
662                         setEnabled(size_->choice_height, 0);
663                         setEnabled(size_->check_aspectratio, 0);
664                         setEnabled(size_->input_scale, 1);
665                 }
666         }
667
668         // check if the input is valid
669         bool invalid = !isValid(bbox_->input_bb_x0);
670         invalid = invalid || !isValid(bbox_->input_bb_x1);
671         invalid = invalid || !isValid(bbox_->input_bb_y0);
672         invalid = invalid || !isValid(bbox_->input_bb_y1);
673         invalid = invalid || !isValid(size_->input_width);
674         invalid = invalid || !isValid(size_->input_height);
675         invalid = invalid || !isValid(lyxview_->input_lyxwidth);
676         invalid = invalid || !isValid(lyxview_->input_lyxheight);
677
678         // deactivate OK/ Apply buttons and
679         // spit out warnings if invalid
680         if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
681             ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
682             ob == size_->input_width || ob == size_->input_height ||
683             ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
684                 if (invalid) {
685                         postWarning(_("Invalid Length!"));
686                         return ButtonPolicy::SMI_INVALID;
687                 } else {
688                         clearMessage();
689                 }
690         }
691
692         return ButtonPolicy::SMI_VALID;
693 }