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