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