1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include "lyx_gui_misc.h"
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
22 #include "FormDocument.h"
23 #include "form_document.h"
27 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "insets/insetquotes.h"
32 #include "support/filetools.h"
35 #include "BufferView.h"
38 #include "CutAndPaste.h"
39 #include "bufferview_funcs.h"
41 #ifdef CXX_WORKING_NAMESPACES
42 using Liason::setMinibuffer;
45 #define USE_CLASS_COMBO 1
47 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
48 : FormBaseBD(lv, d, _("Document Layout"),
49 new NoRepeatedApplyReadOnlyPolicy),
50 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
51 bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
52 fbullet(0), combo_language(0), combo_doc_class(0)
54 // let the popup be shown
55 // This is a permanent connection so we won't bother
56 // storing a copy because we won't be disconnecting.
57 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
61 FormDocument::~FormDocument()
63 #ifdef USE_CLASS_COMBO
64 delete combo_doc_class;
68 delete combo_language;
76 FL_FORM * FormDocument::form() const
78 if (dialog_) return dialog_->form;
83 void FormDocument::build()
88 dialog_ = build_tabbed_document();
90 // manage the restore, ok, apply and cancel/close buttons
91 bc_.setOK(dialog_->button_ok);
92 bc_.setApply(dialog_->button_apply);
93 bc_.setCancel(dialog_->button_cancel);
94 bc_.setUndoAll(dialog_->button_restore);
97 // Workaround dumb xforms sizing bug
101 // the document paper form
102 paper_ = build_doc_paper();
103 fl_addto_choice(paper_->choice_papersize2,
104 _(" Default | Custom | USletter | USlegal "
105 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
106 fl_addto_choice(paper_->choice_paperpackage,
108 "| A4 small Margins (only portrait) "
109 "| A4 very small Margins (only portrait) "
110 "| A4 very wide margins (only portrait) "));
111 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
118 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
119 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
121 bc_.addReadOnly (paper_->choice_paperpackage);
122 bc_.addReadOnly (paper_->greoup_radio_orientation);
123 bc_.addReadOnly (paper_->radio_portrait);
124 bc_.addReadOnly (paper_->radio_landscape);
125 bc_.addReadOnly (paper_->choice_papersize2);
126 bc_.addReadOnly (paper_->push_use_geometry);
127 bc_.addReadOnly (paper_->input_custom_width);
128 bc_.addReadOnly (paper_->input_custom_height);
129 bc_.addReadOnly (paper_->input_top_margin);
130 bc_.addReadOnly (paper_->input_bottom_margin);
131 bc_.addReadOnly (paper_->input_left_margin);
132 bc_.addReadOnly (paper_->input_right_margin);
133 bc_.addReadOnly (paper_->input_head_height);
134 bc_.addReadOnly (paper_->input_head_sep);
135 bc_.addReadOnly (paper_->input_foot_skip);
137 // the document class form
138 class_ = build_doc_class();
141 #ifdef USE_CLASS_COMBO
142 // The language is a combo-box and has to be inserted manually
143 obj = class_->choice_doc_class;
144 fl_addto_form(class_->form);
145 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
146 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
147 combo_doc_class->shortcut("#C",1);
148 combo_doc_class->setcallback(ComboInputCB, this);
150 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
151 cit != textclasslist.end(); ++cit)
153 combo_doc_class->addto((*cit).description());
156 fl_clear_choice(class_->choice_doc_class);
157 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
158 cit != textclasslist.end(); ++cit)
160 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
163 fl_addto_choice(class_->choice_doc_spacing,
164 _(" Single | OneHalf | Double | Other "));
165 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
166 for (n=0; tex_fonts[n][0]; ++n) {
167 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
169 fl_addto_choice(class_->choice_doc_pagestyle,
170 "default|empty|plain|headings|fancy");
171 fl_addto_choice(class_->choice_doc_skip,
172 _(" Smallskip | Medskip | Bigskip | Length "));
173 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
174 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
175 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
177 bc_.addReadOnly (class_->radio_doc_indent);
178 bc_.addReadOnly (class_->radio_doc_skip);
179 #ifndef USE_CLASS_COMBO
180 bc_.addReadOnly (class_->choice_doc_class);
182 bc_.addReadOnly (class_->choice_doc_pagestyle);
183 bc_.addReadOnly (class_->choice_doc_fonts);
184 bc_.addReadOnly (class_->choice_doc_fontsize);
185 bc_.addReadOnly (class_->radio_doc_sides_one);
186 bc_.addReadOnly (class_->radio_doc_sides_two);
187 bc_.addReadOnly (class_->radio_doc_columns_one);
188 bc_.addReadOnly (class_->radio_doc_columns_two);
189 bc_.addReadOnly (class_->input_doc_extra);
190 bc_.addReadOnly (class_->input_doc_skip);
191 bc_.addReadOnly (class_->choice_doc_skip);
192 bc_.addReadOnly (class_->choice_doc_spacing);
193 bc_.addReadOnly (class_->input_doc_spacing);
195 // the document language form
196 language_ = build_doc_language();
197 fl_addto_choice(language_->choice_inputenc,
198 "default|auto|latin1|latin2|latin5"
199 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
201 // The language is a combo-box and has to be inserted manually
202 obj = language_->choice_language;
203 fl_addto_form(language_->form);
204 combo_language = new Combox(FL_COMBOX_DROPLIST);
205 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
206 combo_language->shortcut("#L",1);
207 combo_language->setcallback(ComboInputCB, this);
209 // "default" is not part of the languages array any more.
210 #ifdef DO_USE_DEFAULT_LANGUAGE
211 combo_language->addto("default");
213 for (Languages::const_iterator cit = languages.begin();
214 cit != languages.end(); ++cit) {
215 combo_language->addto((*cit).second.lang());
218 fl_addto_choice(language_->choice_quotes_language,
219 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
220 " «text» | »text« "));
222 bc_.addReadOnly (language_->choice_language);
223 bc_.addReadOnly (language_->choice_inputenc);
225 // the document options form
226 options_ = build_doc_options();
227 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
228 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
229 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
230 fl_set_counter_step(options_->slider_secnumdepth,1,1);
231 fl_set_counter_step(options_->slider_tocdepth,1,1);
232 fl_set_counter_precision(options_->slider_secnumdepth, 0);
233 fl_set_counter_precision(options_->slider_tocdepth, 0);
234 for (n=0; tex_graphics[n][0]; ++n) {
235 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
238 bc_.addReadOnly (options_->slider_secnumdepth);
239 bc_.addReadOnly (options_->slider_tocdepth);
240 bc_.addReadOnly (options_->check_use_amsmath);
241 bc_.addReadOnly (options_->input_float_placement);
242 bc_.addReadOnly (options_->choice_postscript_driver);
244 // the document bullets form
245 bullets_ = build_doc_bullet();
246 fl_addto_choice(bullets_->choice_bullet_size,
247 _(" default | tiny | script | footnote | small |"
248 " normal | large | Large | LARGE | huge | Huge"));
249 fl_set_choice(bullets_->choice_bullet_size, 1);
250 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
251 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
253 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
254 bc_.addReadOnly (bullets_->choice_bullet_size);
255 bc_.addReadOnly (bullets_->input_bullet_latex);
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
259 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
261 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
263 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
265 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
267 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
268 lyxerr << _("Your version of libXpm is older than 4.7.\n"
269 "The `bullet' tab of the document popup "
270 "has been disabled") << '\n';
271 fl_deactivate_object(fbullet);
272 fl_set_object_lcol(fbullet, FL_INACTIVE);
277 void FormDocument::apply()
279 if (!lv_->view()->available() || !dialog_)
282 bool redo = class_apply();
284 redo = language_apply() || redo;
285 redo = options_apply() || redo;
289 lv_->view()->redoCurrentBuffer();
291 lv_->buffer()->markDirty();
292 setMinibuffer(lv_, _("Document layout set"));
296 void FormDocument::cancel()
298 // this avoids confusion when reopening
299 BufferParams & param = lv_->buffer()->params;
300 param.temp_bullets[0] = param.user_defined_bullets[0];
301 param.temp_bullets[1] = param.user_defined_bullets[1];
302 param.temp_bullets[2] = param.user_defined_bullets[2];
303 param.temp_bullets[3] = param.user_defined_bullets[3];
308 void FormDocument::update()
315 BufferParams const & params = lv_->buffer()->params;
317 class_update(params);
318 paper_update(params);
319 language_update(params);
320 options_update(params);
321 bullets_update(params);
325 bool FormDocument::input( FL_OBJECT * ob, long data )
327 State cb = static_cast<State>( data );
330 case CHECKCHOICECLASS:
331 CheckChoiceClass(ob, 0);
333 case CHOICEBULLETSIZE:
334 ChoiceBulletSize(ob, 0);
336 case INPUTBULLETLATEX:
337 InputBulletLaTeX(ob, 0);
354 BulletBMTable(ob, 0);
362 case CHECKCHOICECLASS:
363 case CHOICEBULLETSIZE:
364 case INPUTBULLETLATEX:
366 return CheckDocumentInput(ob, 0);
375 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
377 FormDocument * pre = static_cast<FormDocument*>(v);
378 if (combox == pre->combo_doc_class)
379 pre->CheckChoiceClass(0, 0);
380 pre->bc_.valid(pre->CheckDocumentInput(0,0));
384 bool FormDocument::class_apply()
387 BufferParams ¶ms = lv_->buffer()->params;
389 // If default skip is a "Length" but there's no text in the
390 // input field, reset the kind to "Medskip", which is the default.
391 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
392 !*(fl_get_input (class_->input_doc_skip))) {
393 fl_set_choice (class_->choice_doc_skip, 2);
395 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
396 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
397 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
399 #ifdef USE_CLASS_COMBO
400 unsigned int const new_class = combo_doc_class->get() - 1;
402 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
404 if (params.textclass != new_class) {
405 // try to load new_class
406 if (textclasslist.Load(new_class)) {
407 // successfully loaded
409 setMinibuffer(lv_, _("Converting document to new document class..."));
411 int ret = cap.SwitchLayoutsBetweenClasses(
412 params.textclass, new_class,
413 lv_->buffer()->paragraph);
417 s = _("One paragraph couldn't be converted");
420 s += _(" paragraphs couldn't be converted");
422 WriteAlert(_("Conversion Errors!"),s,
423 _("into chosen document class"));
426 params.textclass = new_class;
428 // problem changing class -- warn user and retain old style
429 WriteAlert(_("Conversion Errors!"),
430 _("Errors loading new document class."),
431 _("Reverting to original document class."));
432 #ifdef USE_CLASS_COMBO
433 combo_doc_class->select(int(params.textclass) + 1);
435 fl_set_choice(class_->choice_doc_class,
436 params.textclass + 1);
440 BufferParams::PARSEP tmpsep = params.paragraph_separation;
441 if (fl_get_button(class_->radio_doc_indent))
442 params.paragraph_separation = BufferParams::PARSEP_INDENT;
444 params.paragraph_separation = BufferParams::PARSEP_SKIP;
445 if (tmpsep != params.paragraph_separation)
448 VSpace tmpdefskip = params.getDefSkip();
449 switch (fl_get_choice (class_->choice_doc_skip)) {
451 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
454 params.setDefSkip(VSpace(VSpace::MEDSKIP));
457 params.setDefSkip(VSpace(VSpace::BIGSKIP));
461 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
463 // DocumentDefskipCB assures that this never happens
465 params.setDefSkip(VSpace(VSpace::MEDSKIP));
468 if (!(tmpdefskip == params.getDefSkip()))
471 if (fl_get_button(class_->radio_doc_columns_two))
475 if (fl_get_button(class_->radio_doc_sides_two))
476 params.sides = LyXTextClass::TwoSides;
478 params.sides = LyXTextClass::OneSide;
480 Spacing tmpSpacing = params.spacing;
481 switch (fl_get_choice(class_->choice_doc_spacing)) {
483 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
484 params.spacing.set(Spacing::Single);
487 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
488 params.spacing.set(Spacing::Onehalf);
491 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
492 params.spacing.set(Spacing::Double);
495 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
496 params.spacing.set(Spacing::Other,
497 fl_get_input(class_->input_doc_spacing));
500 if (tmpSpacing != params.spacing)
503 params.options = fl_get_input(class_->input_doc_extra);
509 void FormDocument::paper_apply()
511 BufferParams & params = lv_->buffer()->params;
514 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
515 params.paperpackage =
516 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
517 params.use_geometry = fl_get_button(paper_->push_use_geometry);
518 if (fl_get_button(paper_->radio_landscape))
519 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
521 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
522 params.paperwidth = fl_get_input(paper_->input_custom_width);
523 params.paperheight = fl_get_input(paper_->input_custom_height);
524 params.leftmargin = fl_get_input(paper_->input_left_margin);
525 params.topmargin = fl_get_input(paper_->input_top_margin);
526 params.rightmargin = fl_get_input(paper_->input_right_margin);
527 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
528 params.headheight = fl_get_input(paper_->input_head_height);
529 params.headsep = fl_get_input(paper_->input_head_sep);
530 params.footskip = fl_get_input(paper_->input_foot_skip);
531 lv_->buffer()->setPaperStuff();
535 bool FormDocument::language_apply()
537 BufferParams & params = lv_->buffer()->params;
538 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
541 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
543 lga = InsetQuotes::EnglishQ;
546 lga = InsetQuotes::SwedishQ;
549 lga = InsetQuotes::GermanQ;
552 lga = InsetQuotes::PolishQ;
555 lga = InsetQuotes::FrenchQ;
558 lga = InsetQuotes::DanishQ;
561 params.quotes_language = lga;
562 if (fl_get_button(language_->radio_single))
563 params.quotes_times = InsetQuotes::SingleQ;
565 params.quotes_times = InsetQuotes::DoubleQ;
567 Language const * old_language = params.language;
568 Language const * new_language =
569 languages.getLanguage(combo_language->getline());
571 new_language = default_language;
573 if (old_language != new_language
574 && old_language->RightToLeft() == new_language->RightToLeft()
575 && !lv_->buffer()->isMultiLingual())
576 lv_->buffer()->ChangeLanguage(old_language, new_language);
577 if (old_language != new_language) {
580 params.language = new_language;
581 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
587 bool FormDocument::options_apply()
589 BufferParams & params = lv_->buffer()->params;
592 params.graphicsDriver =
593 fl_get_choice_text(options_->choice_postscript_driver);
594 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
596 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
597 if (params.secnumdepth != tmpchar)
599 params.secnumdepth = tmpchar;
601 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
603 params.float_placement =
604 fl_get_input(options_->input_float_placement);
610 void FormDocument::bullets_apply()
612 /* update the bullet settings */
613 BufferParams & param = lv_->buffer()->params;
615 // a little bit of loop unrolling
616 param.user_defined_bullets[0] = param.temp_bullets[0];
617 param.user_defined_bullets[1] = param.temp_bullets[1];
618 param.user_defined_bullets[2] = param.temp_bullets[2];
619 param.user_defined_bullets[3] = param.temp_bullets[3];
623 void FormDocument::class_update(BufferParams const & params)
628 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
630 #ifdef USE_CLASS_COMBO
631 combo_doc_class->select_text(
632 textclasslist.DescOfClass(params.textclass));
634 fl_set_choice_text(class_->choice_doc_class,
635 textclasslist.DescOfClass(params.textclass).c_str());
637 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
638 fl_clear_choice(class_->choice_doc_fontsize);
639 fl_addto_choice(class_->choice_doc_fontsize, "default");
640 fl_addto_choice(class_->choice_doc_fontsize,
641 tclass.opt_fontsize().c_str());
642 fl_set_choice(class_->choice_doc_fontsize,
643 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
644 fl_clear_choice(class_->choice_doc_pagestyle);
645 fl_addto_choice(class_->choice_doc_pagestyle, "default");
646 fl_addto_choice(class_->choice_doc_pagestyle,
647 tclass.opt_pagestyle().c_str());
648 fl_set_choice(class_->choice_doc_pagestyle,
649 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
650 fl_set_button(class_->radio_doc_indent, 0);
651 fl_set_button(class_->radio_doc_skip, 0);
652 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
653 fl_set_button(class_->radio_doc_indent, 1);
655 fl_set_button(class_->radio_doc_skip, 1);
656 switch (params.getDefSkip().kind()) {
657 case VSpace::SMALLSKIP:
658 fl_set_choice (class_->choice_doc_skip, 1);
660 case VSpace::MEDSKIP:
661 fl_set_choice (class_->choice_doc_skip, 2);
663 case VSpace::BIGSKIP:
664 fl_set_choice (class_->choice_doc_skip, 3);
667 fl_set_choice (class_->choice_doc_skip, 4);
668 fl_set_input (class_->input_doc_skip,
669 params.getDefSkip().asLyXCommand().c_str());
672 fl_set_choice (class_->choice_doc_skip, 2);
675 fl_set_button(class_->radio_doc_sides_one, 0);
676 fl_set_button(class_->radio_doc_sides_two, 0);
677 if (params.sides == LyXTextClass::TwoSides)
678 fl_set_button(class_->radio_doc_sides_two, 1);
680 fl_set_button(class_->radio_doc_sides_one, 1);
681 fl_set_button(class_->radio_doc_columns_one, 0);
682 fl_set_button(class_->radio_doc_columns_two, 0);
683 if (params.columns == 2)
684 fl_set_button(class_->radio_doc_columns_two, 1);
686 fl_set_button(class_->radio_doc_columns_one, 1);
687 fl_set_input(class_->input_doc_spacing, "");
688 switch (params.spacing.getSpace()) {
689 case Spacing::Default: // nothing bad should happen with this
690 case Spacing::Single:
692 fl_set_choice(class_->choice_doc_spacing, 1);
694 case Spacing::Onehalf:
696 fl_set_choice(class_->choice_doc_spacing, 2);
698 case Spacing::Double:
700 fl_set_choice(class_->choice_doc_spacing, 3);
704 fl_set_choice(class_->choice_doc_spacing, 4);
706 sprintf(sval,"%g",params.spacing.getValue());
707 fl_set_input(class_->input_doc_spacing, sval);
711 if (!params.options.empty())
712 fl_set_input(class_->input_doc_extra, params.options.c_str());
714 fl_set_input(class_->input_doc_extra, "");
718 void FormDocument::language_update(BufferParams const & params)
723 combo_language->select_text(params.language->lang());
724 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
725 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
726 fl_set_button(language_->radio_single, 0);
727 fl_set_button(language_->radio_double, 0);
728 if (params.quotes_times == InsetQuotes::SingleQ)
729 fl_set_button(language_->radio_single, 1);
731 fl_set_button(language_->radio_double, 1);
735 void FormDocument::options_update(BufferParams const & params)
740 fl_set_choice_text(options_->choice_postscript_driver,
741 params.graphicsDriver.c_str());
742 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
743 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
744 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
745 if (!params.float_placement.empty())
746 fl_set_input(options_->input_float_placement,
747 params.float_placement.c_str());
749 fl_set_input(options_->input_float_placement, "");
753 void FormDocument::paper_update(BufferParams const & params)
758 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
759 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
760 fl_set_button(paper_->push_use_geometry, params.use_geometry);
761 fl_set_button(paper_->radio_portrait, 0);
762 fl_set_button(paper_->radio_landscape, 0);
763 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
764 fl_set_button(paper_->radio_landscape, 1);
766 fl_set_button(paper_->radio_portrait, 1);
767 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
768 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
769 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
770 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
771 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
772 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
773 fl_set_input(paper_->input_head_height, params.headheight.c_str());
774 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
775 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
776 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
780 void FormDocument::bullets_update(BufferParams const & params)
782 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
785 if (lv_->buffer()->isLinuxDoc()) {
786 fl_deactivate_object(fbullet);
787 fl_set_object_lcol(fbullet, FL_INACTIVE);
790 fl_activate_object(fbullet);
791 fl_set_object_lcol(fbullet, FL_BLACK);
794 fl_set_button(bullets_->radio_bullet_depth_1, 1);
795 fl_set_input(bullets_->input_bullet_latex,
796 params.user_defined_bullets[0].getText().c_str());
797 fl_set_choice(bullets_->choice_bullet_size,
798 params.user_defined_bullets[0].getSize() + 2);
802 void FormDocument::checkReadOnly()
804 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
805 combo_doc_class->deactivate();
806 combo_language->deactivate();
807 fl_set_object_label(dialog_->text_warning,
808 _("Document is read-only."
809 " No changes to layout permitted."));
810 fl_show_object(dialog_->text_warning);
812 combo_doc_class->activate();
813 combo_language->activate();
814 fl_hide_object(dialog_->text_warning);
819 void FormDocument::checkMarginValues()
821 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
822 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
823 !strlen(fl_get_input(paper_->input_left_margin)) &&
824 !strlen(fl_get_input(paper_->input_right_margin)) &&
825 !strlen(fl_get_input(paper_->input_head_height)) &&
826 !strlen(fl_get_input(paper_->input_head_sep)) &&
827 !strlen(fl_get_input(paper_->input_foot_skip)) &&
828 !strlen(fl_get_input(paper_->input_custom_width)) &&
829 !strlen(fl_get_input(paper_->input_custom_height)));
831 fl_set_button(paper_->push_use_geometry, 1);
834 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
842 if (ob == paper_->choice_papersize2) {
843 val = fl_get_choice(paper_->choice_papersize2)-1;
844 if (val == BufferParams::VM_PAPER_DEFAULT) {
845 fl_set_button(paper_->push_use_geometry, 0);
848 if ((val != BufferParams::VM_PAPER_USLETTER) &&
849 (val != BufferParams::VM_PAPER_USLEGAL) &&
850 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
851 (val != BufferParams::VM_PAPER_A4) &&
852 (val != BufferParams::VM_PAPER_A5) &&
853 (val != BufferParams::VM_PAPER_B5)) {
854 fl_set_button(paper_->push_use_geometry, 1);
856 fl_set_choice(paper_->choice_paperpackage,
857 BufferParams::PACKAGE_NONE + 1);
859 } else if (ob == paper_->choice_paperpackage) {
860 val = fl_get_choice(paper_->choice_paperpackage)-1;
861 if (val != BufferParams::PACKAGE_NONE) {
862 fl_set_choice(paper_->choice_papersize2,
863 BufferParams::VM_PAPER_DEFAULT + 1);
864 fl_set_button(paper_->push_use_geometry, 0);
866 } else if (ob == class_->input_doc_spacing) {
867 input = fl_get_input(class_->input_doc_spacing);
869 fl_set_choice (class_->choice_doc_spacing, 1);
871 fl_set_choice(class_->choice_doc_spacing, 4);
874 // this has to be all out of if/elseif because it has to deactivate
875 // the document buttons and so the whole stuff has to be tested again.
876 str = fl_get_input(paper_->input_custom_width);
877 ok = ok && (str.empty() || isValidLength(str));
878 str = fl_get_input(paper_->input_custom_height);
879 ok = ok && (str.empty() || isValidLength(str));
880 str = fl_get_input(paper_->input_left_margin);
881 ok = ok && (str.empty() || isValidLength(str));
882 str = fl_get_input(paper_->input_right_margin);
883 ok = ok && (str.empty() || isValidLength(str));
884 str = fl_get_input(paper_->input_top_margin);
885 ok = ok && (str.empty() || isValidLength(str));
886 str = fl_get_input(paper_->input_bottom_margin);
887 ok = ok && (str.empty() || isValidLength(str));
888 str = fl_get_input(paper_->input_head_height);
889 ok = ok && (str.empty() || isValidLength(str));
890 str = fl_get_input(paper_->input_head_sep);
891 ok = ok && (str.empty() || isValidLength(str));
892 str = fl_get_input(paper_->input_foot_skip);
893 ok = ok && (str.empty() || isValidLength(str));
894 // "Synchronize" the choice and the input field, so that it
895 // is impossible to commit senseless data.
896 input = fl_get_input (class_->input_doc_skip);
897 if (ob == class_->input_doc_skip) {
899 fl_set_choice (class_->choice_doc_skip, 2);
900 } else if (isValidGlueLength (input)) {
901 fl_set_choice (class_->choice_doc_skip, 4);
903 fl_set_choice(class_->choice_doc_skip, 4);
907 if (*input && !isValidGlueLength(input))
910 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
912 else if (fl_get_choice(class_->choice_doc_skip) != 4)
913 fl_set_input (class_->input_doc_skip, "");
915 input = fl_get_input(class_->input_doc_spacing);
916 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
918 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
919 fl_set_input (class_->input_doc_spacing, "");
924 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
926 BufferParams & param = lv_->buffer()->params;
928 // convert from 1-6 range to -1-4
929 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
930 fl_set_input(bullets_->input_bullet_latex,
931 param.temp_bullets[current_bullet_depth].getText().c_str());
935 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
937 BufferParams & param = lv_->buffer()->params;
939 param.temp_bullets[current_bullet_depth].
940 setText(fl_get_input(bullets_->input_bullet_latex));
944 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
946 /* Should I do the following: */
947 /* 1. change to the panel that the current bullet belongs in */
948 /* 2. show that bullet as selected */
949 /* 3. change the size setting to the size of the bullet in Q.*/
950 /* 4. display the latex equivalent in the latex box */
952 /* I'm inclined to just go with 3 and 4 at the moment and */
953 /* maybe try to support the others later */
954 BufferParams & param = lv_->buffer()->params;
957 if (cb == BULLETDEPTH1 )
959 else if (cb == BULLETDEPTH2 )
961 else if (cb == BULLETDEPTH3 )
963 else if (cb == BULLETDEPTH4 )
966 switch (fl_get_button_numb(ob)) {
968 // right mouse button resets to default
969 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
971 current_bullet_depth = data;
972 fl_set_input(bullets_->input_bullet_latex,
973 param.temp_bullets[data].getText().c_str());
974 fl_set_choice(bullets_->choice_bullet_size,
975 param.temp_bullets[data].getSize() + 2);
980 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
982 /* Here we have to change the background pixmap to that selected */
983 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
986 if (cb == BULLETPANEL1 )
988 else if (cb == BULLETPANEL2 )
990 else if (cb == BULLETPANEL3 )
992 else if (cb == BULLETPANEL4 )
994 else if (cb == BULLETPANEL5 )
996 else if (cb == BULLETPANEL6 )
999 if (data != current_bullet_panel) {
1000 fl_freeze_form(bullets_->form);
1001 current_bullet_panel = data;
1003 /* free the current pixmap */
1004 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1007 /* display the new one */
1009 new_panel = "standard";
1012 new_panel = "amssymb";
1015 new_panel = "psnfss1";
1018 new_panel = "psnfss2";
1021 new_panel = "psnfss3";
1024 new_panel = "psnfss4";
1027 /* something very wrong happened */
1028 // play it safe for now but should be an exception
1029 current_bullet_panel = 0; // standard panel
1030 new_panel = "standard";
1033 new_panel += ".xpm";
1034 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1035 LibFileSearch("images", new_panel).c_str());
1036 fl_redraw_object(bullets_->bmtable_bullet_panel);
1037 fl_unfreeze_form(bullets_->form);
1042 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1044 /* handle the user input by setting the current bullet depth's pixmap */
1045 /* to that extracted from the current chosen position of the BMTable */
1046 /* Don't forget to free the button's old pixmap first. */
1048 BufferParams & param = lv_->buffer()->params;
1049 int bmtable_button = fl_get_bmtable(ob);
1051 /* try to keep the button held down till another is pushed */
1052 /* fl_set_bmtable(ob, 1, bmtable_button); */
1053 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1054 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1055 fl_set_input(bullets_->input_bullet_latex,
1056 param.temp_bullets[current_bullet_depth].getText().c_str());
1060 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1063 ob = class_->choice_doc_class;
1065 ProhibitInput(lv_->view());
1067 #ifdef USE_CLASS_COMBO
1068 int tc = combo_doc_class->get() - 1;
1069 string tct = combo_doc_class->getline();
1071 int tc = fl_get_choice(ob) - 1;
1072 string tct = fl_get_choice_text(ob);
1074 if (textclasslist.Load(tc)) {
1075 if (AskQuestion(_("Should I set some parameters to"), tct,
1076 _("the defaults of this document class?"))) {
1077 BufferParams & params = lv_->buffer()->params;
1079 params.textclass = tc;
1080 params.useClassDefaults();
1081 UpdateLayoutDocument(params);
1084 // unable to load new style
1085 WriteAlert(_("Conversion Errors!"),
1086 _("Unable to switch to new document class."),
1087 _("Reverting to original document class."));
1088 #ifdef USE_CLASS_COMBO
1089 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1091 fl_set_choice(class_->choice_doc_class,
1092 lv_->buffer()->params.textclass + 1);
1095 AllowInput(lv_->view());
1099 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1105 class_update(params);
1106 paper_update(params);
1107 language_update(params);
1108 options_update(params);
1109 bullets_update(params);