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