]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.h
ae44e160eda9c06c328999d860614d768f6b67b6
[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         /// Connect signals etc. Set form's max size.
64         virtual void connect();
65         /// Disconnect signals. Also perform any necessary housekeeping.
66         virtual void disconnect();
67         /** Redraw the form (on receipt of a Signal indicating, for example,
68             that the xform colours have been re-mapped). */
69         virtual void redraw();
70         /// Update the dialog.
71         virtual void update();
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 xform's 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 xform_helpers.h.
95          */
96         void browse( FL_OBJECT * input,
97                      string const & title, string const & pattern, 
98                      std::pair<string,string> const & dir1,
99                      std::pair<string,string> const & dir2 );
100         
101         /// Type definitions from the fdesign produced header file.
102         FD_form_preferences * build_preferences();
103         ///
104         FD_form_outer_tab * build_outer_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_spellchecker * build_spellchecker();
129
130         /// Real GUI implementation.
131         FD_form_preferences * dialog_;
132         /// Converters tabfolder
133         FD_form_outer_tab * converters_tab_;
134         /// reLyX and other import/input stuff
135         FD_form_outer_tab * inputs_tab_;
136         /// HCI configuration
137         FD_form_outer_tab * look_n_feel_tab_;
138         /// Outputs tabfolder
139         FD_form_outer_tab * outputs_tab_;
140         /// Spellchecker, language stuff, etc
141         FD_form_outer_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 ) : parent_(p), dialog_(0) {}
160                 ///
161                 ~Colors();
162                 ///
163                 FD_form_colors const * dialog() { return dialog_; }
164                 ///
165                 void apply(); // not const as modifies modifiedXformPrefs.
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 modifiedXformPrefs;
177
178         private:
179                 ///
180                 void AdjustVal( int, int, double ) const;
181                 ///
182                 void InputBrowserLyX() const;
183                 ///
184                 void InputBrowserX11() const;
185                 ///
186                 void InputHSV();
187                 ///
188                 void LoadBrowserLyX();
189                 ///
190                 bool LoadBrowserX11(string const &);
191                 ///
192                 bool LoadDatabase();
193                 ///
194                 void Modify();
195                 ///
196                 int SearchEntry(RGBColor const &) const;
197                 ///
198                 void Sort();
199                 ///
200                 void SortType();
201
202                 ///
203                 FormPreferences & parent_;
204                 ///
205                 FD_form_colors * dialog_;
206                 /// The usual location of the X11 name database.
207                 static string const colorFile;
208                 /** A vector of RGB colors and associated name.
209                     Each RGB color is unique. */
210                 static std::vector<NamedColor> colorDB;
211
212                 /// A vector of LyX LColor GUI name and associated RGB color.
213                 std::vector<NamedColor> lyxColorDB;
214                 /// A vector of xform color ID, RGB colors and associated name.
215                 std::vector<XformColor> xformColorDB;
216         };
217         ///
218         friend class Colors;
219
220         ///
221         class Converters {
222         public:
223                 ///
224                 Converters( FormPreferences & p ) : parent_(p), dialog_(0) {}
225                 ///
226                 ~Converters();
227                 ///
228                 FD_form_converters const * dialog() { return dialog_; }
229                 ///
230                 void apply() const;
231                 ///
232                 void build();
233                 ///
234                 string const feedback(FL_OBJECT const * const) const;
235                 ///
236                 bool input( FL_OBJECT const * const );
237                 ///
238                 void update();
239                 ///
240                 void UpdateBrowser();
241                 ///
242                 void UpdateChoices() const;
243
244         private:
245                 ///
246                 bool Add();
247                 ///
248                 bool Browser();
249                 ///
250                 bool Delete();
251                 ///
252                 bool Input();
253                 ///
254                 string const GetFrom() const;
255                 ///
256                 string const GetTo() const;
257
258                 ///
259                 FormPreferences & parent_;
260                 ///
261                 FD_form_converters * dialog_;
262         };
263         ///
264         friend class Converters;
265
266         ///
267         class Formats {
268         public:
269                 ///
270                 Formats( FormPreferences &  p ) : parent_(p), dialog_(0) {}
271                 ///
272                 ~Formats();
273                 ///
274                 FD_form_formats const * dialog() { return dialog_; }
275                 ///
276                 void apply() const;
277                 ///
278                 void build();
279                 ///
280                 string const feedback(FL_OBJECT const * const) const;
281                 ///
282                 bool input( FL_OBJECT const * const );
283                 ///
284                 void update();
285
286         private:
287                 ///
288                 bool Add();
289                 ///
290                 bool Browser();
291                 ///
292                 void UpdateBrowser();
293                 ///
294                 bool Delete();
295                 ///
296                 bool Input();
297
298                 ///
299                 FormPreferences & parent_;
300                 ///
301                 FD_form_formats * dialog_;
302         };
303         ///
304         friend class Formats;
305
306         ///
307         class InputsMisc {
308         public:
309                 ///
310                 InputsMisc( FormPreferences &  p ) : parent_(p), dialog_(0) {}
311                 ///
312                 ~InputsMisc();
313                 ///
314                 FD_form_inputs_misc const * dialog() { return dialog_; }
315                 ///
316                 void apply() const;
317                 ///
318                 void build();
319                 ///
320                 string const feedback(FL_OBJECT const * const) const;
321                 ///
322                 void update();
323
324         private:
325                 ///
326                 FormPreferences & parent_;
327                 ///
328                 FD_form_inputs_misc * dialog_;
329         };
330         ///
331         friend class InputsMisc;
332         
333         ///
334         class Interface {
335         public:
336                 ///
337                 Interface( FormPreferences &  p ) : parent_(p), dialog_(0) {}
338                 ///
339                 ~Interface();
340                 ///
341                 FD_form_interface const * dialog() { return dialog_; }
342                 ///
343                 void apply() const;
344                 ///
345                 void build();
346                 ///
347                 string const feedback(FL_OBJECT const * const) const;
348                 ///
349                 bool input( FL_OBJECT const * const );
350                 ///
351                 void update();
352
353         private:
354                 ///
355                 FormPreferences & parent_;
356                 ///
357                 FD_form_interface * dialog_;
358         };
359         ///
360         friend class Interface;
361
362         ///
363         class Language {
364         public:
365                 ///
366                 Language( FormPreferences &  p )
367                         : parent_(p), dialog_(0), combo_default_lang(0) {}
368                 ///
369                 ~Language();
370                 ///
371                 FD_form_language const * dialog() { return dialog_; }
372                 ///
373                 void apply(); // not const because calls update()
374                 ///
375                 void build();
376                 ///
377                 string const feedback(FL_OBJECT const * const) const;
378                 ///
379                 bool input( FL_OBJECT const * const );
380                 ///
381                 void update();
382                 ///
383                 static void ComboCB(int, void *, Combox *);
384
385         private:
386                 ///
387                 FormPreferences & parent_;
388                 ///
389                 FD_form_language * dialog_;
390                 ///
391                 Combox * combo_default_lang;
392         };
393         ///
394         friend class Language;
395         
396         ///
397         class LnFmisc {
398         public:
399                 ///
400                 LnFmisc( FormPreferences &  p ) : parent_(p), dialog_(0) {}
401                 ///
402                 ~LnFmisc();
403                 ///
404                 FD_form_lnf_misc const * dialog() { return dialog_; }
405                 ///
406                 void apply() const;
407                 ///
408                 void build();
409                 ///
410                 string const feedback(FL_OBJECT const * const) const;
411                 ///
412                 void update();
413
414         private:
415                 ///
416                 FormPreferences & parent_;
417                 ///
418                 FD_form_lnf_misc * dialog_;
419         };
420         ///
421         friend class LnFmisc;
422
423         ///
424         class OutputsMisc {
425         public:
426                 ///
427                 OutputsMisc( FormPreferences &  p ) : parent_(p), dialog_(0) {}
428                 ///
429                 ~OutputsMisc();
430                 ///
431                 FD_form_outputs_misc const * dialog() { return dialog_; }
432                 ///
433                 void apply() const;
434                 ///
435                 void build();
436                 ///
437                 string const feedback(FL_OBJECT const * const) const;
438                 ///
439                 void update();
440
441         private:
442                 ///
443                 FormPreferences & parent_;
444                 ///
445                 FD_form_outputs_misc * dialog_;
446         };
447         ///
448         friend class OutputsMisc;
449
450         ///
451         class Paths {
452         public:
453                 ///
454                 Paths( FormPreferences &  p ) : parent_(p), dialog_(0) {}
455                 ///
456                 ~Paths();
457                 ///
458                 FD_form_paths const * dialog() { return dialog_; }
459                 ///
460                 void apply();
461                 ///
462                 void build();
463                 ///
464                 string const feedback(FL_OBJECT const * const) const;
465                 ///
466                 bool input(FL_OBJECT const * const);
467                 ///
468                 void update();
469
470         private:
471                 ///
472                 FormPreferences & parent_;
473                 ///
474                 FD_form_paths * dialog_;
475         };
476         ///
477         friend class Paths;
478
479         ///
480         class Printer {
481         public:
482                 ///
483                 Printer( FormPreferences &  p ) : parent_(p), dialog_(0) {}
484                 ///
485                 ~Printer();
486                 ///
487                 FD_form_printer const * dialog() { return dialog_; }
488                 ///
489                 void apply() const;
490                 ///
491                 void build();
492                 ///
493                 string const feedback(FL_OBJECT const * const) const;
494                 ///
495                 void update();
496
497         private:
498                 ///
499                 FormPreferences & parent_;
500                 ///
501                 FD_form_printer * dialog_;
502         };
503         ///
504         friend class Printer;
505
506         ///
507         class ScreenFonts {
508         public:
509                 ///
510                 ScreenFonts( FormPreferences &  p ) : parent_(p), dialog_(0) {}
511                 ///
512                 ~ScreenFonts();
513                 ///
514                 FD_form_screen_fonts const * dialog() { return dialog_; }
515                 ///
516                 void apply() const;
517                 ///
518                 void build();
519                 ///
520                 string const feedback(FL_OBJECT const * const) const;
521                 ///
522                 bool input();
523                 ///
524                 void update();
525
526         private:
527                 ///
528                 FormPreferences & parent_;
529                 ///
530                 FD_form_screen_fonts * dialog_;
531         };
532         ///
533         friend class ScreenFonts;
534
535         ///
536         class SpellChecker {
537         public:
538                 ///
539                 SpellChecker( FormPreferences &  p ) : parent_(p), dialog_(0) {}
540                 ///
541                 ~SpellChecker();
542                 ///
543                 FD_form_spellchecker const * dialog() { return dialog_; }
544                 ///
545                 void apply(); // not const because calls update()!
546                 ///
547                 void build();
548                 ///
549                 string const feedback(FL_OBJECT const * const) const;
550                 ///
551                 bool input(FL_OBJECT const * const);
552                 ///
553                 void update();
554
555         private:
556                 ///
557                 FormPreferences & parent_;
558                 ///
559                 FD_form_spellchecker * dialog_;
560         };
561         ///
562         friend class SpellChecker;
563
564         /** The tab folders.
565          */
566         
567         ///
568         Colors colors_;
569         ///
570         Converters converters_;
571         ///
572         InputsMisc inputs_misc_;
573         ///
574         Formats formats_;
575         ///
576         Interface interface_;
577         ///
578         Language language_;
579         ///
580         LnFmisc lnf_misc_;
581         ///
582         OutputsMisc outputs_misc_;
583         ///
584         Paths paths_;
585         ///
586         Printer printer_;
587         ///
588         ScreenFonts screen_fonts_;
589         ///
590         SpellChecker spellchecker_;
591
592         /** A couple of helper structs to enable colors to be sorted by name
593             and by color */
594         ///
595         struct SortColorsByName {
596                 ///
597                 int operator()(NamedColor const & a, NamedColor const & b) const
598                         { return (a.getname() < b.getname()); }
599         };
600         ///
601         struct SortColorsByColor {
602                 ///
603                 SortColorsByColor(RGBColor c) : col(c) {}
604                 ///
605                 int operator()(RGBColor const &, RGBColor const &) const;
606                 ///
607                 RGBColor col;
608         };
609
610 };
611
612 #endif