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