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 "xform_helpers.h" // XformColor
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 xform 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 xform's 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 xform_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 modifiedXformPrefs.
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 modifiedXformPrefs;
180 void AdjustVal( int, int, double ) const;
182 void InputBrowserLyX() const;
184 void InputBrowserX11() const;
188 void LoadBrowserLyX();
190 bool LoadBrowserX11(string const &);
196 int SearchEntry(RGBColor const &) const;
203 FormPreferences & parent_;
205 FD_form_colors * dialog_;
206 /// The usual location of the X11 name database.
207 static string const colorFile;
208 /** A vector of RGB colors and associated name.
209 Each RGB color is unique. */
210 static std::vector<NamedColor> colorDB;
212 /// A vector of LyX LColor GUI name and associated RGB color.
213 std::vector<NamedColor> lyxColorDB;
214 /// A vector of xform color ID, RGB colors and associated name.
215 std::vector<XformColor> xformColorDB;
224 Converters( FormPreferences & p ) : parent_(p), dialog_(0) {}
228 FD_form_converters const * dialog() { return dialog_; }
234 string const feedback(FL_OBJECT const * const) const;
236 bool input( FL_OBJECT const * const );
240 void UpdateBrowser();
242 void UpdateChoices() const;
254 string const GetFrom() const;
256 string const GetTo() const;
259 FormPreferences & parent_;
261 FD_form_converters * dialog_;
264 friend class Converters;
270 Formats( FormPreferences & p ) : parent_(p), dialog_(0) {}
274 FD_form_formats const * dialog() { return dialog_; }
280 string const feedback(FL_OBJECT const * const) const;
282 bool input( FL_OBJECT const * const );
292 void UpdateBrowser();
299 FormPreferences & parent_;
301 FD_form_formats * dialog_;
304 friend class Formats;
310 InputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
314 FD_form_inputs_misc const * dialog() { return dialog_; }
320 string const feedback(FL_OBJECT const * const) const;
326 FormPreferences & parent_;
328 FD_form_inputs_misc * dialog_;
331 friend class InputsMisc;
337 Interface( FormPreferences & p ) : parent_(p), dialog_(0) {}
341 FD_form_interface const * dialog() { return dialog_; }
347 string const feedback(FL_OBJECT const * const) const;
349 bool input( FL_OBJECT const * const );
355 FormPreferences & parent_;
357 FD_form_interface * dialog_;
360 friend class Interface;
366 Language( FormPreferences & p )
367 : parent_(p), dialog_(0), combo_default_lang(0) {}
371 FD_form_language const * dialog() { return dialog_; }
373 void apply(); // not const because calls update()
377 string const feedback(FL_OBJECT const * const) const;
379 bool input( FL_OBJECT const * const );
383 static void ComboCB(int, void *, Combox *);
387 FormPreferences & parent_;
389 FD_form_language * dialog_;
391 Combox * combo_default_lang;
394 friend class Language;
400 LnFmisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
404 FD_form_lnf_misc const * dialog() { return dialog_; }
410 string const feedback(FL_OBJECT const * const) const;
416 FormPreferences & parent_;
418 FD_form_lnf_misc * dialog_;
421 friend class LnFmisc;
427 OutputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
431 FD_form_outputs_misc const * dialog() { return dialog_; }
437 string const feedback(FL_OBJECT const * const) const;
443 FormPreferences & parent_;
445 FD_form_outputs_misc * dialog_;
448 friend class OutputsMisc;
454 Paths( FormPreferences & p ) : parent_(p), dialog_(0) {}
458 FD_form_paths const * dialog() { return dialog_; }
464 string const feedback(FL_OBJECT const * const) const;
466 bool input(FL_OBJECT const * const);
472 FormPreferences & parent_;
474 FD_form_paths * dialog_;
483 Printer( FormPreferences & p ) : parent_(p), dialog_(0) {}
487 FD_form_printer const * dialog() { return dialog_; }
493 string const feedback(FL_OBJECT const * const) const;
499 FormPreferences & parent_;
501 FD_form_printer * dialog_;
504 friend class Printer;
510 ScreenFonts( FormPreferences & p ) : parent_(p), dialog_(0) {}
514 FD_form_screen_fonts const * dialog() { return dialog_; }
520 string const feedback(FL_OBJECT const * const) const;
528 FormPreferences & parent_;
530 FD_form_screen_fonts * dialog_;
533 friend class ScreenFonts;
539 SpellChecker( FormPreferences & p ) : parent_(p), dialog_(0) {}
543 FD_form_spellchecker const * dialog() { return dialog_; }
545 void apply(); // not const because calls update()!
549 string const feedback(FL_OBJECT const * const) const;
551 bool input(FL_OBJECT const * const);
557 FormPreferences & parent_;
559 FD_form_spellchecker * dialog_;
562 friend class SpellChecker;
570 Converters converters_;
572 InputsMisc inputs_misc_;
576 Interface interface_;
582 OutputsMisc outputs_misc_;
588 ScreenFonts screen_fonts_;
590 SpellChecker spellchecker_;
592 /** A couple of helper structs to enable colors to be sorted by name
595 struct SortColorsByName {
597 int operator()(NamedColor const & a, NamedColor const & b) const
598 { return (a.getname() < b.getname()); }
601 struct SortColorsByColor {
603 SortColorsByColor(RGBColor c) : col(c) {}
605 int operator()(RGBColor const &, RGBColor const &) const;