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 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
108 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
117 bc().addReadOnly (paper_->choice_paperpackage);
118 bc().addReadOnly (paper_->greoup_radio_orientation);
119 bc().addReadOnly (paper_->radio_portrait);
120 bc().addReadOnly (paper_->radio_landscape);
121 bc().addReadOnly (paper_->choice_papersize2);
122 bc().addReadOnly (paper_->push_use_geometry);
123 bc().addReadOnly (paper_->input_custom_width);
124 bc().addReadOnly (paper_->input_custom_height);
125 bc().addReadOnly (paper_->input_top_margin);
126 bc().addReadOnly (paper_->input_bottom_margin);
127 bc().addReadOnly (paper_->input_left_margin);
128 bc().addReadOnly (paper_->input_right_margin);
129 bc().addReadOnly (paper_->input_head_height);
130 bc().addReadOnly (paper_->input_head_sep);
131 bc().addReadOnly (paper_->input_foot_skip);
133 // the document class form
134 class_.reset(build_doc_class());
137 // The language is a combo-box and has to be inserted manually
138 obj = class_->choice_doc_class;
139 fl_deactivate_object(obj);
140 fl_addto_form(class_->form);
141 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
142 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
143 dialog_->tabbed_folder);
144 combo_doc_class->shortcut("#C",1);
145 combo_doc_class->setcallback(ComboInputCB, this);
147 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
148 cit != textclasslist.end(); ++cit)
150 combo_doc_class->addto(cit->description());
153 fl_addto_choice(class_->choice_doc_spacing,
154 _(" Single | OneHalf | Double | Other "));
155 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
156 for (n=0; tex_fonts[n][0]; ++n) {
157 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
159 fl_addto_choice(class_->choice_doc_pagestyle,
160 "default|empty|plain|headings|fancy");
161 fl_addto_choice(class_->choice_doc_skip,
162 _(" Smallskip | Medskip | Bigskip | Length "));
163 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
164 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
165 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
167 bc().addReadOnly (class_->radio_doc_indent);
168 bc().addReadOnly (class_->radio_doc_skip);
170 bc().addReadOnly (class_->choice_doc_pagestyle);
171 bc().addReadOnly (class_->choice_doc_fonts);
172 bc().addReadOnly (class_->choice_doc_fontsize);
173 bc().addReadOnly (class_->radio_doc_sides_one);
174 bc().addReadOnly (class_->radio_doc_sides_two);
175 bc().addReadOnly (class_->radio_doc_columns_one);
176 bc().addReadOnly (class_->radio_doc_columns_two);
177 bc().addReadOnly (class_->input_doc_extra);
178 bc().addReadOnly (class_->input_doc_skip);
179 bc().addReadOnly (class_->choice_doc_skip);
180 bc().addReadOnly (class_->choice_doc_spacing);
181 bc().addReadOnly (class_->input_doc_spacing);
184 // the document language form
185 language_.reset(build_doc_language());
186 fl_addto_choice(language_->choice_inputenc,
187 "default|auto|latin1|latin2|latin5|latin9"
188 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
190 // The language is a combo-box and has to be inserted manually
191 obj = language_->choice_language;
192 fl_deactivate_object(obj);
193 fl_addto_form(language_->form);
194 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
195 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
196 dialog_->tabbed_folder);
197 combo_language->shortcut("#L",1);
198 combo_language->setcallback(ComboInputCB, this);
201 for (Languages::const_iterator cit = languages.begin();
202 cit != languages.end(); ++cit) {
203 combo_language->addto(cit->second.lang());
206 fl_addto_choice(language_->choice_quotes_language,
207 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
208 " «text» | »text« "));
210 bc().addReadOnly (language_->choice_inputenc);
211 bc().addReadOnly (language_->choice_quotes_language);
212 bc().addReadOnly (language_->radio_single);
213 bc().addReadOnly (language_->radio_double);
215 // the document options form
216 options_.reset(build_doc_options());
217 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
218 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
219 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
220 fl_set_counter_step(options_->slider_secnumdepth,1,1);
221 fl_set_counter_step(options_->slider_tocdepth,1,1);
222 fl_set_counter_precision(options_->slider_secnumdepth, 0);
223 fl_set_counter_precision(options_->slider_tocdepth, 0);
224 for (n=0; tex_graphics[n][0]; ++n) {
225 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
227 fl_addto_choice(options_->choice_citation_format,
228 _(" Author-year | Numerical "));
230 bc_.addReadOnly (options_->slider_secnumdepth);
231 bc_.addReadOnly (options_->slider_tocdepth);
232 bc_.addReadOnly (options_->check_use_amsmath);
233 bc_.addReadOnly (options_->check_use_natbib);
234 bc_.addReadOnly (options_->choice_citation_format);
235 bc_.addReadOnly (options_->input_float_placement);
236 bc_.addReadOnly (options_->choice_postscript_driver);
238 // the document bullets form
239 bullets_.reset(build_doc_bullet());
240 fl_addto_choice(bullets_->choice_bullet_size,
241 _(" default | tiny | script | footnote | small |"
242 " normal | large | Large | LARGE | huge | Huge"));
243 fl_set_choice(bullets_->choice_bullet_size, 1);
244 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
245 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
247 bc().addReadOnly (bullets_->bmtable_bullet_panel);
248 bc().addReadOnly (bullets_->choice_bullet_size);
249 bc().addReadOnly (bullets_->input_bullet_latex);
250 bc().addReadOnly (bullets_->radio_bullet_depth);
251 bc().addReadOnly (bullets_->radio_bullet_panel);
253 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
255 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
259 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
261 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
263 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
264 lyxerr << _("Your version of libXpm is older than 4.7.\n"
265 "The `bullet' tab of the document dialog "
266 "has been disabled") << '\n';
267 fl_deactivate_object(fbullet);
268 fl_set_object_lcol(fbullet, FL_INACTIVE);
273 void FormDocument::apply()
275 if (!lv_->view()->available() || !dialog_.get())
278 bool redo = class_apply();
280 redo = language_apply() || redo;
281 redo = options_apply() || redo;
285 lv_->view()->redoCurrentBuffer();
287 lv_->buffer()->markDirty();
288 setMinibuffer(lv_, _("Document layout set"));
292 void FormDocument::cancel()
294 // this avoids confusion when reopening
295 BufferParams & param = lv_->buffer()->params;
296 param.temp_bullets[0] = param.user_defined_bullets[0];
297 param.temp_bullets[1] = param.user_defined_bullets[1];
298 param.temp_bullets[2] = param.user_defined_bullets[2];
299 param.temp_bullets[3] = param.user_defined_bullets[3];
304 void FormDocument::update()
311 BufferParams const & params = lv_->buffer()->params;
313 fl_set_object_label(dialog_->button_save_defaults,
314 _("Save as Defaults"));
315 fl_set_object_label(dialog_->button_reset_defaults,
317 setEnabled(dialog_->button_reset_defaults,
318 !params.hasClassDefaults());
320 class_update(params);
321 paper_update(params);
322 language_update(params);
323 options_update(params);
324 bullets_update(params);
328 bool FormDocument::input( FL_OBJECT * ob, long data )
330 State cb = static_cast<State>( data );
333 case CHECKCHOICECLASS:
334 CheckChoiceClass(ob, 0);
336 case CHOICEBULLETSIZE:
337 ChoiceBulletSize(ob, 0);
339 case INPUTBULLETLATEX:
340 InputBulletLaTeX(ob, 0);
357 BulletBMTable(ob, 0);
363 if (ob == options_->check_use_natbib) {
364 setEnabled(options_->choice_citation_format,
365 fl_get_button(options_->check_use_natbib));
368 if (ob == dialog_->button_save_defaults) {
369 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
372 if (ob == dialog_->button_reset_defaults) {
373 BufferParams params = lv_->buffer()->params;
374 params.textclass = combo_doc_class->get() - 1;
375 params.useClassDefaults();
376 UpdateLayoutDocument(params);
380 setEnabled(dialog_->button_reset_defaults,
381 lv_->buffer()->params.hasClassDefaults());
386 case CHECKCHOICECLASS:
387 case CHOICEBULLETSIZE:
388 case INPUTBULLETLATEX:
390 return CheckDocumentInput(ob, 0);
399 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
401 FormDocument * pre = static_cast<FormDocument*>(v);
402 if (combox == pre->combo_doc_class.get())
403 pre->CheckChoiceClass(0, 0);
404 pre->bc().valid(pre->CheckDocumentInput(0,0));
408 bool FormDocument::class_apply()
411 BufferParams ¶ms = lv_->buffer()->params;
413 // If default skip is a "Length" but there's no text in the
414 // input field, reset the kind to "Medskip", which is the default.
415 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
416 !*(fl_get_input (class_->input_doc_skip))) {
417 fl_set_choice (class_->choice_doc_skip, 2);
419 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
420 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
421 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
423 unsigned int const new_class = combo_doc_class->get() - 1;
425 if (params.textclass != new_class) {
426 // try to load new_class
427 if (textclasslist.Load(new_class)) {
428 // successfully loaded
430 setMinibuffer(lv_, _("Converting document to new document class..."));
431 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
432 params.textclass, new_class,
433 lv_->buffer()->paragraph);
437 s = _("One paragraph couldn't be converted");
440 s += _(" paragraphs couldn't be converted");
442 WriteAlert(_("Conversion Errors!"),s,
443 _("into chosen document class"));
446 params.textclass = new_class;
448 // problem changing class -- warn user and retain old style
449 WriteAlert(_("Conversion Errors!"),
450 _("Errors loading new document class."),
451 _("Reverting to original document class."));
452 combo_doc_class->select(int(params.textclass) + 1);
455 BufferParams::PARSEP tmpsep = params.paragraph_separation;
456 if (fl_get_button(class_->radio_doc_indent))
457 params.paragraph_separation = BufferParams::PARSEP_INDENT;
459 params.paragraph_separation = BufferParams::PARSEP_SKIP;
460 if (tmpsep != params.paragraph_separation)
463 VSpace tmpdefskip = params.getDefSkip();
464 switch (fl_get_choice (class_->choice_doc_skip)) {
466 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
469 params.setDefSkip(VSpace(VSpace::MEDSKIP));
472 params.setDefSkip(VSpace(VSpace::BIGSKIP));
476 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
478 // DocumentDefskipCB assures that this never happens
480 params.setDefSkip(VSpace(VSpace::MEDSKIP));
483 if (!(tmpdefskip == params.getDefSkip()))
486 if (fl_get_button(class_->radio_doc_columns_two))
490 if (fl_get_button(class_->radio_doc_sides_two))
491 params.sides = LyXTextClass::TwoSides;
493 params.sides = LyXTextClass::OneSide;
495 Spacing tmpSpacing = params.spacing;
496 switch (fl_get_choice(class_->choice_doc_spacing)) {
498 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
499 params.spacing.set(Spacing::Single);
502 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
503 params.spacing.set(Spacing::Onehalf);
506 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
507 params.spacing.set(Spacing::Double);
510 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
511 params.spacing.set(Spacing::Other,
512 fl_get_input(class_->input_doc_spacing));
515 if (tmpSpacing != params.spacing)
518 params.options = fl_get_input(class_->input_doc_extra);
524 void FormDocument::paper_apply()
526 BufferParams & params = lv_->buffer()->params;
529 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
530 params.paperpackage =
531 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
532 params.use_geometry = fl_get_button(paper_->push_use_geometry);
533 if (fl_get_button(paper_->radio_landscape))
534 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
536 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
537 params.paperwidth = fl_get_input(paper_->input_custom_width);
538 params.paperheight = fl_get_input(paper_->input_custom_height);
539 params.leftmargin = fl_get_input(paper_->input_left_margin);
540 params.topmargin = fl_get_input(paper_->input_top_margin);
541 params.rightmargin = fl_get_input(paper_->input_right_margin);
542 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
543 params.headheight = fl_get_input(paper_->input_head_height);
544 params.headsep = fl_get_input(paper_->input_head_sep);
545 params.footskip = fl_get_input(paper_->input_foot_skip);
546 lv_->buffer()->setPaperStuff();
550 bool FormDocument::language_apply()
552 BufferParams & params = lv_->buffer()->params;
553 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
556 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
558 lga = InsetQuotes::EnglishQ;
561 lga = InsetQuotes::SwedishQ;
564 lga = InsetQuotes::GermanQ;
567 lga = InsetQuotes::PolishQ;
570 lga = InsetQuotes::FrenchQ;
573 lga = InsetQuotes::DanishQ;
576 params.quotes_language = lga;
577 if (fl_get_button(language_->radio_single))
578 params.quotes_times = InsetQuotes::SingleQ;
580 params.quotes_times = InsetQuotes::DoubleQ;
582 Language const * old_language = params.language;
583 Language const * new_language =
584 languages.getLanguage(combo_language->getline());
586 new_language = default_language;
588 if (old_language != new_language
589 && old_language->RightToLeft() == new_language->RightToLeft()
590 && !lv_->buffer()->isMultiLingual())
591 lv_->buffer()->changeLanguage(old_language, new_language);
592 if (old_language != new_language) {
595 params.language = new_language;
596 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
602 bool FormDocument::options_apply()
604 BufferParams & params = lv_->buffer()->params;
607 params.graphicsDriver =
608 fl_get_choice_text(options_->choice_postscript_driver);
609 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
610 params.use_natbib = fl_get_button(options_->check_use_natbib);
611 params.use_numerical_citations =
612 fl_get_choice(options_->choice_citation_format)-1;
614 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
615 if (params.secnumdepth != tmpchar)
617 params.secnumdepth = tmpchar;
619 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
621 params.float_placement =
622 fl_get_input(options_->input_float_placement);
628 void FormDocument::bullets_apply()
630 /* update the bullet settings */
631 BufferParams & param = lv_->buffer()->params;
633 // a little bit of loop unrolling
634 param.user_defined_bullets[0] = param.temp_bullets[0];
635 param.user_defined_bullets[1] = param.temp_bullets[1];
636 param.user_defined_bullets[2] = param.temp_bullets[2];
637 param.user_defined_bullets[3] = param.temp_bullets[3];
641 void FormDocument::class_update(BufferParams const & params)
646 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
648 combo_doc_class->select(
649 textclasslist.DescOfClass(params.textclass));
650 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
651 fl_clear_choice(class_->choice_doc_fontsize);
652 fl_addto_choice(class_->choice_doc_fontsize, "default");
653 fl_addto_choice(class_->choice_doc_fontsize,
654 tclass.opt_fontsize().c_str());
655 fl_set_choice(class_->choice_doc_fontsize,
656 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
657 fl_clear_choice(class_->choice_doc_pagestyle);
658 fl_addto_choice(class_->choice_doc_pagestyle, "default");
659 fl_addto_choice(class_->choice_doc_pagestyle,
660 tclass.opt_pagestyle().c_str());
661 fl_set_choice(class_->choice_doc_pagestyle,
662 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
663 fl_set_button(class_->radio_doc_indent, 0);
664 fl_set_button(class_->radio_doc_skip, 0);
665 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
666 fl_set_button(class_->radio_doc_indent, 1);
668 fl_set_button(class_->radio_doc_skip, 1);
669 switch (params.getDefSkip().kind()) {
670 case VSpace::SMALLSKIP:
671 fl_set_choice (class_->choice_doc_skip, 1);
673 case VSpace::MEDSKIP:
674 fl_set_choice (class_->choice_doc_skip, 2);
676 case VSpace::BIGSKIP:
677 fl_set_choice (class_->choice_doc_skip, 3);
680 fl_set_choice (class_->choice_doc_skip, 4);
681 fl_set_input (class_->input_doc_skip,
682 params.getDefSkip().asLyXCommand().c_str());
685 fl_set_choice (class_->choice_doc_skip, 2);
688 fl_set_button(class_->radio_doc_sides_one, 0);
689 fl_set_button(class_->radio_doc_sides_two, 0);
690 if (params.sides == LyXTextClass::TwoSides)
691 fl_set_button(class_->radio_doc_sides_two, 1);
693 fl_set_button(class_->radio_doc_sides_one, 1);
694 fl_set_button(class_->radio_doc_columns_one, 0);
695 fl_set_button(class_->radio_doc_columns_two, 0);
696 if (params.columns == 2)
697 fl_set_button(class_->radio_doc_columns_two, 1);
699 fl_set_button(class_->radio_doc_columns_one, 1);
700 fl_set_input(class_->input_doc_spacing, "");
701 switch (params.spacing.getSpace()) {
702 case Spacing::Default: // nothing bad should happen with this
703 case Spacing::Single:
705 fl_set_choice(class_->choice_doc_spacing, 1);
707 case Spacing::Onehalf:
709 fl_set_choice(class_->choice_doc_spacing, 2);
711 case Spacing::Double:
713 fl_set_choice(class_->choice_doc_spacing, 3);
717 fl_set_choice(class_->choice_doc_spacing, 4);
719 sprintf(sval,"%g",params.spacing.getValue());
720 fl_set_input(class_->input_doc_spacing, sval);
724 if (!params.options.empty())
725 fl_set_input(class_->input_doc_extra, params.options.c_str());
727 fl_set_input(class_->input_doc_extra, "");
731 void FormDocument::language_update(BufferParams const & params)
733 if (!language_.get())
736 combo_language->select(params.language->lang());
737 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
738 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
739 fl_set_button(language_->radio_single, 0);
740 fl_set_button(language_->radio_double, 0);
741 if (params.quotes_times == InsetQuotes::SingleQ)
742 fl_set_button(language_->radio_single, 1);
744 fl_set_button(language_->radio_double, 1);
748 void FormDocument::options_update(BufferParams const & params)
753 fl_set_choice_text(options_->choice_postscript_driver,
754 params.graphicsDriver.c_str());
755 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
756 fl_set_button(options_->check_use_natbib, params.use_natbib);
757 fl_set_choice(options_->choice_citation_format,
758 int(params.use_numerical_citations)+1);
759 setEnabled(options_->choice_citation_format, params.use_natbib);
760 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
761 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
762 if (!params.float_placement.empty())
763 fl_set_input(options_->input_float_placement,
764 params.float_placement.c_str());
766 fl_set_input(options_->input_float_placement, "");
770 void FormDocument::paper_update(BufferParams const & params)
775 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
776 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
777 fl_set_button(paper_->push_use_geometry, params.use_geometry);
778 fl_set_button(paper_->radio_portrait, 0);
779 fl_set_button(paper_->radio_landscape, 0);
780 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
781 fl_set_button(paper_->radio_landscape, 1);
783 fl_set_button(paper_->radio_portrait, 1);
784 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
785 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
786 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
787 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
788 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
789 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
790 fl_set_input(paper_->input_head_height, params.headheight.c_str());
791 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
792 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
793 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
797 void FormDocument::bullets_update(BufferParams const & params)
799 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
802 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
803 setEnabled(fbullet, !isLinuxDoc);
805 if (isLinuxDoc) return;
807 fl_set_button(bullets_->radio_bullet_depth_1, 1);
808 fl_set_input(bullets_->input_bullet_latex,
809 params.user_defined_bullets[0].getText().c_str());
810 fl_set_choice(bullets_->choice_bullet_size,
811 params.user_defined_bullets[0].getSize() + 2);
815 void FormDocument::checkReadOnly()
817 if (bc().readOnly(lv_->buffer()->isReadonly())) {
818 combo_doc_class->deactivate();
819 combo_language->deactivate();
820 fl_set_object_label(dialog_->text_warning,
821 _("Document is read-only."
822 " No changes to layout permitted."));
823 fl_show_object(dialog_->text_warning);
825 combo_doc_class->activate();
826 combo_language->activate();
827 fl_hide_object(dialog_->text_warning);
832 void FormDocument::checkMarginValues()
834 bool const not_empty =
835 strlen(fl_get_input(paper_->input_top_margin)) ||
836 strlen(fl_get_input(paper_->input_bottom_margin)) ||
837 strlen(fl_get_input(paper_->input_left_margin)) ||
838 strlen(fl_get_input(paper_->input_right_margin)) ||
839 strlen(fl_get_input(paper_->input_head_height)) ||
840 strlen(fl_get_input(paper_->input_head_sep)) ||
841 strlen(fl_get_input(paper_->input_foot_skip)) ||
842 strlen(fl_get_input(paper_->input_custom_width)) ||
843 strlen(fl_get_input(paper_->input_custom_height));
845 fl_set_button(paper_->push_use_geometry, 1);
849 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
857 if (ob == paper_->choice_papersize2) {
858 val = fl_get_choice(paper_->choice_papersize2)-1;
859 if (val == BufferParams::VM_PAPER_DEFAULT) {
860 fl_set_button(paper_->push_use_geometry, 0);
863 if ((val != BufferParams::VM_PAPER_USLETTER) &&
864 (val != BufferParams::VM_PAPER_USLEGAL) &&
865 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
866 (val != BufferParams::VM_PAPER_A4) &&
867 (val != BufferParams::VM_PAPER_A5) &&
868 (val != BufferParams::VM_PAPER_B5)) {
869 fl_set_button(paper_->push_use_geometry, 1);
871 fl_set_choice(paper_->choice_paperpackage,
872 BufferParams::PACKAGE_NONE + 1);
874 } else if (ob == paper_->choice_paperpackage) {
875 val = fl_get_choice(paper_->choice_paperpackage)-1;
876 if (val != BufferParams::PACKAGE_NONE) {
877 fl_set_choice(paper_->choice_papersize2,
878 BufferParams::VM_PAPER_DEFAULT + 1);
879 fl_set_button(paper_->push_use_geometry, 0);
881 } else if (ob == class_->input_doc_spacing) {
882 input = fl_get_input(class_->input_doc_spacing);
884 fl_set_choice (class_->choice_doc_spacing, 1);
886 fl_set_choice(class_->choice_doc_spacing, 4);
889 // this has to be all out of if/elseif because it has to deactivate
890 // the document buttons and so the whole stuff has to be tested again.
891 str = fl_get_input(paper_->input_custom_width);
892 ok = ok && (str.empty() || isValidLength(str));
893 str = fl_get_input(paper_->input_custom_height);
894 ok = ok && (str.empty() || isValidLength(str));
895 str = fl_get_input(paper_->input_left_margin);
896 ok = ok && (str.empty() || isValidLength(str));
897 str = fl_get_input(paper_->input_right_margin);
898 ok = ok && (str.empty() || isValidLength(str));
899 str = fl_get_input(paper_->input_top_margin);
900 ok = ok && (str.empty() || isValidLength(str));
901 str = fl_get_input(paper_->input_bottom_margin);
902 ok = ok && (str.empty() || isValidLength(str));
903 str = fl_get_input(paper_->input_head_height);
904 ok = ok && (str.empty() || isValidLength(str));
905 str = fl_get_input(paper_->input_head_sep);
906 ok = ok && (str.empty() || isValidLength(str));
907 str = fl_get_input(paper_->input_foot_skip);
908 ok = ok && (str.empty() || isValidLength(str));
909 // "Synchronize" the choice and the input field, so that it
910 // is impossible to commit senseless data.
911 input = fl_get_input (class_->input_doc_skip);
912 if (ob == class_->input_doc_skip) {
914 fl_set_choice (class_->choice_doc_skip, 2);
915 } else if (isValidGlueLength (input)) {
916 fl_set_choice (class_->choice_doc_skip, 4);
918 fl_set_choice(class_->choice_doc_skip, 4);
922 if (*input && !isValidGlueLength(input))
925 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
927 else if (fl_get_choice(class_->choice_doc_skip) != 4)
928 fl_set_input (class_->input_doc_skip, "");
930 input = fl_get_input(class_->input_doc_spacing);
931 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
933 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
934 fl_set_input (class_->input_doc_spacing, "");
939 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
941 BufferParams & param = lv_->buffer()->params;
943 // convert from 1-6 range to -1-4
944 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
945 fl_set_input(bullets_->input_bullet_latex,
946 param.temp_bullets[current_bullet_depth].getText().c_str());
950 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
952 BufferParams & param = lv_->buffer()->params;
954 param.temp_bullets[current_bullet_depth].
955 setText(fl_get_input(bullets_->input_bullet_latex));
959 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
961 /* Should I do the following: */
962 /* 1. change to the panel that the current bullet belongs in */
963 /* 2. show that bullet as selected */
964 /* 3. change the size setting to the size of the bullet in Q.*/
965 /* 4. display the latex equivalent in the latex box */
967 /* I'm inclined to just go with 3 and 4 at the moment and */
968 /* maybe try to support the others later */
969 BufferParams & param = lv_->buffer()->params;
972 if (cb == BULLETDEPTH1 )
974 else if (cb == BULLETDEPTH2 )
976 else if (cb == BULLETDEPTH3 )
978 else if (cb == BULLETDEPTH4 )
981 switch (fl_get_button_numb(ob)) {
983 // right mouse button resets to default
984 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
986 current_bullet_depth = data;
987 fl_set_input(bullets_->input_bullet_latex,
988 param.temp_bullets[data].getText().c_str());
989 fl_set_choice(bullets_->choice_bullet_size,
990 param.temp_bullets[data].getSize() + 2);
995 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
997 /* Here we have to change the background pixmap to that selected */
998 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1001 if (cb == BULLETPANEL1 )
1003 else if (cb == BULLETPANEL2 )
1005 else if (cb == BULLETPANEL3 )
1007 else if (cb == BULLETPANEL4 )
1009 else if (cb == BULLETPANEL5 )
1011 else if (cb == BULLETPANEL6 )
1014 if (data != current_bullet_panel) {
1015 fl_freeze_form(bullets_->form);
1016 current_bullet_panel = data;
1018 /* free the current pixmap */
1019 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1022 /* display the new one */
1024 new_panel = "standard";
1027 new_panel = "amssymb";
1030 new_panel = "psnfss1";
1033 new_panel = "psnfss2";
1036 new_panel = "psnfss3";
1039 new_panel = "psnfss4";
1042 /* something very wrong happened */
1043 // play it safe for now but should be an exception
1044 current_bullet_panel = 0; // standard panel
1045 new_panel = "standard";
1048 new_panel += ".xpm";
1049 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1050 LibFileSearch("images", new_panel).c_str());
1051 fl_redraw_object(bullets_->bmtable_bullet_panel);
1052 fl_unfreeze_form(bullets_->form);
1057 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1059 /* handle the user input by setting the current bullet depth's pixmap */
1060 /* to that extracted from the current chosen position of the BMTable */
1061 /* Don't forget to free the button's old pixmap first. */
1063 BufferParams & param = lv_->buffer()->params;
1064 int bmtable_button = fl_get_bmtable(ob);
1066 /* try to keep the button held down till another is pushed */
1067 /* fl_set_bmtable(ob, 1, bmtable_button); */
1068 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1069 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1070 fl_set_input(bullets_->input_bullet_latex,
1071 param.temp_bullets[current_bullet_depth].getText().c_str());
1075 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1078 ob = class_->choice_doc_class;
1080 lv_->prohibitInput();
1082 unsigned int tc = combo_doc_class->get() - 1;
1083 if (textclasslist.Load(tc)) {
1084 // we use a copy of the bufferparams because we do not
1085 // want to modify them yet.
1086 BufferParams params = lv_->buffer()->params;
1088 if (lyxrc.auto_reset_options) {
1089 params.textclass = tc;
1090 params.useClassDefaults();
1091 UpdateLayoutDocument(params);
1094 // unable to load new style
1095 WriteAlert(_("Conversion Errors!"),
1096 _("Unable to switch to new document class."),
1097 _("Reverting to original document class."));
1098 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1104 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1110 class_update(params);
1111 paper_update(params);
1112 language_update(params);
1113 options_update(params);
1114 bullets_update(params);