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