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