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