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