]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.h
Patches to FormPreference from Angus and Dekel
[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 "FormBase.h"
21
22 #ifdef __GNUG_
23 #pragma interface
24 #endif
25
26 class Combox;
27 class Command;
28 class Dialogs;
29 class Format;
30 class LyXView;
31 struct FD_form_colours;
32 struct FD_form_converters;
33 struct FD_form_formats;
34 struct FD_form_inputs_misc;
35 struct FD_form_interface;
36 struct FD_form_language;
37 struct FD_form_lnf_misc;
38 struct FD_form_outer_tab;
39 struct FD_form_outputs_misc;
40 struct FD_form_paths;
41 struct FD_form_preferences;
42 struct FD_form_printer;
43 struct FD_form_screen_fonts;
44 struct FD_form_spellchecker;
45
46 /** This class provides an XForms implementation of the FormPreferences Dialog.
47     The preferences dialog allows users to set/save their preferences.
48  */
49 class FormPreferences : public FormBaseBI {
50 public:
51         /// #FormPreferences x(LyXFunc ..., Dialogs ...);#
52         FormPreferences(LyXView *, Dialogs *);
53         ///
54         ~FormPreferences();
55         ///
56         static void ComboLanguageCB(int, void *, Combox *);
57         ///
58         static int FeedbackCB(FL_OBJECT *, int,
59                               FL_Coord, FL_Coord, int, void *);
60
61 private:
62         /// helper struct for Colours
63         struct RGB {
64                 int r;
65                 int g;
66                 int b;
67                 RGB() : r(0), g(0), b(0) {}
68                 RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
69         };
70         ///
71         friend bool operator==(RGB const &, RGB const &);
72         ///
73         friend bool operator!=(RGB const &, RGB const &);
74         ///
75         typedef std::pair<string, RGB> X11Colour;
76
77         /// Update the dialog.
78         virtual void update();
79         ///
80         virtual void hide();
81         /// OK from dialog
82         virtual void ok();
83         /// Apply from dialog
84         virtual void apply();
85         /// Filter the inputs -- return true if entries are valid
86         virtual bool input(FL_OBJECT *, long);
87         /// Build the dialog
88         virtual void build();
89         /// control which feedback message is output
90         void feedback( FL_OBJECT * );
91         /// The handler for the preemptive feedback
92         void Feedback(FL_OBJECT *, int);
93         ///
94         virtual FL_FORM * form() const;
95
96         /** Folder specific apply functions.
97          */
98         
99         ///
100         void applyColours() const;
101         ///
102         void applyConverters() const;
103         ///
104         void applyFormats() const;
105         ///
106         void applyInputsMisc() const;
107         ///
108         void applyInterface() const;
109         ///
110         void applyLanguage(); // not const because calls updateLanguage!
111         ///
112         void applyLnFmisc() const;
113         ///
114         void applyOutputsMisc() const;
115         ///
116         void applyPaths(); // not const because calls updatePaths!
117         ///
118         void applyPrinter() const;
119         ///
120         void applyScreenFonts() const;
121         ///
122         void applySpellChecker(); // not const because calls updateSpellChecker!
123
124         /** Folder specific build functions.
125          */
126         
127         ///
128         void buildColours();
129         ///
130         void buildConverters();
131         ///
132         void buildFormats();
133         ///
134         void buildInputsMisc();
135         ///
136         void buildInterface();
137         ///
138         void buildLanguage();
139         ///
140         void buildLnFmisc();
141         ///
142         void buildOutputsMisc();
143         ///
144         void buildPaths();
145         ///
146         void buildPrinter();
147         ///
148         void buildScreenFonts();
149         ///
150         void buildSpellchecker();
151
152         /** Folder specific feedback functions.
153          */
154         
155         ///
156         string const feedbackColours(FL_OBJECT const * const) const;
157         ///
158         string const feedbackConverters(FL_OBJECT const * const) const;
159         ///
160         string const feedbackFormats( FL_OBJECT const * const ) const;
161         ///
162         string const feedbackInputsMisc(FL_OBJECT const * const) const;
163         ///
164         string const feedbackInterface(FL_OBJECT const * const) const;
165         ///
166         string const feedbackLanguage(FL_OBJECT const * const) const;
167         ///
168         string const feedbackLnFmisc(FL_OBJECT const * const) const;
169         ///
170         string const feedbackOutputsMisc(FL_OBJECT const * const) const;
171         ///
172         string const feedbackPaths(FL_OBJECT const * const) const;
173         ///
174         string const feedbackPrinter(FL_OBJECT const * const) const;
175         ///
176         string const feedbackScreenFonts(FL_OBJECT const * const) const;
177         ///
178         string const feedbackSpellChecker(FL_OBJECT const * const) const;
179
180         /** Folder specific input functions. Not all folders require one.
181          */
182         
183         ///
184         bool inputColours(FL_OBJECT const * const);
185         ///
186         bool inputConverters( FL_OBJECT const * const );
187         ///
188         bool inputFormats( FL_OBJECT const * const );
189         ///
190         bool inputLanguage(FL_OBJECT const * const);
191         ///
192         bool inputPaths(FL_OBJECT const * const);
193         ///
194         bool inputScreenFonts();
195         ///
196         bool inputSpellChecker(FL_OBJECT const * const);
197
198         /** Folder specific update functions.
199          */
200         
201         ///
202         void updateColours();
203         ///
204         void updateConverters();
205         ///
206         void updateFormats();
207         ///
208         void updateInputsMisc();
209         ///
210         void updateInterface();
211         ///
212         void updateLanguage();
213         ///
214         void updateLnFmisc();
215         ///
216         void updateOutputsMisc();
217         ///
218         void updatePaths();
219         ///
220         void updatePrinter();
221         ///
222         void updateScreenFonts();
223         ///
224         void updateSpellChecker();
225
226         /** Some helper functions for specific folders.
227          */
228         
229         ///
230         bool ColoursLoadBrowser( string const & );
231         ///
232         int  ColoursSearchEntry(RGB const & ) const;
233         ///
234         void ColoursUpdateBrowser( int );
235         ///
236         void ColoursUpdateRGB();
237
238         ///
239         bool ConvertersAdd();
240         ///
241         bool ConvertersBrowser();
242         ///
243         void ConvertersClear() const;
244         ///
245         bool ConvertersContainFormat( Format const &) const;
246         ///
247         bool ConvertersDelete();
248         ///
249         bool ConvertersInput();
250         ///
251         bool ConvertersSetCommand( Command & ) const;
252         ///
253         void ConvertersUpdateChoices();
254
255         bool FormatsAdd();
256         ///
257         bool FormatsBrowser();
258         ///
259         void FormatsClear() const;
260         ///
261         bool FormatsDelete();
262         ///
263         bool FormatsInput();
264
265         ///
266         bool WriteableDir( string const & );
267         ///
268         bool ReadableDir( string const & );
269         ///
270         bool WriteableFile( string const &, string const & = string() );
271
272         ///
273         void setPreHandler( FL_OBJECT * ) const;
274         ///
275         void printWarning( string const & );
276
277         /// Type definitions from the fdesign produced header file.
278         FD_form_preferences * build_preferences();
279         ///
280         FD_form_outer_tab * build_outer_tab();
281         ///
282         FD_form_colours * build_colours();
283         ///
284         FD_form_converters * build_converters();
285         ///
286         FD_form_formats * build_formats();
287         ///
288         FD_form_inputs_misc * build_inputs_misc();
289         ///
290         FD_form_interface * build_interface();
291         ///
292         FD_form_language * build_language();
293         ///
294         FD_form_lnf_misc * build_lnf_misc();
295         ///
296         FD_form_outputs_misc * build_outputs_misc();
297         ///
298         FD_form_paths * build_paths();
299         ///
300         FD_form_printer * build_printer();
301         ///
302         FD_form_screen_fonts * build_screen_fonts();
303         ///
304         FD_form_spellchecker * build_spellchecker();
305
306         /// Real GUI implementation.
307         FD_form_preferences * dialog_;
308         /// Converters tabfolder
309         FD_form_outer_tab * converters_tab_;
310         /// reLyX and other import/input stuff
311         FD_form_outer_tab * inputs_tab_;
312         /// HCI configuration
313         FD_form_outer_tab * look_n_feel_tab_;
314         /// Outputs tabfolder
315         FD_form_outer_tab * outputs_tab_;
316         /// Spellchecker, language stuff, etc
317         FD_form_outer_tab * usage_tab_;
318         ///
319         FD_form_colours * colours_;
320         ///
321         FD_form_converters * converters_;
322         ///
323         FD_form_formats * formats_;
324         ///
325         FD_form_inputs_misc * inputs_misc_;
326         ///
327         FD_form_interface * interface_;
328         ///
329         FD_form_language * language_;
330         ///
331         FD_form_lnf_misc * lnf_misc_;
332         ///
333         FD_form_outputs_misc * outputs_misc_;
334         ///
335         FD_form_paths * paths_;
336         ///
337         FD_form_printer * printer_;
338         ///
339         FD_form_screen_fonts * screen_fonts_;
340         ///
341         FD_form_spellchecker * spellchecker_;
342         ///
343         Combox * combo_default_lang;
344         ///
345         Combox * combo_kbmap_1;
346         ///
347         Combox * combo_kbmap_2;
348
349         /// A vector of Formats, to be manipulated in the Format browser.
350         std::vector<Format> formats_vec;
351         /// A vector of Commands, to be manipulated in the Converter browser.
352         std::vector<Command> commands_vec;
353         /// A vector of RGB colours and associated name.
354         static std::vector<X11Colour> colourDB;
355         /** A collection of kmap files.
356             First entry is the file name, full path.
357             Second entry is the shorthand, as appears in the fl_choice.
358             Eg, system_lyxdir/kbd/american2.kmap, american2
359         */
360         static std::pair<std::vector<string>, std::vector<string> > dirlist;
361         ///
362         bool warningPosted;
363 };
364
365 inline
366 bool operator==(FormPreferences::RGB const & c1,
367                 FormPreferences::RGB const & c2)
368 {
369         return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
370 }
371
372
373 inline
374 bool operator!=(FormPreferences::RGB const & c1,
375                 FormPreferences::RGB const & c2)
376 {
377         return !(c1 == c2);
378 }
379
380 #endif