]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
Martin's patches, Part II
[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_left_margin, FL_RETURN_CHANGED);
117         fl_set_input_return(paper_->input_right_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_left_margin,
133                             fl_unsigned_float_filter);
134         fl_set_input_filter(paper_->input_right_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_left_margin_units,   units.c_str());
158         fl_addto_choice(paper_->choice_right_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_left_margin);
174         bc().addReadOnly (paper_->input_right_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                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
455                 bool const metric = paperchoice < 3 || paperchoice > 5;
456                 int const default_unit = metric ? 8 : 9;
457                 if (strip(fl_get_input(class_->input_doc_skip)).empty())
458                         fl_set_choice(class_->choice_default_skip_units,
459                                       default_unit);
460         }
461
462         if (ob == options_->check_use_natbib) {
463                 setEnabled(options_->choice_citation_format,
464                            fl_get_button(options_->check_use_natbib));
465         }
466
467         if (ob == dialog_->button_save_defaults) {
468                 BufferParams params;
469                 class_apply(params);
470                 paper_apply(params);
471                 language_apply(params);
472                 options_apply(params);
473                 bullets_apply(params);
474                 saveParamsAsDefault(params);
475         }
476
477         if (ob == dialog_->button_reset_defaults) {
478                 BufferParams params = lv_->buffer()->params;
479                 params.textclass = combo_doc_class->get() - 1;
480                 params.useClassDefaults();
481                 UpdateLayoutDocument(params);
482         }
483
484         if (ob == paper_->radio_landscape)
485                 fl_set_choice(paper_->choice_paperpackage,
486                 BufferParams::PACKAGE_NONE + 1);
487
488         if (ob == paper_->choice_papersize) {
489                 int const paperchoice = fl_get_choice(paper_->choice_papersize);
490                 bool const custom = paperchoice == 2;
491                 bool const a3size = paperchoice == 6;
492                 bool const b3size = paperchoice == 9;
493                 bool const b4size = paperchoice == 10;
494
495                 if (custom)
496                         fl_set_button(paper_->radio_portrait, 1);
497
498                 bool const use_geom = (custom || a3size || b3size || b4size);
499
500                 fl_set_button(paper_->check_use_geometry, int(use_geom));
501
502                 setEnabled(paper_->input_top_margin,    use_geom);
503                 setEnabled(paper_->input_bottom_margin, use_geom);
504                 setEnabled(paper_->input_left_margin,   use_geom);
505                 setEnabled(paper_->input_right_margin,  use_geom);
506                 setEnabled(paper_->input_head_height,   use_geom);
507                 setEnabled(paper_->input_head_sep,      use_geom);
508                 setEnabled(paper_->input_foot_skip,     use_geom);
509                 setEnabled(paper_->choice_top_margin_units,    use_geom);
510                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
511                 setEnabled(paper_->choice_left_margin_units,   use_geom);
512                 setEnabled(paper_->choice_right_margin_units,  use_geom);
513                 setEnabled(paper_->choice_head_height_units,   use_geom);
514                 setEnabled(paper_->choice_head_sep_units,      use_geom);
515                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
516                 setEnabled(paper_->choice_custom_width_units,  use_geom);
517                 setEnabled(paper_->choice_custom_height_units, use_geom);
518
519                 setEnabled(paper_->input_custom_width,  custom);
520                 setEnabled(paper_->input_custom_height, custom);
521                 setEnabled(paper_->choice_custom_width_units,  custom);
522                 setEnabled(paper_->choice_custom_height_units, custom);
523                 setEnabled(paper_->radio_portrait,  !custom);
524                 setEnabled(paper_->radio_landscape, !custom);
525
526                 // Default unit choice is cm if metric, inches if US paper.
527                 bool const metric = paperchoice < 3 || paperchoice > 5;
528                 int const default_unit = metric ? 8 : 9;
529                 if (strip(fl_get_input(paper_->input_custom_width)).empty())
530                         fl_set_choice(paper_->choice_custom_width_units,
531                                       default_unit);
532                 if (strip(fl_get_input(paper_->input_custom_height)).empty())
533                         fl_set_choice(paper_->choice_custom_height_units,
534                                       default_unit);
535                 if (strip(fl_get_input(paper_->input_top_margin)).empty())
536                         fl_set_choice(paper_->choice_top_margin_units,
537                                       default_unit);
538                 if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
539                         fl_set_choice(paper_->choice_bottom_margin_units,
540                                       default_unit);
541                 if (strip(fl_get_input(paper_->input_left_margin)).empty())
542                         fl_set_choice(paper_->choice_left_margin_units,
543                                       default_unit);
544                 if (strip(fl_get_input(paper_->input_right_margin)).empty())
545                         fl_set_choice(paper_->choice_right_margin_units,
546                                       default_unit);
547                 if (strip(fl_get_input(paper_->input_head_height)).empty())
548                         fl_set_choice(paper_->choice_head_height_units,
549                                       default_unit);
550                 if (strip(fl_get_input(paper_->input_head_sep)).empty())
551                         fl_set_choice(paper_->choice_head_sep_units,
552                                       default_unit);
553                 if (strip(fl_get_input(paper_->input_foot_skip)).empty())
554                         fl_set_choice(paper_->choice_foot_skip_units,
555                                       default_unit);
556         }
557
558         if (ob == paper_->choice_papersize ||
559             ob == paper_->radio_portrait ||
560             ob == paper_->radio_landscape) {
561
562                 setEnabled(paper_->choice_paperpackage,
563                            //either default papersize (preferences)
564                            //or document papersize has to be A4
565                            (fl_get_choice(paper_->choice_papersize) == 7
566                             || fl_get_choice(paper_->choice_papersize) == 1
567                             && lyxrc.default_papersize == 5)
568                            && fl_get_button(paper_->radio_portrait));
569         }
570
571         if (ob == paper_->choice_paperpackage) {
572                 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
573                         fl_set_button(paper_->check_use_geometry, 0);
574
575                         setEnabled(paper_->input_top_margin,    false);
576                         setEnabled(paper_->input_bottom_margin, false);
577                         setEnabled(paper_->input_left_margin,   false);
578                         setEnabled(paper_->input_right_margin,  false);
579                         setEnabled(paper_->input_head_height,   false);
580                         setEnabled(paper_->input_head_sep,      false);
581                         setEnabled(paper_->input_foot_skip,     false);
582                         setEnabled(paper_->choice_top_margin_units,    false);
583                         setEnabled(paper_->choice_bottom_margin_units, false);
584                         setEnabled(paper_->choice_left_margin_units,   false);
585                         setEnabled(paper_->choice_right_margin_units,  false);
586                         setEnabled(paper_->choice_head_height_units,   false);
587                         setEnabled(paper_->choice_head_sep_units,      false);
588                         setEnabled(paper_->choice_foot_skip_units,     false);
589                 }
590         }
591
592         if (ob == paper_->check_use_geometry) {
593                 //don't allow switching geometry off in custom papersize mode
594                 //nor in A3, B3, and B4
595                 int const choice = fl_get_choice(paper_->choice_papersize);
596                 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
597                         fl_set_button(paper_->check_use_geometry, 1);
598
599                 fl_set_choice(paper_->choice_paperpackage,
600                               BufferParams::PACKAGE_NONE + 1);
601
602                 bool const use_geom = fl_get_button(paper_->check_use_geometry);
603                 setEnabled(paper_->input_top_margin,    use_geom);
604                 setEnabled(paper_->input_bottom_margin, use_geom);
605                 setEnabled(paper_->input_left_margin,   use_geom);
606                 setEnabled(paper_->input_right_margin,  use_geom);
607                 setEnabled(paper_->input_head_height,   use_geom);
608                 setEnabled(paper_->input_head_sep,      use_geom);
609                 setEnabled(paper_->input_foot_skip,     use_geom);
610                 setEnabled(paper_->choice_top_margin_units,    use_geom);
611                 setEnabled(paper_->choice_bottom_margin_units, use_geom);
612                 setEnabled(paper_->choice_left_margin_units,   use_geom);
613                 setEnabled(paper_->choice_right_margin_units,  use_geom);
614                 setEnabled(paper_->choice_head_height_units,   use_geom);
615                 setEnabled(paper_->choice_head_sep_units,      use_geom);
616                 setEnabled(paper_->choice_foot_skip_units,     use_geom);
617         }
618
619         switch (data) {
620         case INPUT:
621         case CHECKCHOICECLASS:
622         case CHOICEBULLETSIZE:
623         case INPUTBULLETLATEX:
624         case BULLETBMTABLE:
625                 return CheckDocumentInput(ob, 0);
626         default:
627                 break;
628         }
629
630         return true;
631 }
632
633
634 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
635 {
636         FormDocument * pre = static_cast<FormDocument*>(v);
637         if (combox == pre->combo_doc_class.get())
638                 pre->CheckChoiceClass(0, 0);
639         pre->bc().valid(pre->CheckDocumentInput(0,0));
640 }
641
642
643 bool FormDocument::class_apply(BufferParams &params)
644 {
645         bool redo = false;
646
647         // If default skip is a "Length" but there's no text in the
648         // input field, reset the kind to "Medskip", which is the default.
649         if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
650             !*(fl_get_input (class_->input_doc_skip))) {
651                 fl_set_choice (class_->choice_doc_skip, 2);
652         }
653         params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
654         params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
655         params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
656
657         params.textclass = combo_doc_class->get() - 1;
658         
659         BufferParams::PARSEP tmpsep = params.paragraph_separation;
660         if (fl_get_button(class_->radio_doc_indent))
661                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
662         else
663                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
664         if (tmpsep != params.paragraph_separation)
665                 redo = true;
666         
667         VSpace tmpdefskip = params.getDefSkip();
668         switch (fl_get_choice (class_->choice_doc_skip)) {
669         case 1:
670                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
671                 break;
672         case 2:
673                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
674                 break;
675         case 3:
676             params.setDefSkip(VSpace(VSpace::BIGSKIP));
677             break;
678         case 4:
679         {
680                 string const length =
681                         getLengthFromWidgets(class_->input_doc_skip,
682                                              class_->choice_default_skip_units);
683
684                 params.setDefSkip(VSpace(LyXGlueLength(length)));
685                 break;
686         }
687         default:
688                 // DocumentDefskipCB assures that this never happens
689                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
690                 break;
691         }
692         if (!(tmpdefskip == params.getDefSkip()))
693                 redo = true;
694         
695         if (fl_get_button(class_->radio_doc_columns_two))
696                 params.columns = 2;
697         else
698                 params.columns = 1;
699         if (fl_get_button(class_->radio_doc_sides_two))
700                 params.sides = LyXTextClass::TwoSides;
701         else
702                 params.sides = LyXTextClass::OneSide;
703         
704         Spacing tmpSpacing = params.spacing;
705         switch (fl_get_choice(class_->choice_doc_spacing)) {
706         case 1:
707                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
708                 params.spacing.set(Spacing::Single);
709                 break;
710         case 2:
711                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
712                 params.spacing.set(Spacing::Onehalf);
713                 break;
714         case 3:
715                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
716                 params.spacing.set(Spacing::Double);
717                 break;
718         case 4:
719                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
720                 params.spacing.set(Spacing::Other, 
721                                    fl_get_input(class_->input_doc_spacing));
722                 break;
723         }
724         if (tmpSpacing != params.spacing)
725                 redo = true;
726         
727         params.options = fl_get_input(class_->input_doc_extra);
728         
729         return redo;
730 }
731
732
733 bool FormDocument::class_apply()
734 {
735         BufferParams &params = lv_->buffer()->params;
736
737         unsigned int const old_class = params.textclass;
738
739         bool redo = class_apply(params);
740
741         if (params.textclass != old_class) {
742                 // try to load new_class
743                 if (textclasslist.Load(params.textclass)) {
744                         // successfully loaded
745                         redo = true;
746                         setMinibuffer(lv_, _("Converting document to new document class..."));
747                         int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
748                                 old_class, params.textclass,
749                                 lv_->buffer()->paragraph,
750                                 lv_->buffer()->params);
751                         if (ret) {
752                                 string s;
753                                 if (ret==1) {
754                                         s = _("One paragraph couldn't be converted");
755                                 } else {
756                                         s += tostr(ret);
757                                         s += _(" paragraphs couldn't be converted");
758                                 }
759                                 Alert::alert(_("Conversion Errors!"),s,
760                                            _("into chosen document class"));
761                         }
762                         
763                 } else {
764                         // problem changing class -- warn user and retain old style
765                         Alert::alert(_("Conversion Errors!"),
766                                    _("Errors loading new document class."),
767                                    _("Reverting to original document class."));
768                         combo_doc_class->select(int(old_class) + 1);
769                 }
770         }
771         
772         return redo;
773 }
774
775
776 void FormDocument::paper_apply(BufferParams & params)
777 {
778         params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
779
780         params.paperpackage =
781                 char(fl_get_choice(paper_->choice_paperpackage)-1);
782
783         // set params.papersize from params.papersize2 and params.paperpackage
784         params.setPaperStuff();
785
786         params.use_geometry = fl_get_button(paper_->check_use_geometry);
787
788         if (fl_get_button(paper_->radio_landscape))
789                 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
790         else
791                 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
792
793         params.paperwidth =
794                 getLengthFromWidgets(paper_->input_custom_width,
795                                      paper_->choice_custom_width_units);
796
797         params.paperheight =
798                 getLengthFromWidgets(paper_->input_custom_height,
799                                      paper_->choice_custom_height_units);
800
801         params.leftmargin =
802                 getLengthFromWidgets(paper_->input_left_margin,
803                                      paper_->choice_left_margin_units);
804
805         params.topmargin =
806                 getLengthFromWidgets(paper_->input_top_margin,
807                                      paper_->choice_top_margin_units);
808
809         params.rightmargin =
810                 getLengthFromWidgets(paper_->input_right_margin,
811                                      paper_->choice_right_margin_units);
812
813         params.bottommargin =
814                 getLengthFromWidgets(paper_->input_bottom_margin,
815                                      paper_->choice_bottom_margin_units);
816
817         params.headheight =
818                 getLengthFromWidgets(paper_->input_head_height,
819                                      paper_->choice_head_height_units);
820
821         params.headsep =
822                 getLengthFromWidgets(paper_->input_head_sep,
823                                      paper_->choice_head_sep_units);
824
825         params.footskip =
826                 getLengthFromWidgets(paper_->input_foot_skip,
827                                      paper_->choice_foot_skip_units);
828 }
829
830
831 void FormDocument::paper_apply()
832 {
833         paper_apply(lv_->buffer()->params);
834 }
835
836
837 bool FormDocument::language_apply(BufferParams & params)
838 {
839         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
840         bool redo = false;
841
842         switch (fl_get_choice(language_->choice_quotes_language) - 1) {
843         case 0:
844                 lga = InsetQuotes::EnglishQ;
845                 break;
846         case 1:
847                 lga = InsetQuotes::SwedishQ;
848                 break;
849         case 2:
850                 lga = InsetQuotes::GermanQ;
851                 break;
852         case 3:
853                 lga = InsetQuotes::PolishQ;
854                 break;
855         case 4:
856                 lga = InsetQuotes::FrenchQ;
857                 break;
858         case 5:
859                 lga = InsetQuotes::DanishQ;
860                 break;
861         }
862         params.quotes_language = lga;
863         if (fl_get_button(language_->radio_single))   
864                 params.quotes_times = InsetQuotes::SingleQ;
865         else
866                 params.quotes_times = InsetQuotes::DoubleQ;
867
868         Language const * old_language = params.language;
869         Language const * new_language = 
870                 languages.getLanguage(combo_language->getline());
871         if (!new_language)
872                 new_language = default_language;
873
874         if (old_language != new_language
875             && old_language->RightToLeft() == params.language->RightToLeft()
876             && !lv_->buffer()->isMultiLingual())
877                 lv_->buffer()->changeLanguage(old_language, params.language);
878
879         if (old_language != new_language) {
880                 redo = true;
881         }
882
883         params.language = new_language;
884         params.inputenc = fl_get_choice_text(language_->choice_inputenc);
885
886         return redo;
887 }
888
889
890 bool FormDocument::language_apply()
891 {
892         return language_apply(lv_->buffer()->params);
893 }
894
895
896 bool FormDocument::options_apply(BufferParams & params)
897 {
898         bool redo = false;
899
900         params.graphicsDriver =
901                 fl_get_choice_text(options_->choice_postscript_driver);
902         params.use_amsmath = fl_get_button(options_->check_use_amsmath);
903         params.use_natbib  = fl_get_button(options_->check_use_natbib);
904         params.use_numerical_citations  =
905                 fl_get_choice(options_->choice_citation_format)-1;
906
907         int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
908         if (params.secnumdepth != tmpchar)
909                 redo = true;
910         params.secnumdepth = tmpchar;
911    
912         params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
913
914         params.float_placement =
915                 fl_get_input(options_->input_float_placement);
916
917         return redo;
918 }
919
920
921 bool FormDocument::options_apply()
922 {
923         return options_apply(lv_->buffer()->params);
924 }
925
926
927 void FormDocument::bullets_apply(BufferParams & params)
928 {
929         /* update the bullet settings */
930         BufferParams & buf_params = lv_->buffer()->params;
931
932         // a little bit of loop unrolling
933         params.user_defined_bullets[0] = buf_params.temp_bullets[0];
934         params.user_defined_bullets[1] = buf_params.temp_bullets[1];
935         params.user_defined_bullets[2] = buf_params.temp_bullets[2];
936         params.user_defined_bullets[3] = buf_params.temp_bullets[3];
937 }
938
939
940 void FormDocument::bullets_apply()
941 {
942         bullets_apply(lv_->buffer()->params);
943 }
944
945
946 void FormDocument::class_update(BufferParams const & params)
947 {
948         if (!class_.get())
949                 return;
950
951         LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
952
953         combo_doc_class->select(
954                 textclasslist.DescOfClass(params.textclass));
955         fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
956         fl_clear_choice(class_->choice_doc_fontsize);
957         fl_addto_choice(class_->choice_doc_fontsize, "default");
958         fl_addto_choice(class_->choice_doc_fontsize,
959                         tclass.opt_fontsize().c_str());
960         fl_set_choice(class_->choice_doc_fontsize,
961                       tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
962         fl_clear_choice(class_->choice_doc_pagestyle);
963         fl_addto_choice(class_->choice_doc_pagestyle, "default");
964         fl_addto_choice(class_->choice_doc_pagestyle,
965                         tclass.opt_pagestyle().c_str());
966         fl_set_choice(class_->choice_doc_pagestyle,
967                       tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
968         fl_set_button(class_->radio_doc_indent, 0);
969         fl_set_button(class_->radio_doc_skip, 0);
970         if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
971                 fl_set_button(class_->radio_doc_indent, 1);
972         else
973                 fl_set_button(class_->radio_doc_skip, 1);
974
975         bool const input_length = fl_get_choice(class_->choice_doc_skip) == 4;
976         setEnabled(class_->choice_default_skip_units, input_length);
977         setEnabled(class_->input_doc_skip, input_length);
978
979         switch (params.getDefSkip().kind()) {
980         case VSpace::SMALLSKIP: 
981                 fl_set_choice (class_->choice_doc_skip, 1);
982                 break;
983         case VSpace::MEDSKIP: 
984                 fl_set_choice (class_->choice_doc_skip, 2);
985                 break;
986         case VSpace::BIGSKIP: 
987                 fl_set_choice (class_->choice_doc_skip, 3);
988                 break;
989         case VSpace::LENGTH:
990         {
991                 int const paperchoice = params.papersize2 + 1;
992                 bool const metric = paperchoice < 3 || paperchoice > 5;
993                 string const default_unit = metric ? "cm" : "in";
994                 string const length = params.getDefSkip().asLyXCommand();
995                 updateWidgetsFromLengthString(class_->input_doc_skip,
996                                               class_->choice_default_skip_units,
997                                               length, default_unit);
998                 break;
999         }
1000         default:
1001                 fl_set_choice (class_->choice_doc_skip, 2);
1002                 break;
1003         }
1004         fl_set_button(class_->radio_doc_sides_one, 0);
1005         fl_set_button(class_->radio_doc_sides_two, 0);
1006         setEnabled(class_->choice_doc_skip,
1007                    fl_get_button(class_->radio_doc_skip));
1008
1009         if (params.sides == LyXTextClass::TwoSides)
1010                 fl_set_button(class_->radio_doc_sides_two, 1);
1011         else
1012                 fl_set_button(class_->radio_doc_sides_one, 1);
1013         fl_set_button(class_->radio_doc_columns_one, 0);
1014         fl_set_button(class_->radio_doc_columns_two, 0);
1015         if (params.columns == 2)
1016                 fl_set_button(class_->radio_doc_columns_two, 1);
1017         else
1018                 fl_set_button(class_->radio_doc_columns_one, 1);
1019         fl_set_input(class_->input_doc_spacing, "");
1020
1021         setEnabled(class_->input_doc_spacing, input_length);
1022
1023         switch (params.spacing.getSpace()) {
1024         case Spacing::Default: // nothing bad should happen with this
1025         case Spacing::Single:
1026                 // \singlespacing
1027                 fl_set_choice(class_->choice_doc_spacing, 1);
1028                 break;
1029         case Spacing::Onehalf:
1030                 // \onehalfspacing
1031                 fl_set_choice(class_->choice_doc_spacing, 2);
1032                 break;
1033         case Spacing::Double:
1034                 // \doublespacing
1035                 fl_set_choice(class_->choice_doc_spacing, 3);
1036                 break;
1037         case Spacing::Other:
1038         {
1039                 fl_set_choice(class_->choice_doc_spacing, 4);
1040                 char sval[20];
1041                 sprintf(sval,"%g",params.spacing.getValue()); 
1042                 fl_set_input(class_->input_doc_spacing, sval);
1043                 break;
1044         }
1045         }
1046         if (!params.options.empty())
1047                 fl_set_input(class_->input_doc_extra, params.options.c_str());
1048         else
1049                 fl_set_input(class_->input_doc_extra, "");
1050 }
1051
1052
1053 void FormDocument::language_update(BufferParams const & params)
1054 {
1055         if (!language_.get())
1056                 return;
1057
1058         combo_language->select(params.language->lang());
1059         fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
1060         fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
1061         fl_set_button(language_->radio_single, 0);
1062         fl_set_button(language_->radio_double, 0);
1063         if (params.quotes_times == InsetQuotes::SingleQ)
1064                 fl_set_button(language_->radio_single, 1);
1065         else
1066                 fl_set_button(language_->radio_double, 1);
1067 }
1068
1069
1070 void FormDocument::options_update(BufferParams const & params)
1071 {
1072         if (!options_.get())
1073                 return;
1074
1075         fl_set_choice_text(options_->choice_postscript_driver,
1076                            params.graphicsDriver.c_str());
1077         fl_set_button(options_->check_use_amsmath, params.use_amsmath);
1078         fl_set_button(options_->check_use_natbib,  params.use_natbib);
1079         fl_set_choice(options_->choice_citation_format,
1080                       int(params.use_numerical_citations)+1);
1081         setEnabled(options_->choice_citation_format, params.use_natbib);
1082         fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
1083         fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
1084         if (!params.float_placement.empty())
1085                 fl_set_input(options_->input_float_placement,
1086                              params.float_placement.c_str());
1087         else
1088                 fl_set_input(options_->input_float_placement, "");
1089 }
1090
1091
1092 void FormDocument::paper_update(BufferParams const & params)
1093 {
1094         if (!paper_.get())
1095                 return;
1096
1097         fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1098         fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1099         fl_set_button(paper_->check_use_geometry, params.use_geometry);
1100
1101         int const paperchoice = fl_get_choice(paper_->choice_papersize);
1102         bool const useCustom = paperchoice == 2;
1103         bool const useGeom = fl_get_button(paper_->check_use_geometry);
1104
1105         fl_set_button(paper_->radio_portrait, 0);
1106         setEnabled(paper_->radio_portrait, !useCustom);
1107         fl_set_button(paper_->radio_landscape, 0);
1108         setEnabled(paper_->radio_landscape, !useCustom);
1109
1110         if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1111                 fl_set_button(paper_->radio_landscape, 1);
1112         else
1113                 fl_set_button(paper_->radio_portrait, 1);
1114         setEnabled(paper_->choice_paperpackage,
1115                    //either default papersize (preferences)
1116                    //or document papersize has to be A4
1117                    (paperchoice == 7
1118                     || paperchoice == 1 && lyxrc.default_papersize == 5)
1119                    && fl_get_button(paper_->radio_portrait));
1120
1121         // Default unit choice is cm if metric, inches if US paper.
1122         bool const metric = paperchoice < 3 || paperchoice > 5;
1123         string const default_unit = metric ? "cm" : "in";
1124         updateWidgetsFromLengthString(paper_->input_custom_width,
1125                                       paper_->choice_custom_width_units,
1126                                       params.paperwidth, default_unit);
1127         setEnabled(paper_->input_custom_width, useCustom);
1128         setEnabled(paper_->choice_custom_width_units, useCustom);
1129
1130         updateWidgetsFromLengthString(paper_->input_custom_height,
1131                                       paper_->choice_custom_height_units,
1132                                       params.paperheight, default_unit);
1133         setEnabled(paper_->input_custom_height, useCustom);
1134         setEnabled(paper_->choice_custom_height_units, useCustom);
1135
1136         updateWidgetsFromLengthString(paper_->input_left_margin,
1137                                       paper_->choice_left_margin_units,
1138                                       params.leftmargin, default_unit);
1139         setEnabled(paper_->input_left_margin, useGeom);
1140         setEnabled(paper_->choice_left_margin_units, useGeom);
1141
1142         updateWidgetsFromLengthString(paper_->input_top_margin,
1143                                       paper_->choice_top_margin_units,
1144                                       params.topmargin, default_unit);
1145         setEnabled(paper_->input_top_margin, useGeom);
1146         setEnabled(paper_->choice_top_margin_units, useGeom);
1147
1148         updateWidgetsFromLengthString(paper_->input_right_margin,
1149                                       paper_->choice_right_margin_units,
1150                                       params.rightmargin, default_unit);
1151         setEnabled(paper_->input_right_margin, useGeom);
1152         setEnabled(paper_->choice_right_margin_units, useGeom);
1153
1154         updateWidgetsFromLengthString(paper_->input_bottom_margin,
1155                                       paper_->choice_bottom_margin_units,
1156                                       params.bottommargin, default_unit);
1157         setEnabled(paper_->input_bottom_margin, useGeom);
1158         setEnabled(paper_->choice_bottom_margin_units, useGeom);
1159
1160         updateWidgetsFromLengthString(paper_->input_head_height,
1161                                       paper_->choice_head_height_units,
1162                                       params.headheight, default_unit);
1163         setEnabled(paper_->input_head_height, useGeom);
1164         setEnabled(paper_->choice_head_height_units, useGeom);
1165
1166         updateWidgetsFromLengthString(paper_->input_head_sep,
1167                                       paper_->choice_head_sep_units,
1168                                       params.headsep, default_unit);
1169         setEnabled(paper_->input_head_sep, useGeom);
1170         setEnabled(paper_->choice_head_sep_units, useGeom);
1171
1172         updateWidgetsFromLengthString(paper_->input_foot_skip,
1173                                       paper_->choice_foot_skip_units,
1174                                       params.footskip, default_unit);
1175         setEnabled(paper_->input_foot_skip, useGeom);
1176         setEnabled(paper_->choice_foot_skip_units, useGeom);
1177
1178         fl_set_focus_object(paper_->form, paper_->choice_papersize);
1179 }
1180
1181
1182 void FormDocument::bullets_update(BufferParams const & params)
1183 {
1184         if (!bullets_.get() ||
1185             ((XpmVersion<4) ||
1186              (XpmVersion==4 && XpmRevision<7)))
1187                 return;
1188
1189         bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1190         setEnabled(fbullet, !isLinuxDoc);
1191
1192         if (isLinuxDoc) return;
1193
1194         fl_set_button(bullets_->radio_bullet_depth_1, 1);
1195         fl_set_input(bullets_->input_bullet_latex,
1196                      params.user_defined_bullets[0].getText().c_str());
1197         fl_set_choice(bullets_->choice_bullet_size,
1198                       params.user_defined_bullets[0].getSize() + 2);
1199 }
1200
1201
1202 void FormDocument::checkReadOnly()
1203 {
1204         if (bc().readOnly(lv_->buffer()->isReadonly())) {
1205                 combo_doc_class->deactivate();
1206                 combo_language->deactivate();
1207                 fl_set_object_label(dialog_->text_warning,
1208                                     _("Document is read-only."
1209                                       " No changes to layout permitted."));
1210                 fl_show_object(dialog_->text_warning);
1211         } else {
1212                 combo_doc_class->activate();
1213                 combo_language->activate();
1214                 fl_hide_object(dialog_->text_warning);
1215         }
1216 }
1217
1218
1219 bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
1220 {
1221         string str;
1222         bool ok = true;
1223         char const * input;
1224
1225         // "Synchronize" the choice and the input field, so that it
1226         // is impossible to commit senseless data.
1227         input = fl_get_input (class_->input_doc_skip);
1228         if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1229                 ok = false;
1230         else if (fl_get_choice(class_->choice_doc_skip) != 4)
1231                 fl_set_input (class_->input_doc_skip, "");
1232
1233         input = fl_get_input(class_->input_doc_spacing);
1234         if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1235                 ok = false;
1236         else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1237                 fl_set_input (class_->input_doc_spacing, "");
1238         return ok;
1239 }
1240
1241
1242 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1243 {
1244         BufferParams & param = lv_->buffer()->params;
1245
1246         // convert from 1-6 range to -1-4 
1247         param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1248         fl_set_input(bullets_->input_bullet_latex,
1249                      param.temp_bullets[current_bullet_depth].getText().c_str());
1250 }
1251
1252
1253 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1254 {
1255         BufferParams & param = lv_->buffer()->params;
1256
1257         param.temp_bullets[current_bullet_depth].
1258                 setText(fl_get_input(bullets_->input_bullet_latex));
1259 }
1260
1261
1262 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1263 {
1264         /* Should I do the following:                                 */
1265         /*  1. change to the panel that the current bullet belongs in */
1266         /*  2. show that bullet as selected                           */
1267         /*  3. change the size setting to the size of the bullet in Q.*/
1268         /*  4. display the latex equivalent in the latex box          */
1269         /*                                                            */
1270         /* I'm inclined to just go with 3 and 4 at the moment and     */
1271         /* maybe try to support the others later                      */
1272         BufferParams & param = lv_->buffer()->params;
1273
1274         int data = 0;
1275         if (cb == BULLETDEPTH1 )
1276                 data = 0;
1277         else if (cb == BULLETDEPTH2 )
1278                 data = 1;
1279         else if (cb == BULLETDEPTH3 )
1280                 data = 2;
1281         else if (cb == BULLETDEPTH4 )
1282                 data = 3;
1283
1284         switch (fl_get_button_numb(ob)) {
1285         case 3:
1286                 // right mouse button resets to default
1287                 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1288         default:
1289                 current_bullet_depth = data;
1290                 fl_set_input(bullets_->input_bullet_latex,
1291                              param.temp_bullets[data].getText().c_str());
1292                 fl_set_choice(bullets_->choice_bullet_size,
1293                               param.temp_bullets[data].getSize() + 2);
1294         }
1295 }
1296
1297
1298 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1299 {
1300         /* Here we have to change the background pixmap to that selected */
1301         /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
1302     
1303         int data = 0;
1304         if (cb == BULLETPANEL1 )
1305                 data = 0;
1306         else if (cb == BULLETPANEL2 )
1307                 data = 1;
1308         else if (cb == BULLETPANEL3 )
1309                 data = 2;
1310         else if (cb == BULLETPANEL4 )
1311                 data = 3;
1312         else if (cb == BULLETPANEL5 )
1313                 data = 4;
1314         else if (cb == BULLETPANEL6 )
1315                 data = 5;
1316
1317         if (data != current_bullet_panel) {
1318                 fl_freeze_form(bullets_->form);
1319                 current_bullet_panel = data;
1320
1321                 /* free the current pixmap */
1322                 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1323                 string new_panel;
1324                 switch (cb) {
1325                         /* display the new one */
1326                 case BULLETPANEL1 :
1327                         new_panel = "standard";
1328                         break;
1329                 case BULLETPANEL2 :
1330                         new_panel = "amssymb";
1331                         break;
1332                 case BULLETPANEL3 :
1333                         new_panel = "psnfss1";
1334                         break;
1335                 case BULLETPANEL4 :
1336                         new_panel = "psnfss2";
1337                         break;
1338                 case BULLETPANEL5 :
1339                         new_panel = "psnfss3";
1340                         break;
1341                 case BULLETPANEL6 :
1342                         new_panel = "psnfss4";
1343                         break;
1344                 default :
1345                         /* something very wrong happened */
1346                         // play it safe for now but should be an exception
1347                         current_bullet_panel = 0;  // standard panel
1348                         new_panel = "standard";
1349                         break;
1350                 }
1351                 new_panel += ".xpm";
1352                 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1353                                            LibFileSearch("images", new_panel).c_str());
1354                 fl_redraw_object(bullets_->bmtable_bullet_panel);
1355                 fl_unfreeze_form(bullets_->form);
1356         }
1357 }
1358
1359
1360 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1361 {
1362         /* handle the user input by setting the current bullet depth's pixmap */
1363         /* to that extracted from the current chosen position of the BMTable  */
1364         /* Don't forget to free the button's old pixmap first.                */
1365         
1366         BufferParams & param = lv_->buffer()->params;
1367         int bmtable_button = fl_get_bmtable(ob);
1368         
1369         /* try to keep the button held down till another is pushed */
1370         /*  fl_set_bmtable(ob, 1, bmtable_button); */
1371         param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1372         param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1373         fl_set_input(bullets_->input_bullet_latex,
1374                      param.temp_bullets[current_bullet_depth].getText().c_str());
1375 }
1376
1377
1378 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1379 {
1380         if (!ob)
1381                 ob = class_->choice_doc_class;
1382
1383         lv_->prohibitInput();
1384
1385         unsigned int tc = combo_doc_class->get() - 1;
1386         if (textclasslist.Load(tc)) {
1387                 // we use a copy of the bufferparams because we do not
1388                 // want to modify them yet.
1389                 BufferParams params = lv_->buffer()->params;
1390
1391                 if (lyxrc.auto_reset_options) {
1392                         params.textclass = tc;
1393                         params.useClassDefaults();
1394                         UpdateLayoutDocument(params);
1395                 }
1396         } else {
1397                 // unable to load new style
1398                 Alert::alert(_("Conversion Errors!"),
1399                            _("Unable to switch to new document class."),
1400                            _("Reverting to original document class."));
1401                 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1402         }
1403         lv_->allowInput();
1404 }
1405
1406
1407 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1408 {
1409         if (!dialog_.get())
1410                 return;
1411
1412         checkReadOnly();
1413         class_update(params);
1414         paper_update(params);
1415         language_update(params);
1416         options_update(params);
1417         bullets_update(params);
1418 }