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