]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GExternal.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / gtk / GExternal.C
1 /**
2  * \file GExternal.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bernhard Reiter
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GExternal.h"
22 #include "ControlExternal.h"
23
24 #include "GtkLengthEntry.h"
25
26 #include "ghelpers.h"
27
28 #include "support/lstrings.h"
29 #include "support/convert.h"
30 #include "support/filefilterlist.h"
31
32 #include <libglademm.h>
33
34 #include <vector>
35 #include <string>
36
37 using lyx::support::token;
38 using lyx::support::FileFilterList;
39 using lyx::support::trim;
40
41 using std::string;
42
43
44 namespace lyx {
45 namespace frontend {
46
47 namespace {
48
49 class formatModelColumns : public Gtk::TreeModel::ColumnRecord
50 {
51 public:
52
53         formatModelColumns() { add(name); add(extra); }
54
55         Gtk::TreeModelColumn<Glib::ustring> name;
56         Gtk::TreeModelColumn<Glib::ustring> extra;
57 };
58
59
60 class displayModelColumns : public Gtk::TreeModel::ColumnRecord
61 {
62 public:
63
64         displayModelColumns() { add(name); add(type); }
65
66         Gtk::TreeModelColumn<Glib::ustring> name;
67         Gtk::TreeModelColumn<external::DisplayType> type;
68 };
69
70
71 class templateModelColumns : public Gtk::TreeModel::ColumnRecord
72 {
73 public:
74
75         templateModelColumns() { add(name); add(info); add(filters);}
76
77         Gtk::TreeModelColumn<Glib::ustring> name;
78         Gtk::TreeModelColumn<Glib::ustring> info;
79         Gtk::TreeModelColumn<std::vector<Gtk::FileFilter* > > filters;
80
81 };
82
83
84 formatModelColumns formatColumns;
85
86
87 /* ...ModelColumns singletons, cf. Scott Meyers, Effective C++, Item 47
88  * Needed for proper initialization of the displayModelColumns::type member
89  * which in turn needs to be Glib::Value<>::init'ed in time
90  */
91 displayModelColumns& displayColumns() {
92         static displayModelColumns dC;
93         return dC;
94 }
95
96
97 templateModelColumns& templateColumns() {
98         static templateModelColumns tC;
99         return tC;
100 }
101
102
103 /// Produces a vector of Gtk::FileFilter*s out of the controller's filterstring
104 /// providing sensible descriptions (with alttitle as a fallback)
105 std::vector<Gtk::FileFilter* > get_filters(const std::string & filterstring, const std::string & alttitle)
106 {
107         FileFilterList filterlist(filterstring);
108         std::vector<Gtk::FileFilter* > filters(filterlist.size());
109
110         for (unsigned int i=0; i < filterlist.size(); ++i) {
111                 FileFilterList::Filter ff = filterlist[i];
112
113                 filters[i] = new Gtk::FileFilter();
114                 std::string description = ff.description();
115
116                 if (description.empty())
117                         filters[i]->set_name(Glib::locale_to_utf8(alttitle) +
118                                              " " + lyx::to_utf8(_("files")));
119                 else
120                         filters[i]->set_name(Glib::locale_to_utf8(description));
121
122                 for (FileFilterList::Filter::glob_iterator git = ff.begin();
123                         git!=ff.end(); ++git)
124                         filters[i]->add_pattern(Glib::locale_to_utf8(*git));
125         }
126         return filters;
127 }
128
129
130 void set_display(Gtk::CheckButton * show_check, Gtk::ComboBox * display_combo,
131                  Gtk::Label * display_label, GtkLengthEntry * scale_length,
132                  Gtk::Label * scale_label,
133                  external::DisplayType display, unsigned int scale)
134 {
135
136         typedef Gtk::TreeModel::const_iterator gcit;
137         Glib::RefPtr<const Gtk::TreeModel> const display_store =
138                 display_combo->get_model();
139         bool const no_display = display == external::NoDisplay;
140
141         if (no_display)
142                 display_combo->set_active(
143                         *(display_store->children().begin())); //Default
144         else
145                 for (gcit it = display_store->children().begin();
146                      it != display_store->children().end(); ++it) {
147                         if ((*it)[displayColumns().type] == display) {
148                                 display_combo->set_active(*it);
149                                 break;
150                         }
151                 }
152
153         scale_length->get_spin()->set_value(scale);
154         show_check->set_active(!no_display);
155
156         display_label->set_sensitive(!no_display);
157         display_combo->set_sensitive(!no_display);
158         scale_label->set_sensitive(!no_display);
159         scale_length->set_sensitive(!no_display);
160 }
161
162
163 void get_display(external::DisplayType & display,
164                  unsigned int & scale,
165                  Gtk::CheckButton const * show_check,
166                  Gtk::ComboBox const * display_combo,
167                  GtkLengthEntry const * scale_length)
168 {
169         display = (*(display_combo->get_active()))[displayColumns().type];
170         if (!show_check->get_active())
171                 display = external::NoDisplay;
172         scale = scale_length->get_spin()->get_value_as_int();
173 }
174
175
176 void set_rotation(Gtk::Entry * angle_entry, Gtk::ComboBox * origin_combo,
177                  external::RotationData const & data)
178 {
179         origin_combo->set_active(int(data.origin()));
180         angle_entry->set_text(Glib::locale_to_utf8(data.angle));
181 }
182
183
184 void get_rotation(external::RotationData & data,
185                   Gtk::Entry const * angle_entry,
186                   Gtk::ComboBox const * origin_combo)
187 {
188         typedef external::RotationData::OriginType OriginType;
189
190         data.origin(static_cast<OriginType>(
191                 origin_combo->get_active_row_number()));
192         data.angle = Glib::locale_from_utf8(angle_entry->get_text());
193 }
194
195
196 void set_size(GtkLengthEntry * width_length,
197               GtkLengthEntry * height_length,
198               Gtk::CheckButton * ar_check,
199               external::ResizeData const & data)
200 {
201         bool using_scale = data.usingScale();
202         double scale = convert<double>(data.scale);
203         if (data.no_resize()) {
204                 // Everything is zero, so default to this!
205                 using_scale = true;
206                 scale = 100.0;
207         }
208
209         if (using_scale) {
210                 width_length->get_spin()->set_value(scale);
211                 width_length->get_combo()->set_active_text(
212                                                            lyx::to_utf8(_("Scale%")));
213         } else {
214                 width_length->set_length(data.width);
215         }
216
217         height_length->set_length(data.height);
218         if (!data.width.zero())
219                 height_length->get_combo()->set_active(data.width.unit());
220
221         height_length->set_sensitive(!using_scale);
222
223         ar_check->set_active(data.keepAspectRatio);
224
225         bool const disable_aspectRatio = using_scale ||
226                 data.width.zero() || data.height.zero();
227         ar_check->set_sensitive(!disable_aspectRatio);
228 }
229
230
231 void get_size(external::ResizeData & data,
232               GtkLengthEntry * width_length,
233               GtkLengthEntry * height_length,
234               Gtk::CheckButton * ar_check)
235 {
236         if (width_length->get_combo()->get_active_text() !=
237             lyx::to_utf8(_("Scale%"))) {
238
239                 data.width = width_length->get_length();
240                 data.scale = string();
241         } else {
242                 // scaling instead of a width
243                 data.scale = convert<string>(width_length->get_spin()->get_value());
244                 data.width = LyXLength();
245         }
246
247         data.height = height_length->get_length();
248
249         data.keepAspectRatio = ar_check->get_active();
250 }
251
252
253 void set_crop(Gtk::CheckButton * clip_check,
254               Gtk::Entry * xl_entry, Gtk::Entry * yb_entry,
255               Gtk::Entry * xr_entry, Gtk::Entry * yt_entry,
256               external::ClipData const & data)
257 {
258         clip_check->set_active(data.clip);
259         graphics::BoundingBox const & bbox = data.bbox;
260         xl_entry->set_text(Glib::locale_to_utf8(convert<string>(bbox.xl)));
261         yb_entry->set_text(Glib::locale_to_utf8(convert<string>(bbox.yb)));
262         xr_entry->set_text(Glib::locale_to_utf8(convert<string>(bbox.xr)));
263         yt_entry->set_text(Glib::locale_to_utf8(convert<string>(bbox.yt)));
264
265 }
266
267
268 void get_crop(external::ClipData & data,
269               Gtk::CheckButton const * clip_check,
270               Gtk::Entry const * xl_entry, Gtk::Entry const * yb_entry,
271               Gtk::Entry const * xr_entry, Gtk::Entry const * yt_entry,
272               bool bb_changed)
273 {
274         data.clip = clip_check->get_active();
275
276         if (!bb_changed)
277                 return;
278
279         data.bbox.xl = convert<int>(Glib::locale_from_utf8(xl_entry->get_text()));
280         data.bbox.yb = convert<int>(Glib::locale_from_utf8(yb_entry->get_text()));
281         data.bbox.xr = convert<int>(Glib::locale_from_utf8(xr_entry->get_text()));
282         data.bbox.yt = convert<int>(Glib::locale_from_utf8(yt_entry->get_text()));
283 }
284
285
286 void get_extra(external::ExtraData & data,
287                Glib::RefPtr<Gtk::ListStore> format_store)
288 {
289         Gtk::TreeModel::iterator it  = format_store->children().begin();
290         Gtk::TreeModel::iterator end = format_store->children().end();
291         for (; it != end; ++it)
292                 data.set(Glib::locale_from_utf8((*it)[formatColumns.name]),
293                 trim(Glib::locale_from_utf8((*it)[formatColumns.extra])));
294 }
295
296 } // namespace anon
297
298
299 GExternal::GExternal(Dialog & parent)
300         : GViewCB<ControlExternal, GViewGladeB>(parent, lyx::to_utf8(_("External Settings")), false)
301 {}
302
303
304 void GExternal::doBuild()
305 {
306         string const gladeName = findGladeFile("external");
307         xml_ = Gnome::Glade::Xml::create(gladeName);
308
309         xml_->get_widget("Cancel", cancelbutton_);
310         setCancel(cancelbutton_);
311         xml_->get_widget("Apply", applybutton_);
312         setApply(applybutton_);
313         xml_->get_widget("OK", okbutton_);
314         setOK(okbutton_);
315
316         xml_->get_widget("notebook", notebook_);
317
318         templatestore_ = Gtk::ListStore::create(templateColumns());
319
320         std::vector<string> templates(controller().getTemplates());
321         int count = 0;
322
323         std::vector<std::vector<Gtk::FileFilter> > myfilterlist;
324
325         // Fill the templates combo
326         for (std::vector<string>::const_iterator cit = templates.begin();
327                 cit != templates.end(); ++cit, ++count) {
328                 external::Template templ = controller().getTemplate(count);
329
330                 Gtk::TreeModel::iterator iter = templatestore_->append();
331                 (*iter)[templateColumns().name] = Glib::locale_to_utf8(*cit);
332                 (*iter)[templateColumns().info] =
333                         Glib::locale_to_utf8(templ.helpText);
334                 (*iter)[templateColumns().filters] = get_filters(
335                         controller().getTemplateFilters(*cit),*cit);
336         }
337
338
339         xml_->get_widget("Template", templatecombo_);
340         templatecombo_->pack_start(templateColumns().name);
341         templatecombo_->set_model(templatestore_);
342         templatecombo_->signal_changed().connect(
343                 sigc::mem_fun(*this, &GExternal::template_changed));
344
345         xml_->get_widget("TemplateView", templateview_);
346
347         templatebuffer_ = Gtk::TextBuffer::create();
348         templateview_->set_buffer(templatebuffer_);
349
350         // *** Start "File" Page ***
351         xml_->get_widget("TemplateFile", templatefcbutton_);
352         templatefcbutton_->set_title(lyx::to_utf8(_("Select external file")));
353         templatefcbutton_->signal_file_activated().connect(
354                 sigc::mem_fun(*this, &GExternal::file_changed));
355
356         xml_->get_widget("FileLabel", filelabel_);
357         filelabel_->set_mnemonic_widget(*templatefcbutton_);
358
359         xml_->get_widget("Draft", draftcheck_);
360         xml_->get_widget("EditFile", editfilebutton_);
361         editfilebutton_->signal_clicked().connect(
362                 sigc::mem_fun(*this, &GExternal::edit_clicked));
363         // *** End "File" Page ***
364
365         // *** Start "LyX View" Page ***
366         xml_->get_widget("ShowInLyX", showcheck_);
367         showcheck_->signal_toggled().connect(
368                 sigc::mem_fun(*this, &GExternal::showcheck_toggled));
369
370         xml_->get_widget("DisplayLabel", displaylabel_);
371
372         displaystore_ = Gtk::ListStore::create(displayColumns());
373
374         // Fill the display combo
375         Gtk::TreeModel::iterator iter = displaystore_->append();
376         (*iter)[displayColumns().name] = lyx::to_utf8(_("Default"));
377         (*iter)[displayColumns().type] = external::DefaultDisplay;
378         iter = displaystore_->append();
379         (*iter)[displayColumns().name] = lyx::to_utf8(_("Monochrome"));
380         (*iter)[displayColumns().type] = external::MonochromeDisplay;
381         iter = displaystore_->append();
382         (*iter)[displayColumns().name] = lyx::to_utf8(_("Grayscale"));
383         (*iter)[displayColumns().type] = external::GrayscaleDisplay;
384         iter = displaystore_->append();
385         (*iter)[displayColumns().name] = lyx::to_utf8(_("Color"));
386         (*iter)[displayColumns().type] = external::ColorDisplay;
387         iter = displaystore_->append();
388         (*iter)[displayColumns().name] = lyx::to_utf8(_("Preview"));
389         (*iter)[displayColumns().type] = external::PreviewDisplay;
390
391         xml_->get_widget("Display", displaycombo_);
392         displaycombo_->set_model(displaystore_);
393         displaycombo_->pack_start(displayColumns().name);
394
395         xml_->get_widget_derived ("Scale", scalelength_);
396         scalespin_ = scalelength_->get_spin();
397         scalespin_->set_digits(0);
398         scalespin_->set_range(0,100);
399         scalespin_->set_increments(1,10);
400         scalecombo_ = scalelength_->get_combo();
401         scalecombo_->clear();
402         scalecombo_->append_text(lyx::to_utf8(_("Scale%")));
403         scalecombo_->set_active_text(lyx::to_utf8(_("Scale%")));
404
405         xml_->get_widget("ScaleLabel", scalelabel_);
406         scalelabel_->set_mnemonic_widget(*scalespin_);
407         // *** End "LyX View" Page ***
408
409         // *** Start "Rotate" Page ***
410         xml_->get_widget("Angle", angleentry_);
411
412         Gtk::Box * box = NULL;
413         xml_->get_widget("OriginBox", box);
414         box->pack_start(origincombo_, true, true, 0);
415         box->show_all();
416
417         // Fill the origins combo
418         typedef std::vector<external::RotationDataType> Origins;
419         Origins const & all_origins = external::all_origins();
420         for (Origins::size_type i = 0; i != all_origins.size(); ++i)
421                 origincombo_.append_text(
422                                          external::origin_gui_str(i));
423
424         xml_->get_widget("OriginLabel", originlabel_);
425         originlabel_->set_mnemonic_widget(origincombo_);
426         // *** End "Rotate" Page ***
427
428         // *** Start "Scale" Page ***
429         xml_->get_widget_derived ("Width", widthlength_);
430         widthcombo_ = widthlength_->get_combo();
431         widthcombo_->prepend_text(lyx::to_utf8(_("Scale%")));
432         widthcombo_->set_active_text(lyx::to_utf8(_("Scale%")));
433
434         xml_->get_widget("WidthLabel", widthlabel_);
435         widthlabel_->set_mnemonic_widget(*(widthlength_->get_spin()));
436
437         xml_->get_widget_derived ("Height", heightlength_);
438
439         widthlength_->signal_changed().connect(
440                 sigc::mem_fun(*this, &GExternal::size_changed));
441         heightlength_->signal_changed().connect(
442                 sigc::mem_fun(*this, &GExternal::size_changed));
443
444         xml_->get_widget("HeightLabel", heightlabel_);
445         heightlabel_->set_mnemonic_widget(*(heightlength_->get_spin()));
446
447         xml_->get_widget ("AspectRatio", archeck_);
448         // *** End "Scale" Page ***
449
450         // *** Start "Crop" Page ***
451         xml_->get_widget("Clip", clipcheck_);
452         clipcheck_->signal_toggled().connect(
453                 sigc::mem_fun(*this, &GExternal::clipcheck_toggled));
454
455         xml_->get_widget("GetFromFile", bbfromfilebutton_);
456
457         bbfromfilebutton_->signal_clicked().connect(
458                 sigc::mem_fun(*this, &GExternal::get_bb));
459
460         xml_->get_widget("xLabel", xlabel_);
461         xml_->get_widget("yLabel", ylabel_);
462         xml_->get_widget("RightTopLabel", rtlabel_);
463         xml_->get_widget("LeftBottomLabel", lblabel_);
464
465         xml_->get_widget("xLeft", xlentry_);
466         xlentry_->signal_editing_done().connect(
467                 sigc::mem_fun(*this, &GExternal::bb_changed));
468
469         xml_->get_widget("yBottom", ybentry_);
470         ybentry_->signal_editing_done().connect(
471                 sigc::mem_fun(*this, &GExternal::bb_changed));
472
473         xml_->get_widget("xRight", xrentry_);
474         xrentry_->signal_editing_done().connect(
475                 sigc::mem_fun(*this, &GExternal::bb_changed));
476
477         xml_->get_widget("yTop", ytentry_);
478         ytentry_->signal_editing_done().connect(
479                 sigc::mem_fun(*this, &GExternal::bb_changed));
480
481         // *** End "Crop" Page ***
482
483         // *** Start "Options" Page ***
484         formatstore_ = Gtk::ListStore::create(formatColumns);
485
486         xml_->get_widget("Options", optionsview_);
487         optionsview_->set_model(formatstore_);
488         optionsview_->append_column(lyx::to_utf8(_("Forma_t")), formatColumns.name);
489         optionsview_->append_column_editable(lyx::to_utf8(_("O_ption")), formatColumns.extra);
490         // *** End "Options" Page ***
491 }
492
493
494 void GExternal::update()
495 {
496         InsetExternalParams const & params = controller().params();
497
498         std::string const name = params.filename.outputFilename();
499         templatefcbutton_->set_filename(name);
500
501         if (name != Glib::ustring()) {
502
503                 editfilebutton_->set_sensitive(true);
504                 bbfromfilebutton_->set_sensitive(true);
505         }
506         else {
507                 editfilebutton_->set_sensitive(false);
508                 bbfromfilebutton_->set_sensitive(false);
509         }
510
511         templatecombo_->set_active(
512                 controller().getTemplateNumber(params.templatename()));
513         update_template();
514
515         draftcheck_->set_active(params.draft);
516
517         set_display(showcheck_, displaycombo_, displaylabel_, scalelength_, scalelabel_, params.display, params.lyxscale);
518
519         set_rotation(angleentry_, &origincombo_, params.rotationdata);
520
521         set_size(widthlength_, heightlength_, archeck_, params.resizedata);
522
523         set_crop(clipcheck_,
524                 xlentry_, ybentry_,
525                 xrentry_, ytentry_,
526                 params.clipdata);
527
528         controller().bbChanged(!params.clipdata.bbox.empty());
529 }
530
531
532 void GExternal::update_template()
533 {
534         external::Template templ =
535                 controller().getTemplate(
536                         templatecombo_->get_active_row_number());
537
538         // Remove file stale filters, if present
539         // Keep the current file selected even after a template change
540         Glib::ustring currentfilename;
541
542         typedef std::vector<Gtk::FileFilter* >::iterator ffit;
543         std::vector<Gtk::FileFilter* > templatefilters;
544
545         if (currenttemplate_) {
546                 currentfilename = templatefcbutton_->get_filename();
547                 templatefilters =
548                         (*currenttemplate_)[templateColumns().filters];
549
550                 for (ffit it = templatefilters.begin();
551                          it != templatefilters.end(); ++it)
552                         templatefcbutton_->remove_filter(**it);
553         }
554
555         currenttemplate_ = templatecombo_->get_active();
556
557         templatebuffer_->set_text((*currenttemplate_)[templateColumns().info]);
558
559         // Ascertain which (if any) transformations the template supports
560         // and disable tabs hosting unsupported transforms.
561         typedef std::vector<external::TransformID> TransformIDs;
562         TransformIDs const transformIds = templ.transformIds;
563         TransformIDs::const_iterator tr_begin = transformIds.begin();
564         TransformIDs::const_iterator const tr_end = transformIds.end();
565
566         bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
567         Gtk::Widget * widget = notebook_->get_nth_page(2);
568         widget->set_sensitive(found);
569         notebook_->get_tab_label(*widget)->set_sensitive(found);
570
571         found = find(tr_begin, tr_end, external::Resize) != tr_end;
572         widget = notebook_->get_nth_page(3);
573         widget->set_sensitive(found);
574         notebook_->get_tab_label(*widget)->set_sensitive(found);
575
576         found = find(tr_begin, tr_end, external::Clip) != tr_end;
577         widget = notebook_->get_nth_page(4);
578         widget->set_sensitive(found);
579         notebook_->get_tab_label(*widget)->set_sensitive(found);
580
581         found = find(tr_begin, tr_end, external::Extra) != tr_end;
582         widget = notebook_->get_nth_page(5);
583         widget->set_sensitive(found);
584         notebook_->get_tab_label(*widget)->set_sensitive(found);
585
586         // Add new filters; set the "All files" filter
587         // in order to allow the previously selected file to remain selected
588         templatefilters = (*currenttemplate_)[templateColumns().filters];
589         for (ffit it = templatefilters.begin();
590                 it != templatefilters.end(); ++it)
591                         templatefcbutton_->add_filter(**it);
592
593         templatefcbutton_->set_filter(*templatefilters.back()); // "All files"
594
595         if (currentfilename != Glib::ustring())
596                 templatefcbutton_->set_filename(currentfilename);
597
598         if (!found)
599                 return;
600
601         // Ascertain whether the template has any formats supporting
602         // the 'Extra' option
603         Glib::ustring templatename =
604                         (*currenttemplate_)[templateColumns().name];
605         formatstore_->clear();
606         external::Template::Formats::const_iterator it = templ.formats.begin();
607         external::Template::Formats::const_iterator end = templ.formats.end();
608
609         bool const enabled = (it != end);
610
611         for (; it != end; ++it) {
612                 if (it->second.option_transformers.find(external::Extra) ==
613                     it->second.option_transformers.end())
614                         continue;
615                 string const format = it->first;
616                 string const opt = controller().params().extradata.get(format);
617
618                 Gtk::TreeModel::iterator iter = formatstore_->append();
619                 (*iter)[formatColumns.name] = Glib::locale_to_utf8(format);
620                 (*iter)[formatColumns.extra] = Glib::locale_to_utf8(opt);
621         }
622
623         // widget is still the 'Options' tab
624         notebook_->get_tab_label(*widget)->set_sensitive(enabled);
625 }
626
627
628 void GExternal::apply()
629 {
630         InsetExternalParams params = controller().params();
631
632         params.filename.set(templatefcbutton_->get_filename(),
633                             kernel().bufferFilepath());
634
635         params.settemplate(
636                 Glib::locale_from_utf8((*(templatecombo_->get_active()))[templateColumns().name]));
637
638         params.draft = draftcheck_->get_active();
639
640         get_display(params.display, params.lyxscale,
641                    showcheck_, displaycombo_, scalelength_);
642
643         if (notebook_->get_nth_page(2)->is_sensitive())
644                 get_rotation(params.rotationdata,
645                             angleentry_, &origincombo_);
646
647         if (notebook_->get_nth_page(3)->is_sensitive())
648                 get_size(params.resizedata,
649                          widthlength_, heightlength_, archeck_);
650
651         if (notebook_->get_nth_page(4)->is_sensitive())
652                 get_crop(params.clipdata,
653                         clipcheck_,
654                         xlentry_, ybentry_,
655                         xrentry_, ytentry_,
656                         controller().bbChanged());
657
658         if (notebook_->get_nth_page(5)->is_sensitive())
659                 get_extra(params.extradata, formatstore_);
660
661         controller().setParams(params);
662 }
663
664
665 void GExternal::get_bb()
666 {
667         xlentry_->set_text("0");
668         ybentry_->set_text("0");
669         xrentry_->set_text("0");
670         ytentry_->set_text("0");
671
672         string const filename = templatefcbutton_->get_filename();
673         if (filename.empty())
674                 return;
675
676         string const bb = controller().readBB(filename);
677         if (bb.empty())
678                 return;
679
680         xlentry_->set_text(Glib::locale_to_utf8(token(bb, ' ', 0)));
681         ybentry_->set_text(Glib::locale_to_utf8(token(bb, ' ', 1)));
682         xrentry_->set_text(Glib::locale_to_utf8(token(bb, ' ', 2)));
683         ytentry_->set_text(Glib::locale_to_utf8(token(bb, ' ', 3)));
684
685         controller().bbChanged(false);
686         bc().valid(true);
687 }
688
689
690 bool GExternal::activate_ar() const
691 {
692         if (widthlength_->get_combo()->get_active_text() ==
693             lyx::to_utf8(_("Scale%")))
694                 return false;
695
696         if (widthlength_->get_spin()->get_value() < 0.05)
697                 return false;
698
699         if (heightlength_->get_spin()->get_value() < 0.05)
700                 return false;
701
702         return true;
703 }
704
705
706 void GExternal::bb_changed()
707 {
708         controller().bbChanged(true);
709         bc().valid(true);
710 }
711
712
713 void GExternal::edit_clicked()
714 {
715         controller().editExternal();
716 }
717
718
719 void GExternal::size_changed()
720 {
721         archeck_->set_sensitive(activate_ar());
722
723         bool useHeight = widthlength_->get_combo()->get_active_text() !=
724                 lyx::to_utf8(_("Scale%"));
725
726         heightlength_->set_sensitive(useHeight);
727 }
728
729
730 void GExternal::template_changed()
731 {
732         update_template();
733         bc().valid(true);
734 }
735
736
737 void GExternal::showcheck_toggled()
738 {
739         bool checked = showcheck_->get_active();
740         displaylabel_->set_sensitive(checked);
741         displaycombo_->set_sensitive(checked);
742         scalelabel_->set_sensitive(checked);
743         scalelength_->set_sensitive(checked);
744
745         bc().valid(true);
746 }
747
748
749 void GExternal::clipcheck_toggled()
750 {
751         bool checked = clipcheck_->get_active();
752
753         xlabel_->set_sensitive(checked);
754         ylabel_->set_sensitive(checked);
755         rtlabel_->set_sensitive(checked);
756         lblabel_->set_sensitive(checked);
757
758         xlentry_->set_sensitive(checked);
759         ybentry_->set_sensitive(checked);
760         xrentry_->set_sensitive(checked);
761         ytentry_->set_sensitive(checked);
762
763         bc().valid(true);
764 }
765
766
767 void GExternal::file_changed()
768 {
769         if (templatefcbutton_->get_filename() != Glib::ustring()) {
770
771                 editfilebutton_->set_sensitive(true);
772                 bbfromfilebutton_->set_sensitive(true);
773         }
774         else {
775                 editfilebutton_->set_sensitive(false);
776                 bbfromfilebutton_->set_sensitive(false);
777         }
778         bc().valid(true);
779 }
780
781
782 } // namespace frontend
783 } // namespace lyx