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