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