1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 2000 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include "lyx_gui_misc.h"
20 #include FORMS_H_LOCATION
21 #include XPM_H_LOCATION
23 #include "FormDocument.h"
24 #include "form_document.h"
25 #include "xform_macros.h"
29 #include "tex-strings.h"
30 #include "bufferparams.h"
31 #include "insets/insetquotes.h"
34 #include "support/filetools.h"
37 #include "BufferView.h"
40 #include "CutAndPaste.h"
41 #include "bufferview_funcs.h"
42 #include "ButtonController.h"
44 #ifdef SIGC_CXX_NAMESPACES
48 #ifdef CXX_WORKING_NAMESPACES
49 using Liason::setMinibuffer;
52 C_RETURNCB(FormDocument, WMHideCB)
53 C_GENERICCB(FormDocument, InputCB)
54 C_GENERICCB(FormDocument, OKCB)
55 C_GENERICCB(FormDocument, ApplyCB)
56 C_GENERICCB(FormDocument, CancelCB)
57 C_GENERICCB(FormDocument, RestoreCB)
58 C_GENERICCB(FormDocument, ChoiceClassCB)
59 C_GENERICCB(FormDocument, BulletPanelCB)
60 C_GENERICCB(FormDocument, BulletDepthCB)
61 C_GENERICCB(FormDocument, InputBulletLaTeXCB)
62 C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
64 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
65 : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
66 bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
67 status(POPUP_UNMODIFIED) ,
68 bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
71 // let the popup be shown
72 // This is a permanent connection so we won't bother
73 // storing a copy because we won't be disconnecting.
74 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
75 current_bullet_depth = 0;
76 current_bullet_panel = 0;
79 FormDocument::~FormDocument()
85 void FormDocument::build()
90 dialog_ = build_tabbed_document();
92 // manage the restore, save, apply and cancel/close buttons
93 bc_->setOK(dialog_->button_ok);
94 bc_->setApply(dialog_->button_apply);
95 bc_->setCancel(dialog_->button_cancel);
96 bc_->setUndoAll(dialog_->button_restore);
99 // the document paper form
100 paper_ = build_doc_paper();
101 fl_addto_choice(paper_->choice_papersize2,
102 _(" Default | Custom | USletter | USlegal "
103 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
104 fl_addto_choice(paper_->choice_paperpackage,
106 "| A4 small Margins (only portrait) "
107 "| A4 very small Margins (only portrait) "
108 "| A4 very wide margins (only portrait) "));
109 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
110 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
111 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
112 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
117 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
119 // the document class form
120 class_ = build_doc_class();
121 fl_clear_choice(class_->choice_doc_class);
122 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
123 cit != textclasslist.end(); ++cit)
125 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
127 fl_addto_choice(class_->choice_doc_spacing,
128 _(" Single | OneHalf | Double | Other "));
129 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
130 for (n=0; tex_fonts[n][0]; ++n) {
131 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
133 fl_addto_choice(class_->choice_doc_pagestyle,
134 "default|empty|plain|headings|fancy");
135 fl_addto_choice(class_->choice_doc_skip,
136 _(" Smallskip | Medskip | Bigskip | Length "));
137 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
138 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
140 // the document language form
141 language_ = build_doc_language();
142 fl_addto_choice(language_->choice_inputenc,
143 "default|auto|latin1|latin2|latin5"
144 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
146 // The language is a combo-box and has to be inserted manually
147 FL_OBJECT * obj = language_->choice_language;
148 fl_addto_form(language_->form);
149 combo_language = new Combox(FL_COMBOX_DROPLIST);
150 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
151 combo_language->shortcut("#L",1);
153 // "default" is not part of the languages array any more.
154 combo_language->addto("default");
155 for(Languages::const_iterator cit = languages.begin();
156 cit != languages.end(); ++cit) {
157 combo_language->addto((*cit).second.lang().c_str());
160 fl_addto_choice(language_->choice_quotes_language,
161 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
162 " «text» | »text« "));
164 // the document options form
165 options_ = build_doc_options();
166 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
167 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
168 fl_set_counter_step(options_->slider_secnumdepth,1,1);
169 fl_set_counter_step(options_->slider_tocdepth,1,1);
170 fl_set_counter_precision(options_->slider_secnumdepth, 0);
171 fl_set_counter_precision(options_->slider_tocdepth, 0);
172 for (n=0; tex_graphics[n][0]; ++n) {
173 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
176 // the document bullets form
177 bullets_ = build_doc_bullet();
178 fl_addto_choice(bullets_->choice_bullet_size,
179 _(" default | tiny | script | footnote | small |"
180 " normal | large | Large | LARGE | huge | Huge"));
181 fl_set_choice(bullets_->choice_bullet_size, 1);
182 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
183 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
185 fl_set_form_atclose(dialog_->form,
186 FormDocument::WMHideCB, 0);
187 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
189 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
191 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
193 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
195 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
197 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
198 lyxerr << _("Your version of libXpm is older than 4.7.\n"
199 "The `bullet' tab of the document popup "
200 "has been disabled") << '\n';
201 fl_deactivate_object(fbullet);
202 fl_set_object_lcol(fbullet, FL_INACTIVE);
206 void FormDocument::show()
211 update(); // make sure its up-to-date
212 if (dialog_->form->visible) {
213 fl_raise_form(dialog_->form);
215 fl_show_form(dialog_->form,
216 FL_PLACE_MOUSE | FL_FREE_SIZE,
217 FL_TRANSIENT, _("Document Layout"));
218 u_ = d_->updateBufferDependent.connect(
219 slot(this, &FormDocument::update));
220 h_ = d_->hideBufferDependent.connect(
221 slot(this, &FormDocument::hide));
225 void FormDocument::hide()
227 if (dialog_->form->visible) {
228 fl_hide_form(dialog_->form);
234 void FormDocument::apply()
236 if (!lv_->view()->available() || !dialog_)
242 redo = class_apply();
244 redo = language_apply() || redo;
245 redo = options_apply() || redo;
249 lv_->view()->redoCurrentBuffer();
251 lv_->buffer()->markDirty();
252 setMinibuffer(lv_, _("Document layout set"));
256 bool FormDocument::class_apply()
259 BufferParams ¶ms = lv_->buffer()->params;
261 // If default skip is a "Length" but there's no text in the
262 // input field, reset the kind to "Medskip", which is the default.
263 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
264 !*(fl_get_input (class_->input_doc_skip))) {
265 fl_set_choice (class_->choice_doc_skip, 2);
267 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
268 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
269 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
271 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
272 if (params.textclass != new_class) {
273 // try to load new_class
274 if (textclasslist.Load(new_class)) {
275 // successfully loaded
277 setMinibuffer(lv_, _("Converting document to new document class..."));
279 int ret = cap.SwitchLayoutsBetweenClasses(
280 params.textclass, new_class,
281 lv_->buffer()->paragraph);
285 s = _("One paragraph couldn't be converted");
288 s += _(" paragraphs couldn't be converted");
290 WriteAlert(_("Conversion Errors!"),s,
291 _("into chosen document class"));
294 params.textclass = new_class;
296 // problem changing class -- warn user and retain old style
297 WriteAlert(_("Conversion Errors!"),
298 _("Errors loading new document class."),
299 _("Reverting to original document class."));
300 fl_set_choice(class_->choice_doc_class,
301 params.textclass + 1);
304 char tmpsep = params.paragraph_separation;
305 if (fl_get_button(class_->radio_doc_indent))
306 params.paragraph_separation = BufferParams::PARSEP_INDENT;
308 params.paragraph_separation = BufferParams::PARSEP_SKIP;
309 if (tmpsep != params.paragraph_separation)
312 VSpace tmpdefskip = params.getDefSkip();
313 switch (fl_get_choice (class_->choice_doc_skip)) {
315 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
318 params.setDefSkip(VSpace(VSpace::MEDSKIP));
321 params.setDefSkip(VSpace(VSpace::BIGSKIP));
325 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
327 // DocumentDefskipCB assures that this never happens
329 params.setDefSkip(VSpace(VSpace::MEDSKIP));
332 if (!(tmpdefskip == params.getDefSkip()))
335 if (fl_get_button(class_->radio_doc_columns_two))
339 if (fl_get_button(class_->radio_doc_sides_two))
340 params.sides = LyXTextClass::TwoSides;
342 params.sides = LyXTextClass::OneSide;
344 Spacing tmpSpacing = params.spacing;
345 switch(fl_get_choice(class_->choice_doc_spacing)) {
347 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
348 params.spacing.set(Spacing::Single);
351 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
352 params.spacing.set(Spacing::Onehalf);
355 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
356 params.spacing.set(Spacing::Double);
359 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
360 params.spacing.set(Spacing::Other,
361 fl_get_input(class_->input_doc_spacing));
364 if (tmpSpacing != params.spacing)
367 params.options = fl_get_input(class_->input_doc_extra);
372 void FormDocument::paper_apply()
375 ¶ms = lv_->buffer()->params;
377 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
378 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
379 params.use_geometry = fl_get_button(paper_->push_use_geometry);
380 if (fl_get_button(paper_->radio_landscape))
381 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
383 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
384 params.paperwidth = fl_get_input(paper_->input_custom_width);
385 params.paperheight = fl_get_input(paper_->input_custom_height);
386 params.leftmargin = fl_get_input(paper_->input_left_margin);
387 params.topmargin = fl_get_input(paper_->input_top_margin);
388 params.rightmargin = fl_get_input(paper_->input_right_margin);
389 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
390 params.headheight = fl_get_input(paper_->input_head_height);
391 params.headsep = fl_get_input(paper_->input_head_sep);
392 params.footskip = fl_get_input(paper_->input_foot_skip);
393 lv_->buffer()->setPaperStuff();
396 bool FormDocument::language_apply()
399 ¶ms = lv_->buffer()->params;
400 InsetQuotes::quote_language
401 lga = InsetQuotes::EnglishQ;
404 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
406 lga = InsetQuotes::EnglishQ;
409 lga = InsetQuotes::SwedishQ;
412 lga = InsetQuotes::GermanQ;
415 lga = InsetQuotes::PolishQ;
418 lga = InsetQuotes::FrenchQ;
421 lga = InsetQuotes::DanishQ;
424 params.quotes_language = lga;
425 if (fl_get_button(language_->radio_single))
426 params.quotes_times = InsetQuotes::SingleQ;
428 params.quotes_times = InsetQuotes::DoubleQ;
430 Language const * old_language = params.language_info;
431 params.language = combo_language->getline();
432 Languages::iterator lit = languages.find(params.language);
434 Language const * new_language;
435 if (lit != languages.end())
436 new_language = &(*lit).second;
438 new_language = default_language;
440 if (old_language != new_language
441 && old_language->RightToLeft() == new_language->RightToLeft()
442 && !lv_->buffer()->isMultiLingual())
443 lv_->buffer()->ChangeLanguage(old_language, new_language);
444 if (old_language != new_language) {
447 params.language_info = new_language;
448 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
453 bool FormDocument::options_apply()
456 ¶ms = lv_->buffer()->params;
460 params.graphicsDriver =
461 fl_get_choice_text(options_->choice_postscript_driver);
462 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
464 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
465 if (params.secnumdepth != tmpchar)
467 params.secnumdepth = tmpchar;
469 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
471 params.float_placement =
472 fl_get_input(options_->input_float_placement);
477 void FormDocument::bullets_apply()
479 /* update the bullet settings */
480 BufferParams & param = lv_->buffer()->params;
482 // a little bit of loop unrolling
483 param.user_defined_bullets[0] = param.temp_bullets[0];
484 param.user_defined_bullets[1] = param.temp_bullets[1];
485 param.user_defined_bullets[2] = param.temp_bullets[2];
486 param.user_defined_bullets[3] = param.temp_bullets[3];
489 void FormDocument::cancel()
491 // this avoids confusion when reopening
492 BufferParams & param = lv_->buffer()->params;
493 param.temp_bullets[0] = param.user_defined_bullets[0];
494 param.temp_bullets[1] = param.user_defined_bullets[1];
495 param.temp_bullets[2] = param.user_defined_bullets[2];
496 param.temp_bullets[3] = param.user_defined_bullets[3];
499 void FormDocument::update()
503 fl_hide_object(dialog_->text_warning);
504 EnableDocumentLayout();
505 if (lv_->buffer()->isReadonly()) {
506 DisableDocumentLayout();
507 fl_set_object_label(dialog_->text_warning,
508 _("Document is read-only."
509 " No changes to layout permitted."));
510 fl_show_object(dialog_->text_warning);
514 const & params = lv_->buffer()->params;
516 class_update(params);
517 paper_update(params);
518 language_update(params);
519 options_update(params);
520 bullets_update(params);
523 void FormDocument::class_update(BufferParams const & params)
528 const & tclass = textclasslist.TextClass(params.textclass);
530 fl_set_choice_text(class_->choice_doc_class,
531 textclasslist.DescOfClass(params.textclass).c_str());
532 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
533 fl_clear_choice(class_->choice_doc_fontsize);
534 fl_addto_choice(class_->choice_doc_fontsize, "default");
535 fl_addto_choice(class_->choice_doc_fontsize,
536 tclass.opt_fontsize().c_str());
537 fl_set_choice(class_->choice_doc_fontsize,
538 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
539 fl_clear_choice(class_->choice_doc_pagestyle);
540 fl_addto_choice(class_->choice_doc_pagestyle, "default");
541 fl_addto_choice(class_->choice_doc_pagestyle,
542 tclass.opt_pagestyle().c_str());
543 fl_set_choice(class_->choice_doc_pagestyle,
544 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
545 fl_set_button(class_->radio_doc_indent, 0);
546 fl_set_button(class_->radio_doc_skip, 0);
547 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
548 fl_set_button(class_->radio_doc_indent, 1);
550 fl_set_button(class_->radio_doc_skip, 1);
551 switch (params.getDefSkip().kind()) {
552 case VSpace::SMALLSKIP:
553 fl_set_choice (class_->choice_doc_skip, 1);
555 case VSpace::MEDSKIP:
556 fl_set_choice (class_->choice_doc_skip, 2);
558 case VSpace::BIGSKIP:
559 fl_set_choice (class_->choice_doc_skip, 3);
562 fl_set_choice (class_->choice_doc_skip, 4);
563 fl_set_input (class_->input_doc_skip,
564 params.getDefSkip().asLyXCommand().c_str());
567 fl_set_choice (class_->choice_doc_skip, 2);
570 fl_set_button(class_->radio_doc_sides_one, 0);
571 fl_set_button(class_->radio_doc_sides_two, 0);
572 if (params.sides == 2)
573 fl_set_button(class_->radio_doc_sides_two, 1);
575 fl_set_button(class_->radio_doc_sides_one, 1);
576 fl_set_button(class_->radio_doc_columns_one, 0);
577 fl_set_button(class_->radio_doc_columns_two, 0);
578 if (params.columns == 2)
579 fl_set_button(class_->radio_doc_columns_two, 1);
581 fl_set_button(class_->radio_doc_columns_one, 1);
582 fl_set_input(class_->input_doc_spacing, "");
583 switch (params.spacing.getSpace()) {
584 case Spacing::Default: // nothing bad should happen with this
585 case Spacing::Single:
587 fl_set_choice(class_->choice_doc_spacing, 1);
589 case Spacing::Onehalf:
591 fl_set_choice(class_->choice_doc_spacing, 2);
593 case Spacing::Double:
595 fl_set_choice(class_->choice_doc_spacing, 3);
599 fl_set_choice(class_->choice_doc_spacing, 4);
601 sprintf(sval,"%g",params.spacing.getValue());
602 fl_set_input(class_->input_doc_spacing, sval);
606 if (!params.options.empty())
607 fl_set_input(class_->input_doc_extra, params.options.c_str());
609 fl_set_input(class_->input_doc_extra, "");
612 void FormDocument::language_update(BufferParams const & params)
617 combo_language->select_text(params.language.c_str());
618 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
619 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
620 fl_set_button(language_->radio_single, 0);
621 fl_set_button(language_->radio_double, 0);
622 if (params.quotes_times == InsetQuotes::SingleQ)
623 fl_set_button(language_->radio_single, 1);
625 fl_set_button(language_->radio_double, 1);
628 void FormDocument::options_update(BufferParams const & params)
633 fl_set_choice_text(options_->choice_postscript_driver,
634 params.graphicsDriver.c_str());
635 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
636 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
637 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
638 if (!params.float_placement.empty())
639 fl_set_input(options_->input_float_placement,
640 params.float_placement.c_str());
642 fl_set_input(options_->input_float_placement, "");
645 void FormDocument::paper_update(BufferParams const & params)
650 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
651 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
652 fl_set_button(paper_->push_use_geometry, params.use_geometry);
653 fl_set_button(paper_->radio_portrait, 0);
654 fl_set_button(paper_->radio_landscape, 0);
655 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
656 fl_set_button(paper_->radio_landscape, 1);
658 fl_set_button(paper_->radio_portrait, 1);
659 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
660 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
661 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
662 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
663 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
664 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
665 fl_set_input(paper_->input_head_height, params.headheight.c_str());
666 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
667 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
668 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
671 void FormDocument::bullets_update(BufferParams const & params)
673 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
676 if (lv_->buffer()->isLinuxDoc()) {
677 fl_deactivate_object(fbullet);
678 fl_set_object_lcol(fbullet, FL_INACTIVE);
681 fl_activate_object(fbullet);
682 fl_set_object_lcol(fbullet, FL_BLACK);
684 if (lv_->buffer()->isReadonly()) {
685 fl_deactivate_object (bullets_->bmtable_bullet_panel);
686 fl_deactivate_object (bullets_->choice_bullet_size);
687 fl_deactivate_object (bullets_->input_bullet_latex);
689 fl_activate_object (bullets_->bmtable_bullet_panel);
690 fl_activate_object (bullets_->choice_bullet_size);
691 fl_activate_object (bullets_->input_bullet_latex);
694 fl_set_button(bullets_->radio_bullet_depth_1, 1);
695 fl_set_input(bullets_->input_bullet_latex,
696 params.user_defined_bullets[0].c_str());
697 fl_set_choice(bullets_->choice_bullet_size,
698 params.user_defined_bullets[0].getSize() + 2);
701 void FormDocument::free()
706 fl_free_form(class_->form);
711 fl_free_form(paper_->form);
716 delete combo_language;
717 fl_free_form(language_->form);
722 fl_free_form(options_->form);
727 fl_free_form(bullets_->form);
731 fl_free_form(dialog_->form);
737 int FormDocument::WMHideCB(FL_FORM * form, void *)
739 // Ensure that the signals (u and h) are disconnected even if the
740 // window manager is used to close the popup.
741 FormDocument * pre = (FormDocument*)form->u_vdata;
747 void FormDocument::OKCB(FL_OBJECT * ob, long)
749 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
755 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
757 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
762 void FormDocument::CancelCB(FL_OBJECT * ob, long)
764 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
770 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
772 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
777 void FormDocument::InputCB(FL_OBJECT * ob, long)
779 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
780 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
783 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
785 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
786 pre->CheckChoiceClass(ob,0);
787 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
790 void FormDocument::checkMarginValues()
794 allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
795 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
796 !strlen(fl_get_input(paper_->input_left_margin)) &&
797 !strlen(fl_get_input(paper_->input_right_margin)) &&
798 !strlen(fl_get_input(paper_->input_head_height)) &&
799 !strlen(fl_get_input(paper_->input_head_sep)) &&
800 !strlen(fl_get_input(paper_->input_foot_skip)) &&
801 !strlen(fl_get_input(paper_->input_custom_width)) &&
802 !strlen(fl_get_input(paper_->input_custom_height)));
804 fl_set_button(paper_->push_use_geometry, 1);
807 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
815 if (ob == paper_->choice_papersize2) {
816 val = fl_get_choice(paper_->choice_papersize2)-1;
817 if (val == BufferParams::VM_PAPER_DEFAULT) {
818 fl_set_button(paper_->push_use_geometry, 0);
821 if ((val != BufferParams::VM_PAPER_USLETTER) &&
822 (val != BufferParams::VM_PAPER_USLEGAL) &&
823 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
824 (val != BufferParams::VM_PAPER_A4) &&
825 (val != BufferParams::VM_PAPER_A5) &&
826 (val != BufferParams::VM_PAPER_B5)) {
827 fl_set_button(paper_->push_use_geometry, 1);
829 fl_set_choice(paper_->choice_paperpackage,
830 BufferParams::PACKAGE_NONE + 1);
832 } else if (ob == paper_->choice_paperpackage) {
833 val = fl_get_choice(paper_->choice_paperpackage)-1;
834 if (val != BufferParams::PACKAGE_NONE) {
835 fl_set_choice(paper_->choice_papersize2,
836 BufferParams::VM_PAPER_DEFAULT + 1);
837 fl_set_button(paper_->push_use_geometry, 0);
839 } else if (ob == class_->input_doc_spacing) {
840 input = fl_get_input(class_->input_doc_spacing);
842 fl_set_choice (class_->choice_doc_spacing, 1);
844 fl_set_choice(class_->choice_doc_spacing, 4);
847 // this has to be all out of if/elseif because it has to deactivate
848 // the document buttons and so the whole stuff has to be tested again.
849 str = fl_get_input(paper_->input_custom_width);
850 ok = ok && (str.empty() || isValidLength(str));
851 str = fl_get_input(paper_->input_custom_height);
852 ok = ok && (str.empty() || isValidLength(str));
853 str = fl_get_input(paper_->input_left_margin);
854 ok = ok && (str.empty() || isValidLength(str));
855 str = fl_get_input(paper_->input_right_margin);
856 ok = ok && (str.empty() || isValidLength(str));
857 str = fl_get_input(paper_->input_top_margin);
858 ok = ok && (str.empty() || isValidLength(str));
859 str = fl_get_input(paper_->input_bottom_margin);
860 ok = ok && (str.empty() || isValidLength(str));
861 str = fl_get_input(paper_->input_head_height);
862 ok = ok && (str.empty() || isValidLength(str));
863 str = fl_get_input(paper_->input_head_sep);
864 ok = ok && (str.empty() || isValidLength(str));
865 str = fl_get_input(paper_->input_foot_skip);
866 ok = ok && (str.empty() || isValidLength(str));
867 // "Synchronize" the choice and the input field, so that it
868 // is impossible to commit senseless data.
869 input = fl_get_input (class_->input_doc_skip);
870 if (ob == class_->input_doc_skip) {
872 fl_set_choice (class_->choice_doc_skip, 2);
873 } else if (isValidGlueLength (input)) {
874 fl_set_choice (class_->choice_doc_skip, 4);
876 fl_set_choice(class_->choice_doc_skip, 4);
880 if (*input && !isValidGlueLength(input))
883 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
885 else if (fl_get_choice(class_->choice_doc_skip) != 4)
886 fl_set_input (class_->input_doc_skip, "");
888 input = fl_get_input(class_->input_doc_spacing);
889 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
891 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
892 fl_set_input (class_->input_doc_spacing, "");
896 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
898 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
899 pre->ChoiceBulletSize(ob,0);
900 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
903 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
905 BufferParams & param = lv_->buffer()->params;
907 // convert from 1-6 range to -1-4
908 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
909 fl_set_input(bullets_->input_bullet_latex,
910 param.temp_bullets[current_bullet_depth].c_str());
913 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
915 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
916 pre->InputBulletLaTeX(ob,0);
917 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
920 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
922 BufferParams & param = lv_->buffer()->params;
924 param.temp_bullets[current_bullet_depth].
925 setText(fl_get_input(bullets_->input_bullet_latex));
928 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
930 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
931 pre->BulletDepth(ob,0);
934 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
936 /* Should I do the following: */
937 /* 1. change to the panel that the current bullet belongs in */
938 /* 2. show that bullet as selected */
939 /* 3. change the size setting to the size of the bullet in Q.*/
940 /* 4. display the latex equivalent in the latex box */
942 /* I'm inclined to just go with 3 and 4 at the moment and */
943 /* maybe try to support the others later */
944 BufferParams & param = lv_->buffer()->params;
946 switch (fl_get_button_numb(ob)) {
948 // right mouse button resets to default
949 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
951 current_bullet_depth = data;
952 fl_set_input(bullets_->input_bullet_latex,
953 param.temp_bullets[data].c_str());
954 fl_set_choice(bullets_->choice_bullet_size,
955 param.temp_bullets[data].getSize() + 2);
959 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
961 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
962 pre->BulletPanel(ob,data);
965 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
967 /* Here we have to change the background pixmap to that selected */
968 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
970 if (data != current_bullet_panel) {
971 fl_freeze_form(bullets_->form);
972 current_bullet_panel = data;
974 /* free the current pixmap */
975 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
978 /* display the new one */
980 new_panel = "standard";
983 new_panel = "amssymb";
986 new_panel = "psnfss1";
989 new_panel = "psnfss2";
992 new_panel = "psnfss3";
995 new_panel = "psnfss4";
998 /* something very wrong happened */
999 // play it safe for now but should be an exception
1000 current_bullet_panel = 0; // standard panel
1001 new_panel = "standard";
1004 new_panel += ".xpm";
1005 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1006 LibFileSearch("images", new_panel.c_str()).c_str());
1007 fl_redraw_object(bullets_->bmtable_bullet_panel);
1008 fl_unfreeze_form(bullets_->form);
1012 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1014 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1015 pre->BulletBMTable(ob,0);
1016 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1019 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1021 /* handle the user input by setting the current bullet depth's pixmap */
1022 /* to that extracted from the current chosen position of the BMTable */
1023 /* Don't forget to free the button's old pixmap first. */
1025 BufferParams & param = lv_->buffer()->params;
1026 int bmtable_button = fl_get_bmtable(ob);
1028 /* try to keep the button held down till another is pushed */
1029 /* fl_set_bmtable(ob, 1, bmtable_button); */
1030 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1031 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1032 fl_set_input(bullets_->input_bullet_latex,
1033 param.temp_bullets[current_bullet_depth].c_str());
1036 void FormDocument::EnableDocumentLayout()
1038 fl_activate_object (class_->radio_doc_indent);
1039 fl_activate_object (class_->radio_doc_skip);
1040 fl_activate_object (class_->choice_doc_class);
1041 fl_activate_object (class_->choice_doc_pagestyle);
1042 fl_activate_object (class_->choice_doc_fonts);
1043 fl_activate_object (class_->choice_doc_fontsize);
1044 fl_activate_object (class_->radio_doc_sides_one);
1045 fl_activate_object (class_->radio_doc_sides_two);
1046 fl_activate_object (class_->radio_doc_columns_one);
1047 fl_activate_object (class_->radio_doc_columns_two);
1048 fl_activate_object (class_->input_doc_extra);
1049 fl_activate_object (class_->input_doc_skip);
1050 fl_activate_object (class_->choice_doc_skip);
1051 fl_activate_object (class_->choice_doc_spacing);
1052 fl_activate_object (class_->input_doc_spacing);
1054 fl_activate_object (language_->choice_language);
1055 combo_language->activate();
1056 fl_activate_object (language_->choice_language);
1057 fl_activate_object (language_->choice_inputenc);
1059 fl_activate_object (options_->slider_secnumdepth);
1060 fl_activate_object (options_->slider_tocdepth);
1061 fl_activate_object (options_->check_use_amsmath);
1062 fl_activate_object (options_->input_float_placement);
1063 fl_activate_object (options_->choice_postscript_driver);
1065 fl_activate_object (paper_->choice_paperpackage);
1066 fl_activate_object (paper_->greoup_radio_orientation);
1067 fl_activate_object (paper_->radio_portrait);
1068 fl_activate_object (paper_->radio_landscape);
1069 fl_activate_object (paper_->choice_papersize2);
1070 fl_activate_object (paper_->push_use_geometry);
1071 fl_activate_object (paper_->input_custom_width);
1072 fl_activate_object (paper_->input_custom_height);
1073 fl_activate_object (paper_->input_top_margin);
1074 fl_activate_object (paper_->input_bottom_margin);
1075 fl_activate_object (paper_->input_left_margin);
1076 fl_activate_object (paper_->input_right_margin);
1077 fl_activate_object (paper_->input_head_height);
1078 fl_activate_object (paper_->input_head_sep);
1079 fl_activate_object (paper_->input_foot_skip);
1082 void FormDocument::DisableDocumentLayout()
1084 fl_deactivate_object (class_->radio_doc_indent);
1085 fl_deactivate_object (class_->radio_doc_skip);
1086 fl_deactivate_object (class_->choice_doc_class);
1087 fl_deactivate_object (class_->choice_doc_pagestyle);
1088 fl_deactivate_object (class_->choice_doc_fonts);
1089 fl_deactivate_object (class_->choice_doc_fontsize);
1090 fl_deactivate_object (class_->radio_doc_sides_one);
1091 fl_deactivate_object (class_->radio_doc_sides_two);
1092 fl_deactivate_object (class_->radio_doc_columns_one);
1093 fl_deactivate_object (class_->radio_doc_columns_two);
1094 fl_deactivate_object (class_->input_doc_extra);
1095 fl_deactivate_object (class_->input_doc_skip);
1096 fl_deactivate_object (class_->choice_doc_skip);
1097 fl_deactivate_object (class_->choice_doc_spacing);
1098 fl_deactivate_object (class_->input_doc_spacing);
1100 fl_deactivate_object (language_->choice_language);
1101 combo_language->deactivate();
1102 fl_deactivate_object (language_->choice_inputenc);
1104 fl_deactivate_object (options_->slider_secnumdepth);
1105 fl_deactivate_object (options_->slider_tocdepth);
1106 fl_deactivate_object (options_->check_use_amsmath);
1107 fl_deactivate_object (options_->input_float_placement);
1108 fl_deactivate_object (options_->choice_postscript_driver);
1110 fl_deactivate_object (paper_->choice_paperpackage);
1111 fl_deactivate_object (paper_->greoup_radio_orientation);
1112 fl_deactivate_object (paper_->radio_portrait);
1113 fl_deactivate_object (paper_->radio_landscape);
1114 fl_deactivate_object (paper_->choice_papersize2);
1115 fl_deactivate_object (paper_->push_use_geometry);
1116 fl_deactivate_object (paper_->input_custom_width);
1117 fl_deactivate_object (paper_->input_custom_height);
1118 fl_deactivate_object (paper_->input_top_margin);
1119 fl_deactivate_object (paper_->input_bottom_margin);
1120 fl_deactivate_object (paper_->input_left_margin);
1121 fl_deactivate_object (paper_->input_right_margin);
1122 fl_deactivate_object (paper_->input_head_height);
1123 fl_deactivate_object (paper_->input_head_sep);
1124 fl_deactivate_object (paper_->input_foot_skip);
1127 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1129 ProhibitInput(lv_->view());
1130 if (textclasslist.Load(fl_get_choice(ob)-1)) {
1131 if (AskQuestion(_("Should I set some parameters to"),
1132 fl_get_choice_text(ob),
1133 _("the defaults of this document class?"))) {
1134 BufferParams & params = lv_->buffer()->params;
1136 params.textclass = fl_get_choice(ob)-1;
1137 params.useClassDefaults();
1138 UpdateLayoutDocument(params);
1141 // unable to load new style
1142 WriteAlert(_("Conversion Errors!"),
1143 _("Unable to switch to new document class."),
1144 _("Reverting to original document class."));
1145 fl_set_choice(class_->choice_doc_class,
1146 lv_->view()->buffer()->params.textclass + 1);
1148 AllowInput(lv_->view());
1151 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1155 fl_hide_object(dialog_->text_warning);
1156 EnableDocumentLayout();
1157 if (lv_->buffer()->isReadonly()) {
1158 DisableDocumentLayout();
1159 fl_set_object_label(dialog_->text_warning,
1160 _("Document is read-only."
1161 " No changes to layout permitted."));
1162 fl_show_object(dialog_->text_warning);
1164 class_update(params);
1165 paper_update(params);
1166 language_update(params);
1167 options_update(params);
1168 bullets_update(params);