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