]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
Further improvements to the paper tab of the document dialog.
[lyx.git] / src / frontends / xforms / FormDocument.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000-2001 The LyX Team.
7  *
8  *           @author Jürgen Vigna
9  *
10  *======================================================*/
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
16
17 #ifdef __GNUG_
18 #pragma implementation
19 #endif
20
21 #include "lyx_gui_misc.h"
22
23 #include "FormDocument.h"
24 #include "form_document.h"
25 #include "Dialogs.h"
26 #include "layout.h"
27 #include "combox.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
31 #include "vspace.h"
32 #include "bmtable.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
35 #include "language.h"
36 #include "LyXView.h"
37 #include "lyxfunc.h"
38 #include "lyxrc.h"
39 #include "BufferView.h"
40 #include "buffer.h"
41 #include "Liason.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "xforms_helpers.h" 
45 #include "debug.h"
46 #include "input_validators.h" // fl_unsigned_float_filter
47
48 using Liason::setMinibuffer;
49 using SigC::slot;
50
51 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
52         : FormBaseBD(lv, d, _("Document Layout")),
53           ActCell(0), Confirmed(0),
54           current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
55 {
56         // let the dialog be shown
57         // This is a permanent connection so we won't bother
58         // storing a copy because we won't be disconnecting.
59         d->showDocument.connect(slot(this, &FormDocument::show));
60 }
61
62
63 void FormDocument::redraw()
64 {
65         if( form() && form()->visible )
66                 fl_redraw_form( form() );
67         else
68                 return;
69
70         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
71         if (outer_form && outer_form->visible)
72                 fl_redraw_form( outer_form );
73 }
74
75
76 FL_FORM * FormDocument::form() const
77 {
78         if (dialog_.get()) return dialog_->form;
79         return 0;
80 }
81
82
83 void FormDocument::build()
84 {
85         int n;
86
87         // the tabbed folder
88         dialog_.reset(build_tabbed_document());
89
90         // Manage the restore, ok, apply, restore and cancel/close buttons
91         bc().setOK(dialog_->button_ok);
92         bc().setApply(dialog_->button_apply);
93         bc().setCancel(dialog_->button_cancel);
94         bc().setRestore(dialog_->button_restore);
95         bc().addReadOnly (dialog_->button_save_defaults);
96         bc().addReadOnly (dialog_->button_reset_defaults);
97
98         // the document paper form
99         paper_.reset(build_doc_paper());
100         fl_addto_choice(paper_->choice_papersize,
101                         _(" Default | Custom | USletter | USlegal "
102                           "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
103         fl_addto_choice(paper_->choice_paperpackage,
104                         _(" None "
105                           "| Small Margins "
106                           "| Very small Margins "
107                           "| Very wide Margins "));
108
109         fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
110         fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
111         fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
112         fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
113         fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
114         fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
115         fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
116         fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
117         fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
118
119         // Set input filters on width and height to make them accept only
120         // unsigned numbers.
121         fl_set_input_filter(paper_->input_custom_width,
122                             fl_unsigned_float_filter);
123         fl_set_input_filter(paper_->input_custom_height,
124                             fl_unsigned_float_filter);
125         fl_set_input_filter(paper_->input_top_margin,
126                             fl_unsigned_float_filter);
127         fl_set_input_filter(paper_->input_bottom_margin,
128                             fl_unsigned_float_filter);
129         fl_set_input_filter(paper_->input_left_margin,
130                             fl_unsigned_float_filter);
131         fl_set_input_filter(paper_->input_right_margin,
132                             fl_unsigned_float_filter);
133         fl_set_input_filter(paper_->input_head_height,
134                             fl_unsigned_float_filter);
135         fl_set_input_filter(paper_->input_head_sep,
136                             fl_unsigned_float_filter);
137         fl_set_input_filter(paper_->input_foot_skip,
138                             fl_unsigned_float_filter);
139
140         // Create the contents of the unit choices
141         string const units = " cm | inch ";
142
143         fl_addto_choice(paper_->choice_custom_width_units,  units.c_str());
144         fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
145         fl_addto_choice(paper_->choice_top_margin_units,    units.c_str());
146         fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
147         fl_addto_choice(paper_->choice_left_margin_units,   units.c_str());
148         fl_addto_choice(paper_->choice_right_margin_units,  units.c_str());
149         fl_addto_choice(paper_->choice_head_height_units,   units.c_str());
150         fl_addto_choice(paper_->choice_head_sep_units,      units.c_str());
151         fl_addto_choice(paper_->choice_foot_skip_units,     units.c_str());
152
153         bc().addReadOnly (paper_->choice_paperpackage);
154         bc().addReadOnly (paper_->group_radio_orientation);
155         bc().addReadOnly (paper_->radio_portrait);
156         bc().addReadOnly (paper_->radio_landscape);
157         bc().addReadOnly (paper_->choice_papersize);
158         bc().addReadOnly (paper_->check_use_geometry);
159         bc().addReadOnly (paper_->input_custom_width);
160         bc().addReadOnly (paper_->input_custom_height);
161         bc().addReadOnly (paper_->input_top_margin);
162         bc().addReadOnly (paper_->input_bottom_margin);
163         bc().addReadOnly (paper_->input_left_margin);
164         bc().addReadOnly (paper_->input_right_margin);
165         bc().addReadOnly (paper_->input_head_height);
166         bc().addReadOnly (paper_->input_head_sep);
167         bc().addReadOnly (paper_->input_foot_skip);
168
169         // the document class form
170         class_.reset(build_doc_class());
171
172         FL_OBJECT * obj;
173         // The language is a combo-box and has to be inserted manually
174         obj = class_->choice_doc_class;
175         fl_deactivate_object(obj);
176         fl_addto_form(class_->form);
177         combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
178         combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
179                              dialog_->tabbed_folder);
180         combo_doc_class->shortcut("#C",1);
181         combo_doc_class->setcallback(ComboInputCB, this);
182         fl_end_form();
183         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
184              cit != textclasslist.end(); ++cit) {
185                 combo_doc_class->addto(cit->description());
186         }
187
188         fl_addto_choice(class_->choice_doc_spacing,
189                         _(" Single | OneHalf | Double | Other "));
190         fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
191         for (n=0; tex_fonts[n][0]; ++n) {
192                 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
193         }
194         fl_addto_choice(class_->choice_doc_pagestyle,
195                         "default|empty|plain|headings|fancy");
196         fl_addto_choice(class_->choice_doc_skip,
197                         _(" Smallskip | Medskip | Bigskip | Length "));
198         fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
199         fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
200         fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
201
202         bc().addReadOnly (class_->radio_doc_indent);
203         bc().addReadOnly (class_->radio_doc_skip);
204
205         bc().addReadOnly (class_->choice_doc_pagestyle);
206         bc().addReadOnly (class_->choice_doc_fonts);
207         bc().addReadOnly (class_->choice_doc_fontsize);
208         bc().addReadOnly (class_->radio_doc_sides_one);
209         bc().addReadOnly (class_->radio_doc_sides_two);
210         bc().addReadOnly (class_->radio_doc_columns_one);
211         bc().addReadOnly (class_->radio_doc_columns_two);
212         bc().addReadOnly (class_->input_doc_extra);
213         bc().addReadOnly (class_->input_doc_skip);
214         bc().addReadOnly (class_->choice_doc_skip);
215         bc().addReadOnly (class_->choice_doc_spacing);
216         bc().addReadOnly (class_->input_doc_spacing);
217
218         // the document language form
219         language_.reset(build_doc_language());
220         fl_addto_choice(language_->choice_inputenc,
221                         "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
222                         "|koi8-r|koi8-u|cp866|cp1251|iso88595");
223
224         // The language is a combo-box and has to be inserted manually
225         obj = language_->choice_language;
226         fl_deactivate_object(obj);
227         fl_addto_form(language_->form);
228         combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
229         combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
230                             dialog_->tabbed_folder);
231         combo_language->shortcut("#L",1);
232         combo_language->setcallback(ComboInputCB, this);
233         fl_end_form();
234
235         for (Languages::const_iterator cit = languages.begin();
236              cit != languages.end(); ++cit) {
237                 combo_language->addto(cit->second.lang());
238         }
239
240         fl_addto_choice(language_->choice_quotes_language,
241                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
242                           " «text» | »text« "));
243
244         bc().addReadOnly (language_->choice_inputenc);
245         bc().addReadOnly (language_->choice_quotes_language);
246         bc().addReadOnly (language_->radio_single);
247         bc().addReadOnly (language_->radio_double);
248
249         // the document options form
250         options_.reset(build_doc_options());
251         fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
252         fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
253         fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
254         fl_set_counter_step(options_->slider_secnumdepth,1,1);
255         fl_set_counter_step(options_->slider_tocdepth,1,1);
256         fl_set_counter_precision(options_->slider_secnumdepth, 0);
257         fl_set_counter_precision(options_->slider_tocdepth, 0);
258         for (n=0; tex_graphics[n][0]; ++n) {
259                 fl_addto_choice(options_->choice_postscript_driver,
260                                 tex_graphics[n]);
261         }
262         fl_addto_choice(options_->choice_citation_format,
263                         _(" Author-year | Numerical "));
264
265         bc_.addReadOnly (options_->slider_secnumdepth);
266         bc_.addReadOnly (options_->slider_tocdepth);
267         bc_.addReadOnly (options_->check_use_amsmath);
268         bc_.addReadOnly (options_->check_use_natbib);
269         bc_.addReadOnly (options_->choice_citation_format);
270         bc_.addReadOnly (options_->input_float_placement);
271         bc_.addReadOnly (options_->choice_postscript_driver);
272
273         // the document bullets form
274         bullets_.reset(build_doc_bullet());
275         fl_addto_choice(bullets_->choice_bullet_size,
276                         _(" default | tiny | script | footnote | small |"
277                           " normal | large | Large | LARGE | huge | Huge"));
278         fl_set_choice(bullets_->choice_bullet_size, 1);
279         fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
280         fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
281
282         bc().addReadOnly (bullets_->bmtable_bullet_panel);
283         bc().addReadOnly (bullets_->choice_bullet_size);
284         bc().addReadOnly (bullets_->input_bullet_latex);
285         bc().addReadOnly (bullets_->radio_bullet_depth);
286         bc().addReadOnly (bullets_->radio_bullet_panel);
287
288         fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
289                            class_->form);
290         fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
291                            paper_->form);
292         fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
293                            language_->form);
294         fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
295                            options_->form);
296         fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
297                                      bullets_->form);
298         if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
299                 lyxerr << _("Your version of libXpm is older than 4.7.\n"
300                             "The `bullet' tab of the document dialog "
301                             "has been disabled") << '\n';
302                 fl_deactivate_object(fbullet);
303                 fl_set_object_lcol(fbullet, FL_INACTIVE);
304         }
305 }
306
307
308 void FormDocument::apply()
309 {
310         if (!lv_->view()->available() || !dialog_.get())
311                 return;
312
313         bool redo = class_apply();
314         paper_apply();
315         redo = language_apply() || redo;
316         redo = options_apply() || redo;
317         bullets_apply();
318
319         if (redo) {
320                 lv_->view()->redoCurrentBuffer();
321         }
322         lv_->buffer()->markDirty();
323         setMinibuffer(lv_, _("Document layout set"));
324 }
325
326
327 void FormDocument::cancel()
328 {
329         // this avoids confusion when reopening
330         BufferParams & param = lv_->buffer()->params;
331         param.temp_bullets[0] = param.user_defined_bullets[0];
332         param.temp_bullets[1] = param.user_defined_bullets[1];
333         param.temp_bullets[2] = param.user_defined_bullets[2];
334         param.temp_bullets[3] = param.user_defined_bullets[3];
335         hide();
336 }
337
338
339 void FormDocument::update()
340 {
341         if (!dialog_.get())
342                 return;
343
344         checkReadOnly();
345
346         BufferParams const & params = lv_->buffer()->params;
347
348 //      fl_set_object_label(dialog_->button_save_defaults,
349 //                          _("Save as Defaults"));
350 //      fl_set_object_label(dialog_->button_reset_defaults,
351 //                          _("Use Class Defaults"));
352         setEnabled(dialog_->button_reset_defaults,
353                    !params.hasClassDefaults());
354
355         class_update(params);
356         paper_update(params);
357         language_update(params);
358         options_update(params);
359         bullets_update(params);
360 }
361
362
363 bool FormDocument::input( FL_OBJECT * ob, long data )
364 {
365         State cb = static_cast<State>( data );
366
367         switch (cb) {
368         case CHECKCHOICECLASS:
369                 CheckChoiceClass(ob, 0);
370                 break;
371         case CHOICEBULLETSIZE:
372                 ChoiceBulletSize(ob, 0);
373                 break;
374         case INPUTBULLETLATEX:
375                 InputBulletLaTeX(ob, 0);
376                 break;
377         case BULLETDEPTH1:
378         case BULLETDEPTH2:
379         case BULLETDEPTH3:
380         case BULLETDEPTH4:
381                 BulletDepth(ob, cb);
382                 break;
383         case BULLETPANEL1:
384         case BULLETPANEL2:
385         case BULLETPANEL3:
386         case BULLETPANEL4:
387         case BULLETPANEL5:
388         case BULLETPANEL6:
389                 BulletPanel(ob, cb);
390                 break;
391         case BULLETBMTABLE:
392                 BulletBMTable(ob, 0);
393                 break;
394         default:
395                 break;
396         }
397
398         if (ob == options_->check_use_natbib) {
399                 setEnabled(options_->choice_citation_format,
400                            fl_get_button(options_->check_use_natbib));
401         }
402
403         if (ob == dialog_->button_save_defaults) {
404                 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
405         }
406
407         if (ob == dialog_->button_reset_defaults) {
408                 BufferParams params = lv_->buffer()->params;
409                 params.textclass = combo_doc_class->get() - 1;
410                 params.useClassDefaults();
411                 UpdateLayoutDocument(params);
412         }
413
414         if (ob == paper_->radio_landscape)
415                 fl_set_choice(paper_->choice_paperpackage,
416                 BufferParams::PACKAGE_NONE + 1);
417
418         if (ob == paper_->choice_papersize) {
419                 if (fl_get_choice(paper_->choice_papersize) == 2)
420                         fl_set_button(paper_->radio_portrait, 1);
421                 bool const custom =
422                         fl_get_choice(paper_->choice_papersize) == 2;
423                 setEnabled(paper_->input_custom_width,  custom);
424                 setEnabled(paper_->input_custom_height, custom);
425                 setEnabled(paper_->choice_custom_width_units,  custom);
426                 setEnabled(paper_->choice_custom_height_units, custom);
427                 setEnabled(paper_->radio_portrait,  !custom);
428                 setEnabled(paper_->radio_landscape, !custom);
429         }
430
431         if (ob == paper_->choice_papersize
432             || paper_->radio_portrait
433             || paper_->radio_landscape) {
434
435                 setEnabled(paper_->choice_paperpackage,
436                            //either default papersize (preferences)
437                            //or document papersize has to be A4
438                            (fl_get_choice(paper_->choice_papersize) == 7
439                             || fl_get_choice(paper_->choice_papersize) == 1
440                             && lyxrc.default_papersize == 5)
441                            && fl_get_button(paper_->radio_portrait));
442         }
443
444         if (ob == paper_->choice_paperpackage) {
445                 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
446                         fl_set_button(paper_->check_use_geometry, 0);
447
448                         setEnabled(paper_->input_top_margin,    false);
449                         setEnabled(paper_->input_bottom_margin, false);
450                         setEnabled(paper_->input_left_margin,   false);
451                         setEnabled(paper_->input_right_margin,  false);
452                         setEnabled(paper_->input_head_height,   false);
453                         setEnabled(paper_->input_head_sep,      false);
454                         setEnabled(paper_->input_foot_skip,     false);
455                         setEnabled(paper_->choice_top_margin_units,    false);
456                         setEnabled(paper_->choice_bottom_margin_units, false);
457                         setEnabled(paper_->choice_left_margin_units,   false);
458                         setEnabled(paper_->choice_right_margin_units,  false);
459                         setEnabled(paper_->choice_head_height_units,   false);
460                         setEnabled(paper_->choice_head_sep_units,      false);
461                         setEnabled(paper_->choice_foot_skip_units,     false);
462                 }
463         }
464
465         if (ob == paper_->check_use_geometry) {
466                 //don't allow switching geometry off in custom papersize mode
467                 if (fl_get_choice(paper_->choice_papersize) == 2)
468                         fl_set_button(paper_->check_use_geometry, 1);
469                 fl_set_choice(paper_->choice_paperpackage,
470                               BufferParams::PACKAGE_NONE + 1);
471
472                 bool const use_geom = fl_get_button(paper_->check_use_geometry);
473                 setEnabled(paper_->input_top_margin,    use_geom);
474                 setEnabled(paper_->input_bottom_margin, use_geom);
475                 setEnabled(paper_->input_left_margin,   use_geom);
476                 setEnabled(paper_->input_right_margin,  use_geom);
477                 setEnabled(paper_->input_head_height,   use_geom);
478                 setEnabled(paper_->input_head_sep,      use_geom);
479                 setEnabled(paper_->input_foot_skip,     use_geom);
480                 setEnabled(paper_->choice_top_margin_units,    use_geom);
481                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
482                 setEnabled(paper_->choice_left_margin_units,   use_geom);
483                 setEnabled(paper_->choice_right_margin_units,  use_geom);
484                 setEnabled(paper_->choice_head_height_units,   use_geom);
485                 setEnabled(paper_->choice_head_sep_units,      use_geom);
486                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
487         }
488
489         setEnabled(dialog_->button_reset_defaults,
490                    lv_->buffer()->params.hasClassDefaults());
491
492         switch (data) {
493         case INPUT:
494         case CHECKCHOICECLASS:
495         case CHOICEBULLETSIZE:
496         case INPUTBULLETLATEX:
497         case BULLETBMTABLE:
498                 return CheckDocumentInput(ob, 0);
499         default:
500                 break;
501         }
502
503         return true;
504 }
505
506
507 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
508 {
509         FormDocument * pre = static_cast<FormDocument*>(v);
510         if (combox == pre->combo_doc_class.get())
511                 pre->CheckChoiceClass(0, 0);
512         pre->bc().valid(pre->CheckDocumentInput(0,0));
513 }
514
515
516 bool FormDocument::class_apply()
517 {
518         bool redo = false;
519         BufferParams &params = lv_->buffer()->params;
520
521         // If default skip is a "Length" but there's no text in the
522         // input field, reset the kind to "Medskip", which is the default.
523         if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
524             !*(fl_get_input (class_->input_doc_skip))) {
525                 fl_set_choice (class_->choice_doc_skip, 2);
526         }
527         params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
528         params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
529         params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
530
531         unsigned int const new_class = combo_doc_class->get() - 1;
532         
533         if (params.textclass != new_class) {
534                 // try to load new_class
535                 if (textclasslist.Load(new_class)) {
536                         // successfully loaded
537                         redo = true;
538                         setMinibuffer(lv_, _("Converting document to new document class..."));
539                         int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
540                                 params.textclass, new_class,
541                                 lv_->buffer()->paragraph);
542                         if (ret) {
543                                 string s;
544                                 if (ret==1) {
545                                         s = _("One paragraph couldn't be converted");
546                                 } else {
547                                         s += tostr(ret);
548                                         s += _(" paragraphs couldn't be converted");
549                                 }
550                                 WriteAlert(_("Conversion Errors!"),s,
551                                            _("into chosen document class"));
552                         }
553                         
554                         params.textclass = new_class;
555                 } else {
556                         // problem changing class -- warn user and retain old style
557                         WriteAlert(_("Conversion Errors!"),
558                                    _("Errors loading new document class."),
559                                    _("Reverting to original document class."));
560                         combo_doc_class->select(int(params.textclass) + 1);
561                 }
562         }
563         BufferParams::PARSEP tmpsep = params.paragraph_separation;
564         if (fl_get_button(class_->radio_doc_indent))
565                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
566         else
567                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
568         if (tmpsep != params.paragraph_separation)
569                 redo = true;
570         
571         VSpace tmpdefskip = params.getDefSkip();
572         switch (fl_get_choice (class_->choice_doc_skip)) {
573         case 1:
574                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
575                 break;
576         case 2:
577                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
578                 break;
579         case 3:
580             params.setDefSkip(VSpace(VSpace::BIGSKIP));
581             break;
582         case 4:
583                 params.setDefSkip
584                         (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
585                 break;
586                 // DocumentDefskipCB assures that this never happens
587         default:
588                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
589                 break;
590         }
591         if (!(tmpdefskip == params.getDefSkip()))
592                 redo = true;
593         
594         if (fl_get_button(class_->radio_doc_columns_two))
595                 params.columns = 2;
596         else
597                 params.columns = 1;
598         if (fl_get_button(class_->radio_doc_sides_two))
599                 params.sides = LyXTextClass::TwoSides;
600         else
601                 params.sides = LyXTextClass::OneSide;
602         
603         Spacing tmpSpacing = params.spacing;
604         switch (fl_get_choice(class_->choice_doc_spacing)) {
605         case 1:
606                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
607                 params.spacing.set(Spacing::Single);
608                 break;
609         case 2:
610                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
611                 params.spacing.set(Spacing::Onehalf);
612                 break;
613         case 3:
614                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
615                 params.spacing.set(Spacing::Double);
616                 break;
617         case 4:
618                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
619                 params.spacing.set(Spacing::Other, 
620                                    fl_get_input(class_->input_doc_spacing));
621                 break;
622         }
623         if (tmpSpacing != params.spacing)
624                 redo = true;
625         
626         params.options = fl_get_input(class_->input_doc_extra);
627         
628         return redo;
629 }
630
631
632 void FormDocument::paper_apply()
633 {
634         BufferParams & params = lv_->buffer()->params;
635
636         params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
637
638         params.paperpackage =
639                 char(fl_get_choice(paper_->choice_paperpackage)-1);
640
641         // set params.papersize from params.papersize2 and params.paperpackage
642         lv_->buffer()->setPaperStuff();
643
644         params.use_geometry = fl_get_button(paper_->check_use_geometry);
645
646         if (fl_get_button(paper_->radio_landscape))
647                 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
648         else
649                 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
650
651         params.paperwidth =
652                 getLengthFromWidgets(paper_->input_custom_width,
653                                      paper_->choice_custom_width_units);
654
655         params.paperheight =
656                 getLengthFromWidgets(paper_->input_custom_height,
657                                      paper_->choice_custom_height_units);
658
659         params.leftmargin =
660                 getLengthFromWidgets(paper_->input_left_margin,
661                                      paper_->choice_left_margin_units);
662
663         params.topmargin =
664                 getLengthFromWidgets(paper_->input_top_margin,
665                                      paper_->choice_top_margin_units);
666
667         params.rightmargin =
668                 getLengthFromWidgets(paper_->input_right_margin,
669                                      paper_->choice_right_margin_units);
670
671         params.bottommargin =
672                 getLengthFromWidgets(paper_->input_bottom_margin,
673                                      paper_->choice_bottom_margin_units);
674
675         params.headheight =
676                 getLengthFromWidgets(paper_->input_head_height,
677                                      paper_->choice_head_height_units);
678
679         params.headsep =
680                 getLengthFromWidgets(paper_->input_head_sep,
681                                      paper_->choice_head_sep_units);
682
683         params.footskip =
684                 getLengthFromWidgets(paper_->input_foot_skip,
685                                      paper_->choice_foot_skip_units);
686 }
687
688
689 bool FormDocument::language_apply()
690 {
691         BufferParams & params = lv_->buffer()->params;
692         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
693         bool redo = false;
694
695         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
696         case 0:
697                 lga = InsetQuotes::EnglishQ;
698                 break;
699         case 1:
700                 lga = InsetQuotes::SwedishQ;
701                 break;
702         case 2:
703                 lga = InsetQuotes::GermanQ;
704                 break;
705         case 3:
706                 lga = InsetQuotes::PolishQ;
707                 break;
708         case 4:
709                 lga = InsetQuotes::FrenchQ;
710                 break;
711         case 5:
712                 lga = InsetQuotes::DanishQ;
713                 break;
714         }
715         params.quotes_language = lga;
716         if (fl_get_button(language_->radio_single))   
717                 params.quotes_times = InsetQuotes::SingleQ;
718         else
719                 params.quotes_times = InsetQuotes::DoubleQ;
720
721         Language const * old_language = params.language;
722         Language const * new_language = 
723                 languages.getLanguage(combo_language->getline());
724         if (!new_language)
725                 new_language = default_language;
726
727         if (old_language != new_language
728             && old_language->RightToLeft() == new_language->RightToLeft()
729             && !lv_->buffer()->isMultiLingual())
730                 lv_->buffer()->changeLanguage(old_language, new_language);
731         if (old_language != new_language) {
732                 redo = true;
733         }
734         params.language = new_language;
735         params.inputenc = fl_get_choice_text(language_->choice_inputenc);
736
737         return redo;
738 }
739
740
741 bool FormDocument::options_apply()
742 {
743         BufferParams & params = lv_->buffer()->params;
744         bool redo = false;
745
746         params.graphicsDriver =
747                 fl_get_choice_text(options_->choice_postscript_driver);
748         params.use_amsmath = fl_get_button(options_->check_use_amsmath);
749         params.use_natbib  = fl_get_button(options_->check_use_natbib);
750         params.use_numerical_citations  =
751                 fl_get_choice(options_->choice_citation_format)-1;
752
753         int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
754         if (params.secnumdepth != tmpchar)
755                 redo = true;
756         params.secnumdepth = tmpchar;
757    
758         params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
759
760         params.float_placement =
761                 fl_get_input(options_->input_float_placement);
762
763         return redo;
764 }
765
766
767 void FormDocument::bullets_apply()
768 {
769         /* update the bullet settings */
770         BufferParams & param = lv_->buffer()->params;
771
772         // a little bit of loop unrolling
773         param.user_defined_bullets[0] = param.temp_bullets[0];
774         param.user_defined_bullets[1] = param.temp_bullets[1];
775         param.user_defined_bullets[2] = param.temp_bullets[2];
776         param.user_defined_bullets[3] = param.temp_bullets[3];
777 }
778
779
780 void FormDocument::class_update(BufferParams const & params)
781 {
782         if (!class_.get())
783                 return;
784
785         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
786
787         combo_doc_class->select(
788                 textclasslist.DescOfClass(params.textclass));
789         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
790         fl_clear_choice(class_->choice_doc_fontsize);
791         fl_addto_choice(class_->choice_doc_fontsize, "default");
792         fl_addto_choice(class_->choice_doc_fontsize,
793                         tclass.opt_fontsize().c_str());
794         fl_set_choice(class_->choice_doc_fontsize,
795                       tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
796         fl_clear_choice(class_->choice_doc_pagestyle);
797         fl_addto_choice(class_->choice_doc_pagestyle, "default");
798         fl_addto_choice(class_->choice_doc_pagestyle,
799                         tclass.opt_pagestyle().c_str());
800         fl_set_choice(class_->choice_doc_pagestyle,
801                       tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
802         fl_set_button(class_->radio_doc_indent, 0);
803         fl_set_button(class_->radio_doc_skip, 0);
804         if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
805                 fl_set_button(class_->radio_doc_indent, 1);
806         else
807                 fl_set_button(class_->radio_doc_skip, 1);
808         switch (params.getDefSkip().kind()) {
809         case VSpace::SMALLSKIP: 
810                 fl_set_choice (class_->choice_doc_skip, 1);
811                 break;
812         case VSpace::MEDSKIP: 
813                 fl_set_choice (class_->choice_doc_skip, 2);
814                 break;
815         case VSpace::BIGSKIP: 
816                 fl_set_choice (class_->choice_doc_skip, 3);
817                 break;
818         case VSpace::LENGTH: 
819                 fl_set_choice (class_->choice_doc_skip, 4);
820                 fl_set_input (class_->input_doc_skip,
821                               params.getDefSkip().asLyXCommand().c_str());
822                 break;
823         default:
824                 fl_set_choice (class_->choice_doc_skip, 2);
825                 break;
826         }
827         fl_set_button(class_->radio_doc_sides_one, 0);
828         fl_set_button(class_->radio_doc_sides_two, 0);
829         if (params.sides == LyXTextClass::TwoSides)
830                 fl_set_button(class_->radio_doc_sides_two, 1);
831         else
832                 fl_set_button(class_->radio_doc_sides_one, 1);
833         fl_set_button(class_->radio_doc_columns_one, 0);
834         fl_set_button(class_->radio_doc_columns_two, 0);
835         if (params.columns == 2)
836                 fl_set_button(class_->radio_doc_columns_two, 1);
837         else
838                 fl_set_button(class_->radio_doc_columns_one, 1);
839         fl_set_input(class_->input_doc_spacing, "");
840         switch (params.spacing.getSpace()) {
841         case Spacing::Default: // nothing bad should happen with this
842         case Spacing::Single:
843                 // \singlespacing
844                 fl_set_choice(class_->choice_doc_spacing, 1);
845                 break;
846         case Spacing::Onehalf:
847                 // \onehalfspacing
848                 fl_set_choice(class_->choice_doc_spacing, 2);
849                 break;
850         case Spacing::Double:
851                 // \doublespacing
852                 fl_set_choice(class_->choice_doc_spacing, 3);
853                 break;
854         case Spacing::Other:
855         {
856                 fl_set_choice(class_->choice_doc_spacing, 4);
857                 char sval[20];
858                 sprintf(sval,"%g",params.spacing.getValue()); 
859                 fl_set_input(class_->input_doc_spacing, sval);
860                 break;
861         }
862         }
863         if (!params.options.empty())
864                 fl_set_input(class_->input_doc_extra, params.options.c_str());
865         else
866                 fl_set_input(class_->input_doc_extra, "");
867 }
868
869
870 void FormDocument::language_update(BufferParams const & params)
871 {
872         if (!language_.get())
873                 return;
874
875         combo_language->select(params.language->lang());
876         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
877         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
878         fl_set_button(language_->radio_single, 0);
879         fl_set_button(language_->radio_double, 0);
880         if (params.quotes_times == InsetQuotes::SingleQ)
881                 fl_set_button(language_->radio_single, 1);
882         else
883                 fl_set_button(language_->radio_double, 1);
884 }
885
886
887 void FormDocument::options_update(BufferParams const & params)
888 {
889         if (!options_.get())
890                 return;
891
892         fl_set_choice_text(options_->choice_postscript_driver,
893                            params.graphicsDriver.c_str());
894         fl_set_button(options_->check_use_amsmath, params.use_amsmath);
895         fl_set_button(options_->check_use_natbib,  params.use_natbib);
896         fl_set_choice(options_->choice_citation_format,
897                       int(params.use_numerical_citations)+1);
898         setEnabled(options_->choice_citation_format, params.use_natbib);
899         fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
900         fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
901         if (!params.float_placement.empty())
902                 fl_set_input(options_->input_float_placement,
903                              params.float_placement.c_str());
904         else
905                 fl_set_input(options_->input_float_placement, "");
906 }
907
908
909 void FormDocument::paper_update(BufferParams const & params)
910 {
911         if (!paper_.get())
912                 return;
913
914         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
915         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
916         fl_set_button(paper_->check_use_geometry, params.use_geometry);
917
918         bool const useCustom = fl_get_choice(paper_->choice_papersize) == 2;
919         bool const useGeom = fl_get_button(paper_->check_use_geometry);
920
921         fl_set_button(paper_->radio_portrait, 0);
922         setEnabled(paper_->radio_portrait, !useCustom);
923         fl_set_button(paper_->radio_landscape, 0);
924         setEnabled(paper_->radio_landscape, !useCustom);
925
926         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
927                 fl_set_button(paper_->radio_landscape, 1);
928         else
929                 fl_set_button(paper_->radio_portrait, 1);
930         setEnabled(paper_->choice_paperpackage,
931                    //either default papersize (preferences)
932                    //or document papersize has to be A4
933                    (fl_get_choice(paper_->choice_papersize) == 7
934                     || fl_get_choice(paper_->choice_papersize) == 1
935                     && lyxrc.default_papersize == 5)
936                    && fl_get_button(paper_->radio_portrait));
937
938         updateWidgetsFromLengthString(paper_->input_custom_width,
939                                       paper_->choice_custom_width_units,
940                                       params.paperwidth);
941         setEnabled(paper_->input_custom_width, useCustom);
942         setEnabled(paper_->choice_custom_width_units, useCustom);
943
944         updateWidgetsFromLengthString(paper_->input_custom_height,
945                                       paper_->choice_custom_height_units,
946                                       params.paperheight);
947         setEnabled(paper_->input_custom_height, useCustom);
948         setEnabled(paper_->choice_custom_height_units, useCustom);
949
950         updateWidgetsFromLengthString(paper_->input_left_margin,
951                                       paper_->choice_left_margin_units,
952                                       params.leftmargin);
953         setEnabled(paper_->input_left_margin, useGeom);
954         setEnabled(paper_->choice_left_margin_units, useGeom);
955
956         updateWidgetsFromLengthString(paper_->input_top_margin,
957                                       paper_->choice_top_margin_units,
958                                       params.topmargin);
959         setEnabled(paper_->input_top_margin, useGeom);
960         setEnabled(paper_->choice_top_margin_units, useGeom);
961
962         updateWidgetsFromLengthString(paper_->input_right_margin,
963                                       paper_->choice_right_margin_units,
964                                       params.rightmargin);
965         setEnabled(paper_->input_right_margin, useGeom);
966         setEnabled(paper_->choice_right_margin_units, useGeom);
967
968         updateWidgetsFromLengthString(paper_->input_bottom_margin,
969                                       paper_->choice_bottom_margin_units,
970                                       params.bottommargin);
971         setEnabled(paper_->input_bottom_margin, useGeom);
972         setEnabled(paper_->choice_bottom_margin_units, useGeom);
973
974         updateWidgetsFromLengthString(paper_->input_head_height,
975                                       paper_->choice_head_height_units,
976                                       params.headheight);
977         setEnabled(paper_->input_head_height, useGeom);
978         setEnabled(paper_->choice_head_height_units, useGeom);
979
980         updateWidgetsFromLengthString(paper_->input_head_sep,
981                                       paper_->choice_head_sep_units,
982                                       params.headsep);
983         setEnabled(paper_->input_head_sep, useGeom);
984         setEnabled(paper_->choice_head_sep_units, useGeom);
985
986         updateWidgetsFromLengthString(paper_->input_foot_skip,
987                                       paper_->choice_foot_skip_units,
988                                       params.footskip);
989         setEnabled(paper_->input_foot_skip, useGeom);
990         setEnabled(paper_->choice_foot_skip_units, useGeom);
991
992         fl_set_focus_object(paper_->form, paper_->choice_papersize);
993 }
994
995
996 void FormDocument::bullets_update(BufferParams const & params)
997 {
998         if (!bullets_.get() ||
999             ((XpmVersion<4) ||
1000              (XpmVersion==4 && XpmRevision<7)))
1001                 return;
1002
1003         bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1004         setEnabled(fbullet, !isLinuxDoc);
1005
1006         if (isLinuxDoc) return;
1007
1008         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1009         fl_set_input(bullets_->input_bullet_latex,
1010                      params.user_defined_bullets[0].getText().c_str());
1011         fl_set_choice(bullets_->choice_bullet_size,
1012                       params.user_defined_bullets[0].getSize() + 2);
1013 }
1014
1015
1016 void FormDocument::checkReadOnly()
1017 {
1018         if (bc().readOnly(lv_->buffer()->isReadonly())) {
1019                 combo_doc_class->deactivate();
1020                 combo_language->deactivate();
1021                 fl_set_object_label(dialog_->text_warning,
1022                                     _("Document is read-only."
1023                                       " No changes to layout permitted."));
1024                 fl_show_object(dialog_->text_warning);
1025         } else {
1026                 combo_doc_class->activate();
1027                 combo_language->activate();
1028                 fl_hide_object(dialog_->text_warning);
1029         }
1030 }
1031
1032
1033 void FormDocument::checkMarginValues()
1034 {
1035 //this is not needed after the recent redesign (JSpitzm)
1036 #if 0
1037         bool const not_empty =
1038                 strlen(fl_get_input(paper_->input_top_margin)) ||
1039                 strlen(fl_get_input(paper_->input_bottom_margin)) ||
1040                 strlen(fl_get_input(paper_->input_left_margin)) ||
1041                 strlen(fl_get_input(paper_->input_right_margin)) ||
1042                 strlen(fl_get_input(paper_->input_head_height)) ||
1043                 strlen(fl_get_input(paper_->input_head_sep)) ||
1044                 strlen(fl_get_input(paper_->input_foot_skip)) ||
1045                 strlen(fl_get_input(paper_->input_custom_width)) ||
1046                 strlen(fl_get_input(paper_->input_custom_height));
1047 #endif
1048 }
1049
1050
1051
1052 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
1053 {
1054         string str;
1055         bool ok = true;
1056         char const * input;
1057
1058 // this is not needed after the recent redesign (Angus)
1059 #if 0 
1060         int val;
1061         checkMarginValues();
1062         if (ob == paper_->choice_papersize) {
1063                 val = fl_get_choice(paper_->choice_papersize)-1;
1064                 if (val == BufferParams::VM_PAPER_DEFAULT) {
1065                         fl_set_button(paper_->check_use_geometry, 0);
1066                         setEnabled(paper_->input_top_margin,
1067                                    fl_get_button(paper_->check_use_geometry));
1068                         setEnabled(paper_->input_bottom_margin,
1069                                    fl_get_button(paper_->check_use_geometry));
1070                         setEnabled(paper_->input_left_margin,
1071                                    fl_get_button(paper_->check_use_geometry));
1072                         setEnabled(paper_->input_right_margin,
1073                                    fl_get_button(paper_->check_use_geometry));
1074                         setEnabled(paper_->input_head_height,
1075                                    fl_get_button(paper_->check_use_geometry));
1076                         setEnabled(paper_->input_head_sep,
1077                                    fl_get_button(paper_->check_use_geometry));
1078                         setEnabled(paper_->input_foot_skip,
1079                                    fl_get_button(paper_->check_use_geometry));
1080                         checkMarginValues();
1081                 } else {
1082                         if ((val != BufferParams::VM_PAPER_USLETTER) &&
1083                             (val != BufferParams::VM_PAPER_USLEGAL) &&
1084                             (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
1085                             (val != BufferParams::VM_PAPER_A4) &&
1086                             (val != BufferParams::VM_PAPER_A5) &&
1087                             (val != BufferParams::VM_PAPER_B5)) {
1088                                 fl_set_button(paper_->check_use_geometry, 1);
1089                                 setEnabled(paper_->input_top_margin,
1090                                            fl_get_button(paper_->check_use_geometry));
1091                                 setEnabled(paper_->input_bottom_margin,
1092                                            fl_get_button(paper_->check_use_geometry));
1093                                 setEnabled(paper_->input_left_margin,
1094                                            fl_get_button(paper_->check_use_geometry));
1095                                 setEnabled(paper_->input_right_margin,
1096                                            fl_get_button(paper_->check_use_geometry));
1097                                 setEnabled(paper_->input_head_height,
1098                                            fl_get_button(paper_->check_use_geometry));
1099                                 setEnabled(paper_->input_head_sep,
1100                                            fl_get_button(paper_->check_use_geometry));
1101                                 setEnabled(paper_->input_foot_skip,
1102                                            fl_get_button(paper_->check_use_geometry));
1103                         }
1104                         fl_set_choice(paper_->choice_paperpackage,
1105                                       BufferParams::PACKAGE_NONE + 1);
1106                 }
1107         } else if (ob == paper_->choice_paperpackage) {
1108                 val = fl_get_choice(paper_->choice_paperpackage)-1;
1109                 if (val != BufferParams::PACKAGE_NONE) {
1110                         fl_set_button(paper_->check_use_geometry, 0);
1111                         setEnabled(paper_->input_top_margin,
1112                                    fl_get_button(paper_->check_use_geometry));
1113                         setEnabled(paper_->input_bottom_margin,
1114                                    fl_get_button(paper_->check_use_geometry));
1115                         setEnabled(paper_->input_left_margin,
1116                                    fl_get_button(paper_->check_use_geometry));
1117                         setEnabled(paper_->input_right_margin,
1118                                    fl_get_button(paper_->check_use_geometry));
1119                         setEnabled(paper_->input_head_height,
1120                                    fl_get_button(paper_->check_use_geometry));
1121                         setEnabled(paper_->input_head_sep,
1122                                    fl_get_button(paper_->check_use_geometry));
1123                         setEnabled(paper_->input_foot_skip,
1124                                    fl_get_button(paper_->check_use_geometry));
1125                 }
1126         } else if (ob == class_->input_doc_spacing) {
1127                 input = fl_get_input(class_->input_doc_spacing);
1128                 if (!*input) {
1129                         fl_set_choice (class_->choice_doc_spacing, 1);
1130                 } else {
1131                         fl_set_choice(class_->choice_doc_spacing, 4);
1132                 }
1133         }
1134         // this has to be all out of if/elseif because it has to deactivate
1135         // the document buttons and so the whole stuff has to be tested again.
1136         str = fl_get_input(paper_->input_custom_width);
1137         ok = ok && (str.empty() || isValidLength(str));
1138         str = fl_get_input(paper_->input_custom_height);
1139         ok = ok && (str.empty() || isValidLength(str));
1140         str = fl_get_input(paper_->input_left_margin);
1141         ok = ok && (str.empty() || isValidLength(str));
1142         str = fl_get_input(paper_->input_right_margin);
1143         ok = ok && (str.empty() || isValidLength(str));
1144         str = fl_get_input(paper_->input_top_margin);
1145         ok = ok && (str.empty() || isValidLength(str));
1146         str = fl_get_input(paper_->input_bottom_margin);
1147         ok = ok && (str.empty() || isValidLength(str));
1148         str = fl_get_input(paper_->input_head_height);
1149         ok = ok && (str.empty() || isValidLength(str));
1150         str = fl_get_input(paper_->input_head_sep);
1151         ok = ok && (str.empty() || isValidLength(str));
1152         str = fl_get_input(paper_->input_foot_skip);
1153         ok = ok && (str.empty() || isValidLength(str));
1154 #endif
1155
1156         // "Synchronize" the choice and the input field, so that it
1157         // is impossible to commit senseless data.
1158         input = fl_get_input (class_->input_doc_skip);
1159         if (ob == class_->input_doc_skip) {
1160                 if (!*input) {
1161                         fl_set_choice (class_->choice_doc_skip, 2);
1162                 } else if (isValidGlueLength (input)) {
1163                         fl_set_choice (class_->choice_doc_skip, 4);
1164                 } else {
1165                         fl_set_choice(class_->choice_doc_skip, 4);
1166                         ok = false;
1167                 }
1168         } else {
1169                 if (*input && !isValidGlueLength(input))
1170                         ok = false;
1171         }
1172
1173         if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1174                 ok = false;
1175         else if (fl_get_choice(class_->choice_doc_skip) != 4)
1176                 fl_set_input (class_->input_doc_skip, "");
1177
1178         input = fl_get_input(class_->input_doc_spacing);
1179         if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1180                 ok = false;
1181         else  if (fl_get_choice(class_->choice_doc_spacing) != 4)
1182                 fl_set_input (class_->input_doc_spacing, "");
1183         return ok;
1184 }
1185
1186
1187 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1188 {
1189         BufferParams & param = lv_->buffer()->params;
1190
1191         // convert from 1-6 range to -1-4 
1192         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1193         fl_set_input(bullets_->input_bullet_latex,
1194                      param.temp_bullets[current_bullet_depth].getText().c_str());
1195 }
1196
1197
1198 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1199 {
1200         BufferParams & param = lv_->buffer()->params;
1201
1202         param.temp_bullets[current_bullet_depth].
1203                 setText(fl_get_input(bullets_->input_bullet_latex));
1204 }
1205
1206
1207 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1208 {
1209         /* Should I do the following:                                 */
1210         /*  1. change to the panel that the current bullet belongs in */
1211         /*  2. show that bullet as selected                           */
1212         /*  3. change the size setting to the size of the bullet in Q.*/
1213         /*  4. display the latex equivalent in the latex box          */
1214         /*                                                            */
1215         /* I'm inclined to just go with 3 and 4 at the moment and     */
1216         /* maybe try to support the others later                      */
1217         BufferParams & param = lv_->buffer()->params;
1218
1219         int data = 0;
1220         if (cb == BULLETDEPTH1 )
1221                 data = 0;
1222         else if (cb == BULLETDEPTH2 )
1223                 data = 1;
1224         else if (cb == BULLETDEPTH3 )
1225                 data = 2;
1226         else if (cb == BULLETDEPTH4 )
1227                 data = 3;
1228
1229         switch (fl_get_button_numb(ob)) {
1230         case 3:
1231                 // right mouse button resets to default
1232                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1233         default:
1234                 current_bullet_depth = data;
1235                 fl_set_input(bullets_->input_bullet_latex,
1236                              param.temp_bullets[data].getText().c_str());
1237                 fl_set_choice(bullets_->choice_bullet_size,
1238                               param.temp_bullets[data].getSize() + 2);
1239         }
1240 }
1241
1242
1243 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1244 {
1245         /* Here we have to change the background pixmap to that selected */
1246         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1247     
1248         int data = 0;
1249         if (cb == BULLETPANEL1 )
1250                 data = 0;
1251         else if (cb == BULLETPANEL2 )
1252                 data = 1;
1253         else if (cb == BULLETPANEL3 )
1254                 data = 2;
1255         else if (cb == BULLETPANEL4 )
1256                 data = 3;
1257         else if (cb == BULLETPANEL5 )
1258                 data = 4;
1259         else if (cb == BULLETPANEL6 )
1260                 data = 5;
1261
1262         if (data != current_bullet_panel) {
1263                 fl_freeze_form(bullets_->form);
1264                 current_bullet_panel = data;
1265
1266                 /* free the current pixmap */
1267                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1268                 string new_panel;
1269                 switch (cb) {
1270                         /* display the new one */
1271                 case BULLETPANEL1 :
1272                         new_panel = "standard";
1273                         break;
1274                 case BULLETPANEL2 :
1275                         new_panel = "amssymb";
1276                         break;
1277                 case BULLETPANEL3 :
1278                         new_panel = "psnfss1";
1279                         break;
1280                 case BULLETPANEL4 :
1281                         new_panel = "psnfss2";
1282                         break;
1283                 case BULLETPANEL5 :
1284                         new_panel = "psnfss3";
1285                         break;
1286                 case BULLETPANEL6 :
1287                         new_panel = "psnfss4";
1288                         break;
1289                 default :
1290                         /* something very wrong happened */
1291                         // play it safe for now but should be an exception
1292                         current_bullet_panel = 0;  // standard panel
1293                         new_panel = "standard";
1294                         break;
1295                 }
1296                 new_panel += ".xpm";
1297                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1298                                            LibFileSearch("images", new_panel).c_str());
1299                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1300                 fl_unfreeze_form(bullets_->form);
1301         }
1302 }
1303
1304
1305 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1306 {
1307         /* handle the user input by setting the current bullet depth's pixmap */
1308         /* to that extracted from the current chosen position of the BMTable  */
1309         /* Don't forget to free the button's old pixmap first.                */
1310         
1311         BufferParams & param = lv_->buffer()->params;
1312         int bmtable_button = fl_get_bmtable(ob);
1313         
1314         /* try to keep the button held down till another is pushed */
1315         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1316         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1317         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1318         fl_set_input(bullets_->input_bullet_latex,
1319                      param.temp_bullets[current_bullet_depth].getText().c_str());
1320 }
1321
1322
1323 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1324 {
1325         if (!ob)
1326                 ob = class_->choice_doc_class;
1327
1328         lv_->prohibitInput();
1329
1330         unsigned int tc = combo_doc_class->get() - 1;
1331         if (textclasslist.Load(tc)) {
1332                 // we use a copy of the bufferparams because we do not
1333                 // want to modify them yet.
1334                 BufferParams params = lv_->buffer()->params;
1335
1336                 if (lyxrc.auto_reset_options) {
1337                         params.textclass = tc;
1338                         params.useClassDefaults();
1339                         UpdateLayoutDocument(params);
1340                 }
1341         } else {
1342                 // unable to load new style
1343                 WriteAlert(_("Conversion Errors!"),
1344                            _("Unable to switch to new document class."),
1345                            _("Reverting to original document class."));
1346                 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1347         }
1348         lv_->allowInput();
1349 }
1350
1351
1352 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1353 {
1354         if (!dialog_.get())
1355                 return;
1356
1357         checkReadOnly();
1358         class_update(params);
1359         paper_update(params);
1360         language_update(params);
1361         options_update(params);
1362         bullets_update(params);
1363 }