]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormPreferences.C
5815dd11ad95f42a988357ed6bbfbba7bc3484f0
[features.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 "input_validators.h"
16 #include "LyXView.h"
17 #include "lyxfunc.h"
18 #include "Dialogs.h"
19 #include "lyxrc.h"
20 #include "debug.h"
21 #include "support/FileInfo.h"
22 #include "support/filetools.h"
23 #include "lyx_gui_misc.h"
24
25 #ifdef SIGC_CXX_NAMESPACES
26 using SigC::slot;
27 #endif
28
29
30 FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
31         : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy),
32           dialog_(0), outputs_tab_(0), look_n_feel_tab_(0), inputs_tab_(0),
33           lnf_general_(0), screen_fonts_(0), interface_(0),
34           printer_(0), paths_(0), outputs_general_(0)
35 {
36         // let the dialog be shown
37         // This is a permanent connection so we won't bother
38         // storing a copy because we won't be disconnecting.
39         d->showPreferences.connect(slot(this, &FormPreferences::show));
40 }
41
42
43 FormPreferences::~FormPreferences()
44 {
45         delete dialog_;
46         delete look_n_feel_tab_;
47         delete inputs_tab_;
48         delete outputs_tab_;
49         delete lnf_general_;
50         delete screen_fonts_;
51         delete interface_;
52         delete printer_;
53         delete paths_;
54         delete outputs_general_;
55 }
56
57
58 void FormPreferences::hide()
59 {
60         // We need to hide the active tabfolder otherwise we get a
61         // BadDrawable error from X windows and LyX crashes without saving.
62         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder_prefs);
63         if (outer_form
64             && outer_form->visible) {
65                 fl_hide_form(outer_form);
66         }
67         FormBase::hide();
68 }
69
70
71 void FormPreferences::build()
72 {
73         dialog_ = build_preferences();
74
75         // manage the restore, save, apply and cancel/close buttons
76         bc_.setOK(dialog_->button_ok);
77         bc_.setApply(dialog_->button_apply);
78         bc_.setCancel(dialog_->button_cancel);
79         bc_.setUndoAll(dialog_->button_restore);
80         bc_.refresh();
81
82         // Workaround dumb xforms sizing bug
83         minw_ = form()->w;
84         minh_ = form()->h;
85
86         // build the tab folders
87         outputs_tab_ = build_outer_tab();
88         look_n_feel_tab_ = build_outer_tab();
89         inputs_tab_  = build_outer_tab();
90
91         // build actual tabfolder contents
92         // these will become nested tabfolders
93         screen_fonts_ = build_screen_fonts();
94         interface_ = build_interface();
95         lnf_general_ = build_lnf_general();
96         printer_ = build_printer();
97         paths_ = build_paths();
98         outputs_general_ = build_outputs_general();
99
100         // setup the input returns
101         // Lnf_General tab
102         fl_set_counter_return(lnf_general_->counter_autosave, FL_RETURN_CHANGED);
103         fl_set_counter_return(lnf_general_->counter_wm_jump, FL_RETURN_CHANGED);
104         // Screen fonts
105         fl_set_input_return(screen_fonts_->input_roman, FL_RETURN_CHANGED);
106         fl_set_input_return(screen_fonts_->input_sans, FL_RETURN_CHANGED);
107         fl_set_input_return(screen_fonts_->input_typewriter,
108                             FL_RETURN_CHANGED);
109         fl_set_input_return(screen_fonts_->input_screen_encoding,
110                             FL_RETURN_CHANGED);
111         fl_set_counter_return(screen_fonts_->counter_zoom, FL_RETURN_CHANGED);
112         fl_set_input_return(screen_fonts_->input_tiny, FL_RETURN_CHANGED);
113         fl_set_input_return(screen_fonts_->input_script, FL_RETURN_CHANGED);
114         fl_set_input_return(screen_fonts_->input_footnote, FL_RETURN_CHANGED);
115         fl_set_input_return(screen_fonts_->input_small, FL_RETURN_CHANGED);
116         fl_set_input_return(screen_fonts_->input_normal, FL_RETURN_CHANGED);
117         fl_set_input_return(screen_fonts_->input_large, FL_RETURN_CHANGED);
118         fl_set_input_return(screen_fonts_->input_larger, FL_RETURN_CHANGED);
119         fl_set_input_return(screen_fonts_->input_largest, FL_RETURN_CHANGED);
120         fl_set_input_return(screen_fonts_->input_huge, FL_RETURN_CHANGED);
121         fl_set_input_return(screen_fonts_->input_huger, FL_RETURN_CHANGED);
122         // interface
123         fl_set_input_return(interface_->input_popup_font,
124                             FL_RETURN_CHANGED);
125         fl_set_input_return(interface_->input_menu_font,
126                             FL_RETURN_CHANGED);
127         fl_set_input_return(interface_->input_popup_encoding,
128                             FL_RETURN_CHANGED);
129         fl_set_input_return(interface_->input_bind_file,
130                             FL_RETURN_CHANGED);
131         fl_set_input_return(interface_->input_ui_file,
132                             FL_RETURN_CHANGED);
133         // printer
134         fl_set_input_return(printer_->input_command, FL_RETURN_CHANGED);
135         fl_set_input_return(printer_->input_page_range, FL_RETURN_CHANGED);
136         fl_set_input_return(printer_->input_copies, FL_RETURN_CHANGED);
137         fl_set_input_return(printer_->input_reverse, FL_RETURN_CHANGED);
138         fl_set_input_return(printer_->input_to_printer, FL_RETURN_CHANGED);
139         fl_set_input_return(printer_->input_file_extension, FL_RETURN_CHANGED);
140         fl_set_input_return(printer_->input_spool_command, FL_RETURN_CHANGED);
141         fl_set_input_return(printer_->input_paper_type, FL_RETURN_CHANGED);
142         fl_set_input_return(printer_->input_even_pages, FL_RETURN_CHANGED);
143         fl_set_input_return(printer_->input_odd_pages, FL_RETURN_CHANGED);
144         fl_set_input_return(printer_->input_collated, FL_RETURN_CHANGED);
145         fl_set_input_return(printer_->input_landscape, FL_RETURN_CHANGED);
146         fl_set_input_return(printer_->input_to_file, FL_RETURN_CHANGED);
147         fl_set_input_return(printer_->input_extra_options, FL_RETURN_CHANGED);
148         fl_set_input_return(printer_->input_spool_prefix, FL_RETURN_CHANGED);
149         fl_set_input_return(printer_->input_paper_size, FL_RETURN_CHANGED);
150         fl_set_input_return(printer_->input_name, FL_RETURN_CHANGED);
151         // paths
152         fl_set_input_return(paths_->input_default_path, FL_RETURN_CHANGED);
153         fl_set_input_return(paths_->input_template_path, FL_RETURN_CHANGED);
154         fl_set_input_return(paths_->input_temp_dir, FL_RETURN_CHANGED);
155         fl_set_input_return(paths_->input_lastfiles, FL_RETURN_CHANGED);
156         fl_set_input_return(paths_->input_backup_path, FL_RETURN_CHANGED);
157         fl_set_counter_return(paths_->counter_lastfiles, FL_RETURN_CHANGED);
158         fl_set_input_return(paths_->input_serverpipe, FL_RETURN_CHANGED);
159         // outputs general
160         fl_set_counter_return(outputs_general_->counter_line_len,
161                               FL_RETURN_CHANGED);
162
163         // Now add them to the tabfolder
164         fl_addto_tabfolder(dialog_->tabfolder_prefs,
165                            _("Look and Feel"),
166                            look_n_feel_tab_->form);
167         fl_addto_tabfolder(dialog_->tabfolder_prefs,
168                            _("Inputs"),
169                            inputs_tab_->form);
170         fl_addto_tabfolder(dialog_->tabfolder_prefs,
171                            _("Outputs"),
172                            outputs_tab_->form);
173
174         // now build the nested tabfolders
175         // Starting with look and feel
176         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
177                            _("Screen Fonts"),
178                            screen_fonts_->form);
179         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
180                            _("Interface"),
181                            interface_->form);
182         fl_addto_tabfolder(look_n_feel_tab_->tabfolder_outer,
183                            _("General"),
184                            lnf_general_->form);
185
186         // then build inputs
187         // Paths should probably go in a few outer_tab called Files
188         fl_addto_tabfolder(inputs_tab_->tabfolder_outer,
189                            _("Paths"),
190                            paths_->form);
191
192         // then building outputs
193         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
194                            _("Printer"),
195                            printer_->form);
196         fl_addto_tabfolder(outputs_tab_->tabfolder_outer,
197                            _("General"),
198                            outputs_general_->form);
199
200         // deactivate the various browse buttons because they
201         // currently aren't implemented
202         fl_deactivate_object(interface_->button_bind_file_browse);
203         fl_deactivate_object(interface_->button_ui_file_browse);
204         fl_deactivate_object(paths_->button_document_browse);
205         fl_deactivate_object(paths_->button_template_browse);
206         fl_deactivate_object(paths_->button_temp_dir_browse);
207         fl_deactivate_object(paths_->button_lastfiles_browse);
208         fl_deactivate_object(paths_->button_backup_path_browse);
209         fl_deactivate_object(paths_->button_serverpipe_browse);
210         fl_set_object_lcol(interface_->button_bind_file_browse, FL_INACTIVE);
211         fl_set_object_lcol(interface_->button_ui_file_browse, FL_INACTIVE);
212         fl_set_object_lcol(paths_->button_document_browse, FL_INACTIVE);
213         fl_set_object_lcol(paths_->button_template_browse, FL_INACTIVE);
214         fl_set_object_lcol(paths_->button_temp_dir_browse, FL_INACTIVE);
215         fl_set_object_lcol(paths_->button_lastfiles_browse, FL_INACTIVE);
216         fl_set_object_lcol(paths_->button_backup_path_browse, FL_INACTIVE);
217         fl_set_object_lcol(paths_->button_serverpipe_browse, FL_INACTIVE);
218 }
219
220
221 FL_FORM * FormPreferences::form() const
222 {
223         if (dialog_) return dialog_->form;
224         return 0;
225 }
226
227
228 void FormPreferences::apply()
229 {
230         // set the new lyxrc entries
231         // many of these need to trigger other functions when the assignment
232         // is made.  For example, screen zoom and font types.  These could be
233         // handled either by signals/slots in lyxrc or just directly call the
234         // associated functions here.
235         // There are other problems with this scheme.  We really should check
236         // what we copy to make sure that it really is necessary to do things
237         // like update the screen fonts because that flushes the textcache
238         // and other stuff which may cost us a lot on slower/high-load machines.
239         
240         // Look 'n Feel General tab
241         lyxrc.show_banner = fl_get_button(lnf_general_->check_banner);
242         lyxrc.auto_region_delete = fl_get_button(lnf_general_->
243                                                  check_auto_region_delete);
244         lyxrc.exit_confirmation = fl_get_button(lnf_general_->check_exit_confirm);
245         lyxrc.display_shortcuts =
246                 fl_get_button(lnf_general_->check_display_shortcuts);
247         lyxrc.new_ask_filename = fl_get_button(lnf_general_->check_ask_new_file);
248         lyxrc.cursor_follows_scrollbar =
249                 fl_get_button(lnf_general_->check_cursor_follows_scrollbar);
250         lyxrc.autosave = static_cast<unsigned int>
251                 (fl_get_counter_value(lnf_general_->counter_autosave));
252         lyxrc.wheel_jump = static_cast<unsigned int>
253                 (fl_get_counter_value(lnf_general_->counter_wm_jump));
254         // Interface
255         lyxrc.popup_font_name =
256                 fl_get_input(interface_->input_popup_font);
257         lyxrc.menu_font_name = fl_get_input(interface_->input_menu_font);
258         lyxrc.font_norm_menu =
259                 fl_get_input(interface_->input_popup_encoding);
260         lyxrc.bind_file = fl_get_input(interface_->input_bind_file);
261         lyxrc.ui_file = fl_get_input(interface_->input_ui_file);
262         lyxrc.override_x_deadkeys =
263                 fl_get_button(interface_->check_override_x_dead_keys);
264         // Screen fonts
265         if (lyxrc.roman_font_name !=
266             fl_get_input(screen_fonts_->input_roman) ||
267             lyxrc.sans_font_name !=
268             fl_get_input(screen_fonts_->input_sans) ||
269             lyxrc.typewriter_font_name !=
270             fl_get_input(screen_fonts_->input_typewriter) ||
271             lyxrc.font_norm !=
272             fl_get_input(screen_fonts_->input_screen_encoding) ||
273             lyxrc.use_scalable_fonts !=
274             fl_get_button(screen_fonts_->check_scalable) ||
275             lyxrc.zoom != static_cast<unsigned int>
276             (fl_get_counter_value(screen_fonts_->counter_zoom)) ||
277             lyxrc.font_sizes[LyXFont::SIZE_TINY] !=
278             strToDbl(fl_get_input(screen_fonts_->input_tiny)) ||
279             lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] !=
280             strToDbl(fl_get_input(screen_fonts_->input_script)) ||
281             lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] !=
282             strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
283             lyxrc.font_sizes[LyXFont::SIZE_SMALL] !=
284             strToDbl(fl_get_input(screen_fonts_->input_small)) ||
285             lyxrc.font_sizes[LyXFont::SIZE_NORMAL] !=
286             strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
287             lyxrc.font_sizes[LyXFont::SIZE_LARGE] !=
288             strToDbl(fl_get_input(screen_fonts_->input_large)) ||
289             lyxrc.font_sizes[LyXFont::SIZE_LARGER] !=
290             strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
291             lyxrc.font_sizes[LyXFont::SIZE_LARGEST] !=
292             strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
293             lyxrc.font_sizes[LyXFont::SIZE_HUGE] !=
294             strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
295             lyxrc.font_sizes[LyXFont::SIZE_HUGER] !=
296             strToDbl(fl_get_input(screen_fonts_->input_huger))) {
297                 // Something has changed so copy all of them and then force
298                 // an update of the screen fonts (ie. redraw every buffer)
299                 lyxrc.roman_font_name = fl_get_input(screen_fonts_->input_roman);
300                 lyxrc.sans_font_name = fl_get_input(screen_fonts_->input_sans);
301                 lyxrc.typewriter_font_name = fl_get_input(screen_fonts_->
302                                                           input_typewriter);
303                 lyxrc.font_norm = fl_get_input(screen_fonts_->
304                                                input_screen_encoding);
305                 lyxrc.use_scalable_fonts =
306                         fl_get_button(screen_fonts_->check_scalable);
307                 lyxrc.zoom = static_cast<unsigned int>
308                         (fl_get_counter_value(screen_fonts_->counter_zoom));
309                 lyxrc.font_sizes[LyXFont::SIZE_TINY] = 
310                         strToDbl(fl_get_input(screen_fonts_->input_tiny));
311                 lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] =
312                         strToDbl(fl_get_input(screen_fonts_->input_script));
313                 lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] =
314                         strToDbl(fl_get_input(screen_fonts_->input_footnote));
315                 lyxrc.font_sizes[LyXFont::SIZE_SMALL] =
316                         strToDbl(fl_get_input(screen_fonts_->input_small));
317                 lyxrc.font_sizes[LyXFont::SIZE_NORMAL] =
318                         strToDbl(fl_get_input(screen_fonts_->input_normal));
319                 lyxrc.font_sizes[LyXFont::SIZE_LARGE] =
320                         strToDbl(fl_get_input(screen_fonts_->input_large));
321                 lyxrc.font_sizes[LyXFont::SIZE_LARGER] =
322                 strToDbl(fl_get_input(screen_fonts_->input_larger));
323                 lyxrc.font_sizes[LyXFont::SIZE_LARGEST] =
324                         strToDbl(fl_get_input(screen_fonts_->input_largest));
325                 lyxrc.font_sizes[LyXFont::SIZE_HUGE] =
326                         strToDbl(fl_get_input(screen_fonts_->input_huge));
327                 lyxrc.font_sizes[LyXFont::SIZE_HUGER] =
328                         strToDbl(fl_get_input(screen_fonts_->input_huger));
329                 // Now update the buffers
330                 // Can anything below here affect the redraw process?
331                 lv_->getLyXFunc()->Dispatch(LFUN_SCREEN_FONT_UPDATE);
332         }
333         // printer
334         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
335         lyxrc.print_command = fl_get_input(printer_->input_command);
336         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
337         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
338         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
339         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
340         lyxrc.print_file_extension =
341                 fl_get_input(printer_->input_file_extension);
342         lyxrc.print_spool_command =
343                 fl_get_input(printer_->input_spool_command);
344         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
345         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
346         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
347         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
348         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
349         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
350         lyxrc.print_extra_options =
351                 fl_get_input(printer_->input_extra_options);
352         lyxrc.print_spool_printerprefix =
353                 fl_get_input(printer_->input_spool_prefix);
354         lyxrc.print_paper_dimension_flag =
355                 fl_get_input(printer_->input_paper_size);
356         lyxrc.printer = fl_get_input(printer_->input_name);
357         // paths
358         lyxrc.document_path = fl_get_input(paths_->input_default_path);
359         lyxrc.template_path = fl_get_input(paths_->input_template_path);
360         lyxrc.tempdir_path = fl_get_input(paths_->input_temp_dir);
361         lyxrc.lastfiles = fl_get_input(paths_->input_lastfiles);
362         lyxrc.backupdir_path = fl_get_input(paths_->input_backup_path);
363         lyxrc.use_tempdir = fl_get_button(paths_->check_use_temp_dir);
364         lyxrc.check_lastfiles = fl_get_button(paths_->check_last_files);
365         lyxrc.make_backup = fl_get_button(paths_->check_make_backups);
366         lyxrc.num_lastfiles = static_cast<unsigned int>
367                 (fl_get_counter_value(paths_->counter_lastfiles));
368         lyxrc.lyxpipes = fl_get_input(paths_->input_serverpipe);
369         // outputs general
370         lyxrc.ascii_linelen = static_cast<unsigned int>
371                 (fl_get_counter_value(outputs_general_->counter_line_len));
372 }
373
374
375 // we can safely ignore the parameter because we can always update
376 void FormPreferences::update(bool)
377 {
378         if (dialog_) {
379                 // read lyxrc entries
380                 // Lnf_General tab
381                 fl_set_button(lnf_general_->check_banner,
382                               lyxrc.show_banner);
383                 fl_set_button(lnf_general_->check_auto_region_delete,
384                               lyxrc.auto_region_delete);
385                 fl_set_button(lnf_general_->check_exit_confirm,
386                               lyxrc.exit_confirmation);
387                 fl_set_button(lnf_general_->check_display_shortcuts,
388                               lyxrc.display_shortcuts);
389                 fl_set_button(lnf_general_->check_ask_new_file,
390                               lyxrc.new_ask_filename);
391                 fl_set_button(lnf_general_->check_cursor_follows_scrollbar,
392                               lyxrc.cursor_follows_scrollbar);
393                 fl_set_counter_value(lnf_general_->counter_autosave,
394                                      lyxrc.autosave);
395                 fl_set_counter_value(lnf_general_->counter_wm_jump,
396                                      lyxrc.wheel_jump);
397                 // Screen fonts
398                 fl_set_input(screen_fonts_->input_roman,
399                              lyxrc.roman_font_name.c_str());
400                 fl_set_input(screen_fonts_->input_sans,
401                              lyxrc.sans_font_name.c_str());
402                 fl_set_input(screen_fonts_->input_typewriter,
403                              lyxrc.typewriter_font_name.c_str());
404                 fl_set_input(screen_fonts_->input_screen_encoding,
405                              lyxrc.font_norm.c_str());
406                 fl_set_button(screen_fonts_->check_scalable,
407                              lyxrc.use_scalable_fonts);
408                 fl_set_counter_value(screen_fonts_->counter_zoom,
409                              lyxrc.zoom);
410                 fl_set_input(screen_fonts_->input_tiny,
411                              tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
412                 fl_set_input(screen_fonts_->input_script,
413                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
414                 fl_set_input(screen_fonts_->input_footnote,
415                              tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
416                 fl_set_input(screen_fonts_->input_small,
417                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
418                 fl_set_input(screen_fonts_->input_normal,
419                              tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
420                 fl_set_input(screen_fonts_->input_large,
421                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
422                 fl_set_input(screen_fonts_->input_larger,
423                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
424                 fl_set_input(screen_fonts_->input_largest,
425                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
426                 fl_set_input(screen_fonts_->input_huge,
427                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
428                 fl_set_input(screen_fonts_->input_huger,
429                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
430                 // interface
431                 fl_set_input(interface_->input_popup_font,
432                              lyxrc.popup_font_name.c_str());
433                 fl_set_input(interface_->input_menu_font,
434                              lyxrc.menu_font_name.c_str());
435                 fl_set_input(interface_->input_popup_encoding,
436                              lyxrc.font_norm_menu.c_str());
437                 fl_set_input(interface_->input_bind_file,
438                              lyxrc.bind_file.c_str());
439                 fl_set_input(interface_->input_ui_file,
440                              lyxrc.ui_file.c_str());
441                 fl_set_button(interface_->check_override_x_dead_keys,
442                               lyxrc.override_x_deadkeys);
443                 // printer
444                 fl_set_button(printer_->check_adapt_output,
445                               lyxrc.print_adapt_output);
446                 fl_set_input(printer_->input_command,
447                              lyxrc.print_command.c_str());
448                 fl_set_input(printer_->input_page_range,
449                              lyxrc.print_pagerange_flag.c_str());
450                 fl_set_input(printer_->input_copies,
451                              lyxrc.print_copies_flag.c_str());
452                 fl_set_input(printer_->input_reverse,
453                               lyxrc.print_reverse_flag.c_str());
454                 fl_set_input(printer_->input_to_printer,
455                              lyxrc.print_to_printer.c_str());
456                 fl_set_input(printer_->input_file_extension,
457                              lyxrc.print_file_extension.c_str());
458                 fl_set_input(printer_->input_spool_command,
459                              lyxrc.print_spool_command.c_str());
460                 fl_set_input(printer_->input_paper_type,
461                              lyxrc.print_paper_flag.c_str());
462                 fl_set_input(printer_->input_even_pages,
463                              lyxrc.print_evenpage_flag.c_str());
464                 fl_set_input(printer_->input_odd_pages,
465                              lyxrc.print_oddpage_flag.c_str());
466                 fl_set_input(printer_->input_collated,
467                              lyxrc.print_collcopies_flag.c_str());
468                 fl_set_input(printer_->input_landscape,
469                              lyxrc.print_landscape_flag.c_str());
470                 fl_set_input(printer_->input_to_file,
471                              lyxrc.print_to_file.c_str());
472                 fl_set_input(printer_->input_extra_options,
473                              lyxrc.print_extra_options.c_str());
474                 fl_set_input(printer_->input_spool_prefix,
475                              lyxrc.print_spool_printerprefix.c_str());
476                 fl_set_input(printer_->input_paper_size,
477                              lyxrc.print_paper_dimension_flag.c_str());
478                 fl_set_input(printer_->input_name,
479                              lyxrc.printer.c_str());
480                 // paths
481                 fl_set_input(paths_->input_default_path,
482                              lyxrc.document_path.c_str());
483                 fl_set_input(paths_->input_template_path,
484                              lyxrc.template_path.c_str());
485                 fl_set_input(paths_->input_temp_dir,
486                              lyxrc.tempdir_path.c_str());
487                 fl_set_input(paths_->input_lastfiles,
488                              lyxrc.lastfiles.c_str());
489                 fl_set_input(paths_->input_backup_path,
490                              lyxrc.backupdir_path.c_str());
491                 fl_set_button(paths_->check_use_temp_dir,
492                               lyxrc.use_tempdir);
493                 fl_set_button(paths_->check_last_files,
494                               lyxrc.check_lastfiles);           
495                 fl_set_button(paths_->check_make_backups,
496                               lyxrc.make_backup);
497                 fl_set_counter_value(paths_->counter_lastfiles,
498                                      lyxrc.num_lastfiles);
499                 fl_set_input(paths_->input_serverpipe, lyxrc.lyxpipes.c_str());
500                 // outputs general
501                 fl_set_counter_value(outputs_general_->counter_line_len,
502                                      lyxrc.ascii_linelen);
503
504         }
505 }
506
507
508 bool FormPreferences::input(FL_OBJECT *, long)
509 {
510         bool activate = true;
511         //
512         // whatever checks you need to ensure the user hasn't entered
513         // some totally ridiculous value somewhere.  Change activate to suit.
514         // comments before each test describe what is _valid_
515
516         // input path -- dir should exist, be writable & absolute
517         if (!AbsolutePath(fl_get_input(paths_->input_default_path))
518             || 1 != IsDirWriteable(fl_get_input(paths_->input_default_path))) {
519                 activate = false;
520                 lyxerr[Debug::GUI] << "Preferences: input path is wrong\n";
521         }
522
523         {
524                 // template_path should be a readable directory
525                 string temp(fl_get_input(paths_->input_template_path));
526                 FileInfo tp(temp);
527                 if (!AbsolutePath(temp)
528                     || !tp.isDir()
529                     || !tp.readable()) {
530                         activate = false;
531                         lyxerr[Debug::GUI] << "Preferences: template path is wrong\n";
532                 }
533         }
534
535         // tmpdir:  not used
536         //          || writable directory
537         if (fl_get_button(paths_->check_use_temp_dir)
538             && (1 != IsDirWriteable(fl_get_input(paths_->input_temp_dir))
539                 || !AbsolutePath(fl_get_input(paths_->input_temp_dir)))) {
540                 activate = false;
541                 lyxerr[Debug::GUI] << "Preferences: tmpdir is wrong\n";
542         }
543
544         // backupdir: not used
545         //            || empty
546         //            || writable dir
547         if (fl_get_button(paths_->check_make_backups)
548             && (!string(fl_get_input(paths_->input_backup_path)).empty()
549                 && (1 != IsDirWriteable(fl_get_input(paths_->
550                                                      input_backup_path))
551                     || !AbsolutePath(fl_get_input(paths_->
552                                                   input_backup_path))))) {
553                 activate = false;
554                 lyxerr[Debug::GUI] << "Preferences: backupdir is wrong\n";
555         }
556
557         // lastfiles: exists && writeable
558         //            || non-existent && isn't a dir
559 #ifdef WITH_WARNINGS
560 #warning incorrectly allows files in /, other tests might also do this
561 #endif
562         {
563                 string lastfiles(fl_get_input(paths_->input_lastfiles));
564                 FileInfo lf(lastfiles);
565                 if (!AbsolutePath(lastfiles)
566                     || 1 != IsDirWriteable(OnlyPath(lastfiles))
567                     || (lf.exist()
568                         && (lf.isDir()
569                             || !lf.writable()))) {
570                         activate = false;
571                         lyxerr[Debug::GUI] << "Preferences: lastfiles is wrong\n";
572                 }
573         }
574
575         // serverpipe:  empty
576         //              || non-existent && isn't a dir
577         //              || exists && writeable
578         // remember we append .in and .out later
579         if (!string(fl_get_input(paths_->input_serverpipe)).empty()) {
580                 string pipe(fl_get_input(paths_->input_serverpipe));
581                 FileInfo sp_in(pipe + ".in");
582                 FileInfo sp_out(pipe + ".out");
583                 if (!AbsolutePath(pipe)
584                     || 1 != IsDirWriteable(OnlyPath(pipe))
585                     || (sp_in.exist()
586                         && (!sp_in.writable()
587                             || sp_in.isDir()))
588                     || (sp_out.exist()
589                         && (!sp_out.writable()
590                             || sp_out.isDir()))) {
591                         activate = false;
592                         lyxerr[Debug::GUI] << "Preferences: Serverpipe is wrong\n";
593                 }
594         }
595
596         //  fontsizes -- tiny < script < footnote etc.
597         if (0.0 >= strToDbl(fl_get_input(screen_fonts_->input_tiny))
598             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_script))
599             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_footnote))
600             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_small))
601             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_normal))
602             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_large))
603             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_larger))
604             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_largest))
605             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huge))
606             || 0.0 >= strToDbl(fl_get_input(screen_fonts_->input_huger))) {
607                 // make sure they all have positive entries
608                 // Also note that an empty entry is returned as 0.0 by strToDbl
609                 activate = false;
610                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
611         } else if (strToDbl(fl_get_input(screen_fonts_->input_tiny)) >
612                    strToDbl(fl_get_input(screen_fonts_->input_script)) ||
613                    strToDbl(fl_get_input(screen_fonts_->input_script)) >
614                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) ||
615                    strToDbl(fl_get_input(screen_fonts_->input_footnote)) >
616                    strToDbl(fl_get_input(screen_fonts_->input_small)) ||
617                    strToDbl(fl_get_input(screen_fonts_->input_small)) >
618                    strToDbl(fl_get_input(screen_fonts_->input_normal)) ||
619                    strToDbl(fl_get_input(screen_fonts_->input_normal)) >
620                    strToDbl(fl_get_input(screen_fonts_->input_large)) ||
621                    strToDbl(fl_get_input(screen_fonts_->input_large)) >
622                    strToDbl(fl_get_input(screen_fonts_->input_larger)) ||
623                    strToDbl(fl_get_input(screen_fonts_->input_larger)) >
624                    strToDbl(fl_get_input(screen_fonts_->input_largest)) ||
625                    strToDbl(fl_get_input(screen_fonts_->input_largest)) >
626                    strToDbl(fl_get_input(screen_fonts_->input_huge)) ||
627                    strToDbl(fl_get_input(screen_fonts_->input_huge)) >
628                    strToDbl(fl_get_input(screen_fonts_->input_huger))) {
629                 activate = false;
630                 lyxerr[Debug::GUI] << "Preferences: Sizes are wrong\n";
631         }
632
633         return activate;
634 }
635
636
637 void FormPreferences::ok()
638 {
639         FormBase::ok();
640         lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
641 }
642
643
644 void FormPreferences::restore()
645 {
646         update();
647 // if I add an error message line to the dialog it'll have to be controlled
648 // within input().  I don't need it yet so I'll leave it commented out.
649 //      bc_.valid(input(0));
650 }