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