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"
24 #include "xform_macros.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
33 #include "support/filetools.h"
36 #include "BufferView.h"
39 #include "CutAndPaste.h"
40 #include "bufferview_funcs.h"
42 #ifdef SIGC_CXX_NAMESPACES
46 #ifdef CXX_WORKING_NAMESPACES
47 using Liason::setMinibuffer;
50 #define USE_CLASS_COMBO 1
52 C_GENERICCB(FormDocument, InputCB)
53 C_GENERICCB(FormDocument, ChoiceClassCB)
54 C_GENERICCB(FormDocument, BulletPanelCB)
55 C_GENERICCB(FormDocument, BulletDepthCB)
56 C_GENERICCB(FormDocument, InputBulletLaTeXCB)
57 C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
60 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
61 : FormBase(lv, d, BUFFER_DEPENDENT, _("Document Layout"),
62 new NoRepeatedApplyReadOnlyPolicy),
63 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
66 // let the popup be shown
67 // This is a permanent connection so we won't bother
68 // storing a copy because we won't be disconnecting.
69 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
70 current_bullet_depth = 0;
71 current_bullet_panel = 0;
75 FormDocument::~FormDocument()
77 #ifdef USE_CLASS_COMBO
78 delete combo_doc_class;
82 delete combo_language;
90 FL_FORM * const FormDocument::form() const
92 if (dialog_) return dialog_->form;
97 void FormDocument::build()
102 dialog_ = build_tabbed_document();
104 // manage the restore, ok, apply and cancel/close buttons
105 bc_.setOK(dialog_->button_ok);
106 bc_.setApply(dialog_->button_apply);
107 bc_.setCancel(dialog_->button_cancel);
108 bc_.setUndoAll(dialog_->button_restore);
111 // the document paper form
112 paper_ = build_doc_paper();
113 fl_addto_choice(paper_->choice_papersize2,
114 _(" Default | Custom | USletter | USlegal "
115 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
116 fl_addto_choice(paper_->choice_paperpackage,
118 "| A4 small Margins (only portrait) "
119 "| A4 very small Margins (only portrait) "
120 "| A4 very wide margins (only portrait) "));
121 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
122 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
123 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
124 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
125 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
126 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
127 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
128 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
129 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
131 bc_.addReadOnly (paper_->choice_paperpackage);
132 bc_.addReadOnly (paper_->greoup_radio_orientation);
133 bc_.addReadOnly (paper_->radio_portrait);
134 bc_.addReadOnly (paper_->radio_landscape);
135 bc_.addReadOnly (paper_->choice_papersize2);
136 bc_.addReadOnly (paper_->push_use_geometry);
137 bc_.addReadOnly (paper_->input_custom_width);
138 bc_.addReadOnly (paper_->input_custom_height);
139 bc_.addReadOnly (paper_->input_top_margin);
140 bc_.addReadOnly (paper_->input_bottom_margin);
141 bc_.addReadOnly (paper_->input_left_margin);
142 bc_.addReadOnly (paper_->input_right_margin);
143 bc_.addReadOnly (paper_->input_head_height);
144 bc_.addReadOnly (paper_->input_head_sep);
145 bc_.addReadOnly (paper_->input_foot_skip);
147 // the document class form
148 class_ = build_doc_class();
151 #ifdef USE_CLASS_COMBO
152 // The language is a combo-box and has to be inserted manually
153 obj = class_->choice_doc_class;
154 fl_addto_form(class_->form);
155 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
156 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 200);
157 combo_doc_class->shortcut("#C",1);
158 combo_doc_class->setcallback(ComboInputCB, this);
160 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
161 cit != textclasslist.end(); ++cit)
163 combo_doc_class->addto((*cit).description().c_str());
166 fl_clear_choice(class_->choice_doc_class);
167 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
168 cit != textclasslist.end(); ++cit)
170 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
173 fl_addto_choice(class_->choice_doc_spacing,
174 _(" Single | OneHalf | Double | Other "));
175 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
176 for (n=0; tex_fonts[n][0]; ++n) {
177 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
179 fl_addto_choice(class_->choice_doc_pagestyle,
180 "default|empty|plain|headings|fancy");
181 fl_addto_choice(class_->choice_doc_skip,
182 _(" Smallskip | Medskip | Bigskip | Length "));
183 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
184 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
186 bc_.addReadOnly (class_->radio_doc_indent);
187 bc_.addReadOnly (class_->radio_doc_skip);
188 #ifndef USE_CLASS_COMBO
189 bc_.addReadOnly (class_->choice_doc_class);
191 bc_.addReadOnly (class_->choice_doc_pagestyle);
192 bc_.addReadOnly (class_->choice_doc_fonts);
193 bc_.addReadOnly (class_->choice_doc_fontsize);
194 bc_.addReadOnly (class_->radio_doc_sides_one);
195 bc_.addReadOnly (class_->radio_doc_sides_two);
196 bc_.addReadOnly (class_->radio_doc_columns_one);
197 bc_.addReadOnly (class_->radio_doc_columns_two);
198 bc_.addReadOnly (class_->input_doc_extra);
199 bc_.addReadOnly (class_->input_doc_skip);
200 bc_.addReadOnly (class_->choice_doc_skip);
201 bc_.addReadOnly (class_->choice_doc_spacing);
202 bc_.addReadOnly (class_->input_doc_spacing);
204 // the document language form
205 language_ = build_doc_language();
206 fl_addto_choice(language_->choice_inputenc,
207 "default|auto|latin1|latin2|latin5"
208 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
210 // The language is a combo-box and has to be inserted manually
211 obj = language_->choice_language;
212 fl_addto_form(language_->form);
213 combo_language = new Combox(FL_COMBOX_DROPLIST);
214 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
215 combo_language->shortcut("#L",1);
216 combo_language->setcallback(ComboInputCB, this);
218 // "default" is not part of the languages array any more.
219 #ifdef DO_USE_DEFAULT_LANGUAGE
220 combo_language->addto("default");
222 for(Languages::iterator cit = languages.begin();
223 cit != languages.end(); ++cit) {
224 combo_language->addto((*cit).second.lang().c_str());
227 fl_addto_choice(language_->choice_quotes_language,
228 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
229 " «text» | »text« "));
231 bc_.addReadOnly (language_->choice_language);
232 bc_.addReadOnly (language_->choice_inputenc);
234 // the document options form
235 options_ = build_doc_options();
236 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
237 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
238 fl_set_counter_step(options_->slider_secnumdepth,1,1);
239 fl_set_counter_step(options_->slider_tocdepth,1,1);
240 fl_set_counter_precision(options_->slider_secnumdepth, 0);
241 fl_set_counter_precision(options_->slider_tocdepth, 0);
242 for (n=0; tex_graphics[n][0]; ++n) {
243 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
246 bc_.addReadOnly (options_->slider_secnumdepth);
247 bc_.addReadOnly (options_->slider_tocdepth);
248 bc_.addReadOnly (options_->check_use_amsmath);
249 bc_.addReadOnly (options_->input_float_placement);
250 bc_.addReadOnly (options_->choice_postscript_driver);
252 // the document bullets form
253 bullets_ = build_doc_bullet();
254 fl_addto_choice(bullets_->choice_bullet_size,
255 _(" default | tiny | script | footnote | small |"
256 " normal | large | Large | LARGE | huge | Huge"));
257 fl_set_choice(bullets_->choice_bullet_size, 1);
258 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
259 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
261 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
262 bc_.addReadOnly (bullets_->choice_bullet_size);
263 bc_.addReadOnly (bullets_->input_bullet_latex);
265 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
267 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
269 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
271 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
273 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
275 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
276 lyxerr << _("Your version of libXpm is older than 4.7.\n"
277 "The `bullet' tab of the document popup "
278 "has been disabled") << '\n';
279 fl_deactivate_object(fbullet);
280 fl_set_object_lcol(fbullet, FL_INACTIVE);
285 void FormDocument::apply()
287 if (!lv_->view()->available() || !dialog_)
290 bool redo = class_apply();
292 redo = language_apply() || redo;
293 redo = options_apply() || redo;
297 lv_->view()->redoCurrentBuffer();
299 lv_->buffer()->markDirty();
300 setMinibuffer(lv_, _("Document layout set"));
304 bool FormDocument::class_apply()
307 BufferParams ¶ms = lv_->buffer()->params;
309 // If default skip is a "Length" but there's no text in the
310 // input field, reset the kind to "Medskip", which is the default.
311 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
312 !*(fl_get_input (class_->input_doc_skip))) {
313 fl_set_choice (class_->choice_doc_skip, 2);
315 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
316 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
317 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
319 #ifdef USE_CLASS_COMBO
320 unsigned int new_class = combo_doc_class->get() - 1;
322 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
324 if (params.textclass != new_class) {
325 // try to load new_class
326 if (textclasslist.Load(new_class)) {
327 // successfully loaded
329 setMinibuffer(lv_, _("Converting document to new document class..."));
331 int ret = cap.SwitchLayoutsBetweenClasses(
332 params.textclass, new_class,
333 lv_->buffer()->paragraph);
337 s = _("One paragraph couldn't be converted");
340 s += _(" paragraphs couldn't be converted");
342 WriteAlert(_("Conversion Errors!"),s,
343 _("into chosen document class"));
346 params.textclass = new_class;
348 // problem changing class -- warn user and retain old style
349 WriteAlert(_("Conversion Errors!"),
350 _("Errors loading new document class."),
351 _("Reverting to original document class."));
352 #ifdef USE_CLASS_COMBO
353 combo_doc_class->select(params.textclass + 1);
355 fl_set_choice(class_->choice_doc_class,
356 params.textclass + 1);
360 char tmpsep = params.paragraph_separation;
361 if (fl_get_button(class_->radio_doc_indent))
362 params.paragraph_separation = BufferParams::PARSEP_INDENT;
364 params.paragraph_separation = BufferParams::PARSEP_SKIP;
365 if (tmpsep != params.paragraph_separation)
368 VSpace tmpdefskip = params.getDefSkip();
369 switch (fl_get_choice (class_->choice_doc_skip)) {
371 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
374 params.setDefSkip(VSpace(VSpace::MEDSKIP));
377 params.setDefSkip(VSpace(VSpace::BIGSKIP));
381 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
383 // DocumentDefskipCB assures that this never happens
385 params.setDefSkip(VSpace(VSpace::MEDSKIP));
388 if (!(tmpdefskip == params.getDefSkip()))
391 if (fl_get_button(class_->radio_doc_columns_two))
395 if (fl_get_button(class_->radio_doc_sides_two))
396 params.sides = LyXTextClass::TwoSides;
398 params.sides = LyXTextClass::OneSide;
400 Spacing tmpSpacing = params.spacing;
401 switch(fl_get_choice(class_->choice_doc_spacing)) {
403 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
404 params.spacing.set(Spacing::Single);
407 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
408 params.spacing.set(Spacing::Onehalf);
411 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
412 params.spacing.set(Spacing::Double);
415 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
416 params.spacing.set(Spacing::Other,
417 fl_get_input(class_->input_doc_spacing));
420 if (tmpSpacing != params.spacing)
423 params.options = fl_get_input(class_->input_doc_extra);
429 void FormDocument::paper_apply()
431 BufferParams & params = lv_->buffer()->params;
433 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
434 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
435 params.use_geometry = fl_get_button(paper_->push_use_geometry);
436 if (fl_get_button(paper_->radio_landscape))
437 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
439 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
440 params.paperwidth = fl_get_input(paper_->input_custom_width);
441 params.paperheight = fl_get_input(paper_->input_custom_height);
442 params.leftmargin = fl_get_input(paper_->input_left_margin);
443 params.topmargin = fl_get_input(paper_->input_top_margin);
444 params.rightmargin = fl_get_input(paper_->input_right_margin);
445 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
446 params.headheight = fl_get_input(paper_->input_head_height);
447 params.headsep = fl_get_input(paper_->input_head_sep);
448 params.footskip = fl_get_input(paper_->input_foot_skip);
449 lv_->buffer()->setPaperStuff();
453 bool FormDocument::language_apply()
455 BufferParams & params = lv_->buffer()->params;
456 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
459 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
461 lga = InsetQuotes::EnglishQ;
464 lga = InsetQuotes::SwedishQ;
467 lga = InsetQuotes::GermanQ;
470 lga = InsetQuotes::PolishQ;
473 lga = InsetQuotes::FrenchQ;
476 lga = InsetQuotes::DanishQ;
479 params.quotes_language = lga;
480 if (fl_get_button(language_->radio_single))
481 params.quotes_times = InsetQuotes::SingleQ;
483 params.quotes_times = InsetQuotes::DoubleQ;
485 Language const * old_language = params.language_info;
486 params.language = combo_language->getline();
487 Languages::iterator lit = languages.find(params.language);
489 Language const * new_language;
490 if (lit != languages.end())
491 new_language = &(*lit).second;
493 new_language = default_language;
495 if (old_language != new_language
496 && old_language->RightToLeft() == new_language->RightToLeft()
497 && !lv_->buffer()->isMultiLingual())
498 lv_->buffer()->ChangeLanguage(old_language, new_language);
499 if (old_language != new_language) {
502 params.language_info = new_language;
503 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
509 bool FormDocument::options_apply()
511 BufferParams & params = lv_->buffer()->params;
514 params.graphicsDriver =
515 fl_get_choice_text(options_->choice_postscript_driver);
516 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
518 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
519 if (params.secnumdepth != tmpchar)
521 params.secnumdepth = tmpchar;
523 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
525 params.float_placement =
526 fl_get_input(options_->input_float_placement);
532 void FormDocument::bullets_apply()
534 /* update the bullet settings */
535 BufferParams & param = lv_->buffer()->params;
537 // a little bit of loop unrolling
538 param.user_defined_bullets[0] = param.temp_bullets[0];
539 param.user_defined_bullets[1] = param.temp_bullets[1];
540 param.user_defined_bullets[2] = param.temp_bullets[2];
541 param.user_defined_bullets[3] = param.temp_bullets[3];
545 void FormDocument::cancel()
547 // this avoids confusion when reopening
548 BufferParams & param = lv_->buffer()->params;
549 param.temp_bullets[0] = param.user_defined_bullets[0];
550 param.temp_bullets[1] = param.user_defined_bullets[1];
551 param.temp_bullets[2] = param.user_defined_bullets[2];
552 param.temp_bullets[3] = param.user_defined_bullets[3];
557 void FormDocument::update()
564 BufferParams const & params = lv_->buffer()->params;
566 class_update(params);
567 paper_update(params);
568 language_update(params);
569 options_update(params);
570 bullets_update(params);
574 void FormDocument::class_update(BufferParams const & params)
579 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
581 #ifdef USE_CLASS_COMBO
582 combo_doc_class->select_text(
583 textclasslist.DescOfClass(params.textclass).c_str());
585 fl_set_choice_text(class_->choice_doc_class,
586 textclasslist.DescOfClass(params.textclass).c_str());
588 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
589 fl_clear_choice(class_->choice_doc_fontsize);
590 fl_addto_choice(class_->choice_doc_fontsize, "default");
591 fl_addto_choice(class_->choice_doc_fontsize,
592 tclass.opt_fontsize().c_str());
593 fl_set_choice(class_->choice_doc_fontsize,
594 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
595 fl_clear_choice(class_->choice_doc_pagestyle);
596 fl_addto_choice(class_->choice_doc_pagestyle, "default");
597 fl_addto_choice(class_->choice_doc_pagestyle,
598 tclass.opt_pagestyle().c_str());
599 fl_set_choice(class_->choice_doc_pagestyle,
600 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
601 fl_set_button(class_->radio_doc_indent, 0);
602 fl_set_button(class_->radio_doc_skip, 0);
603 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
604 fl_set_button(class_->radio_doc_indent, 1);
606 fl_set_button(class_->radio_doc_skip, 1);
607 switch (params.getDefSkip().kind()) {
608 case VSpace::SMALLSKIP:
609 fl_set_choice (class_->choice_doc_skip, 1);
611 case VSpace::MEDSKIP:
612 fl_set_choice (class_->choice_doc_skip, 2);
614 case VSpace::BIGSKIP:
615 fl_set_choice (class_->choice_doc_skip, 3);
618 fl_set_choice (class_->choice_doc_skip, 4);
619 fl_set_input (class_->input_doc_skip,
620 params.getDefSkip().asLyXCommand().c_str());
623 fl_set_choice (class_->choice_doc_skip, 2);
626 fl_set_button(class_->radio_doc_sides_one, 0);
627 fl_set_button(class_->radio_doc_sides_two, 0);
628 if (params.sides == 2)
629 fl_set_button(class_->radio_doc_sides_two, 1);
631 fl_set_button(class_->radio_doc_sides_one, 1);
632 fl_set_button(class_->radio_doc_columns_one, 0);
633 fl_set_button(class_->radio_doc_columns_two, 0);
634 if (params.columns == 2)
635 fl_set_button(class_->radio_doc_columns_two, 1);
637 fl_set_button(class_->radio_doc_columns_one, 1);
638 fl_set_input(class_->input_doc_spacing, "");
639 switch (params.spacing.getSpace()) {
640 case Spacing::Default: // nothing bad should happen with this
641 case Spacing::Single:
643 fl_set_choice(class_->choice_doc_spacing, 1);
645 case Spacing::Onehalf:
647 fl_set_choice(class_->choice_doc_spacing, 2);
649 case Spacing::Double:
651 fl_set_choice(class_->choice_doc_spacing, 3);
655 fl_set_choice(class_->choice_doc_spacing, 4);
657 sprintf(sval,"%g",params.spacing.getValue());
658 fl_set_input(class_->input_doc_spacing, sval);
662 if (!params.options.empty())
663 fl_set_input(class_->input_doc_extra, params.options.c_str());
665 fl_set_input(class_->input_doc_extra, "");
669 void FormDocument::language_update(BufferParams const & params)
674 combo_language->select_text(params.language.c_str());
675 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
676 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
677 fl_set_button(language_->radio_single, 0);
678 fl_set_button(language_->radio_double, 0);
679 if (params.quotes_times == InsetQuotes::SingleQ)
680 fl_set_button(language_->radio_single, 1);
682 fl_set_button(language_->radio_double, 1);
686 void FormDocument::options_update(BufferParams const & params)
691 fl_set_choice_text(options_->choice_postscript_driver,
692 params.graphicsDriver.c_str());
693 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
694 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
695 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
696 if (!params.float_placement.empty())
697 fl_set_input(options_->input_float_placement,
698 params.float_placement.c_str());
700 fl_set_input(options_->input_float_placement, "");
704 void FormDocument::paper_update(BufferParams const & params)
709 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
710 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
711 fl_set_button(paper_->push_use_geometry, params.use_geometry);
712 fl_set_button(paper_->radio_portrait, 0);
713 fl_set_button(paper_->radio_landscape, 0);
714 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
715 fl_set_button(paper_->radio_landscape, 1);
717 fl_set_button(paper_->radio_portrait, 1);
718 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
719 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
720 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
721 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
722 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
723 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
724 fl_set_input(paper_->input_head_height, params.headheight.c_str());
725 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
726 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
727 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
731 void FormDocument::bullets_update(BufferParams const & params)
733 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
736 if (lv_->buffer()->isLinuxDoc()) {
737 fl_deactivate_object(fbullet);
738 fl_set_object_lcol(fbullet, FL_INACTIVE);
741 fl_activate_object(fbullet);
742 fl_set_object_lcol(fbullet, FL_BLACK);
745 fl_set_button(bullets_->radio_bullet_depth_1, 1);
746 fl_set_input(bullets_->input_bullet_latex,
747 params.user_defined_bullets[0].getText().c_str());
748 fl_set_choice(bullets_->choice_bullet_size,
749 params.user_defined_bullets[0].getSize() + 2);
753 void FormDocument::InputCB(FL_OBJECT * ob, long)
755 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
756 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
760 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
762 FormDocument * pre = static_cast<FormDocument*>(v);
763 if (combox == pre->combo_doc_class)
764 pre->CheckChoiceClass(0, 0);
765 pre->bc_.valid(pre->CheckDocumentInput(0,0));
769 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
771 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
772 pre->CheckChoiceClass(ob,0);
773 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
777 void FormDocument::checkReadOnly()
779 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
780 combo_doc_class->deactivate();
781 combo_language->deactivate();
782 fl_set_object_label(dialog_->text_warning,
783 _("Document is read-only."
784 " No changes to layout permitted."));
785 fl_show_object(dialog_->text_warning);
787 combo_doc_class->activate();
788 combo_language->activate();
789 fl_hide_object(dialog_->text_warning);
794 void FormDocument::checkMarginValues()
796 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
797 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
798 !strlen(fl_get_input(paper_->input_left_margin)) &&
799 !strlen(fl_get_input(paper_->input_right_margin)) &&
800 !strlen(fl_get_input(paper_->input_head_height)) &&
801 !strlen(fl_get_input(paper_->input_head_sep)) &&
802 !strlen(fl_get_input(paper_->input_foot_skip)) &&
803 !strlen(fl_get_input(paper_->input_custom_width)) &&
804 !strlen(fl_get_input(paper_->input_custom_height)));
806 fl_set_button(paper_->push_use_geometry, 1);
809 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
817 if (ob == paper_->choice_papersize2) {
818 val = fl_get_choice(paper_->choice_papersize2)-1;
819 if (val == BufferParams::VM_PAPER_DEFAULT) {
820 fl_set_button(paper_->push_use_geometry, 0);
823 if ((val != BufferParams::VM_PAPER_USLETTER) &&
824 (val != BufferParams::VM_PAPER_USLEGAL) &&
825 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
826 (val != BufferParams::VM_PAPER_A4) &&
827 (val != BufferParams::VM_PAPER_A5) &&
828 (val != BufferParams::VM_PAPER_B5)) {
829 fl_set_button(paper_->push_use_geometry, 1);
831 fl_set_choice(paper_->choice_paperpackage,
832 BufferParams::PACKAGE_NONE + 1);
834 } else if (ob == paper_->choice_paperpackage) {
835 val = fl_get_choice(paper_->choice_paperpackage)-1;
836 if (val != BufferParams::PACKAGE_NONE) {
837 fl_set_choice(paper_->choice_papersize2,
838 BufferParams::VM_PAPER_DEFAULT + 1);
839 fl_set_button(paper_->push_use_geometry, 0);
841 } else if (ob == class_->input_doc_spacing) {
842 input = fl_get_input(class_->input_doc_spacing);
844 fl_set_choice (class_->choice_doc_spacing, 1);
846 fl_set_choice(class_->choice_doc_spacing, 4);
849 // this has to be all out of if/elseif because it has to deactivate
850 // the document buttons and so the whole stuff has to be tested again.
851 str = fl_get_input(paper_->input_custom_width);
852 ok = ok && (str.empty() || isValidLength(str));
853 str = fl_get_input(paper_->input_custom_height);
854 ok = ok && (str.empty() || isValidLength(str));
855 str = fl_get_input(paper_->input_left_margin);
856 ok = ok && (str.empty() || isValidLength(str));
857 str = fl_get_input(paper_->input_right_margin);
858 ok = ok && (str.empty() || isValidLength(str));
859 str = fl_get_input(paper_->input_top_margin);
860 ok = ok && (str.empty() || isValidLength(str));
861 str = fl_get_input(paper_->input_bottom_margin);
862 ok = ok && (str.empty() || isValidLength(str));
863 str = fl_get_input(paper_->input_head_height);
864 ok = ok && (str.empty() || isValidLength(str));
865 str = fl_get_input(paper_->input_head_sep);
866 ok = ok && (str.empty() || isValidLength(str));
867 str = fl_get_input(paper_->input_foot_skip);
868 ok = ok && (str.empty() || isValidLength(str));
869 // "Synchronize" the choice and the input field, so that it
870 // is impossible to commit senseless data.
871 input = fl_get_input (class_->input_doc_skip);
872 if (ob == class_->input_doc_skip) {
874 fl_set_choice (class_->choice_doc_skip, 2);
875 } else if (isValidGlueLength (input)) {
876 fl_set_choice (class_->choice_doc_skip, 4);
878 fl_set_choice(class_->choice_doc_skip, 4);
882 if (*input && !isValidGlueLength(input))
885 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
887 else if (fl_get_choice(class_->choice_doc_skip) != 4)
888 fl_set_input (class_->input_doc_skip, "");
890 input = fl_get_input(class_->input_doc_spacing);
891 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
893 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
894 fl_set_input (class_->input_doc_spacing, "");
899 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
901 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
902 pre->ChoiceBulletSize(ob,0);
903 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
907 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
909 BufferParams & param = lv_->buffer()->params;
911 // convert from 1-6 range to -1-4
912 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
913 fl_set_input(bullets_->input_bullet_latex,
914 param.temp_bullets[current_bullet_depth].getText().c_str());
918 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
920 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
921 pre->InputBulletLaTeX(ob,0);
922 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
926 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
928 BufferParams & param = lv_->buffer()->params;
930 param.temp_bullets[current_bullet_depth].
931 setText(fl_get_input(bullets_->input_bullet_latex));
935 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long data)
937 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
938 pre->BulletDepth(ob, data);
942 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
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;
954 switch (fl_get_button_numb(ob)) {
956 // right mouse button resets to default
957 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
959 current_bullet_depth = data;
960 fl_set_input(bullets_->input_bullet_latex,
961 param.temp_bullets[data].getText().c_str());
962 fl_set_choice(bullets_->choice_bullet_size,
963 param.temp_bullets[data].getSize() + 2);
968 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
970 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
971 pre->BulletPanel(ob,data);
975 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
977 /* Here we have to change the background pixmap to that selected */
978 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
980 if (data != current_bullet_panel) {
981 fl_freeze_form(bullets_->form);
982 current_bullet_panel = data;
984 /* free the current pixmap */
985 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
988 /* display the new one */
990 new_panel = "standard";
993 new_panel = "amssymb";
996 new_panel = "psnfss1";
999 new_panel = "psnfss2";
1002 new_panel = "psnfss3";
1005 new_panel = "psnfss4";
1008 /* something very wrong happened */
1009 // play it safe for now but should be an exception
1010 current_bullet_panel = 0; // standard panel
1011 new_panel = "standard";
1014 new_panel += ".xpm";
1015 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1016 LibFileSearch("images", new_panel.c_str()).c_str());
1017 fl_redraw_object(bullets_->bmtable_bullet_panel);
1018 fl_unfreeze_form(bullets_->form);
1023 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1025 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1026 pre->BulletBMTable(ob,0);
1027 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
1031 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1033 /* handle the user input by setting the current bullet depth's pixmap */
1034 /* to that extracted from the current chosen position of the BMTable */
1035 /* Don't forget to free the button's old pixmap first. */
1037 BufferParams & param = lv_->buffer()->params;
1038 int bmtable_button = fl_get_bmtable(ob);
1040 /* try to keep the button held down till another is pushed */
1041 /* fl_set_bmtable(ob, 1, bmtable_button); */
1042 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1043 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1044 fl_set_input(bullets_->input_bullet_latex,
1045 param.temp_bullets[current_bullet_depth].getText().c_str());
1049 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1052 ob = class_->choice_doc_class;
1054 ProhibitInput(lv_->view());
1058 #ifdef USE_CLASS_COMBO
1059 tc = combo_doc_class->get() - 1;
1060 tct = combo_doc_class->getline();
1062 tc = fl_get_choice(ob) - 1;
1063 tct = fl_get_choice_text(ob);
1065 if (textclasslist.Load(tc)) {
1066 if (AskQuestion(_("Should I set some parameters to"), tct,
1067 _("the defaults of this document class?"))) {
1068 BufferParams & params = lv_->buffer()->params;
1070 params.textclass = tc;
1071 params.useClassDefaults();
1072 UpdateLayoutDocument(params);
1075 // unable to load new style
1076 WriteAlert(_("Conversion Errors!"),
1077 _("Unable to switch to new document class."),
1078 _("Reverting to original document class."));
1079 #ifdef USE_CLASS_COMBO
1080 combo_doc_class->select(lv_->buffer()->params.textclass + 1);
1082 fl_set_choice(class_->choice_doc_class,
1083 lv_->buffer()->params.textclass + 1);
1086 AllowInput(lv_->view());
1090 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1096 class_update(params);
1097 paper_update(params);
1098 language_update(params);
1099 options_update(params);
1100 bullets_update(params);