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