]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.h
fc26cceda40e18a7ebdebb5901bdf3f300db311f
[lyx.git] / src / frontends / xforms / FormPreferences.h
1 // -*- C++ -*-
2 /**
3  * \file FormPreferences.h
4  * Copyright 1999-2001 Allan Rae
5  * This file is part of LyX, the document processor.
6  * Licence details can be found in the file COPYING.
7  *
8  * \author Allan Rae
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #ifndef FORMPREFERENCES_H
15 #define FORMPREFERENCES_H
16
17
18 #include "FormBase.h"
19 #include "Color.h" // NamedColor
20 #include "xforms_helpers.h" // XformColor
21
22 #include <boost/scoped_ptr.hpp>
23
24 #include "lyx_forms.h"
25 #include <utility> // pair
26
27 class ControlPrefs;
28
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_identity;
41 struct FD_preferences_inner_tab;
42 struct FD_preferences_outputs_misc;
43 struct FD_preferences_paths;
44 struct FD_preferences_printer;
45 struct FD_preferences_screen_fonts;
46 struct FD_preferences_spelloptions;
47
48
49 /** This class provides an XForms implementation of the FormPreferences Dialog.
50  *  The preferences dialog allows users to set/save their preferences.
51  */
52 class FormPreferences : public FormCB<ControlPrefs, FormDB<FD_preferences> > {
53 public:
54         FormPreferences();
55
56 private:
57         /** Redraw the form (on receipt of a Signal indicating, for example,
58             that the xforms colours have been re-mapped). */
59         virtual void redraw();
60         /// Update the dialog.
61         virtual void update();
62         /// Hide the dialog.
63         virtual void hide();
64         /// Apply from dialog
65         virtual void apply();
66         /// Filter the inputs -- return true if entries are valid
67         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
68         /// Build the dialog
69         virtual void build();
70         /// control which feedback message is output
71         string const getFeedback(FL_OBJECT *);
72
73         /// Converters tabfolder
74         boost::scoped_ptr<FD_preferences_inner_tab> converters_tab_;
75         /// reLyX and other import/input stuff
76         boost::scoped_ptr<FD_preferences_inner_tab> inputs_tab_;
77         /// HCI configuration
78         boost::scoped_ptr<FD_preferences_inner_tab> look_n_feel_tab_;
79         /// Outputs tabfolder
80         boost::scoped_ptr<FD_preferences_inner_tab> outputs_tab_;
81         /// Spellchecker, language stuff, etc
82         boost::scoped_ptr<FD_preferences_inner_tab> lang_opts_tab_;
83
84         /** Each tab folder is encapsulated in its own class.
85          */
86
87         class Colors {
88         public:
89                 ///
90                 enum GuiColors {
91                         GUI_COLOR_CHOICE   = FL_FREE_COL14,
92                         GUI_COLOR_HUE_DIAL = FL_FREE_COL15,
93                         GUI_COLOR_CURSOR   = FL_FREE_COL16
94                 };
95                 ///
96                 Colors(FormPreferences & p);
97                 ///
98                 FD_preferences_colors const * dialog();
99                 ///
100                 void apply(); // not const as modifies modifiedXformsPrefs.
101                 ///
102                 void build();
103                 ///
104                 string const feedback(FL_OBJECT const * const) const;
105                 ///
106                 void input(FL_OBJECT const * const);
107                 ///
108                 void update() { LoadBrowserLyX(); }
109
110                 /// Flag whether Xforms colors have changed since last file save
111                 bool modifiedXformsPrefs;
112
113         private:
114                 ///
115                 void AdjustVal(int, int, double) const;
116                 ///
117                 void InputBrowserLyX() const;
118                 ///
119                 void InputHSV();
120                 ///
121                 void InputRGB();
122                 ///
123                 void LoadBrowserLyX();
124                 ///
125                 void Modify();
126                 ///
127                 void SwitchColorSpace() const;
128
129                 ///
130                 FormPreferences & parent_;
131                 ///
132                 boost::scoped_ptr<FD_preferences_colors> dialog_;
133
134                 /// A vector of LyX LColor GUI name and associated RGB color.
135                 std::vector<NamedColor> lyxColorDB;
136                 /// A vector of xforms color ID, RGB colors and associated name.
137                 std::vector<XformsColor> xformsColorDB;
138         };
139         ///
140         friend class Colors;
141
142         ///
143         class Converters {
144         public:
145                 ///
146                 Converters(FormPreferences & p);
147                 ///
148                 FD_preferences_converters const * dialog();
149                 ///
150                 void apply() const;
151                 ///
152                 void build();
153                 ///
154                 string const feedback(FL_OBJECT const * const) const;
155                 ///
156                 bool input(FL_OBJECT const * const);
157                 ///
158                 void update();
159                 ///
160                 void UpdateBrowser();
161                 ///
162                 void UpdateChoices() const;
163
164         private:
165                 ///
166                 bool Add();
167                 ///
168                 bool Browser();
169                 ///
170                 bool erase();
171                 ///
172                 bool Input();
173                 ///
174                 string const GetFrom() const;
175                 ///
176                 string const GetTo() const;
177
178                 ///
179                 FormPreferences & parent_;
180                 ///
181                 boost::scoped_ptr<FD_preferences_converters> dialog_;
182         };
183         ///
184         friend class Converters;
185
186         ///
187         class Formats {
188         public:
189                 ///
190                 Formats(FormPreferences &  p);
191                 ///
192                 FD_preferences_formats const * dialog();
193                 ///
194                 void apply() const;
195                 ///
196                 void build();
197                 ///
198                 string const feedback(FL_OBJECT const * const) const;
199                 ///
200                 bool input(FL_OBJECT const * const);
201                 ///
202                 void update();
203
204         private:
205                 ///
206                 bool Add();
207                 ///
208                 bool Browser();
209                 ///
210                 void UpdateBrowser();
211                 ///
212                 bool erase();
213                 ///
214                 bool Input();
215
216                 ///
217                 FormPreferences & parent_;
218                 ///
219                 boost::scoped_ptr<FD_preferences_formats> dialog_;
220         };
221         ///
222         friend class Formats;
223
224         ///
225         class InputsMisc {
226         public:
227                 ///
228                 InputsMisc(FormPreferences &  p);
229                 ///
230                 FD_preferences_inputs_misc const * dialog();
231                 ///
232                 void apply(LyXRC & rc) const;
233                 ///
234                 void build();
235                 ///
236                 string const feedback(FL_OBJECT const * const) const;
237                 ///
238                 void update(LyXRC const & rc);
239
240         private:
241                 ///
242                 FormPreferences & parent_;
243                 ///
244                 boost::scoped_ptr<FD_preferences_inputs_misc> dialog_;
245         };
246         ///
247         friend class InputsMisc;
248
249         ///
250         class Interface {
251         public:
252                 ///
253                 Interface(FormPreferences &  p);
254                 ///
255                 FD_preferences_interface const * dialog();
256                 ///
257                 void apply(LyXRC & rc) const;
258                 ///
259                 void build();
260                 ///
261                 string const feedback(FL_OBJECT const * const) const;
262                 ///
263                 bool input(FL_OBJECT const * const);
264                 ///
265                 void update(LyXRC const & rc);
266
267         private:
268                 ///
269                 FormPreferences & parent_;
270                 ///
271                 boost::scoped_ptr<FD_preferences_interface> dialog_;
272         };
273         ///
274         friend class Interface;
275
276         ///
277         class Language {
278         public:
279                 ///
280                 Language(FormPreferences &  p);
281                 ///
282                 FD_preferences_language const * dialog();
283                 ///
284                 void apply(LyXRC & rc); // not const because calls update()
285                 ///
286                 void build();
287                 ///
288                 string const feedback(FL_OBJECT const * const) const;
289                 ///
290                 bool input(FL_OBJECT const * const);
291                 ///
292                 void update(LyXRC const & rc);
293
294         private:
295                 ///
296                 FormPreferences & parent_;
297                 ///
298                 boost::scoped_ptr<FD_preferences_language> dialog_;
299                 ///
300                 std::vector<string> lang_;
301         };
302         ///
303         friend class Language;
304
305         ///
306         class LnFmisc {
307         public:
308                 ///
309                 LnFmisc(FormPreferences &  p);
310                 ///
311                 FD_preferences_lnf_misc const * dialog();
312                 ///
313                 void apply(LyXRC & rc) const;
314                 ///
315                 void build();
316                 ///
317                 string const feedback(FL_OBJECT const * const) const;
318                 ///
319                 void update(LyXRC const & rc);
320
321         private:
322                 ///
323                 FormPreferences & parent_;
324                 ///
325                 boost::scoped_ptr<FD_preferences_lnf_misc> dialog_;
326         };
327         ///
328         friend class LnFmisc;
329
330         class Identity {
331         public:
332                 ///
333                 Identity(FormPreferences &  p);
334                 ///
335                 FD_preferences_identity const * dialog();
336                 ///
337                 void apply(LyXRC & rc) const;
338                 ///
339                 void build();
340                 ///
341                 string const feedback(FL_OBJECT const * const) const;
342                 ///
343                 void update(LyXRC const & rc);
344
345         private:
346                 ///
347                 FormPreferences & parent_;
348                 ///
349                 boost::scoped_ptr<FD_preferences_identity> dialog_;
350         };
351         friend class Identity;
352
353         ///
354         class OutputsMisc {
355         public:
356                 ///
357                 OutputsMisc(FormPreferences &  p);
358                 ///
359                 FD_preferences_outputs_misc const * dialog();
360                 ///
361                 void apply(LyXRC & rc) const;
362                 ///
363                 void build();
364                 ///
365                 string const feedback(FL_OBJECT const * const) const;
366                 ///
367                 void update(LyXRC const & rc);
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(LyXRC & rc);
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(LyXRC const & rc);
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(LyXRC & rc) const;
414                 ///
415                 void build();
416                 ///
417                 string const feedback(FL_OBJECT const * const) const;
418                 ///
419                 void update(LyXRC const & rc);
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(LyXRC & rc) const;
439                 ///
440                 void build();
441                 ///
442                 string const feedback(FL_OBJECT const * const) const;
443                 ///
444                 bool input();
445                 ///
446                 void update(LyXRC const & rc);
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(LyXRC & rc); // 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(LyXRC const & rc);
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         Identity identity_;
503         ///
504         OutputsMisc outputs_misc_;
505         ///
506         Paths paths_;
507         ///
508         Printer printer_;
509         ///
510         ScreenFonts screen_fonts_;
511         ///
512         SpellOptions spelloptions_;
513
514         /** A couple of helper structs to enable colors to be sorted by name
515             and by color */
516         ///
517         struct SortColorsByName {
518                 ///
519                 int operator()(NamedColor const & a, NamedColor const & b) const
520                         { return (a.getname() < b.getname()); }
521         };
522         ///
523         struct SortColorsByColor {
524                 ///
525                 SortColorsByColor(RGBColor c) : col(c) {}
526                 ///
527                 int operator()(RGBColor const &, RGBColor const &) const;
528                 ///
529                 RGBColor col;
530         };
531 };
532
533 #endif // FORMPREFERENCES_H