]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
major GUII cleanup + Baruchs patch + Angus's patch + removed a couple of generated...
[lyx.git] / src / frontends / xforms / FormPreferences.C
1 /* FormPreferences.C
2  * FormPreferences Interface Class Implementation
3  */
4
5 #include <config.h>
6
7 #include FORMS_H_LOCATION
8
9 #ifdef __GNUG_
10 #pragma implementation
11 #endif
12
13 #include "FormPreferences.h"
14 #include "form_preferences.h"
15 #include "xform_macros.h"
16 #include "input_validators.h"
17 #include "LyXView.h"
18 #include "lyxfunc.h"
19 #include "Dialogs.h"
20 #include "lyxrc.h"
21 #include "debug.h"
22 #include "support/FileInfo.h"
23 #include "support/filetools.h"
24 #include "lyx_gui_misc.h"
25 #include "gettext.h"
26 #include "ButtonController.h"
27
28 #ifdef SIGC_CXX_NAMESPACES
29 using SigC::slot;
30 #endif
31
32 C_RETURNCB(FormPreferences,  WMHideCB)
33 C_GENERICCB(FormPreferences, OKCB)
34 C_GENERICCB(FormPreferences, ApplyCB)
35 C_GENERICCB(FormPreferences, CancelCB)
36 C_GENERICCB(FormPreferences, InputCB)
37 C_GENERICCB(FormPreferences, RestoreCB)
38
39
40 FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
41         : dialog_(0), bind_(0), misc_(0), screen_fonts_(0), interface_fonts_(0),
42           printer_(0), paths_(0), lv_(lv), d_(d), u_(0), h_(0),
43           minw_(0), minh_(0),
44           bc_(new ButtonController<PreferencesPolicy>(_("Cancel"), _("Close")))
45 {
46         // let the dialog be shown
47         // This is a permanent connection so we won't bother
48         // storing a copy because we won't be disconnecting.
49         d->showPreferences.connect(slot(this, &FormPreferences::show));
50 }
51
52
53 FormPreferences::~FormPreferences()
54 {
55         delete dialog_;
56         delete bc_;
57 }
58
59
60 void FormPreferences::build()
61 {
62         dialog_ = build_preferences();
63
64         // manage the restore, save, apply and cancel/close buttons
65         bc_->setOkay(dialog_->button_ok);
66         bc_->setApply(dialog_->button_apply);
67         bc_->setCancel(dialog_->button_cancel);
68         bc_->setUndoAll(dialog_->button_restore);
69         bc_->refresh();
70
71         // Workaround dumb xforms sizing bug
72         minw_ = dialog_->form->w;
73         minh_ = dialog_->form->h;
74
75         bind_ = build_bind();
76         screen_fonts_ = build_screen_fonts();
77         interface_fonts_ = build_interface_fonts();
78         misc_ = build_misc();
79         printer_ = build_printer();
80         paths_ = build_paths();
81
82         // setup the input returns
83         // Bind tab
84         fl_set_input_return(bind_->input_bind, FL_RETURN_CHANGED);
85         // Misc tab
86         fl_set_counter_return(misc_->counter_autosave, FL_RETURN_CHANGED);
87         fl_set_counter_return(misc_->counter_line_len, FL_RETURN_CHANGED);
88         // Screen fonts
89         fl_set_input_return(screen_fonts_->input_roman, FL_RETURN_CHANGED);
90         fl_set_input_return(screen_fonts_->input_sans, FL_RETURN_CHANGED);
91         fl_set_input_return(screen_fonts_->input_typewriter,
92                             FL_RETURN_CHANGED);
93         fl_set_input_return(screen_fonts_->input_screen_encoding,
94                             FL_RETURN_CHANGED);
95         fl_set_counter_return(screen_fonts_->counter_zoom, FL_RETURN_CHANGED);
96         fl_set_input_return(screen_fonts_->input_tiny, FL_RETURN_CHANGED);
97         fl_set_input_return(screen_fonts_->input_script, FL_RETURN_CHANGED);
98         fl_set_input_return(screen_fonts_->input_footnote, FL_RETURN_CHANGED);
99         fl_set_input_return(screen_fonts_->input_small, FL_RETURN_CHANGED);
100         fl_set_input_return(screen_fonts_->input_normal, FL_RETURN_CHANGED);
101         fl_set_input_return(screen_fonts_->input_large, FL_RETURN_CHANGED);
102         fl_set_input_return(screen_fonts_->input_larger, FL_RETURN_CHANGED);
103         fl_set_input_return(screen_fonts_->input_largest, FL_RETURN_CHANGED);
104         fl_set_input_return(screen_fonts_->input_huge, FL_RETURN_CHANGED);
105         fl_set_input_return(screen_fonts_->input_huger, FL_RETURN_CHANGED);
106         // interface fonts
107         fl_set_input_return(interface_fonts_->input_popup_font,
108                             FL_RETURN_CHANGED);
109         fl_set_input_return(interface_fonts_->input_menu_font,
110                             FL_RETURN_CHANGED);
111         fl_set_input_return(interface_fonts_->input_popup_encoding,
112                             FL_RETURN_CHANGED);
113         // printer
114         fl_set_input_return(printer_->input_command, FL_RETURN_CHANGED);
115         fl_set_input_return(printer_->input_page_range, FL_RETURN_CHANGED);
116         fl_set_input_return(printer_->input_copies, FL_RETURN_CHANGED);
117         fl_set_input_return(printer_->input_reverse, FL_RETURN_CHANGED);
118         fl_set_input_return(printer_->input_to_printer, FL_RETURN_CHANGED);
119         fl_set_input_return(printer_->input_file_extension, FL_RETURN_CHANGED);
120         fl_set_input_return(printer_->input_spool_command, FL_RETURN_CHANGED);
121         fl_set_input_return(printer_->input_paper_type, FL_RETURN_CHANGED);
122         fl_set_input_return(printer_->input_even_pages, FL_RETURN_CHANGED);
123         fl_set_input_return(printer_->input_odd_pages, FL_RETURN_CHANGED);
124         fl_set_input_return(printer_->input_collated, FL_RETURN_CHANGED);
125         fl_set_input_return(printer_->input_landscape, FL_RETURN_CHANGED);
126         fl_set_input_return(printer_->input_to_file, FL_RETURN_CHANGED);
127         fl_set_input_return(printer_->input_extra_options, FL_RETURN_CHANGED);
128         fl_set_input_return(printer_->input_spool_prefix, FL_RETURN_CHANGED);
129         fl_set_input_return(printer_->input_paper_size, FL_RETURN_CHANGED);
130         fl_set_input_return(printer_->input_name, FL_RETURN_CHANGED);
131         // paths
132         fl_set_input_return(paths_->input_default_path, FL_RETURN_CHANGED);
133         fl_set_input_return(paths_->input_template_path, FL_RETURN_CHANGED);
134         fl_set_input_return(paths_->input_temp_dir, FL_RETURN_CHANGED);
135         fl_set_input_return(paths_->input_lastfiles, FL_RETURN_CHANGED);
136         fl_set_input_return(paths_->input_backup_path, FL_RETURN_CHANGED);
137         fl_set_counter_return(paths_->counter_lastfiles, FL_RETURN_CHANGED);
138
139         // Now add them to the tabfolder
140         fl_addto_tabfolder(dialog_->tabfolder_prefs,
141                            _("Bindings"),
142                            bind_->form);
143         fl_addto_tabfolder(dialog_->tabfolder_prefs,
144                            _("Screen Fonts"),
145                            screen_fonts_->form);
146         fl_addto_tabfolder(dialog_->tabfolder_prefs,
147                            _("Interface Fonts"),
148                            interface_fonts_->form);
149         fl_addto_tabfolder(dialog_->tabfolder_prefs,
150                            _("Miscellaneous"),
151                            misc_->form);
152         fl_addto_tabfolder(dialog_->tabfolder_prefs,
153                            _("Printer"),
154                            printer_->form);
155         fl_addto_tabfolder(dialog_->tabfolder_prefs,
156                            _("Paths"),
157                            paths_->form);
158
159         fl_set_form_atclose(dialog_->form,
160                             C_FormPreferencesWMHideCB, 0);
161
162         // deactivate the various browse buttons because they
163         // currently aren't implemented
164         fl_deactivate_object(bind_->button_bind_file_browse);
165         fl_deactivate_object(paths_->button_document_browse);
166         fl_deactivate_object(paths_->button_template_browse);
167         fl_deactivate_object(paths_->button_temp_dir_browse);
168         fl_deactivate_object(paths_->button_lastfiles_browse);
169         fl_deactivate_object(paths_->button_backup_path_browse);
170         fl_set_object_lcol(bind_->button_bind_file_browse, FL_INACTIVE);
171         fl_set_object_lcol(paths_->button_document_browse, FL_INACTIVE);
172         fl_set_object_lcol(paths_->button_template_browse, FL_INACTIVE);
173         fl_set_object_lcol(paths_->button_temp_dir_browse, FL_INACTIVE);
174         fl_set_object_lcol(paths_->button_lastfiles_browse, FL_INACTIVE);
175         fl_set_object_lcol(paths_->button_backup_path_browse, FL_INACTIVE);
176 }
177
178
179 void FormPreferences::show()
180 {
181         if (!dialog_) {
182                 build();
183         }
184         update();  // make sure its up-to-date
185
186         if (dialog_->form->visible) {
187                 fl_raise_form(dialog_->form);
188         } else {
189                 fl_set_form_minsize(dialog_->form,
190                                     minw_,
191                                     minh_);
192                 fl_show_form(dialog_->form,
193                              FL_PLACE_MOUSE | FL_FREE_SIZE,
194                              FL_TRANSIENT,
195                              _("Preferences"));
196         }
197 }
198
199
200 void FormPreferences::hide()
201 {
202         if (dialog_
203             && dialog_->form
204             && dialog_->form->visible) {
205                 bc_->hide();
206                 fl_hide_form(dialog_->form);
207         }
208 }
209
210
211 void FormPreferences::apply()
212 {
213         // set the new lyxrc entries
214         // many of these need to trigger other functions when the assignment
215         // is made.  For example, screen zoom and font types.  These could be
216         // handled either by signals/slots in lyxrc or just directly call the
217         // associated functions here.
218         // There are other problems with this scheme.  We really should check
219         // what we copy to make sure that it really is necessary to do things
220         // like update the screen fonts because that flushes the textcache
221         // and other stuff which may cost us a lot on slower/high-load machines.
222         
223         // Bind tab
224         lyxrc.bind_file = fl_get_input(bind_->input_bind);
225         // Misc tab
226         lyxrc.show_banner = fl_get_button(misc_->check_banner);
227         lyxrc.auto_region_delete = fl_get_button(misc_->
228                                                  check_auto_region_delete);
229         lyxrc.exit_confirmation = fl_get_button(misc_->check_exit_confirm);
230         lyxrc.display_shortcuts =
231                 fl_get_button(misc_->check_display_shortcuts);
232         lyxrc.autosave = static_cast<unsigned int>
233                 (fl_get_counter_value(misc_->counter_autosave));
234         lyxrc.ascii_linelen = static_cast<unsigned int>
235                 (fl_get_counter_value(misc_->counter_line_len));
236         // Interface fonts
237         lyxrc.popup_font_name =
238                 fl_get_input(interface_fonts_->input_popup_font);
239         lyxrc.menu_font_name = fl_get_input(interface_fonts_->input_menu_font);
240         lyxrc.font_norm_menu =
241                 fl_get_input(interface_fonts_->input_popup_encoding);
242         // Screen fonts
243         if (lyxrc.roman_font_name !=
244             fl_get_input(screen_fonts_->input_roman) ||
245             lyxrc.sans_font_name !=
246             fl_get_input(screen_fonts_->input_sans) ||
247             lyxrc.typewriter_font_name !=
248             fl_get_input(screen_fonts_->input_typewriter) ||
249             lyxrc.font_norm !=
250             fl_get_input(screen_fonts_->input_screen_encoding) ||
251             lyxrc.use_scalable_fonts !=
252             fl_get_button(screen_fonts_->check_scalable) ||
253             lyxrc.zoom != static_cast<unsigned int>
254             (fl_get_counter_value(screen_fonts_->counter_zoom)) ||
255             lyxrc.font_sizes[LyXFont::SIZE_TINY] !=
256             strToDbl(fl_get_input(screen_fonts_->input_tiny)) ||
257             lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] !=
258             strToDbl(fl_get_input(screen_fonts_->input_script)) ||
259             lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] !=
260             strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
261             lyxrc.font_sizes[LyXFont::SIZE_SMALL] !=
262             strToDbl(fl_get_input(screen_fonts_->input_small)) ||
263             lyxrc.font_sizes[LyXFont::SIZE_NORMAL] !=
264             strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
265             lyxrc.font_sizes[LyXFont::SIZE_LARGE] !=
266             strToDbl(fl_get_input(screen_fonts_->input_large)) ||
267             lyxrc.font_sizes[LyXFont::SIZE_LARGER] !=
268             strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
269             lyxrc.font_sizes[LyXFont::SIZE_LARGEST] !=
270             strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
271             lyxrc.font_sizes[LyXFont::SIZE_HUGE] !=
272             strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
273             lyxrc.font_sizes[LyXFont::SIZE_HUGER] !=
274             strToDbl(fl_get_input(screen_fonts_->input_huger))) {
275                 // Something has changed so copy all of them and then force
276                 // an update of the screen fonts (ie. redraw every buffer)
277                 lyxrc.roman_font_name = fl_get_input(screen_fonts_->input_roman);
278                 lyxrc.sans_font_name = fl_get_input(screen_fonts_->input_sans);
279                 lyxrc.typewriter_font_name = fl_get_input(screen_fonts_->
280                                                           input_typewriter);
281                 lyxrc.font_norm = fl_get_input(screen_fonts_->
282                                                input_screen_encoding);
283                 lyxrc.use_scalable_fonts =
284                         fl_get_button(screen_fonts_->check_scalable);
285                 lyxrc.zoom = static_cast<unsigned int>
286                         (fl_get_counter_value(screen_fonts_->counter_zoom));
287                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = 
288                         strToDbl(fl_get_input(screen_fonts_->input_tiny));
289                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] =
290                         strToDbl(fl_get_input(screen_fonts_->input_script));
291                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] =
292                         strToDbl(fl_get_input(screen_fonts_->input_footnote));
293                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] =
294                         strToDbl(fl_get_input(screen_fonts_->input_small));
295                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] =
296                         strToDbl(fl_get_input(screen_fonts_->input_normal));
297                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] =
298                         strToDbl(fl_get_input(screen_fonts_->input_large));
299                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] =
300                 strToDbl(fl_get_input(screen_fonts_->input_larger));
301                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] =
302                         strToDbl(fl_get_input(screen_fonts_->input_largest));
303                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] =
304                         strToDbl(fl_get_input(screen_fonts_->input_huge));
305                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] =
306                         strToDbl(fl_get_input(screen_fonts_->input_huger));
307                 // Now update the buffers
308                 // Can anything below here affect the redraw process?
309                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
310         }
311         // printer
312         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
313         lyxrc.print_command = fl_get_input(printer_->input_command);
314         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
315         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
316         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
317         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
318         lyxrc.print_file_extension =
319                 fl_get_input(printer_->input_file_extension);
320         lyxrc.print_spool_command =
321                 fl_get_input(printer_->input_spool_command);
322         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
323         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
324         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
325         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
326         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
327         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
328         lyxrc.print_extra_options =
329                 fl_get_input(printer_->input_extra_options);
330         lyxrc.print_spool_printerprefix =
331                 fl_get_input(printer_->input_spool_prefix);
332         lyxrc.print_paper_dimension_flag =
333                 fl_get_input(printer_->input_paper_size);
334         lyxrc.printer = fl_get_input(printer_->input_name);
335         // paths
336         lyxrc.document_path = fl_get_input(paths_->input_default_path);
337         lyxrc.template_path = fl_get_input(paths_->input_template_path);
338         lyxrc.tempdir_path = fl_get_input(paths_->input_temp_dir);
339         lyxrc.lastfiles = fl_get_input(paths_->input_lastfiles);
340         lyxrc.backupdir_path = fl_get_input(paths_->input_backup_path);
341         lyxrc.use_tempdir = fl_get_button(paths_->check_use_temp_dir);
342         lyxrc.check_lastfiles = fl_get_button(paths_->check_last_files);
343         lyxrc.make_backup = fl_get_button(paths_->check_make_backups);
344         lyxrc.num_lastfiles = static_cast<unsigned int>
345                 (fl_get_counter_value(paths_->counter_lastfiles));
346
347         bc_->apply();
348 }
349
350
351 void FormPreferences::update()
352 {
353         if (dialog_) {
354                 // read lyxrc entries
355                 // Bind tab
356                 fl_set_input(bind_->input_bind, lyxrc.bind_file.c_str());
357                 // Misc tab
358                 fl_set_button(misc_->check_banner,
359                               lyxrc.show_banner);
360                 fl_set_button(misc_->check_auto_region_delete,
361                               lyxrc.auto_region_delete);
362                 fl_set_button(misc_->check_exit_confirm,
363                               lyxrc.exit_confirmation);
364                 fl_set_button(misc_->check_display_shortcuts,
365                               lyxrc.display_shortcuts);
366                 fl_set_counter_value(misc_->counter_autosave,
367                                      lyxrc.autosave);
368                 fl_set_counter_value(misc_->counter_line_len,
369                                      lyxrc.ascii_linelen);
370                 // Screen fonts
371                 fl_set_input(screen_fonts_->input_roman,
372                              lyxrc.roman_font_name.c_str());
373                 fl_set_input(screen_fonts_->input_sans,
374                              lyxrc.sans_font_name.c_str());
375                 fl_set_input(screen_fonts_->input_typewriter,
376                              lyxrc.typewriter_font_name.c_str());
377                 fl_set_input(screen_fonts_->input_screen_encoding,
378                              lyxrc.font_norm.c_str());
379                 fl_set_button(screen_fonts_->check_scalable,
380                              lyxrc.use_scalable_fonts);
381                 fl_set_counter_value(screen_fonts_->counter_zoom,
382                              lyxrc.zoom);
383                 fl_set_input(screen_fonts_->input_tiny,
384                              tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
385                 fl_set_input(screen_fonts_->input_script,
386                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
387                 fl_set_input(screen_fonts_->input_footnote,
388                              tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
389                 fl_set_input(screen_fonts_->input_small,
390                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
391                 fl_set_input(screen_fonts_->input_normal,
392                              tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
393                 fl_set_input(screen_fonts_->input_large,
394                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
395                 fl_set_input(screen_fonts_->input_larger,
396                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
397                 fl_set_input(screen_fonts_->input_largest,
398                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
399                 fl_set_input(screen_fonts_->input_huge,
400                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
401                 fl_set_input(screen_fonts_->input_huger,
402                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
403                 // interface fonts
404                 fl_set_input(interface_fonts_->input_popup_font,
405                              lyxrc.popup_font_name.c_str());
406                 fl_set_input(interface_fonts_->input_menu_font,
407                              lyxrc.menu_font_name.c_str());
408                 fl_set_input(interface_fonts_->input_popup_encoding,
409                              lyxrc.font_norm_menu.c_str());
410                 // printer
411                 fl_set_button(printer_->check_adapt_output,
412                               lyxrc.print_adapt_output);
413                 fl_set_input(printer_->input_command,
414                              lyxrc.print_command.c_str());
415                 fl_set_input(printer_->input_page_range,
416                              lyxrc.print_pagerange_flag.c_str());
417                 fl_set_input(printer_->input_copies,
418                              lyxrc.print_copies_flag.c_str());
419                 fl_set_input(printer_->input_reverse,
420                               lyxrc.print_reverse_flag.c_str());
421                 fl_set_input(printer_->input_to_printer,
422                              lyxrc.print_to_printer.c_str());
423                 fl_set_input(printer_->input_file_extension,
424                              lyxrc.print_file_extension.c_str());
425                 fl_set_input(printer_->input_spool_command,
426                              lyxrc.print_spool_command.c_str());
427                 fl_set_input(printer_->input_paper_type,
428                              lyxrc.print_paper_flag.c_str());
429                 fl_set_input(printer_->input_even_pages,
430                              lyxrc.print_evenpage_flag.c_str());
431                 fl_set_input(printer_->input_odd_pages,
432                              lyxrc.print_oddpage_flag.c_str());
433                 fl_set_input(printer_->input_collated,
434                              lyxrc.print_collcopies_flag.c_str());
435                 fl_set_input(printer_->input_landscape,
436                              lyxrc.print_landscape_flag.c_str());
437                 fl_set_input(printer_->input_to_file,
438                              lyxrc.print_to_file.c_str());
439                 fl_set_input(printer_->input_extra_options,
440                              lyxrc.print_extra_options.c_str());
441                 fl_set_input(printer_->input_spool_prefix,
442                              lyxrc.print_spool_printerprefix.c_str());
443                 fl_set_input(printer_->input_paper_size,
444                              lyxrc.print_paper_dimension_flag.c_str());
445                 fl_set_input(printer_->input_name,
446                              lyxrc.printer.c_str());
447                 // paths
448                 fl_set_input(paths_->input_default_path,
449                              lyxrc.document_path.c_str());
450                 fl_set_input(paths_->input_template_path,
451                              lyxrc.template_path.c_str());
452                 fl_set_input(paths_->input_temp_dir,
453                              lyxrc.tempdir_path.c_str());
454                 fl_set_input(paths_->input_lastfiles,
455                              lyxrc.lastfiles.c_str());
456                 fl_set_input(paths_->input_backup_path,
457                              lyxrc.backupdir_path.c_str());
458                 fl_set_button(paths_->check_use_temp_dir,
459                               lyxrc.use_tempdir);
460                 fl_set_button(paths_->check_last_files,
461                               lyxrc.check_lastfiles);           
462                 fl_set_button(paths_->check_make_backups,
463                               lyxrc.make_backup);
464                 fl_set_counter_value(paths_->counter_lastfiles,
465                                      lyxrc.num_lastfiles);
466         }
467 }
468
469
470 bool FormPreferences::input()
471 {
472         bool activate = true;
473         //
474         // whatever checks you need to ensure the user hasn't entered
475         // some totally ridiculous value somewhere.  Change activate to suit.
476         //
477         // Examples:
478         //  paths -- all dirs in the path should exist, be writable & absolute
479         if (!AbsolutePath(fl_get_input(paths_->input_default_path))
480             || 1 != IsDirWriteable(fl_get_input(paths_->input_default_path))
481             || !AbsolutePath(fl_get_input(paths_->input_template_path))
482             || 1 != IsDirWriteable(fl_get_input(paths_->input_template_path))
483             // lastfiles: exists && writeable || non-existent && isn't a dir
484             // NOTE: assumes IsFileWriteable == -1 means non-existent hence
485             //       the extra check to see if its a directory
486             || !AbsolutePath(fl_get_input(paths_->input_lastfiles))
487             || 1 != IsDirWriteable(OnlyPath(fl_get_input(paths_->
488                                                          input_lastfiles)))
489             || 0 == IsFileWriteable(OnlyPath(fl_get_input(paths_->
490                                                           input_lastfiles)))
491             || FileInfo(fl_get_input(paths_->input_lastfiles)).isDir()
492             // tmpdir: only check if we are using it
493             || (fl_get_button(paths_->check_use_temp_dir)
494                 && (1 != IsDirWriteable(fl_get_input(paths_->input_temp_dir))
495                     || !AbsolutePath(fl_get_input(paths_->input_temp_dir))))
496             // backupdir: can safely be left empty
497             || (fl_get_button(paths_->check_make_backups)
498                 && (!string(fl_get_input(paths_->input_backup_path)).empty()
499                     && (1 != IsDirWriteable(fl_get_input(paths_->
500                                                         input_backup_path))
501                         || !AbsolutePath(fl_get_input(paths_->
502                                                       input_backup_path)))))) {
503                 activate = false;
504                 lyxerr[Debug::GUI] << "Preferences: Path is wrong\n";
505         }
506
507         //  fontsizes -- tiny < script < footnote etc.
508         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
509             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
510             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
511             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
512             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
513             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
514             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
515             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
516             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
517             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
518                 // make sure they all have positive entries
519                 // Also note that an empty entry is returned as 0.0 by strToDbl
520                 activate = false;
521                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
522         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
523                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
524                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
525                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
526                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
527                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
528                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
529                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
530                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
531                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
532                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
533                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
534                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
535                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
536                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
537                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
538                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
539                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
540                 activate = false;
541                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
542         }
543
544         return activate;
545 }
546
547
548 int FormPreferences::WMHideCB(FL_FORM * form, void *)
549 {
550         // Ensure that the signals (u and h) are disconnected even if the
551         // window manager is used to close the dialog.
552         FormPreferences * pre = static_cast<FormPreferences*>(form->u_vdata);
553         pre->hide();
554         return FL_CANCEL;
555 }
556
557
558 void FormPreferences::OKCB(FL_OBJECT * ob, long)
559 {
560         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
561         pre->apply();
562         pre->hide();
563  
564         pre->lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
565 }
566
567
568 void FormPreferences::ApplyCB(FL_OBJECT * ob, long)
569 {
570         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
571         pre->apply();
572 }
573
574
575 void FormPreferences::CancelCB(FL_OBJECT * ob, long)
576 {
577         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
578         pre->hide();
579 }
580
581
582 void FormPreferences::InputCB(FL_OBJECT * ob, long)
583 {
584         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
585         pre->bc_->valid(pre->input());
586 }
587
588
589 void FormPreferences::RestoreCB(FL_OBJECT * ob, long)
590 {
591         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
592         pre->update();
593         pre->input();
594         pre->bc_->undoAll();
595 }