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 /** Redraw the form (on receipt of a Signal indicating, for example,
64 that the xform colours have been re-mapped). */
65 virtual void redraw();
66 /// Update the dialog.
67 virtual void update();
70 /// OK (Save) from dialog
74 /// Filter the inputs -- return true if entries are valid
75 virtual bool input(FL_OBJECT *, long);
78 /// Pointer to the actual instantiation of xform's form.
79 virtual FL_FORM * form() const;
80 /// control which feedback message is output
81 void feedback(FL_OBJECT *);
83 /// Set the preemptive handler for each FL_OBJECT.
84 static void setPreHandler(FL_OBJECT *);
85 /// The preemptive handler for feedback messages.
86 void Feedback(FL_OBJECT *, int);
87 /// Print a warning message and set warning flag.
88 void printWarning( string const & );
89 /** Launch a file dialog and modify input if it returns a new file.
90 For an explanation of the various parameters, see xform_helpers.h.
92 void browse( FL_OBJECT * input,
93 string const & title, string const & pattern,
94 std::pair<string,string> const & dir1,
95 std::pair<string,string> const & dir2 );
97 /// Type definitions from the fdesign produced header file.
98 FD_form_preferences * build_preferences();
100 FD_form_outer_tab * build_outer_tab();
102 FD_form_colors * build_colors();
104 FD_form_converters * build_converters();
106 FD_form_formats * build_formats();
108 FD_form_inputs_misc * build_inputs_misc();
110 FD_form_interface * build_interface();
112 FD_form_language * build_language();
114 FD_form_lnf_misc * build_lnf_misc();
116 FD_form_outputs_misc * build_outputs_misc();
118 FD_form_paths * build_paths();
120 FD_form_printer * build_printer();
122 FD_form_screen_fonts * build_screen_fonts();
124 FD_form_spellchecker * build_spellchecker();
126 /// Real GUI implementation.
127 FD_form_preferences * dialog_;
128 /// Converters tabfolder
129 FD_form_outer_tab * converters_tab_;
130 /// reLyX and other import/input stuff
131 FD_form_outer_tab * inputs_tab_;
132 /// HCI configuration
133 FD_form_outer_tab * look_n_feel_tab_;
134 /// Outputs tabfolder
135 FD_form_outer_tab * outputs_tab_;
136 /// Spellchecker, language stuff, etc
137 FD_form_outer_tab * usage_tab_;
139 /** Flag whether a warning has been posted to the text window.
140 If so, don't redraw the window when the mouse leaves an object. */
143 /** Each tab folder is encapsulated in its own class.
149 Colors( FormPreferences & p ) : parent_(p), dialog_(0) {}
153 FD_form_colors const * dialog() { return dialog_; }
155 void apply(); // not const as modifies modifiedXformPrefs.
159 string const feedback(FL_OBJECT const * const) const;
161 bool input(FL_OBJECT const * const);
163 void update() { LoadBrowserLyX(); }
165 /// Flag whether Xforms colors have changed since last file save
166 bool modifiedXformPrefs;
170 void AdjustVal( int, int, double ) const;
172 bool InputBrowserLyX() const;
174 bool InputBrowserX11() const;
178 void LoadBrowserLyX();
180 bool LoadBrowserX11(string const &);
186 int SearchEntry(RGBColor const &) const;
193 FormPreferences & parent_;
195 FD_form_colors * dialog_;
196 /// The usual location of the X11 name database.
197 static string const colorFile;
198 /** A vector of RGB colors and associated name.
199 Each RGB color is unique. */
200 static std::vector<NamedColor> colorDB;
202 /// A vector of LyX LColor GUI name and associated RGB color.
203 std::vector<NamedColor> lyxColorDB;
204 /// A vector of xform color ID, RGB colors and associated name.
205 std::vector<XformColor> xformColorDB;
214 Converters( FormPreferences & p ) : parent_(p), dialog_(0) {}
218 FD_form_converters const * dialog() { return dialog_; }
224 string const feedback(FL_OBJECT const * const) const;
226 bool input( FL_OBJECT const * const );
230 void UpdateBrowser();
232 void UpdateChoices() const;
244 string const GetFrom() const;
246 string const GetTo() const;
249 FormPreferences & parent_;
251 FD_form_converters * dialog_;
254 friend class Converters;
260 Formats( FormPreferences & p ) : parent_(p), dialog_(0) {}
264 FD_form_formats const * dialog() { return dialog_; }
270 string const feedback(FL_OBJECT const * const) const;
272 bool input( FL_OBJECT const * const );
282 void UpdateBrowser();
289 FormPreferences & parent_;
291 FD_form_formats * dialog_;
294 friend class Formats;
300 InputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
304 FD_form_inputs_misc const * dialog() { return dialog_; }
310 string const feedback(FL_OBJECT const * const) const;
316 FormPreferences & parent_;
318 FD_form_inputs_misc * dialog_;
321 friend class InputsMisc;
327 Interface( FormPreferences & p ) : parent_(p), dialog_(0) {}
331 FD_form_interface const * dialog() { return dialog_; }
337 string const feedback(FL_OBJECT const * const) const;
339 bool input( FL_OBJECT const * const );
345 FormPreferences & parent_;
347 FD_form_interface * dialog_;
350 friend class Interface;
356 Language( FormPreferences & p )
357 : parent_(p), dialog_(0), combo_default_lang(0) {}
361 FD_form_language const * dialog() { return dialog_; }
363 void apply(); // not const because calls update()
367 string const feedback(FL_OBJECT const * const) const;
369 bool input( FL_OBJECT const * const );
373 static void ComboCB(int, void *, Combox *);
377 FormPreferences & parent_;
379 FD_form_language * dialog_;
381 Combox * combo_default_lang;
384 friend class Language;
390 LnFmisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
394 FD_form_lnf_misc const * dialog() { return dialog_; }
400 string const feedback(FL_OBJECT const * const) const;
406 FormPreferences & parent_;
408 FD_form_lnf_misc * dialog_;
411 friend class LnFmisc;
417 OutputsMisc( FormPreferences & p ) : parent_(p), dialog_(0) {}
421 FD_form_outputs_misc const * dialog() { return dialog_; }
427 string const feedback(FL_OBJECT const * const) const;
433 FormPreferences & parent_;
435 FD_form_outputs_misc * dialog_;
438 friend class OutputsMisc;
444 Paths( FormPreferences & p ) : parent_(p), dialog_(0) {}
448 FD_form_paths const * dialog() { return dialog_; }
454 string const feedback(FL_OBJECT const * const) const;
456 bool input(FL_OBJECT const * const);
462 FormPreferences & parent_;
464 FD_form_paths * dialog_;
473 Printer( FormPreferences & p ) : parent_(p), dialog_(0) {}
477 FD_form_printer const * dialog() { return dialog_; }
483 string const feedback(FL_OBJECT const * const) const;
489 FormPreferences & parent_;
491 FD_form_printer * dialog_;
494 friend class Printer;
500 ScreenFonts( FormPreferences & p ) : parent_(p), dialog_(0) {}
504 FD_form_screen_fonts const * dialog() { return dialog_; }
510 string const feedback(FL_OBJECT const * const) const;
518 FormPreferences & parent_;
520 FD_form_screen_fonts * dialog_;
523 friend class ScreenFonts;
529 SpellChecker( FormPreferences & p ) : parent_(p), dialog_(0) {}
533 FD_form_spellchecker const * dialog() { return dialog_; }
535 void apply(); // not const because calls update()!
539 string const feedback(FL_OBJECT const * const) const;
541 bool input(FL_OBJECT const * const);
547 FormPreferences & parent_;
549 FD_form_spellchecker * dialog_;
552 friend class SpellChecker;
560 Converters converters_;
562 InputsMisc inputs_misc_;
566 Interface interface_;
572 OutputsMisc outputs_misc_;
578 ScreenFonts screen_fonts_;
580 SpellChecker spellchecker_;
582 /** A couple of helper structs to enable colors to be sorted by name
585 struct SortColorsByName {
587 int operator()(NamedColor const & a, NamedColor const & b) const
588 { return (a.getname() < b.getname()); }
591 struct SortColorsByColor {
593 SortColorsByColor(RGBColor c) : col(c) {}
595 int operator()(RGBColor const &, RGBColor const &) const;