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