]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormGraphics.C
22d9e46ab5144741a883e6bc235f419fa31e7f18
[features.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         bc().addReadOnly(lyxview_->check_lyxaspectratio);
136
137         // the size section
138         size_.reset(build_graphics_size(this));
139
140         fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
141         fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
142         fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
143
144         setPrehandler(size_->input_scale);
145         setPrehandler(size_->input_width);
146         setPrehandler(size_->input_height);
147
148         fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
149         fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
150         fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
151
152         fl_set_input_filter(size_->input_scale,  fl_unsigned_float_filter);
153
154         fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
155         fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
156
157         bc().addReadOnly(size_->radio_asis);
158         bc().addReadOnly(size_->radio_wh);
159         bc().addReadOnly(size_->radio_scale);
160         bc().addReadOnly(size_->check_aspectratio);
161
162         // the bounding box selection
163         bbox_.reset(build_graphics_bbox(this));
164         fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
165         fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
166         fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
167         fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
168
169         fl_set_input_filter(bbox_->input_bb_x0,  fl_unsigned_float_filter);
170         fl_set_input_filter(bbox_->input_bb_y0,  fl_unsigned_float_filter);
171         fl_set_input_filter(bbox_->input_bb_x1,  fl_unsigned_float_filter);
172         fl_set_input_filter(bbox_->input_bb_y1,  fl_unsigned_float_filter);
173
174         setPrehandler(bbox_->input_bb_x0);
175         setPrehandler(bbox_->input_bb_y0);
176         setPrehandler(bbox_->input_bb_x1);
177         setPrehandler(bbox_->input_bb_y1);
178
179         string const bb_units = "bp|cm|mm|in";
180         fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
181         bc().addReadOnly(bbox_->button_getBB);
182         bc().addReadOnly(bbox_->check_clip);
183
184         // the rotate section
185         special_.reset(build_graphics_special(this));
186
187         fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
188         setPrehandler(special_->input_special);
189
190         // add the different tabfolders
191         fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
192         fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
193         fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
194         fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
195         fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
196         // set the right default unit
197         if (lyxrc.default_papersize < 3)
198                 defaultUnit = "in";
199 }
200
201
202 void FormGraphics::apply()
203 {
204         // Create the parameters structure and fill the data from the dialog.
205         InsetGraphicsParams & igp = controller().params();
206
207         // the file section
208         igp.filename = getStringFromInput(file_->input_filename);
209         igp.subcaption = fl_get_button(file_->check_subcaption);
210         igp.subcaptionText = getStringFromInput(file_->input_subcaption);
211         igp.rotate = fl_get_button(file_->check_rotate);
212         igp.rotateAngle =
213                 strToDbl(getStringFromInput(file_->input_rotate_angle));
214         while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
215                 if (igp.rotateAngle < 0.0) {
216                         igp.rotateAngle += 360.0;
217                 } else if (igp.rotateAngle > 360.0) {
218                         igp.rotateAngle -= 360.0;
219                 }
220         }
221         int const pos = fl_get_choice(file_->choice_origin);
222         if (pos > 0)
223                 igp.rotateOrigin = origins_[pos-1];
224         else
225                 igp.rotateOrigin = string();
226
227         igp.draft = fl_get_button(file_->check_draft);
228         igp.noUnzip = fl_get_button(file_->check_nounzip);
229
230         // the lyxview section
231         if (fl_get_button(lyxview_->radio_pref))
232                 igp.display = InsetGraphicsParams::DEFAULT;
233         else if (fl_get_button(lyxview_->radio_mono))
234                 igp.display = InsetGraphicsParams::MONOCHROME;
235         else if (fl_get_button(lyxview_->radio_gray))
236                 igp.display = InsetGraphicsParams::GRAYSCALE;
237         else if (fl_get_button(lyxview_->radio_color))
238                 igp.display = InsetGraphicsParams::COLOR;
239         else if (fl_get_button(lyxview_->radio_nodisplay))
240                 igp.display = InsetGraphicsParams::NONE;
241
242         if (fl_get_button(lyxview_->radio_lyxasis))
243                 igp.lyxsize_type = InsetGraphicsParams::DEFAULT_SIZE;
244         else if (fl_get_button(lyxview_->radio_lyxwh))
245                 igp.lyxsize_type = InsetGraphicsParams::WH;
246         else
247                 igp.lyxsize_type = InsetGraphicsParams::SCALE;
248
249         igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
250                                                lyxview_->choice_lyxwidth);
251
252         igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
253                                                 lyxview_->choice_lyxheight);
254
255         igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
256         igp.keepLyXAspectRatio = fl_get_button(lyxview_->check_lyxaspectratio);
257
258         // the size section
259         if (fl_get_button(size_->radio_asis))
260                 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
261         else if (fl_get_button(size_->radio_wh))
262                 igp.size_type = InsetGraphicsParams::WH;
263         else
264                 igp.size_type = InsetGraphicsParams::SCALE;
265
266         igp.width = getLyXLengthFromWidgets(size_->input_width,
267                                             size_->choice_width);
268
269         igp.height = getLyXLengthFromWidgets(size_->input_height,
270                                    size_->choice_height);
271
272         igp.scale = strToInt(getStringFromInput(size_->input_scale));
273         igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
274
275         // the bb section
276         if (!controller().bbChanged)            // different to the original one?
277                 igp.bb = string();                      // don't write anything
278         else {
279                 string bb;
280                 if (getStringFromInput(bbox_->input_bb_x0).empty())
281                         bb = "0 ";
282                 else
283                         bb = getLengthFromWidgets(bbox_->input_bb_x0,
284                                                   bbox_->choice_bb_units)+" ";
285                 if (getStringFromInput(bbox_->input_bb_y0).empty())
286                         bb += "0 ";
287                 else
288                         bb += (getLengthFromWidgets(bbox_->input_bb_y0,
289                                                     bbox_->choice_bb_units)+" ");
290                 if (getStringFromInput(bbox_->input_bb_x1).empty())
291                         bb += "0 ";
292                 else
293                         bb += (getLengthFromWidgets(bbox_->input_bb_x1,
294                                                     bbox_->choice_bb_units)+" ");
295                 if (getStringFromInput(bbox_->input_bb_y1).empty())
296                         bb += "0 ";
297                 else
298                         bb += (getLengthFromWidgets(bbox_->input_bb_y1,
299                                                     bbox_->choice_bb_units)+" ");
300                 igp.bb = bb;
301         }
302         igp.clip = fl_get_button(bbox_->check_clip);
303
304         // the special section
305         igp.special = getStringFromInput(special_->input_special);
306 }
307
308
309 void FormGraphics::update() {
310         // Update dialog with details from inset
311         InsetGraphicsParams & igp = controller().params();
312
313         // the file section
314         fl_set_input(file_->input_filename, igp.filename.c_str());
315         fl_set_button(file_->check_subcaption, igp.subcaption);
316         fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
317         setEnabled(file_->input_subcaption,
318                    fl_get_button(file_->check_subcaption));
319         fl_set_button(file_->check_rotate, igp.rotate);
320         fl_set_input(file_->input_rotate_angle,
321                      tostr(igp.rotateAngle).c_str());
322         if (igp.rotateOrigin.empty())
323                 fl_set_choice(file_->choice_origin,1);
324         else {
325                 int pos = int(findPos(origins_, igp.rotateOrigin));
326                 fl_set_choice(file_->choice_origin, pos+1);
327         }
328
329         setEnabled(file_->input_rotate_angle,
330                    fl_get_button(file_->check_rotate));
331         setEnabled(file_->choice_origin,
332                    fl_get_button(file_->check_rotate));
333         fl_set_button(file_->check_draft, igp.draft);
334         fl_set_button(file_->check_nounzip, igp.noUnzip);
335
336         // the lyxview section
337         switch (igp.display) {
338         case InsetGraphicsParams::DEFAULT:
339                 fl_set_button(lyxview_->radio_pref, 1);
340                 break;
341         case InsetGraphicsParams::MONOCHROME:
342                 fl_set_button(lyxview_->radio_mono, 1);
343                 break;
344         case InsetGraphicsParams::GRAYSCALE:
345                 fl_set_button(lyxview_->radio_gray, 1);
346                 break;
347         case InsetGraphicsParams::COLOR:
348                 fl_set_button(lyxview_->radio_color, 1);
349                 break;
350         case InsetGraphicsParams::NONE:
351                 fl_set_button(lyxview_->radio_nodisplay, 1);
352                 break;
353         }
354         updateWidgetsFromLength(lyxview_->input_lyxwidth,
355                                 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
356         updateWidgetsFromLength(lyxview_->input_lyxheight,
357                                 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
358         fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
359         switch (igp.lyxsize_type) {
360         case InsetGraphicsParams::DEFAULT_SIZE: {
361                 fl_set_button(lyxview_->radio_lyxasis,1);
362                 setEnabled(lyxview_->input_lyxwidth, 0);
363                 setEnabled(lyxview_->choice_lyxwidth, 0);
364                 setEnabled(lyxview_->input_lyxheight, 0);
365                 setEnabled(lyxview_->choice_lyxheight, 0);
366                 setEnabled(lyxview_->check_lyxaspectratio, 0);
367                 setEnabled(lyxview_->input_lyxscale, 0);
368                 break;
369         }
370         case InsetGraphicsParams::WH: {
371                 fl_set_button(lyxview_->radio_lyxwh, 1);
372                 setEnabled(lyxview_->input_lyxwidth, 1);
373                 setEnabled(lyxview_->choice_lyxwidth, 1);
374                 setEnabled(lyxview_->input_lyxheight, 1);
375                 setEnabled(lyxview_->choice_lyxheight, 1);
376                 setEnabled(lyxview_->check_lyxaspectratio, 1);
377                 setEnabled(lyxview_->input_lyxscale, 0);
378                 break;
379         }
380         case InsetGraphicsParams::SCALE: {
381                 fl_set_button(lyxview_->radio_lyxscale, 1);
382                 setEnabled(lyxview_->input_lyxwidth, 0);
383                 setEnabled(lyxview_->choice_lyxwidth, 0);
384                 setEnabled(lyxview_->input_lyxheight, 0);
385                 setEnabled(lyxview_->choice_lyxheight, 0);
386                 setEnabled(lyxview_->check_lyxaspectratio, 0);
387                 setEnabled(lyxview_->input_lyxscale, 1);
388                 break;
389         }
390         }
391
392         fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
393
394         // the size section
395         // Update the draft and clip mode
396         updateWidgetsFromLength(size_->input_width,
397                                 size_->choice_width, igp.width, defaultUnit);
398         updateWidgetsFromLength(size_->input_height,
399                                 size_->choice_height, igp.height, defaultUnit);
400         fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
401         switch (igp.size_type) {
402         case InsetGraphicsParams::DEFAULT_SIZE: {
403                 fl_set_button(size_->radio_asis,1);
404                 setEnabled(size_->input_width, 0);
405                 setEnabled(size_->choice_width, 0);
406                 setEnabled(size_->input_height, 0);
407                 setEnabled(size_->choice_height, 0);
408                 setEnabled(size_->check_aspectratio, 0);
409                 setEnabled(size_->input_scale, 0);
410                 break;
411         }
412         case InsetGraphicsParams::WH: {
413                 fl_set_button(size_->radio_wh, 1);
414                 setEnabled(size_->input_width, 1);
415                 setEnabled(size_->choice_width, 1);
416                 setEnabled(size_->input_height, 1);
417                 setEnabled(size_->choice_height, 1);
418                 setEnabled(size_->check_aspectratio, 1);
419                 setEnabled(size_->input_scale, 0);
420                 break;
421         }
422         case InsetGraphicsParams::SCALE: {
423                 fl_set_button(size_->radio_scale, 1);
424                 setEnabled(size_->input_width, 0);
425                 setEnabled(size_->choice_width, 0);
426                 setEnabled(size_->input_height, 0);
427                 setEnabled(size_->choice_height, 0);
428                 setEnabled(size_->check_aspectratio, 0);
429                 setEnabled(size_->input_scale, 1);
430                 break;
431         }
432         }
433         fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
434
435         // the bb section
436         // set the bounding box values, if exists. First we need the whole
437         // path, because the controller knows nothing about the doc-dir
438         updateBB(igp.filename, igp.bb);
439         fl_set_button(bbox_->check_clip, igp.clip);
440
441         // the special section
442         fl_set_input(special_->input_special, igp.special.c_str());
443 }
444
445
446 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
447 {
448         // Update dialog with details from inset
449         // set the bounding box values, if exists. First we need the whole
450         // path, because the controller knows nothing about the doc-dir
451         controller().bbChanged = false;
452         if (bb_inset.empty()) {
453                 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
454                 string const bb = controller().readBB(filename);
455                 if (!bb.empty()) {
456                         // get the values from the file
457                         // in this case we always have the point-unit
458                         fl_set_input(bbox_->input_bb_x0,
459                                      token(bb,' ',0).c_str());
460                         fl_set_input(bbox_->input_bb_y0,
461                                      token(bb,' ',1).c_str());
462                         fl_set_input(bbox_->input_bb_x1,
463                                      token(bb,' ',2).c_str());
464                         fl_set_input(bbox_->input_bb_y1,
465                                      token(bb,' ',3).c_str());
466
467                 } else {
468                         // no bb from file
469                         fl_set_input(bbox_->input_bb_x0, bb.c_str());
470                         fl_set_input(bbox_->input_bb_y0, bb.c_str());
471                         fl_set_input(bbox_->input_bb_x1, bb.c_str());
472                         fl_set_input(bbox_->input_bb_y1, bb.c_str());
473                 }
474                 // "bp"
475                 fl_set_choice(bbox_->choice_bb_units, 1);
476
477         } else {
478                 // get the values from the inset
479                 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
480                                         << endl;
481                 controller().bbChanged = true;
482                 LyXLength anyLength;
483                 anyLength = LyXLength(token(bb_inset,' ',0));
484                 updateWidgetsFromLength(bbox_->input_bb_x0,
485                                         bbox_->choice_bb_units,anyLength,"bp");
486                 anyLength = LyXLength(token(bb_inset,' ',1));
487                 updateWidgetsFromLength(bbox_->input_bb_y0,
488                                         bbox_->choice_bb_units,anyLength,"bp");
489                 anyLength = LyXLength(token(bb_inset,' ',2));
490                 updateWidgetsFromLength(bbox_->input_bb_x1,
491                                         bbox_->choice_bb_units,anyLength,"bp");
492                 anyLength = LyXLength(token(bb_inset,' ',3));
493                 updateWidgetsFromLength(bbox_->input_bb_y1,
494                                         bbox_->choice_bb_units,anyLength,"bp");
495         }
496 }
497
498 namespace {
499
500 bool isValid(FL_OBJECT * ob)
501 {
502         string const input = getStringFromInput(ob);
503         return input.empty() || isValidLength(input) || isStrDbl(input);
504 }
505
506 } // namespace anon
507
508
509
510 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
511 {
512         // the file section
513         if (ob == file_->button_browse) {
514                 // Get the filename from the dialog
515                 string const in_name = getStringFromInput(file_->input_filename);
516                 string const out_name = controller().Browse(in_name);
517                 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
518                 if (out_name != in_name && !out_name.empty()) {
519                         fl_set_input(file_->input_filename, out_name.c_str());
520                 }
521                 if (controller().isFilenameValid(out_name) &&
522                     !controller().bbChanged)
523                         updateBB(out_name, string());
524
525         } else if (ob == file_->check_subcaption) {
526                 setEnabled(file_->input_subcaption,
527                            fl_get_button(file_->check_subcaption));
528         } else if (ob == file_->check_rotate) {
529                 setEnabled(file_->input_rotate_angle,
530                            fl_get_button(file_->check_rotate));
531                 setEnabled(file_->choice_origin,
532                            fl_get_button(file_->check_rotate));
533
534                 // the lyxview section
535         } else if (ob == lyxview_->radio_lyxasis) {
536                 setEnabled(lyxview_->input_lyxwidth, 0);
537                 setEnabled(lyxview_->choice_lyxwidth, 0);
538                 setEnabled(lyxview_->input_lyxheight, 0);
539                 setEnabled(lyxview_->choice_lyxheight, 0);
540                 setEnabled(lyxview_->check_lyxaspectratio, 0);
541                 setEnabled(lyxview_->input_lyxscale, 0);
542         } else if (ob == lyxview_->radio_lyxwh) {
543                 setEnabled(lyxview_->input_lyxwidth, 1);
544                 setEnabled(lyxview_->choice_lyxwidth, 1);
545                 setEnabled(lyxview_->input_lyxheight, 1);
546                 setEnabled(lyxview_->choice_lyxheight, 1);
547                 setEnabled(lyxview_->check_lyxaspectratio, 1);
548                 setEnabled(lyxview_->input_lyxscale, 0);
549         } else if (ob == lyxview_->radio_lyxscale) {
550                 setEnabled(lyxview_->input_lyxwidth, 0);
551                 setEnabled(lyxview_->choice_lyxwidth, 0);
552                 setEnabled(lyxview_->input_lyxheight, 0);
553                 setEnabled(lyxview_->choice_lyxheight, 0);
554                 setEnabled(lyxview_->check_lyxaspectratio, 0);
555                 setEnabled(lyxview_->input_lyxscale, 1);
556         } else if (ob == lyxview_->button_latex_values) {
557                 if (contains(fl_get_choice_text(size_->choice_width),'%') || 
558                         contains(fl_get_choice_text(size_->choice_height),'%'))
559                         Alert::alert(_("Warning!"),
560                                      _("The %-units are not allowed here."),
561                                      _("Cannot use the values from LaTeX size!"));
562                 else {
563                         LyXLength dummy =
564                                 getLyXLengthFromWidgets(size_->input_width,
565                                                         size_->choice_width);
566                         updateWidgetsFromLength(lyxview_->input_lyxwidth,
567                                                 lyxview_->choice_lyxwidth,
568                                                 dummy, defaultUnit);
569
570                         dummy = getLyXLengthFromWidgets(size_->input_height,
571                                                         size_->choice_height);
572                         updateWidgetsFromLength(lyxview_->input_lyxheight,
573                                                 lyxview_->choice_lyxheight,
574                                                 dummy, defaultUnit);
575                         string const scale = getStringFromInput(size_->input_scale);
576                         fl_set_input(lyxview_->input_lyxscale, scale.c_str());
577                         if (fl_get_button (size_->radio_asis) == 1) {
578                                 fl_set_button (lyxview_->radio_lyxasis, 1);
579                                 setEnabled(lyxview_->input_lyxwidth, 0);
580                                 setEnabled(lyxview_->choice_lyxwidth, 0);
581                                 setEnabled(lyxview_->input_lyxheight, 0);
582                                 setEnabled(lyxview_->choice_lyxheight, 0);
583                                 setEnabled(lyxview_->check_lyxaspectratio, 0);
584                                 setEnabled(lyxview_->input_lyxscale, 0);
585                         } else if (fl_get_button (size_->radio_wh) == 1) {
586                                 fl_set_button (lyxview_->radio_lyxwh, 1);
587                                 setEnabled(lyxview_->input_lyxwidth, 1);
588                                 setEnabled(lyxview_->choice_lyxwidth, 1);
589                                 setEnabled(lyxview_->input_lyxheight, 1);
590                                 setEnabled(lyxview_->choice_lyxheight, 1);
591                                 setEnabled(lyxview_->check_lyxaspectratio, 1);
592                                 setEnabled(lyxview_->input_lyxscale, 0);
593                         } else if (fl_get_button (size_->radio_scale) ==1) {
594                                 fl_set_button (lyxview_->radio_lyxscale, 1);
595                                 setEnabled(lyxview_->input_lyxwidth, 0);
596                                 setEnabled(lyxview_->choice_lyxwidth, 0);
597                                 setEnabled(lyxview_->input_lyxheight, 0);
598                                 setEnabled(lyxview_->choice_lyxheight, 0);
599                                 setEnabled(lyxview_->check_lyxaspectratio, 0);
600                                 setEnabled(lyxview_->input_lyxscale, 1);
601                         }
602                 }
603                 fl_set_button(lyxview_->check_lyxaspectratio,
604                         fl_get_button(size_->check_aspectratio));
605
606                 // the bb section
607         } else if (!controller().bbChanged &&
608                    (ob == bbox_->check_clip  || ob == bbox_->choice_bb_units ||
609                     ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
610                     ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
611                 controller().bbChanged = true;
612         } else if (ob == bbox_->button_getBB) {
613                 string const filename = getStringFromInput(file_->input_filename);
614                 if (!filename.empty()) {
615                         string bb = controller().readBB(filename);
616                         if (!bb.empty()) {
617                                 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
618                                 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
619                                 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
620                                 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
621                                 string const unit("bp");
622                                 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
623                         }
624                         controller().bbChanged = false;
625                 } else {
626                         fl_set_input(bbox_->input_bb_x0, "");
627                         fl_set_input(bbox_->input_bb_y0, "");
628                         fl_set_input(bbox_->input_bb_x1, "");
629                         fl_set_input(bbox_->input_bb_y1, "");
630                         fl_set_choice_text(bbox_->choice_bb_units, "bp");
631                 }
632
633                 // the size section
634         } else if (ob == size_->radio_asis) {
635                 setEnabled(size_->input_width, 0);
636                 setEnabled(size_->choice_width, 0);
637                 setEnabled(size_->input_height, 0);
638                 setEnabled(size_->choice_height, 0);
639                 setEnabled(size_->check_aspectratio, 0);
640                 setEnabled(size_->input_scale, 0);
641         } else if (ob == size_->radio_wh) {
642                 setEnabled(size_->input_width, 1);
643                 setEnabled(size_->choice_width, 1);
644                 setEnabled(size_->input_height, 1);
645                 setEnabled(size_->choice_height, 1);
646                 setEnabled(size_->check_aspectratio, 1);
647                 setEnabled(size_->input_scale, 0);
648         } else if (ob == size_->radio_scale) {
649                 setEnabled(size_->input_width, 0);
650                 setEnabled(size_->choice_width, 0);
651                 setEnabled(size_->input_height, 0);
652                 setEnabled(size_->choice_height, 0);
653                 setEnabled(size_->check_aspectratio, 0);
654                 setEnabled(size_->input_scale, 1);
655         } else if (ob == size_->button_lyx_values) {
656                 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
657                                                           lyxview_->choice_lyxwidth);
658                 updateWidgetsFromLength(size_->input_width,
659                                         size_->choice_width,
660                                         dummy, defaultUnit);
661                 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
662                                                 lyxview_->choice_lyxheight);
663                 updateWidgetsFromLength(size_->input_height,
664                                         size_->choice_height,
665                                         dummy, defaultUnit);
666                 string const scale = getStringFromInput(lyxview_->input_lyxscale);
667                 fl_set_input(size_->input_scale, scale.c_str());
668                 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
669                         fl_set_button (size_->radio_asis, 1);
670                         setEnabled(size_->input_width, 0);
671                         setEnabled(size_->choice_width, 0);
672                         setEnabled(size_->input_height, 0);
673                         setEnabled(size_->choice_height, 0);
674                         setEnabled(size_->check_aspectratio, 0);
675                         setEnabled(size_->input_scale, 0);
676                 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
677                         fl_set_button (size_->radio_wh, 1);
678                         setEnabled(size_->input_width, 1);
679                         setEnabled(size_->choice_width, 1);
680                         setEnabled(size_->input_height, 1);
681                         setEnabled(size_->choice_height, 1);
682                         setEnabled(size_->check_aspectratio, 1);
683                         setEnabled(size_->input_scale, 0);
684                 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
685                         fl_set_button (size_->radio_scale, 1);
686                         setEnabled(size_->input_width, 0);
687                         setEnabled(size_->choice_width, 0);
688                         setEnabled(size_->input_height, 0);
689                         setEnabled(size_->choice_height, 0);
690                         setEnabled(size_->check_aspectratio, 0);
691                         setEnabled(size_->input_scale, 1);
692                 }
693                 fl_set_button(size_->check_aspectratio,
694                               fl_get_button(lyxview_->check_lyxaspectratio));
695         }
696
697         // check if the input is valid
698         bool invalid = !isValid(bbox_->input_bb_x0);
699         invalid = invalid || !isValid(bbox_->input_bb_x1);
700         invalid = invalid || !isValid(bbox_->input_bb_y0);
701         invalid = invalid || !isValid(bbox_->input_bb_y1);
702         invalid = invalid || !isValid(size_->input_width);
703         invalid = invalid || !isValid(size_->input_height);
704         invalid = invalid || !isValid(lyxview_->input_lyxwidth);
705         invalid = invalid || !isValid(lyxview_->input_lyxheight);
706
707         // deactivate OK/ Apply buttons and
708         // spit out warnings if invalid
709         if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
710             ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
711             ob == size_->input_width || ob == size_->input_height ||
712             ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
713                 if (invalid) {
714                         postWarning(_("Invalid Length!"));
715                         return ButtonPolicy::SMI_INVALID;
716                 } else {
717                         clearMessage();
718                 }
719         }
720
721         return ButtonPolicy::SMI_VALID;
722 }