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 #define USE_CLASS_COMBO 1
54 C_RETURNCB(FormDocument, WMHideCB)
55 C_GENERICCB(FormDocument, InputCB)
56 C_GENERICCB(FormDocument, OKCB)
57 C_GENERICCB(FormDocument, ApplyCB)
58 C_GENERICCB(FormDocument, CancelCB)
59 C_GENERICCB(FormDocument, RestoreCB)
60 C_GENERICCB(FormDocument, ChoiceClassCB)
61 C_GENERICCB(FormDocument, BulletPanelCB)
62 C_GENERICCB(FormDocument, BulletDepthCB)
63 C_GENERICCB(FormDocument, InputBulletLaTeXCB)
64 C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
66 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
67 : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
68 bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
69 status(POPUP_UNMODIFIED) ,
70 bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
73 // let the popup be shown
74 // This is a permanent connection so we won't bother
75 // storing a copy because we won't be disconnecting.
76 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
77 current_bullet_depth = 0;
78 current_bullet_panel = 0;
81 FormDocument::~FormDocument()
87 void FormDocument::build()
92 dialog_ = build_tabbed_document();
94 // manage the restore, ok, apply and cancel/close buttons
95 bc_->setOK(dialog_->button_ok);
96 bc_->setApply(dialog_->button_apply);
97 bc_->setCancel(dialog_->button_cancel);
98 bc_->setUndoAll(dialog_->button_restore);
101 // the document paper form
102 paper_ = build_doc_paper();
103 fl_addto_choice(paper_->choice_papersize2,
104 _(" Default | Custom | USletter | USlegal "
105 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
106 fl_addto_choice(paper_->choice_paperpackage,
108 "| A4 small Margins (only portrait) "
109 "| A4 very small Margins (only portrait) "
110 "| A4 very wide margins (only portrait) "));
111 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
112 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
117 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
118 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
119 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
121 bc_->addReadOnly (paper_->choice_paperpackage);
122 bc_->addReadOnly (paper_->greoup_radio_orientation);
123 bc_->addReadOnly (paper_->radio_portrait);
124 bc_->addReadOnly (paper_->radio_landscape);
125 bc_->addReadOnly (paper_->choice_papersize2);
126 bc_->addReadOnly (paper_->push_use_geometry);
127 bc_->addReadOnly (paper_->input_custom_width);
128 bc_->addReadOnly (paper_->input_custom_height);
129 bc_->addReadOnly (paper_->input_top_margin);
130 bc_->addReadOnly (paper_->input_bottom_margin);
131 bc_->addReadOnly (paper_->input_left_margin);
132 bc_->addReadOnly (paper_->input_right_margin);
133 bc_->addReadOnly (paper_->input_head_height);
134 bc_->addReadOnly (paper_->input_head_sep);
135 bc_->addReadOnly (paper_->input_foot_skip);
137 // the document class form
138 class_ = build_doc_class();
141 #ifdef USE_CLASS_COMBO
142 // The language is a combo-box and has to be inserted manually
143 obj = class_->choice_doc_class;
144 fl_addto_form(class_->form);
145 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
146 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 200);
147 combo_doc_class->shortcut("#C",1);
148 combo_doc_class->setcallback(ComboInputCB, this);
150 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
151 cit != textclasslist.end(); ++cit)
153 combo_doc_class->addto((*cit).description().c_str());
156 fl_clear_choice(class_->choice_doc_class);
157 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
158 cit != textclasslist.end(); ++cit)
160 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
163 fl_addto_choice(class_->choice_doc_spacing,
164 _(" Single | OneHalf | Double | Other "));
165 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
166 for (n=0; tex_fonts[n][0]; ++n) {
167 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
169 fl_addto_choice(class_->choice_doc_pagestyle,
170 "default|empty|plain|headings|fancy");
171 fl_addto_choice(class_->choice_doc_skip,
172 _(" Smallskip | Medskip | Bigskip | Length "));
173 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
174 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
176 bc_->addReadOnly (class_->radio_doc_indent);
177 bc_->addReadOnly (class_->radio_doc_skip);
178 #ifndef USE_CLASS_COMBO
179 bc_->addReadOnly (class_->choice_doc_class);
181 bc_->addReadOnly (class_->choice_doc_pagestyle);
182 bc_->addReadOnly (class_->choice_doc_fonts);
183 bc_->addReadOnly (class_->choice_doc_fontsize);
184 bc_->addReadOnly (class_->radio_doc_sides_one);
185 bc_->addReadOnly (class_->radio_doc_sides_two);
186 bc_->addReadOnly (class_->radio_doc_columns_one);
187 bc_->addReadOnly (class_->radio_doc_columns_two);
188 bc_->addReadOnly (class_->input_doc_extra);
189 bc_->addReadOnly (class_->input_doc_skip);
190 bc_->addReadOnly (class_->choice_doc_skip);
191 bc_->addReadOnly (class_->choice_doc_spacing);
192 bc_->addReadOnly (class_->input_doc_spacing);
194 // the document language form
195 language_ = build_doc_language();
196 fl_addto_choice(language_->choice_inputenc,
197 "default|auto|latin1|latin2|latin5"
198 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
200 // The language is a combo-box and has to be inserted manually
201 obj = language_->choice_language;
202 fl_addto_form(language_->form);
203 combo_language = new Combox(FL_COMBOX_DROPLIST);
204 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
205 combo_language->shortcut("#L",1);
206 combo_language->setcallback(ComboInputCB, this);
208 // "default" is not part of the languages array any more.
209 combo_language->addto("default");
210 for(Languages::const_iterator cit = languages.begin();
211 cit != languages.end(); ++cit) {
212 combo_language->addto((*cit).second.lang().c_str());
215 fl_addto_choice(language_->choice_quotes_language,
216 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
217 " «text» | »text« "));
219 bc_->addReadOnly (language_->choice_language);
220 bc_->addReadOnly (language_->choice_inputenc);
222 // the document options form
223 options_ = build_doc_options();
224 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
225 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
226 fl_set_counter_step(options_->slider_secnumdepth,1,1);
227 fl_set_counter_step(options_->slider_tocdepth,1,1);
228 fl_set_counter_precision(options_->slider_secnumdepth, 0);
229 fl_set_counter_precision(options_->slider_tocdepth, 0);
230 for (n=0; tex_graphics[n][0]; ++n) {
231 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
234 bc_->addReadOnly (options_->slider_secnumdepth);
235 bc_->addReadOnly (options_->slider_tocdepth);
236 bc_->addReadOnly (options_->check_use_amsmath);
237 bc_->addReadOnly (options_->input_float_placement);
238 bc_->addReadOnly (options_->choice_postscript_driver);
240 // the document bullets form
241 bullets_ = build_doc_bullet();
242 fl_addto_choice(bullets_->choice_bullet_size,
243 _(" default | tiny | script | footnote | small |"
244 " normal | large | Large | LARGE | huge | Huge"));
245 fl_set_choice(bullets_->choice_bullet_size, 1);
246 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
247 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
249 fl_set_form_atclose(dialog_->form,
250 C_FormDocumentWMHideCB, 0);
251 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
253 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
255 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
259 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
261 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
262 lyxerr << _("Your version of libXpm is older than 4.7.\n"
263 "The `bullet' tab of the document popup "
264 "has been disabled") << '\n';
265 fl_deactivate_object(fbullet);
266 fl_set_object_lcol(fbullet, FL_INACTIVE);
270 void FormDocument::show()
275 update(); // make sure its up-to-date
276 if (dialog_->form->visible) {
277 fl_raise_form(dialog_->form);
279 fl_show_form(dialog_->form,
280 FL_PLACE_MOUSE | FL_FREE_SIZE,
281 FL_TRANSIENT, _("Document Layout"));
282 u_ = d_->updateBufferDependent.connect(
283 slot(this, &FormDocument::update));
284 h_ = d_->hideBufferDependent.connect(
285 slot(this, &FormDocument::hide));
289 void FormDocument::hide()
291 if (dialog_->form->visible) {
292 fl_hide_form(dialog_->form);
298 void FormDocument::apply()
300 if (!lv_->view()->available() || !dialog_)
306 redo = class_apply();
308 redo = language_apply() || redo;
309 redo = options_apply() || redo;
313 lv_->view()->redoCurrentBuffer();
315 lv_->buffer()->markDirty();
316 setMinibuffer(lv_, _("Document layout set"));
320 bool FormDocument::class_apply()
323 BufferParams ¶ms = lv_->buffer()->params;
325 // If default skip is a "Length" but there's no text in the
326 // input field, reset the kind to "Medskip", which is the default.
327 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
328 !*(fl_get_input (class_->input_doc_skip))) {
329 fl_set_choice (class_->choice_doc_skip, 2);
331 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
332 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
333 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
335 #ifdef USE_CLASS_COMBO
336 unsigned int new_class = combo_doc_class->get();
338 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
340 if (params.textclass != new_class) {
341 // try to load new_class
342 if (textclasslist.Load(new_class)) {
343 // successfully loaded
345 setMinibuffer(lv_, _("Converting document to new document class..."));
347 int ret = cap.SwitchLayoutsBetweenClasses(
348 params.textclass, new_class,
349 lv_->buffer()->paragraph);
353 s = _("One paragraph couldn't be converted");
356 s += _(" paragraphs couldn't be converted");
358 WriteAlert(_("Conversion Errors!"),s,
359 _("into chosen document class"));
362 params.textclass = new_class;
364 // problem changing class -- warn user and retain old style
365 WriteAlert(_("Conversion Errors!"),
366 _("Errors loading new document class."),
367 _("Reverting to original document class."));
368 #ifdef USE_CLASS_COMBO
369 combo_doc_class->select(params.textclass);
371 fl_set_choice(class_->choice_doc_class,
372 params.textclass + 1);
376 char tmpsep = params.paragraph_separation;
377 if (fl_get_button(class_->radio_doc_indent))
378 params.paragraph_separation = BufferParams::PARSEP_INDENT;
380 params.paragraph_separation = BufferParams::PARSEP_SKIP;
381 if (tmpsep != params.paragraph_separation)
384 VSpace tmpdefskip = params.getDefSkip();
385 switch (fl_get_choice (class_->choice_doc_skip)) {
387 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
390 params.setDefSkip(VSpace(VSpace::MEDSKIP));
393 params.setDefSkip(VSpace(VSpace::BIGSKIP));
397 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
399 // DocumentDefskipCB assures that this never happens
401 params.setDefSkip(VSpace(VSpace::MEDSKIP));
404 if (!(tmpdefskip == params.getDefSkip()))
407 if (fl_get_button(class_->radio_doc_columns_two))
411 if (fl_get_button(class_->radio_doc_sides_two))
412 params.sides = LyXTextClass::TwoSides;
414 params.sides = LyXTextClass::OneSide;
416 Spacing tmpSpacing = params.spacing;
417 switch(fl_get_choice(class_->choice_doc_spacing)) {
419 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
420 params.spacing.set(Spacing::Single);
423 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
424 params.spacing.set(Spacing::Onehalf);
427 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
428 params.spacing.set(Spacing::Double);
431 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
432 params.spacing.set(Spacing::Other,
433 fl_get_input(class_->input_doc_spacing));
436 if (tmpSpacing != params.spacing)
439 params.options = fl_get_input(class_->input_doc_extra);
444 void FormDocument::paper_apply()
447 ¶ms = lv_->buffer()->params;
449 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
450 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
451 params.use_geometry = fl_get_button(paper_->push_use_geometry);
452 if (fl_get_button(paper_->radio_landscape))
453 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
455 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
456 params.paperwidth = fl_get_input(paper_->input_custom_width);
457 params.paperheight = fl_get_input(paper_->input_custom_height);
458 params.leftmargin = fl_get_input(paper_->input_left_margin);
459 params.topmargin = fl_get_input(paper_->input_top_margin);
460 params.rightmargin = fl_get_input(paper_->input_right_margin);
461 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
462 params.headheight = fl_get_input(paper_->input_head_height);
463 params.headsep = fl_get_input(paper_->input_head_sep);
464 params.footskip = fl_get_input(paper_->input_foot_skip);
465 lv_->buffer()->setPaperStuff();
468 bool FormDocument::language_apply()
471 ¶ms = lv_->buffer()->params;
472 InsetQuotes::quote_language
473 lga = InsetQuotes::EnglishQ;
476 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
478 lga = InsetQuotes::EnglishQ;
481 lga = InsetQuotes::SwedishQ;
484 lga = InsetQuotes::GermanQ;
487 lga = InsetQuotes::PolishQ;
490 lga = InsetQuotes::FrenchQ;
493 lga = InsetQuotes::DanishQ;
496 params.quotes_language = lga;
497 if (fl_get_button(language_->radio_single))
498 params.quotes_times = InsetQuotes::SingleQ;
500 params.quotes_times = InsetQuotes::DoubleQ;
502 Language const * old_language = params.language_info;
503 params.language = combo_language->getline();
504 Languages::iterator lit = languages.find(params.language);
506 Language const * new_language;
507 if (lit != languages.end())
508 new_language = &(*lit).second;
510 new_language = default_language;
512 if (old_language != new_language
513 && old_language->RightToLeft() == new_language->RightToLeft()
514 && !lv_->buffer()->isMultiLingual())
515 lv_->buffer()->ChangeLanguage(old_language, new_language);
516 if (old_language != new_language) {
519 params.language_info = new_language;
520 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
525 bool FormDocument::options_apply()
528 ¶ms = lv_->buffer()->params;
532 params.graphicsDriver =
533 fl_get_choice_text(options_->choice_postscript_driver);
534 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
536 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
537 if (params.secnumdepth != tmpchar)
539 params.secnumdepth = tmpchar;
541 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
543 params.float_placement =
544 fl_get_input(options_->input_float_placement);
549 void FormDocument::bullets_apply()
551 /* update the bullet settings */
552 BufferParams & param = lv_->buffer()->params;
554 // a little bit of loop unrolling
555 param.user_defined_bullets[0] = param.temp_bullets[0];
556 param.user_defined_bullets[1] = param.temp_bullets[1];
557 param.user_defined_bullets[2] = param.temp_bullets[2];
558 param.user_defined_bullets[3] = param.temp_bullets[3];
561 void FormDocument::cancel()
563 // this avoids confusion when reopening
564 BufferParams & param = lv_->buffer()->params;
565 param.temp_bullets[0] = param.user_defined_bullets[0];
566 param.temp_bullets[1] = param.user_defined_bullets[1];
567 param.temp_bullets[2] = param.user_defined_bullets[2];
568 param.temp_bullets[3] = param.user_defined_bullets[3];
571 void FormDocument::update()
579 const & params = lv_->buffer()->params;
581 class_update(params);
582 paper_update(params);
583 language_update(params);
584 options_update(params);
585 bullets_update(params);
588 void FormDocument::class_update(BufferParams const & params)
593 const & tclass = textclasslist.TextClass(params.textclass);
595 #ifdef USE_CLASS_COMBO
596 combo_doc_class->select_text(
597 textclasslist.DescOfClass(params.textclass).c_str());
599 fl_set_choice_text(class_->choice_doc_class,
600 textclasslist.DescOfClass(params.textclass).c_str());
602 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
603 fl_clear_choice(class_->choice_doc_fontsize);
604 fl_addto_choice(class_->choice_doc_fontsize, "default");
605 fl_addto_choice(class_->choice_doc_fontsize,
606 tclass.opt_fontsize().c_str());
607 fl_set_choice(class_->choice_doc_fontsize,
608 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
609 fl_clear_choice(class_->choice_doc_pagestyle);
610 fl_addto_choice(class_->choice_doc_pagestyle, "default");
611 fl_addto_choice(class_->choice_doc_pagestyle,
612 tclass.opt_pagestyle().c_str());
613 fl_set_choice(class_->choice_doc_pagestyle,
614 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
615 fl_set_button(class_->radio_doc_indent, 0);
616 fl_set_button(class_->radio_doc_skip, 0);
617 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
618 fl_set_button(class_->radio_doc_indent, 1);
620 fl_set_button(class_->radio_doc_skip, 1);
621 switch (params.getDefSkip().kind()) {
622 case VSpace::SMALLSKIP:
623 fl_set_choice (class_->choice_doc_skip, 1);
625 case VSpace::MEDSKIP:
626 fl_set_choice (class_->choice_doc_skip, 2);
628 case VSpace::BIGSKIP:
629 fl_set_choice (class_->choice_doc_skip, 3);
632 fl_set_choice (class_->choice_doc_skip, 4);
633 fl_set_input (class_->input_doc_skip,
634 params.getDefSkip().asLyXCommand().c_str());
637 fl_set_choice (class_->choice_doc_skip, 2);
640 fl_set_button(class_->radio_doc_sides_one, 0);
641 fl_set_button(class_->radio_doc_sides_two, 0);
642 if (params.sides == 2)
643 fl_set_button(class_->radio_doc_sides_two, 1);
645 fl_set_button(class_->radio_doc_sides_one, 1);
646 fl_set_button(class_->radio_doc_columns_one, 0);
647 fl_set_button(class_->radio_doc_columns_two, 0);
648 if (params.columns == 2)
649 fl_set_button(class_->radio_doc_columns_two, 1);
651 fl_set_button(class_->radio_doc_columns_one, 1);
652 fl_set_input(class_->input_doc_spacing, "");
653 switch (params.spacing.getSpace()) {
654 case Spacing::Default: // nothing bad should happen with this
655 case Spacing::Single:
657 fl_set_choice(class_->choice_doc_spacing, 1);
659 case Spacing::Onehalf:
661 fl_set_choice(class_->choice_doc_spacing, 2);
663 case Spacing::Double:
665 fl_set_choice(class_->choice_doc_spacing, 3);
669 fl_set_choice(class_->choice_doc_spacing, 4);
671 sprintf(sval,"%g",params.spacing.getValue());
672 fl_set_input(class_->input_doc_spacing, sval);
676 if (!params.options.empty())
677 fl_set_input(class_->input_doc_extra, params.options.c_str());
679 fl_set_input(class_->input_doc_extra, "");
682 void FormDocument::language_update(BufferParams const & params)
687 combo_language->select_text(params.language.c_str());
688 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
689 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
690 fl_set_button(language_->radio_single, 0);
691 fl_set_button(language_->radio_double, 0);
692 if (params.quotes_times == InsetQuotes::SingleQ)
693 fl_set_button(language_->radio_single, 1);
695 fl_set_button(language_->radio_double, 1);
698 void FormDocument::options_update(BufferParams const & params)
703 fl_set_choice_text(options_->choice_postscript_driver,
704 params.graphicsDriver.c_str());
705 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
706 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
707 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
708 if (!params.float_placement.empty())
709 fl_set_input(options_->input_float_placement,
710 params.float_placement.c_str());
712 fl_set_input(options_->input_float_placement, "");
715 void FormDocument::paper_update(BufferParams const & params)
720 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
721 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
722 fl_set_button(paper_->push_use_geometry, params.use_geometry);
723 fl_set_button(paper_->radio_portrait, 0);
724 fl_set_button(paper_->radio_landscape, 0);
725 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
726 fl_set_button(paper_->radio_landscape, 1);
728 fl_set_button(paper_->radio_portrait, 1);
729 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
730 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
731 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
732 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
733 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
734 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
735 fl_set_input(paper_->input_head_height, params.headheight.c_str());
736 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
737 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
738 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
741 void FormDocument::bullets_update(BufferParams const & params)
743 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
746 if (lv_->buffer()->isLinuxDoc()) {
747 fl_deactivate_object(fbullet);
748 fl_set_object_lcol(fbullet, FL_INACTIVE);
751 fl_activate_object(fbullet);
752 fl_set_object_lcol(fbullet, FL_BLACK);
754 if (lv_->buffer()->isReadonly()) {
755 fl_deactivate_object (bullets_->bmtable_bullet_panel);
756 fl_deactivate_object (bullets_->choice_bullet_size);
757 fl_deactivate_object (bullets_->input_bullet_latex);
759 fl_activate_object (bullets_->bmtable_bullet_panel);
760 fl_activate_object (bullets_->choice_bullet_size);
761 fl_activate_object (bullets_->input_bullet_latex);
764 fl_set_button(bullets_->radio_bullet_depth_1, 1);
765 fl_set_input(bullets_->input_bullet_latex,
766 params.user_defined_bullets[0].c_str());
767 fl_set_choice(bullets_->choice_bullet_size,
768 params.user_defined_bullets[0].getSize() + 2);
771 void FormDocument::free()
776 #ifdef USE_CLASS_COMBO
777 delete combo_doc_class;
779 fl_free_form(class_->form);
784 fl_free_form(paper_->form);
789 delete combo_language;
790 fl_free_form(language_->form);
795 fl_free_form(options_->form);
800 fl_free_form(bullets_->form);
804 fl_free_form(dialog_->form);
810 int FormDocument::WMHideCB(FL_FORM * form, void *)
812 // Ensure that the signals (u and h) are disconnected even if the
813 // window manager is used to close the popup.
814 FormDocument * pre = (FormDocument*)form->u_vdata;
820 void FormDocument::OKCB(FL_OBJECT * ob, long)
822 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
828 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
830 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
835 void FormDocument::CancelCB(FL_OBJECT * ob, long)
837 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
843 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
845 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
850 void FormDocument::InputCB(FL_OBJECT * ob, long)
852 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
853 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
856 void FormDocument::ComboInputCB(int, void * v)
858 FormDocument * pre = static_cast<FormDocument*>(v);
859 // pre->CheckChoiceClass(0, 0);
860 pre->bc_->valid(pre->CheckDocumentInput(0,0));
863 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
865 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
866 pre->CheckChoiceClass(ob,0);
867 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
870 void FormDocument::checkReadOnly()
872 if (bc_->readOnly(lv_->buffer()->isReadonly())) {
873 combo_doc_class->deactivate();
874 combo_language->deactivate();
875 fl_set_object_label(dialog_->text_warning,
876 _("Document is read-only."
877 " No changes to layout permitted."));
878 fl_show_object(dialog_->text_warning);
880 combo_doc_class->activate();
881 combo_language->activate();
882 fl_hide_object(dialog_->text_warning);
886 void FormDocument::checkMarginValues()
890 allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
891 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
892 !strlen(fl_get_input(paper_->input_left_margin)) &&
893 !strlen(fl_get_input(paper_->input_right_margin)) &&
894 !strlen(fl_get_input(paper_->input_head_height)) &&
895 !strlen(fl_get_input(paper_->input_head_sep)) &&
896 !strlen(fl_get_input(paper_->input_foot_skip)) &&
897 !strlen(fl_get_input(paper_->input_custom_width)) &&
898 !strlen(fl_get_input(paper_->input_custom_height)));
900 fl_set_button(paper_->push_use_geometry, 1);
903 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
911 if (ob == paper_->choice_papersize2) {
912 val = fl_get_choice(paper_->choice_papersize2)-1;
913 if (val == BufferParams::VM_PAPER_DEFAULT) {
914 fl_set_button(paper_->push_use_geometry, 0);
917 if ((val != BufferParams::VM_PAPER_USLETTER) &&
918 (val != BufferParams::VM_PAPER_USLEGAL) &&
919 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
920 (val != BufferParams::VM_PAPER_A4) &&
921 (val != BufferParams::VM_PAPER_A5) &&
922 (val != BufferParams::VM_PAPER_B5)) {
923 fl_set_button(paper_->push_use_geometry, 1);
925 fl_set_choice(paper_->choice_paperpackage,
926 BufferParams::PACKAGE_NONE + 1);
928 } else if (ob == paper_->choice_paperpackage) {
929 val = fl_get_choice(paper_->choice_paperpackage)-1;
930 if (val != BufferParams::PACKAGE_NONE) {
931 fl_set_choice(paper_->choice_papersize2,
932 BufferParams::VM_PAPER_DEFAULT + 1);
933 fl_set_button(paper_->push_use_geometry, 0);
935 } else if (ob == class_->input_doc_spacing) {
936 input = fl_get_input(class_->input_doc_spacing);
938 fl_set_choice (class_->choice_doc_spacing, 1);
940 fl_set_choice(class_->choice_doc_spacing, 4);
943 // this has to be all out of if/elseif because it has to deactivate
944 // the document buttons and so the whole stuff has to be tested again.
945 str = fl_get_input(paper_->input_custom_width);
946 ok = ok && (str.empty() || isValidLength(str));
947 str = fl_get_input(paper_->input_custom_height);
948 ok = ok && (str.empty() || isValidLength(str));
949 str = fl_get_input(paper_->input_left_margin);
950 ok = ok && (str.empty() || isValidLength(str));
951 str = fl_get_input(paper_->input_right_margin);
952 ok = ok && (str.empty() || isValidLength(str));
953 str = fl_get_input(paper_->input_top_margin);
954 ok = ok && (str.empty() || isValidLength(str));
955 str = fl_get_input(paper_->input_bottom_margin);
956 ok = ok && (str.empty() || isValidLength(str));
957 str = fl_get_input(paper_->input_head_height);
958 ok = ok && (str.empty() || isValidLength(str));
959 str = fl_get_input(paper_->input_head_sep);
960 ok = ok && (str.empty() || isValidLength(str));
961 str = fl_get_input(paper_->input_foot_skip);
962 ok = ok && (str.empty() || isValidLength(str));
963 // "Synchronize" the choice and the input field, so that it
964 // is impossible to commit senseless data.
965 input = fl_get_input (class_->input_doc_skip);
966 if (ob == class_->input_doc_skip) {
968 fl_set_choice (class_->choice_doc_skip, 2);
969 } else if (isValidGlueLength (input)) {
970 fl_set_choice (class_->choice_doc_skip, 4);
972 fl_set_choice(class_->choice_doc_skip, 4);
976 if (*input && !isValidGlueLength(input))
979 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
981 else if (fl_get_choice(class_->choice_doc_skip) != 4)
982 fl_set_input (class_->input_doc_skip, "");
984 input = fl_get_input(class_->input_doc_spacing);
985 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
987 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
988 fl_set_input (class_->input_doc_spacing, "");
992 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
994 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
995 pre->ChoiceBulletSize(ob,0);
996 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
999 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1001 BufferParams & param = lv_->buffer()->params;
1003 // convert from 1-6 range to -1-4
1004 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1005 fl_set_input(bullets_->input_bullet_latex,
1006 param.temp_bullets[current_bullet_depth].c_str());
1009 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
1011 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1012 pre->InputBulletLaTeX(ob,0);
1013 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1016 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1018 BufferParams & param = lv_->buffer()->params;
1020 param.temp_bullets[current_bullet_depth].
1021 setText(fl_get_input(bullets_->input_bullet_latex));
1024 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
1026 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1027 pre->BulletDepth(ob,0);
1030 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
1032 /* Should I do the following: */
1033 /* 1. change to the panel that the current bullet belongs in */
1034 /* 2. show that bullet as selected */
1035 /* 3. change the size setting to the size of the bullet in Q.*/
1036 /* 4. display the latex equivalent in the latex box */
1038 /* I'm inclined to just go with 3 and 4 at the moment and */
1039 /* maybe try to support the others later */
1040 BufferParams & param = lv_->buffer()->params;
1042 switch (fl_get_button_numb(ob)) {
1044 // right mouse button resets to default
1045 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1047 current_bullet_depth = data;
1048 fl_set_input(bullets_->input_bullet_latex,
1049 param.temp_bullets[data].c_str());
1050 fl_set_choice(bullets_->choice_bullet_size,
1051 param.temp_bullets[data].getSize() + 2);
1055 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
1057 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1058 pre->BulletPanel(ob,data);
1061 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
1063 /* Here we have to change the background pixmap to that selected */
1064 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1066 if (data != current_bullet_panel) {
1067 fl_freeze_form(bullets_->form);
1068 current_bullet_panel = data;
1070 /* free the current pixmap */
1071 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1074 /* display the new one */
1076 new_panel = "standard";
1079 new_panel = "amssymb";
1082 new_panel = "psnfss1";
1085 new_panel = "psnfss2";
1088 new_panel = "psnfss3";
1091 new_panel = "psnfss4";
1094 /* something very wrong happened */
1095 // play it safe for now but should be an exception
1096 current_bullet_panel = 0; // standard panel
1097 new_panel = "standard";
1100 new_panel += ".xpm";
1101 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1102 LibFileSearch("images", new_panel.c_str()).c_str());
1103 fl_redraw_object(bullets_->bmtable_bullet_panel);
1104 fl_unfreeze_form(bullets_->form);
1108 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1110 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1111 pre->BulletBMTable(ob,0);
1112 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1115 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1117 /* handle the user input by setting the current bullet depth's pixmap */
1118 /* to that extracted from the current chosen position of the BMTable */
1119 /* Don't forget to free the button's old pixmap first. */
1121 BufferParams & param = lv_->buffer()->params;
1122 int bmtable_button = fl_get_bmtable(ob);
1124 /* try to keep the button held down till another is pushed */
1125 /* fl_set_bmtable(ob, 1, bmtable_button); */
1126 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1127 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1128 fl_set_input(bullets_->input_bullet_latex,
1129 param.temp_bullets[current_bullet_depth].c_str());
1132 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1135 ob = class_->choice_doc_class;
1137 ProhibitInput(lv_->view());
1141 #ifdef USE_CLASS_COMBO
1142 tc = combo_doc_class->get();
1143 tct = combo_doc_class->getline();
1145 tc = fl_get_choice(ob) - 1;
1146 tct = fl_get_choice_text(ob);
1148 if (textclasslist.Load(tc)) {
1149 if (AskQuestion(_("Should I set some parameters to"), tct,
1150 _("the defaults of this document class?"))) {
1151 BufferParams & params = lv_->buffer()->params;
1153 params.textclass = tc;
1154 params.useClassDefaults();
1155 UpdateLayoutDocument(params);
1158 // unable to load new style
1159 WriteAlert(_("Conversion Errors!"),
1160 _("Unable to switch to new document class."),
1161 _("Reverting to original document class."));
1162 #ifdef USE_CLASS_COMBO
1163 combo_doc_class->select(lv_->buffer()->params.textclass);
1165 fl_set_choice(class_->choice_doc_class,
1166 lv_->buffer()->params.textclass + 1);
1169 AllowInput(lv_->view());
1172 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1178 class_update(params);
1179 paper_update(params);
1180 language_update(params);
1181 options_update(params);
1182 bullets_update(params);