]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormPreferences.C
Headers cleanup from Angus
[features.git] / src / frontends / xforms / FormPreferences.C
1 /* FormPreferences.C
2  * FormPreferences Interface Class Implementation
3  */
4
5 #include <config.h>
6 #include "lyx_gui_misc.h"
7 #include "gettext.h"
8 #include FORMS_H_LOCATION
9
10 #include "FormPreferences.h"
11 #include "form_preferences.h"
12 #include "xform_macros.h"
13 #include "input_validators.h"
14 #include "LyXView.h"
15 #include "lyxfunc.h"
16 #include "Dialogs.h"
17 #include "lyxrc.h"
18 #include "debug.h"
19
20
21 #ifdef SIGC_CXX_NAMESPACES
22 using SigC::slot;
23 #endif
24
25 C_RETURNCB(FormPreferences,  WMHideCB)
26 C_GENERICCB(FormPreferences, OKCB)
27 C_GENERICCB(FormPreferences, ApplyCB)
28 C_GENERICCB(FormPreferences, CancelCB)
29 C_GENERICCB(FormPreferences, InputCB)
30
31
32 FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
33         : dialog_(0), bind_(0), misc_(0), screen_fonts_(0),
34           interface_fonts_(0), printer_(0), paths_(0),
35           lv_(lv), d_(d), u_(0), h_(0)
36 {
37         // let the dialog be shown
38         // This is a permanent connection so we won't bother
39         // storing a copy because we won't be disconnecting.
40         d->showPreferences.connect(slot(this,&FormPreferences::show));
41 }
42
43
44 FormPreferences::~FormPreferences()
45 {
46         free();
47 }
48
49
50 void FormPreferences::build()
51 {
52         dialog_ = build_preferences();
53         bind_ = build_bind();
54         screen_fonts_ = build_screen_fonts();
55         interface_fonts_ = build_interface_fonts();
56         misc_ = build_misc();
57         printer_ = build_printer();
58         paths_ = build_paths();
59
60         fl_addto_tabfolder(dialog_->tabfolder_prefs,
61                            _("Bindings"),
62                            bind_->form_bind);
63         fl_addto_tabfolder(dialog_->tabfolder_prefs,
64                            _("Screen Fonts"),
65                            screen_fonts_->form_screen_fonts);
66         fl_addto_tabfolder(dialog_->tabfolder_prefs,
67                            _("Interface Fonts"),
68                            interface_fonts_->form_interface_fonts);
69         fl_addto_tabfolder(dialog_->tabfolder_prefs,
70                            _("Miscellaneous"),
71                            misc_->form_misc);
72         fl_addto_tabfolder(dialog_->tabfolder_prefs,
73                            _("Printer"),
74                            printer_->form_printer);
75         fl_addto_tabfolder(dialog_->tabfolder_prefs,
76                            _("Paths"),
77                            paths_->form_paths);
78
79         fl_set_form_atclose(dialog_->form_preferences,
80                             C_FormPreferencesWMHideCB, 0);
81 }
82
83
84 void FormPreferences::show()
85 {
86         if (!dialog_) {
87                 build();
88         }
89         update();  // make sure its up-to-date
90
91         if (dialog_->form_preferences->visible) {
92                 fl_raise_form(dialog_->form_preferences);
93         } else {
94                 fl_show_form(dialog_->form_preferences,
95                              FL_PLACE_MOUSE | FL_FREE_SIZE,
96                              FL_FULLBORDER,
97                              _("Preferences"));
98         }
99 }
100
101
102 void FormPreferences::hide()
103 {
104         if (dialog_
105             && dialog_->form_preferences
106             && dialog_->form_preferences->visible) {
107                 fl_hide_form(dialog_->form_preferences);
108         }
109 }
110
111
112 void FormPreferences::apply()
113 {
114         // set the new lyxrc entries
115         // many of these need to trigger other functions when the assignment
116         // is made.  For example, screen zoom and font types.  These could be
117         // handled either by signals/slots in lyxrc or just directly call the
118         // associated functions here.
119
120         // Bind tab
121         lyxrc.bind_file = fl_get_input(bind_->input_bind);
122         // Misc tab
123         lyxrc.show_banner = fl_get_button(misc_->check_banner);
124         lyxrc.auto_region_delete = fl_get_button(misc_->
125                                                  check_auto_region_delete);
126         lyxrc.exit_confirmation = fl_get_button(misc_->check_exit_confirm);
127         lyxrc.display_shortcuts = fl_get_button(misc_->check_display_shortcuts);
128         lyxrc.autosave = static_cast<unsigned int>
129                 (fl_get_counter_value(misc_->counter_autosave));
130         lyxrc.ascii_linelen = static_cast<unsigned int>
131                 (fl_get_counter_value(misc_->counter_line_len));
132         // Screen fonts
133         lyxrc.roman_font_name = fl_get_input(screen_fonts_->input_roman);
134         lyxrc.sans_font_name = fl_get_input(screen_fonts_->input_sans);
135         lyxrc.typewriter_font_name = fl_get_input(screen_fonts_->
136                                                   input_typewriter);
137         lyxrc.font_norm = fl_get_input(screen_fonts_->input_encoding);
138         lyxrc.use_scalable_fonts = fl_get_button(screen_fonts_->check_scalable);
139         lyxrc.zoom = static_cast<unsigned int>
140                 (fl_get_counter_value(screen_fonts_->counter_zoom));
141         lyxrc.font_sizes[LyXFont::SIZE_TINY] = 
142                 strToDbl(fl_get_input(screen_fonts_->input_tiny));
143         lyxrc.font_sizes[LyXFont::SIZE_SCRIPT] =
144                 strToDbl(fl_get_input(screen_fonts_->input_script));
145         lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE] =
146                 strToDbl(fl_get_input(screen_fonts_->input_footnote));
147         lyxrc.font_sizes[LyXFont::SIZE_SMALL] =
148                 strToDbl(fl_get_input(screen_fonts_->input_small));
149         lyxrc.font_sizes[LyXFont::SIZE_NORMAL] =
150                 strToDbl(fl_get_input(screen_fonts_->input_normal));
151         lyxrc.font_sizes[LyXFont::SIZE_LARGE] =
152                 strToDbl(fl_get_input(screen_fonts_->input_large));
153         lyxrc.font_sizes[LyXFont::SIZE_LARGER] =
154                 strToDbl(fl_get_input(screen_fonts_->input_larger));
155         lyxrc.font_sizes[LyXFont::SIZE_LARGEST] =
156                 strToDbl(fl_get_input(screen_fonts_->input_largest));
157         lyxrc.font_sizes[LyXFont::SIZE_HUGE] =
158                 strToDbl(fl_get_input(screen_fonts_->input_huge));
159         lyxrc.font_sizes[LyXFont::SIZE_HUGER] =
160                 strToDbl(fl_get_input(screen_fonts_->input_huger));
161         // interface fonts
162         lyxrc.popup_font_name =
163                 fl_get_input(interface_fonts_->input_popup_font);
164         lyxrc.menu_font_name = fl_get_input(interface_fonts_->input_menu_font);
165         lyxrc.font_norm_menu = fl_get_input(interface_fonts_->input_encoding);
166         // printer
167         lyxrc.print_adapt_output = fl_get_button(printer_->check_adapt_output);
168         lyxrc.print_command = fl_get_input(printer_->input_command);
169         lyxrc.print_pagerange_flag = fl_get_input(printer_->input_page_range);
170         lyxrc.print_copies_flag = fl_get_input(printer_->input_copies);
171         lyxrc.print_reverse_flag = fl_get_input(printer_->input_reverse);
172         lyxrc.print_to_printer = fl_get_input(printer_->input_to_printer);
173         lyxrc.print_file_extension =
174                 fl_get_input(printer_->input_file_extension);
175         lyxrc.print_spool_command =
176                 fl_get_input(printer_->input_spool_command);
177         lyxrc.print_paper_flag = fl_get_input(printer_->input_paper_type);
178         lyxrc.print_evenpage_flag = fl_get_input(printer_->input_even_pages);
179         lyxrc.print_oddpage_flag = fl_get_input(printer_->input_odd_pages);
180         lyxrc.print_collcopies_flag = fl_get_input(printer_->input_collated);
181         lyxrc.print_landscape_flag = fl_get_input(printer_->input_landscape);
182         lyxrc.print_to_file = fl_get_input(printer_->input_to_file);
183         lyxrc.print_extra_options =
184                 fl_get_input(printer_->input_extra_options);
185         lyxrc.print_spool_printerprefix =
186                 fl_get_input(printer_->input_spool_prefix);
187         lyxrc.print_paper_dimension_flag =
188                 fl_get_input(printer_->input_paper_size);
189         lyxrc.printer = fl_get_input(printer_->input_name);
190         // paths
191         lyxrc.document_path = fl_get_input(paths_->input_default_path);
192         lyxrc.template_path = fl_get_input(paths_->input_template_path);
193         lyxrc.tempdir_path = fl_get_input(paths_->input_temp_dir);
194         lyxrc.lastfiles = fl_get_input(paths_->input_lastfiles);
195         lyxrc.backupdir_path = fl_get_input(paths_->input_backup_path);
196         lyxrc.use_tempdir = fl_get_button(paths_->check_use_temp_dir);
197         lyxrc.check_lastfiles = fl_get_button(paths_->check_last_files);
198         lyxrc.make_backup = fl_get_button(paths_->check_make_backups);
199         lyxrc.num_lastfiles = static_cast<unsigned int>
200                 (fl_get_counter_value(paths_->counter_lastfiles));
201 }
202
203
204 void FormPreferences::update()
205 {
206         if (dialog_) {
207                 // read lyxrc entries
208                 // Bind tab
209                 fl_set_input(bind_->input_bind, lyxrc.bind_file.c_str());
210                 // Misc tab
211                 fl_set_button(misc_->check_banner,
212                               lyxrc.show_banner);
213                 fl_set_button(misc_->check_auto_region_delete,
214                               lyxrc.auto_region_delete);
215                 fl_set_button(misc_->check_exit_confirm,
216                               lyxrc.exit_confirmation);
217                 fl_set_button(misc_->check_display_shortcuts,
218                               lyxrc.display_shortcuts);
219                 fl_set_counter_value(misc_->counter_autosave,
220                                      lyxrc.autosave);
221                 fl_set_counter_value(misc_->counter_line_len,
222                                      lyxrc.ascii_linelen);
223                 // Screen fonts
224                 fl_set_input(screen_fonts_->input_roman,
225                              lyxrc.roman_font_name.c_str());
226                 fl_set_input(screen_fonts_->input_sans,
227                              lyxrc.sans_font_name.c_str());
228                 fl_set_input(screen_fonts_->input_typewriter,
229                              lyxrc.typewriter_font_name.c_str());
230                 fl_set_input(screen_fonts_->input_encoding,
231                              lyxrc.font_norm.c_str());
232                 fl_set_button(screen_fonts_->check_scalable,
233                              lyxrc.use_scalable_fonts);
234                 fl_set_counter_value(screen_fonts_->counter_zoom,
235                              lyxrc.zoom);
236                 fl_set_input(screen_fonts_->input_tiny,
237                              tostr(lyxrc.font_sizes[LyXFont::SIZE_TINY]).c_str());
238                 fl_set_input(screen_fonts_->input_script,
239                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
240                 fl_set_input(screen_fonts_->input_footnote,
241                              tostr(lyxrc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
242                 fl_set_input(screen_fonts_->input_small,
243                              tostr(lyxrc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
244                 fl_set_input(screen_fonts_->input_normal,
245                              tostr(lyxrc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
246                 fl_set_input(screen_fonts_->input_large,
247                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
248                 fl_set_input(screen_fonts_->input_larger,
249                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
250                 fl_set_input(screen_fonts_->input_largest,
251                              tostr(lyxrc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
252                 fl_set_input(screen_fonts_->input_huge,
253                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
254                 fl_set_input(screen_fonts_->input_huger,
255                              tostr(lyxrc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
256                 // interface fonts
257                 fl_set_input(interface_fonts_->input_popup_font,
258                              lyxrc.popup_font_name.c_str());
259                 fl_set_input(interface_fonts_->input_menu_font,
260                              lyxrc.menu_font_name.c_str());
261                 fl_set_input(interface_fonts_->input_encoding,
262                              lyxrc.font_norm_menu.c_str());
263                 // printer
264                 fl_set_button(printer_->check_adapt_output,
265                               lyxrc.print_adapt_output);
266                 fl_set_input(printer_->input_command,
267                              lyxrc.print_command.c_str());
268                 fl_set_input(printer_->input_page_range,
269                              lyxrc.print_pagerange_flag.c_str());
270                 fl_set_input(printer_->input_copies,
271                              lyxrc.print_copies_flag.c_str());
272                 fl_set_input(printer_->input_reverse,
273                               lyxrc.print_reverse_flag.c_str());
274                 fl_set_input(printer_->input_to_printer,
275                              lyxrc.print_to_printer.c_str());
276                 fl_set_input(printer_->input_file_extension,
277                              lyxrc.print_file_extension.c_str());
278                 fl_set_input(printer_->input_spool_command,
279                              lyxrc.print_spool_command.c_str());
280                 fl_set_input(printer_->input_paper_type,
281                              lyxrc.print_paper_flag.c_str());
282                 fl_set_input(printer_->input_even_pages,
283                              lyxrc.print_evenpage_flag.c_str());
284                 fl_set_input(printer_->input_odd_pages,
285                              lyxrc.print_oddpage_flag.c_str());
286                 fl_set_input(printer_->input_collated,
287                              lyxrc.print_collcopies_flag.c_str());
288                 fl_set_input(printer_->input_landscape,
289                              lyxrc.print_landscape_flag.c_str());
290                 fl_set_input(printer_->input_to_file,
291                              lyxrc.print_to_file.c_str());
292                 fl_set_input(printer_->input_extra_options,
293                              lyxrc.print_extra_options.c_str());
294                 fl_set_input(printer_->input_spool_prefix,
295                              lyxrc.print_spool_printerprefix.c_str());
296                 fl_set_input(printer_->input_paper_size,
297                              lyxrc.print_paper_dimension_flag.c_str());
298                 fl_set_input(printer_->input_name,
299                              lyxrc.printer.c_str());
300                 // paths
301                 fl_set_input(paths_->input_default_path,
302                              lyxrc.document_path.c_str());
303                 fl_set_input(paths_->input_template_path,
304                              lyxrc.template_path.c_str());
305                 fl_set_input(paths_->input_temp_dir,
306                              lyxrc.tempdir_path.c_str());
307                 fl_set_input(paths_->input_lastfiles,
308                              lyxrc.lastfiles.c_str());
309                 fl_set_input(paths_->input_backup_path,
310                              lyxrc.backupdir_path.c_str());
311                 fl_set_button(paths_->check_use_temp_dir,
312                               lyxrc.use_tempdir);
313                 fl_set_button(paths_->check_last_files,
314                               lyxrc.check_lastfiles);           
315                 fl_set_button(paths_->check_make_backups,
316                               lyxrc.make_backup);
317                 fl_set_counter_value(paths_->counter_lastfiles,
318                                      lyxrc.num_lastfiles);
319         }
320 }
321
322
323 void FormPreferences::input()
324 {
325         bool activate = true;
326         //
327         // whatever checks you need
328         //
329         if (activate) {
330                 fl_activate_object(dialog_->button_ok);
331                 fl_activate_object(dialog_->button_apply);
332                 fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
333                 fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
334         } else {
335                 fl_deactivate_object(dialog_->button_ok);
336                 fl_deactivate_object(dialog_->button_apply);
337                 fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
338                 fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
339         }
340 }
341
342
343 void FormPreferences::free()
344 {
345         // we don't need to delete u and h here because
346         // hide() does that after disconnecting.
347         if (dialog_) {
348                 if (dialog_->form_preferences
349                     && dialog_->form_preferences->visible) {
350                         hide();
351                 }
352                 fl_free_form(dialog_->form_preferences);
353                 delete dialog_;
354                 dialog_ = 0;
355         }
356 }
357
358
359 int FormPreferences::WMHideCB(FL_FORM * form, void *)
360 {
361         // Ensure that the signals (u and h) are disconnected even if the
362         // window manager is used to close the dialog.
363         FormPreferences * pre = static_cast<FormPreferences*>(form->u_vdata);
364         pre->hide();
365         return FL_CANCEL;
366 }
367
368
369 void FormPreferences::OKCB(FL_OBJECT * ob, long)
370 {
371         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
372         pre->apply();
373         pre->hide();
374
375         pre->lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES);
376 }
377
378
379 void FormPreferences::ApplyCB(FL_OBJECT * ob, long)
380 {
381         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
382         pre->apply();
383 }
384
385
386 void FormPreferences::CancelCB(FL_OBJECT * ob, long)
387 {
388         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
389         pre->hide();
390 }
391
392
393 void FormPreferences::InputCB(FL_OBJECT * ob, long)
394 {
395         FormPreferences * pre = static_cast<FormPreferences*>(ob->form->u_vdata);
396         pre->input();
397 }
398
399
400