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"
36 #include "BufferView.h"
39 #include "CutAndPaste.h"
40 #include "bufferview_funcs.h"
41 #include "xforms_helpers.h"
43 using Liason::setMinibuffer;
46 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
47 : FormBaseBD(lv, d, _("Document Layout")), fbullet(0)
49 // let the dialog be shown
50 // This is a permanent connection so we won't bother
51 // storing a copy because we won't be disconnecting.
52 d->showDocument.connect(slot(this, &FormDocument::show));
56 void FormDocument::redraw()
58 if( form() && form()->visible )
59 fl_redraw_form( form() );
63 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
64 if (outer_form && outer_form->visible)
65 fl_redraw_form( outer_form );
69 FL_FORM * FormDocument::form() const
71 if (dialog_.get()) return dialog_->form;
76 void FormDocument::build()
81 dialog_.reset(build_tabbed_document());
83 // Manage the restore, ok, apply, restore and cancel/close buttons
84 bc().setOK(dialog_->button_ok);
85 bc().setApply(dialog_->button_apply);
86 bc().setCancel(dialog_->button_cancel);
87 bc().setRestore(dialog_->button_restore);
89 // the document paper form
90 paper_.reset(build_doc_paper());
91 fl_addto_choice(paper_->choice_papersize2,
92 _(" Default | Custom | USletter | USlegal "
93 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
94 fl_addto_choice(paper_->choice_paperpackage,
96 "| A4 small Margins (only portrait) "
97 "| A4 very small Margins (only portrait) "
98 "| A4 very wide margins (only portrait) "));
99 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
100 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
101 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
102 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
103 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
104 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
105 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
106 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
107 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
109 bc().addReadOnly (paper_->choice_paperpackage);
110 bc().addReadOnly (paper_->greoup_radio_orientation);
111 bc().addReadOnly (paper_->radio_portrait);
112 bc().addReadOnly (paper_->radio_landscape);
113 bc().addReadOnly (paper_->choice_papersize2);
114 bc().addReadOnly (paper_->push_use_geometry);
115 bc().addReadOnly (paper_->input_custom_width);
116 bc().addReadOnly (paper_->input_custom_height);
117 bc().addReadOnly (paper_->input_top_margin);
118 bc().addReadOnly (paper_->input_bottom_margin);
119 bc().addReadOnly (paper_->input_left_margin);
120 bc().addReadOnly (paper_->input_right_margin);
121 bc().addReadOnly (paper_->input_head_height);
122 bc().addReadOnly (paper_->input_head_sep);
123 bc().addReadOnly (paper_->input_foot_skip);
125 // the document class form
126 class_.reset(build_doc_class());
129 // The language is a combo-box and has to be inserted manually
130 obj = class_->choice_doc_class;
131 fl_deactivate_object(obj);
132 fl_addto_form(class_->form);
133 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
134 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
135 dialog_->tabbed_folder);
136 combo_doc_class->shortcut("#C",1);
137 combo_doc_class->setcallback(ComboInputCB, this);
139 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
140 cit != textclasslist.end(); ++cit)
142 combo_doc_class->addto((*cit).description());
145 fl_addto_choice(class_->choice_doc_spacing,
146 _(" Single | OneHalf | Double | Other "));
147 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
148 for (n=0; tex_fonts[n][0]; ++n) {
149 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
151 fl_addto_choice(class_->choice_doc_pagestyle,
152 "default|empty|plain|headings|fancy");
153 fl_addto_choice(class_->choice_doc_skip,
154 _(" Smallskip | Medskip | Bigskip | Length "));
155 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
156 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
157 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
159 bc().addReadOnly (class_->radio_doc_indent);
160 bc().addReadOnly (class_->radio_doc_skip);
162 bc().addReadOnly (class_->choice_doc_pagestyle);
163 bc().addReadOnly (class_->choice_doc_fonts);
164 bc().addReadOnly (class_->choice_doc_fontsize);
165 bc().addReadOnly (class_->radio_doc_sides_one);
166 bc().addReadOnly (class_->radio_doc_sides_two);
167 bc().addReadOnly (class_->radio_doc_columns_one);
168 bc().addReadOnly (class_->radio_doc_columns_two);
169 bc().addReadOnly (class_->input_doc_extra);
170 bc().addReadOnly (class_->input_doc_skip);
171 bc().addReadOnly (class_->choice_doc_skip);
172 bc().addReadOnly (class_->choice_doc_spacing);
173 bc().addReadOnly (class_->input_doc_spacing);
175 // the document language form
176 language_.reset(build_doc_language());
177 fl_addto_choice(language_->choice_inputenc,
178 "default|auto|latin1|latin2|latin5|latin9"
179 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
181 // The language is a combo-box and has to be inserted manually
182 obj = language_->choice_language;
183 fl_deactivate_object(obj);
184 fl_addto_form(language_->form);
185 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
186 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
187 dialog_->tabbed_folder);
188 combo_language->shortcut("#L",1);
189 combo_language->setcallback(ComboInputCB, this);
192 for (Languages::const_iterator cit = languages.begin();
193 cit != languages.end(); ++cit) {
194 combo_language->addto((*cit).second.lang());
197 fl_addto_choice(language_->choice_quotes_language,
198 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
199 " «text» | »text« "));
201 bc().addReadOnly (language_->choice_inputenc);
203 // the document options form
204 options_.reset(build_doc_options());
205 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
206 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
207 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
208 fl_set_counter_step(options_->slider_secnumdepth,1,1);
209 fl_set_counter_step(options_->slider_tocdepth,1,1);
210 fl_set_counter_precision(options_->slider_secnumdepth, 0);
211 fl_set_counter_precision(options_->slider_tocdepth, 0);
212 for (n=0; tex_graphics[n][0]; ++n) {
213 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
216 bc().addReadOnly (options_->slider_secnumdepth);
217 bc().addReadOnly (options_->slider_tocdepth);
218 bc().addReadOnly (options_->check_use_amsmath);
219 bc().addReadOnly (options_->input_float_placement);
220 bc().addReadOnly (options_->choice_postscript_driver);
222 // the document bullets form
223 bullets_.reset(build_doc_bullet());
224 fl_addto_choice(bullets_->choice_bullet_size,
225 _(" default | tiny | script | footnote | small |"
226 " normal | large | Large | LARGE | huge | Huge"));
227 fl_set_choice(bullets_->choice_bullet_size, 1);
228 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
229 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
231 bc().addReadOnly (bullets_->bmtable_bullet_panel);
232 bc().addReadOnly (bullets_->choice_bullet_size);
233 bc().addReadOnly (bullets_->input_bullet_latex);
235 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
237 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
239 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
241 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
243 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
245 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
246 lyxerr << _("Your version of libXpm is older than 4.7.\n"
247 "The `bullet' tab of the document dialog "
248 "has been disabled") << '\n';
249 fl_deactivate_object(fbullet);
250 fl_set_object_lcol(fbullet, FL_INACTIVE);
255 void FormDocument::apply()
257 if (!lv_->view()->available() || !dialog_.get())
260 bool redo = class_apply();
262 redo = language_apply() || redo;
263 redo = options_apply() || redo;
267 lv_->view()->redoCurrentBuffer();
269 lv_->buffer()->markDirty();
270 setMinibuffer(lv_, _("Document layout set"));
274 void FormDocument::cancel()
276 // this avoids confusion when reopening
277 BufferParams & param = lv_->buffer()->params;
278 param.temp_bullets[0] = param.user_defined_bullets[0];
279 param.temp_bullets[1] = param.user_defined_bullets[1];
280 param.temp_bullets[2] = param.user_defined_bullets[2];
281 param.temp_bullets[3] = param.user_defined_bullets[3];
286 void FormDocument::update()
293 BufferParams const & params = lv_->buffer()->params;
295 class_update(params);
296 paper_update(params);
297 language_update(params);
298 options_update(params);
299 bullets_update(params);
303 bool FormDocument::input( FL_OBJECT * ob, long data )
305 State cb = static_cast<State>( data );
308 case CHECKCHOICECLASS:
309 CheckChoiceClass(ob, 0);
311 case CHOICEBULLETSIZE:
312 ChoiceBulletSize(ob, 0);
314 case INPUTBULLETLATEX:
315 InputBulletLaTeX(ob, 0);
332 BulletBMTable(ob, 0);
340 case CHECKCHOICECLASS:
341 case CHOICEBULLETSIZE:
342 case INPUTBULLETLATEX:
344 return CheckDocumentInput(ob, 0);
353 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
355 FormDocument * pre = static_cast<FormDocument*>(v);
356 if (combox == pre->combo_doc_class.get())
357 pre->CheckChoiceClass(0, 0);
358 pre->bc().valid(pre->CheckDocumentInput(0,0));
362 bool FormDocument::class_apply()
365 BufferParams ¶ms = lv_->buffer()->params;
367 // If default skip is a "Length" but there's no text in the
368 // input field, reset the kind to "Medskip", which is the default.
369 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
370 !*(fl_get_input (class_->input_doc_skip))) {
371 fl_set_choice (class_->choice_doc_skip, 2);
373 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
374 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
375 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
377 unsigned int const new_class = combo_doc_class->get() - 1;
379 if (params.textclass != new_class) {
380 // try to load new_class
381 if (textclasslist.Load(new_class)) {
382 // successfully loaded
384 setMinibuffer(lv_, _("Converting document to new document class..."));
386 int ret = cap.SwitchLayoutsBetweenClasses(
387 params.textclass, new_class,
388 lv_->buffer()->paragraph);
392 s = _("One paragraph couldn't be converted");
395 s += _(" paragraphs couldn't be converted");
397 WriteAlert(_("Conversion Errors!"),s,
398 _("into chosen document class"));
401 params.textclass = new_class;
403 // problem changing class -- warn user and retain old style
404 WriteAlert(_("Conversion Errors!"),
405 _("Errors loading new document class."),
406 _("Reverting to original document class."));
407 combo_doc_class->select(int(params.textclass) + 1);
410 BufferParams::PARSEP tmpsep = params.paragraph_separation;
411 if (fl_get_button(class_->radio_doc_indent))
412 params.paragraph_separation = BufferParams::PARSEP_INDENT;
414 params.paragraph_separation = BufferParams::PARSEP_SKIP;
415 if (tmpsep != params.paragraph_separation)
418 VSpace tmpdefskip = params.getDefSkip();
419 switch (fl_get_choice (class_->choice_doc_skip)) {
421 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
424 params.setDefSkip(VSpace(VSpace::MEDSKIP));
427 params.setDefSkip(VSpace(VSpace::BIGSKIP));
431 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
433 // DocumentDefskipCB assures that this never happens
435 params.setDefSkip(VSpace(VSpace::MEDSKIP));
438 if (!(tmpdefskip == params.getDefSkip()))
441 if (fl_get_button(class_->radio_doc_columns_two))
445 if (fl_get_button(class_->radio_doc_sides_two))
446 params.sides = LyXTextClass::TwoSides;
448 params.sides = LyXTextClass::OneSide;
450 Spacing tmpSpacing = params.spacing;
451 switch (fl_get_choice(class_->choice_doc_spacing)) {
453 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
454 params.spacing.set(Spacing::Single);
457 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
458 params.spacing.set(Spacing::Onehalf);
461 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
462 params.spacing.set(Spacing::Double);
465 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
466 params.spacing.set(Spacing::Other,
467 fl_get_input(class_->input_doc_spacing));
470 if (tmpSpacing != params.spacing)
473 params.options = fl_get_input(class_->input_doc_extra);
479 void FormDocument::paper_apply()
481 BufferParams & params = lv_->buffer()->params;
484 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
485 params.paperpackage =
486 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
487 params.use_geometry = fl_get_button(paper_->push_use_geometry);
488 if (fl_get_button(paper_->radio_landscape))
489 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
491 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
492 params.paperwidth = fl_get_input(paper_->input_custom_width);
493 params.paperheight = fl_get_input(paper_->input_custom_height);
494 params.leftmargin = fl_get_input(paper_->input_left_margin);
495 params.topmargin = fl_get_input(paper_->input_top_margin);
496 params.rightmargin = fl_get_input(paper_->input_right_margin);
497 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
498 params.headheight = fl_get_input(paper_->input_head_height);
499 params.headsep = fl_get_input(paper_->input_head_sep);
500 params.footskip = fl_get_input(paper_->input_foot_skip);
501 lv_->buffer()->setPaperStuff();
505 bool FormDocument::language_apply()
507 BufferParams & params = lv_->buffer()->params;
508 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
511 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
513 lga = InsetQuotes::EnglishQ;
516 lga = InsetQuotes::SwedishQ;
519 lga = InsetQuotes::GermanQ;
522 lga = InsetQuotes::PolishQ;
525 lga = InsetQuotes::FrenchQ;
528 lga = InsetQuotes::DanishQ;
531 params.quotes_language = lga;
532 if (fl_get_button(language_->radio_single))
533 params.quotes_times = InsetQuotes::SingleQ;
535 params.quotes_times = InsetQuotes::DoubleQ;
537 Language const * old_language = params.language;
538 Language const * new_language =
539 languages.getLanguage(combo_language->getline());
541 new_language = default_language;
543 if (old_language != new_language
544 && old_language->RightToLeft() == new_language->RightToLeft()
545 && !lv_->buffer()->isMultiLingual())
546 lv_->buffer()->changeLanguage(old_language, new_language);
547 if (old_language != new_language) {
550 params.language = new_language;
551 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
557 bool FormDocument::options_apply()
559 BufferParams & params = lv_->buffer()->params;
562 params.graphicsDriver =
563 fl_get_choice_text(options_->choice_postscript_driver);
564 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
566 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
567 if (params.secnumdepth != tmpchar)
569 params.secnumdepth = tmpchar;
571 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
573 params.float_placement =
574 fl_get_input(options_->input_float_placement);
580 void FormDocument::bullets_apply()
582 /* update the bullet settings */
583 BufferParams & param = lv_->buffer()->params;
585 // a little bit of loop unrolling
586 param.user_defined_bullets[0] = param.temp_bullets[0];
587 param.user_defined_bullets[1] = param.temp_bullets[1];
588 param.user_defined_bullets[2] = param.temp_bullets[2];
589 param.user_defined_bullets[3] = param.temp_bullets[3];
593 void FormDocument::class_update(BufferParams const & params)
598 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
600 combo_doc_class->select_text(
601 textclasslist.DescOfClass(params.textclass));
602 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
603 fl_clear_choice(class_->choice_doc_fontsize);
604 fl_addto_choice(class_->choice_doc_fontsize, "default");
605 fl_addto_choice(class_->choice_doc_fontsize,
606 tclass.opt_fontsize().c_str());
607 fl_set_choice(class_->choice_doc_fontsize,
608 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
609 fl_clear_choice(class_->choice_doc_pagestyle);
610 fl_addto_choice(class_->choice_doc_pagestyle, "default");
611 fl_addto_choice(class_->choice_doc_pagestyle,
612 tclass.opt_pagestyle().c_str());
613 fl_set_choice(class_->choice_doc_pagestyle,
614 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
615 fl_set_button(class_->radio_doc_indent, 0);
616 fl_set_button(class_->radio_doc_skip, 0);
617 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
618 fl_set_button(class_->radio_doc_indent, 1);
620 fl_set_button(class_->radio_doc_skip, 1);
621 switch (params.getDefSkip().kind()) {
622 case VSpace::SMALLSKIP:
623 fl_set_choice (class_->choice_doc_skip, 1);
625 case VSpace::MEDSKIP:
626 fl_set_choice (class_->choice_doc_skip, 2);
628 case VSpace::BIGSKIP:
629 fl_set_choice (class_->choice_doc_skip, 3);
632 fl_set_choice (class_->choice_doc_skip, 4);
633 fl_set_input (class_->input_doc_skip,
634 params.getDefSkip().asLyXCommand().c_str());
637 fl_set_choice (class_->choice_doc_skip, 2);
640 fl_set_button(class_->radio_doc_sides_one, 0);
641 fl_set_button(class_->radio_doc_sides_two, 0);
642 if (params.sides == LyXTextClass::TwoSides)
643 fl_set_button(class_->radio_doc_sides_two, 1);
645 fl_set_button(class_->radio_doc_sides_one, 1);
646 fl_set_button(class_->radio_doc_columns_one, 0);
647 fl_set_button(class_->radio_doc_columns_two, 0);
648 if (params.columns == 2)
649 fl_set_button(class_->radio_doc_columns_two, 1);
651 fl_set_button(class_->radio_doc_columns_one, 1);
652 fl_set_input(class_->input_doc_spacing, "");
653 switch (params.spacing.getSpace()) {
654 case Spacing::Default: // nothing bad should happen with this
655 case Spacing::Single:
657 fl_set_choice(class_->choice_doc_spacing, 1);
659 case Spacing::Onehalf:
661 fl_set_choice(class_->choice_doc_spacing, 2);
663 case Spacing::Double:
665 fl_set_choice(class_->choice_doc_spacing, 3);
669 fl_set_choice(class_->choice_doc_spacing, 4);
671 sprintf(sval,"%g",params.spacing.getValue());
672 fl_set_input(class_->input_doc_spacing, sval);
676 if (!params.options.empty())
677 fl_set_input(class_->input_doc_extra, params.options.c_str());
679 fl_set_input(class_->input_doc_extra, "");
683 void FormDocument::language_update(BufferParams const & params)
685 if (!language_.get())
688 combo_language->select_text(params.language->lang());
689 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
690 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
691 fl_set_button(language_->radio_single, 0);
692 fl_set_button(language_->radio_double, 0);
693 if (params.quotes_times == InsetQuotes::SingleQ)
694 fl_set_button(language_->radio_single, 1);
696 fl_set_button(language_->radio_double, 1);
700 void FormDocument::options_update(BufferParams const & params)
705 fl_set_choice_text(options_->choice_postscript_driver,
706 params.graphicsDriver.c_str());
707 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
708 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
709 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
710 if (!params.float_placement.empty())
711 fl_set_input(options_->input_float_placement,
712 params.float_placement.c_str());
714 fl_set_input(options_->input_float_placement, "");
718 void FormDocument::paper_update(BufferParams const & params)
723 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
724 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
725 fl_set_button(paper_->push_use_geometry, params.use_geometry);
726 fl_set_button(paper_->radio_portrait, 0);
727 fl_set_button(paper_->radio_landscape, 0);
728 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
729 fl_set_button(paper_->radio_landscape, 1);
731 fl_set_button(paper_->radio_portrait, 1);
732 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
733 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
734 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
735 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
736 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
737 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
738 fl_set_input(paper_->input_head_height, params.headheight.c_str());
739 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
740 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
741 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
745 void FormDocument::bullets_update(BufferParams const & params)
747 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
750 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
751 setEnabled(fbullet, !isLinuxDoc);
753 if (isLinuxDoc) return;
755 fl_set_button(bullets_->radio_bullet_depth_1, 1);
756 fl_set_input(bullets_->input_bullet_latex,
757 params.user_defined_bullets[0].getText().c_str());
758 fl_set_choice(bullets_->choice_bullet_size,
759 params.user_defined_bullets[0].getSize() + 2);
763 void FormDocument::checkReadOnly()
765 if (bc().readOnly(lv_->buffer()->isReadonly())) {
766 combo_doc_class->deactivate();
767 combo_language->deactivate();
768 fl_set_object_label(dialog_->text_warning,
769 _("Document is read-only."
770 " No changes to layout permitted."));
771 fl_show_object(dialog_->text_warning);
773 combo_doc_class->activate();
774 combo_language->activate();
775 fl_hide_object(dialog_->text_warning);
780 void FormDocument::checkMarginValues()
782 bool const not_empty =
783 strlen(fl_get_input(paper_->input_top_margin)) ||
784 strlen(fl_get_input(paper_->input_bottom_margin)) ||
785 strlen(fl_get_input(paper_->input_left_margin)) ||
786 strlen(fl_get_input(paper_->input_right_margin)) ||
787 strlen(fl_get_input(paper_->input_head_height)) ||
788 strlen(fl_get_input(paper_->input_head_sep)) ||
789 strlen(fl_get_input(paper_->input_foot_skip)) ||
790 strlen(fl_get_input(paper_->input_custom_width)) ||
791 strlen(fl_get_input(paper_->input_custom_height));
793 fl_set_button(paper_->push_use_geometry, 1);
797 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
805 if (ob == paper_->choice_papersize2) {
806 val = fl_get_choice(paper_->choice_papersize2)-1;
807 if (val == BufferParams::VM_PAPER_DEFAULT) {
808 fl_set_button(paper_->push_use_geometry, 0);
811 if ((val != BufferParams::VM_PAPER_USLETTER) &&
812 (val != BufferParams::VM_PAPER_USLEGAL) &&
813 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
814 (val != BufferParams::VM_PAPER_A4) &&
815 (val != BufferParams::VM_PAPER_A5) &&
816 (val != BufferParams::VM_PAPER_B5)) {
817 fl_set_button(paper_->push_use_geometry, 1);
819 fl_set_choice(paper_->choice_paperpackage,
820 BufferParams::PACKAGE_NONE + 1);
822 } else if (ob == paper_->choice_paperpackage) {
823 val = fl_get_choice(paper_->choice_paperpackage)-1;
824 if (val != BufferParams::PACKAGE_NONE) {
825 fl_set_choice(paper_->choice_papersize2,
826 BufferParams::VM_PAPER_DEFAULT + 1);
827 fl_set_button(paper_->push_use_geometry, 0);
829 } else if (ob == class_->input_doc_spacing) {
830 input = fl_get_input(class_->input_doc_spacing);
832 fl_set_choice (class_->choice_doc_spacing, 1);
834 fl_set_choice(class_->choice_doc_spacing, 4);
837 // this has to be all out of if/elseif because it has to deactivate
838 // the document buttons and so the whole stuff has to be tested again.
839 str = fl_get_input(paper_->input_custom_width);
840 ok = ok && (str.empty() || isValidLength(str));
841 str = fl_get_input(paper_->input_custom_height);
842 ok = ok && (str.empty() || isValidLength(str));
843 str = fl_get_input(paper_->input_left_margin);
844 ok = ok && (str.empty() || isValidLength(str));
845 str = fl_get_input(paper_->input_right_margin);
846 ok = ok && (str.empty() || isValidLength(str));
847 str = fl_get_input(paper_->input_top_margin);
848 ok = ok && (str.empty() || isValidLength(str));
849 str = fl_get_input(paper_->input_bottom_margin);
850 ok = ok && (str.empty() || isValidLength(str));
851 str = fl_get_input(paper_->input_head_height);
852 ok = ok && (str.empty() || isValidLength(str));
853 str = fl_get_input(paper_->input_head_sep);
854 ok = ok && (str.empty() || isValidLength(str));
855 str = fl_get_input(paper_->input_foot_skip);
856 ok = ok && (str.empty() || isValidLength(str));
857 // "Synchronize" the choice and the input field, so that it
858 // is impossible to commit senseless data.
859 input = fl_get_input (class_->input_doc_skip);
860 if (ob == class_->input_doc_skip) {
862 fl_set_choice (class_->choice_doc_skip, 2);
863 } else if (isValidGlueLength (input)) {
864 fl_set_choice (class_->choice_doc_skip, 4);
866 fl_set_choice(class_->choice_doc_skip, 4);
870 if (*input && !isValidGlueLength(input))
873 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
875 else if (fl_get_choice(class_->choice_doc_skip) != 4)
876 fl_set_input (class_->input_doc_skip, "");
878 input = fl_get_input(class_->input_doc_spacing);
879 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
881 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
882 fl_set_input (class_->input_doc_spacing, "");
887 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
889 BufferParams & param = lv_->buffer()->params;
891 // convert from 1-6 range to -1-4
892 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
893 fl_set_input(bullets_->input_bullet_latex,
894 param.temp_bullets[current_bullet_depth].getText().c_str());
898 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
900 BufferParams & param = lv_->buffer()->params;
902 param.temp_bullets[current_bullet_depth].
903 setText(fl_get_input(bullets_->input_bullet_latex));
907 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
909 /* Should I do the following: */
910 /* 1. change to the panel that the current bullet belongs in */
911 /* 2. show that bullet as selected */
912 /* 3. change the size setting to the size of the bullet in Q.*/
913 /* 4. display the latex equivalent in the latex box */
915 /* I'm inclined to just go with 3 and 4 at the moment and */
916 /* maybe try to support the others later */
917 BufferParams & param = lv_->buffer()->params;
920 if (cb == BULLETDEPTH1 )
922 else if (cb == BULLETDEPTH2 )
924 else if (cb == BULLETDEPTH3 )
926 else if (cb == BULLETDEPTH4 )
929 switch (fl_get_button_numb(ob)) {
931 // right mouse button resets to default
932 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
934 current_bullet_depth = data;
935 fl_set_input(bullets_->input_bullet_latex,
936 param.temp_bullets[data].getText().c_str());
937 fl_set_choice(bullets_->choice_bullet_size,
938 param.temp_bullets[data].getSize() + 2);
943 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
945 /* Here we have to change the background pixmap to that selected */
946 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
949 if (cb == BULLETPANEL1 )
951 else if (cb == BULLETPANEL2 )
953 else if (cb == BULLETPANEL3 )
955 else if (cb == BULLETPANEL4 )
957 else if (cb == BULLETPANEL5 )
959 else if (cb == BULLETPANEL6 )
962 if (data != current_bullet_panel) {
963 fl_freeze_form(bullets_->form);
964 current_bullet_panel = data;
966 /* free the current pixmap */
967 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
970 /* display the new one */
972 new_panel = "standard";
975 new_panel = "amssymb";
978 new_panel = "psnfss1";
981 new_panel = "psnfss2";
984 new_panel = "psnfss3";
987 new_panel = "psnfss4";
990 /* something very wrong happened */
991 // play it safe for now but should be an exception
992 current_bullet_panel = 0; // standard panel
993 new_panel = "standard";
997 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
998 LibFileSearch("images", new_panel).c_str());
999 fl_redraw_object(bullets_->bmtable_bullet_panel);
1000 fl_unfreeze_form(bullets_->form);
1005 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1007 /* handle the user input by setting the current bullet depth's pixmap */
1008 /* to that extracted from the current chosen position of the BMTable */
1009 /* Don't forget to free the button's old pixmap first. */
1011 BufferParams & param = lv_->buffer()->params;
1012 int bmtable_button = fl_get_bmtable(ob);
1014 /* try to keep the button held down till another is pushed */
1015 /* fl_set_bmtable(ob, 1, bmtable_button); */
1016 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1017 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1018 fl_set_input(bullets_->input_bullet_latex,
1019 param.temp_bullets[current_bullet_depth].getText().c_str());
1023 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1026 ob = class_->choice_doc_class;
1028 lv_->prohibitInput();
1030 unsigned int tc = combo_doc_class->get() - 1;
1031 if (textclasslist.Load(tc)) {
1032 // we use a copy of the bufferparams because we do not
1033 // want to modify them yet.
1034 BufferParams params = lv_->buffer()->params;
1036 if (params.textclass != tc
1037 && AskQuestion(_("Should I set some parameters to"),
1038 _("the defaults of this document class?"))) {
1039 params.textclass = tc;
1040 params.useClassDefaults();
1041 UpdateLayoutDocument(params);
1044 // unable to load new style
1045 WriteAlert(_("Conversion Errors!"),
1046 _("Unable to switch to new document class."),
1047 _("Reverting to original document class."));
1048 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1054 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1060 class_update(params);
1061 paper_update(params);
1062 language_update(params);
1063 options_update(params);
1064 bullets_update(params);