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