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