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_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_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 /// 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();
74 /// show the spellchecker tab
78 /// OK (Save) from dialog
82 /// Filter the inputs -- return true if entries are valid
83 virtual bool input(FL_OBJECT *, long);
86 /// Pointer to the actual instantiation of the xforms form.
87 virtual FL_FORM * form() const;
88 /// control which feedback message is output
89 void feedback(FL_OBJECT *);
91 /// Set the preemptive handler for each FL_OBJECT.
92 static void setPreHandler(FL_OBJECT *);
93 /// The preemptive handler for feedback messages.
94 void Feedback(FL_OBJECT *, int);
95 /// Print a warning message and set warning flag.
96 void printWarning( string const & );
97 /** Launch a file dialog and modify input if it returns a new file.
98 For an explanation of the various parameters, see xforms_helpers.h.
100 void browse( FL_OBJECT * input,
101 string const & title, string const & pattern,
102 std::pair<string,string> const & dir1,
103 std::pair<string,string> const & dir2 );
105 /// Fdesign generated methods
106 FD_form_preferences * build_preferences();
108 FD_form_outer_tab * build_outer_tab();
110 FD_form_colors * build_colors();
112 FD_form_converters * build_converters();
114 FD_form_formats * build_formats();
116 FD_form_inputs_misc * build_inputs_misc();
118 FD_form_interface * build_interface();
120 FD_form_language * build_language();
122 FD_form_lnf_misc * build_lnf_misc();
124 FD_form_outputs_misc * build_outputs_misc();
126 FD_form_paths * build_paths();
128 FD_form_printer * build_printer();
130 FD_form_screen_fonts * build_screen_fonts();
132 FD_form_spelloptions * build_spelloptions();
134 /// Real GUI implementation.
135 boost::scoped_ptr<FD_form_preferences> dialog_;
136 /// Converters tabfolder
137 boost::scoped_ptr<FD_form_outer_tab> converters_tab_;
138 /// reLyX and other import/input stuff
139 boost::scoped_ptr<FD_form_outer_tab> inputs_tab_;
140 /// HCI configuration
141 boost::scoped_ptr<FD_form_outer_tab> look_n_feel_tab_;
142 /// Outputs tabfolder
143 boost::scoped_ptr<FD_form_outer_tab> outputs_tab_;
144 /// Spellchecker, language stuff, etc
145 boost::scoped_ptr<FD_form_outer_tab> lang_opts_tab_;
147 /** Flag whether a warning has been posted to the text window.
148 If so, don't redraw the window when the mouse leaves an object. */
151 /** Each tab folder is encapsulated in its own class.
158 GUI_COLOR_CHOICE = FL_FREE_COL1,
159 GUI_COLOR_HUE_DIAL = FL_FREE_COL2,
160 GUI_COLOR_CURSOR = FL_FREE_COL3
163 Colors( FormPreferences & p );
165 FD_form_colors const * dialog();
167 void apply(); // not const as modifies modifiedXformsPrefs.
171 string const feedback(FL_OBJECT const * const) const;
173 void input(FL_OBJECT const * const);
175 void update() { LoadBrowserLyX(); }
177 /// Flag whether Xforms colors have changed since last file save
178 bool modifiedXformsPrefs;
182 void AdjustVal( int, int, double ) const;
184 void InputBrowserLyX() const;
190 void LoadBrowserLyX();
194 void SwitchColorSpace() const;
196 string const X11hexname(RGBColor const &) const;
199 FormPreferences & parent_;
201 boost::scoped_ptr<FD_form_colors> dialog_;
203 /// A vector of LyX LColor GUI name and associated RGB color.
204 std::vector<NamedColor> lyxColorDB;
205 /// A vector of xforms color ID, RGB colors and associated name.
206 std::vector<XformsColor> xformsColorDB;
215 Converters( FormPreferences & p );
217 FD_form_converters const * dialog();
223 string const feedback(FL_OBJECT const * const) const;
225 bool input( FL_OBJECT const * const );
229 void UpdateBrowser();
231 void UpdateChoices() const;
243 string const GetFrom() const;
245 string const GetTo() const;
248 FormPreferences & parent_;
250 boost::scoped_ptr<FD_form_converters> dialog_;
253 friend class Converters;
259 Formats( FormPreferences & p );
261 FD_form_formats const * dialog();
267 string const feedback(FL_OBJECT const * const) const;
269 bool input( FL_OBJECT const * const );
279 void UpdateBrowser();
286 FormPreferences & parent_;
288 boost::scoped_ptr<FD_form_formats> dialog_;
291 friend class Formats;
297 InputsMisc( FormPreferences & p );
299 FD_form_inputs_misc const * dialog();
305 string const feedback(FL_OBJECT const * const) const;
311 FormPreferences & parent_;
313 boost::scoped_ptr<FD_form_inputs_misc> dialog_;
316 friend class InputsMisc;
322 Interface( FormPreferences & p );
324 FD_form_interface const * dialog();
330 string const feedback(FL_OBJECT const * const) const;
332 bool input( FL_OBJECT const * const );
338 FormPreferences & parent_;
340 boost::scoped_ptr<FD_form_interface> dialog_;
343 friend class Interface;
349 Language( FormPreferences & p );
351 FD_form_language const * dialog();
353 void apply(); // not const because calls update()
357 string const feedback(FL_OBJECT const * const) const;
359 bool input( FL_OBJECT const * const );
363 static void ComboCB(int, void *, Combox *);
367 FormPreferences & parent_;
369 boost::scoped_ptr<FD_form_language> dialog_;
371 boost::scoped_ptr<Combox> combo_default_lang;
374 friend class Language;
380 LnFmisc( FormPreferences & p );
382 FD_form_lnf_misc const * dialog();
388 string const feedback(FL_OBJECT const * const) const;
394 FormPreferences & parent_;
396 boost::scoped_ptr<FD_form_lnf_misc> dialog_;
399 friend class LnFmisc;
405 OutputsMisc( FormPreferences & p );
407 FD_form_outputs_misc const * dialog();
413 string const feedback(FL_OBJECT const * const) const;
419 FormPreferences & parent_;
421 boost::scoped_ptr<FD_form_outputs_misc> dialog_;
424 friend class OutputsMisc;
430 Paths( FormPreferences & p );
432 FD_form_paths const * dialog();
438 string const feedback(FL_OBJECT const * const) const;
440 bool input(FL_OBJECT const * const);
446 FormPreferences & parent_;
448 boost::scoped_ptr<FD_form_paths> dialog_;
457 Printer( FormPreferences & p );
459 FD_form_printer const * dialog();
465 string const feedback(FL_OBJECT const * const) const;
471 FormPreferences & parent_;
473 boost::scoped_ptr<FD_form_printer> dialog_;
476 friend class Printer;
482 ScreenFonts( FormPreferences & p );
484 FD_form_screen_fonts const * dialog();
490 string const feedback(FL_OBJECT const * const) const;
498 FormPreferences & parent_;
500 boost::scoped_ptr<FD_form_screen_fonts> dialog_;
503 friend class ScreenFonts;
509 SpellOptions( FormPreferences & p );
511 FD_form_spelloptions const * dialog();
513 void apply(); // not const because calls update()!
517 string const feedback(FL_OBJECT const * const) const;
519 bool input(FL_OBJECT const * const);
525 FormPreferences & parent_;
527 boost::scoped_ptr<FD_form_spelloptions> dialog_;
530 friend class SpellOptions;
538 Converters converters_;
540 InputsMisc inputs_misc_;
544 Interface interface_;
550 OutputsMisc outputs_misc_;
556 ScreenFonts screen_fonts_;
558 SpellOptions spelloptions_;
560 /** A couple of helper structs to enable colors to be sorted by name
563 struct SortColorsByName {
565 int operator()(NamedColor const & a, NamedColor const & b) const
566 { return (a.getname() < b.getname()); }
569 struct SortColorsByColor {
571 SortColorsByColor(RGBColor c) : col(c) {}
573 int operator()(RGBColor const &, RGBColor const &) const;
577 /// The ButtonController
578 ButtonController<PreferencesPolicy, xformsBC> bc_;
583 xformsBC & FormPreferences::bc()