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
36 struct FD_form_colors;
37 struct FD_form_converters;
38 struct FD_form_formats;
39 struct FD_form_inputs_misc;
40 struct FD_form_interface;
41 struct FD_form_language;
42 struct FD_form_lnf_misc;
43 struct FD_form_outer_tab;
44 struct FD_form_outputs_misc;
46 struct FD_form_preferences;
47 struct FD_form_printer;
48 struct FD_form_screen_fonts;
49 struct FD_form_spellchecker;
52 /** This class provides an XForms implementation of the FormPreferences Dialog.
53 The preferences dialog allows users to set/save their preferences.
55 class FormPreferences : public FormBaseBI {
57 /// #FormPreferences x(LyXFunc ..., Dialogs ...);#
58 FormPreferences(LyXView *, Dialogs *);
60 static int FeedbackCB(FL_OBJECT *, int,
61 FL_Coord, FL_Coord, int, void *);
64 /// Pointer to the actual instantiation of the ButtonController.
65 virtual xformsBC & bc();
66 /// Connect signals etc. Set form's max size.
67 virtual void connect();
68 /// Disconnect signals. Also perform any necessary housekeeping.
69 virtual void disconnect();
70 /** Redraw the form (on receipt of a Signal indicating, for example,
71 that the xforms colours have been re-mapped). */
72 virtual void redraw();
73 /// Update the dialog.
74 virtual void update();
77 /// OK (Save) from dialog
81 /// Filter the inputs -- return true if entries are valid
82 virtual bool input(FL_OBJECT *, long);
85 /// Pointer to the actual instantiation of the xforms form.
86 virtual FL_FORM * form() const;
87 /// control which feedback message is output
88 void feedback(FL_OBJECT *);
90 /// Set the preemptive handler for each FL_OBJECT.
91 static void setPreHandler(FL_OBJECT *);
92 /// The preemptive handler for feedback messages.
93 void Feedback(FL_OBJECT *, int);
94 /// Print a warning message and set warning flag.
95 void printWarning( string const & );
96 /** Launch a file dialog and modify input if it returns a new file.
97 For an explanation of the various parameters, see xforms_helpers.h.
99 void browse( FL_OBJECT * input,
100 string const & title, string const & pattern,
101 std::pair<string,string> const & dir1,
102 std::pair<string,string> const & dir2 );
104 /// Type definitions from the fdesign produced header file.
105 FD_form_preferences * build_preferences();
107 FD_form_outer_tab * build_outer_tab();
109 FD_form_colors * build_colors();
111 FD_form_converters * build_converters();
113 FD_form_formats * build_formats();
115 FD_form_inputs_misc * build_inputs_misc();
117 FD_form_interface * build_interface();
119 FD_form_language * build_language();
121 FD_form_lnf_misc * build_lnf_misc();
123 FD_form_outputs_misc * build_outputs_misc();
125 FD_form_paths * build_paths();
127 FD_form_printer * build_printer();
129 FD_form_screen_fonts * build_screen_fonts();
131 FD_form_spellchecker * build_spellchecker();
133 /// Real GUI implementation.
134 boost::scoped_ptr<FD_form_preferences> dialog_;
135 /// Converters tabfolder
136 boost::scoped_ptr<FD_form_outer_tab> converters_tab_;
137 /// reLyX and other import/input stuff
138 boost::scoped_ptr<FD_form_outer_tab> inputs_tab_;
139 /// HCI configuration
140 boost::scoped_ptr<FD_form_outer_tab> look_n_feel_tab_;
141 /// Outputs tabfolder
142 boost::scoped_ptr<FD_form_outer_tab> outputs_tab_;
143 /// Spellchecker, language stuff, etc
144 boost::scoped_ptr<FD_form_outer_tab> lang_opts_tab_;
146 /** Flag whether a warning has been posted to the text window.
147 If so, don't redraw the window when the mouse leaves an object. */
150 /** Each tab folder is encapsulated in its own class.
157 GUI_COLOR_CHOICE = FL_FREE_COL1,
158 GUI_COLOR_HUE_DIAL = FL_FREE_COL2,
159 GUI_COLOR_CURSOR = FL_FREE_COL3
162 Colors( FormPreferences & p );
164 FD_form_colors const * dialog();
166 void apply(); // not const as modifies modifiedXformsPrefs.
170 string const feedback(FL_OBJECT const * const) const;
172 void input(FL_OBJECT const * const);
174 void update() { LoadBrowserLyX(); }
176 /// Flag whether Xforms colors have changed since last file save
177 bool modifiedXformsPrefs;
181 void AdjustVal( int, int, double ) const;
183 void InputBrowserLyX() const;
189 void LoadBrowserLyX();
193 void SwitchColorSpace() const;
195 string const X11hexname(RGBColor const &) const;
198 FormPreferences & parent_;
200 boost::scoped_ptr<FD_form_colors> dialog_;
202 /// A vector of LyX LColor GUI name and associated RGB color.
203 std::vector<NamedColor> lyxColorDB;
204 /// A vector of xforms color ID, RGB colors and associated name.
205 std::vector<XformsColor> xformsColorDB;
214 Converters( FormPreferences & p );
216 FD_form_converters const * dialog();
222 string const feedback(FL_OBJECT const * const) const;
224 bool input( FL_OBJECT const * const );
228 void UpdateBrowser();
230 void UpdateChoices() const;
242 string const GetFrom() const;
244 string const GetTo() const;
247 FormPreferences & parent_;
249 boost::scoped_ptr<FD_form_converters> dialog_;
252 friend class Converters;
258 Formats( FormPreferences & p );
260 FD_form_formats const * dialog();
266 string const feedback(FL_OBJECT const * const) const;
268 bool input( FL_OBJECT const * const );
278 void UpdateBrowser();
285 FormPreferences & parent_;
287 boost::scoped_ptr<FD_form_formats> dialog_;
290 friend class Formats;
296 InputsMisc( FormPreferences & p );
298 FD_form_inputs_misc const * dialog();
304 string const feedback(FL_OBJECT const * const) const;
310 FormPreferences & parent_;
312 boost::scoped_ptr<FD_form_inputs_misc> dialog_;
315 friend class InputsMisc;
321 Interface( FormPreferences & p );
323 FD_form_interface const * dialog();
329 string const feedback(FL_OBJECT const * const) const;
331 bool input( FL_OBJECT const * const );
337 FormPreferences & parent_;
339 boost::scoped_ptr<FD_form_interface> dialog_;
342 friend class Interface;
348 Language( FormPreferences & p );
350 FD_form_language const * dialog();
352 void apply(); // not const because calls update()
356 string const feedback(FL_OBJECT const * const) const;
358 bool input( FL_OBJECT const * const );
362 static void ComboCB(int, void *, Combox *);
366 FormPreferences & parent_;
368 boost::scoped_ptr<FD_form_language> dialog_;
370 boost::scoped_ptr<Combox> combo_default_lang;
373 friend class Language;
379 LnFmisc( FormPreferences & p );
381 FD_form_lnf_misc const * dialog();
387 string const feedback(FL_OBJECT const * const) const;
393 FormPreferences & parent_;
395 boost::scoped_ptr<FD_form_lnf_misc> dialog_;
398 friend class LnFmisc;
404 OutputsMisc( FormPreferences & p );
406 FD_form_outputs_misc const * dialog();
412 string const feedback(FL_OBJECT const * const) const;
418 FormPreferences & parent_;
420 boost::scoped_ptr<FD_form_outputs_misc> dialog_;
423 friend class OutputsMisc;
429 Paths( FormPreferences & p );
431 FD_form_paths const * dialog();
437 string const feedback(FL_OBJECT const * const) const;
439 bool input(FL_OBJECT const * const);
445 FormPreferences & parent_;
447 boost::scoped_ptr<FD_form_paths> dialog_;
456 Printer( FormPreferences & p );
458 FD_form_printer const * dialog();
464 string const feedback(FL_OBJECT const * const) const;
470 FormPreferences & parent_;
472 boost::scoped_ptr<FD_form_printer> dialog_;
475 friend class Printer;
481 ScreenFonts( FormPreferences & p );
483 FD_form_screen_fonts const * dialog();
489 string const feedback(FL_OBJECT const * const) const;
497 FormPreferences & parent_;
499 boost::scoped_ptr<FD_form_screen_fonts> dialog_;
502 friend class ScreenFonts;
508 SpellChecker( FormPreferences & p );
510 FD_form_spellchecker const * dialog();
512 void apply(); // not const because calls update()!
516 string const feedback(FL_OBJECT const * const) const;
518 bool input(FL_OBJECT const * const);
524 FormPreferences & parent_;
526 boost::scoped_ptr<FD_form_spellchecker> dialog_;
529 friend class SpellChecker;
537 Converters converters_;
539 InputsMisc inputs_misc_;
543 Interface interface_;
549 OutputsMisc outputs_misc_;
555 ScreenFonts screen_fonts_;
557 SpellChecker spellchecker_;
559 /** A couple of helper structs to enable colors to be sorted by name
562 struct SortColorsByName {
564 int operator()(NamedColor const & a, NamedColor const & b) const
565 { return (a.getname() < b.getname()); }
568 struct SortColorsByColor {
570 SortColorsByColor(RGBColor c) : col(c) {}
572 int operator()(RGBColor const &, RGBColor const &) const;
576 /// The ButtonController
577 ButtonController<PreferencesPolicy, xformsBC> bc_;
582 xformsBC & FormPreferences::bc()