1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
10 *======================================================*/
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
18 #pragma implementation
21 #include "lyx_gui_misc.h"
23 #include "FormDocument.h"
24 #include "form_document.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
39 #include "BufferView.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "xforms_helpers.h"
47 using Liason::setMinibuffer;
50 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
51 : FormBaseBD(lv, d, _("Document Layout")),
52 ActCell(0), Confirmed(0),
53 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
55 // let the dialog be shown
56 // This is a permanent connection so we won't bother
57 // storing a copy because we won't be disconnecting.
58 d->showDocument.connect(slot(this, &FormDocument::show));
62 void FormDocument::redraw()
64 if( form() && form()->visible )
65 fl_redraw_form( form() );
69 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
70 if (outer_form && outer_form->visible)
71 fl_redraw_form( outer_form );
75 FL_FORM * FormDocument::form() const
77 if (dialog_.get()) return dialog_->form;
82 void FormDocument::build()
87 dialog_.reset(build_tabbed_document());
89 // Manage the restore, ok, apply, restore and cancel/close buttons
90 bc().setOK(dialog_->button_ok);
91 bc().setApply(dialog_->button_apply);
92 bc().setCancel(dialog_->button_cancel);
93 bc().setRestore(dialog_->button_restore);
94 bc().addReadOnly (dialog_->button_save_defaults);
95 bc().addReadOnly (dialog_->button_reset_defaults);
97 // the document paper form
98 paper_.reset(build_doc_paper());
99 fl_addto_choice(paper_->choice_papersize2,
100 _(" Default | Custom | USletter | USlegal "
101 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
102 fl_addto_choice(paper_->choice_paperpackage,
104 "| A4 small Margins (only portrait) "
105 "| A4 very small Margins (only portrait) "
106 "| A4 very wide margins (only portrait) "));
107 setEnabled(paper_->choice_paperpackage, true);
109 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
119 bc().addReadOnly (paper_->choice_paperpackage);
120 bc().addReadOnly (paper_->greoup_radio_orientation);
121 bc().addReadOnly (paper_->radio_portrait);
122 bc().addReadOnly (paper_->radio_landscape);
123 bc().addReadOnly (paper_->choice_papersize2);
124 bc().addReadOnly (paper_->push_use_geometry);
125 bc().addReadOnly (paper_->input_custom_width);
126 bc().addReadOnly (paper_->input_custom_height);
127 bc().addReadOnly (paper_->input_top_margin);
128 bc().addReadOnly (paper_->input_bottom_margin);
129 bc().addReadOnly (paper_->input_left_margin);
130 bc().addReadOnly (paper_->input_right_margin);
131 bc().addReadOnly (paper_->input_head_height);
132 bc().addReadOnly (paper_->input_head_sep);
133 bc().addReadOnly (paper_->input_foot_skip);
135 // the document class form
136 class_.reset(build_doc_class());
139 // The language is a combo-box and has to be inserted manually
140 obj = class_->choice_doc_class;
141 fl_deactivate_object(obj);
142 fl_addto_form(class_->form);
143 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
144 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
145 dialog_->tabbed_folder);
146 combo_doc_class->shortcut("#C",1);
147 combo_doc_class->setcallback(ComboInputCB, this);
149 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
150 cit != textclasslist.end(); ++cit)
152 combo_doc_class->addto(cit->description());
155 fl_addto_choice(class_->choice_doc_spacing,
156 _(" Single | OneHalf | Double | Other "));
157 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
158 for (n=0; tex_fonts[n][0]; ++n) {
159 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
161 fl_addto_choice(class_->choice_doc_pagestyle,
162 "default|empty|plain|headings|fancy");
163 fl_addto_choice(class_->choice_doc_skip,
164 _(" Smallskip | Medskip | Bigskip | Length "));
165 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
166 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
167 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
169 bc().addReadOnly (class_->radio_doc_indent);
170 bc().addReadOnly (class_->radio_doc_skip);
172 bc().addReadOnly (class_->choice_doc_pagestyle);
173 bc().addReadOnly (class_->choice_doc_fonts);
174 bc().addReadOnly (class_->choice_doc_fontsize);
175 bc().addReadOnly (class_->radio_doc_sides_one);
176 bc().addReadOnly (class_->radio_doc_sides_two);
177 bc().addReadOnly (class_->radio_doc_columns_one);
178 bc().addReadOnly (class_->radio_doc_columns_two);
179 bc().addReadOnly (class_->input_doc_extra);
180 bc().addReadOnly (class_->input_doc_skip);
181 bc().addReadOnly (class_->choice_doc_skip);
182 bc().addReadOnly (class_->choice_doc_spacing);
183 bc().addReadOnly (class_->input_doc_spacing);
186 // the document language form
187 language_.reset(build_doc_language());
188 fl_addto_choice(language_->choice_inputenc,
189 "default|auto|latin1|latin2|latin5|latin9"
190 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
192 // The language is a combo-box and has to be inserted manually
193 obj = language_->choice_language;
194 fl_deactivate_object(obj);
195 fl_addto_form(language_->form);
196 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
197 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
198 dialog_->tabbed_folder);
199 combo_language->shortcut("#L",1);
200 combo_language->setcallback(ComboInputCB, this);
203 for (Languages::const_iterator cit = languages.begin();
204 cit != languages.end(); ++cit) {
205 combo_language->addto(cit->second.lang());
208 fl_addto_choice(language_->choice_quotes_language,
209 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
210 " «text» | »text« "));
212 bc().addReadOnly (language_->choice_inputenc);
213 bc().addReadOnly (language_->choice_quotes_language);
214 bc().addReadOnly (language_->radio_single);
215 bc().addReadOnly (language_->radio_double);
217 // the document options form
218 options_.reset(build_doc_options());
219 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
220 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
221 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
222 fl_set_counter_step(options_->slider_secnumdepth,1,1);
223 fl_set_counter_step(options_->slider_tocdepth,1,1);
224 fl_set_counter_precision(options_->slider_secnumdepth, 0);
225 fl_set_counter_precision(options_->slider_tocdepth, 0);
226 for (n=0; tex_graphics[n][0]; ++n) {
227 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
229 fl_addto_choice(options_->choice_citation_format,
230 _(" Author-year | Numerical "));
232 bc_.addReadOnly (options_->slider_secnumdepth);
233 bc_.addReadOnly (options_->slider_tocdepth);
234 bc_.addReadOnly (options_->check_use_amsmath);
235 bc_.addReadOnly (options_->check_use_natbib);
236 bc_.addReadOnly (options_->choice_citation_format);
237 bc_.addReadOnly (options_->input_float_placement);
238 bc_.addReadOnly (options_->choice_postscript_driver);
240 // the document bullets form
241 bullets_.reset(build_doc_bullet());
242 fl_addto_choice(bullets_->choice_bullet_size,
243 _(" default | tiny | script | footnote | small |"
244 " normal | large | Large | LARGE | huge | Huge"));
245 fl_set_choice(bullets_->choice_bullet_size, 1);
246 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
247 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
249 bc().addReadOnly (bullets_->bmtable_bullet_panel);
250 bc().addReadOnly (bullets_->choice_bullet_size);
251 bc().addReadOnly (bullets_->input_bullet_latex);
252 bc().addReadOnly (bullets_->radio_bullet_depth);
253 bc().addReadOnly (bullets_->radio_bullet_panel);
255 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
259 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
261 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
263 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
265 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
266 lyxerr << _("Your version of libXpm is older than 4.7.\n"
267 "The `bullet' tab of the document dialog "
268 "has been disabled") << '\n';
269 fl_deactivate_object(fbullet);
270 fl_set_object_lcol(fbullet, FL_INACTIVE);
275 void FormDocument::apply()
277 if (!lv_->view()->available() || !dialog_.get())
280 bool redo = class_apply();
282 redo = language_apply() || redo;
283 redo = options_apply() || redo;
287 lv_->view()->redoCurrentBuffer();
289 lv_->buffer()->markDirty();
290 setMinibuffer(lv_, _("Document layout set"));
294 void FormDocument::cancel()
296 // this avoids confusion when reopening
297 BufferParams & param = lv_->buffer()->params;
298 param.temp_bullets[0] = param.user_defined_bullets[0];
299 param.temp_bullets[1] = param.user_defined_bullets[1];
300 param.temp_bullets[2] = param.user_defined_bullets[2];
301 param.temp_bullets[3] = param.user_defined_bullets[3];
306 void FormDocument::update()
313 BufferParams const & params = lv_->buffer()->params;
315 fl_set_object_label(dialog_->button_save_defaults,
316 _("Save as Defaults"));
317 fl_set_object_label(dialog_->button_reset_defaults,
319 setEnabled(dialog_->button_reset_defaults,
320 !params.hasClassDefaults());
322 class_update(params);
323 paper_update(params);
324 language_update(params);
325 options_update(params);
326 bullets_update(params);
330 bool FormDocument::input( FL_OBJECT * ob, long data )
332 State cb = static_cast<State>( data );
335 case CHECKCHOICECLASS:
336 CheckChoiceClass(ob, 0);
338 case CHOICEBULLETSIZE:
339 ChoiceBulletSize(ob, 0);
341 case INPUTBULLETLATEX:
342 InputBulletLaTeX(ob, 0);
359 BulletBMTable(ob, 0);
365 if (ob == options_->check_use_natbib) {
366 setEnabled(options_->choice_citation_format,
367 fl_get_button(options_->check_use_natbib));
370 if (ob == dialog_->button_save_defaults) {
371 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
374 if (ob == dialog_->button_reset_defaults) {
375 BufferParams params = lv_->buffer()->params;
376 params.textclass = combo_doc_class->get() - 1;
377 params.useClassDefaults();
378 UpdateLayoutDocument(params);
382 setEnabled(dialog_->button_reset_defaults,
383 lv_->buffer()->params.hasClassDefaults());
388 case CHECKCHOICECLASS:
389 case CHOICEBULLETSIZE:
390 case INPUTBULLETLATEX:
392 return CheckDocumentInput(ob, 0);
401 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
403 FormDocument * pre = static_cast<FormDocument*>(v);
404 if (combox == pre->combo_doc_class.get())
405 pre->CheckChoiceClass(0, 0);
406 pre->bc().valid(pre->CheckDocumentInput(0,0));
410 bool FormDocument::class_apply()
413 BufferParams ¶ms = lv_->buffer()->params;
415 // If default skip is a "Length" but there's no text in the
416 // input field, reset the kind to "Medskip", which is the default.
417 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
418 !*(fl_get_input (class_->input_doc_skip))) {
419 fl_set_choice (class_->choice_doc_skip, 2);
421 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
422 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
423 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
425 unsigned int const new_class = combo_doc_class->get() - 1;
427 if (params.textclass != new_class) {
428 // try to load new_class
429 if (textclasslist.Load(new_class)) {
430 // successfully loaded
432 setMinibuffer(lv_, _("Converting document to new document class..."));
433 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
434 params.textclass, new_class,
435 lv_->buffer()->paragraph);
439 s = _("One paragraph couldn't be converted");
442 s += _(" paragraphs couldn't be converted");
444 WriteAlert(_("Conversion Errors!"),s,
445 _("into chosen document class"));
448 params.textclass = new_class;
450 // problem changing class -- warn user and retain old style
451 WriteAlert(_("Conversion Errors!"),
452 _("Errors loading new document class."),
453 _("Reverting to original document class."));
454 combo_doc_class->select(int(params.textclass) + 1);
457 BufferParams::PARSEP tmpsep = params.paragraph_separation;
458 if (fl_get_button(class_->radio_doc_indent))
459 params.paragraph_separation = BufferParams::PARSEP_INDENT;
461 params.paragraph_separation = BufferParams::PARSEP_SKIP;
462 if (tmpsep != params.paragraph_separation)
465 VSpace tmpdefskip = params.getDefSkip();
466 switch (fl_get_choice (class_->choice_doc_skip)) {
468 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
471 params.setDefSkip(VSpace(VSpace::MEDSKIP));
474 params.setDefSkip(VSpace(VSpace::BIGSKIP));
478 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
480 // DocumentDefskipCB assures that this never happens
482 params.setDefSkip(VSpace(VSpace::MEDSKIP));
485 if (!(tmpdefskip == params.getDefSkip()))
488 if (fl_get_button(class_->radio_doc_columns_two))
492 if (fl_get_button(class_->radio_doc_sides_two))
493 params.sides = LyXTextClass::TwoSides;
495 params.sides = LyXTextClass::OneSide;
497 Spacing tmpSpacing = params.spacing;
498 switch (fl_get_choice(class_->choice_doc_spacing)) {
500 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
501 params.spacing.set(Spacing::Single);
504 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
505 params.spacing.set(Spacing::Onehalf);
508 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
509 params.spacing.set(Spacing::Double);
512 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
513 params.spacing.set(Spacing::Other,
514 fl_get_input(class_->input_doc_spacing));
517 if (tmpSpacing != params.spacing)
520 params.options = fl_get_input(class_->input_doc_extra);
526 void FormDocument::paper_apply()
528 BufferParams & params = lv_->buffer()->params;
531 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
532 params.paperpackage =
533 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
534 params.use_geometry = fl_get_button(paper_->push_use_geometry);
535 if (fl_get_button(paper_->radio_landscape))
536 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
538 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
539 params.paperwidth = fl_get_input(paper_->input_custom_width);
540 params.paperheight = fl_get_input(paper_->input_custom_height);
541 params.leftmargin = fl_get_input(paper_->input_left_margin);
542 params.topmargin = fl_get_input(paper_->input_top_margin);
543 params.rightmargin = fl_get_input(paper_->input_right_margin);
544 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
545 params.headheight = fl_get_input(paper_->input_head_height);
546 params.headsep = fl_get_input(paper_->input_head_sep);
547 params.footskip = fl_get_input(paper_->input_foot_skip);
548 lv_->buffer()->setPaperStuff();
552 bool FormDocument::language_apply()
554 BufferParams & params = lv_->buffer()->params;
555 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
558 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
560 lga = InsetQuotes::EnglishQ;
563 lga = InsetQuotes::SwedishQ;
566 lga = InsetQuotes::GermanQ;
569 lga = InsetQuotes::PolishQ;
572 lga = InsetQuotes::FrenchQ;
575 lga = InsetQuotes::DanishQ;
578 params.quotes_language = lga;
579 if (fl_get_button(language_->radio_single))
580 params.quotes_times = InsetQuotes::SingleQ;
582 params.quotes_times = InsetQuotes::DoubleQ;
584 Language const * old_language = params.language;
585 Language const * new_language =
586 languages.getLanguage(combo_language->getline());
588 new_language = default_language;
590 if (old_language != new_language
591 && old_language->RightToLeft() == new_language->RightToLeft()
592 && !lv_->buffer()->isMultiLingual())
593 lv_->buffer()->changeLanguage(old_language, new_language);
594 if (old_language != new_language) {
597 params.language = new_language;
598 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
604 bool FormDocument::options_apply()
606 BufferParams & params = lv_->buffer()->params;
609 params.graphicsDriver =
610 fl_get_choice_text(options_->choice_postscript_driver);
611 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
612 params.use_natbib = fl_get_button(options_->check_use_natbib);
613 params.use_numerical_citations =
614 fl_get_choice(options_->choice_citation_format)-1;
616 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
617 if (params.secnumdepth != tmpchar)
619 params.secnumdepth = tmpchar;
621 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
623 params.float_placement =
624 fl_get_input(options_->input_float_placement);
630 void FormDocument::bullets_apply()
632 /* update the bullet settings */
633 BufferParams & param = lv_->buffer()->params;
635 // a little bit of loop unrolling
636 param.user_defined_bullets[0] = param.temp_bullets[0];
637 param.user_defined_bullets[1] = param.temp_bullets[1];
638 param.user_defined_bullets[2] = param.temp_bullets[2];
639 param.user_defined_bullets[3] = param.temp_bullets[3];
643 void FormDocument::class_update(BufferParams const & params)
648 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
650 combo_doc_class->select(
651 textclasslist.DescOfClass(params.textclass));
652 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
653 fl_clear_choice(class_->choice_doc_fontsize);
654 fl_addto_choice(class_->choice_doc_fontsize, "default");
655 fl_addto_choice(class_->choice_doc_fontsize,
656 tclass.opt_fontsize().c_str());
657 fl_set_choice(class_->choice_doc_fontsize,
658 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
659 fl_clear_choice(class_->choice_doc_pagestyle);
660 fl_addto_choice(class_->choice_doc_pagestyle, "default");
661 fl_addto_choice(class_->choice_doc_pagestyle,
662 tclass.opt_pagestyle().c_str());
663 fl_set_choice(class_->choice_doc_pagestyle,
664 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
665 fl_set_button(class_->radio_doc_indent, 0);
666 fl_set_button(class_->radio_doc_skip, 0);
667 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
668 fl_set_button(class_->radio_doc_indent, 1);
670 fl_set_button(class_->radio_doc_skip, 1);
671 switch (params.getDefSkip().kind()) {
672 case VSpace::SMALLSKIP:
673 fl_set_choice (class_->choice_doc_skip, 1);
675 case VSpace::MEDSKIP:
676 fl_set_choice (class_->choice_doc_skip, 2);
678 case VSpace::BIGSKIP:
679 fl_set_choice (class_->choice_doc_skip, 3);
682 fl_set_choice (class_->choice_doc_skip, 4);
683 fl_set_input (class_->input_doc_skip,
684 params.getDefSkip().asLyXCommand().c_str());
687 fl_set_choice (class_->choice_doc_skip, 2);
690 fl_set_button(class_->radio_doc_sides_one, 0);
691 fl_set_button(class_->radio_doc_sides_two, 0);
692 if (params.sides == LyXTextClass::TwoSides)
693 fl_set_button(class_->radio_doc_sides_two, 1);
695 fl_set_button(class_->radio_doc_sides_one, 1);
696 fl_set_button(class_->radio_doc_columns_one, 0);
697 fl_set_button(class_->radio_doc_columns_two, 0);
698 if (params.columns == 2)
699 fl_set_button(class_->radio_doc_columns_two, 1);
701 fl_set_button(class_->radio_doc_columns_one, 1);
702 fl_set_input(class_->input_doc_spacing, "");
703 switch (params.spacing.getSpace()) {
704 case Spacing::Default: // nothing bad should happen with this
705 case Spacing::Single:
707 fl_set_choice(class_->choice_doc_spacing, 1);
709 case Spacing::Onehalf:
711 fl_set_choice(class_->choice_doc_spacing, 2);
713 case Spacing::Double:
715 fl_set_choice(class_->choice_doc_spacing, 3);
719 fl_set_choice(class_->choice_doc_spacing, 4);
721 sprintf(sval,"%g",params.spacing.getValue());
722 fl_set_input(class_->input_doc_spacing, sval);
726 if (!params.options.empty())
727 fl_set_input(class_->input_doc_extra, params.options.c_str());
729 fl_set_input(class_->input_doc_extra, "");
733 void FormDocument::language_update(BufferParams const & params)
735 if (!language_.get())
738 combo_language->select(params.language->lang());
739 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
740 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
741 fl_set_button(language_->radio_single, 0);
742 fl_set_button(language_->radio_double, 0);
743 if (params.quotes_times == InsetQuotes::SingleQ)
744 fl_set_button(language_->radio_single, 1);
746 fl_set_button(language_->radio_double, 1);
750 void FormDocument::options_update(BufferParams const & params)
755 fl_set_choice_text(options_->choice_postscript_driver,
756 params.graphicsDriver.c_str());
757 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
758 fl_set_button(options_->check_use_natbib, params.use_natbib);
759 fl_set_choice(options_->choice_citation_format,
760 int(params.use_numerical_citations)+1);
761 setEnabled(options_->choice_citation_format, params.use_natbib);
762 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
763 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
764 if (!params.float_placement.empty())
765 fl_set_input(options_->input_float_placement,
766 params.float_placement.c_str());
768 fl_set_input(options_->input_float_placement, "");
772 void FormDocument::paper_update(BufferParams const & params)
777 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
778 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
779 fl_set_button(paper_->push_use_geometry, params.use_geometry);
780 fl_set_button(paper_->radio_portrait, 0);
781 fl_set_button(paper_->radio_landscape, 0);
782 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
783 fl_set_button(paper_->radio_landscape, 1);
785 fl_set_button(paper_->radio_portrait, 1);
786 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
787 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
788 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
789 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
790 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
791 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
792 fl_set_input(paper_->input_head_height, params.headheight.c_str());
793 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
794 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
795 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
799 void FormDocument::bullets_update(BufferParams const & params)
801 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
804 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
805 setEnabled(fbullet, !isLinuxDoc);
807 if (isLinuxDoc) return;
809 fl_set_button(bullets_->radio_bullet_depth_1, 1);
810 fl_set_input(bullets_->input_bullet_latex,
811 params.user_defined_bullets[0].getText().c_str());
812 fl_set_choice(bullets_->choice_bullet_size,
813 params.user_defined_bullets[0].getSize() + 2);
817 void FormDocument::checkReadOnly()
819 if (bc().readOnly(lv_->buffer()->isReadonly())) {
820 combo_doc_class->deactivate();
821 combo_language->deactivate();
822 fl_set_object_label(dialog_->text_warning,
823 _("Document is read-only."
824 " No changes to layout permitted."));
825 fl_show_object(dialog_->text_warning);
827 combo_doc_class->activate();
828 combo_language->activate();
829 fl_hide_object(dialog_->text_warning);
834 void FormDocument::checkMarginValues()
836 bool const not_empty =
837 strlen(fl_get_input(paper_->input_top_margin)) ||
838 strlen(fl_get_input(paper_->input_bottom_margin)) ||
839 strlen(fl_get_input(paper_->input_left_margin)) ||
840 strlen(fl_get_input(paper_->input_right_margin)) ||
841 strlen(fl_get_input(paper_->input_head_height)) ||
842 strlen(fl_get_input(paper_->input_head_sep)) ||
843 strlen(fl_get_input(paper_->input_foot_skip)) ||
844 strlen(fl_get_input(paper_->input_custom_width)) ||
845 strlen(fl_get_input(paper_->input_custom_height));
847 fl_set_button(paper_->push_use_geometry, 1);
851 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
859 if (ob == paper_->choice_papersize2) {
860 val = fl_get_choice(paper_->choice_papersize2)-1;
861 if (val == BufferParams::VM_PAPER_DEFAULT) {
862 fl_set_button(paper_->push_use_geometry, 0);
865 if ((val != BufferParams::VM_PAPER_USLETTER) &&
866 (val != BufferParams::VM_PAPER_USLEGAL) &&
867 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
868 (val != BufferParams::VM_PAPER_A4) &&
869 (val != BufferParams::VM_PAPER_A5) &&
870 (val != BufferParams::VM_PAPER_B5)) {
871 fl_set_button(paper_->push_use_geometry, 1);
873 fl_set_choice(paper_->choice_paperpackage,
874 BufferParams::PACKAGE_NONE + 1);
876 } else if (ob == paper_->choice_paperpackage) {
877 val = fl_get_choice(paper_->choice_paperpackage)-1;
878 if (val != BufferParams::PACKAGE_NONE) {
879 fl_set_choice(paper_->choice_papersize2,
880 BufferParams::VM_PAPER_DEFAULT + 1);
881 fl_set_button(paper_->push_use_geometry, 0);
883 } else if (ob == class_->input_doc_spacing) {
884 input = fl_get_input(class_->input_doc_spacing);
886 fl_set_choice (class_->choice_doc_spacing, 1);
888 fl_set_choice(class_->choice_doc_spacing, 4);
891 // this has to be all out of if/elseif because it has to deactivate
892 // the document buttons and so the whole stuff has to be tested again.
893 str = fl_get_input(paper_->input_custom_width);
894 ok = ok && (str.empty() || isValidLength(str));
895 str = fl_get_input(paper_->input_custom_height);
896 ok = ok && (str.empty() || isValidLength(str));
897 str = fl_get_input(paper_->input_left_margin);
898 ok = ok && (str.empty() || isValidLength(str));
899 str = fl_get_input(paper_->input_right_margin);
900 ok = ok && (str.empty() || isValidLength(str));
901 str = fl_get_input(paper_->input_top_margin);
902 ok = ok && (str.empty() || isValidLength(str));
903 str = fl_get_input(paper_->input_bottom_margin);
904 ok = ok && (str.empty() || isValidLength(str));
905 str = fl_get_input(paper_->input_head_height);
906 ok = ok && (str.empty() || isValidLength(str));
907 str = fl_get_input(paper_->input_head_sep);
908 ok = ok && (str.empty() || isValidLength(str));
909 str = fl_get_input(paper_->input_foot_skip);
910 ok = ok && (str.empty() || isValidLength(str));
911 // "Synchronize" the choice and the input field, so that it
912 // is impossible to commit senseless data.
913 input = fl_get_input (class_->input_doc_skip);
914 if (ob == class_->input_doc_skip) {
916 fl_set_choice (class_->choice_doc_skip, 2);
917 } else if (isValidGlueLength (input)) {
918 fl_set_choice (class_->choice_doc_skip, 4);
920 fl_set_choice(class_->choice_doc_skip, 4);
924 if (*input && !isValidGlueLength(input))
928 if (ob == paper_->radio_portrait) {
929 setEnabled(paper_->choice_paperpackage,
930 fl_get_button(paper_->radio_portrait));
933 if (ob == paper_->radio_landscape) {
934 setEnabled(paper_->choice_paperpackage,
935 fl_get_button(paper_->radio_portrait));
936 fl_set_choice(paper_->choice_paperpackage,
937 BufferParams::PACKAGE_NONE + 1);
940 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
942 else if (fl_get_choice(class_->choice_doc_skip) != 4)
943 fl_set_input (class_->input_doc_skip, "");
945 input = fl_get_input(class_->input_doc_spacing);
946 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
948 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
949 fl_set_input (class_->input_doc_spacing, "");
954 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
956 BufferParams & param = lv_->buffer()->params;
958 // convert from 1-6 range to -1-4
959 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
960 fl_set_input(bullets_->input_bullet_latex,
961 param.temp_bullets[current_bullet_depth].getText().c_str());
965 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
967 BufferParams & param = lv_->buffer()->params;
969 param.temp_bullets[current_bullet_depth].
970 setText(fl_get_input(bullets_->input_bullet_latex));
974 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
976 /* Should I do the following: */
977 /* 1. change to the panel that the current bullet belongs in */
978 /* 2. show that bullet as selected */
979 /* 3. change the size setting to the size of the bullet in Q.*/
980 /* 4. display the latex equivalent in the latex box */
982 /* I'm inclined to just go with 3 and 4 at the moment and */
983 /* maybe try to support the others later */
984 BufferParams & param = lv_->buffer()->params;
987 if (cb == BULLETDEPTH1 )
989 else if (cb == BULLETDEPTH2 )
991 else if (cb == BULLETDEPTH3 )
993 else if (cb == BULLETDEPTH4 )
996 switch (fl_get_button_numb(ob)) {
998 // right mouse button resets to default
999 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1001 current_bullet_depth = data;
1002 fl_set_input(bullets_->input_bullet_latex,
1003 param.temp_bullets[data].getText().c_str());
1004 fl_set_choice(bullets_->choice_bullet_size,
1005 param.temp_bullets[data].getSize() + 2);
1010 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1012 /* Here we have to change the background pixmap to that selected */
1013 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1016 if (cb == BULLETPANEL1 )
1018 else if (cb == BULLETPANEL2 )
1020 else if (cb == BULLETPANEL3 )
1022 else if (cb == BULLETPANEL4 )
1024 else if (cb == BULLETPANEL5 )
1026 else if (cb == BULLETPANEL6 )
1029 if (data != current_bullet_panel) {
1030 fl_freeze_form(bullets_->form);
1031 current_bullet_panel = data;
1033 /* free the current pixmap */
1034 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1037 /* display the new one */
1039 new_panel = "standard";
1042 new_panel = "amssymb";
1045 new_panel = "psnfss1";
1048 new_panel = "psnfss2";
1051 new_panel = "psnfss3";
1054 new_panel = "psnfss4";
1057 /* something very wrong happened */
1058 // play it safe for now but should be an exception
1059 current_bullet_panel = 0; // standard panel
1060 new_panel = "standard";
1063 new_panel += ".xpm";
1064 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1065 LibFileSearch("images", new_panel).c_str());
1066 fl_redraw_object(bullets_->bmtable_bullet_panel);
1067 fl_unfreeze_form(bullets_->form);
1072 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1074 /* handle the user input by setting the current bullet depth's pixmap */
1075 /* to that extracted from the current chosen position of the BMTable */
1076 /* Don't forget to free the button's old pixmap first. */
1078 BufferParams & param = lv_->buffer()->params;
1079 int bmtable_button = fl_get_bmtable(ob);
1081 /* try to keep the button held down till another is pushed */
1082 /* fl_set_bmtable(ob, 1, bmtable_button); */
1083 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1084 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1085 fl_set_input(bullets_->input_bullet_latex,
1086 param.temp_bullets[current_bullet_depth].getText().c_str());
1090 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1093 ob = class_->choice_doc_class;
1095 lv_->prohibitInput();
1097 unsigned int tc = combo_doc_class->get() - 1;
1098 if (textclasslist.Load(tc)) {
1099 // we use a copy of the bufferparams because we do not
1100 // want to modify them yet.
1101 BufferParams params = lv_->buffer()->params;
1103 if (lyxrc.auto_reset_options) {
1104 params.textclass = tc;
1105 params.useClassDefaults();
1106 UpdateLayoutDocument(params);
1109 // unable to load new style
1110 WriteAlert(_("Conversion Errors!"),
1111 _("Unable to switch to new document class."),
1112 _("Reverting to original document class."));
1113 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1119 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1125 class_update(params);
1126 paper_update(params);
1127 language_update(params);
1128 options_update(params);
1129 bullets_update(params);