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