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_ALWAYS);
112 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
117 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
118 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
119 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
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_skip, FL_RETURN_ALWAYS);
174 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
176 bc_.addReadOnly (class_->radio_doc_indent);
177 bc_.addReadOnly (class_->radio_doc_skip);
178 #ifndef USE_CLASS_COMBO
179 bc_.addReadOnly (class_->choice_doc_class);
181 bc_.addReadOnly (class_->choice_doc_pagestyle);
182 bc_.addReadOnly (class_->choice_doc_fonts);
183 bc_.addReadOnly (class_->choice_doc_fontsize);
184 bc_.addReadOnly (class_->radio_doc_sides_one);
185 bc_.addReadOnly (class_->radio_doc_sides_two);
186 bc_.addReadOnly (class_->radio_doc_columns_one);
187 bc_.addReadOnly (class_->radio_doc_columns_two);
188 bc_.addReadOnly (class_->input_doc_extra);
189 bc_.addReadOnly (class_->input_doc_skip);
190 bc_.addReadOnly (class_->choice_doc_skip);
191 bc_.addReadOnly (class_->choice_doc_spacing);
192 bc_.addReadOnly (class_->input_doc_spacing);
194 // the document language form
195 language_ = build_doc_language();
196 fl_addto_choice(language_->choice_inputenc,
197 "default|auto|latin1|latin2|latin5"
198 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
200 // The language is a combo-box and has to be inserted manually
201 obj = language_->choice_language;
202 fl_addto_form(language_->form);
203 combo_language = new Combox(FL_COMBOX_DROPLIST);
204 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
205 combo_language->shortcut("#L",1);
206 combo_language->setcallback(ComboInputCB, this);
208 // "default" is not part of the languages array any more.
209 #ifdef DO_USE_DEFAULT_LANGUAGE
210 combo_language->addto("default");
212 for(Languages::const_iterator cit = languages.begin();
213 cit != languages.end(); ++cit) {
214 combo_language->addto((*cit).second.lang());
217 fl_addto_choice(language_->choice_quotes_language,
218 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
219 " «text» | »text« "));
221 bc_.addReadOnly (language_->choice_language);
222 bc_.addReadOnly (language_->choice_inputenc);
224 // the document options form
225 options_ = build_doc_options();
226 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
227 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
228 fl_set_counter_step(options_->slider_secnumdepth,1,1);
229 fl_set_counter_step(options_->slider_tocdepth,1,1);
230 fl_set_counter_precision(options_->slider_secnumdepth, 0);
231 fl_set_counter_precision(options_->slider_tocdepth, 0);
232 for (n=0; tex_graphics[n][0]; ++n) {
233 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
236 bc_.addReadOnly (options_->slider_secnumdepth);
237 bc_.addReadOnly (options_->slider_tocdepth);
238 bc_.addReadOnly (options_->check_use_amsmath);
239 bc_.addReadOnly (options_->input_float_placement);
240 bc_.addReadOnly (options_->choice_postscript_driver);
242 // the document bullets form
243 bullets_ = build_doc_bullet();
244 fl_addto_choice(bullets_->choice_bullet_size,
245 _(" default | tiny | script | footnote | small |"
246 " normal | large | Large | LARGE | huge | Huge"));
247 fl_set_choice(bullets_->choice_bullet_size, 1);
248 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
249 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
251 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
252 bc_.addReadOnly (bullets_->choice_bullet_size);
253 bc_.addReadOnly (bullets_->input_bullet_latex);
255 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
259 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
261 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
263 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
265 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
266 lyxerr << _("Your version of libXpm is older than 4.7.\n"
267 "The `bullet' tab of the document popup "
268 "has been disabled") << '\n';
269 fl_deactivate_object(fbullet);
270 fl_set_object_lcol(fbullet, FL_INACTIVE);
275 void FormDocument::apply()
277 if (!lv_->view()->available() || !dialog_)
280 bool redo = class_apply();
282 redo = language_apply() || redo;
283 redo = options_apply() || redo;
287 lv_->view()->redoCurrentBuffer();
289 lv_->buffer()->markDirty();
290 setMinibuffer(lv_, _("Document layout set"));
294 void FormDocument::cancel()
296 // this avoids confusion when reopening
297 BufferParams & param = lv_->buffer()->params;
298 param.temp_bullets[0] = param.user_defined_bullets[0];
299 param.temp_bullets[1] = param.user_defined_bullets[1];
300 param.temp_bullets[2] = param.user_defined_bullets[2];
301 param.temp_bullets[3] = param.user_defined_bullets[3];
306 void FormDocument::update()
313 BufferParams const & params = lv_->buffer()->params;
315 class_update(params);
316 paper_update(params);
317 language_update(params);
318 options_update(params);
319 bullets_update(params);
323 bool FormDocument::input( FL_OBJECT * ob, long data )
325 State cb = static_cast<State>( data );
328 case CHECKCHOICECLASS:
329 CheckChoiceClass(ob, 0);
331 case CHOICEBULLETSIZE:
332 ChoiceBulletSize(ob, 0);
334 case INPUTBULLETLATEX:
335 InputBulletLaTeX(ob, 0);
352 BulletBMTable(ob, 0);
360 case CHECKCHOICECLASS:
361 case CHOICEBULLETSIZE:
362 case INPUTBULLETLATEX:
364 return CheckDocumentInput(ob, 0);
373 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
375 FormDocument * pre = static_cast<FormDocument*>(v);
376 if (combox == pre->combo_doc_class)
377 pre->CheckChoiceClass(0, 0);
378 pre->bc_.valid(pre->CheckDocumentInput(0,0));
382 bool FormDocument::class_apply()
385 BufferParams ¶ms = lv_->buffer()->params;
387 // If default skip is a "Length" but there's no text in the
388 // input field, reset the kind to "Medskip", which is the default.
389 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
390 !*(fl_get_input (class_->input_doc_skip))) {
391 fl_set_choice (class_->choice_doc_skip, 2);
393 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
394 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
395 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
397 #ifdef USE_CLASS_COMBO
398 unsigned int const new_class = combo_doc_class->get() - 1;
400 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
402 if (params.textclass != new_class) {
403 // try to load new_class
404 if (textclasslist.Load(new_class)) {
405 // successfully loaded
407 setMinibuffer(lv_, _("Converting document to new document class..."));
409 int ret = cap.SwitchLayoutsBetweenClasses(
410 params.textclass, new_class,
411 lv_->buffer()->paragraph);
415 s = _("One paragraph couldn't be converted");
418 s += _(" paragraphs couldn't be converted");
420 WriteAlert(_("Conversion Errors!"),s,
421 _("into chosen document class"));
424 params.textclass = new_class;
426 // problem changing class -- warn user and retain old style
427 WriteAlert(_("Conversion Errors!"),
428 _("Errors loading new document class."),
429 _("Reverting to original document class."));
430 #ifdef USE_CLASS_COMBO
431 combo_doc_class->select(int(params.textclass) + 1);
433 fl_set_choice(class_->choice_doc_class,
434 params.textclass + 1);
438 BufferParams::PARSEP tmpsep = params.paragraph_separation;
439 if (fl_get_button(class_->radio_doc_indent))
440 params.paragraph_separation = BufferParams::PARSEP_INDENT;
442 params.paragraph_separation = BufferParams::PARSEP_SKIP;
443 if (tmpsep != params.paragraph_separation)
446 VSpace tmpdefskip = params.getDefSkip();
447 switch (fl_get_choice (class_->choice_doc_skip)) {
449 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
452 params.setDefSkip(VSpace(VSpace::MEDSKIP));
455 params.setDefSkip(VSpace(VSpace::BIGSKIP));
459 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
461 // DocumentDefskipCB assures that this never happens
463 params.setDefSkip(VSpace(VSpace::MEDSKIP));
466 if (!(tmpdefskip == params.getDefSkip()))
469 if (fl_get_button(class_->radio_doc_columns_two))
473 if (fl_get_button(class_->radio_doc_sides_two))
474 params.sides = LyXTextClass::TwoSides;
476 params.sides = LyXTextClass::OneSide;
478 Spacing tmpSpacing = params.spacing;
479 switch(fl_get_choice(class_->choice_doc_spacing)) {
481 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
482 params.spacing.set(Spacing::Single);
485 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
486 params.spacing.set(Spacing::Onehalf);
489 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
490 params.spacing.set(Spacing::Double);
493 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
494 params.spacing.set(Spacing::Other,
495 fl_get_input(class_->input_doc_spacing));
498 if (tmpSpacing != params.spacing)
501 params.options = fl_get_input(class_->input_doc_extra);
507 void FormDocument::paper_apply()
509 BufferParams & params = lv_->buffer()->params;
512 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
513 params.paperpackage =
514 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
515 params.use_geometry = fl_get_button(paper_->push_use_geometry);
516 if (fl_get_button(paper_->radio_landscape))
517 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
519 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
520 params.paperwidth = fl_get_input(paper_->input_custom_width);
521 params.paperheight = fl_get_input(paper_->input_custom_height);
522 params.leftmargin = fl_get_input(paper_->input_left_margin);
523 params.topmargin = fl_get_input(paper_->input_top_margin);
524 params.rightmargin = fl_get_input(paper_->input_right_margin);
525 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
526 params.headheight = fl_get_input(paper_->input_head_height);
527 params.headsep = fl_get_input(paper_->input_head_sep);
528 params.footskip = fl_get_input(paper_->input_foot_skip);
529 lv_->buffer()->setPaperStuff();
533 bool FormDocument::language_apply()
535 BufferParams & params = lv_->buffer()->params;
536 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
539 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
541 lga = InsetQuotes::EnglishQ;
544 lga = InsetQuotes::SwedishQ;
547 lga = InsetQuotes::GermanQ;
550 lga = InsetQuotes::PolishQ;
553 lga = InsetQuotes::FrenchQ;
556 lga = InsetQuotes::DanishQ;
559 params.quotes_language = lga;
560 if (fl_get_button(language_->radio_single))
561 params.quotes_times = InsetQuotes::SingleQ;
563 params.quotes_times = InsetQuotes::DoubleQ;
565 Language const * old_language = params.language;
566 Language const * new_language =
567 languages.getLanguage(combo_language->getline());
569 new_language = default_language;
571 if (old_language != new_language
572 && old_language->RightToLeft() == new_language->RightToLeft()
573 && !lv_->buffer()->isMultiLingual())
574 lv_->buffer()->ChangeLanguage(old_language, new_language);
575 if (old_language != new_language) {
578 params.language = new_language;
579 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
585 bool FormDocument::options_apply()
587 BufferParams & params = lv_->buffer()->params;
590 params.graphicsDriver =
591 fl_get_choice_text(options_->choice_postscript_driver);
592 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
594 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
595 if (params.secnumdepth != tmpchar)
597 params.secnumdepth = tmpchar;
599 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
601 params.float_placement =
602 fl_get_input(options_->input_float_placement);
608 void FormDocument::bullets_apply()
610 /* update the bullet settings */
611 BufferParams & param = lv_->buffer()->params;
613 // a little bit of loop unrolling
614 param.user_defined_bullets[0] = param.temp_bullets[0];
615 param.user_defined_bullets[1] = param.temp_bullets[1];
616 param.user_defined_bullets[2] = param.temp_bullets[2];
617 param.user_defined_bullets[3] = param.temp_bullets[3];
621 void FormDocument::class_update(BufferParams const & params)
626 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
628 #ifdef USE_CLASS_COMBO
629 combo_doc_class->select_text(
630 textclasslist.DescOfClass(params.textclass));
632 fl_set_choice_text(class_->choice_doc_class,
633 textclasslist.DescOfClass(params.textclass).c_str());
635 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
636 fl_clear_choice(class_->choice_doc_fontsize);
637 fl_addto_choice(class_->choice_doc_fontsize, "default");
638 fl_addto_choice(class_->choice_doc_fontsize,
639 tclass.opt_fontsize().c_str());
640 fl_set_choice(class_->choice_doc_fontsize,
641 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
642 fl_clear_choice(class_->choice_doc_pagestyle);
643 fl_addto_choice(class_->choice_doc_pagestyle, "default");
644 fl_addto_choice(class_->choice_doc_pagestyle,
645 tclass.opt_pagestyle().c_str());
646 fl_set_choice(class_->choice_doc_pagestyle,
647 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
648 fl_set_button(class_->radio_doc_indent, 0);
649 fl_set_button(class_->radio_doc_skip, 0);
650 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
651 fl_set_button(class_->radio_doc_indent, 1);
653 fl_set_button(class_->radio_doc_skip, 1);
654 switch (params.getDefSkip().kind()) {
655 case VSpace::SMALLSKIP:
656 fl_set_choice (class_->choice_doc_skip, 1);
658 case VSpace::MEDSKIP:
659 fl_set_choice (class_->choice_doc_skip, 2);
661 case VSpace::BIGSKIP:
662 fl_set_choice (class_->choice_doc_skip, 3);
665 fl_set_choice (class_->choice_doc_skip, 4);
666 fl_set_input (class_->input_doc_skip,
667 params.getDefSkip().asLyXCommand().c_str());
670 fl_set_choice (class_->choice_doc_skip, 2);
673 fl_set_button(class_->radio_doc_sides_one, 0);
674 fl_set_button(class_->radio_doc_sides_two, 0);
675 if (params.sides == LyXTextClass::TwoSides)
676 fl_set_button(class_->radio_doc_sides_two, 1);
678 fl_set_button(class_->radio_doc_sides_one, 1);
679 fl_set_button(class_->radio_doc_columns_one, 0);
680 fl_set_button(class_->radio_doc_columns_two, 0);
681 if (params.columns == 2)
682 fl_set_button(class_->radio_doc_columns_two, 1);
684 fl_set_button(class_->radio_doc_columns_one, 1);
685 fl_set_input(class_->input_doc_spacing, "");
686 switch (params.spacing.getSpace()) {
687 case Spacing::Default: // nothing bad should happen with this
688 case Spacing::Single:
690 fl_set_choice(class_->choice_doc_spacing, 1);
692 case Spacing::Onehalf:
694 fl_set_choice(class_->choice_doc_spacing, 2);
696 case Spacing::Double:
698 fl_set_choice(class_->choice_doc_spacing, 3);
702 fl_set_choice(class_->choice_doc_spacing, 4);
704 sprintf(sval,"%g",params.spacing.getValue());
705 fl_set_input(class_->input_doc_spacing, sval);
709 if (!params.options.empty())
710 fl_set_input(class_->input_doc_extra, params.options.c_str());
712 fl_set_input(class_->input_doc_extra, "");
716 void FormDocument::language_update(BufferParams const & params)
721 combo_language->select_text(params.language->lang());
722 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
723 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
724 fl_set_button(language_->radio_single, 0);
725 fl_set_button(language_->radio_double, 0);
726 if (params.quotes_times == InsetQuotes::SingleQ)
727 fl_set_button(language_->radio_single, 1);
729 fl_set_button(language_->radio_double, 1);
733 void FormDocument::options_update(BufferParams const & params)
738 fl_set_choice_text(options_->choice_postscript_driver,
739 params.graphicsDriver.c_str());
740 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
741 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
742 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
743 if (!params.float_placement.empty())
744 fl_set_input(options_->input_float_placement,
745 params.float_placement.c_str());
747 fl_set_input(options_->input_float_placement, "");
751 void FormDocument::paper_update(BufferParams const & params)
756 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
757 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
758 fl_set_button(paper_->push_use_geometry, params.use_geometry);
759 fl_set_button(paper_->radio_portrait, 0);
760 fl_set_button(paper_->radio_landscape, 0);
761 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
762 fl_set_button(paper_->radio_landscape, 1);
764 fl_set_button(paper_->radio_portrait, 1);
765 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
766 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
767 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
768 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
769 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
770 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
771 fl_set_input(paper_->input_head_height, params.headheight.c_str());
772 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
773 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
774 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
778 void FormDocument::bullets_update(BufferParams const & params)
780 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
783 if (lv_->buffer()->isLinuxDoc()) {
784 fl_deactivate_object(fbullet);
785 fl_set_object_lcol(fbullet, FL_INACTIVE);
788 fl_activate_object(fbullet);
789 fl_set_object_lcol(fbullet, FL_BLACK);
792 fl_set_button(bullets_->radio_bullet_depth_1, 1);
793 fl_set_input(bullets_->input_bullet_latex,
794 params.user_defined_bullets[0].getText().c_str());
795 fl_set_choice(bullets_->choice_bullet_size,
796 params.user_defined_bullets[0].getSize() + 2);
800 void FormDocument::checkReadOnly()
802 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
803 combo_doc_class->deactivate();
804 combo_language->deactivate();
805 fl_set_object_label(dialog_->text_warning,
806 _("Document is read-only."
807 " No changes to layout permitted."));
808 fl_show_object(dialog_->text_warning);
810 combo_doc_class->activate();
811 combo_language->activate();
812 fl_hide_object(dialog_->text_warning);
817 void FormDocument::checkMarginValues()
819 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
820 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
821 !strlen(fl_get_input(paper_->input_left_margin)) &&
822 !strlen(fl_get_input(paper_->input_right_margin)) &&
823 !strlen(fl_get_input(paper_->input_head_height)) &&
824 !strlen(fl_get_input(paper_->input_head_sep)) &&
825 !strlen(fl_get_input(paper_->input_foot_skip)) &&
826 !strlen(fl_get_input(paper_->input_custom_width)) &&
827 !strlen(fl_get_input(paper_->input_custom_height)));
829 fl_set_button(paper_->push_use_geometry, 1);
832 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
840 if (ob == paper_->choice_papersize2) {
841 val = fl_get_choice(paper_->choice_papersize2)-1;
842 if (val == BufferParams::VM_PAPER_DEFAULT) {
843 fl_set_button(paper_->push_use_geometry, 0);
846 if ((val != BufferParams::VM_PAPER_USLETTER) &&
847 (val != BufferParams::VM_PAPER_USLEGAL) &&
848 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
849 (val != BufferParams::VM_PAPER_A4) &&
850 (val != BufferParams::VM_PAPER_A5) &&
851 (val != BufferParams::VM_PAPER_B5)) {
852 fl_set_button(paper_->push_use_geometry, 1);
854 fl_set_choice(paper_->choice_paperpackage,
855 BufferParams::PACKAGE_NONE + 1);
857 } else if (ob == paper_->choice_paperpackage) {
858 val = fl_get_choice(paper_->choice_paperpackage)-1;
859 if (val != BufferParams::PACKAGE_NONE) {
860 fl_set_choice(paper_->choice_papersize2,
861 BufferParams::VM_PAPER_DEFAULT + 1);
862 fl_set_button(paper_->push_use_geometry, 0);
864 } else if (ob == class_->input_doc_spacing) {
865 input = fl_get_input(class_->input_doc_spacing);
867 fl_set_choice (class_->choice_doc_spacing, 1);
869 fl_set_choice(class_->choice_doc_spacing, 4);
872 // this has to be all out of if/elseif because it has to deactivate
873 // the document buttons and so the whole stuff has to be tested again.
874 str = fl_get_input(paper_->input_custom_width);
875 ok = ok && (str.empty() || isValidLength(str));
876 str = fl_get_input(paper_->input_custom_height);
877 ok = ok && (str.empty() || isValidLength(str));
878 str = fl_get_input(paper_->input_left_margin);
879 ok = ok && (str.empty() || isValidLength(str));
880 str = fl_get_input(paper_->input_right_margin);
881 ok = ok && (str.empty() || isValidLength(str));
882 str = fl_get_input(paper_->input_top_margin);
883 ok = ok && (str.empty() || isValidLength(str));
884 str = fl_get_input(paper_->input_bottom_margin);
885 ok = ok && (str.empty() || isValidLength(str));
886 str = fl_get_input(paper_->input_head_height);
887 ok = ok && (str.empty() || isValidLength(str));
888 str = fl_get_input(paper_->input_head_sep);
889 ok = ok && (str.empty() || isValidLength(str));
890 str = fl_get_input(paper_->input_foot_skip);
891 ok = ok && (str.empty() || isValidLength(str));
892 // "Synchronize" the choice and the input field, so that it
893 // is impossible to commit senseless data.
894 input = fl_get_input (class_->input_doc_skip);
895 if (ob == class_->input_doc_skip) {
897 fl_set_choice (class_->choice_doc_skip, 2);
898 } else if (isValidGlueLength (input)) {
899 fl_set_choice (class_->choice_doc_skip, 4);
901 fl_set_choice(class_->choice_doc_skip, 4);
905 if (*input && !isValidGlueLength(input))
908 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
910 else if (fl_get_choice(class_->choice_doc_skip) != 4)
911 fl_set_input (class_->input_doc_skip, "");
913 input = fl_get_input(class_->input_doc_spacing);
914 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
916 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
917 fl_set_input (class_->input_doc_spacing, "");
922 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
924 BufferParams & param = lv_->buffer()->params;
926 // convert from 1-6 range to -1-4
927 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
928 fl_set_input(bullets_->input_bullet_latex,
929 param.temp_bullets[current_bullet_depth].getText().c_str());
933 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
935 BufferParams & param = lv_->buffer()->params;
937 param.temp_bullets[current_bullet_depth].
938 setText(fl_get_input(bullets_->input_bullet_latex));
942 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
944 /* Should I do the following: */
945 /* 1. change to the panel that the current bullet belongs in */
946 /* 2. show that bullet as selected */
947 /* 3. change the size setting to the size of the bullet in Q.*/
948 /* 4. display the latex equivalent in the latex box */
950 /* I'm inclined to just go with 3 and 4 at the moment and */
951 /* maybe try to support the others later */
952 BufferParams & param = lv_->buffer()->params;
955 if( cb == BULLETDEPTH1 )
957 else if ( cb == BULLETDEPTH2 )
959 else if ( cb == BULLETDEPTH3 )
961 else if ( cb == BULLETDEPTH4 )
964 switch (fl_get_button_numb(ob)) {
966 // right mouse button resets to default
967 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
969 current_bullet_depth = data;
970 fl_set_input(bullets_->input_bullet_latex,
971 param.temp_bullets[data].getText().c_str());
972 fl_set_choice(bullets_->choice_bullet_size,
973 param.temp_bullets[data].getSize() + 2);
978 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
980 /* Here we have to change the background pixmap to that selected */
981 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
984 if( cb == BULLETPANEL1 )
986 else if ( cb == BULLETPANEL2 )
988 else if ( cb == BULLETPANEL3 )
990 else if ( cb == BULLETPANEL4 )
992 else if ( cb == BULLETPANEL5 )
994 else if ( cb == BULLETPANEL6 )
997 if (data != current_bullet_panel) {
998 fl_freeze_form(bullets_->form);
999 current_bullet_panel = data;
1001 /* free the current pixmap */
1002 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1005 /* display the new one */
1007 new_panel = "standard";
1010 new_panel = "amssymb";
1013 new_panel = "psnfss1";
1016 new_panel = "psnfss2";
1019 new_panel = "psnfss3";
1022 new_panel = "psnfss4";
1025 /* something very wrong happened */
1026 // play it safe for now but should be an exception
1027 current_bullet_panel = 0; // standard panel
1028 new_panel = "standard";
1031 new_panel += ".xpm";
1032 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1033 LibFileSearch("images", new_panel).c_str());
1034 fl_redraw_object(bullets_->bmtable_bullet_panel);
1035 fl_unfreeze_form(bullets_->form);
1040 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1042 /* handle the user input by setting the current bullet depth's pixmap */
1043 /* to that extracted from the current chosen position of the BMTable */
1044 /* Don't forget to free the button's old pixmap first. */
1046 BufferParams & param = lv_->buffer()->params;
1047 int bmtable_button = fl_get_bmtable(ob);
1049 /* try to keep the button held down till another is pushed */
1050 /* fl_set_bmtable(ob, 1, bmtable_button); */
1051 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1052 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1053 fl_set_input(bullets_->input_bullet_latex,
1054 param.temp_bullets[current_bullet_depth].getText().c_str());
1058 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1061 ob = class_->choice_doc_class;
1063 ProhibitInput(lv_->view());
1065 #ifdef USE_CLASS_COMBO
1066 int tc = combo_doc_class->get() - 1;
1067 string tct = combo_doc_class->getline();
1069 int tc = fl_get_choice(ob) - 1;
1070 string tct = fl_get_choice_text(ob);
1072 if (textclasslist.Load(tc)) {
1073 if (AskQuestion(_("Should I set some parameters to"), tct,
1074 _("the defaults of this document class?"))) {
1075 BufferParams & params = lv_->buffer()->params;
1077 params.textclass = tc;
1078 params.useClassDefaults();
1079 UpdateLayoutDocument(params);
1082 // unable to load new style
1083 WriteAlert(_("Conversion Errors!"),
1084 _("Unable to switch to new document class."),
1085 _("Reverting to original document class."));
1086 #ifdef USE_CLASS_COMBO
1087 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1089 fl_set_choice(class_->choice_doc_class,
1090 lv_->buffer()->params.textclass + 1);
1093 AllowInput(lv_->view());
1097 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1103 class_update(params);
1104 paper_update(params);
1105 language_update(params);
1106 options_update(params);
1107 bullets_update(params);