2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * This file copyright 1999-2000
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_outer_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_spellchecker;
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 /// Connect signals etc. Set form's max size.
66 virtual void connect();
67 /// Disconnect signals. Also perform any necessary housekeeping.
68 virtual void disconnect();
69 /** Redraw the form (on receipt of a Signal indicating, for example,
70 that the xforms colours have been re-mapped). */
71 virtual void redraw();
72 /// Update the dialog.
73 virtual void update();
76 /// OK (Save) from dialog
80 /// Filter the inputs -- return true if entries are valid
81 virtual bool input(FL_OBJECT *, long);
84 /// Pointer to the actual instantiation of the xforms form.
85 virtual FL_FORM * form() const;
86 /// control which feedback message is output
87 void feedback(FL_OBJECT *);
89 /// Set the preemptive handler for each FL_OBJECT.
90 static void setPreHandler(FL_OBJECT *);
91 /// The preemptive handler for feedback messages.
92 void Feedback(FL_OBJECT *, int);
93 /// Print a warning message and set warning flag.
94 void printWarning( string const & );
95 /** Launch a file dialog and modify input if it returns a new file.
96 For an explanation of the various parameters, see xforms_helpers.h.
98 void browse( FL_OBJECT * input,
99 string const & title, string const & pattern,
100 std::pair<string,string> const & dir1,
101 std::pair<string,string> const & dir2 );
103 /// Fdesign generated methods
104 FD_form_preferences * build_preferences();
106 FD_form_outer_tab * build_outer_tab();
108 FD_form_colors * build_colors();
110 FD_form_converters * build_converters();
112 FD_form_formats * build_formats();
114 FD_form_inputs_misc * build_inputs_misc();
116 FD_form_interface * build_interface();
118 FD_form_language * build_language();
120 FD_form_lnf_misc * build_lnf_misc();
122 FD_form_outputs_misc * build_outputs_misc();
124 FD_form_paths * build_paths();
126 FD_form_printer * build_printer();
128 FD_form_screen_fonts * build_screen_fonts();
130 FD_form_spellchecker * build_spellchecker();
132 /// Real GUI implementation.
133 boost::scoped_ptr<FD_form_preferences> dialog_;
134 /// Converters tabfolder
135 boost::scoped_ptr<FD_form_outer_tab> converters_tab_;
136 /// reLyX and other import/input stuff
137 boost::scoped_ptr<FD_form_outer_tab> inputs_tab_;
138 /// HCI configuration
139 boost::scoped_ptr<FD_form_outer_tab> look_n_feel_tab_;
140 /// Outputs tabfolder
141 boost::scoped_ptr<FD_form_outer_tab> outputs_tab_;
142 /// Spellchecker, language stuff, etc
143 boost::scoped_ptr<FD_form_outer_tab> lang_opts_tab_;
145 /** Flag whether a warning has been posted to the text window.
146 If so, don't redraw the window when the mouse leaves an object. */
149 /** Each tab folder is encapsulated in its own class.
156 GUI_COLOR_CHOICE = FL_FREE_COL1,
157 GUI_COLOR_HUE_DIAL = FL_FREE_COL2,
158 GUI_COLOR_CURSOR = FL_FREE_COL3
161 Colors( FormPreferences & p );
163 FD_form_colors const * dialog();
165 void apply(); // not const as modifies modifiedXformsPrefs.
169 string const feedback(FL_OBJECT const * const) const;
171 void input(FL_OBJECT const * const);
173 void update() { LoadBrowserLyX(); }
175 /// Flag whether Xforms colors have changed since last file save
176 bool modifiedXformsPrefs;
180 void AdjustVal( int, int, double ) const;
182 void InputBrowserLyX() const;
188 void LoadBrowserLyX();
192 void SwitchColorSpace() const;
194 string const X11hexname(RGBColor const &) const;
197 FormPreferences & parent_;
199 boost::scoped_ptr<FD_form_colors> dialog_;
201 /// A vector of LyX LColor GUI name and associated RGB color.
202 std::vector<NamedColor> lyxColorDB;
203 /// A vector of xforms color ID, RGB colors and associated name.
204 std::vector<XformsColor> xformsColorDB;
213 Converters( FormPreferences & p );
215 FD_form_converters const * dialog();
221 string const feedback(FL_OBJECT const * const) const;
223 bool input( FL_OBJECT const * const );
227 void UpdateBrowser();
229 void UpdateChoices() const;
241 string const GetFrom() const;
243 string const GetTo() const;
246 FormPreferences & parent_;
248 boost::scoped_ptr<FD_form_converters> dialog_;
251 friend class Converters;
257 Formats( FormPreferences & p );
259 FD_form_formats const * dialog();
265 string const feedback(FL_OBJECT const * const) const;
267 bool input( FL_OBJECT const * const );
277 void UpdateBrowser();
284 FormPreferences & parent_;
286 boost::scoped_ptr<FD_form_formats> dialog_;
289 friend class Formats;
295 InputsMisc( FormPreferences & p );
297 FD_form_inputs_misc const * dialog();
303 string const feedback(FL_OBJECT const * const) const;
309 FormPreferences & parent_;
311 boost::scoped_ptr<FD_form_inputs_misc> dialog_;
314 friend class InputsMisc;
320 Interface( FormPreferences & p );
322 FD_form_interface const * dialog();
328 string const feedback(FL_OBJECT const * const) const;
330 bool input( FL_OBJECT const * const );
336 FormPreferences & parent_;
338 boost::scoped_ptr<FD_form_interface> dialog_;
341 friend class Interface;
347 Language( FormPreferences & p );
349 FD_form_language const * dialog();
351 void apply(); // not const because calls update()
355 string const feedback(FL_OBJECT const * const) const;
357 bool input( FL_OBJECT const * const );
361 static void ComboCB(int, void *, Combox *);
365 FormPreferences & parent_;
367 boost::scoped_ptr<FD_form_language> dialog_;
369 boost::scoped_ptr<Combox> combo_default_lang;
372 friend class Language;
378 LnFmisc( FormPreferences & p );
380 FD_form_lnf_misc const * dialog();
386 string const feedback(FL_OBJECT const * const) const;
392 FormPreferences & parent_;
394 boost::scoped_ptr<FD_form_lnf_misc> dialog_;
397 friend class LnFmisc;
403 OutputsMisc( FormPreferences & p );
405 FD_form_outputs_misc const * dialog();
411 string const feedback(FL_OBJECT const * const) const;
417 FormPreferences & parent_;
419 boost::scoped_ptr<FD_form_outputs_misc> dialog_;
422 friend class OutputsMisc;
428 Paths( FormPreferences & p );
430 FD_form_paths const * dialog();
436 string const feedback(FL_OBJECT const * const) const;
438 bool input(FL_OBJECT const * const);
444 FormPreferences & parent_;
446 boost::scoped_ptr<FD_form_paths> dialog_;
455 Printer( FormPreferences & p );
457 FD_form_printer const * dialog();
463 string const feedback(FL_OBJECT const * const) const;
469 FormPreferences & parent_;
471 boost::scoped_ptr<FD_form_printer> dialog_;
474 friend class Printer;
480 ScreenFonts( FormPreferences & p );
482 FD_form_screen_fonts const * dialog();
488 string const feedback(FL_OBJECT const * const) const;
496 FormPreferences & parent_;
498 boost::scoped_ptr<FD_form_screen_fonts> dialog_;
501 friend class ScreenFonts;
507 SpellChecker( FormPreferences & p );
509 FD_form_spellchecker const * dialog();
511 void apply(); // not const because calls update()!
515 string const feedback(FL_OBJECT const * const) const;
517 bool input(FL_OBJECT const * const);
523 FormPreferences & parent_;
525 boost::scoped_ptr<FD_form_spellchecker> dialog_;
528 friend class SpellChecker;
536 Converters converters_;
538 InputsMisc inputs_misc_;
542 Interface interface_;
548 OutputsMisc outputs_misc_;
554 ScreenFonts screen_fonts_;
556 SpellChecker spellchecker_;
558 /** A couple of helper structs to enable colors to be sorted by name
561 struct SortColorsByName {
563 int operator()(NamedColor const & a, NamedColor const & b) const
564 { return (a.getname() < b.getname()); }
567 struct SortColorsByColor {
569 SortColorsByColor(RGBColor c) : col(c) {}
571 int operator()(RGBColor const &, RGBColor const &) const;
575 /// The ButtonController
576 ButtonController<PreferencesPolicy, xformsBC> bc_;
581 xformsBC & FormPreferences::bc()