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