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
24 #include <utility> // pair
26 #include "Color.h" // NamedColor
27 #include "xforms_helpers.h" // XformsColor
33 struct FD_form_colors;
34 struct FD_form_converters;
35 struct FD_form_formats;
36 struct FD_form_inputs_misc;
37 struct FD_form_interface;
38 struct FD_form_language;
39 struct FD_form_lnf_misc;
40 struct FD_form_outer_tab;
41 struct FD_form_outputs_misc;
43 struct FD_form_preferences;
44 struct FD_form_printer;
45 struct FD_form_screen_fonts;
46 struct FD_form_spellchecker;
49 /** This class provides an XForms implementation of the FormPreferences Dialog.
50 The preferences dialog allows users to set/save their preferences.
52 class FormPreferences : public FormBaseBI {
54 /// #FormPreferences x(LyXFunc ..., Dialogs ...);#
55 FormPreferences(LyXView *, Dialogs *);
59 static int FeedbackCB(FL_OBJECT *, int,
60 FL_Coord, FL_Coord, int, void *);
63 /// Connect signals etc. Set form's max size.
64 virtual void connect();
65 /// Disconnect signals. Also perform any necessary housekeeping.
66 virtual void disconnect();
67 /** Redraw the form (on receipt of a Signal indicating, for example,
68 that the xforms colours have been re-mapped). */
69 virtual void redraw();
70 /// Update the dialog.
71 virtual void update();
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,
99 std::pair<string,string> const & dir2 );
101 /// Type definitions from the fdesign produced header file.
102 FD_form_preferences * build_preferences();
104 FD_form_outer_tab * build_outer_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_spellchecker * build_spellchecker();
130 /// Real GUI implementation.
131 FD_form_preferences * dialog_;
132 /// Converters tabfolder
133 FD_form_outer_tab * converters_tab_;
134 /// reLyX and other import/input stuff
135 FD_form_outer_tab * inputs_tab_;
136 /// HCI configuration
137 FD_form_outer_tab * look_n_feel_tab_;
138 /// Outputs tabfolder
139 FD_form_outer_tab * outputs_tab_;
140 /// Spellchecker, language stuff, etc
141 FD_form_outer_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 ) : parent_(p), dialog_(0) {}
163 FD_form_colors const * dialog() { return 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 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 ) : parent_(p), dialog_(0) {}
217 FD_form_converters const * dialog() { return 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 FD_form_converters * dialog_;
253 friend class Converters;
259 Formats( FormPreferences & p ) : parent_(p), dialog_(0) {}
263 FD_form_formats const * dialog() { return dialog_; }
269 string const feedback(FL_OBJECT const * const) const;
271 bool input( FL_OBJECT const * const );
281 void UpdateBrowser();
288 FormPreferences & parent_;
290 FD_form_formats * dialog_;
293 friend class Formats;
299 InputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
303 FD_form_inputs_misc const * dialog() { return dialog_; }
309 string const feedback(FL_OBJECT const * const) const;
315 FormPreferences & parent_;
317 FD_form_inputs_misc * dialog_;
320 friend class InputsMisc;
326 Interface( FormPreferences & p ) : parent_(p), dialog_(0) {}
330 FD_form_interface const * dialog() { return dialog_; }
336 string const feedback(FL_OBJECT const * const) const;
338 bool input( FL_OBJECT const * const );
344 FormPreferences & parent_;
346 FD_form_interface * dialog_;
349 friend class Interface;
355 Language( FormPreferences & p )
356 : parent_(p), dialog_(0), combo_default_lang(0) {}
360 FD_form_language const * dialog() { return dialog_; }
362 void apply(); // not const because calls update()
366 string const feedback(FL_OBJECT const * const) const;
368 bool input( FL_OBJECT const * const );
372 static void ComboCB(int, void *, Combox *);
376 FormPreferences & parent_;
378 FD_form_language * dialog_;
380 Combox * combo_default_lang;
383 friend class Language;
389 LnFmisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
393 FD_form_lnf_misc const * dialog() { return dialog_; }
399 string const feedback(FL_OBJECT const * const) const;
405 FormPreferences & parent_;
407 FD_form_lnf_misc * dialog_;
410 friend class LnFmisc;
416 OutputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
420 FD_form_outputs_misc const * dialog() { return dialog_; }
426 string const feedback(FL_OBJECT const * const) const;
432 FormPreferences & parent_;
434 FD_form_outputs_misc * dialog_;
437 friend class OutputsMisc;
443 Paths( FormPreferences & p ) : parent_(p), dialog_(0) {}
447 FD_form_paths const * dialog() { return dialog_; }
453 string const feedback(FL_OBJECT const * const) const;
455 bool input(FL_OBJECT const * const);
461 FormPreferences & parent_;
463 FD_form_paths * dialog_;
472 Printer( FormPreferences & p ) : parent_(p), dialog_(0) {}
476 FD_form_printer const * dialog() { return dialog_; }
482 string const feedback(FL_OBJECT const * const) const;
488 FormPreferences & parent_;
490 FD_form_printer * dialog_;
493 friend class Printer;
499 ScreenFonts( FormPreferences & p ) : parent_(p), dialog_(0) {}
503 FD_form_screen_fonts const * dialog() { return dialog_; }
509 string const feedback(FL_OBJECT const * const) const;
517 FormPreferences & parent_;
519 FD_form_screen_fonts * dialog_;
522 friend class ScreenFonts;
528 SpellChecker( FormPreferences & p ) : parent_(p), dialog_(0) {}
532 FD_form_spellchecker const * dialog() { return dialog_; }
534 void apply(); // not const because calls update()!
538 string const feedback(FL_OBJECT const * const) const;
540 bool input(FL_OBJECT const * const);
546 FormPreferences & parent_;
548 FD_form_spellchecker * dialog_;
551 friend class SpellChecker;
559 Converters converters_;
561 InputsMisc inputs_misc_;
565 Interface interface_;
571 OutputsMisc outputs_misc_;
577 ScreenFonts screen_fonts_;
579 SpellChecker spellchecker_;
581 /** A couple of helper structs to enable colors to be sorted by name
584 struct SortColorsByName {
586 int operator()(NamedColor const & a, NamedColor const & b) const
587 { return (a.getname() < b.getname()); }
590 struct SortColorsByColor {
592 SortColorsByColor(RGBColor c) : col(c) {}
594 int operator()(RGBColor const &, RGBColor const &) const;