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