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"
37 #include "BufferView.h"
40 #include "CutAndPaste.h"
41 #include "bufferview_funcs.h"
42 #include "xforms_helpers.h"
45 using Liason::setMinibuffer;
48 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
49 : FormBaseBD(lv, d, _("Document Layout")), fbullet(0)
51 // let the dialog be shown
52 // This is a permanent connection so we won't bother
53 // storing a copy because we won't be disconnecting.
54 d->showDocument.connect(slot(this, &FormDocument::show));
58 void FormDocument::redraw()
60 if( form() && form()->visible )
61 fl_redraw_form( form() );
65 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
66 if (outer_form && outer_form->visible)
67 fl_redraw_form( outer_form );
71 FL_FORM * FormDocument::form() const
73 if (dialog_.get()) return dialog_->form;
78 void FormDocument::build()
83 dialog_.reset(build_tabbed_document());
85 // Manage the restore, ok, apply, restore and cancel/close buttons
86 bc().setOK(dialog_->button_ok);
87 bc().setApply(dialog_->button_apply);
88 bc().setCancel(dialog_->button_cancel);
89 bc().setRestore(dialog_->button_restore);
91 // the document paper form
92 paper_.reset(build_doc_paper());
93 fl_addto_choice(paper_->choice_papersize2,
94 _(" Default | Custom | USletter | USlegal "
95 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
96 fl_addto_choice(paper_->choice_paperpackage,
98 "| A4 small Margins (only portrait) "
99 "| A4 very small Margins (only portrait) "
100 "| A4 very wide margins (only portrait) "));
101 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
102 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
103 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
104 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
105 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
106 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
107 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
108 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
111 bc().addReadOnly (paper_->choice_paperpackage);
112 bc().addReadOnly (paper_->greoup_radio_orientation);
113 bc().addReadOnly (paper_->radio_portrait);
114 bc().addReadOnly (paper_->radio_landscape);
115 bc().addReadOnly (paper_->choice_papersize2);
116 bc().addReadOnly (paper_->push_use_geometry);
117 bc().addReadOnly (paper_->input_custom_width);
118 bc().addReadOnly (paper_->input_custom_height);
119 bc().addReadOnly (paper_->input_top_margin);
120 bc().addReadOnly (paper_->input_bottom_margin);
121 bc().addReadOnly (paper_->input_left_margin);
122 bc().addReadOnly (paper_->input_right_margin);
123 bc().addReadOnly (paper_->input_head_height);
124 bc().addReadOnly (paper_->input_head_sep);
125 bc().addReadOnly (paper_->input_foot_skip);
127 // the document class form
128 class_.reset(build_doc_class());
131 // The language is a combo-box and has to be inserted manually
132 obj = class_->choice_doc_class;
133 fl_deactivate_object(obj);
134 fl_addto_form(class_->form);
135 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
136 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
137 dialog_->tabbed_folder);
138 combo_doc_class->shortcut("#C",1);
139 combo_doc_class->setcallback(ComboInputCB, this);
141 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
142 cit != textclasslist.end(); ++cit)
144 combo_doc_class->addto(cit->description());
147 fl_addto_choice(class_->choice_doc_spacing,
148 _(" Single | OneHalf | Double | Other "));
149 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
150 for (n=0; tex_fonts[n][0]; ++n) {
151 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
153 fl_addto_choice(class_->choice_doc_pagestyle,
154 "default|empty|plain|headings|fancy");
155 fl_addto_choice(class_->choice_doc_skip,
156 _(" Smallskip | Medskip | Bigskip | Length "));
157 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
158 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
159 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
161 bc().addReadOnly (class_->radio_doc_indent);
162 bc().addReadOnly (class_->radio_doc_skip);
164 bc().addReadOnly (class_->choice_doc_pagestyle);
165 bc().addReadOnly (class_->choice_doc_fonts);
166 bc().addReadOnly (class_->choice_doc_fontsize);
167 bc().addReadOnly (class_->radio_doc_sides_one);
168 bc().addReadOnly (class_->radio_doc_sides_two);
169 bc().addReadOnly (class_->radio_doc_columns_one);
170 bc().addReadOnly (class_->radio_doc_columns_two);
171 bc().addReadOnly (class_->input_doc_extra);
172 bc().addReadOnly (class_->input_doc_skip);
173 bc().addReadOnly (class_->choice_doc_skip);
174 bc().addReadOnly (class_->choice_doc_spacing);
175 bc().addReadOnly (class_->input_doc_spacing);
177 // the document language form
178 language_.reset(build_doc_language());
179 fl_addto_choice(language_->choice_inputenc,
180 "default|auto|latin1|latin2|latin5|latin9"
181 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
183 // The language is a combo-box and has to be inserted manually
184 obj = language_->choice_language;
185 fl_deactivate_object(obj);
186 fl_addto_form(language_->form);
187 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
188 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
189 dialog_->tabbed_folder);
190 combo_language->shortcut("#L",1);
191 combo_language->setcallback(ComboInputCB, this);
194 for (Languages::const_iterator cit = languages.begin();
195 cit != languages.end(); ++cit) {
196 combo_language->addto(cit->second.lang());
199 fl_addto_choice(language_->choice_quotes_language,
200 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
201 " «text» | »text« "));
203 bc().addReadOnly (language_->choice_inputenc);
205 // the document options form
206 options_.reset(build_doc_options());
207 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
208 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
209 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
210 fl_set_counter_step(options_->slider_secnumdepth,1,1);
211 fl_set_counter_step(options_->slider_tocdepth,1,1);
212 fl_set_counter_precision(options_->slider_secnumdepth, 0);
213 fl_set_counter_precision(options_->slider_tocdepth, 0);
214 for (n=0; tex_graphics[n][0]; ++n) {
215 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
217 fl_addto_choice(options_->choice_citation_format,
218 _(" Author-year | Numerical "));
220 bc_.addReadOnly (options_->slider_secnumdepth);
221 bc_.addReadOnly (options_->slider_tocdepth);
222 bc_.addReadOnly (options_->check_use_amsmath);
223 bc_.addReadOnly (options_->check_use_natbib);
224 bc_.addReadOnly (options_->choice_citation_format);
225 bc_.addReadOnly (options_->input_float_placement);
226 bc_.addReadOnly (options_->choice_postscript_driver);
228 // the document bullets form
229 bullets_.reset(build_doc_bullet());
230 fl_addto_choice(bullets_->choice_bullet_size,
231 _(" default | tiny | script | footnote | small |"
232 " normal | large | Large | LARGE | huge | Huge"));
233 fl_set_choice(bullets_->choice_bullet_size, 1);
234 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
235 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
237 bc().addReadOnly (bullets_->bmtable_bullet_panel);
238 bc().addReadOnly (bullets_->choice_bullet_size);
239 bc().addReadOnly (bullets_->input_bullet_latex);
241 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
243 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
245 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
247 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
249 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
251 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
252 lyxerr << _("Your version of libXpm is older than 4.7.\n"
253 "The `bullet' tab of the document dialog "
254 "has been disabled") << '\n';
255 fl_deactivate_object(fbullet);
256 fl_set_object_lcol(fbullet, FL_INACTIVE);
261 void FormDocument::apply()
263 if (!lv_->view()->available() || !dialog_.get())
266 bool redo = class_apply();
268 redo = language_apply() || redo;
269 redo = options_apply() || redo;
273 lv_->view()->redoCurrentBuffer();
275 lv_->buffer()->markDirty();
276 setMinibuffer(lv_, _("Document layout set"));
280 void FormDocument::cancel()
282 // this avoids confusion when reopening
283 BufferParams & param = lv_->buffer()->params;
284 param.temp_bullets[0] = param.user_defined_bullets[0];
285 param.temp_bullets[1] = param.user_defined_bullets[1];
286 param.temp_bullets[2] = param.user_defined_bullets[2];
287 param.temp_bullets[3] = param.user_defined_bullets[3];
292 void FormDocument::update()
299 BufferParams const & params = lv_->buffer()->params;
301 class_update(params);
302 paper_update(params);
303 language_update(params);
304 options_update(params);
305 bullets_update(params);
309 bool FormDocument::input( FL_OBJECT * ob, long data )
311 State cb = static_cast<State>( data );
314 case CHECKCHOICECLASS:
315 CheckChoiceClass(ob, 0);
317 case CHOICEBULLETSIZE:
318 ChoiceBulletSize(ob, 0);
320 case INPUTBULLETLATEX:
321 InputBulletLaTeX(ob, 0);
338 BulletBMTable(ob, 0);
346 case CHECKCHOICECLASS:
347 case CHOICEBULLETSIZE:
348 case INPUTBULLETLATEX:
350 return CheckDocumentInput(ob, 0);
359 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
361 FormDocument * pre = static_cast<FormDocument*>(v);
362 if (combox == pre->combo_doc_class.get())
363 pre->CheckChoiceClass(0, 0);
364 pre->bc().valid(pre->CheckDocumentInput(0,0));
368 bool FormDocument::class_apply()
371 BufferParams ¶ms = lv_->buffer()->params;
373 // If default skip is a "Length" but there's no text in the
374 // input field, reset the kind to "Medskip", which is the default.
375 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
376 !*(fl_get_input (class_->input_doc_skip))) {
377 fl_set_choice (class_->choice_doc_skip, 2);
379 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
380 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
381 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
383 unsigned int const new_class = combo_doc_class->get() - 1;
385 if (params.textclass != new_class) {
386 // try to load new_class
387 if (textclasslist.Load(new_class)) {
388 // successfully loaded
390 setMinibuffer(lv_, _("Converting document to new document class..."));
391 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
392 params.textclass, new_class,
393 lv_->buffer()->paragraph);
397 s = _("One paragraph couldn't be converted");
400 s += _(" paragraphs couldn't be converted");
402 WriteAlert(_("Conversion Errors!"),s,
403 _("into chosen document class"));
406 params.textclass = new_class;
408 // problem changing class -- warn user and retain old style
409 WriteAlert(_("Conversion Errors!"),
410 _("Errors loading new document class."),
411 _("Reverting to original document class."));
412 combo_doc_class->select(int(params.textclass) + 1);
415 BufferParams::PARSEP tmpsep = params.paragraph_separation;
416 if (fl_get_button(class_->radio_doc_indent))
417 params.paragraph_separation = BufferParams::PARSEP_INDENT;
419 params.paragraph_separation = BufferParams::PARSEP_SKIP;
420 if (tmpsep != params.paragraph_separation)
423 VSpace tmpdefskip = params.getDefSkip();
424 switch (fl_get_choice (class_->choice_doc_skip)) {
426 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
429 params.setDefSkip(VSpace(VSpace::MEDSKIP));
432 params.setDefSkip(VSpace(VSpace::BIGSKIP));
436 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
438 // DocumentDefskipCB assures that this never happens
440 params.setDefSkip(VSpace(VSpace::MEDSKIP));
443 if (!(tmpdefskip == params.getDefSkip()))
446 if (fl_get_button(class_->radio_doc_columns_two))
450 if (fl_get_button(class_->radio_doc_sides_two))
451 params.sides = LyXTextClass::TwoSides;
453 params.sides = LyXTextClass::OneSide;
455 Spacing tmpSpacing = params.spacing;
456 switch (fl_get_choice(class_->choice_doc_spacing)) {
458 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
459 params.spacing.set(Spacing::Single);
462 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
463 params.spacing.set(Spacing::Onehalf);
466 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
467 params.spacing.set(Spacing::Double);
470 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
471 params.spacing.set(Spacing::Other,
472 fl_get_input(class_->input_doc_spacing));
475 if (tmpSpacing != params.spacing)
478 params.options = fl_get_input(class_->input_doc_extra);
484 void FormDocument::paper_apply()
486 BufferParams & params = lv_->buffer()->params;
489 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
490 params.paperpackage =
491 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
492 params.use_geometry = fl_get_button(paper_->push_use_geometry);
493 if (fl_get_button(paper_->radio_landscape))
494 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
496 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
497 params.paperwidth = fl_get_input(paper_->input_custom_width);
498 params.paperheight = fl_get_input(paper_->input_custom_height);
499 params.leftmargin = fl_get_input(paper_->input_left_margin);
500 params.topmargin = fl_get_input(paper_->input_top_margin);
501 params.rightmargin = fl_get_input(paper_->input_right_margin);
502 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
503 params.headheight = fl_get_input(paper_->input_head_height);
504 params.headsep = fl_get_input(paper_->input_head_sep);
505 params.footskip = fl_get_input(paper_->input_foot_skip);
506 lv_->buffer()->setPaperStuff();
510 bool FormDocument::language_apply()
512 BufferParams & params = lv_->buffer()->params;
513 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
516 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
518 lga = InsetQuotes::EnglishQ;
521 lga = InsetQuotes::SwedishQ;
524 lga = InsetQuotes::GermanQ;
527 lga = InsetQuotes::PolishQ;
530 lga = InsetQuotes::FrenchQ;
533 lga = InsetQuotes::DanishQ;
536 params.quotes_language = lga;
537 if (fl_get_button(language_->radio_single))
538 params.quotes_times = InsetQuotes::SingleQ;
540 params.quotes_times = InsetQuotes::DoubleQ;
542 Language const * old_language = params.language;
543 Language const * new_language =
544 languages.getLanguage(combo_language->getline());
546 new_language = default_language;
548 if (old_language != new_language
549 && old_language->RightToLeft() == new_language->RightToLeft()
550 && !lv_->buffer()->isMultiLingual())
551 lv_->buffer()->changeLanguage(old_language, new_language);
552 if (old_language != new_language) {
555 params.language = new_language;
556 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
562 bool FormDocument::options_apply()
564 BufferParams & params = lv_->buffer()->params;
567 params.graphicsDriver =
568 fl_get_choice_text(options_->choice_postscript_driver);
569 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
570 params.use_natbib = fl_get_button(options_->check_use_natbib);
571 params.use_numerical_citations =
572 fl_get_choice(options_->choice_citation_format)-1;
574 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
575 if (params.secnumdepth != tmpchar)
577 params.secnumdepth = tmpchar;
579 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
581 params.float_placement =
582 fl_get_input(options_->input_float_placement);
588 void FormDocument::bullets_apply()
590 /* update the bullet settings */
591 BufferParams & param = lv_->buffer()->params;
593 // a little bit of loop unrolling
594 param.user_defined_bullets[0] = param.temp_bullets[0];
595 param.user_defined_bullets[1] = param.temp_bullets[1];
596 param.user_defined_bullets[2] = param.temp_bullets[2];
597 param.user_defined_bullets[3] = param.temp_bullets[3];
601 void FormDocument::class_update(BufferParams const & params)
606 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
608 combo_doc_class->select_text(
609 textclasslist.DescOfClass(params.textclass));
610 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
611 fl_clear_choice(class_->choice_doc_fontsize);
612 fl_addto_choice(class_->choice_doc_fontsize, "default");
613 fl_addto_choice(class_->choice_doc_fontsize,
614 tclass.opt_fontsize().c_str());
615 fl_set_choice(class_->choice_doc_fontsize,
616 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
617 fl_clear_choice(class_->choice_doc_pagestyle);
618 fl_addto_choice(class_->choice_doc_pagestyle, "default");
619 fl_addto_choice(class_->choice_doc_pagestyle,
620 tclass.opt_pagestyle().c_str());
621 fl_set_choice(class_->choice_doc_pagestyle,
622 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
623 fl_set_button(class_->radio_doc_indent, 0);
624 fl_set_button(class_->radio_doc_skip, 0);
625 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
626 fl_set_button(class_->radio_doc_indent, 1);
628 fl_set_button(class_->radio_doc_skip, 1);
629 switch (params.getDefSkip().kind()) {
630 case VSpace::SMALLSKIP:
631 fl_set_choice (class_->choice_doc_skip, 1);
633 case VSpace::MEDSKIP:
634 fl_set_choice (class_->choice_doc_skip, 2);
636 case VSpace::BIGSKIP:
637 fl_set_choice (class_->choice_doc_skip, 3);
640 fl_set_choice (class_->choice_doc_skip, 4);
641 fl_set_input (class_->input_doc_skip,
642 params.getDefSkip().asLyXCommand().c_str());
645 fl_set_choice (class_->choice_doc_skip, 2);
648 fl_set_button(class_->radio_doc_sides_one, 0);
649 fl_set_button(class_->radio_doc_sides_two, 0);
650 if (params.sides == LyXTextClass::TwoSides)
651 fl_set_button(class_->radio_doc_sides_two, 1);
653 fl_set_button(class_->radio_doc_sides_one, 1);
654 fl_set_button(class_->radio_doc_columns_one, 0);
655 fl_set_button(class_->radio_doc_columns_two, 0);
656 if (params.columns == 2)
657 fl_set_button(class_->radio_doc_columns_two, 1);
659 fl_set_button(class_->radio_doc_columns_one, 1);
660 fl_set_input(class_->input_doc_spacing, "");
661 switch (params.spacing.getSpace()) {
662 case Spacing::Default: // nothing bad should happen with this
663 case Spacing::Single:
665 fl_set_choice(class_->choice_doc_spacing, 1);
667 case Spacing::Onehalf:
669 fl_set_choice(class_->choice_doc_spacing, 2);
671 case Spacing::Double:
673 fl_set_choice(class_->choice_doc_spacing, 3);
677 fl_set_choice(class_->choice_doc_spacing, 4);
679 sprintf(sval,"%g",params.spacing.getValue());
680 fl_set_input(class_->input_doc_spacing, sval);
684 if (!params.options.empty())
685 fl_set_input(class_->input_doc_extra, params.options.c_str());
687 fl_set_input(class_->input_doc_extra, "");
691 void FormDocument::language_update(BufferParams const & params)
693 if (!language_.get())
696 combo_language->select_text(params.language->lang());
697 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
698 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
699 fl_set_button(language_->radio_single, 0);
700 fl_set_button(language_->radio_double, 0);
701 if (params.quotes_times == InsetQuotes::SingleQ)
702 fl_set_button(language_->radio_single, 1);
704 fl_set_button(language_->radio_double, 1);
708 void FormDocument::options_update(BufferParams const & params)
713 fl_set_choice_text(options_->choice_postscript_driver,
714 params.graphicsDriver.c_str());
715 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
716 fl_set_button(options_->check_use_natbib, params.use_natbib);
717 fl_set_choice(options_->choice_citation_format,
718 int(params.use_numerical_citations)+1);
719 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
720 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
721 if (!params.float_placement.empty())
722 fl_set_input(options_->input_float_placement,
723 params.float_placement.c_str());
725 fl_set_input(options_->input_float_placement, "");
729 void FormDocument::paper_update(BufferParams const & params)
734 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
735 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
736 fl_set_button(paper_->push_use_geometry, params.use_geometry);
737 fl_set_button(paper_->radio_portrait, 0);
738 fl_set_button(paper_->radio_landscape, 0);
739 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
740 fl_set_button(paper_->radio_landscape, 1);
742 fl_set_button(paper_->radio_portrait, 1);
743 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
744 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
745 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
746 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
747 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
748 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
749 fl_set_input(paper_->input_head_height, params.headheight.c_str());
750 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
751 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
752 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
756 void FormDocument::bullets_update(BufferParams const & params)
758 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
761 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
762 setEnabled(fbullet, !isLinuxDoc);
764 if (isLinuxDoc) return;
766 fl_set_button(bullets_->radio_bullet_depth_1, 1);
767 fl_set_input(bullets_->input_bullet_latex,
768 params.user_defined_bullets[0].getText().c_str());
769 fl_set_choice(bullets_->choice_bullet_size,
770 params.user_defined_bullets[0].getSize() + 2);
774 void FormDocument::checkReadOnly()
776 if (bc().readOnly(lv_->buffer()->isReadonly())) {
777 combo_doc_class->deactivate();
778 combo_language->deactivate();
779 fl_set_object_label(dialog_->text_warning,
780 _("Document is read-only."
781 " No changes to layout permitted."));
782 fl_show_object(dialog_->text_warning);
784 combo_doc_class->activate();
785 combo_language->activate();
786 fl_hide_object(dialog_->text_warning);
791 void FormDocument::checkMarginValues()
793 bool const not_empty =
794 strlen(fl_get_input(paper_->input_top_margin)) ||
795 strlen(fl_get_input(paper_->input_bottom_margin)) ||
796 strlen(fl_get_input(paper_->input_left_margin)) ||
797 strlen(fl_get_input(paper_->input_right_margin)) ||
798 strlen(fl_get_input(paper_->input_head_height)) ||
799 strlen(fl_get_input(paper_->input_head_sep)) ||
800 strlen(fl_get_input(paper_->input_foot_skip)) ||
801 strlen(fl_get_input(paper_->input_custom_width)) ||
802 strlen(fl_get_input(paper_->input_custom_height));
804 fl_set_button(paper_->push_use_geometry, 1);
808 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
816 if (ob == paper_->choice_papersize2) {
817 val = fl_get_choice(paper_->choice_papersize2)-1;
818 if (val == BufferParams::VM_PAPER_DEFAULT) {
819 fl_set_button(paper_->push_use_geometry, 0);
822 if ((val != BufferParams::VM_PAPER_USLETTER) &&
823 (val != BufferParams::VM_PAPER_USLEGAL) &&
824 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
825 (val != BufferParams::VM_PAPER_A4) &&
826 (val != BufferParams::VM_PAPER_A5) &&
827 (val != BufferParams::VM_PAPER_B5)) {
828 fl_set_button(paper_->push_use_geometry, 1);
830 fl_set_choice(paper_->choice_paperpackage,
831 BufferParams::PACKAGE_NONE + 1);
833 } else if (ob == paper_->choice_paperpackage) {
834 val = fl_get_choice(paper_->choice_paperpackage)-1;
835 if (val != BufferParams::PACKAGE_NONE) {
836 fl_set_choice(paper_->choice_papersize2,
837 BufferParams::VM_PAPER_DEFAULT + 1);
838 fl_set_button(paper_->push_use_geometry, 0);
840 } else if (ob == class_->input_doc_spacing) {
841 input = fl_get_input(class_->input_doc_spacing);
843 fl_set_choice (class_->choice_doc_spacing, 1);
845 fl_set_choice(class_->choice_doc_spacing, 4);
848 // this has to be all out of if/elseif because it has to deactivate
849 // the document buttons and so the whole stuff has to be tested again.
850 str = fl_get_input(paper_->input_custom_width);
851 ok = ok && (str.empty() || isValidLength(str));
852 str = fl_get_input(paper_->input_custom_height);
853 ok = ok && (str.empty() || isValidLength(str));
854 str = fl_get_input(paper_->input_left_margin);
855 ok = ok && (str.empty() || isValidLength(str));
856 str = fl_get_input(paper_->input_right_margin);
857 ok = ok && (str.empty() || isValidLength(str));
858 str = fl_get_input(paper_->input_top_margin);
859 ok = ok && (str.empty() || isValidLength(str));
860 str = fl_get_input(paper_->input_bottom_margin);
861 ok = ok && (str.empty() || isValidLength(str));
862 str = fl_get_input(paper_->input_head_height);
863 ok = ok && (str.empty() || isValidLength(str));
864 str = fl_get_input(paper_->input_head_sep);
865 ok = ok && (str.empty() || isValidLength(str));
866 str = fl_get_input(paper_->input_foot_skip);
867 ok = ok && (str.empty() || isValidLength(str));
868 // "Synchronize" the choice and the input field, so that it
869 // is impossible to commit senseless data.
870 input = fl_get_input (class_->input_doc_skip);
871 if (ob == class_->input_doc_skip) {
873 fl_set_choice (class_->choice_doc_skip, 2);
874 } else if (isValidGlueLength (input)) {
875 fl_set_choice (class_->choice_doc_skip, 4);
877 fl_set_choice(class_->choice_doc_skip, 4);
881 if (*input && !isValidGlueLength(input))
884 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
886 else if (fl_get_choice(class_->choice_doc_skip) != 4)
887 fl_set_input (class_->input_doc_skip, "");
889 input = fl_get_input(class_->input_doc_spacing);
890 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
892 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
893 fl_set_input (class_->input_doc_spacing, "");
898 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
900 BufferParams & param = lv_->buffer()->params;
902 // convert from 1-6 range to -1-4
903 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
904 fl_set_input(bullets_->input_bullet_latex,
905 param.temp_bullets[current_bullet_depth].getText().c_str());
909 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
911 BufferParams & param = lv_->buffer()->params;
913 param.temp_bullets[current_bullet_depth].
914 setText(fl_get_input(bullets_->input_bullet_latex));
918 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
920 /* Should I do the following: */
921 /* 1. change to the panel that the current bullet belongs in */
922 /* 2. show that bullet as selected */
923 /* 3. change the size setting to the size of the bullet in Q.*/
924 /* 4. display the latex equivalent in the latex box */
926 /* I'm inclined to just go with 3 and 4 at the moment and */
927 /* maybe try to support the others later */
928 BufferParams & param = lv_->buffer()->params;
931 if (cb == BULLETDEPTH1 )
933 else if (cb == BULLETDEPTH2 )
935 else if (cb == BULLETDEPTH3 )
937 else if (cb == BULLETDEPTH4 )
940 switch (fl_get_button_numb(ob)) {
942 // right mouse button resets to default
943 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
945 current_bullet_depth = data;
946 fl_set_input(bullets_->input_bullet_latex,
947 param.temp_bullets[data].getText().c_str());
948 fl_set_choice(bullets_->choice_bullet_size,
949 param.temp_bullets[data].getSize() + 2);
954 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
956 /* Here we have to change the background pixmap to that selected */
957 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
960 if (cb == BULLETPANEL1 )
962 else if (cb == BULLETPANEL2 )
964 else if (cb == BULLETPANEL3 )
966 else if (cb == BULLETPANEL4 )
968 else if (cb == BULLETPANEL5 )
970 else if (cb == BULLETPANEL6 )
973 if (data != current_bullet_panel) {
974 fl_freeze_form(bullets_->form);
975 current_bullet_panel = data;
977 /* free the current pixmap */
978 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
981 /* display the new one */
983 new_panel = "standard";
986 new_panel = "amssymb";
989 new_panel = "psnfss1";
992 new_panel = "psnfss2";
995 new_panel = "psnfss3";
998 new_panel = "psnfss4";
1001 /* something very wrong happened */
1002 // play it safe for now but should be an exception
1003 current_bullet_panel = 0; // standard panel
1004 new_panel = "standard";
1007 new_panel += ".xpm";
1008 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1009 LibFileSearch("images", new_panel).c_str());
1010 fl_redraw_object(bullets_->bmtable_bullet_panel);
1011 fl_unfreeze_form(bullets_->form);
1016 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1018 /* handle the user input by setting the current bullet depth's pixmap */
1019 /* to that extracted from the current chosen position of the BMTable */
1020 /* Don't forget to free the button's old pixmap first. */
1022 BufferParams & param = lv_->buffer()->params;
1023 int bmtable_button = fl_get_bmtable(ob);
1025 /* try to keep the button held down till another is pushed */
1026 /* fl_set_bmtable(ob, 1, bmtable_button); */
1027 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1028 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1029 fl_set_input(bullets_->input_bullet_latex,
1030 param.temp_bullets[current_bullet_depth].getText().c_str());
1034 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1037 ob = class_->choice_doc_class;
1039 lv_->prohibitInput();
1041 unsigned int tc = combo_doc_class->get() - 1;
1042 if (textclasslist.Load(tc)) {
1043 // we use a copy of the bufferparams because we do not
1044 // want to modify them yet.
1045 BufferParams params = lv_->buffer()->params;
1047 if (params.textclass != tc
1048 && AskQuestion(_("Should I set some parameters to"),
1049 _("the defaults of this document class?"))) {
1050 params.textclass = tc;
1051 params.useClassDefaults();
1052 UpdateLayoutDocument(params);
1055 // unable to load new style
1056 WriteAlert(_("Conversion Errors!"),
1057 _("Unable to switch to new document class."),
1058 _("Reverting to original document class."));
1059 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1065 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1071 class_update(params);
1072 paper_update(params);
1073 language_update(params);
1074 options_update(params);
1075 bullets_update(params);