]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreferences.C
Dekel's Spacing.C patch + Garst's setOK complaint + use the right policy for FormDocument
[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_->setOK(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                 fl_hide_form(dialog_->form);
206         }
207 }
208
209
210 void FormPreferences::apply()
211 {
212         // set the new lyxrc entries
213         // many of these need to trigger other functions when the assignment
214         // is made.  For example, screen zoom and font types.  These could be
215         // handled either by signals/slots in lyxrc or just directly call the
216         // associated functions here.
217         // There are other problems with this scheme.  We really should check
218         // what we copy to make sure that it really is necessary to do things
219         // like update the screen fonts because that flushes the textcache
220         // and other stuff which may cost us a lot on slower/high-load machines.
221         
222         // Bind tab
223         lyxrc.bind_file = fl_get_input(bind_->input_bind);
224         // Misc tab
225         lyxrc.show_banner = fl_get_button(misc_->check_banner);
226         lyxrc.auto_region_delete = fl_get_button(misc_->
227                                                  check_auto_region_delete);
228         lyxrc.exit_confirmation = fl_get_button(misc_->check_exit_confirm);
229         lyxrc.display_shortcuts =
230                 fl_get_button(misc_->check_display_shortcuts);
231         lyxrc.autosave = static_cast<unsigned int>
232                 (fl_get_counter_value(misc_->counter_autosave));
233         lyxrc.ascii_linelen = static_cast<unsigned int>
234                 (fl_get_counter_value(misc_->counter_line_len));
235         // Interface fonts
236         lyxrc.popup_font_name =
237                 fl_get_input(interface_fonts_->input_popup_font);
238         lyxrc.menu_font_name = fl_get_input(interface_fonts_->input_menu_font);
239         lyxrc.font_norm_menu =
240                 fl_get_input(interface_fonts_->input_popup_encoding);
241         // Screen fonts
242         if (lyxrc.roman_font_name !=
243             fl_get_input(screen_fonts_->input_roman) ||
244             lyxrc.sans_font_name !=
245             fl_get_input(screen_fonts_->input_sans) ||
246             lyxrc.typewriter_font_name !=
247             fl_get_input(screen_fonts_->input_typewriter) ||
248             lyxrc.font_norm !=
249             fl_get_input(screen_fonts_->input_screen_encoding) ||
250             lyxrc.use_scalable_fonts !=
251             fl_get_button(screen_fonts_->check_scalable) ||
252             lyxrc.zoom != static_cast<unsigned int>
253             (fl_get_counter_value(screen_fonts_->counter_zoom)) ||
254             lyxrc.font_sizes[LyXFont::SIZE_TINY] !=
255             strToDbl(fl_get_input(screen_fonts_->input_tiny)) ||
256             lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] !=
257             strToDbl(fl_get_input(screen_fonts_->input_script)) ||
258             lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] !=
259             strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
260             lyxrc.font_sizes[LyXFont::SIZE_SMALL] !=
261             strToDbl(fl_get_input(screen_fonts_->input_small)) ||
262             lyxrc.font_sizes[LyXFont::SIZE_NORMAL] !=
263             strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
264             lyxrc.font_sizes[LyXFont::SIZE_LARGE] !=
265             strToDbl(fl_get_input(screen_fonts_->input_large)) ||
266             lyxrc.font_sizes[LyXFont::SIZE_LARGER] !=
267             strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
268             lyxrc.font_sizes[LyXFont::SIZE_LARGEST] !=
269             strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
270             lyxrc.font_sizes[LyXFont::SIZE_HUGE] !=
271             strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
272             lyxrc.font_sizes[LyXFont::SIZE_HUGER] !=
273             strToDbl(fl_get_input(screen_fonts_->input_huger))) {
274                 // Something has changed so copy all of them and then force
275                 // an update of the screen fonts (ie. redraw every buffer)
276                 lyxrc.roman_font_name = fl_get_input(screen_fonts_->input_roman);
277                 lyxrc.sans_font_name = fl_get_input(screen_fonts_->input_sans);
278                 lyxrc.typewriter_font_name = fl_get_input(screen_fonts_->
279                                                           input_typewriter);
280                 lyxrc.font_norm = fl_get_input(screen_fonts_->
281                                                input_screen_encoding);
282                 lyxrc.use_scalable_fonts =
283                         fl_get_button(screen_fonts_->check_scalable);
284                 lyxrc.zoom = static_cast<unsigned int>
285                         (fl_get_counter_value(screen_fonts_->counter_zoom));
286                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = 
287                         strToDbl(fl_get_input(screen_fonts_->input_tiny));
288                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] =
289                         strToDbl(fl_get_input(screen_fonts_->input_script));
290                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] =
291                         strToDbl(fl_get_input(screen_fonts_->input_footnote));
292                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] =
293                         strToDbl(fl_get_input(screen_fonts_->input_small));
294                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] =
295                         strToDbl(fl_get_input(screen_fonts_->input_normal));
296                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] =
297                         strToDbl(fl_get_input(screen_fonts_->input_large));
298                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] =
299                 strToDbl(fl_get_input(screen_fonts_->input_larger));
300                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] =
301                         strToDbl(fl_get_input(screen_fonts_->input_largest));
302                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] =
303                         strToDbl(fl_get_input(screen_fonts_->input_huge));
304                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] =
305                         strToDbl(fl_get_input(screen_fonts_->input_huger));
306                 // Now update the buffers
307                 // Can anything below here affect the redraw process?
308                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
309         }
310         // printer
311         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
312         lyxrc.print_command = fl_get_input(printer_->input_command);
313         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
314         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
315         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
316         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
317         lyxrc.print_file_extension =
318                 fl_get_input(printer_->input_file_extension);
319         lyxrc.print_spool_command =
320                 fl_get_input(printer_->input_spool_command);
321         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
322         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
323         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
324         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
325         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
326         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
327         lyxrc.print_extra_options =
328                 fl_get_input(printer_->input_extra_options);
329         lyxrc.print_spool_printerprefix =
330                 fl_get_input(printer_->input_spool_prefix);
331         lyxrc.print_paper_dimension_flag =
332                 fl_get_input(printer_->input_paper_size);
333         lyxrc.printer = fl_get_input(printer_->input_name);
334         // paths
335         lyxrc.document_path = fl_get_input(paths_->input_default_path);
336         lyxrc.template_path = fl_get_input(paths_->input_template_path);
337         lyxrc.tempdir_path = fl_get_input(paths_->input_temp_dir);
338         lyxrc.lastfiles = fl_get_input(paths_->input_lastfiles);
339         lyxrc.backupdir_path = fl_get_input(paths_->input_backup_path);
340         lyxrc.use_tempdir = fl_get_button(paths_->check_use_temp_dir);
341         lyxrc.check_lastfiles = fl_get_button(paths_->check_last_files);
342         lyxrc.make_backup = fl_get_button(paths_->check_make_backups);
343         lyxrc.num_lastfiles = static_cast<unsigned int>
344                 (fl_get_counter_value(paths_->counter_lastfiles));
345 }
346
347
348 void FormPreferences::update()
349 {
350         if (dialog_) {
351                 // read lyxrc entries
352                 // Bind tab
353                 fl_set_input(bind_->input_bind, lyxrc.bind_file.c_str());
354                 // Misc tab
355                 fl_set_button(misc_->check_banner,
356                               lyxrc.show_banner);
357                 fl_set_button(misc_->check_auto_region_delete,
358                               lyxrc.auto_region_delete);
359                 fl_set_button(misc_->check_exit_confirm,
360                               lyxrc.exit_confirmation);
361                 fl_set_button(misc_->check_display_shortcuts,
362                               lyxrc.display_shortcuts);
363                 fl_set_counter_value(misc_->counter_autosave,
364                                      lyxrc.autosave);
365                 fl_set_counter_value(misc_->counter_line_len,
366                                      lyxrc.ascii_linelen);
367                 // Screen fonts
368                 fl_set_input(screen_fonts_->input_roman,
369                              lyxrc.roman_font_name.c_str());
370                 fl_set_input(screen_fonts_->input_sans,
371                              lyxrc.sans_font_name.c_str());
372                 fl_set_input(screen_fonts_->input_typewriter,
373                              lyxrc.typewriter_font_name.c_str());
374                 fl_set_input(screen_fonts_->input_screen_encoding,
375                              lyxrc.font_norm.c_str());
376                 fl_set_button(screen_fonts_->check_scalable,
377                              lyxrc.use_scalable_fonts);
378                 fl_set_counter_value(screen_fonts_->counter_zoom,
379                              lyxrc.zoom);
380                 fl_set_input(screen_fonts_->input_tiny,
381                              tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
382                 fl_set_input(screen_fonts_->input_script,
383                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
384                 fl_set_input(screen_fonts_->input_footnote,
385                              tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
386                 fl_set_input(screen_fonts_->input_small,
387                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
388                 fl_set_input(screen_fonts_->input_normal,
389                              tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
390                 fl_set_input(screen_fonts_->input_large,
391                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
392                 fl_set_input(screen_fonts_->input_larger,
393                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
394                 fl_set_input(screen_fonts_->input_largest,
395                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
396                 fl_set_input(screen_fonts_->input_huge,
397                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
398                 fl_set_input(screen_fonts_->input_huger,
399                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
400                 // interface fonts
401                 fl_set_input(interface_fonts_->input_popup_font,
402                              lyxrc.popup_font_name.c_str());
403                 fl_set_input(interface_fonts_->input_menu_font,
404                              lyxrc.menu_font_name.c_str());
405                 fl_set_input(interface_fonts_->input_popup_encoding,
406                              lyxrc.font_norm_menu.c_str());
407                 // printer
408                 fl_set_button(printer_->check_adapt_output,
409                               lyxrc.print_adapt_output);
410                 fl_set_input(printer_->input_command,
411                              lyxrc.print_command.c_str());
412                 fl_set_input(printer_->input_page_range,
413                              lyxrc.print_pagerange_flag.c_str());
414                 fl_set_input(printer_->input_copies,
415                              lyxrc.print_copies_flag.c_str());
416                 fl_set_input(printer_->input_reverse,
417                               lyxrc.print_reverse_flag.c_str());
418                 fl_set_input(printer_->input_to_printer,
419                              lyxrc.print_to_printer.c_str());
420                 fl_set_input(printer_->input_file_extension,
421                              lyxrc.print_file_extension.c_str());
422                 fl_set_input(printer_->input_spool_command,
423                              lyxrc.print_spool_command.c_str());
424                 fl_set_input(printer_->input_paper_type,
425                              lyxrc.print_paper_flag.c_str());
426                 fl_set_input(printer_->input_even_pages,
427                              lyxrc.print_evenpage_flag.c_str());
428                 fl_set_input(printer_->input_odd_pages,
429                              lyxrc.print_oddpage_flag.c_str());
430                 fl_set_input(printer_->input_collated,
431                              lyxrc.print_collcopies_flag.c_str());
432                 fl_set_input(printer_->input_landscape,
433                              lyxrc.print_landscape_flag.c_str());
434                 fl_set_input(printer_->input_to_file,
435                              lyxrc.print_to_file.c_str());
436                 fl_set_input(printer_->input_extra_options,
437                              lyxrc.print_extra_options.c_str());
438                 fl_set_input(printer_->input_spool_prefix,
439                              lyxrc.print_spool_printerprefix.c_str());
440                 fl_set_input(printer_->input_paper_size,
441                              lyxrc.print_paper_dimension_flag.c_str());
442                 fl_set_input(printer_->input_name,
443                              lyxrc.printer.c_str());
444                 // paths
445                 fl_set_input(paths_->input_default_path,
446                              lyxrc.document_path.c_str());
447                 fl_set_input(paths_->input_template_path,
448                              lyxrc.template_path.c_str());
449                 fl_set_input(paths_->input_temp_dir,
450                              lyxrc.tempdir_path.c_str());
451                 fl_set_input(paths_->input_lastfiles,
452                              lyxrc.lastfiles.c_str());
453                 fl_set_input(paths_->input_backup_path,
454                              lyxrc.backupdir_path.c_str());
455                 fl_set_button(paths_->check_use_temp_dir,
456                               lyxrc.use_tempdir);
457                 fl_set_button(paths_->check_last_files,
458                               lyxrc.check_lastfiles);           
459                 fl_set_button(paths_->check_make_backups,
460                               lyxrc.make_backup);
461                 fl_set_counter_value(paths_->counter_lastfiles,
462                                      lyxrc.num_lastfiles);
463         }
464 }
465
466
467 bool FormPreferences::input()
468 {
469         bool activate = true;
470         //
471         // whatever checks you need to ensure the user hasn't entered
472         // some totally ridiculous value somewhere.  Change activate to suit.
473         //
474         // Examples:
475         //  paths -- all dirs in the path should exist, be writable & absolute
476         if (!AbsolutePath(fl_get_input(paths_->input_default_path))
477             || 1 != IsDirWriteable(fl_get_input(paths_->input_default_path))
478             || !AbsolutePath(fl_get_input(paths_->input_template_path))
479             || 1 != IsDirWriteable(fl_get_input(paths_->input_template_path))
480             // lastfiles: exists && writeable || non-existent && isn't a dir
481             // NOTE: assumes IsFileWriteable == -1 means non-existent hence
482             //       the extra check to see if its a directory
483             || !AbsolutePath(fl_get_input(paths_->input_lastfiles))
484             || 1 != IsDirWriteable(OnlyPath(fl_get_input(paths_->
485                                                          input_lastfiles)))
486             || 0 == IsFileWriteable(OnlyPath(fl_get_input(paths_->
487                                                           input_lastfiles)))
488             || FileInfo(fl_get_input(paths_->input_lastfiles)).isDir()
489             // tmpdir: only check if we are using it
490             || (fl_get_button(paths_->check_use_temp_dir)
491                 && (1 != IsDirWriteable(fl_get_input(paths_->input_temp_dir))
492                     || !AbsolutePath(fl_get_input(paths_->input_temp_dir))))
493             // backupdir: can safely be left empty
494             || (fl_get_button(paths_->check_make_backups)
495                 && (!string(fl_get_input(paths_->input_backup_path)).empty()
496                     && (1 != IsDirWriteable(fl_get_input(paths_->
497                                                         input_backup_path))
498                         || !AbsolutePath(fl_get_input(paths_->
499                                                       input_backup_path)))))) {
500                 activate = false;
501                 lyxerr[Debug::GUI] << "Preferences: Path is wrong\n";
502         }
503
504         //  fontsizes -- tiny < script < footnote etc.
505         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
506             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
507             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
508             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
509             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
510             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
511             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
512             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
513             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
514             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
515                 // make sure they all have positive entries
516                 // Also note that an empty entry is returned as 0.0 by strToDbl
517                 activate = false;
518                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
519         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
520                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
521                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
522                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
523                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
524                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
525                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
526                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
527                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
528                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
529                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
530                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
531                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
532                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
533                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
534                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
535                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
536                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
537                 activate = false;
538                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
539         }
540
541         return activate;
542 }
543
544
545 int FormPreferences::WMHideCB(FL_FORM * form, void *)
546 {
547         // Ensure that the signals (u and h) are disconnected even if the
548         // window manager is used to close the dialog.
549         FormPreferences * pre = static_cast<FormPreferences*>(form->u_vdata);
550         pre->hide();
551         pre->bc_->hide();
552         return FL_CANCEL;
553 }
554
555
556 void FormPreferences::OKCB(FL_OBJECT * ob, long)
557 {
558         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
559         pre->apply();
560         pre->hide();
561         pre->bc_->ok();
562         pre->lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
563 }
564
565
566 void FormPreferences::ApplyCB(FL_OBJECT * ob, long)
567 {
568         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
569         pre->apply();
570         pre->bc_->apply();
571 }
572
573
574 void FormPreferences::CancelCB(FL_OBJECT * ob, long)
575 {
576         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
577         pre->hide();
578         pre->bc_->cancel();
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 }