]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormGraphics.C
fix tooltips in toolbar
[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 #include "Tooltips.h"
22
23 #include "xforms_helpers.h"
24 #include "helper_funcs.h"
25 #include "input_validators.h"
26 #include "debug.h" // for lyxerr
27 #include "support/lstrings.h"  // for strToDbl & tostr
28 #include "support/filetools.h"  // for MakeAbsPath etc
29 #include "insets/insetgraphicsParams.h"
30 #include "lyxrc.h" // for lyxrc.display_graphics
31 #include FORMS_H_LOCATION
32
33 using std::endl;
34 using std::vector;
35
36 namespace {
37
38 // Bound the number of input characters
39 int const SCALE_MAXDIGITS = 3;         // %-value
40 int const WIDTH_MAXDIGITS = 10;
41 int const HEIGHT_MAXDIGITS = 10;
42 int const ROTATE_MAXCHARS = 5;         // like 270.1
43 int const FILENAME_MAXCHARS = 1024;
44 string defaultUnit("cm");
45
46 /// Given input and choice widgets, create a LyXLength
47 LyXLength getLyXLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
48 {
49         return LyXLength(getLengthFromWidgets(input, choice));
50 }
51
52 } // namespace anon
53
54
55 typedef FormCB<ControlGraphics, FormDB<FD_graphics> > base_class;
56
57 FormGraphics::FormGraphics(ControlGraphics & c, Dialogs & d)
58         : base_class(c, d, _("Graphics"), false)
59 {}
60
61
62 void FormGraphics::redraw()
63 {
64         if (form() && form()->visible)
65                 fl_redraw_form(form());
66         else
67                 return;
68         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder);
69         if (outer_form && outer_form->visible)
70                 fl_redraw_form(outer_form);
71 }
72
73
74 void FormGraphics::build()
75 {
76         dialog_.reset(build_graphics(this));
77
78         // Allow the base class to control messages
79         setMessageWidget(dialog_->text_warning);
80
81         // Manage the ok, apply, restore and cancel/close buttons
82         bc().setOK(dialog_->button_ok);
83         bc().setApply(dialog_->button_apply);
84         bc().setCancel(dialog_->button_close);
85         bc().setRestore(dialog_->button_restore);
86
87         // the file section
88         file_.reset(build_graphics_file(this));
89
90         fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
91         fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
92         fl_set_input_return (file_->input_rotate_angle, FL_RETURN_CHANGED);
93         fl_set_input_maxchars(file_->input_filename,  FILENAME_MAXCHARS);
94         fl_set_input_maxchars(file_->input_rotate_angle, ROTATE_MAXCHARS);
95         fl_set_input_filter(file_->input_rotate_angle, fl_float_filter);
96
97         setPrehandler(file_->input_filename);
98         setPrehandler(file_->input_subcaption);
99         setPrehandler(file_->input_rotate_angle);
100
101         using namespace frnt;
102         vector<RotationOriginPair> origindata = getRotationOriginData();
103
104         // Store the identifiers for later
105         origins_ = getSecond(origindata);
106
107         string const choice =
108                 " " + getStringFromVector(getFirst(origindata), " | ") +" ";
109         fl_addto_choice(file_->choice_origin, choice.c_str());
110
111         bc().addReadOnly(file_->button_browse);
112         bc().addReadOnly(file_->check_subcaption);
113         bc().addReadOnly(file_->check_rotate);
114         bc().addReadOnly(file_->check_draft);
115         bc().addReadOnly(file_->check_nounzip);
116
117         // set up the tooltips for the filesection
118         string str = _("The file you want to insert.");
119         tooltips().init(file_->input_filename, str);
120         str = _("Browse the directories.");
121         tooltips().init(file_->button_browse, str);
122
123         str = _("Enables use of subfigure with an own caption.");
124         tooltips().init(file_->check_subcaption, str);
125         str = _("Insert the an optional subfigure caption");
126         tooltips().init(file_->input_subcaption, str);
127
128         str = _("Enables use of rotating for the image.");
129         tooltips().init(file_->check_rotate, str);
130         str = _("Insert the rotating angle in degrees (max 5 characters like 270.1)");
131         tooltips().init(file_->input_rotate_angle, str);
132
133         str = _("Insert the rotating origin point.");
134         tooltips().init(file_->choice_origin, str);
135
136         str = _("Pass a filename like \"file.eps.gz\" to the LaTeX output. "
137             "This is useful when LaTeX should unzip the file. Needs an additional file "
138             "like \"file.eps.bb\" which holds the values for the bounding box");
139         tooltips().init(file_->check_nounzip, str);
140
141         str = _("Show image only as a rectangle of the original size.");
142         tooltips().init(file_->check_draft, str);
143
144         // the lyxview section
145         lyxview_.reset(build_graphics_lyxview(this));
146
147         fl_set_input_return (lyxview_->input_lyxwidth, FL_RETURN_CHANGED);
148         fl_set_input_return (lyxview_->input_lyxheight, FL_RETURN_CHANGED);
149         fl_set_input_return (lyxview_->input_lyxscale, FL_RETURN_CHANGED);
150
151         setPrehandler(lyxview_->input_lyxwidth);
152         setPrehandler(lyxview_->input_lyxheight);
153         setPrehandler(lyxview_->input_lyxscale);
154
155         fl_addto_choice(lyxview_->choice_lyxwidth, choice_Length_WithUnit.c_str());
156         fl_addto_choice(lyxview_->choice_lyxheight, choice_Length_WithUnit.c_str());
157
158         bc().addReadOnly(lyxview_->radio_pref);
159         bc().addReadOnly(lyxview_->radio_mono);
160         bc().addReadOnly(lyxview_->radio_gray);
161         bc().addReadOnly(lyxview_->radio_color);
162         bc().addReadOnly(lyxview_->radio_nodisplay);
163         bc().addReadOnly(lyxview_->check_lyxaspectratio);
164
165         // set up the tooltips for the lyxview section
166         str = _("Take the definition from the Preferences->Look&Feel->Misc as default.");
167         tooltips().init(lyxview_->radio_pref, str);
168         str = _("Show this image in black and white (monochrome).");
169         tooltips().init(lyxview_->radio_mono, str);
170         str = _("Show this image in grayscale.");
171         tooltips().init(lyxview_->radio_gray, str);
172         str = _("Show this image in color.");
173         tooltips().init(lyxview_->radio_color, str);
174         str = _("Do not display this image.");
175         tooltips().init(lyxview_->radio_nodisplay, str);
176
177         str = _("Copies all values from the LaTeX tab");
178         tooltips().init(lyxview_->button_latex_values, str);
179
180         str = _("Show this image in it's original size.");
181         tooltips().init(lyxview_->radio_lyxasis, str);
182         str = _("Scale the image down to the inserted values.");
183         tooltips().init(lyxview_->radio_lyxwh, str);
184         str = _("Scale the image down to the inserted value and keep aspectratio.");
185         tooltips().init(lyxview_->radio_lyxscale, str);
186
187         str = _("Insert a width in any valid unit to which the image in the LyX-view "
188                 "should be scaled up/down");
189         tooltips().init(lyxview_->input_lyxwidth, str);
190         str = _("Insert a height in any valid unit to which the image in the LyX-view "
191                 "should be scaled up/down");
192         tooltips().init(lyxview_->input_lyxheight, str);
193         str = _("Insert a value > 0 in persent to which the image should be scaled up/down");
194         tooltips().init(lyxview_->input_lyxscale, str);
195         str = _("Shows all possible units for the length");
196         tooltips().init(lyxview_->choice_lyxwidth, str);
197         tooltips().init(lyxview_->choice_lyxheight, str);
198         str = _("Modifies the meaning of the \"width\" and \"height\" (and "
199                 "\"totalheight\") keys such that if both are specified then rather than "
200                 "distort the figure the figure is scaled such that neither dimension "
201                 "exceeds the stated dimensions.");
202         tooltips().init(lyxview_->check_lyxaspectratio, str);
203
204         // the size section
205         size_.reset(build_graphics_size(this));
206
207         fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
208         fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
209         fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
210
211         setPrehandler(size_->input_scale);
212         setPrehandler(size_->input_width);
213         setPrehandler(size_->input_height);
214
215         fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
216         fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
217         fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
218
219         fl_set_input_filter(size_->input_scale,  fl_unsigned_float_filter);
220
221         fl_addto_choice(size_->choice_width, choice_Length_All.c_str());
222         fl_addto_choice(size_->choice_height, choice_Length_All.c_str());
223
224         bc().addReadOnly(size_->radio_asis);
225         bc().addReadOnly(size_->radio_wh);
226         bc().addReadOnly(size_->radio_scale);
227         bc().addReadOnly(size_->check_aspectratio);
228
229         // set up the tooltips for the size section
230         str = _("Copies all values from the LyX tab");
231         tooltips().init(size_->button_lyx_values, str);
232
233         str = _("Show this image in it's original size.");
234         tooltips().init(size_->radio_asis, str);
235         str = _("Scale the image down to the inserted values.");
236         tooltips().init(size_->radio_wh, str);
237         str = _("Scale the image down to the inserted value and keep aspectratio.");
238         tooltips().init(size_->radio_scale, str);
239
240         str = _("Modifies the meaning of the \"width\" and \"height\" (and "
241                 "\"totalheight\") keys such that if both are specified then rather than "
242                 "distort the figure the figure is scaled such that neither dimension "
243                 "exceeds the stated dimensions.");
244         tooltips().init(size_->check_aspectratio, str);
245
246         str = _("Insert a width in any valid unit to which the image in the LyX-view "
247                 "should be scaled up/down");
248         tooltips().init(lyxview_->input_lyxwidth, str);
249         str = _("Insert a height in any valid unit to which the image in the LyX-view "
250                 "should be scaled up/down");
251         tooltips().init(lyxview_->input_lyxheight, str);
252         str = _("Insert a value > 0 in persent to which the image should be scaled up/down");
253         tooltips().init(lyxview_->input_lyxscale, str);
254         str = _("Shows all possible units for the length");
255         tooltips().init(lyxview_->choice_lyxwidth, str);
256         tooltips().init(lyxview_->choice_lyxheight, str);
257
258         // the bounding box selection
259         bbox_.reset(build_graphics_bbox(this));
260         fl_set_input_return (bbox_->input_bb_x0, FL_RETURN_CHANGED);
261         fl_set_input_return (bbox_->input_bb_y0, FL_RETURN_CHANGED);
262         fl_set_input_return (bbox_->input_bb_x1, FL_RETURN_CHANGED);
263         fl_set_input_return (bbox_->input_bb_y1, FL_RETURN_CHANGED);
264
265         fl_set_input_filter(bbox_->input_bb_x0,  fl_unsigned_float_filter);
266         fl_set_input_filter(bbox_->input_bb_y0,  fl_unsigned_float_filter);
267         fl_set_input_filter(bbox_->input_bb_x1,  fl_unsigned_float_filter);
268         fl_set_input_filter(bbox_->input_bb_y1,  fl_unsigned_float_filter);
269
270         setPrehandler(bbox_->input_bb_x0);
271         setPrehandler(bbox_->input_bb_y0);
272         setPrehandler(bbox_->input_bb_x1);
273         setPrehandler(bbox_->input_bb_y1);
274
275         string const bb_units = "bp|cm|mm|in";
276         fl_addto_choice(bbox_->choice_bb_units, bb_units.c_str());
277         bc().addReadOnly(bbox_->button_getBB);
278         bc().addReadOnly(bbox_->check_clip);
279
280         // set up the tooltips for the bounding-box-section
281         str = _("The lower left x-value of the bounding box");
282         tooltips().init(bbox_->input_bb_x0, str);
283         str = _("The lower left y-value of the bounding box");
284         tooltips().init(bbox_->input_bb_y0, str);
285         str = _("The upper right x-value of the bounding box");
286         tooltips().init(bbox_->input_bb_x1, str);
287         str = _("The upper right y-value of the bounding box");
288         tooltips().init(bbox_->input_bb_y1, str);
289         str = _("Shows all possible units for the bounding box values");
290         tooltips().init(bbox_->choice_bb_units, str);
291
292         str = _("Read the image coordinates new from file. If it's an (e)ps-file "
293                 "than the bounding box is read otherwise the imagesize in pixels. "
294                 "The default unit is \"bp\" the PostScript b)ig p)oint.");
295         tooltips().init(bbox_->button_getBB, str);
296
297         str = _("Enable this checkbox when the image should be clipped to the "
298                 "bounding box values.");
299         tooltips().init(bbox_->check_clip, str);
300
301         // the rotate section
302         special_.reset(build_graphics_special(this));
303
304         fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
305         setPrehandler(special_->input_special);
306
307         // set up the tooltips for the special section
308         str = _("Any additional option, which is defined in the graphicx-package "
309                 "and not mentioned in the gui's tabfolders can be defined.");
310         tooltips().init(special_->input_special, str);
311
312         // add the different tabfolders
313         fl_addto_tabfolder(dialog_->tabfolder, _("File"), file_->form);
314         fl_addto_tabfolder(dialog_->tabfolder, _("LyX View"), lyxview_->form);
315         fl_addto_tabfolder(dialog_->tabfolder, _("LaTeX Size"), size_->form);
316         fl_addto_tabfolder(dialog_->tabfolder, _("Bounding Box"), bbox_->form);
317         fl_addto_tabfolder(dialog_->tabfolder, _("Extras"), special_->form);
318
319         // set the right default unit
320         if (lyxrc.default_papersize < 3)
321                 defaultUnit = "in";
322 }
323
324
325 void FormGraphics::apply()
326 {
327         // Create the parameters structure and fill the data from the dialog.
328         InsetGraphicsParams & igp = controller().params();
329
330         // the file section
331         igp.filename = getString(file_->input_filename);
332         igp.subcaption = fl_get_button(file_->check_subcaption);
333         igp.subcaptionText = getString(file_->input_subcaption);
334         igp.rotate = fl_get_button(file_->check_rotate);
335         igp.rotateAngle =
336                 strToDbl(getString(file_->input_rotate_angle));
337         while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
338                 if (igp.rotateAngle < 0.0) {
339                         igp.rotateAngle += 360.0;
340                 } else if (igp.rotateAngle > 360.0) {
341                         igp.rotateAngle -= 360.0;
342                 }
343         }
344         int const pos = fl_get_choice(file_->choice_origin);
345         if (pos > 0)
346                 igp.rotateOrigin = origins_[pos-1];
347         else
348                 igp.rotateOrigin = string();
349
350         igp.draft = fl_get_button(file_->check_draft);
351         igp.noUnzip = fl_get_button(file_->check_nounzip);
352
353         // the lyxview section
354         if (fl_get_button(lyxview_->radio_pref))
355                 igp.display = InsetGraphicsParams::DEFAULT;
356         else if (fl_get_button(lyxview_->radio_mono))
357                 igp.display = InsetGraphicsParams::MONOCHROME;
358         else if (fl_get_button(lyxview_->radio_gray))
359                 igp.display = InsetGraphicsParams::GRAYSCALE;
360         else if (fl_get_button(lyxview_->radio_color))
361                 igp.display = InsetGraphicsParams::COLOR;
362         else if (fl_get_button(lyxview_->radio_nodisplay))
363                 igp.display = InsetGraphicsParams::NONE;
364
365         if (fl_get_button(lyxview_->radio_lyxasis))
366                 igp.lyxsize_kind = InsetGraphicsParams::DEFAULT_SIZE;
367         else if (fl_get_button(lyxview_->radio_lyxwh))
368                 igp.lyxsize_kind = InsetGraphicsParams::WH;
369         else
370                 igp.lyxsize_kind = InsetGraphicsParams::SCALE;
371
372         igp.lyxwidth = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
373                                                lyxview_->choice_lyxwidth);
374
375         igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
376                                                 lyxview_->choice_lyxheight);
377
378         igp.lyxscale = strToInt(getString(lyxview_->input_lyxscale));
379         igp.keepLyXAspectRatio = fl_get_button(lyxview_->check_lyxaspectratio);
380
381         // the size section
382         if (fl_get_button(size_->radio_asis))
383                 igp.size_kind = InsetGraphicsParams::DEFAULT_SIZE;
384         else if (fl_get_button(size_->radio_wh))
385                 igp.size_kind = InsetGraphicsParams::WH;
386         else
387                 igp.size_kind = InsetGraphicsParams::SCALE;
388
389         igp.width = getLyXLengthFromWidgets(size_->input_width,
390                                             size_->choice_width);
391
392         igp.height = getLyXLengthFromWidgets(size_->input_height,
393                                    size_->choice_height);
394
395         igp.scale = strToInt(getString(size_->input_scale));
396         igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
397
398         // the bb section
399         if (!controller().bbChanged)            // different to the original one?
400                 igp.bb = string();                      // don't write anything
401         else {
402                 string bb;
403                 if (getString(bbox_->input_bb_x0).empty())
404                         bb = "0 ";
405                 else
406                         bb = getLengthFromWidgets(bbox_->input_bb_x0,
407                                                   bbox_->choice_bb_units)+" ";
408                 if (getString(bbox_->input_bb_y0).empty())
409                         bb += "0 ";
410                 else
411                         bb += (getLengthFromWidgets(bbox_->input_bb_y0,
412                                                     bbox_->choice_bb_units)+" ");
413                 if (getString(bbox_->input_bb_x1).empty())
414                         bb += "0 ";
415                 else
416                         bb += (getLengthFromWidgets(bbox_->input_bb_x1,
417                                                     bbox_->choice_bb_units)+" ");
418                 if (getString(bbox_->input_bb_y1).empty())
419                         bb += "0 ";
420                 else
421                         bb += (getLengthFromWidgets(bbox_->input_bb_y1,
422                                                     bbox_->choice_bb_units)+" ");
423                 igp.bb = bb;
424         }
425         igp.clip = fl_get_button(bbox_->check_clip);
426
427         // the special section
428         igp.special = getString(special_->input_special);
429 }
430
431
432 void FormGraphics::update() {
433         // Update dialog with details from inset
434         InsetGraphicsParams & igp = controller().params();
435
436         // the file section
437         fl_set_input(file_->input_filename, igp.filename.c_str());
438         fl_set_button(file_->check_subcaption, igp.subcaption);
439         fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
440         setEnabled(file_->input_subcaption,
441                    fl_get_button(file_->check_subcaption));
442         fl_set_button(file_->check_rotate, igp.rotate);
443         fl_set_input(file_->input_rotate_angle,
444                      tostr(igp.rotateAngle).c_str());
445         if (igp.rotateOrigin.empty())
446                 fl_set_choice(file_->choice_origin,1);
447         else {
448                 int pos = int(findPos(origins_, igp.rotateOrigin));
449                 fl_set_choice(file_->choice_origin, pos+1);
450         }
451
452         setEnabled(file_->input_rotate_angle,
453                    fl_get_button(file_->check_rotate));
454         setEnabled(file_->choice_origin,
455                    fl_get_button(file_->check_rotate));
456         fl_set_button(file_->check_draft, igp.draft);
457         fl_set_button(file_->check_nounzip, igp.noUnzip);
458
459         // the lyxview section
460         switch (igp.display) {
461         case InsetGraphicsParams::DEFAULT:
462                 fl_set_button(lyxview_->radio_pref, 1);
463                 break;
464         case InsetGraphicsParams::MONOCHROME:
465                 fl_set_button(lyxview_->radio_mono, 1);
466                 break;
467         case InsetGraphicsParams::GRAYSCALE:
468                 fl_set_button(lyxview_->radio_gray, 1);
469                 break;
470         case InsetGraphicsParams::COLOR:
471                 fl_set_button(lyxview_->radio_color, 1);
472                 break;
473         case InsetGraphicsParams::NONE:
474                 fl_set_button(lyxview_->radio_nodisplay, 1);
475                 break;
476         }
477         updateWidgetsFromLength(lyxview_->input_lyxwidth,
478                                 lyxview_->choice_lyxwidth, igp.lyxwidth, defaultUnit);
479         updateWidgetsFromLength(lyxview_->input_lyxheight,
480                                 lyxview_->choice_lyxheight, igp.lyxheight, defaultUnit);
481         fl_set_input(lyxview_->input_lyxscale, tostr(igp.lyxscale).c_str());
482         switch (igp.lyxsize_kind) {
483         case InsetGraphicsParams::DEFAULT_SIZE: {
484                 fl_set_button(lyxview_->radio_lyxasis,1);
485                 setEnabled(lyxview_->input_lyxwidth, 0);
486                 setEnabled(lyxview_->choice_lyxwidth, 0);
487                 setEnabled(lyxview_->input_lyxheight, 0);
488                 setEnabled(lyxview_->choice_lyxheight, 0);
489                 setEnabled(lyxview_->check_lyxaspectratio, 0);
490                 setEnabled(lyxview_->input_lyxscale, 0);
491                 break;
492         }
493         case InsetGraphicsParams::SCALE: {
494                 fl_set_button(lyxview_->radio_lyxscale, 1);
495                 setEnabled(lyxview_->input_lyxwidth, 0);
496                 setEnabled(lyxview_->choice_lyxwidth, 0);
497                 setEnabled(lyxview_->input_lyxheight, 0);
498                 setEnabled(lyxview_->choice_lyxheight, 0);
499                 setEnabled(lyxview_->input_lyxscale, 1);
500                 break;
501         }
502         case InsetGraphicsParams::WH: {
503                 fl_set_button(lyxview_->radio_lyxwh, 1);
504                 setEnabled(lyxview_->input_lyxwidth, 1);
505                 setEnabled(lyxview_->choice_lyxwidth, 1);
506                 setEnabled(lyxview_->input_lyxheight, 1);
507                 setEnabled(lyxview_->choice_lyxheight, 1);
508                 setEnabled(lyxview_->check_lyxaspectratio, 1);
509                 setEnabled(lyxview_->input_lyxscale, 0);
510                 break;
511         }
512         }
513         fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
514
515         fl_set_button(lyxview_->check_lyxaspectratio, igp.keepLyXAspectRatio);
516
517         // the size section
518         // Update the draft and clip mode
519         updateWidgetsFromLength(size_->input_width,
520                                 size_->choice_width, igp.width, defaultUnit);
521         updateWidgetsFromLength(size_->input_height,
522                                 size_->choice_height, igp.height, defaultUnit);
523         fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
524         lyxerr[Debug::GRAPHICS] << "FormGraphics::update: igp.size_kind = "
525                                 <<  igp.size_kind << endl;
526         switch (igp.size_kind) {
527         case InsetGraphicsParams::DEFAULT_SIZE: {
528                 fl_set_button(size_->radio_asis,1);
529                 setEnabled(size_->input_width, 0);
530                 setEnabled(size_->choice_width, 0);
531                 setEnabled(size_->input_height, 0);
532                 setEnabled(size_->choice_height, 0);
533                 setEnabled(size_->check_aspectratio, 0);
534                 setEnabled(size_->input_scale, 0);
535                 break;
536         }
537         case InsetGraphicsParams::SCALE: {
538                 fl_set_button(size_->radio_scale, 1);
539                 setEnabled(size_->input_width, 0);
540                 setEnabled(size_->choice_width, 0);
541                 setEnabled(size_->input_height, 0);
542                 setEnabled(size_->choice_height, 0);
543                 setEnabled(size_->check_aspectratio, 0);
544                 setEnabled(size_->input_scale, 1);
545                 break;
546         }
547         case InsetGraphicsParams::WH: {
548                 fl_set_button(size_->radio_wh, 1);
549                 setEnabled(size_->input_width, 1);
550                 setEnabled(size_->choice_width, 1);
551                 setEnabled(size_->input_height, 1);
552                 setEnabled(size_->choice_height, 1);
553                 setEnabled(size_->check_aspectratio, 1);
554                 setEnabled(size_->input_scale, 0);
555                 break;
556         }
557         }
558         fl_set_button(size_->check_aspectratio, igp.keepAspectRatio);
559
560         // the bb section
561         // set the bounding box values, if exists. First we need the whole
562         // path, because the controller knows nothing about the doc-dir
563         updateBB(igp.filename, igp.bb);
564         fl_set_button(bbox_->check_clip, igp.clip);
565
566         // the special section
567         fl_set_input(special_->input_special, igp.special.c_str());
568 }
569
570
571 void FormGraphics::updateBB(string const & filename, string const & bb_inset)
572 {
573         // Update dialog with details from inset
574         // set the bounding box values, if exists. First we need the whole
575         // path, because the controller knows nothing about the doc-dir
576         controller().bbChanged = false;
577         if (bb_inset.empty()) {
578                 lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
579                 string const bb = controller().readBB(filename);
580                 if (!bb.empty()) {
581                         // get the values from the file
582                         // in this case we always have the point-unit
583                         fl_set_input(bbox_->input_bb_x0,
584                                      token(bb,' ',0).c_str());
585                         fl_set_input(bbox_->input_bb_y0,
586                                      token(bb,' ',1).c_str());
587                         fl_set_input(bbox_->input_bb_x1,
588                                      token(bb,' ',2).c_str());
589                         fl_set_input(bbox_->input_bb_y1,
590                                      token(bb,' ',3).c_str());
591
592                 } else {
593                         // no bb from file
594                         fl_set_input(bbox_->input_bb_x0, bb.c_str());
595                         fl_set_input(bbox_->input_bb_y0, bb.c_str());
596                         fl_set_input(bbox_->input_bb_x1, bb.c_str());
597                         fl_set_input(bbox_->input_bb_y1, bb.c_str());
598                 }
599                 // "bp"
600                 fl_set_choice(bbox_->choice_bb_units, 1);
601
602         } else {
603                 // get the values from the inset
604                 lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
605                                         << endl;
606                 controller().bbChanged = true;
607                 LyXLength anyLength;
608                 anyLength = LyXLength(token(bb_inset,' ',0));
609                 updateWidgetsFromLength(bbox_->input_bb_x0,
610                                         bbox_->choice_bb_units,anyLength,"bp");
611                 anyLength = LyXLength(token(bb_inset,' ',1));
612                 updateWidgetsFromLength(bbox_->input_bb_y0,
613                                         bbox_->choice_bb_units,anyLength,"bp");
614                 anyLength = LyXLength(token(bb_inset,' ',2));
615                 updateWidgetsFromLength(bbox_->input_bb_x1,
616                                         bbox_->choice_bb_units,anyLength,"bp");
617                 anyLength = LyXLength(token(bb_inset,' ',3));
618                 updateWidgetsFromLength(bbox_->input_bb_y1,
619                                         bbox_->choice_bb_units,anyLength,"bp");
620         }
621 }
622
623 namespace {
624
625 bool isValid(FL_OBJECT * ob)
626 {
627         string const input = getString(ob);
628         return input.empty() || isValidLength(input) || isStrDbl(input);
629 }
630
631 } // namespace anon
632
633
634
635 ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
636 {
637         // the file section
638         if (ob == file_->button_browse) {
639                 // Get the filename from the dialog
640                 string const in_name = getString(file_->input_filename);
641                 string const out_name = controller().Browse(in_name);
642                 lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
643                 if (out_name != in_name && !out_name.empty()) {
644                         fl_set_input(file_->input_filename, out_name.c_str());
645                 }
646                 if (controller().isFilenameValid(out_name) &&
647                     !controller().bbChanged)
648                         updateBB(out_name, string());
649
650         } else if (ob == file_->check_subcaption) {
651                 setEnabled(file_->input_subcaption,
652                            fl_get_button(file_->check_subcaption));
653         } else if (ob == file_->check_rotate) {
654                 setEnabled(file_->input_rotate_angle,
655                            fl_get_button(file_->check_rotate));
656                 setEnabled(file_->choice_origin,
657                            fl_get_button(file_->check_rotate));
658
659                 // the lyxview section
660         } else if (ob == lyxview_->radio_lyxasis) {
661                 setEnabled(lyxview_->input_lyxwidth, 0);
662                 setEnabled(lyxview_->choice_lyxwidth, 0);
663                 setEnabled(lyxview_->input_lyxheight, 0);
664                 setEnabled(lyxview_->choice_lyxheight, 0);
665                 setEnabled(lyxview_->check_lyxaspectratio, 0);
666                 setEnabled(lyxview_->input_lyxscale, 0);
667         } else if (ob == lyxview_->radio_lyxscale) {
668                 setEnabled(lyxview_->input_lyxwidth, 0);
669                 setEnabled(lyxview_->choice_lyxwidth, 0);
670                 setEnabled(lyxview_->input_lyxheight, 0);
671                 setEnabled(lyxview_->choice_lyxheight, 0);
672                 setEnabled(lyxview_->check_lyxaspectratio, 0);
673                 setEnabled(lyxview_->input_lyxscale, 1);
674         } else if (ob == lyxview_->radio_lyxwh) {
675                 setEnabled(lyxview_->input_lyxwidth, 1);
676                 setEnabled(lyxview_->choice_lyxwidth, 1);
677                 setEnabled(lyxview_->input_lyxheight, 1);
678                 setEnabled(lyxview_->choice_lyxheight, 1);
679                 setEnabled(lyxview_->check_lyxaspectratio, 1);
680                 setEnabled(lyxview_->input_lyxscale, 0);
681         } else if (ob == lyxview_->button_latex_values) {
682                 if (contains(fl_get_choice_text(size_->choice_width),'%') || 
683                         contains(fl_get_choice_text(size_->choice_height),'%'))
684                         Alert::alert(_("Warning!"),
685                                      _("The %-units are not allowed here."),
686                                      _("Cannot use the values from LaTeX size!"));
687                 else {
688                         LyXLength dummy =
689                                 getLyXLengthFromWidgets(size_->input_width,
690                                                         size_->choice_width);
691                         updateWidgetsFromLength(lyxview_->input_lyxwidth,
692                                                 lyxview_->choice_lyxwidth,
693                                                 dummy, defaultUnit);
694
695                         dummy = getLyXLengthFromWidgets(size_->input_height,
696                                                         size_->choice_height);
697                         updateWidgetsFromLength(lyxview_->input_lyxheight,
698                                                 lyxview_->choice_lyxheight,
699                                                 dummy, defaultUnit);
700                         string const scale = getString(size_->input_scale);
701                         fl_set_input(lyxview_->input_lyxscale, scale.c_str());
702                         if (fl_get_button (size_->radio_asis) == 1) {
703                                 fl_set_button (lyxview_->radio_lyxasis, 1);
704                                 setEnabled(lyxview_->input_lyxwidth, 0);
705                                 setEnabled(lyxview_->choice_lyxwidth, 0);
706                                 setEnabled(lyxview_->input_lyxheight, 0);
707                                 setEnabled(lyxview_->choice_lyxheight, 0);
708                                 setEnabled(lyxview_->check_lyxaspectratio, 0);
709                                 setEnabled(lyxview_->input_lyxscale, 0);
710                         } else if (fl_get_button (size_->radio_scale) ==1) {
711                                 fl_set_button (lyxview_->radio_lyxscale, 1);
712                                 setEnabled(lyxview_->input_lyxwidth, 0);
713                                 setEnabled(lyxview_->choice_lyxwidth, 0);
714                                 setEnabled(lyxview_->input_lyxheight, 0);
715                                 setEnabled(lyxview_->choice_lyxheight, 0);
716                                 setEnabled(lyxview_->check_lyxaspectratio, 0);
717                                 setEnabled(lyxview_->input_lyxscale, 1);
718                         } else if (fl_get_button (size_->radio_wh) == 1) {
719                                 fl_set_button (lyxview_->radio_lyxwh, 1);
720                                 setEnabled(lyxview_->input_lyxwidth, 1);
721                                 setEnabled(lyxview_->choice_lyxwidth, 1);
722                                 setEnabled(lyxview_->input_lyxheight, 1);
723                                 setEnabled(lyxview_->choice_lyxheight, 1);
724                                 setEnabled(lyxview_->check_lyxaspectratio, 1);
725                                 setEnabled(lyxview_->input_lyxscale, 0);
726                                 setEnabled(lyxview_->check_lyxaspectratio, 1);
727                         }
728                 }
729                 fl_set_button(lyxview_->check_lyxaspectratio,
730                         fl_get_button(size_->check_aspectratio));
731
732                 // the bb section
733         } else if (!controller().bbChanged &&
734                    (ob == bbox_->check_clip  || ob == bbox_->choice_bb_units ||
735                     ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_y0 ||
736                     ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
737                 controller().bbChanged = true;
738         } else if (ob == bbox_->button_getBB) {
739                 string const filename = getString(file_->input_filename);
740                 if (!filename.empty()) {
741                         string bb = controller().readBB(filename);
742                         if (!bb.empty()) {
743                                 fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
744                                 fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
745                                 fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
746                                 fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
747                                 string const unit("bp");
748                                 fl_set_choice_text(bbox_->choice_bb_units, unit.c_str());
749                         }
750                         controller().bbChanged = false;
751                 } else {
752                         fl_set_input(bbox_->input_bb_x0, "");
753                         fl_set_input(bbox_->input_bb_y0, "");
754                         fl_set_input(bbox_->input_bb_x1, "");
755                         fl_set_input(bbox_->input_bb_y1, "");
756                         fl_set_choice_text(bbox_->choice_bb_units, "bp");
757                 }
758
759                 // the size section
760         } else if (ob == size_->radio_asis) {
761                 setEnabled(size_->input_width, 0);
762                 setEnabled(size_->choice_width, 0);
763                 setEnabled(size_->input_height, 0);
764                 setEnabled(size_->choice_height, 0);
765                 setEnabled(size_->check_aspectratio, 0);
766                 setEnabled(size_->input_scale, 0);
767         } else if (ob == size_->radio_scale) {
768                 setEnabled(size_->input_width, 0);
769                 setEnabled(size_->choice_width, 0);
770                 setEnabled(size_->input_height, 0);
771                 setEnabled(size_->choice_height, 0);
772                 setEnabled(size_->check_aspectratio, 0);
773                 setEnabled(size_->input_scale, 1);
774         } else if (ob == size_->radio_wh) {
775                 setEnabled(size_->input_width, 1);
776                 setEnabled(size_->choice_width, 1);
777                 setEnabled(size_->input_height, 1);
778                 setEnabled(size_->choice_height, 1);
779                 setEnabled(size_->check_aspectratio, 1);
780                 setEnabled(size_->input_scale, 0);
781         } else if (ob == size_->button_lyx_values) {
782                 LyXLength dummy = getLyXLengthFromWidgets(lyxview_->input_lyxwidth,
783                                                           lyxview_->choice_lyxwidth);
784                 updateWidgetsFromLength(size_->input_width,
785                                         size_->choice_width,
786                                         dummy, defaultUnit);
787                 dummy = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
788                                                 lyxview_->choice_lyxheight);
789                 updateWidgetsFromLength(size_->input_height,
790                                         size_->choice_height,
791                                         dummy, defaultUnit);
792                 string const scale = getString(lyxview_->input_lyxscale);
793                 fl_set_input(size_->input_scale, scale.c_str());
794                 if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
795                         fl_set_button (size_->radio_asis, 1);
796                         setEnabled(size_->input_width, 0);
797                         setEnabled(size_->choice_width, 0);
798                         setEnabled(size_->input_height, 0);
799                         setEnabled(size_->choice_height, 0);
800                         setEnabled(size_->check_aspectratio, 0);
801                         setEnabled(size_->input_scale, 0);
802                 } else if (fl_get_button (lyxview_->radio_lyxscale) ==1) {
803                         fl_set_button (size_->radio_scale, 1);
804                         setEnabled(size_->input_width, 0);
805                         setEnabled(size_->choice_width, 0);
806                         setEnabled(size_->input_height, 0);
807                         setEnabled(size_->choice_height, 0);
808                         setEnabled(size_->check_aspectratio, 0);
809                         setEnabled(size_->input_scale, 1);
810                 } else if (fl_get_button (lyxview_->radio_lyxwh) == 1) {
811                         fl_set_button (size_->radio_wh, 1);
812                         setEnabled(size_->input_width, 1);
813                         setEnabled(size_->choice_width, 1);
814                         setEnabled(size_->input_height, 1);
815                         setEnabled(size_->choice_height, 1);
816                         setEnabled(size_->check_aspectratio, 1);
817                         setEnabled(size_->input_scale, 0);
818                 }
819                 fl_set_button(size_->check_aspectratio,
820                               fl_get_button(lyxview_->check_lyxaspectratio));
821         }
822
823         // check if the input is valid
824         bool invalid = !isValid(bbox_->input_bb_x0);
825         invalid = invalid || !isValid(bbox_->input_bb_x1);
826         invalid = invalid || !isValid(bbox_->input_bb_y0);
827         invalid = invalid || !isValid(bbox_->input_bb_y1);
828         invalid = invalid || !isValid(size_->input_width);
829         invalid = invalid || !isValid(size_->input_height);
830         invalid = invalid || !isValid(lyxview_->input_lyxwidth);
831         invalid = invalid || !isValid(lyxview_->input_lyxheight);
832
833         // deactivate OK/ Apply buttons and
834         // spit out warnings if invalid
835         if (ob == bbox_->input_bb_x0 || ob == bbox_->input_bb_x1 ||
836             ob == bbox_->input_bb_y0 || ob == bbox_->input_bb_y1 ||
837             ob == size_->input_width || ob == size_->input_height ||
838             ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
839                 if (invalid) {
840                         postWarning(_("Invalid Length!"));
841                         return ButtonPolicy::SMI_INVALID;
842                 } else {
843                         clearMessage();
844                 }
845         }
846
847         return ButtonPolicy::SMI_VALID;
848 }