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