2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * This file copyright 1999-2001
12 *======================================================*/
14 * FormPreferences Interface Class
17 #ifndef FORMPREFERENCES_H
18 #define FORMPREFERENCES_H
20 #include <utility> // pair
21 #include <boost/smart_ptr.hpp>
27 #include "FormBaseDeprecated.h"
28 #include "Color.h" // NamedColor
29 #include "xforms_helpers.h" // XformColor
35 struct FD_form_colors;
36 struct FD_form_converters;
37 struct FD_form_formats;
38 struct FD_form_inputs_misc;
39 struct FD_form_interface;
40 struct FD_form_language;
41 struct FD_form_lnf_misc;
42 struct FD_form_inner_tab;
43 struct FD_form_outputs_misc;
45 struct FD_form_preferences;
46 struct FD_form_printer;
47 struct FD_form_screen_fonts;
48 struct FD_form_spelloptions;
51 /** This class provides an XForms implementation of the FormPreferences Dialog.
52 The preferences dialog allows users to set/save their preferences.
54 class FormPreferences : public FormBaseBI {
56 /// #FormPreferences x(LyXFunc ..., Dialogs ...);#
57 FormPreferences(LyXView *, Dialogs *);
59 static int FeedbackCB(FL_OBJECT *, int,
60 FL_Coord, FL_Coord, int, void *);
63 /// Pointer to the actual instantiation of the ButtonController.
64 virtual xformsBC & bc();
65 /** Redraw the form (on receipt of a Signal indicating, for example,
66 that the xforms colours have been re-mapped). */
67 virtual void redraw();
68 /// Update the dialog.
69 virtual void update();
70 /// show the spellchecker tab
74 /// OK (Save) from dialog
78 /// Filter the inputs -- return true if entries are valid
79 virtual bool input(FL_OBJECT *, long);
82 /// Pointer to the actual instantiation of the xforms form.
83 virtual FL_FORM * form() const;
84 /// control which feedback message is output
85 void feedback(FL_OBJECT *);
87 /// Set the preemptive handler for each FL_OBJECT.
88 static void setPreHandler(FL_OBJECT *);
89 /// The preemptive handler for feedback messages.
90 void Feedback(FL_OBJECT *, int);
91 /// Print a warning message and set warning flag.
92 void printWarning( string const & );
93 /** Launch a file dialog and modify input if it returns a new file.
94 For an explanation of the various parameters, see xforms_helpers.h.
96 void browse( FL_OBJECT * input,
97 string const & title, string const & pattern,
98 std::pair<string,string> const & dir1= std::make_pair(string(),string()),
99 std::pair<string,string> const & dir2 = std::make_pair(string(),string()));
101 /// Fdesign generated methods
102 FD_form_preferences * build_preferences();
104 FD_form_inner_tab * build_inner_tab();
106 FD_form_colors * build_colors();
108 FD_form_converters * build_converters();
110 FD_form_formats * build_formats();
112 FD_form_inputs_misc * build_inputs_misc();
114 FD_form_interface * build_interface();
116 FD_form_language * build_language();
118 FD_form_lnf_misc * build_lnf_misc();
120 FD_form_outputs_misc * build_outputs_misc();
122 FD_form_paths * build_paths();
124 FD_form_printer * build_printer();
126 FD_form_screen_fonts * build_screen_fonts();
128 FD_form_spelloptions * build_spelloptions();
130 /// Real GUI implementation.
131 boost::scoped_ptr<FD_form_preferences> dialog_;
132 /// Converters tabfolder
133 boost::scoped_ptr<FD_form_inner_tab> converters_tab_;
134 /// reLyX and other import/input stuff
135 boost::scoped_ptr<FD_form_inner_tab> inputs_tab_;
136 /// HCI configuration
137 boost::scoped_ptr<FD_form_inner_tab> look_n_feel_tab_;
138 /// Outputs tabfolder
139 boost::scoped_ptr<FD_form_inner_tab> outputs_tab_;
140 /// Spellchecker, language stuff, etc
141 boost::scoped_ptr<FD_form_inner_tab> lang_opts_tab_;
143 /** Flag whether a warning has been posted to the text window.
144 If so, don't redraw the window when the mouse leaves an object. */
147 /** Each tab folder is encapsulated in its own class.
154 GUI_COLOR_CHOICE = FL_FREE_COL1,
155 GUI_COLOR_HUE_DIAL = FL_FREE_COL2,
156 GUI_COLOR_CURSOR = FL_FREE_COL3
159 Colors( FormPreferences & p );
161 FD_form_colors const * dialog();
163 void apply(); // not const as modifies modifiedXformsPrefs.
167 string const feedback(FL_OBJECT const * const) const;
169 void input(FL_OBJECT const * const);
171 void update() { LoadBrowserLyX(); }
173 /// Flag whether Xforms colors have changed since last file save
174 bool modifiedXformsPrefs;
178 void AdjustVal( int, int, double ) const;
180 void InputBrowserLyX() const;
186 void LoadBrowserLyX();
190 void SwitchColorSpace() const;
192 string const X11hexname(RGBColor const &) const;
195 FormPreferences & parent_;
197 boost::scoped_ptr<FD_form_colors> dialog_;
199 /// A vector of LyX LColor GUI name and associated RGB color.
200 std::vector<NamedColor> lyxColorDB;
201 /// A vector of xforms color ID, RGB colors and associated name.
202 std::vector<XformsColor> xformsColorDB;
211 Converters( FormPreferences & p );
213 FD_form_converters const * dialog();
219 string const feedback(FL_OBJECT const * const) const;
221 bool input( FL_OBJECT const * const );
225 void UpdateBrowser();
227 void UpdateChoices() const;
239 string const GetFrom() const;
241 string const GetTo() const;
244 FormPreferences & parent_;
246 boost::scoped_ptr<FD_form_converters> dialog_;
249 friend class Converters;
255 Formats( FormPreferences & p );
257 FD_form_formats const * dialog();
263 string const feedback(FL_OBJECT const * const) const;
265 bool input( FL_OBJECT const * const );
275 void UpdateBrowser();
282 FormPreferences & parent_;
284 boost::scoped_ptr<FD_form_formats> dialog_;
287 friend class Formats;
293 InputsMisc( FormPreferences & p );
295 FD_form_inputs_misc const * dialog();
301 string const feedback(FL_OBJECT const * const) const;
307 FormPreferences & parent_;
309 boost::scoped_ptr<FD_form_inputs_misc> dialog_;
312 friend class InputsMisc;
318 Interface( FormPreferences & p );
320 FD_form_interface const * dialog();
326 string const feedback(FL_OBJECT const * const) const;
328 bool input( FL_OBJECT const * const );
334 FormPreferences & parent_;
336 boost::scoped_ptr<FD_form_interface> dialog_;
339 friend class Interface;
345 Language( FormPreferences & p );
347 FD_form_language const * dialog();
349 void apply(); // not const because calls update()
353 string const feedback(FL_OBJECT const * const) const;
355 bool input( FL_OBJECT const * const );
359 static void ComboCB(int, void *, Combox *);
363 FormPreferences & parent_;
365 boost::scoped_ptr<FD_form_language> dialog_;
367 boost::scoped_ptr<Combox> combo_default_lang;
370 friend class Language;
376 LnFmisc( FormPreferences & p );
378 FD_form_lnf_misc const * dialog();
384 string const feedback(FL_OBJECT const * const) const;
390 FormPreferences & parent_;
392 boost::scoped_ptr<FD_form_lnf_misc> dialog_;
395 friend class LnFmisc;
401 OutputsMisc( FormPreferences & p );
403 FD_form_outputs_misc const * dialog();
409 string const feedback(FL_OBJECT const * const) const;
415 FormPreferences & parent_;
417 boost::scoped_ptr<FD_form_outputs_misc> dialog_;
420 friend class OutputsMisc;
426 Paths( FormPreferences & p );
428 FD_form_paths const * dialog();
434 string const feedback(FL_OBJECT const * const) const;
436 bool input(FL_OBJECT const * const);
442 FormPreferences & parent_;
444 boost::scoped_ptr<FD_form_paths> dialog_;
453 Printer( FormPreferences & p );
455 FD_form_printer const * dialog();
461 string const feedback(FL_OBJECT const * const) const;
467 FormPreferences & parent_;
469 boost::scoped_ptr<FD_form_printer> dialog_;
472 friend class Printer;
478 ScreenFonts( FormPreferences & p );
480 FD_form_screen_fonts const * dialog();
486 string const feedback(FL_OBJECT const * const) const;
494 FormPreferences & parent_;
496 boost::scoped_ptr<FD_form_screen_fonts> dialog_;
499 friend class ScreenFonts;
505 SpellOptions( FormPreferences & p );
507 FD_form_spelloptions const * dialog();
509 void apply(); // not const because calls update()!
513 string const feedback(FL_OBJECT const * const) const;
515 bool input(FL_OBJECT const * const);
521 FormPreferences & parent_;
523 boost::scoped_ptr<FD_form_spelloptions> dialog_;
526 friend class SpellOptions;
534 Converters converters_;
536 InputsMisc inputs_misc_;
540 Interface interface_;
546 OutputsMisc outputs_misc_;
552 ScreenFonts screen_fonts_;
554 SpellOptions spelloptions_;
556 /** A couple of helper structs to enable colors to be sorted by name
559 struct SortColorsByName {
561 int operator()(NamedColor const & a, NamedColor const & b) const
562 { return (a.getname() < b.getname()); }
565 struct SortColorsByColor {
567 SortColorsByColor(RGBColor c) : col(c) {}
569 int operator()(RGBColor const &, RGBColor const &) const;
573 /// The ButtonController
574 ButtonController<PreferencesPolicy, xformsBC> bc_;
579 xformsBC & FormPreferences::bc()