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