]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormDocument.C
6f28e1468506914f497fc573e895e9261b033cd7
[lyx.git] / src / frontends / xforms / FormDocument.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000 The LyX Team.
7  *
8  *           @author Jürgen Vigna
9  *
10  *======================================================*/
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include "lyx_gui_misc.h"
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
21
22 #include "FormDocument.h"
23 #include "form_document.h"
24 #include "Dialogs.h"
25 #include "layout.h"
26 #include "combox.h"
27 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "insets/insetquotes.h"
30 #include "vspace.h"
31 #include "bmtable.h"
32 #include "support/filetools.h"
33 #include "language.h"
34 #include "LyXView.h"
35 #include "BufferView.h"
36 #include "buffer.h"
37 #include "Liason.h"
38 #include "CutAndPaste.h"
39 #include "bufferview_funcs.h"
40
41 #ifdef CXX_WORKING_NAMESPACES
42 using Liason::setMinibuffer;
43 #endif
44
45 #define USE_CLASS_COMBO 1
46
47 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
48         : FormBaseBD(lv, d, _("Document Layout"),
49                      new NoRepeatedApplyReadOnlyPolicy),
50           dialog_(0), paper_(0), class_(0), language_(0), options_(0),
51           bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
52           fbullet(0), combo_language(0), combo_doc_class(0)
53 {
54     // let the popup be shown
55     // This is a permanent connection so we won't bother
56     // storing a copy because we won't be disconnecting.
57     d->showLayoutDocument.connect(slot(this, &FormDocument::show));
58 }
59
60
61 FormDocument::~FormDocument()
62 {
63 #ifdef USE_CLASS_COMBO
64     delete combo_doc_class;
65 #endif
66     delete class_;
67     delete paper_;
68     delete combo_language;
69     delete language_;
70     delete options_;
71     delete bullets_;
72     delete dialog_;
73 }
74
75
76 void FormDocument::redraw()
77 {
78         if( form() && form()->visible )
79                 fl_redraw_form( form() );
80         else
81                 return;
82
83         FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
84         if (outer_form && outer_form->visible)
85                 fl_redraw_form( outer_form );
86 }
87
88
89 FL_FORM * FormDocument::form() const
90 {
91     if (dialog_) return dialog_->form;
92     return 0;
93 }
94
95
96 void FormDocument::build()
97 {
98     int n;
99
100     // the tabbed folder
101     dialog_ = build_tabbed_document();
102
103     // Manage the restore, ok, apply, restore and cancel/close buttons
104     bc_.setOK(dialog_->button_ok);
105     bc_.setApply(dialog_->button_apply);
106     bc_.setCancel(dialog_->button_cancel);
107     bc_.setUndoAll(dialog_->button_restore);
108     bc_.refresh();
109
110     // Workaround dumb xforms sizing bug
111     minw_ = form()->w;
112     minh_ = form()->h;
113
114     // the document paper form
115     paper_ = build_doc_paper();
116     fl_addto_choice(paper_->choice_papersize2,
117                     _(" Default | Custom | USletter | USlegal "
118                       "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
119     fl_addto_choice(paper_->choice_paperpackage,
120                     _(" None "
121                       "| A4 small Margins (only portrait) "
122                       "| A4 very small Margins (only portrait) "
123                       "| A4 very wide margins (only portrait) "));
124     fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
125     fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
126     fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
127     fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
128     fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
129     fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
130     fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
131     fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
132     fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
133
134     bc_.addReadOnly (paper_->choice_paperpackage);
135     bc_.addReadOnly (paper_->greoup_radio_orientation);
136     bc_.addReadOnly (paper_->radio_portrait);
137     bc_.addReadOnly (paper_->radio_landscape);
138     bc_.addReadOnly (paper_->choice_papersize2);
139     bc_.addReadOnly (paper_->push_use_geometry);
140     bc_.addReadOnly (paper_->input_custom_width);
141     bc_.addReadOnly (paper_->input_custom_height);
142     bc_.addReadOnly (paper_->input_top_margin);
143     bc_.addReadOnly (paper_->input_bottom_margin);
144     bc_.addReadOnly (paper_->input_left_margin);
145     bc_.addReadOnly (paper_->input_right_margin);
146     bc_.addReadOnly (paper_->input_head_height);
147     bc_.addReadOnly (paper_->input_head_sep);
148     bc_.addReadOnly (paper_->input_foot_skip);
149
150     // the document class form
151     class_ = build_doc_class();
152
153     FL_OBJECT * obj;
154 #ifdef USE_CLASS_COMBO
155     // The language is a combo-box and has to be inserted manually
156     obj = class_->choice_doc_class;
157     fl_addto_form(class_->form);
158     combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
159     combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
160                          dialog_->tabbed_folder);
161     combo_doc_class->shortcut("#C",1);
162     combo_doc_class->setcallback(ComboInputCB, this);
163     fl_end_form();
164     for (LyXTextClassList::const_iterator cit = textclasslist.begin();
165          cit != textclasslist.end(); ++cit)
166     {
167         combo_doc_class->addto((*cit).description());
168     }
169 #else
170     fl_clear_choice(class_->choice_doc_class);
171     for (LyXTextClassList::const_iterator cit = textclasslist.begin();
172          cit != textclasslist.end(); ++cit)
173     {
174         fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
175     }
176 #endif
177     fl_addto_choice(class_->choice_doc_spacing,
178                     _(" Single | OneHalf | Double | Other "));
179     fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
180    for (n=0; tex_fonts[n][0]; ++n) {
181         fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
182     }
183     fl_addto_choice(class_->choice_doc_pagestyle,
184                     "default|empty|plain|headings|fancy");
185     fl_addto_choice(class_->choice_doc_skip,
186                     _(" Smallskip | Medskip | Bigskip | Length "));
187     fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
188     fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
189     fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
190
191     bc_.addReadOnly (class_->radio_doc_indent);
192     bc_.addReadOnly (class_->radio_doc_skip);
193 #ifndef USE_CLASS_COMBO
194     bc_.addReadOnly (class_->choice_doc_class);
195 #endif
196     bc_.addReadOnly (class_->choice_doc_pagestyle);
197     bc_.addReadOnly (class_->choice_doc_fonts);
198     bc_.addReadOnly (class_->choice_doc_fontsize);
199     bc_.addReadOnly (class_->radio_doc_sides_one);
200     bc_.addReadOnly (class_->radio_doc_sides_two);
201     bc_.addReadOnly (class_->radio_doc_columns_one);
202     bc_.addReadOnly (class_->radio_doc_columns_two);
203     bc_.addReadOnly (class_->input_doc_extra);
204     bc_.addReadOnly (class_->input_doc_skip);
205     bc_.addReadOnly (class_->choice_doc_skip);
206     bc_.addReadOnly (class_->choice_doc_spacing);
207     bc_.addReadOnly (class_->input_doc_spacing);
208
209     // the document language form
210     language_ = build_doc_language();
211     fl_addto_choice(language_->choice_inputenc,
212                     "default|auto|latin1|latin2|latin5"
213                     "|koi8-r|koi8-u|cp866|cp1251|iso88595");
214
215     // The language is a combo-box and has to be inserted manually
216     obj = language_->choice_language;
217     fl_addto_form(language_->form);
218     combo_language = new Combox(FL_COMBOX_DROPLIST);
219     combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
220                         dialog_->tabbed_folder);
221     combo_language->shortcut("#L",1);
222     combo_language->setcallback(ComboInputCB, this);
223     fl_end_form();
224     // "default" is not part of the languages array any more.
225 #ifdef DO_USE_DEFAULT_LANGUAGE
226     combo_language->addto("default");
227 #endif
228     for (Languages::const_iterator cit = languages.begin();
229         cit != languages.end(); ++cit) {
230         combo_language->addto((*cit).second.lang());
231     }
232
233     fl_addto_choice(language_->choice_quotes_language,
234                     _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
235                       " «text» | »text« "));
236
237     bc_.addReadOnly (language_->choice_language);
238     bc_.addReadOnly (language_->choice_inputenc);
239
240     // the document options form
241     options_ = build_doc_options();
242     fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
243     fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
244     fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
245     fl_set_counter_step(options_->slider_secnumdepth,1,1);
246     fl_set_counter_step(options_->slider_tocdepth,1,1);
247     fl_set_counter_precision(options_->slider_secnumdepth, 0);
248     fl_set_counter_precision(options_->slider_tocdepth, 0);
249     for (n=0; tex_graphics[n][0]; ++n) {
250         fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
251     }
252
253     bc_.addReadOnly (options_->slider_secnumdepth);
254     bc_.addReadOnly (options_->slider_tocdepth);
255     bc_.addReadOnly (options_->check_use_amsmath);
256     bc_.addReadOnly (options_->input_float_placement);
257     bc_.addReadOnly (options_->choice_postscript_driver);
258
259     // the document bullets form
260     bullets_ = build_doc_bullet();
261     fl_addto_choice(bullets_->choice_bullet_size,
262                     _(" default | tiny | script | footnote | small |"
263                       " normal | large | Large | LARGE | huge | Huge"));
264     fl_set_choice(bullets_->choice_bullet_size, 1);
265     fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
266     fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
267
268     bc_.addReadOnly (bullets_->bmtable_bullet_panel);
269     bc_.addReadOnly (bullets_->choice_bullet_size);
270     bc_.addReadOnly (bullets_->input_bullet_latex);
271
272     fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
273                        class_->form);
274     fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
275                        paper_->form);
276     fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
277                        language_->form);
278     fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
279                        options_->form);
280     fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
281                                  bullets_->form);
282     if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
283             lyxerr << _("Your version of libXpm is older than 4.7.\n"
284                         "The `bullet' tab of the document popup "
285                         "has been disabled") << '\n';
286         fl_deactivate_object(fbullet);
287         fl_set_object_lcol(fbullet, FL_INACTIVE);
288     }
289 }
290
291
292 void FormDocument::apply()
293 {
294     if (!lv_->view()->available() || !dialog_)
295         return;
296
297     bool redo = class_apply();
298     paper_apply();
299     redo = language_apply() || redo;
300     redo = options_apply() || redo;
301     bullets_apply();
302
303     if (redo) {
304             lv_->view()->redoCurrentBuffer();
305     }
306     lv_->buffer()->markDirty();
307     setMinibuffer(lv_, _("Document layout set"));
308 }
309
310
311 void FormDocument::cancel()
312 {
313     // this avoids confusion when reopening
314     BufferParams & param = lv_->buffer()->params;
315     param.temp_bullets[0] = param.user_defined_bullets[0];
316     param.temp_bullets[1] = param.user_defined_bullets[1];
317     param.temp_bullets[2] = param.user_defined_bullets[2];
318     param.temp_bullets[3] = param.user_defined_bullets[3];
319     hide();
320 }
321
322
323 void FormDocument::update()
324 {
325     if (!dialog_)
326         return;
327
328     checkReadOnly();
329
330     BufferParams const & params = lv_->buffer()->params;
331
332     class_update(params);
333     paper_update(params);
334     language_update(params);
335     options_update(params);
336     bullets_update(params);
337 }
338
339
340 bool FormDocument::input( FL_OBJECT * ob, long data )
341 {
342         State cb = static_cast<State>( data );
343
344         switch (cb) {
345         case CHECKCHOICECLASS:
346                 CheckChoiceClass(ob, 0);
347                 break;
348         case CHOICEBULLETSIZE:
349                 ChoiceBulletSize(ob, 0);
350                 break;
351         case INPUTBULLETLATEX:
352                 InputBulletLaTeX(ob, 0);
353                 break;
354         case BULLETDEPTH1:
355         case BULLETDEPTH2:
356         case BULLETDEPTH3:
357         case BULLETDEPTH4:
358                 BulletDepth(ob, cb);
359                 break;
360         case BULLETPANEL1:
361         case BULLETPANEL2:
362         case BULLETPANEL3:
363         case BULLETPANEL4:
364         case BULLETPANEL5:
365         case BULLETPANEL6:
366                 BulletPanel(ob, cb);
367                 break;
368         case BULLETBMTABLE:
369                 BulletBMTable(ob, 0);
370                 break;
371         default:
372                 break;
373         }
374         
375         switch (data) {
376         case INPUT:
377         case CHECKCHOICECLASS:
378         case CHOICEBULLETSIZE:
379         case INPUTBULLETLATEX:
380         case BULLETBMTABLE:
381                 return CheckDocumentInput(ob, 0);
382         default:
383                 break;
384         }
385
386         return true;
387 }
388
389
390 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
391 {
392     FormDocument * pre = static_cast<FormDocument*>(v);
393     if (combox == pre->combo_doc_class)
394         pre->CheckChoiceClass(0, 0);
395     pre->bc_.valid(pre->CheckDocumentInput(0,0));
396 }
397
398
399 bool FormDocument::class_apply()
400 {
401         bool redo = false;
402         BufferParams &params = lv_->buffer()->params;
403
404         // If default skip is a "Length" but there's no text in the
405         // input field, reset the kind to "Medskip", which is the default.
406         if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
407             !*(fl_get_input (class_->input_doc_skip))) {
408                 fl_set_choice (class_->choice_doc_skip, 2);
409         }
410         params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
411         params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
412         params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
413
414 #ifdef USE_CLASS_COMBO   
415         unsigned int const new_class = combo_doc_class->get() - 1;
416 #else
417         unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
418 #endif
419         if (params.textclass != new_class) {
420                 // try to load new_class
421                 if (textclasslist.Load(new_class)) {
422                         // successfully loaded
423                         redo = true;
424                         setMinibuffer(lv_, _("Converting document to new document class..."));
425                         CutAndPaste cap;
426                         int ret = cap.SwitchLayoutsBetweenClasses(
427                             params.textclass, new_class,
428                             lv_->buffer()->paragraph);
429                         if (ret) {
430                                 string s;
431                                 if (ret==1) {
432                                         s = _("One paragraph couldn't be converted");
433                                 } else {
434                                         s += tostr(ret);
435                                         s += _(" paragraphs couldn't be converted");
436                                 }
437                                 WriteAlert(_("Conversion Errors!"),s,
438                                            _("into chosen document class"));
439                         }
440                         
441                         params.textclass = new_class;
442                 } else {
443                         // problem changing class -- warn user and retain old style
444                         WriteAlert(_("Conversion Errors!"),
445                                    _("Errors loading new document class."),
446                                    _("Reverting to original document class."));
447 #ifdef USE_CLASS_COMBO
448                         combo_doc_class->select(int(params.textclass) + 1);
449 #else
450                         fl_set_choice(class_->choice_doc_class,
451                                       params.textclass + 1);
452 #endif
453                 }
454         }
455         BufferParams::PARSEP tmpsep = params.paragraph_separation;
456         if (fl_get_button(class_->radio_doc_indent))
457                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
458         else
459                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
460         if (tmpsep != params.paragraph_separation)
461                 redo = true;
462         
463         VSpace tmpdefskip = params.getDefSkip();
464         switch (fl_get_choice (class_->choice_doc_skip)) {
465         case 1:
466                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
467                 break;
468         case 2:
469                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
470                 break;
471     case 3:
472             params.setDefSkip(VSpace(VSpace::BIGSKIP));
473             break;
474         case 4:
475                 params.setDefSkip
476                         (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
477                 break;
478                 // DocumentDefskipCB assures that this never happens
479         default:
480                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
481                 break;
482         }
483         if (!(tmpdefskip == params.getDefSkip()))
484                 redo = true;
485         
486         if (fl_get_button(class_->radio_doc_columns_two))
487                 params.columns = 2;
488         else
489                 params.columns = 1;
490         if (fl_get_button(class_->radio_doc_sides_two))
491                 params.sides = LyXTextClass::TwoSides;
492         else
493                 params.sides = LyXTextClass::OneSide;
494         
495         Spacing tmpSpacing = params.spacing;
496         switch (fl_get_choice(class_->choice_doc_spacing)) {
497         case 1:
498                 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
499                 params.spacing.set(Spacing::Single);
500                 break;
501         case 2:
502                 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
503                 params.spacing.set(Spacing::Onehalf);
504                 break;
505         case 3:
506                 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
507                 params.spacing.set(Spacing::Double);
508                 break;
509         case 4:
510                 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
511                 params.spacing.set(Spacing::Other, 
512                                    fl_get_input(class_->input_doc_spacing));
513                 break;
514         }
515         if (tmpSpacing != params.spacing)
516                 redo = true;
517         
518         params.options = fl_get_input(class_->input_doc_extra);
519         
520         return redo;
521 }
522
523
524 void FormDocument::paper_apply()
525 {
526     BufferParams & params = lv_->buffer()->params;
527     
528     params.papersize2 =
529             static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
530     params.paperpackage =
531             static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
532     params.use_geometry = fl_get_button(paper_->push_use_geometry);
533     if (fl_get_button(paper_->radio_landscape))
534         params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
535     else
536         params.orientation = BufferParams::ORIENTATION_PORTRAIT;
537     params.paperwidth = fl_get_input(paper_->input_custom_width);
538     params.paperheight = fl_get_input(paper_->input_custom_height);
539     params.leftmargin = fl_get_input(paper_->input_left_margin);
540     params.topmargin = fl_get_input(paper_->input_top_margin);
541     params.rightmargin = fl_get_input(paper_->input_right_margin);
542     params.bottommargin = fl_get_input(paper_->input_bottom_margin);
543     params.headheight = fl_get_input(paper_->input_head_height);
544     params.headsep = fl_get_input(paper_->input_head_sep);
545     params.footskip = fl_get_input(paper_->input_foot_skip);
546     lv_->buffer()->setPaperStuff();
547 }
548
549
550 bool FormDocument::language_apply()
551 {
552     BufferParams & params = lv_->buffer()->params;
553     InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
554     bool redo = false;
555
556     switch (fl_get_choice(language_->choice_quotes_language) - 1) {
557     case 0:
558         lga = InsetQuotes::EnglishQ;
559         break;
560     case 1:
561         lga = InsetQuotes::SwedishQ;
562         break;
563     case 2:
564         lga = InsetQuotes::GermanQ;
565         break;
566     case 3:
567         lga = InsetQuotes::PolishQ;
568                 break;
569     case 4:
570         lga = InsetQuotes::FrenchQ;
571         break;
572     case 5:
573         lga = InsetQuotes::DanishQ;
574         break;
575     }
576     params.quotes_language = lga;
577     if (fl_get_button(language_->radio_single))   
578         params.quotes_times = InsetQuotes::SingleQ;
579     else
580         params.quotes_times = InsetQuotes::DoubleQ;
581
582     Language const * old_language = params.language;
583     Language const * new_language = 
584             languages.getLanguage(combo_language->getline());
585     if (!new_language)
586         new_language = default_language;
587
588     if (old_language != new_language
589         && old_language->RightToLeft() == new_language->RightToLeft()
590         && !lv_->buffer()->isMultiLingual())
591         lv_->buffer()->ChangeLanguage(old_language, new_language);
592     if (old_language != new_language) {
593         redo = true;
594     }
595     params.language = new_language;
596     params.inputenc = fl_get_choice_text(language_->choice_inputenc);
597
598     return redo;
599 }
600
601
602 bool FormDocument::options_apply()
603 {
604     BufferParams & params = lv_->buffer()->params;
605     bool redo = false;
606
607     params.graphicsDriver =
608         fl_get_choice_text(options_->choice_postscript_driver);
609     params.use_amsmath = fl_get_button(options_->check_use_amsmath);
610
611     int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
612     if (params.secnumdepth != tmpchar)
613         redo = true;
614     params.secnumdepth = tmpchar;
615    
616     params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
617
618     params.float_placement =
619         fl_get_input(options_->input_float_placement);
620
621     return redo;
622 }
623
624
625 void FormDocument::bullets_apply()
626 {
627     /* update the bullet settings */
628     BufferParams & param = lv_->buffer()->params;
629     
630     // a little bit of loop unrolling
631     param.user_defined_bullets[0] = param.temp_bullets[0];
632     param.user_defined_bullets[1] = param.temp_bullets[1];
633     param.user_defined_bullets[2] = param.temp_bullets[2];
634     param.user_defined_bullets[3] = param.temp_bullets[3];
635 }
636
637
638 void FormDocument::class_update(BufferParams const & params)
639 {
640     if (!class_)
641         return;
642
643     LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
644
645 #ifdef USE_CLASS_COMBO
646     combo_doc_class->select_text(
647         textclasslist.DescOfClass(params.textclass));
648 #else   
649     fl_set_choice_text(class_->choice_doc_class, 
650                        textclasslist.DescOfClass(params.textclass).c_str());
651 #endif
652     fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
653     fl_clear_choice(class_->choice_doc_fontsize);
654     fl_addto_choice(class_->choice_doc_fontsize, "default");
655     fl_addto_choice(class_->choice_doc_fontsize,
656                     tclass.opt_fontsize().c_str());
657     fl_set_choice(class_->choice_doc_fontsize,
658                   tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
659     fl_clear_choice(class_->choice_doc_pagestyle);
660     fl_addto_choice(class_->choice_doc_pagestyle, "default");
661     fl_addto_choice(class_->choice_doc_pagestyle,
662                     tclass.opt_pagestyle().c_str());
663     fl_set_choice(class_->choice_doc_pagestyle,
664                   tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
665     fl_set_button(class_->radio_doc_indent, 0);
666     fl_set_button(class_->radio_doc_skip, 0);
667     if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
668         fl_set_button(class_->radio_doc_indent, 1);
669     else
670         fl_set_button(class_->radio_doc_skip, 1);
671     switch (params.getDefSkip().kind()) {
672     case VSpace::SMALLSKIP: 
673         fl_set_choice (class_->choice_doc_skip, 1);
674         break;
675     case VSpace::MEDSKIP: 
676         fl_set_choice (class_->choice_doc_skip, 2);
677         break;
678     case VSpace::BIGSKIP: 
679         fl_set_choice (class_->choice_doc_skip, 3);
680         break;
681     case VSpace::LENGTH: 
682         fl_set_choice (class_->choice_doc_skip, 4);
683         fl_set_input (class_->input_doc_skip,
684                       params.getDefSkip().asLyXCommand().c_str());
685         break;
686     default:
687         fl_set_choice (class_->choice_doc_skip, 2);
688         break;
689     }
690     fl_set_button(class_->radio_doc_sides_one, 0);
691     fl_set_button(class_->radio_doc_sides_two, 0);
692     if (params.sides == LyXTextClass::TwoSides)
693         fl_set_button(class_->radio_doc_sides_two, 1);
694     else
695         fl_set_button(class_->radio_doc_sides_one, 1);
696     fl_set_button(class_->radio_doc_columns_one, 0);
697     fl_set_button(class_->radio_doc_columns_two, 0);
698     if (params.columns == 2)
699         fl_set_button(class_->radio_doc_columns_two, 1);
700     else
701         fl_set_button(class_->radio_doc_columns_one, 1);
702     fl_set_input(class_->input_doc_spacing, "");
703     switch (params.spacing.getSpace()) {
704     case Spacing::Default: // nothing bad should happen with this
705     case Spacing::Single:
706         // \singlespacing
707         fl_set_choice(class_->choice_doc_spacing, 1);
708         break;
709     case Spacing::Onehalf:
710         // \onehalfspacing
711         fl_set_choice(class_->choice_doc_spacing, 2);
712         break;
713     case Spacing::Double:
714         // \doublespacing
715         fl_set_choice(class_->choice_doc_spacing, 3);
716         break;
717     case Spacing::Other:
718         {
719             fl_set_choice(class_->choice_doc_spacing, 4);
720             char sval[20];
721             sprintf(sval,"%g",params.spacing.getValue()); 
722             fl_set_input(class_->input_doc_spacing, sval);
723             break;
724         }
725     }
726     if (!params.options.empty())
727         fl_set_input(class_->input_doc_extra, params.options.c_str());
728     else
729         fl_set_input(class_->input_doc_extra, "");
730 }
731
732
733 void FormDocument::language_update(BufferParams const & params)
734 {
735     if (!language_)
736         return;
737
738     combo_language->select_text(params.language->lang());
739     fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
740     fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
741     fl_set_button(language_->radio_single, 0);
742     fl_set_button(language_->radio_double, 0);
743     if (params.quotes_times == InsetQuotes::SingleQ)
744         fl_set_button(language_->radio_single, 1);
745     else
746         fl_set_button(language_->radio_double, 1);
747 }
748
749
750 void FormDocument::options_update(BufferParams const & params)
751 {
752     if (!options_)
753         return;
754
755     fl_set_choice_text(options_->choice_postscript_driver,
756                        params.graphicsDriver.c_str());
757     fl_set_button(options_->check_use_amsmath, params.use_amsmath);
758     fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
759     fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
760     if (!params.float_placement.empty())
761         fl_set_input(options_->input_float_placement,
762                      params.float_placement.c_str());
763     else
764         fl_set_input(options_->input_float_placement, "");
765 }
766
767
768 void FormDocument::paper_update(BufferParams const & params)
769 {
770     if (!paper_)
771         return;
772
773     fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
774     fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
775     fl_set_button(paper_->push_use_geometry, params.use_geometry);
776     fl_set_button(paper_->radio_portrait, 0);
777     fl_set_button(paper_->radio_landscape, 0);
778     if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
779         fl_set_button(paper_->radio_landscape, 1);
780     else
781         fl_set_button(paper_->radio_portrait, 1);
782     fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
783     fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
784     fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
785     fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
786     fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
787     fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
788     fl_set_input(paper_->input_head_height, params.headheight.c_str());
789     fl_set_input(paper_->input_head_sep, params.headsep.c_str());
790     fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
791     fl_set_focus_object(paper_->form, paper_->choice_papersize2);
792 }
793
794
795 void FormDocument::bullets_update(BufferParams const & params)
796 {
797     if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
798         return;
799
800     if (lv_->buffer()->isLinuxDoc()) {
801         fl_deactivate_object(fbullet);
802         fl_set_object_lcol(fbullet, FL_INACTIVE);
803         return;
804     } else {
805         fl_activate_object(fbullet);
806         fl_set_object_lcol(fbullet, FL_BLACK);
807     }
808
809     fl_set_button(bullets_->radio_bullet_depth_1, 1);
810     fl_set_input(bullets_->input_bullet_latex,
811                  params.user_defined_bullets[0].getText().c_str());
812     fl_set_choice(bullets_->choice_bullet_size,
813                   params.user_defined_bullets[0].getSize() + 2);
814 }
815
816
817 void FormDocument::checkReadOnly()
818 {
819     if (bc_.readOnly(lv_->buffer()->isReadonly())) {
820         combo_doc_class->deactivate();
821         combo_language->deactivate();
822         fl_set_object_label(dialog_->text_warning,
823                             _("Document is read-only."
824                               " No changes to layout permitted."));
825         fl_show_object(dialog_->text_warning);
826     } else {
827         combo_doc_class->activate();
828         combo_language->activate();
829         fl_hide_object(dialog_->text_warning);
830     }   
831 }
832
833
834 void FormDocument::checkMarginValues()
835 {
836     int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
837                 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
838                 !strlen(fl_get_input(paper_->input_left_margin)) &&
839                 !strlen(fl_get_input(paper_->input_right_margin)) &&
840                 !strlen(fl_get_input(paper_->input_head_height)) &&
841                 !strlen(fl_get_input(paper_->input_head_sep)) &&
842                 !strlen(fl_get_input(paper_->input_foot_skip)) &&
843                 !strlen(fl_get_input(paper_->input_custom_width)) &&
844                 !strlen(fl_get_input(paper_->input_custom_height)));
845     if (!allEmpty)
846         fl_set_button(paper_->push_use_geometry, 1);
847 }
848
849 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
850 {
851     string str;
852     int val;
853     bool ok = true;
854     char const * input;
855     
856     checkMarginValues();
857     if (ob == paper_->choice_papersize2) {
858         val = fl_get_choice(paper_->choice_papersize2)-1;
859         if (val == BufferParams::VM_PAPER_DEFAULT) {
860             fl_set_button(paper_->push_use_geometry, 0);
861             checkMarginValues();
862         } else {
863             if ((val != BufferParams::VM_PAPER_USLETTER) &&
864                 (val != BufferParams::VM_PAPER_USLEGAL) &&
865                 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
866                 (val != BufferParams::VM_PAPER_A4) &&
867                 (val != BufferParams::VM_PAPER_A5) &&
868                 (val != BufferParams::VM_PAPER_B5)) {
869                 fl_set_button(paper_->push_use_geometry, 1);
870             }
871             fl_set_choice(paper_->choice_paperpackage,
872                           BufferParams::PACKAGE_NONE + 1);
873         }
874     } else if (ob == paper_->choice_paperpackage) {
875         val = fl_get_choice(paper_->choice_paperpackage)-1;
876         if (val != BufferParams::PACKAGE_NONE) {
877             fl_set_choice(paper_->choice_papersize2,
878                           BufferParams::VM_PAPER_DEFAULT + 1);
879             fl_set_button(paper_->push_use_geometry, 0);
880         }
881     } else if (ob == class_->input_doc_spacing) {
882         input = fl_get_input(class_->input_doc_spacing);
883         if (!*input) {
884             fl_set_choice (class_->choice_doc_spacing, 1);
885         } else {
886             fl_set_choice(class_->choice_doc_spacing, 4);
887         }
888     }
889     // this has to be all out of if/elseif because it has to deactivate
890     // the document buttons and so the whole stuff has to be tested again.
891     str = fl_get_input(paper_->input_custom_width);
892     ok = ok && (str.empty() || isValidLength(str));
893     str = fl_get_input(paper_->input_custom_height);
894     ok = ok && (str.empty() || isValidLength(str));
895     str = fl_get_input(paper_->input_left_margin);
896     ok = ok && (str.empty() || isValidLength(str));
897     str = fl_get_input(paper_->input_right_margin);
898     ok = ok && (str.empty() || isValidLength(str));
899     str = fl_get_input(paper_->input_top_margin);
900     ok = ok && (str.empty() || isValidLength(str));
901     str = fl_get_input(paper_->input_bottom_margin);
902     ok = ok && (str.empty() || isValidLength(str));
903     str = fl_get_input(paper_->input_head_height);
904     ok = ok && (str.empty() || isValidLength(str));
905     str = fl_get_input(paper_->input_head_sep);
906     ok = ok && (str.empty() || isValidLength(str));
907     str = fl_get_input(paper_->input_foot_skip);
908     ok = ok && (str.empty() || isValidLength(str));
909     // "Synchronize" the choice and the input field, so that it
910     // is impossible to commit senseless data.
911     input = fl_get_input (class_->input_doc_skip);
912     if (ob == class_->input_doc_skip) {
913         if (!*input) {
914             fl_set_choice (class_->choice_doc_skip, 2);
915         } else if (isValidGlueLength (input)) {
916             fl_set_choice (class_->choice_doc_skip, 4);
917         } else {
918             fl_set_choice(class_->choice_doc_skip, 4);
919             ok = false;
920         }
921     } else {
922         if (*input && !isValidGlueLength(input))
923             ok = false;
924     }
925     if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
926         ok = false;
927     else if (fl_get_choice(class_->choice_doc_skip) != 4)
928         fl_set_input (class_->input_doc_skip, "");
929
930     input = fl_get_input(class_->input_doc_spacing);
931     if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
932         ok = false;
933     else  if (fl_get_choice(class_->choice_doc_spacing) != 4)
934         fl_set_input (class_->input_doc_spacing, "");
935     return ok;
936 }
937
938
939 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
940 {
941     BufferParams & param = lv_->buffer()->params;
942
943     // convert from 1-6 range to -1-4 
944     param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
945     fl_set_input(bullets_->input_bullet_latex,
946                  param.temp_bullets[current_bullet_depth].getText().c_str());
947 }
948
949
950 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
951 {
952     BufferParams & param = lv_->buffer()->params;
953
954     param.temp_bullets[current_bullet_depth].
955         setText(fl_get_input(bullets_->input_bullet_latex));
956 }
957
958
959 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
960 {
961     /* Should I do the following:                                 */
962     /*  1. change to the panel that the current bullet belongs in */
963     /*  2. show that bullet as selected                           */
964     /*  3. change the size setting to the size of the bullet in Q.*/
965     /*  4. display the latex equivalent in the latex box          */
966     /*                                                            */
967     /* I'm inclined to just go with 3 and 4 at the moment and     */
968     /* maybe try to support the others later                      */
969     BufferParams & param = lv_->buffer()->params;
970
971     int data = 0;
972     if (cb == BULLETDEPTH1 )
973             data = 0;
974     else if (cb == BULLETDEPTH2 )
975             data = 1;
976     else if (cb == BULLETDEPTH3 )
977             data = 2;
978     else if (cb == BULLETDEPTH4 )
979             data = 3;
980
981     switch (fl_get_button_numb(ob)) {
982     case 3:
983             // right mouse button resets to default
984         param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
985     default:
986         current_bullet_depth = data;
987         fl_set_input(bullets_->input_bullet_latex,
988                      param.temp_bullets[data].getText().c_str());
989         fl_set_choice(bullets_->choice_bullet_size,
990                       param.temp_bullets[data].getSize() + 2);
991     }
992 }
993
994
995 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
996 {
997     /* Here we have to change the background pixmap to that selected */
998     /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
999     
1000     int data = 0;
1001     if (cb == BULLETPANEL1 )
1002             data = 0;
1003     else if (cb == BULLETPANEL2 )
1004             data = 1;
1005     else if (cb == BULLETPANEL3 )
1006             data = 2;
1007     else if (cb == BULLETPANEL4 )
1008             data = 3;
1009     else if (cb == BULLETPANEL5 )
1010             data = 4;
1011     else if (cb == BULLETPANEL6 )
1012             data = 5;
1013
1014     if (data != current_bullet_panel) {
1015         fl_freeze_form(bullets_->form);
1016         current_bullet_panel = data;
1017
1018         /* free the current pixmap */
1019         fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1020         string new_panel;
1021         switch (cb) {
1022             /* display the new one */
1023         case BULLETPANEL1 :
1024             new_panel = "standard";
1025             break;
1026         case BULLETPANEL2 :
1027             new_panel = "amssymb";
1028             break;
1029         case BULLETPANEL3 :
1030             new_panel = "psnfss1";
1031             break;
1032         case BULLETPANEL4 :
1033             new_panel = "psnfss2";
1034             break;
1035         case BULLETPANEL5 :
1036             new_panel = "psnfss3";
1037             break;
1038         case BULLETPANEL6 :
1039             new_panel = "psnfss4";
1040             break;
1041         default :
1042             /* something very wrong happened */
1043             // play it safe for now but should be an exception
1044             current_bullet_panel = 0;  // standard panel
1045             new_panel = "standard";
1046             break;
1047         }
1048         new_panel += ".xpm";
1049         fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1050                                    LibFileSearch("images", new_panel).c_str());
1051         fl_redraw_object(bullets_->bmtable_bullet_panel);
1052         fl_unfreeze_form(bullets_->form);
1053     }
1054 }
1055
1056
1057 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1058 {
1059     /* handle the user input by setting the current bullet depth's pixmap */
1060     /* to that extracted from the current chosen position of the BMTable  */
1061     /* Don't forget to free the button's old pixmap first.                */
1062
1063     BufferParams & param = lv_->buffer()->params;
1064     int bmtable_button = fl_get_bmtable(ob);
1065
1066     /* try to keep the button held down till another is pushed */
1067     /*  fl_set_bmtable(ob, 1, bmtable_button); */
1068     param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1069     param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1070     fl_set_input(bullets_->input_bullet_latex,
1071                  param.temp_bullets[current_bullet_depth].getText().c_str());
1072 }
1073
1074
1075 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1076 {
1077     if (!ob)
1078         ob = class_->choice_doc_class;
1079
1080     ProhibitInput(lv_->view());
1081
1082 #ifdef USE_CLASS_COMBO
1083     int tc = combo_doc_class->get() - 1;
1084     string tct = combo_doc_class->getline();
1085 #else
1086     int tc = fl_get_choice(ob) - 1;
1087     string tct = fl_get_choice_text(ob);
1088 #endif
1089     if (textclasslist.Load(tc)) {
1090         if (AskQuestion(_("Should I set some parameters to"), tct,
1091                         _("the defaults of this document class?"))) {
1092             BufferParams & params = lv_->buffer()->params;
1093
1094             params.textclass = tc;
1095             params.useClassDefaults();
1096             UpdateLayoutDocument(params);
1097         }
1098     } else {
1099         // unable to load new style
1100         WriteAlert(_("Conversion Errors!"),
1101                    _("Unable to switch to new document class."),
1102                    _("Reverting to original document class."));
1103 #ifdef USE_CLASS_COMBO
1104         combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1105 #else
1106         fl_set_choice(class_->choice_doc_class, 
1107                       lv_->buffer()->params.textclass + 1);
1108 #endif
1109     }
1110     AllowInput(lv_->view());
1111 }
1112
1113
1114 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1115 {
1116     if (!dialog_)
1117         return;
1118
1119     checkReadOnly();
1120     class_update(params);
1121     paper_update(params);
1122     language_update(params);
1123     options_update(params);
1124     bullets_update(params);
1125 }