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