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 // we can safely ignore the parameter because we can always update
307 void FormDocument::update(bool)
314 BufferParams const & params = lv_->buffer()->params;
316 class_update(params);
317 paper_update(params);
318 language_update(params);
319 options_update(params);
320 bullets_update(params);
324 bool FormDocument::input( FL_OBJECT * ob, long data )
326 State cb = static_cast<State>( data );
329 case CHECKCHOICECLASS:
330 CheckChoiceClass(ob, 0);
332 case CHOICEBULLETSIZE:
333 ChoiceBulletSize(ob, 0);
335 case INPUTBULLETLATEX:
336 InputBulletLaTeX(ob, 0);
353 BulletBMTable(ob, 0);
361 case CHECKCHOICECLASS:
362 case CHOICEBULLETSIZE:
363 case INPUTBULLETLATEX:
365 return CheckDocumentInput(ob, 0);
374 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
376 FormDocument * pre = static_cast<FormDocument*>(v);
377 if (combox == pre->combo_doc_class)
378 pre->CheckChoiceClass(0, 0);
379 pre->bc_.valid(pre->CheckDocumentInput(0,0));
383 bool FormDocument::class_apply()
386 BufferParams ¶ms = lv_->buffer()->params;
388 // If default skip is a "Length" but there's no text in the
389 // input field, reset the kind to "Medskip", which is the default.
390 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
391 !*(fl_get_input (class_->input_doc_skip))) {
392 fl_set_choice (class_->choice_doc_skip, 2);
394 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
395 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
396 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
398 #ifdef USE_CLASS_COMBO
399 unsigned int const new_class = combo_doc_class->get() - 1;
401 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
403 if (params.textclass != new_class) {
404 // try to load new_class
405 if (textclasslist.Load(new_class)) {
406 // successfully loaded
408 setMinibuffer(lv_, _("Converting document to new document class..."));
410 int ret = cap.SwitchLayoutsBetweenClasses(
411 params.textclass, new_class,
412 lv_->buffer()->paragraph);
416 s = _("One paragraph couldn't be converted");
419 s += _(" paragraphs couldn't be converted");
421 WriteAlert(_("Conversion Errors!"),s,
422 _("into chosen document class"));
425 params.textclass = new_class;
427 // problem changing class -- warn user and retain old style
428 WriteAlert(_("Conversion Errors!"),
429 _("Errors loading new document class."),
430 _("Reverting to original document class."));
431 #ifdef USE_CLASS_COMBO
432 combo_doc_class->select(int(params.textclass) + 1);
434 fl_set_choice(class_->choice_doc_class,
435 params.textclass + 1);
439 BufferParams::PARSEP tmpsep = params.paragraph_separation;
440 if (fl_get_button(class_->radio_doc_indent))
441 params.paragraph_separation = BufferParams::PARSEP_INDENT;
443 params.paragraph_separation = BufferParams::PARSEP_SKIP;
444 if (tmpsep != params.paragraph_separation)
447 VSpace tmpdefskip = params.getDefSkip();
448 switch (fl_get_choice (class_->choice_doc_skip)) {
450 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
453 params.setDefSkip(VSpace(VSpace::MEDSKIP));
456 params.setDefSkip(VSpace(VSpace::BIGSKIP));
460 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
462 // DocumentDefskipCB assures that this never happens
464 params.setDefSkip(VSpace(VSpace::MEDSKIP));
467 if (!(tmpdefskip == params.getDefSkip()))
470 if (fl_get_button(class_->radio_doc_columns_two))
474 if (fl_get_button(class_->radio_doc_sides_two))
475 params.sides = LyXTextClass::TwoSides;
477 params.sides = LyXTextClass::OneSide;
479 Spacing tmpSpacing = params.spacing;
480 switch(fl_get_choice(class_->choice_doc_spacing)) {
482 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
483 params.spacing.set(Spacing::Single);
486 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
487 params.spacing.set(Spacing::Onehalf);
490 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
491 params.spacing.set(Spacing::Double);
494 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
495 params.spacing.set(Spacing::Other,
496 fl_get_input(class_->input_doc_spacing));
499 if (tmpSpacing != params.spacing)
502 params.options = fl_get_input(class_->input_doc_extra);
508 void FormDocument::paper_apply()
510 BufferParams & params = lv_->buffer()->params;
513 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
514 params.paperpackage =
515 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
516 params.use_geometry = fl_get_button(paper_->push_use_geometry);
517 if (fl_get_button(paper_->radio_landscape))
518 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
520 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
521 params.paperwidth = fl_get_input(paper_->input_custom_width);
522 params.paperheight = fl_get_input(paper_->input_custom_height);
523 params.leftmargin = fl_get_input(paper_->input_left_margin);
524 params.topmargin = fl_get_input(paper_->input_top_margin);
525 params.rightmargin = fl_get_input(paper_->input_right_margin);
526 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
527 params.headheight = fl_get_input(paper_->input_head_height);
528 params.headsep = fl_get_input(paper_->input_head_sep);
529 params.footskip = fl_get_input(paper_->input_foot_skip);
530 lv_->buffer()->setPaperStuff();
534 bool FormDocument::language_apply()
536 BufferParams & params = lv_->buffer()->params;
537 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
540 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
542 lga = InsetQuotes::EnglishQ;
545 lga = InsetQuotes::SwedishQ;
548 lga = InsetQuotes::GermanQ;
551 lga = InsetQuotes::PolishQ;
554 lga = InsetQuotes::FrenchQ;
557 lga = InsetQuotes::DanishQ;
560 params.quotes_language = lga;
561 if (fl_get_button(language_->radio_single))
562 params.quotes_times = InsetQuotes::SingleQ;
564 params.quotes_times = InsetQuotes::DoubleQ;
566 Language const * old_language = params.language;
567 Language const * new_language =
568 languages.getLanguage(combo_language->getline());
570 new_language = default_language;
572 if (old_language != new_language
573 && old_language->RightToLeft() == new_language->RightToLeft()
574 && !lv_->buffer()->isMultiLingual())
575 lv_->buffer()->ChangeLanguage(old_language, new_language);
576 if (old_language != new_language) {
579 params.language = new_language;
580 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
586 bool FormDocument::options_apply()
588 BufferParams & params = lv_->buffer()->params;
591 params.graphicsDriver =
592 fl_get_choice_text(options_->choice_postscript_driver);
593 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
595 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
596 if (params.secnumdepth != tmpchar)
598 params.secnumdepth = tmpchar;
600 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
602 params.float_placement =
603 fl_get_input(options_->input_float_placement);
609 void FormDocument::bullets_apply()
611 /* update the bullet settings */
612 BufferParams & param = lv_->buffer()->params;
614 // a little bit of loop unrolling
615 param.user_defined_bullets[0] = param.temp_bullets[0];
616 param.user_defined_bullets[1] = param.temp_bullets[1];
617 param.user_defined_bullets[2] = param.temp_bullets[2];
618 param.user_defined_bullets[3] = param.temp_bullets[3];
622 void FormDocument::class_update(BufferParams const & params)
627 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
629 #ifdef USE_CLASS_COMBO
630 combo_doc_class->select_text(
631 textclasslist.DescOfClass(params.textclass));
633 fl_set_choice_text(class_->choice_doc_class,
634 textclasslist.DescOfClass(params.textclass).c_str());
636 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
637 fl_clear_choice(class_->choice_doc_fontsize);
638 fl_addto_choice(class_->choice_doc_fontsize, "default");
639 fl_addto_choice(class_->choice_doc_fontsize,
640 tclass.opt_fontsize().c_str());
641 fl_set_choice(class_->choice_doc_fontsize,
642 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
643 fl_clear_choice(class_->choice_doc_pagestyle);
644 fl_addto_choice(class_->choice_doc_pagestyle, "default");
645 fl_addto_choice(class_->choice_doc_pagestyle,
646 tclass.opt_pagestyle().c_str());
647 fl_set_choice(class_->choice_doc_pagestyle,
648 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
649 fl_set_button(class_->radio_doc_indent, 0);
650 fl_set_button(class_->radio_doc_skip, 0);
651 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
652 fl_set_button(class_->radio_doc_indent, 1);
654 fl_set_button(class_->radio_doc_skip, 1);
655 switch (params.getDefSkip().kind()) {
656 case VSpace::SMALLSKIP:
657 fl_set_choice (class_->choice_doc_skip, 1);
659 case VSpace::MEDSKIP:
660 fl_set_choice (class_->choice_doc_skip, 2);
662 case VSpace::BIGSKIP:
663 fl_set_choice (class_->choice_doc_skip, 3);
666 fl_set_choice (class_->choice_doc_skip, 4);
667 fl_set_input (class_->input_doc_skip,
668 params.getDefSkip().asLyXCommand().c_str());
671 fl_set_choice (class_->choice_doc_skip, 2);
674 fl_set_button(class_->radio_doc_sides_one, 0);
675 fl_set_button(class_->radio_doc_sides_two, 0);
676 if (params.sides == 2)
677 fl_set_button(class_->radio_doc_sides_two, 1);
679 fl_set_button(class_->radio_doc_sides_one, 1);
680 fl_set_button(class_->radio_doc_columns_one, 0);
681 fl_set_button(class_->radio_doc_columns_two, 0);
682 if (params.columns == 2)
683 fl_set_button(class_->radio_doc_columns_two, 1);
685 fl_set_button(class_->radio_doc_columns_one, 1);
686 fl_set_input(class_->input_doc_spacing, "");
687 switch (params.spacing.getSpace()) {
688 case Spacing::Default: // nothing bad should happen with this
689 case Spacing::Single:
691 fl_set_choice(class_->choice_doc_spacing, 1);
693 case Spacing::Onehalf:
695 fl_set_choice(class_->choice_doc_spacing, 2);
697 case Spacing::Double:
699 fl_set_choice(class_->choice_doc_spacing, 3);
703 fl_set_choice(class_->choice_doc_spacing, 4);
705 sprintf(sval,"%g",params.spacing.getValue());
706 fl_set_input(class_->input_doc_spacing, sval);
710 if (!params.options.empty())
711 fl_set_input(class_->input_doc_extra, params.options.c_str());
713 fl_set_input(class_->input_doc_extra, "");
717 void FormDocument::language_update(BufferParams const & params)
722 combo_language->select_text(params.language->lang());
723 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
724 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
725 fl_set_button(language_->radio_single, 0);
726 fl_set_button(language_->radio_double, 0);
727 if (params.quotes_times == InsetQuotes::SingleQ)
728 fl_set_button(language_->radio_single, 1);
730 fl_set_button(language_->radio_double, 1);
734 void FormDocument::options_update(BufferParams const & params)
739 fl_set_choice_text(options_->choice_postscript_driver,
740 params.graphicsDriver.c_str());
741 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
742 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
743 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
744 if (!params.float_placement.empty())
745 fl_set_input(options_->input_float_placement,
746 params.float_placement.c_str());
748 fl_set_input(options_->input_float_placement, "");
752 void FormDocument::paper_update(BufferParams const & params)
757 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
758 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
759 fl_set_button(paper_->push_use_geometry, params.use_geometry);
760 fl_set_button(paper_->radio_portrait, 0);
761 fl_set_button(paper_->radio_landscape, 0);
762 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
763 fl_set_button(paper_->radio_landscape, 1);
765 fl_set_button(paper_->radio_portrait, 1);
766 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
767 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
768 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
769 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
770 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
771 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
772 fl_set_input(paper_->input_head_height, params.headheight.c_str());
773 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
774 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
775 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
779 void FormDocument::bullets_update(BufferParams const & params)
781 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
784 if (lv_->buffer()->isLinuxDoc()) {
785 fl_deactivate_object(fbullet);
786 fl_set_object_lcol(fbullet, FL_INACTIVE);
789 fl_activate_object(fbullet);
790 fl_set_object_lcol(fbullet, FL_BLACK);
793 fl_set_button(bullets_->radio_bullet_depth_1, 1);
794 fl_set_input(bullets_->input_bullet_latex,
795 params.user_defined_bullets[0].getText().c_str());
796 fl_set_choice(bullets_->choice_bullet_size,
797 params.user_defined_bullets[0].getSize() + 2);
801 void FormDocument::checkReadOnly()
803 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
804 combo_doc_class->deactivate();
805 combo_language->deactivate();
806 fl_set_object_label(dialog_->text_warning,
807 _("Document is read-only."
808 " No changes to layout permitted."));
809 fl_show_object(dialog_->text_warning);
811 combo_doc_class->activate();
812 combo_language->activate();
813 fl_hide_object(dialog_->text_warning);
818 void FormDocument::checkMarginValues()
820 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
821 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
822 !strlen(fl_get_input(paper_->input_left_margin)) &&
823 !strlen(fl_get_input(paper_->input_right_margin)) &&
824 !strlen(fl_get_input(paper_->input_head_height)) &&
825 !strlen(fl_get_input(paper_->input_head_sep)) &&
826 !strlen(fl_get_input(paper_->input_foot_skip)) &&
827 !strlen(fl_get_input(paper_->input_custom_width)) &&
828 !strlen(fl_get_input(paper_->input_custom_height)));
830 fl_set_button(paper_->push_use_geometry, 1);
833 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
841 if (ob == paper_->choice_papersize2) {
842 val = fl_get_choice(paper_->choice_papersize2)-1;
843 if (val == BufferParams::VM_PAPER_DEFAULT) {
844 fl_set_button(paper_->push_use_geometry, 0);
847 if ((val != BufferParams::VM_PAPER_USLETTER) &&
848 (val != BufferParams::VM_PAPER_USLEGAL) &&
849 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
850 (val != BufferParams::VM_PAPER_A4) &&
851 (val != BufferParams::VM_PAPER_A5) &&
852 (val != BufferParams::VM_PAPER_B5)) {
853 fl_set_button(paper_->push_use_geometry, 1);
855 fl_set_choice(paper_->choice_paperpackage,
856 BufferParams::PACKAGE_NONE + 1);
858 } else if (ob == paper_->choice_paperpackage) {
859 val = fl_get_choice(paper_->choice_paperpackage)-1;
860 if (val != BufferParams::PACKAGE_NONE) {
861 fl_set_choice(paper_->choice_papersize2,
862 BufferParams::VM_PAPER_DEFAULT + 1);
863 fl_set_button(paper_->push_use_geometry, 0);
865 } else if (ob == class_->input_doc_spacing) {
866 input = fl_get_input(class_->input_doc_spacing);
868 fl_set_choice (class_->choice_doc_spacing, 1);
870 fl_set_choice(class_->choice_doc_spacing, 4);
873 // this has to be all out of if/elseif because it has to deactivate
874 // the document buttons and so the whole stuff has to be tested again.
875 str = fl_get_input(paper_->input_custom_width);
876 ok = ok && (str.empty() || isValidLength(str));
877 str = fl_get_input(paper_->input_custom_height);
878 ok = ok && (str.empty() || isValidLength(str));
879 str = fl_get_input(paper_->input_left_margin);
880 ok = ok && (str.empty() || isValidLength(str));
881 str = fl_get_input(paper_->input_right_margin);
882 ok = ok && (str.empty() || isValidLength(str));
883 str = fl_get_input(paper_->input_top_margin);
884 ok = ok && (str.empty() || isValidLength(str));
885 str = fl_get_input(paper_->input_bottom_margin);
886 ok = ok && (str.empty() || isValidLength(str));
887 str = fl_get_input(paper_->input_head_height);
888 ok = ok && (str.empty() || isValidLength(str));
889 str = fl_get_input(paper_->input_head_sep);
890 ok = ok && (str.empty() || isValidLength(str));
891 str = fl_get_input(paper_->input_foot_skip);
892 ok = ok && (str.empty() || isValidLength(str));
893 // "Synchronize" the choice and the input field, so that it
894 // is impossible to commit senseless data.
895 input = fl_get_input (class_->input_doc_skip);
896 if (ob == class_->input_doc_skip) {
898 fl_set_choice (class_->choice_doc_skip, 2);
899 } else if (isValidGlueLength (input)) {
900 fl_set_choice (class_->choice_doc_skip, 4);
902 fl_set_choice(class_->choice_doc_skip, 4);
906 if (*input && !isValidGlueLength(input))
909 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
911 else if (fl_get_choice(class_->choice_doc_skip) != 4)
912 fl_set_input (class_->input_doc_skip, "");
914 input = fl_get_input(class_->input_doc_spacing);
915 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
917 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
918 fl_set_input (class_->input_doc_spacing, "");
923 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
925 BufferParams & param = lv_->buffer()->params;
927 // convert from 1-6 range to -1-4
928 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
929 fl_set_input(bullets_->input_bullet_latex,
930 param.temp_bullets[current_bullet_depth].getText().c_str());
934 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
936 BufferParams & param = lv_->buffer()->params;
938 param.temp_bullets[current_bullet_depth].
939 setText(fl_get_input(bullets_->input_bullet_latex));
943 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
945 /* Should I do the following: */
946 /* 1. change to the panel that the current bullet belongs in */
947 /* 2. show that bullet as selected */
948 /* 3. change the size setting to the size of the bullet in Q.*/
949 /* 4. display the latex equivalent in the latex box */
951 /* I'm inclined to just go with 3 and 4 at the moment and */
952 /* maybe try to support the others later */
953 BufferParams & param = lv_->buffer()->params;
956 if( cb == BULLETDEPTH1 )
958 else if ( cb == BULLETDEPTH2 )
960 else if ( cb == BULLETDEPTH3 )
962 else if ( cb == BULLETDEPTH4 )
965 switch (fl_get_button_numb(ob)) {
967 // right mouse button resets to default
968 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
970 current_bullet_depth = data;
971 fl_set_input(bullets_->input_bullet_latex,
972 param.temp_bullets[data].getText().c_str());
973 fl_set_choice(bullets_->choice_bullet_size,
974 param.temp_bullets[data].getSize() + 2);
979 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
981 /* Here we have to change the background pixmap to that selected */
982 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
985 if( cb == BULLETPANEL1 )
987 else if ( cb == BULLETPANEL2 )
989 else if ( cb == BULLETPANEL3 )
991 else if ( cb == BULLETPANEL4 )
993 else if ( cb == BULLETPANEL5 )
995 else if ( cb == BULLETPANEL6 )
998 if (data != current_bullet_panel) {
999 fl_freeze_form(bullets_->form);
1000 current_bullet_panel = data;
1002 /* free the current pixmap */
1003 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1006 /* display the new one */
1008 new_panel = "standard";
1011 new_panel = "amssymb";
1014 new_panel = "psnfss1";
1017 new_panel = "psnfss2";
1020 new_panel = "psnfss3";
1023 new_panel = "psnfss4";
1026 /* something very wrong happened */
1027 // play it safe for now but should be an exception
1028 current_bullet_panel = 0; // standard panel
1029 new_panel = "standard";
1032 new_panel += ".xpm";
1033 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1034 LibFileSearch("images", new_panel).c_str());
1035 fl_redraw_object(bullets_->bmtable_bullet_panel);
1036 fl_unfreeze_form(bullets_->form);
1041 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1043 /* handle the user input by setting the current bullet depth's pixmap */
1044 /* to that extracted from the current chosen position of the BMTable */
1045 /* Don't forget to free the button's old pixmap first. */
1047 BufferParams & param = lv_->buffer()->params;
1048 int bmtable_button = fl_get_bmtable(ob);
1050 /* try to keep the button held down till another is pushed */
1051 /* fl_set_bmtable(ob, 1, bmtable_button); */
1052 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1053 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1054 fl_set_input(bullets_->input_bullet_latex,
1055 param.temp_bullets[current_bullet_depth].getText().c_str());
1059 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1062 ob = class_->choice_doc_class;
1064 ProhibitInput(lv_->view());
1066 #ifdef USE_CLASS_COMBO
1067 int tc = combo_doc_class->get() - 1;
1068 string tct = combo_doc_class->getline();
1070 int tc = fl_get_choice(ob) - 1;
1071 string tct = fl_get_choice_text(ob);
1073 if (textclasslist.Load(tc)) {
1074 if (AskQuestion(_("Should I set some parameters to"), tct,
1075 _("the defaults of this document class?"))) {
1076 BufferParams & params = lv_->buffer()->params;
1078 params.textclass = tc;
1079 params.useClassDefaults();
1080 UpdateLayoutDocument(params);
1083 // unable to load new style
1084 WriteAlert(_("Conversion Errors!"),
1085 _("Unable to switch to new document class."),
1086 _("Reverting to original document class."));
1087 #ifdef USE_CLASS_COMBO
1088 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1090 fl_set_choice(class_->choice_doc_class,
1091 lv_->buffer()->params.textclass + 1);
1094 AllowInput(lv_->view());
1098 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1104 class_update(params);
1105 paper_update(params);
1106 language_update(params);
1107 options_update(params);
1108 bullets_update(params);