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