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