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,
105 "| Very small Margins "
106 "| Very wide Margins "));
108 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
118 bc().addReadOnly (paper_->choice_paperpackage);
119 bc().addReadOnly (paper_->greoup_radio_orientation);
120 bc().addReadOnly (paper_->radio_portrait);
121 bc().addReadOnly (paper_->radio_landscape);
122 bc().addReadOnly (paper_->choice_papersize2);
123 bc().addReadOnly (paper_->push_use_geometry);
124 bc().addReadOnly (paper_->input_custom_width);
125 bc().addReadOnly (paper_->input_custom_height);
126 bc().addReadOnly (paper_->input_top_margin);
127 bc().addReadOnly (paper_->input_bottom_margin);
128 bc().addReadOnly (paper_->input_left_margin);
129 bc().addReadOnly (paper_->input_right_margin);
130 bc().addReadOnly (paper_->input_head_height);
131 bc().addReadOnly (paper_->input_head_sep);
132 bc().addReadOnly (paper_->input_foot_skip);
134 // the document class form
135 class_.reset(build_doc_class());
138 // The language is a combo-box and has to be inserted manually
139 obj = class_->choice_doc_class;
140 fl_deactivate_object(obj);
141 fl_addto_form(class_->form);
142 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
143 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
144 dialog_->tabbed_folder);
145 combo_doc_class->shortcut("#C",1);
146 combo_doc_class->setcallback(ComboInputCB, this);
148 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
149 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);
183 // the document language form
184 language_.reset(build_doc_language());
185 fl_addto_choice(language_->choice_inputenc,
186 "default|auto|latin1|latin2|latin5|latin9"
187 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
189 // The language is a combo-box and has to be inserted manually
190 obj = language_->choice_language;
191 fl_deactivate_object(obj);
192 fl_addto_form(language_->form);
193 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
194 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
195 dialog_->tabbed_folder);
196 combo_language->shortcut("#L",1);
197 combo_language->setcallback(ComboInputCB, this);
200 for (Languages::const_iterator cit = languages.begin();
201 cit != languages.end(); ++cit) {
202 combo_language->addto(cit->second.lang());
205 fl_addto_choice(language_->choice_quotes_language,
206 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
207 " «text» | »text« "));
209 bc().addReadOnly (language_->choice_inputenc);
210 bc().addReadOnly (language_->choice_quotes_language);
211 bc().addReadOnly (language_->radio_single);
212 bc().addReadOnly (language_->radio_double);
214 // the document options form
215 options_.reset(build_doc_options());
216 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
217 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
218 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
219 fl_set_counter_step(options_->slider_secnumdepth,1,1);
220 fl_set_counter_step(options_->slider_tocdepth,1,1);
221 fl_set_counter_precision(options_->slider_secnumdepth, 0);
222 fl_set_counter_precision(options_->slider_tocdepth, 0);
223 for (n=0; tex_graphics[n][0]; ++n) {
224 fl_addto_choice(options_->choice_postscript_driver,
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,
316 // _("Use Class 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);
379 if (ob == paper_->radio_landscape)
380 fl_set_choice(paper_->choice_paperpackage,
381 BufferParams::PACKAGE_NONE + 1);
383 if (ob == paper_->choice_papersize2) {
384 if (fl_get_choice(paper_->choice_papersize2) == 2)
385 fl_set_button(paper_->radio_portrait, 1);
386 setEnabled(paper_->input_custom_width,
387 fl_get_choice(paper_->choice_papersize2) == 2);
388 setEnabled(paper_->input_custom_height,
389 fl_get_choice(paper_->choice_papersize2) == 2);
390 setEnabled(paper_->radio_portrait,
391 fl_get_choice(paper_->choice_papersize2) != 2);
392 setEnabled(paper_->radio_landscape,
393 fl_get_choice(paper_->choice_papersize2) != 2);
396 if (ob == paper_->choice_papersize2
397 || paper_->radio_portrait
398 || paper_->radio_landscape)
399 setEnabled(paper_->choice_paperpackage,
400 //either default papersize (preferences)
401 //or document papersize has to be A4
402 (fl_get_choice(paper_->choice_papersize2) == 7
403 || fl_get_choice(paper_->choice_papersize2) == 1
404 && lyxrc.default_papersize == 5)
405 && fl_get_button(paper_->radio_portrait));
407 if (ob == paper_->choice_paperpackage) {
408 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
409 fl_set_button(paper_->push_use_geometry, 0);
410 setEnabled(paper_->input_top_margin,
411 fl_get_button(paper_->push_use_geometry));
412 setEnabled(paper_->input_bottom_margin,
413 fl_get_button(paper_->push_use_geometry));
414 setEnabled(paper_->input_left_margin,
415 fl_get_button(paper_->push_use_geometry));
416 setEnabled(paper_->input_right_margin,
417 fl_get_button(paper_->push_use_geometry));
418 setEnabled(paper_->input_head_height,
419 fl_get_button(paper_->push_use_geometry));
420 setEnabled(paper_->input_head_sep,
421 fl_get_button(paper_->push_use_geometry));
422 setEnabled(paper_->input_foot_skip,
423 fl_get_button(paper_->push_use_geometry));
427 if (ob == paper_->push_use_geometry) {
428 //don't allow switching geometry off in custom papersize mode
429 if (fl_get_choice(paper_->choice_papersize2) == 2)
430 fl_set_button(paper_->push_use_geometry, 1);
431 fl_set_choice(paper_->choice_paperpackage,
432 BufferParams::PACKAGE_NONE + 1);
433 setEnabled(paper_->input_top_margin,
434 fl_get_button(paper_->push_use_geometry));
435 setEnabled(paper_->input_bottom_margin,
436 fl_get_button(paper_->push_use_geometry));
437 setEnabled(paper_->input_left_margin,
438 fl_get_button(paper_->push_use_geometry));
439 setEnabled(paper_->input_right_margin,
440 fl_get_button(paper_->push_use_geometry));
441 setEnabled(paper_->input_head_height,
442 fl_get_button(paper_->push_use_geometry));
443 setEnabled(paper_->input_head_sep,
444 fl_get_button(paper_->push_use_geometry));
445 setEnabled(paper_->input_foot_skip,
446 fl_get_button(paper_->push_use_geometry));
449 setEnabled(dialog_->button_reset_defaults,
450 lv_->buffer()->params.hasClassDefaults());
454 case CHECKCHOICECLASS:
455 case CHOICEBULLETSIZE:
456 case INPUTBULLETLATEX:
458 return CheckDocumentInput(ob, 0);
467 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
469 FormDocument * pre = static_cast<FormDocument*>(v);
470 if (combox == pre->combo_doc_class.get())
471 pre->CheckChoiceClass(0, 0);
472 pre->bc().valid(pre->CheckDocumentInput(0,0));
476 bool FormDocument::class_apply()
479 BufferParams ¶ms = lv_->buffer()->params;
481 // If default skip is a "Length" but there's no text in the
482 // input field, reset the kind to "Medskip", which is the default.
483 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
484 !*(fl_get_input (class_->input_doc_skip))) {
485 fl_set_choice (class_->choice_doc_skip, 2);
487 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
488 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
489 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
491 unsigned int const new_class = combo_doc_class->get() - 1;
493 if (params.textclass != new_class) {
494 // try to load new_class
495 if (textclasslist.Load(new_class)) {
496 // successfully loaded
498 setMinibuffer(lv_, _("Converting document to new document class..."));
499 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
500 params.textclass, new_class,
501 lv_->buffer()->paragraph);
505 s = _("One paragraph couldn't be converted");
508 s += _(" paragraphs couldn't be converted");
510 WriteAlert(_("Conversion Errors!"),s,
511 _("into chosen document class"));
514 params.textclass = new_class;
516 // problem changing class -- warn user and retain old style
517 WriteAlert(_("Conversion Errors!"),
518 _("Errors loading new document class."),
519 _("Reverting to original document class."));
520 combo_doc_class->select(int(params.textclass) + 1);
523 BufferParams::PARSEP tmpsep = params.paragraph_separation;
524 if (fl_get_button(class_->radio_doc_indent))
525 params.paragraph_separation = BufferParams::PARSEP_INDENT;
527 params.paragraph_separation = BufferParams::PARSEP_SKIP;
528 if (tmpsep != params.paragraph_separation)
531 VSpace tmpdefskip = params.getDefSkip();
532 switch (fl_get_choice (class_->choice_doc_skip)) {
534 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
537 params.setDefSkip(VSpace(VSpace::MEDSKIP));
540 params.setDefSkip(VSpace(VSpace::BIGSKIP));
544 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
546 // DocumentDefskipCB assures that this never happens
548 params.setDefSkip(VSpace(VSpace::MEDSKIP));
551 if (!(tmpdefskip == params.getDefSkip()))
554 if (fl_get_button(class_->radio_doc_columns_two))
558 if (fl_get_button(class_->radio_doc_sides_two))
559 params.sides = LyXTextClass::TwoSides;
561 params.sides = LyXTextClass::OneSide;
563 Spacing tmpSpacing = params.spacing;
564 switch (fl_get_choice(class_->choice_doc_spacing)) {
566 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
567 params.spacing.set(Spacing::Single);
570 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
571 params.spacing.set(Spacing::Onehalf);
574 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
575 params.spacing.set(Spacing::Double);
578 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
579 params.spacing.set(Spacing::Other,
580 fl_get_input(class_->input_doc_spacing));
583 if (tmpSpacing != params.spacing)
586 params.options = fl_get_input(class_->input_doc_extra);
592 void FormDocument::paper_apply()
594 BufferParams & params = lv_->buffer()->params;
597 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
598 params.paperpackage =
599 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
600 params.use_geometry = fl_get_button(paper_->push_use_geometry);
601 if (fl_get_button(paper_->radio_landscape))
602 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
604 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
605 params.paperwidth = fl_get_input(paper_->input_custom_width);
606 params.paperheight = fl_get_input(paper_->input_custom_height);
607 params.leftmargin = fl_get_input(paper_->input_left_margin);
608 params.topmargin = fl_get_input(paper_->input_top_margin);
609 params.rightmargin = fl_get_input(paper_->input_right_margin);
610 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
611 params.headheight = fl_get_input(paper_->input_head_height);
612 params.headsep = fl_get_input(paper_->input_head_sep);
613 params.footskip = fl_get_input(paper_->input_foot_skip);
614 lv_->buffer()->setPaperStuff();
618 bool FormDocument::language_apply()
620 BufferParams & params = lv_->buffer()->params;
621 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
624 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
626 lga = InsetQuotes::EnglishQ;
629 lga = InsetQuotes::SwedishQ;
632 lga = InsetQuotes::GermanQ;
635 lga = InsetQuotes::PolishQ;
638 lga = InsetQuotes::FrenchQ;
641 lga = InsetQuotes::DanishQ;
644 params.quotes_language = lga;
645 if (fl_get_button(language_->radio_single))
646 params.quotes_times = InsetQuotes::SingleQ;
648 params.quotes_times = InsetQuotes::DoubleQ;
650 Language const * old_language = params.language;
651 Language const * new_language =
652 languages.getLanguage(combo_language->getline());
654 new_language = default_language;
656 if (old_language != new_language
657 && old_language->RightToLeft() == new_language->RightToLeft()
658 && !lv_->buffer()->isMultiLingual())
659 lv_->buffer()->changeLanguage(old_language, new_language);
660 if (old_language != new_language) {
663 params.language = new_language;
664 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
670 bool FormDocument::options_apply()
672 BufferParams & params = lv_->buffer()->params;
675 params.graphicsDriver =
676 fl_get_choice_text(options_->choice_postscript_driver);
677 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
678 params.use_natbib = fl_get_button(options_->check_use_natbib);
679 params.use_numerical_citations =
680 fl_get_choice(options_->choice_citation_format)-1;
682 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
683 if (params.secnumdepth != tmpchar)
685 params.secnumdepth = tmpchar;
687 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
689 params.float_placement =
690 fl_get_input(options_->input_float_placement);
696 void FormDocument::bullets_apply()
698 /* update the bullet settings */
699 BufferParams & param = lv_->buffer()->params;
701 // a little bit of loop unrolling
702 param.user_defined_bullets[0] = param.temp_bullets[0];
703 param.user_defined_bullets[1] = param.temp_bullets[1];
704 param.user_defined_bullets[2] = param.temp_bullets[2];
705 param.user_defined_bullets[3] = param.temp_bullets[3];
709 void FormDocument::class_update(BufferParams const & params)
714 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
716 combo_doc_class->select(
717 textclasslist.DescOfClass(params.textclass));
718 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
719 fl_clear_choice(class_->choice_doc_fontsize);
720 fl_addto_choice(class_->choice_doc_fontsize, "default");
721 fl_addto_choice(class_->choice_doc_fontsize,
722 tclass.opt_fontsize().c_str());
723 fl_set_choice(class_->choice_doc_fontsize,
724 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
725 fl_clear_choice(class_->choice_doc_pagestyle);
726 fl_addto_choice(class_->choice_doc_pagestyle, "default");
727 fl_addto_choice(class_->choice_doc_pagestyle,
728 tclass.opt_pagestyle().c_str());
729 fl_set_choice(class_->choice_doc_pagestyle,
730 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
731 fl_set_button(class_->radio_doc_indent, 0);
732 fl_set_button(class_->radio_doc_skip, 0);
733 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
734 fl_set_button(class_->radio_doc_indent, 1);
736 fl_set_button(class_->radio_doc_skip, 1);
737 switch (params.getDefSkip().kind()) {
738 case VSpace::SMALLSKIP:
739 fl_set_choice (class_->choice_doc_skip, 1);
741 case VSpace::MEDSKIP:
742 fl_set_choice (class_->choice_doc_skip, 2);
744 case VSpace::BIGSKIP:
745 fl_set_choice (class_->choice_doc_skip, 3);
748 fl_set_choice (class_->choice_doc_skip, 4);
749 fl_set_input (class_->input_doc_skip,
750 params.getDefSkip().asLyXCommand().c_str());
753 fl_set_choice (class_->choice_doc_skip, 2);
756 fl_set_button(class_->radio_doc_sides_one, 0);
757 fl_set_button(class_->radio_doc_sides_two, 0);
758 if (params.sides == LyXTextClass::TwoSides)
759 fl_set_button(class_->radio_doc_sides_two, 1);
761 fl_set_button(class_->radio_doc_sides_one, 1);
762 fl_set_button(class_->radio_doc_columns_one, 0);
763 fl_set_button(class_->radio_doc_columns_two, 0);
764 if (params.columns == 2)
765 fl_set_button(class_->radio_doc_columns_two, 1);
767 fl_set_button(class_->radio_doc_columns_one, 1);
768 fl_set_input(class_->input_doc_spacing, "");
769 switch (params.spacing.getSpace()) {
770 case Spacing::Default: // nothing bad should happen with this
771 case Spacing::Single:
773 fl_set_choice(class_->choice_doc_spacing, 1);
775 case Spacing::Onehalf:
777 fl_set_choice(class_->choice_doc_spacing, 2);
779 case Spacing::Double:
781 fl_set_choice(class_->choice_doc_spacing, 3);
785 fl_set_choice(class_->choice_doc_spacing, 4);
787 sprintf(sval,"%g",params.spacing.getValue());
788 fl_set_input(class_->input_doc_spacing, sval);
792 if (!params.options.empty())
793 fl_set_input(class_->input_doc_extra, params.options.c_str());
795 fl_set_input(class_->input_doc_extra, "");
799 void FormDocument::language_update(BufferParams const & params)
801 if (!language_.get())
804 combo_language->select(params.language->lang());
805 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
806 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
807 fl_set_button(language_->radio_single, 0);
808 fl_set_button(language_->radio_double, 0);
809 if (params.quotes_times == InsetQuotes::SingleQ)
810 fl_set_button(language_->radio_single, 1);
812 fl_set_button(language_->radio_double, 1);
816 void FormDocument::options_update(BufferParams const & params)
821 fl_set_choice_text(options_->choice_postscript_driver,
822 params.graphicsDriver.c_str());
823 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
824 fl_set_button(options_->check_use_natbib, params.use_natbib);
825 fl_set_choice(options_->choice_citation_format,
826 int(params.use_numerical_citations)+1);
827 setEnabled(options_->choice_citation_format, params.use_natbib);
828 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
829 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
830 if (!params.float_placement.empty())
831 fl_set_input(options_->input_float_placement,
832 params.float_placement.c_str());
834 fl_set_input(options_->input_float_placement, "");
838 void FormDocument::paper_update(BufferParams const & params)
843 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
844 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
845 fl_set_button(paper_->push_use_geometry, params.use_geometry);
846 fl_set_button(paper_->radio_portrait, 0);
847 setEnabled(paper_->radio_portrait,
848 fl_get_choice(paper_->choice_papersize2) != 2);
849 fl_set_button(paper_->radio_landscape, 0);
850 setEnabled(paper_->radio_landscape,
851 fl_get_choice(paper_->choice_papersize2) != 2);
852 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
853 fl_set_button(paper_->radio_landscape, 1);
855 fl_set_button(paper_->radio_portrait, 1);
856 setEnabled(paper_->choice_paperpackage,
857 //either default papersize (preferences)
858 //or document papersize has to be A4
859 (fl_get_choice(paper_->choice_papersize2) == 7
860 || fl_get_choice(paper_->choice_papersize2) == 1
861 && lyxrc.default_papersize == 5)
862 && fl_get_button(paper_->radio_portrait));
863 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
864 setEnabled(paper_->input_custom_width,
865 fl_get_choice(paper_->choice_papersize2) == 2);
866 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
867 setEnabled(paper_->input_custom_height,
868 fl_get_choice(paper_->choice_papersize2) == 2);
869 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
870 setEnabled(paper_->input_left_margin,
871 fl_get_button(paper_->push_use_geometry));
872 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
873 setEnabled(paper_->input_top_margin,
874 fl_get_button(paper_->push_use_geometry));
875 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
876 setEnabled(paper_->input_right_margin,
877 fl_get_button(paper_->push_use_geometry));
878 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
879 setEnabled(paper_->input_bottom_margin,
880 fl_get_button(paper_->push_use_geometry));
881 fl_set_input(paper_->input_head_height, params.headheight.c_str());
882 setEnabled(paper_->input_head_height,
883 fl_get_button(paper_->push_use_geometry));
884 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
885 setEnabled(paper_->input_head_sep,
886 fl_get_button(paper_->push_use_geometry));
887 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
888 setEnabled(paper_->input_foot_skip,
889 fl_get_button(paper_->push_use_geometry));
890 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
894 void FormDocument::bullets_update(BufferParams const & params)
896 if (!bullets_.get() ||
898 (XpmVersion==4 && XpmRevision<7)))
901 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
902 setEnabled(fbullet, !isLinuxDoc);
904 if (isLinuxDoc) return;
906 fl_set_button(bullets_->radio_bullet_depth_1, 1);
907 fl_set_input(bullets_->input_bullet_latex,
908 params.user_defined_bullets[0].getText().c_str());
909 fl_set_choice(bullets_->choice_bullet_size,
910 params.user_defined_bullets[0].getSize() + 2);
914 void FormDocument::checkReadOnly()
916 if (bc().readOnly(lv_->buffer()->isReadonly())) {
917 combo_doc_class->deactivate();
918 combo_language->deactivate();
919 fl_set_object_label(dialog_->text_warning,
920 _("Document is read-only."
921 " No changes to layout permitted."));
922 fl_show_object(dialog_->text_warning);
924 combo_doc_class->activate();
925 combo_language->activate();
926 fl_hide_object(dialog_->text_warning);
931 void FormDocument::checkMarginValues()
933 //this is not needed after the recent redesign (JSpitzm)
935 bool const not_empty =
936 strlen(fl_get_input(paper_->input_top_margin)) ||
937 strlen(fl_get_input(paper_->input_bottom_margin)) ||
938 strlen(fl_get_input(paper_->input_left_margin)) ||
939 strlen(fl_get_input(paper_->input_right_margin)) ||
940 strlen(fl_get_input(paper_->input_head_height)) ||
941 strlen(fl_get_input(paper_->input_head_sep)) ||
942 strlen(fl_get_input(paper_->input_foot_skip)) ||
943 strlen(fl_get_input(paper_->input_custom_width)) ||
944 strlen(fl_get_input(paper_->input_custom_height));
950 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
958 if (ob == paper_->choice_papersize2) {
959 val = fl_get_choice(paper_->choice_papersize2)-1;
960 if (val == BufferParams::VM_PAPER_DEFAULT) {
961 fl_set_button(paper_->push_use_geometry, 0);
962 setEnabled(paper_->input_top_margin,
963 fl_get_button(paper_->push_use_geometry));
964 setEnabled(paper_->input_bottom_margin,
965 fl_get_button(paper_->push_use_geometry));
966 setEnabled(paper_->input_left_margin,
967 fl_get_button(paper_->push_use_geometry));
968 setEnabled(paper_->input_right_margin,
969 fl_get_button(paper_->push_use_geometry));
970 setEnabled(paper_->input_head_height,
971 fl_get_button(paper_->push_use_geometry));
972 setEnabled(paper_->input_head_sep,
973 fl_get_button(paper_->push_use_geometry));
974 setEnabled(paper_->input_foot_skip,
975 fl_get_button(paper_->push_use_geometry));
978 if ((val != BufferParams::VM_PAPER_USLETTER) &&
979 (val != BufferParams::VM_PAPER_USLEGAL) &&
980 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
981 (val != BufferParams::VM_PAPER_A4) &&
982 (val != BufferParams::VM_PAPER_A5) &&
983 (val != BufferParams::VM_PAPER_B5)) {
984 fl_set_button(paper_->push_use_geometry, 1);
985 setEnabled(paper_->input_top_margin,
986 fl_get_button(paper_->push_use_geometry));
987 setEnabled(paper_->input_bottom_margin,
988 fl_get_button(paper_->push_use_geometry));
989 setEnabled(paper_->input_left_margin,
990 fl_get_button(paper_->push_use_geometry));
991 setEnabled(paper_->input_right_margin,
992 fl_get_button(paper_->push_use_geometry));
993 setEnabled(paper_->input_head_height,
994 fl_get_button(paper_->push_use_geometry));
995 setEnabled(paper_->input_head_sep,
996 fl_get_button(paper_->push_use_geometry));
997 setEnabled(paper_->input_foot_skip,
998 fl_get_button(paper_->push_use_geometry));
1000 fl_set_choice(paper_->choice_paperpackage,
1001 BufferParams::PACKAGE_NONE + 1);
1003 } else if (ob == paper_->choice_paperpackage) {
1004 val = fl_get_choice(paper_->choice_paperpackage)-1;
1005 if (val != BufferParams::PACKAGE_NONE) {
1006 fl_set_button(paper_->push_use_geometry, 0);
1007 setEnabled(paper_->input_top_margin,
1008 fl_get_button(paper_->push_use_geometry));
1009 setEnabled(paper_->input_bottom_margin,
1010 fl_get_button(paper_->push_use_geometry));
1011 setEnabled(paper_->input_left_margin,
1012 fl_get_button(paper_->push_use_geometry));
1013 setEnabled(paper_->input_right_margin,
1014 fl_get_button(paper_->push_use_geometry));
1015 setEnabled(paper_->input_head_height,
1016 fl_get_button(paper_->push_use_geometry));
1017 setEnabled(paper_->input_head_sep,
1018 fl_get_button(paper_->push_use_geometry));
1019 setEnabled(paper_->input_foot_skip,
1020 fl_get_button(paper_->push_use_geometry));
1022 } else if (ob == class_->input_doc_spacing) {
1023 input = fl_get_input(class_->input_doc_spacing);
1025 fl_set_choice (class_->choice_doc_spacing, 1);
1027 fl_set_choice(class_->choice_doc_spacing, 4);
1030 // this has to be all out of if/elseif because it has to deactivate
1031 // the document buttons and so the whole stuff has to be tested again.
1032 str = fl_get_input(paper_->input_custom_width);
1033 ok = ok && (str.empty() || isValidLength(str));
1034 str = fl_get_input(paper_->input_custom_height);
1035 ok = ok && (str.empty() || isValidLength(str));
1036 str = fl_get_input(paper_->input_left_margin);
1037 ok = ok && (str.empty() || isValidLength(str));
1038 str = fl_get_input(paper_->input_right_margin);
1039 ok = ok && (str.empty() || isValidLength(str));
1040 str = fl_get_input(paper_->input_top_margin);
1041 ok = ok && (str.empty() || isValidLength(str));
1042 str = fl_get_input(paper_->input_bottom_margin);
1043 ok = ok && (str.empty() || isValidLength(str));
1044 str = fl_get_input(paper_->input_head_height);
1045 ok = ok && (str.empty() || isValidLength(str));
1046 str = fl_get_input(paper_->input_head_sep);
1047 ok = ok && (str.empty() || isValidLength(str));
1048 str = fl_get_input(paper_->input_foot_skip);
1049 ok = ok && (str.empty() || isValidLength(str));
1050 // "Synchronize" the choice and the input field, so that it
1051 // is impossible to commit senseless data.
1052 input = fl_get_input (class_->input_doc_skip);
1053 if (ob == class_->input_doc_skip) {
1055 fl_set_choice (class_->choice_doc_skip, 2);
1056 } else if (isValidGlueLength (input)) {
1057 fl_set_choice (class_->choice_doc_skip, 4);
1059 fl_set_choice(class_->choice_doc_skip, 4);
1063 if (*input && !isValidGlueLength(input))
1067 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1069 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1070 fl_set_input (class_->input_doc_skip, "");
1072 input = fl_get_input(class_->input_doc_spacing);
1073 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1075 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1076 fl_set_input (class_->input_doc_spacing, "");
1081 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1083 BufferParams & param = lv_->buffer()->params;
1085 // convert from 1-6 range to -1-4
1086 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1087 fl_set_input(bullets_->input_bullet_latex,
1088 param.temp_bullets[current_bullet_depth].getText().c_str());
1092 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1094 BufferParams & param = lv_->buffer()->params;
1096 param.temp_bullets[current_bullet_depth].
1097 setText(fl_get_input(bullets_->input_bullet_latex));
1101 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1103 /* Should I do the following: */
1104 /* 1. change to the panel that the current bullet belongs in */
1105 /* 2. show that bullet as selected */
1106 /* 3. change the size setting to the size of the bullet in Q.*/
1107 /* 4. display the latex equivalent in the latex box */
1109 /* I'm inclined to just go with 3 and 4 at the moment and */
1110 /* maybe try to support the others later */
1111 BufferParams & param = lv_->buffer()->params;
1114 if (cb == BULLETDEPTH1 )
1116 else if (cb == BULLETDEPTH2 )
1118 else if (cb == BULLETDEPTH3 )
1120 else if (cb == BULLETDEPTH4 )
1123 switch (fl_get_button_numb(ob)) {
1125 // right mouse button resets to default
1126 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1128 current_bullet_depth = data;
1129 fl_set_input(bullets_->input_bullet_latex,
1130 param.temp_bullets[data].getText().c_str());
1131 fl_set_choice(bullets_->choice_bullet_size,
1132 param.temp_bullets[data].getSize() + 2);
1137 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1139 /* Here we have to change the background pixmap to that selected */
1140 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1143 if (cb == BULLETPANEL1 )
1145 else if (cb == BULLETPANEL2 )
1147 else if (cb == BULLETPANEL3 )
1149 else if (cb == BULLETPANEL4 )
1151 else if (cb == BULLETPANEL5 )
1153 else if (cb == BULLETPANEL6 )
1156 if (data != current_bullet_panel) {
1157 fl_freeze_form(bullets_->form);
1158 current_bullet_panel = data;
1160 /* free the current pixmap */
1161 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1164 /* display the new one */
1166 new_panel = "standard";
1169 new_panel = "amssymb";
1172 new_panel = "psnfss1";
1175 new_panel = "psnfss2";
1178 new_panel = "psnfss3";
1181 new_panel = "psnfss4";
1184 /* something very wrong happened */
1185 // play it safe for now but should be an exception
1186 current_bullet_panel = 0; // standard panel
1187 new_panel = "standard";
1190 new_panel += ".xpm";
1191 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1192 LibFileSearch("images", new_panel).c_str());
1193 fl_redraw_object(bullets_->bmtable_bullet_panel);
1194 fl_unfreeze_form(bullets_->form);
1199 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1201 /* handle the user input by setting the current bullet depth's pixmap */
1202 /* to that extracted from the current chosen position of the BMTable */
1203 /* Don't forget to free the button's old pixmap first. */
1205 BufferParams & param = lv_->buffer()->params;
1206 int bmtable_button = fl_get_bmtable(ob);
1208 /* try to keep the button held down till another is pushed */
1209 /* fl_set_bmtable(ob, 1, bmtable_button); */
1210 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1211 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1212 fl_set_input(bullets_->input_bullet_latex,
1213 param.temp_bullets[current_bullet_depth].getText().c_str());
1217 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1220 ob = class_->choice_doc_class;
1222 lv_->prohibitInput();
1224 unsigned int tc = combo_doc_class->get() - 1;
1225 if (textclasslist.Load(tc)) {
1226 // we use a copy of the bufferparams because we do not
1227 // want to modify them yet.
1228 BufferParams params = lv_->buffer()->params;
1230 if (lyxrc.auto_reset_options) {
1231 params.textclass = tc;
1232 params.useClassDefaults();
1233 UpdateLayoutDocument(params);
1236 // unable to load new style
1237 WriteAlert(_("Conversion Errors!"),
1238 _("Unable to switch to new document class."),
1239 _("Reverting to original document class."));
1240 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1246 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1252 class_update(params);
1253 paper_update(params);
1254 language_update(params);
1255 options_update(params);
1256 bullets_update(params);