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<PreferencesPolicy>(_("Cancel"), _("Close")))
70 // let the popup be shown
71 // This is a permanent connection so we won't bother
72 // storing a copy because we won't be disconnecting.
73 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
74 current_bullet_depth = 0;
75 current_bullet_panel = 0;
78 FormDocument::~FormDocument()
84 void FormDocument::build()
89 dialog_ = build_tabbed_document();
91 // manage the restore, save, apply and cancel/close buttons
92 bc_->setOk(dialog_->button_ok);
93 bc_->setApply(dialog_->button_apply);
94 bc_->setCancel(dialog_->button_cancel);
95 bc_->setUndoAll(dialog_->button_restore);
98 // the document paper form
99 paper_ = build_doc_paper();
100 fl_addto_choice(paper_->choice_papersize2,
101 _(" Default | Custom | USletter | USlegal "
102 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
103 fl_addto_choice(paper_->choice_paperpackage,
105 "| A4 small Margins (only portrait) "
106 "| A4 very small Margins (only portrait) "
107 "| A4 very wide margins (only portrait) "));
108 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
109 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
110 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
111 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
112 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
118 // the document class form
119 class_ = build_doc_class();
120 fl_clear_choice(class_->choice_doc_class);
121 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
122 cit != textclasslist.end(); ++cit)
124 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
126 fl_addto_choice(class_->choice_doc_spacing,
127 _(" Single | OneHalf | Double | Other "));
128 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
129 for (n=0; tex_fonts[n][0]; ++n) {
130 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
132 fl_addto_choice(class_->choice_doc_pagestyle,
133 "default|empty|plain|headings|fancy");
134 fl_addto_choice(class_->choice_doc_skip,
135 _(" Smallskip | Medskip | Bigskip | Length "));
136 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
137 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
139 // the document language form
140 language_ = build_doc_language();
141 fl_addto_choice(language_->choice_inputenc,
142 "default|auto|latin1|latin2|latin5"
143 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
145 // The language is a combo-box and has to be inserted manually
146 FL_OBJECT * obj = language_->choice_language;
147 fl_addto_form(language_->form);
148 combo_language = new Combox(FL_COMBOX_DROPLIST);
149 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
150 combo_language->shortcut("#L",1);
152 // "default" is not part of the languages array any more.
153 combo_language->addto("default");
154 for(Languages::const_iterator cit = languages.begin();
155 cit != languages.end(); ++cit) {
156 combo_language->addto((*cit).second.lang().c_str());
159 fl_addto_choice(language_->choice_quotes_language,
160 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
161 " «text» | »text« "));
163 // the document options form
164 options_ = build_doc_options();
165 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
166 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
167 fl_set_counter_step(options_->slider_secnumdepth,1,1);
168 fl_set_counter_step(options_->slider_tocdepth,1,1);
169 fl_set_counter_precision(options_->slider_secnumdepth, 0);
170 fl_set_counter_precision(options_->slider_tocdepth, 0);
171 for (n=0; tex_graphics[n][0]; ++n) {
172 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
175 // the document bullets form
176 bullets_ = build_doc_bullet();
177 fl_addto_choice(bullets_->choice_bullet_size,
178 _(" default | tiny | script | footnote | small |"
179 " normal | large | Large | LARGE | huge | Huge"));
180 fl_set_choice(bullets_->choice_bullet_size, 1);
181 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
182 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
184 fl_set_form_atclose(dialog_->form,
185 FormDocument::WMHideCB, 0);
186 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
188 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
190 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
192 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
194 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
196 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
197 lyxerr << _("Your version of libXpm is older than 4.7.\n"
198 "The `bullet' tab of the document popup "
199 "has been disabled") << '\n';
200 fl_deactivate_object(fbullet);
201 fl_set_object_lcol(fbullet, FL_INACTIVE);
205 void FormDocument::show()
210 update(); // make sure its up-to-date
211 if (dialog_->form->visible) {
212 fl_raise_form(dialog_->form);
214 fl_show_form(dialog_->form,
215 FL_PLACE_MOUSE | FL_FREE_SIZE,
216 FL_TRANSIENT, _("Document Layout"));
217 u_ = d_->updateBufferDependent.connect(
218 slot(this, &FormDocument::update));
219 h_ = d_->hideBufferDependent.connect(
220 slot(this, &FormDocument::hide));
224 void FormDocument::hide()
226 if (dialog_->form->visible) {
227 fl_hide_form(dialog_->form);
233 void FormDocument::apply()
235 if (!lv_->view()->available() || !dialog_)
241 redo = class_apply();
243 redo = language_apply() || redo;
244 redo = options_apply() || redo;
248 lv_->view()->redoCurrentBuffer();
250 lv_->buffer()->markDirty();
251 setMinibuffer(lv_, _("Document layout set"));
255 bool FormDocument::class_apply()
258 BufferParams ¶ms = lv_->buffer()->params;
260 // If default skip is a "Length" but there's no text in the
261 // input field, reset the kind to "Medskip", which is the default.
262 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
263 !*(fl_get_input (class_->input_doc_skip))) {
264 fl_set_choice (class_->choice_doc_skip, 2);
266 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
267 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
268 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
270 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
271 if (params.textclass != new_class) {
272 // try to load new_class
273 if (textclasslist.Load(new_class)) {
274 // successfully loaded
276 setMinibuffer(lv_, _("Converting document to new document class..."));
278 int ret = cap.SwitchLayoutsBetweenClasses(
279 params.textclass, new_class,
280 lv_->buffer()->paragraph);
284 s = _("One paragraph couldn't be converted");
287 s += _(" paragraphs couldn't be converted");
289 WriteAlert(_("Conversion Errors!"),s,
290 _("into chosen document class"));
293 params.textclass = new_class;
295 // problem changing class -- warn user and retain old style
296 WriteAlert(_("Conversion Errors!"),
297 _("Errors loading new document class."),
298 _("Reverting to original document class."));
299 fl_set_choice(class_->choice_doc_class,
300 params.textclass + 1);
303 char tmpsep = params.paragraph_separation;
304 if (fl_get_button(class_->radio_doc_indent))
305 params.paragraph_separation = BufferParams::PARSEP_INDENT;
307 params.paragraph_separation = BufferParams::PARSEP_SKIP;
308 if (tmpsep != params.paragraph_separation)
311 VSpace tmpdefskip = params.getDefSkip();
312 switch (fl_get_choice (class_->choice_doc_skip)) {
314 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
317 params.setDefSkip(VSpace(VSpace::MEDSKIP));
320 params.setDefSkip(VSpace(VSpace::BIGSKIP));
324 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
326 // DocumentDefskipCB assures that this never happens
328 params.setDefSkip(VSpace(VSpace::MEDSKIP));
331 if (!(tmpdefskip == params.getDefSkip()))
334 if (fl_get_button(class_->radio_doc_columns_two))
338 if (fl_get_button(class_->radio_doc_sides_two))
339 params.sides = LyXTextClass::TwoSides;
341 params.sides = LyXTextClass::OneSide;
343 Spacing tmpSpacing = params.spacing;
344 switch(fl_get_choice(class_->choice_doc_spacing)) {
346 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
347 params.spacing.set(Spacing::Single);
350 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
351 params.spacing.set(Spacing::Onehalf);
354 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
355 params.spacing.set(Spacing::Double);
358 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
359 params.spacing.set(Spacing::Other,
360 fl_get_input(class_->input_doc_spacing));
363 if (tmpSpacing != params.spacing)
366 params.options = fl_get_input(class_->input_doc_extra);
371 void FormDocument::paper_apply()
374 ¶ms = lv_->buffer()->params;
376 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
377 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
378 params.use_geometry = fl_get_button(paper_->push_use_geometry);
379 if (fl_get_button(paper_->radio_landscape))
380 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
382 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
383 params.paperwidth = fl_get_input(paper_->input_custom_width);
384 params.paperheight = fl_get_input(paper_->input_custom_height);
385 params.leftmargin = fl_get_input(paper_->input_left_margin);
386 params.topmargin = fl_get_input(paper_->input_top_margin);
387 params.rightmargin = fl_get_input(paper_->input_right_margin);
388 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
389 params.headheight = fl_get_input(paper_->input_head_height);
390 params.headsep = fl_get_input(paper_->input_head_sep);
391 params.footskip = fl_get_input(paper_->input_foot_skip);
392 lv_->buffer()->setPaperStuff();
395 bool FormDocument::language_apply()
398 ¶ms = lv_->buffer()->params;
399 InsetQuotes::quote_language
400 lga = InsetQuotes::EnglishQ;
403 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
405 lga = InsetQuotes::EnglishQ;
408 lga = InsetQuotes::SwedishQ;
411 lga = InsetQuotes::GermanQ;
414 lga = InsetQuotes::PolishQ;
417 lga = InsetQuotes::FrenchQ;
420 lga = InsetQuotes::DanishQ;
423 params.quotes_language = lga;
424 if (fl_get_button(language_->radio_single))
425 params.quotes_times = InsetQuotes::SingleQ;
427 params.quotes_times = InsetQuotes::DoubleQ;
429 Language const * old_language = params.language_info;
430 params.language = combo_language->getline();
431 Languages::iterator lit = languages.find(params.language);
433 Language const * new_language;
434 if (lit != languages.end())
435 new_language = &(*lit).second;
437 new_language = default_language;
439 if (old_language != new_language
440 && old_language->RightToLeft() == new_language->RightToLeft()
441 && !lv_->buffer()->isMultiLingual())
442 lv_->buffer()->ChangeLanguage(old_language, new_language);
443 if (old_language != new_language) {
446 params.language_info = new_language;
447 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
452 bool FormDocument::options_apply()
455 ¶ms = lv_->buffer()->params;
459 params.graphicsDriver =
460 fl_get_choice_text(options_->choice_postscript_driver);
461 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
463 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
464 if (params.secnumdepth != tmpchar)
466 params.secnumdepth = tmpchar;
468 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
470 params.float_placement =
471 fl_get_input(options_->input_float_placement);
476 void FormDocument::bullets_apply()
478 /* update the bullet settings */
479 BufferParams & param = lv_->buffer()->params;
481 // a little bit of loop unrolling
482 param.user_defined_bullets[0] = param.temp_bullets[0];
483 param.user_defined_bullets[1] = param.temp_bullets[1];
484 param.user_defined_bullets[2] = param.temp_bullets[2];
485 param.user_defined_bullets[3] = param.temp_bullets[3];
488 void FormDocument::cancel()
490 // this avoids confusion when reopening
491 BufferParams & param = lv_->buffer()->params;
492 param.temp_bullets[0] = param.user_defined_bullets[0];
493 param.temp_bullets[1] = param.user_defined_bullets[1];
494 param.temp_bullets[2] = param.user_defined_bullets[2];
495 param.temp_bullets[3] = param.user_defined_bullets[3];
498 void FormDocument::update()
502 fl_hide_object(dialog_->text_warning);
503 EnableDocumentLayout();
504 if (lv_->buffer()->isReadonly()) {
505 DisableDocumentLayout();
506 fl_set_object_label(dialog_->text_warning,
507 _("Document is read-only."
508 " No changes to layout permitted."));
509 fl_show_object(dialog_->text_warning);
513 const & params = lv_->buffer()->params;
515 class_update(params);
516 paper_update(params);
517 language_update(params);
518 options_update(params);
519 bullets_update(params);
522 void FormDocument::class_update(BufferParams const & params)
527 const & tclass = textclasslist.TextClass(params.textclass);
529 fl_set_choice_text(class_->choice_doc_class,
530 textclasslist.DescOfClass(params.textclass).c_str());
531 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
532 fl_clear_choice(class_->choice_doc_fontsize);
533 fl_addto_choice(class_->choice_doc_fontsize, "default");
534 fl_addto_choice(class_->choice_doc_fontsize,
535 tclass.opt_fontsize().c_str());
536 fl_set_choice(class_->choice_doc_fontsize,
537 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
538 fl_clear_choice(class_->choice_doc_pagestyle);
539 fl_addto_choice(class_->choice_doc_pagestyle, "default");
540 fl_addto_choice(class_->choice_doc_pagestyle,
541 tclass.opt_pagestyle().c_str());
542 fl_set_choice(class_->choice_doc_pagestyle,
543 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
544 fl_set_button(class_->radio_doc_indent, 0);
545 fl_set_button(class_->radio_doc_skip, 0);
546 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
547 fl_set_button(class_->radio_doc_indent, 1);
549 fl_set_button(class_->radio_doc_skip, 1);
550 switch (params.getDefSkip().kind()) {
551 case VSpace::SMALLSKIP:
552 fl_set_choice (class_->choice_doc_skip, 1);
554 case VSpace::MEDSKIP:
555 fl_set_choice (class_->choice_doc_skip, 2);
557 case VSpace::BIGSKIP:
558 fl_set_choice (class_->choice_doc_skip, 3);
561 fl_set_choice (class_->choice_doc_skip, 4);
562 fl_set_input (class_->input_doc_skip,
563 params.getDefSkip().asLyXCommand().c_str());
566 fl_set_choice (class_->choice_doc_skip, 2);
569 fl_set_button(class_->radio_doc_sides_one, 0);
570 fl_set_button(class_->radio_doc_sides_two, 0);
571 if (params.sides == 2)
572 fl_set_button(class_->radio_doc_sides_two, 1);
574 fl_set_button(class_->radio_doc_sides_one, 1);
575 fl_set_button(class_->radio_doc_columns_one, 0);
576 fl_set_button(class_->radio_doc_columns_two, 0);
577 if (params.columns == 2)
578 fl_set_button(class_->radio_doc_columns_two, 1);
580 fl_set_button(class_->radio_doc_columns_one, 1);
581 fl_set_input(class_->input_doc_spacing, "");
582 switch (params.spacing.getSpace()) {
583 case Spacing::Default: // nothing bad should happen with this
584 case Spacing::Single:
586 fl_set_choice(class_->choice_doc_spacing, 1);
588 case Spacing::Onehalf:
590 fl_set_choice(class_->choice_doc_spacing, 2);
592 case Spacing::Double:
594 fl_set_choice(class_->choice_doc_spacing, 3);
598 fl_set_choice(class_->choice_doc_spacing, 4);
600 sprintf(sval,"%g",params.spacing.getValue());
601 fl_set_input(class_->input_doc_spacing, sval);
605 if (!params.options.empty())
606 fl_set_input(class_->input_doc_extra, params.options.c_str());
608 fl_set_input(class_->input_doc_extra, "");
611 void FormDocument::language_update(BufferParams const & params)
616 combo_language->select_text(params.language.c_str());
617 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
618 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
619 fl_set_button(language_->radio_single, 0);
620 fl_set_button(language_->radio_double, 0);
621 if (params.quotes_times == InsetQuotes::SingleQ)
622 fl_set_button(language_->radio_single, 1);
624 fl_set_button(language_->radio_double, 1);
627 void FormDocument::options_update(BufferParams const & params)
632 fl_set_choice_text(options_->choice_postscript_driver,
633 params.graphicsDriver.c_str());
634 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
635 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
636 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
637 if (!params.float_placement.empty())
638 fl_set_input(options_->input_float_placement,
639 params.float_placement.c_str());
641 fl_set_input(options_->input_float_placement, "");
644 void FormDocument::paper_update(BufferParams const & params)
649 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
650 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
651 fl_set_button(paper_->push_use_geometry, params.use_geometry);
652 fl_set_button(paper_->radio_portrait, 0);
653 fl_set_button(paper_->radio_landscape, 0);
654 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
655 fl_set_button(paper_->radio_landscape, 1);
657 fl_set_button(paper_->radio_portrait, 1);
658 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
659 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
660 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
661 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
662 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
663 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
664 fl_set_input(paper_->input_head_height, params.headheight.c_str());
665 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
666 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
667 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
670 void FormDocument::bullets_update(BufferParams const & params)
672 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
675 if (lv_->buffer()->isLinuxDoc()) {
676 fl_deactivate_object(fbullet);
677 fl_set_object_lcol(fbullet, FL_INACTIVE);
680 fl_activate_object(fbullet);
681 fl_set_object_lcol(fbullet, FL_BLACK);
683 if (lv_->buffer()->isReadonly()) {
684 fl_deactivate_object (bullets_->bmtable_bullet_panel);
685 fl_deactivate_object (bullets_->choice_bullet_size);
686 fl_deactivate_object (bullets_->input_bullet_latex);
688 fl_activate_object (bullets_->bmtable_bullet_panel);
689 fl_activate_object (bullets_->choice_bullet_size);
690 fl_activate_object (bullets_->input_bullet_latex);
693 fl_set_button(bullets_->radio_bullet_depth_1, 1);
694 fl_set_input(bullets_->input_bullet_latex,
695 params.user_defined_bullets[0].c_str());
696 fl_set_choice(bullets_->choice_bullet_size,
697 params.user_defined_bullets[0].getSize() + 2);
700 void FormDocument::free()
705 fl_free_form(class_->form);
710 fl_free_form(paper_->form);
715 delete combo_language;
716 fl_free_form(language_->form);
721 fl_free_form(options_->form);
726 fl_free_form(bullets_->form);
730 fl_free_form(dialog_->form);
736 int FormDocument::WMHideCB(FL_FORM * form, void *)
738 // Ensure that the signals (u and h) are disconnected even if the
739 // window manager is used to close the popup.
740 FormDocument * pre = (FormDocument*)form->u_vdata;
746 void FormDocument::OKCB(FL_OBJECT * ob, long)
748 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
754 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
756 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
761 void FormDocument::CancelCB(FL_OBJECT * ob, long)
763 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
769 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
771 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
776 void FormDocument::InputCB(FL_OBJECT * ob, long)
778 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
779 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
782 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
784 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
785 pre->CheckChoiceClass(ob,0);
786 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
789 void FormDocument::checkMarginValues()
793 allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
794 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
795 !strlen(fl_get_input(paper_->input_left_margin)) &&
796 !strlen(fl_get_input(paper_->input_right_margin)) &&
797 !strlen(fl_get_input(paper_->input_head_height)) &&
798 !strlen(fl_get_input(paper_->input_head_sep)) &&
799 !strlen(fl_get_input(paper_->input_foot_skip)) &&
800 !strlen(fl_get_input(paper_->input_custom_width)) &&
801 !strlen(fl_get_input(paper_->input_custom_height)));
803 fl_set_button(paper_->push_use_geometry, 1);
806 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
814 if (ob == paper_->choice_papersize2) {
815 val = fl_get_choice(paper_->choice_papersize2)-1;
816 if (val == BufferParams::VM_PAPER_DEFAULT) {
817 fl_set_button(paper_->push_use_geometry, 0);
820 if ((val != BufferParams::VM_PAPER_USLETTER) &&
821 (val != BufferParams::VM_PAPER_USLEGAL) &&
822 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
823 (val != BufferParams::VM_PAPER_A4) &&
824 (val != BufferParams::VM_PAPER_A5) &&
825 (val != BufferParams::VM_PAPER_B5)) {
826 fl_set_button(paper_->push_use_geometry, 1);
828 fl_set_choice(paper_->choice_paperpackage,
829 BufferParams::PACKAGE_NONE + 1);
831 } else if (ob == paper_->choice_paperpackage) {
832 val = fl_get_choice(paper_->choice_paperpackage)-1;
833 if (val != BufferParams::PACKAGE_NONE) {
834 fl_set_choice(paper_->choice_papersize2,
835 BufferParams::VM_PAPER_DEFAULT + 1);
836 fl_set_button(paper_->push_use_geometry, 0);
838 } else if (ob == class_->input_doc_spacing) {
839 input = fl_get_input(class_->input_doc_spacing);
841 fl_set_choice (class_->choice_doc_spacing, 1);
843 fl_set_choice(class_->choice_doc_spacing, 4);
846 // this has to be all out of if/elseif because it has to deactivate
847 // the document buttons and so the whole stuff has to be tested again.
848 str = fl_get_input(paper_->input_custom_width);
849 ok = ok && (str.empty() || isValidLength(str));
850 str = fl_get_input(paper_->input_custom_height);
851 ok = ok && (str.empty() || isValidLength(str));
852 str = fl_get_input(paper_->input_left_margin);
853 ok = ok && (str.empty() || isValidLength(str));
854 str = fl_get_input(paper_->input_right_margin);
855 ok = ok && (str.empty() || isValidLength(str));
856 str = fl_get_input(paper_->input_top_margin);
857 ok = ok && (str.empty() || isValidLength(str));
858 str = fl_get_input(paper_->input_bottom_margin);
859 ok = ok && (str.empty() || isValidLength(str));
860 str = fl_get_input(paper_->input_head_height);
861 ok = ok && (str.empty() || isValidLength(str));
862 str = fl_get_input(paper_->input_head_sep);
863 ok = ok && (str.empty() || isValidLength(str));
864 str = fl_get_input(paper_->input_foot_skip);
865 ok = ok && (str.empty() || isValidLength(str));
866 // "Synchronize" the choice and the input field, so that it
867 // is impossible to commit senseless data.
868 input = fl_get_input (class_->input_doc_skip);
869 if (ob == class_->input_doc_skip) {
871 fl_set_choice (class_->choice_doc_skip, 2);
872 } else if (isValidGlueLength (input)) {
873 fl_set_choice (class_->choice_doc_skip, 4);
875 fl_set_choice(class_->choice_doc_skip, 4);
879 if (*input && !isValidGlueLength(input))
882 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
884 else if (fl_get_choice(class_->choice_doc_skip) != 4)
885 fl_set_input (class_->input_doc_skip, "");
887 input = fl_get_input(class_->input_doc_spacing);
888 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
890 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
891 fl_set_input (class_->input_doc_spacing, "");
895 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
897 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
898 pre->ChoiceBulletSize(ob,0);
899 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
902 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
904 BufferParams & param = lv_->buffer()->params;
906 // convert from 1-6 range to -1-4
907 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
908 fl_set_input(bullets_->input_bullet_latex,
909 param.temp_bullets[current_bullet_depth].c_str());
912 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
914 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
915 pre->InputBulletLaTeX(ob,0);
916 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
919 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
921 BufferParams & param = lv_->buffer()->params;
923 param.temp_bullets[current_bullet_depth].
924 setText(fl_get_input(bullets_->input_bullet_latex));
927 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
929 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
930 pre->BulletDepth(ob,0);
933 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
935 /* Should I do the following: */
936 /* 1. change to the panel that the current bullet belongs in */
937 /* 2. show that bullet as selected */
938 /* 3. change the size setting to the size of the bullet in Q.*/
939 /* 4. display the latex equivalent in the latex box */
941 /* I'm inclined to just go with 3 and 4 at the moment and */
942 /* maybe try to support the others later */
943 BufferParams & param = lv_->buffer()->params;
945 switch (fl_get_button_numb(ob)) {
947 // right mouse button resets to default
948 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
950 current_bullet_depth = data;
951 fl_set_input(bullets_->input_bullet_latex,
952 param.temp_bullets[data].c_str());
953 fl_set_choice(bullets_->choice_bullet_size,
954 param.temp_bullets[data].getSize() + 2);
958 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
960 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
961 pre->BulletPanel(ob,data);
964 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
966 /* Here we have to change the background pixmap to that selected */
967 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
969 if (data != current_bullet_panel) {
970 fl_freeze_form(bullets_->form);
971 current_bullet_panel = data;
973 /* free the current pixmap */
974 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
977 /* display the new one */
979 new_panel = "standard";
982 new_panel = "amssymb";
985 new_panel = "psnfss1";
988 new_panel = "psnfss2";
991 new_panel = "psnfss3";
994 new_panel = "psnfss4";
997 /* something very wrong happened */
998 // play it safe for now but should be an exception
999 current_bullet_panel = 0; // standard panel
1000 new_panel = "standard";
1003 new_panel += ".xpm";
1004 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1005 LibFileSearch("images", new_panel.c_str()).c_str());
1006 fl_redraw_object(bullets_->bmtable_bullet_panel);
1007 fl_unfreeze_form(bullets_->form);
1011 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1013 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1014 pre->BulletBMTable(ob,0);
1015 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1018 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1020 /* handle the user input by setting the current bullet depth's pixmap */
1021 /* to that extracted from the current chosen position of the BMTable */
1022 /* Don't forget to free the button's old pixmap first. */
1024 BufferParams & param = lv_->buffer()->params;
1025 int bmtable_button = fl_get_bmtable(ob);
1027 /* try to keep the button held down till another is pushed */
1028 /* fl_set_bmtable(ob, 1, bmtable_button); */
1029 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1030 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1031 fl_set_input(bullets_->input_bullet_latex,
1032 param.temp_bullets[current_bullet_depth].c_str());
1035 void FormDocument::EnableDocumentLayout()
1037 fl_activate_object (class_->radio_doc_indent);
1038 fl_activate_object (class_->radio_doc_skip);
1039 fl_activate_object (class_->choice_doc_class);
1040 fl_activate_object (class_->choice_doc_pagestyle);
1041 fl_activate_object (class_->choice_doc_fonts);
1042 fl_activate_object (class_->choice_doc_fontsize);
1043 fl_activate_object (class_->radio_doc_sides_one);
1044 fl_activate_object (class_->radio_doc_sides_two);
1045 fl_activate_object (class_->radio_doc_columns_one);
1046 fl_activate_object (class_->radio_doc_columns_two);
1047 fl_activate_object (class_->input_doc_extra);
1048 fl_activate_object (class_->input_doc_skip);
1049 fl_activate_object (class_->choice_doc_skip);
1050 fl_activate_object (class_->choice_doc_spacing);
1051 fl_activate_object (class_->input_doc_spacing);
1053 fl_activate_object (language_->choice_language);
1054 combo_language->activate();
1055 fl_activate_object (language_->choice_language);
1056 fl_activate_object (language_->choice_inputenc);
1058 fl_activate_object (options_->slider_secnumdepth);
1059 fl_activate_object (options_->slider_tocdepth);
1060 fl_activate_object (options_->check_use_amsmath);
1061 fl_activate_object (options_->input_float_placement);
1062 fl_activate_object (options_->choice_postscript_driver);
1064 fl_activate_object (paper_->choice_paperpackage);
1065 fl_activate_object (paper_->greoup_radio_orientation);
1066 fl_activate_object (paper_->radio_portrait);
1067 fl_activate_object (paper_->radio_landscape);
1068 fl_activate_object (paper_->choice_papersize2);
1069 fl_activate_object (paper_->push_use_geometry);
1070 fl_activate_object (paper_->input_custom_width);
1071 fl_activate_object (paper_->input_custom_height);
1072 fl_activate_object (paper_->input_top_margin);
1073 fl_activate_object (paper_->input_bottom_margin);
1074 fl_activate_object (paper_->input_left_margin);
1075 fl_activate_object (paper_->input_right_margin);
1076 fl_activate_object (paper_->input_head_height);
1077 fl_activate_object (paper_->input_head_sep);
1078 fl_activate_object (paper_->input_foot_skip);
1081 void FormDocument::DisableDocumentLayout()
1083 fl_deactivate_object (class_->radio_doc_indent);
1084 fl_deactivate_object (class_->radio_doc_skip);
1085 fl_deactivate_object (class_->choice_doc_class);
1086 fl_deactivate_object (class_->choice_doc_pagestyle);
1087 fl_deactivate_object (class_->choice_doc_fonts);
1088 fl_deactivate_object (class_->choice_doc_fontsize);
1089 fl_deactivate_object (class_->radio_doc_sides_one);
1090 fl_deactivate_object (class_->radio_doc_sides_two);
1091 fl_deactivate_object (class_->radio_doc_columns_one);
1092 fl_deactivate_object (class_->radio_doc_columns_two);
1093 fl_deactivate_object (class_->input_doc_extra);
1094 fl_deactivate_object (class_->input_doc_skip);
1095 fl_deactivate_object (class_->choice_doc_skip);
1096 fl_deactivate_object (class_->choice_doc_spacing);
1097 fl_deactivate_object (class_->input_doc_spacing);
1099 fl_deactivate_object (language_->choice_language);
1100 combo_language->deactivate();
1101 fl_deactivate_object (language_->choice_inputenc);
1103 fl_deactivate_object (options_->slider_secnumdepth);
1104 fl_deactivate_object (options_->slider_tocdepth);
1105 fl_deactivate_object (options_->check_use_amsmath);
1106 fl_deactivate_object (options_->input_float_placement);
1107 fl_deactivate_object (options_->choice_postscript_driver);
1109 fl_deactivate_object (paper_->choice_paperpackage);
1110 fl_deactivate_object (paper_->greoup_radio_orientation);
1111 fl_deactivate_object (paper_->radio_portrait);
1112 fl_deactivate_object (paper_->radio_landscape);
1113 fl_deactivate_object (paper_->choice_papersize2);
1114 fl_deactivate_object (paper_->push_use_geometry);
1115 fl_deactivate_object (paper_->input_custom_width);
1116 fl_deactivate_object (paper_->input_custom_height);
1117 fl_deactivate_object (paper_->input_top_margin);
1118 fl_deactivate_object (paper_->input_bottom_margin);
1119 fl_deactivate_object (paper_->input_left_margin);
1120 fl_deactivate_object (paper_->input_right_margin);
1121 fl_deactivate_object (paper_->input_head_height);
1122 fl_deactivate_object (paper_->input_head_sep);
1123 fl_deactivate_object (paper_->input_foot_skip);
1126 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1128 ProhibitInput(lv_->view());
1129 if (textclasslist.Load(fl_get_choice(ob)-1)) {
1130 if (AskQuestion(_("Should I set some parameters to"),
1131 fl_get_choice_text(ob),
1132 _("the defaults of this document class?"))) {
1133 BufferParams & params = lv_->buffer()->params;
1135 params.textclass = fl_get_choice(ob)-1;
1136 params.useClassDefaults();
1137 UpdateLayoutDocument(params);
1140 // unable to load new style
1141 WriteAlert(_("Conversion Errors!"),
1142 _("Unable to switch to new document class."),
1143 _("Reverting to original document class."));
1144 fl_set_choice(class_->choice_doc_class,
1145 lv_->view()->buffer()->params.textclass + 1);
1147 AllowInput(lv_->view());
1150 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1154 fl_hide_object(dialog_->text_warning);
1155 EnableDocumentLayout();
1156 if (lv_->buffer()->isReadonly()) {
1157 DisableDocumentLayout();
1158 fl_set_object_label(dialog_->text_warning,
1159 _("Document is read-only."
1160 " No changes to layout permitted."));
1161 fl_show_object(dialog_->text_warning);
1163 class_update(params);
1164 paper_update(params);
1165 language_update(params);
1166 options_update(params);
1167 bullets_update(params);