]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.h
fix tooltips in toolbar
[lyx.git] / src / frontends / xforms / FormPreferences.h
1 // -*- C++ -*-
2 /**
3  * \file FormPreferences.h
4  * Copyright 1995-2002 the LyX Team
5  * Copyright 1999-2001 Allan Rae
6  * Read the file COPYING
7  *
8  * \author Allan Rae, rae@lyx.org
9  * \author Angus Leeming, a.leeming@ic.ac.uk
10  */
11
12 #ifndef FORMPREFERENCES_H
13 #define FORMPREFERENCES_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "FormBaseDeprecated.h"
20 #include "Color.h" // NamedColor
21 #include "xforms_helpers.h" // XformColor
22
23 #include <boost/scoped_ptr.hpp>
24
25 #include FORMS_H_LOCATION
26 #include <utility> // pair
27
28 class Combox;
29 class Dialogs;
30 class LyXView;
31 class RGBColor;
32 struct FD_preferences;
33 struct FD_preferences_colors;
34 struct FD_preferences_converters;
35 struct FD_preferences_formats;
36 struct FD_preferences_inputs_misc;
37 struct FD_preferences_interface;
38 struct FD_preferences_language;
39 struct FD_preferences_lnf_misc;
40 struct FD_preferences_inner_tab;
41 struct FD_preferences_outputs_misc;
42 struct FD_preferences_paths;
43 struct FD_preferences_printer;
44 struct FD_preferences_screen_fonts;
45 struct FD_preferences_spelloptions;
46
47
48 /** This class provides an XForms implementation of the FormPreferences Dialog.
49     The preferences dialog allows users to set/save their preferences.
50  */
51 class FormPreferences : public FormBaseBI {
52 public:
53         friend void gui_ShowPreferences(LyXView &, Dialogs &);
54         friend void gui_ShowSpellcheckerPreferences(LyXView &, Dialogs &);
55         ///
56         FormPreferences(LyXView &, Dialogs &);
57
58 private:
59         /// Pointer to the actual instantiation of the ButtonController.
60         virtual xformsBC & bc();
61         /** Redraw the form (on receipt of a Signal indicating, for example,
62             that the xforms colours have been re-mapped). */
63         virtual void redraw();
64         /// Update the dialog.
65         virtual void update();
66         /// show the spellchecker tab
67         void showSpellPref();
68         /// Hide the dialog.
69         virtual void hide();
70         /// OK (Save) from dialog
71         virtual void ok();
72         /// Apply from dialog
73         virtual void apply();
74         /// Filter the inputs -- return true if entries are valid
75         virtual bool input(FL_OBJECT *, long);
76         /// Build the dialog
77         virtual void build();
78         /// Pointer to the actual instantiation of the xforms form.
79         virtual FL_FORM * form() const;
80         /// control which feedback message is output
81         string const getFeedback(FL_OBJECT *);
82         ///
83         void browse(FL_OBJECT * input,
84                     string const & title, string const & pattern,
85                     std::pair<string,string> const & dir1= std::make_pair(string(),string()),
86                     std::pair<string,string> const & dir2 = std::make_pair(string(),string()));
87
88         /// Real GUI implementation.
89         boost::scoped_ptr<FD_preferences> dialog_;
90         /// Converters tabfolder
91         boost::scoped_ptr<FD_preferences_inner_tab> converters_tab_;
92         /// reLyX and other import/input stuff
93         boost::scoped_ptr<FD_preferences_inner_tab> inputs_tab_;
94         /// HCI configuration
95         boost::scoped_ptr<FD_preferences_inner_tab> look_n_feel_tab_;
96         /// Outputs tabfolder
97         boost::scoped_ptr<FD_preferences_inner_tab> outputs_tab_;
98         /// Spellchecker, language stuff, etc
99         boost::scoped_ptr<FD_preferences_inner_tab> lang_opts_tab_;
100
101         /** Each tab folder is encapsulated in its own class.
102          */
103
104         class Colors {
105         public:
106                 ///
107                 enum GuiColors {
108                         GUI_COLOR_CHOICE   = FL_FREE_COL14,
109                         GUI_COLOR_HUE_DIAL = FL_FREE_COL15,
110                         GUI_COLOR_CURSOR   = FL_FREE_COL16
111                 };
112                 ///
113                 Colors(FormPreferences & p);
114                 ///
115                 FD_preferences_colors const * dialog();
116                 ///
117                 void apply(); // not const as modifies modifiedXformsPrefs.
118                 ///
119                 void build();
120                 ///
121                 string const feedback(FL_OBJECT const * const) const;
122                 ///
123                 void input(FL_OBJECT const * const);
124                 ///
125                 void update() { LoadBrowserLyX(); }
126
127                 /// Flag whether Xforms colors have changed since last file save
128                 bool modifiedXformsPrefs;
129
130         private:
131                 ///
132                 void AdjustVal(int, int, double) const;
133                 ///
134                 void InputBrowserLyX() const;
135                 ///
136                 void InputHSV();
137                 ///
138                 void InputRGB();
139                 ///
140                 void LoadBrowserLyX();
141                 ///
142                 void Modify();
143                 ///
144                 void SwitchColorSpace() const;
145                 ///
146                 string const X11hexname(RGBColor const &) const;
147
148                 ///
149                 FormPreferences & parent_;
150                 ///
151                 boost::scoped_ptr<FD_preferences_colors> dialog_;
152
153                 /// A vector of LyX LColor GUI name and associated RGB color.
154                 std::vector<NamedColor> lyxColorDB;
155                 /// A vector of xforms color ID, RGB colors and associated name.
156                 std::vector<XformsColor> xformsColorDB;
157         };
158         ///
159         friend class Colors;
160
161         ///
162         class Converters {
163         public:
164                 ///
165                 Converters(FormPreferences & p);
166                 ///
167                 FD_preferences_converters const * dialog();
168                 ///
169                 void apply() const;
170                 ///
171                 void build();
172                 ///
173                 string const feedback(FL_OBJECT const * const) const;
174                 ///
175                 bool input(FL_OBJECT const * const);
176                 ///
177                 void update();
178                 ///
179                 void UpdateBrowser();
180                 ///
181                 void UpdateChoices() const;
182
183         private:
184                 ///
185                 bool Add();
186                 ///
187                 bool Browser();
188                 ///
189                 bool erase();
190                 ///
191                 bool Input();
192                 ///
193                 string const GetFrom() const;
194                 ///
195                 string const GetTo() const;
196
197                 ///
198                 FormPreferences & parent_;
199                 ///
200                 boost::scoped_ptr<FD_preferences_converters> dialog_;
201         };
202         ///
203         friend class Converters;
204
205         ///
206         class Formats {
207         public:
208                 ///
209                 Formats(FormPreferences &  p);
210                 ///
211                 FD_preferences_formats const * dialog();
212                 ///
213                 void apply() const;
214                 ///
215                 void build();
216                 ///
217                 string const feedback(FL_OBJECT const * const) const;
218                 ///
219                 bool input(FL_OBJECT const * const);
220                 ///
221                 void update();
222
223         private:
224                 ///
225                 bool Add();
226                 ///
227                 bool Browser();
228                 ///
229                 void UpdateBrowser();
230                 ///
231                 bool erase();
232                 ///
233                 bool Input();
234
235                 ///
236                 FormPreferences & parent_;
237                 ///
238                 boost::scoped_ptr<FD_preferences_formats> dialog_;
239         };
240         ///
241         friend class Formats;
242
243         ///
244         class InputsMisc {
245         public:
246                 ///
247                 InputsMisc(FormPreferences &  p);
248                 ///
249                 FD_preferences_inputs_misc const * dialog();
250                 ///
251                 void apply() const;
252                 ///
253                 void build();
254                 ///
255                 string const feedback(FL_OBJECT const * const) const;
256                 ///
257                 void update();
258
259         private:
260                 ///
261                 FormPreferences & parent_;
262                 ///
263                 boost::scoped_ptr<FD_preferences_inputs_misc> dialog_;
264         };
265         ///
266         friend class InputsMisc;
267
268         ///
269         class Interface {
270         public:
271                 ///
272                 Interface(FormPreferences &  p);
273                 ///
274                 FD_preferences_interface const * dialog();
275                 ///
276                 void apply() const;
277                 ///
278                 void build();
279                 ///
280                 string const feedback(FL_OBJECT const * const) const;
281                 ///
282                 bool input(FL_OBJECT const * const);
283                 ///
284                 void update();
285
286         private:
287                 ///
288                 FormPreferences & parent_;
289                 ///
290                 boost::scoped_ptr<FD_preferences_interface> dialog_;
291         };
292         ///
293         friend class Interface;
294
295         ///
296         class Language {
297         public:
298                 ///
299                 Language(FormPreferences &  p);
300                 ///
301                 FD_preferences_language const * dialog();
302                 ///
303                 void apply(); // not const because calls update()
304                 ///
305                 void build();
306                 ///
307                 string const feedback(FL_OBJECT const * const) const;
308                 ///
309                 bool input(FL_OBJECT const * const);
310                 ///
311                 void update();
312                 ///
313                 static void ComboCB(int, void *, Combox *);
314
315         private:
316                 ///
317                 FormPreferences & parent_;
318                 ///
319                 boost::scoped_ptr<FD_preferences_language> dialog_;
320                 ///
321                 boost::scoped_ptr<Combox> combo_default_lang;
322                 ///
323                 std::vector<string> lang_;
324         };
325         ///
326         friend class Language;
327
328         ///
329         class LnFmisc {
330         public:
331                 ///
332                 LnFmisc(FormPreferences &  p);
333                 ///
334                 FD_preferences_lnf_misc const * dialog();
335                 ///
336                 void apply() const;
337                 ///
338                 void build();
339                 ///
340                 string const feedback(FL_OBJECT const * const) const;
341                 ///
342                 void update();
343
344         private:
345                 ///
346                 FormPreferences & parent_;
347                 ///
348                 boost::scoped_ptr<FD_preferences_lnf_misc> dialog_;
349         };
350         ///
351         friend class LnFmisc;
352
353         ///
354         class OutputsMisc {
355         public:
356                 ///
357                 OutputsMisc(FormPreferences &  p);
358                 ///
359                 FD_preferences_outputs_misc const * dialog();
360                 ///
361                 void apply() const;
362                 ///
363                 void build();
364                 ///
365                 string const feedback(FL_OBJECT const * const) const;
366                 ///
367                 void update();
368
369         private:
370                 ///
371                 FormPreferences & parent_;
372                 ///
373                 boost::scoped_ptr<FD_preferences_outputs_misc> dialog_;
374         };
375         ///
376         friend class OutputsMisc;
377
378         ///
379         class Paths {
380         public:
381                 ///
382                 Paths(FormPreferences &  p);
383                 ///
384                 FD_preferences_paths const * dialog();
385                 ///
386                 void apply();
387                 ///
388                 void build();
389                 ///
390                 string const feedback(FL_OBJECT const * const) const;
391                 ///
392                 bool input(FL_OBJECT const * const);
393                 ///
394                 void update();
395
396         private:
397                 ///
398                 FormPreferences & parent_;
399                 ///
400                 boost::scoped_ptr<FD_preferences_paths> dialog_;
401         };
402         ///
403         friend class Paths;
404
405         ///
406         class Printer {
407         public:
408                 ///
409                 Printer(FormPreferences &  p);
410                 ///
411                 FD_preferences_printer const * dialog();
412                 ///
413                 void apply() const;
414                 ///
415                 void build();
416                 ///
417                 string const feedback(FL_OBJECT const * const) const;
418                 ///
419                 void update();
420
421         private:
422                 ///
423                 FormPreferences & parent_;
424                 ///
425                 boost::scoped_ptr<FD_preferences_printer> dialog_;
426         };
427         ///
428         friend class Printer;
429
430         ///
431         class ScreenFonts {
432         public:
433                 ///
434                 ScreenFonts(FormPreferences &  p);
435                 ///
436                 FD_preferences_screen_fonts const * dialog();
437                 ///
438                 void apply() const;
439                 ///
440                 void build();
441                 ///
442                 string const feedback(FL_OBJECT const * const) const;
443                 ///
444                 bool input();
445                 ///
446                 void update();
447
448         private:
449                 ///
450                 FormPreferences & parent_;
451                 ///
452                 boost::scoped_ptr<FD_preferences_screen_fonts> dialog_;
453         };
454         ///
455         friend class ScreenFonts;
456
457         ///
458         class SpellOptions {
459         public:
460                 ///
461                 SpellOptions(FormPreferences &  p);
462                 ///
463                 FD_preferences_spelloptions const * dialog();
464                 ///
465                 void apply(); // not const because calls update()!
466                 ///
467                 void build();
468                 ///
469                 string const feedback(FL_OBJECT const * const) const;
470                 ///
471                 bool input(FL_OBJECT const * const);
472                 ///
473                 void update();
474
475         private:
476                 ///
477                 FormPreferences & parent_;
478                 ///
479                 boost::scoped_ptr<FD_preferences_spelloptions> dialog_;
480         };
481         ///
482         friend class SpellOptions;
483
484         /** The tab folders.
485          */
486
487         ///
488         Colors colors_;
489         ///
490         Converters converters_;
491         ///
492         InputsMisc inputs_misc_;
493         ///
494         Formats formats_;
495         ///
496         Interface interface_;
497         ///
498         Language language_;
499         ///
500         LnFmisc lnf_misc_;
501         ///
502         OutputsMisc outputs_misc_;
503         ///
504         Paths paths_;
505         ///
506         Printer printer_;
507         ///
508         ScreenFonts screen_fonts_;
509         ///
510         SpellOptions spelloptions_;
511
512         /** A couple of helper structs to enable colors to be sorted by name
513             and by color */
514         ///
515         struct SortColorsByName {
516                 ///
517                 int operator()(NamedColor const & a, NamedColor const & b) const
518                         { return (a.getname() < b.getname()); }
519         };
520         ///
521         struct SortColorsByColor {
522                 ///
523                 SortColorsByColor(RGBColor c) : col(c) {}
524                 ///
525                 int operator()(RGBColor const &, RGBColor const &) const;
526                 ///
527                 RGBColor col;
528         };
529         /// The ButtonController
530         ButtonController<PreferencesPolicy, xformsBC> bc_;
531 };
532
533
534 inline
535 xformsBC & FormPreferences::bc()
536 {
537         return bc_;
538 }
539
540 #endif