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