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