]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.h
fix rbearing
[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 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "FormBaseDeprecated.h"
22 #include "Color.h" // NamedColor
23 #include "xforms_helpers.h" // XformColor
24
25 #include <boost/scoped_ptr.hpp>
26
27 #include FORMS_H_LOCATION
28 #include <utility> // pair
29
30 class Combox;
31 class Dialogs;
32 class LyXView;
33 class RGBColor;
34 struct FD_preferences;
35 struct FD_preferences_colors;
36 struct FD_preferences_converters;
37 struct FD_preferences_formats;
38 struct FD_preferences_inputs_misc;
39 struct FD_preferences_interface;
40 struct FD_preferences_language;
41 struct FD_preferences_lnf_misc;
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 FormBaseBI {
54 public:
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         /// Hide the dialog.
67         virtual void hide();
68         /// OK (Save) from dialog
69         virtual void ok();
70         /// Apply from dialog
71         virtual void apply();
72         /// Filter the inputs -- return true if entries are valid
73         virtual bool input(FL_OBJECT *, long);
74         /// Build the dialog
75         virtual void build();
76         /// Pointer to the actual instantiation of the xforms form.
77         virtual FL_FORM * form() const;
78         /// control which feedback message is output
79         string const getFeedback(FL_OBJECT *);
80         ///
81         void browse(FL_OBJECT * input,
82                     string const & title, string const & pattern,
83                     std::pair<string,string> const & dir1= std::make_pair(string(),string()),
84                     std::pair<string,string> const & dir2 = std::make_pair(string(),string()));
85
86         /// Real GUI implementation.
87         boost::scoped_ptr<FD_preferences> dialog_;
88         /// Converters tabfolder
89         boost::scoped_ptr<FD_preferences_inner_tab> converters_tab_;
90         /// reLyX and other import/input stuff
91         boost::scoped_ptr<FD_preferences_inner_tab> inputs_tab_;
92         /// HCI configuration
93         boost::scoped_ptr<FD_preferences_inner_tab> look_n_feel_tab_;
94         /// Outputs tabfolder
95         boost::scoped_ptr<FD_preferences_inner_tab> outputs_tab_;
96         /// Spellchecker, language stuff, etc
97         boost::scoped_ptr<FD_preferences_inner_tab> lang_opts_tab_;
98
99         /** Each tab folder is encapsulated in its own class.
100          */
101
102         class Colors {
103         public:
104                 ///
105                 enum GuiColors {
106                         GUI_COLOR_CHOICE   = FL_FREE_COL14,
107                         GUI_COLOR_HUE_DIAL = FL_FREE_COL15,
108                         GUI_COLOR_CURSOR   = FL_FREE_COL16
109                 };
110                 ///
111                 Colors(FormPreferences & p);
112                 ///
113                 FD_preferences_colors const * dialog();
114                 ///
115                 void apply(); // not const as modifies modifiedXformsPrefs.
116                 ///
117                 void build();
118                 ///
119                 string const feedback(FL_OBJECT const * const) const;
120                 ///
121                 void input(FL_OBJECT const * const);
122                 ///
123                 void update() { LoadBrowserLyX(); }
124
125                 /// Flag whether Xforms colors have changed since last file save
126                 bool modifiedXformsPrefs;
127
128         private:
129                 ///
130                 void AdjustVal(int, int, double) const;
131                 ///
132                 void InputBrowserLyX() const;
133                 ///
134                 void InputHSV();
135                 ///
136                 void InputRGB();
137                 ///
138                 void LoadBrowserLyX();
139                 ///
140                 void Modify();
141                 ///
142                 void SwitchColorSpace() const;
143                 ///
144                 string const X11hexname(RGBColor const &) const;
145
146                 ///
147                 FormPreferences & parent_;
148                 ///
149                 boost::scoped_ptr<FD_preferences_colors> dialog_;
150
151                 /// A vector of LyX LColor GUI name and associated RGB color.
152                 std::vector<NamedColor> lyxColorDB;
153                 /// A vector of xforms color ID, RGB colors and associated name.
154                 std::vector<XformsColor> xformsColorDB;
155         };
156         ///
157         friend class Colors;
158
159         ///
160         class Converters {
161         public:
162                 ///
163                 Converters(FormPreferences & p);
164                 ///
165                 FD_preferences_converters const * dialog();
166                 ///
167                 void apply() const;
168                 ///
169                 void build();
170                 ///
171                 string const feedback(FL_OBJECT const * const) const;
172                 ///
173                 bool input(FL_OBJECT const * const);
174                 ///
175                 void update();
176                 ///
177                 void UpdateBrowser();
178                 ///
179                 void UpdateChoices() const;
180
181         private:
182                 ///
183                 bool Add();
184                 ///
185                 bool Browser();
186                 ///
187                 bool erase();
188                 ///
189                 bool Input();
190                 ///
191                 string const GetFrom() const;
192                 ///
193                 string const GetTo() const;
194
195                 ///
196                 FormPreferences & parent_;
197                 ///
198                 boost::scoped_ptr<FD_preferences_converters> dialog_;
199         };
200         ///
201         friend class Converters;
202
203         ///
204         class Formats {
205         public:
206                 ///
207                 Formats(FormPreferences &  p);
208                 ///
209                 FD_preferences_formats const * dialog();
210                 ///
211                 void apply() const;
212                 ///
213                 void build();
214                 ///
215                 string const feedback(FL_OBJECT const * const) const;
216                 ///
217                 bool input(FL_OBJECT const * const);
218                 ///
219                 void update();
220
221         private:
222                 ///
223                 bool Add();
224                 ///
225                 bool Browser();
226                 ///
227                 void UpdateBrowser();
228                 ///
229                 bool erase();
230                 ///
231                 bool Input();
232
233                 ///
234                 FormPreferences & parent_;
235                 ///
236                 boost::scoped_ptr<FD_preferences_formats> dialog_;
237         };
238         ///
239         friend class Formats;
240
241         ///
242         class InputsMisc {
243         public:
244                 ///
245                 InputsMisc(FormPreferences &  p);
246                 ///
247                 FD_preferences_inputs_misc const * dialog();
248                 ///
249                 void apply() const;
250                 ///
251                 void build();
252                 ///
253                 string const feedback(FL_OBJECT const * const) const;
254                 ///
255                 void update();
256
257         private:
258                 ///
259                 FormPreferences & parent_;
260                 ///
261                 boost::scoped_ptr<FD_preferences_inputs_misc> dialog_;
262         };
263         ///
264         friend class InputsMisc;
265
266         ///
267         class Interface {
268         public:
269                 ///
270                 Interface(FormPreferences &  p);
271                 ///
272                 FD_preferences_interface const * dialog();
273                 ///
274                 void apply() const;
275                 ///
276                 void build();
277                 ///
278                 string const feedback(FL_OBJECT const * const) const;
279                 ///
280                 bool input(FL_OBJECT const * const);
281                 ///
282                 void update();
283
284         private:
285                 ///
286                 FormPreferences & parent_;
287                 ///
288                 boost::scoped_ptr<FD_preferences_interface> dialog_;
289         };
290         ///
291         friend class Interface;
292
293         ///
294         class Language {
295         public:
296                 ///
297                 Language(FormPreferences &  p);
298                 ///
299                 FD_preferences_language const * dialog();
300                 ///
301                 void apply(); // not const because calls update()
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                 static void ComboCB(int, void *, Combox *);
312
313         private:
314                 ///
315                 FormPreferences & parent_;
316                 ///
317                 boost::scoped_ptr<FD_preferences_language> dialog_;
318                 ///
319                 boost::scoped_ptr<Combox> combo_default_lang;
320                 ///
321                 std::vector<string> lang_;
322         };
323         ///
324         friend class Language;
325
326         ///
327         class LnFmisc {
328         public:
329                 ///
330                 LnFmisc(FormPreferences &  p);
331                 ///
332                 FD_preferences_lnf_misc const * dialog();
333                 ///
334                 void apply() const;
335                 ///
336                 void build();
337                 ///
338                 string const feedback(FL_OBJECT const * const) const;
339                 ///
340                 void update();
341
342         private:
343                 ///
344                 FormPreferences & parent_;
345                 ///
346                 boost::scoped_ptr<FD_preferences_lnf_misc> dialog_;
347         };
348         ///
349         friend class LnFmisc;
350
351         ///
352         class OutputsMisc {
353         public:
354                 ///
355                 OutputsMisc(FormPreferences &  p);
356                 ///
357                 FD_preferences_outputs_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_preferences_outputs_misc> dialog_;
372         };
373         ///
374         friend class OutputsMisc;
375
376         ///
377         class Paths {
378         public:
379                 ///
380                 Paths(FormPreferences &  p);
381                 ///
382                 FD_preferences_paths const * dialog();
383                 ///
384                 void apply();
385                 ///
386                 void build();
387                 ///
388                 string const feedback(FL_OBJECT const * const) const;
389                 ///
390                 bool input(FL_OBJECT const * const);
391                 ///
392                 void update();
393
394         private:
395                 ///
396                 FormPreferences & parent_;
397                 ///
398                 boost::scoped_ptr<FD_preferences_paths> dialog_;
399         };
400         ///
401         friend class Paths;
402
403         ///
404         class Printer {
405         public:
406                 ///
407                 Printer(FormPreferences &  p);
408                 ///
409                 FD_preferences_printer const * dialog();
410                 ///
411                 void apply() const;
412                 ///
413                 void build();
414                 ///
415                 string const feedback(FL_OBJECT const * const) const;
416                 ///
417                 void update();
418
419         private:
420                 ///
421                 FormPreferences & parent_;
422                 ///
423                 boost::scoped_ptr<FD_preferences_printer> dialog_;
424         };
425         ///
426         friend class Printer;
427
428         ///
429         class ScreenFonts {
430         public:
431                 ///
432                 ScreenFonts(FormPreferences &  p);
433                 ///
434                 FD_preferences_screen_fonts const * dialog();
435                 ///
436                 void apply() const;
437                 ///
438                 void build();
439                 ///
440                 string const feedback(FL_OBJECT const * const) const;
441                 ///
442                 bool input();
443                 ///
444                 void update();
445
446         private:
447                 ///
448                 FormPreferences & parent_;
449                 ///
450                 boost::scoped_ptr<FD_preferences_screen_fonts> dialog_;
451         };
452         ///
453         friend class ScreenFonts;
454
455         ///
456         class SpellOptions {
457         public:
458                 ///
459                 SpellOptions(FormPreferences &  p);
460                 ///
461                 FD_preferences_spelloptions const * dialog();
462                 ///
463                 void apply(); // not const because calls update()!
464                 ///
465                 void build();
466                 ///
467                 string const feedback(FL_OBJECT const * const) const;
468                 ///
469                 bool input(FL_OBJECT const * const);
470                 ///
471                 void update();
472
473         private:
474                 ///
475                 FormPreferences & parent_;
476                 ///
477                 boost::scoped_ptr<FD_preferences_spelloptions> dialog_;
478         };
479         ///
480         friend class SpellOptions;
481
482         /** The tab folders.
483          */
484
485         ///
486         Colors colors_;
487         ///
488         Converters converters_;
489         ///
490         InputsMisc inputs_misc_;
491         ///
492         Formats formats_;
493         ///
494         Interface interface_;
495         ///
496         Language language_;
497         ///
498         LnFmisc lnf_misc_;
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         /// The ButtonController
528         ButtonController<PreferencesPolicy, xformsBC> bc_;
529 };
530
531
532 inline
533 xformsBC & FormPreferences::bc()
534 {
535         return bc_;
536 }
537
538 #endif