1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include "lyx_gui_misc.h"
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)
67 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
68 : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
69 bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
70 status(POPUP_UNMODIFIED) ,
71 bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
74 // let the popup be shown
75 // This is a permanent connection so we won't bother
76 // storing a copy because we won't be disconnecting.
77 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
78 current_bullet_depth = 0;
79 current_bullet_panel = 0;
83 FormDocument::~FormDocument()
90 void FormDocument::build()
95 dialog_ = build_tabbed_document();
97 // manage the restore, ok, apply and cancel/close buttons
98 bc_->setOK(dialog_->button_ok);
99 bc_->setApply(dialog_->button_apply);
100 bc_->setCancel(dialog_->button_cancel);
101 bc_->setUndoAll(dialog_->button_restore);
104 // the document paper form
105 paper_ = build_doc_paper();
106 fl_addto_choice(paper_->choice_papersize2,
107 _(" Default | Custom | USletter | USlegal "
108 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
109 fl_addto_choice(paper_->choice_paperpackage,
111 "| A4 small Margins (only portrait) "
112 "| A4 very small Margins (only portrait) "
113 "| A4 very wide margins (only portrait) "));
114 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
117 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
118 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
119 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
120 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
121 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
122 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
124 bc_->addReadOnly (paper_->choice_paperpackage);
125 bc_->addReadOnly (paper_->greoup_radio_orientation);
126 bc_->addReadOnly (paper_->radio_portrait);
127 bc_->addReadOnly (paper_->radio_landscape);
128 bc_->addReadOnly (paper_->choice_papersize2);
129 bc_->addReadOnly (paper_->push_use_geometry);
130 bc_->addReadOnly (paper_->input_custom_width);
131 bc_->addReadOnly (paper_->input_custom_height);
132 bc_->addReadOnly (paper_->input_top_margin);
133 bc_->addReadOnly (paper_->input_bottom_margin);
134 bc_->addReadOnly (paper_->input_left_margin);
135 bc_->addReadOnly (paper_->input_right_margin);
136 bc_->addReadOnly (paper_->input_head_height);
137 bc_->addReadOnly (paper_->input_head_sep);
138 bc_->addReadOnly (paper_->input_foot_skip);
140 // the document class form
141 class_ = build_doc_class();
144 #ifdef USE_CLASS_COMBO
145 // The language is a combo-box and has to be inserted manually
146 obj = class_->choice_doc_class;
147 fl_addto_form(class_->form);
148 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
149 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 200);
150 combo_doc_class->shortcut("#C",1);
151 combo_doc_class->setcallback(ComboInputCB, this);
153 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
154 cit != textclasslist.end(); ++cit)
156 combo_doc_class->addto((*cit).description().c_str());
159 fl_clear_choice(class_->choice_doc_class);
160 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
161 cit != textclasslist.end(); ++cit)
163 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
166 fl_addto_choice(class_->choice_doc_spacing,
167 _(" Single | OneHalf | Double | Other "));
168 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
169 for (n=0; tex_fonts[n][0]; ++n) {
170 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
172 fl_addto_choice(class_->choice_doc_pagestyle,
173 "default|empty|plain|headings|fancy");
174 fl_addto_choice(class_->choice_doc_skip,
175 _(" Smallskip | Medskip | Bigskip | Length "));
176 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
177 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
179 bc_->addReadOnly (class_->radio_doc_indent);
180 bc_->addReadOnly (class_->radio_doc_skip);
181 #ifndef USE_CLASS_COMBO
182 bc_->addReadOnly (class_->choice_doc_class);
184 bc_->addReadOnly (class_->choice_doc_pagestyle);
185 bc_->addReadOnly (class_->choice_doc_fonts);
186 bc_->addReadOnly (class_->choice_doc_fontsize);
187 bc_->addReadOnly (class_->radio_doc_sides_one);
188 bc_->addReadOnly (class_->radio_doc_sides_two);
189 bc_->addReadOnly (class_->radio_doc_columns_one);
190 bc_->addReadOnly (class_->radio_doc_columns_two);
191 bc_->addReadOnly (class_->input_doc_extra);
192 bc_->addReadOnly (class_->input_doc_skip);
193 bc_->addReadOnly (class_->choice_doc_skip);
194 bc_->addReadOnly (class_->choice_doc_spacing);
195 bc_->addReadOnly (class_->input_doc_spacing);
197 // the document language form
198 language_ = build_doc_language();
199 fl_addto_choice(language_->choice_inputenc,
200 "default|auto|latin1|latin2|latin5"
201 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
203 // The language is a combo-box and has to be inserted manually
204 obj = language_->choice_language;
205 fl_addto_form(language_->form);
206 combo_language = new Combox(FL_COMBOX_DROPLIST);
207 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
208 combo_language->shortcut("#L",1);
209 combo_language->setcallback(ComboInputCB, this);
211 // "default" is not part of the languages array any more.
212 combo_language->addto("default");
213 for(Languages::const_iterator cit = languages.begin();
214 cit != languages.end(); ++cit) {
215 combo_language->addto((*cit).second.lang().c_str());
218 fl_addto_choice(language_->choice_quotes_language,
219 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
220 " «text» | »text« "));
222 bc_->addReadOnly (language_->choice_language);
223 bc_->addReadOnly (language_->choice_inputenc);
225 // the document options form
226 options_ = build_doc_options();
227 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
228 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
229 fl_set_counter_step(options_->slider_secnumdepth,1,1);
230 fl_set_counter_step(options_->slider_tocdepth,1,1);
231 fl_set_counter_precision(options_->slider_secnumdepth, 0);
232 fl_set_counter_precision(options_->slider_tocdepth, 0);
233 for (n=0; tex_graphics[n][0]; ++n) {
234 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
237 bc_->addReadOnly (options_->slider_secnumdepth);
238 bc_->addReadOnly (options_->slider_tocdepth);
239 bc_->addReadOnly (options_->check_use_amsmath);
240 bc_->addReadOnly (options_->input_float_placement);
241 bc_->addReadOnly (options_->choice_postscript_driver);
243 // the document bullets form
244 bullets_ = build_doc_bullet();
245 fl_addto_choice(bullets_->choice_bullet_size,
246 _(" default | tiny | script | footnote | small |"
247 " normal | large | Large | LARGE | huge | Huge"));
248 fl_set_choice(bullets_->choice_bullet_size, 1);
249 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
250 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
252 fl_set_form_atclose(dialog_->form,
253 C_FormDocumentWMHideCB, 0);
254 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
256 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
258 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
260 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
262 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
264 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
265 lyxerr << _("Your version of libXpm is older than 4.7.\n"
266 "The `bullet' tab of the document popup "
267 "has been disabled") << '\n';
268 fl_deactivate_object(fbullet);
269 fl_set_object_lcol(fbullet, FL_INACTIVE);
274 void FormDocument::show()
279 update(); // make sure its up-to-date
280 if (dialog_->form->visible) {
281 fl_raise_form(dialog_->form);
283 fl_show_form(dialog_->form,
284 FL_PLACE_MOUSE | FL_FREE_SIZE,
285 FL_TRANSIENT, _("Document Layout"));
286 u_ = d_->updateBufferDependent.connect(
287 slot(this, &FormDocument::update));
288 h_ = d_->hideBufferDependent.connect(
289 slot(this, &FormDocument::hide));
294 void FormDocument::hide()
296 if (dialog_->form->visible) {
297 fl_hide_form(dialog_->form);
304 void FormDocument::apply()
306 if (!lv_->view()->available() || !dialog_)
309 bool redo = class_apply();
311 redo = language_apply() || redo;
312 redo = options_apply() || redo;
316 lv_->view()->redoCurrentBuffer();
318 lv_->buffer()->markDirty();
319 setMinibuffer(lv_, _("Document layout set"));
323 bool FormDocument::class_apply()
326 BufferParams ¶ms = lv_->buffer()->params;
328 // If default skip is a "Length" but there's no text in the
329 // input field, reset the kind to "Medskip", which is the default.
330 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
331 !*(fl_get_input (class_->input_doc_skip))) {
332 fl_set_choice (class_->choice_doc_skip, 2);
334 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
335 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
336 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
338 #ifdef USE_CLASS_COMBO
339 unsigned int new_class = combo_doc_class->get() - 1;
341 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
343 if (params.textclass != new_class) {
344 // try to load new_class
345 if (textclasslist.Load(new_class)) {
346 // successfully loaded
348 setMinibuffer(lv_, _("Converting document to new document class..."));
350 int ret = cap.SwitchLayoutsBetweenClasses(
351 params.textclass, new_class,
352 lv_->buffer()->paragraph);
356 s = _("One paragraph couldn't be converted");
359 s += _(" paragraphs couldn't be converted");
361 WriteAlert(_("Conversion Errors!"),s,
362 _("into chosen document class"));
365 params.textclass = new_class;
367 // problem changing class -- warn user and retain old style
368 WriteAlert(_("Conversion Errors!"),
369 _("Errors loading new document class."),
370 _("Reverting to original document class."));
371 #ifdef USE_CLASS_COMBO
372 combo_doc_class->select(params.textclass + 1);
374 fl_set_choice(class_->choice_doc_class,
375 params.textclass + 1);
379 char tmpsep = params.paragraph_separation;
380 if (fl_get_button(class_->radio_doc_indent))
381 params.paragraph_separation = BufferParams::PARSEP_INDENT;
383 params.paragraph_separation = BufferParams::PARSEP_SKIP;
384 if (tmpsep != params.paragraph_separation)
387 VSpace tmpdefskip = params.getDefSkip();
388 switch (fl_get_choice (class_->choice_doc_skip)) {
390 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
393 params.setDefSkip(VSpace(VSpace::MEDSKIP));
396 params.setDefSkip(VSpace(VSpace::BIGSKIP));
400 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
402 // DocumentDefskipCB assures that this never happens
404 params.setDefSkip(VSpace(VSpace::MEDSKIP));
407 if (!(tmpdefskip == params.getDefSkip()))
410 if (fl_get_button(class_->radio_doc_columns_two))
414 if (fl_get_button(class_->radio_doc_sides_two))
415 params.sides = LyXTextClass::TwoSides;
417 params.sides = LyXTextClass::OneSide;
419 Spacing tmpSpacing = params.spacing;
420 switch(fl_get_choice(class_->choice_doc_spacing)) {
422 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
423 params.spacing.set(Spacing::Single);
426 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
427 params.spacing.set(Spacing::Onehalf);
430 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
431 params.spacing.set(Spacing::Double);
434 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
435 params.spacing.set(Spacing::Other,
436 fl_get_input(class_->input_doc_spacing));
439 if (tmpSpacing != params.spacing)
442 params.options = fl_get_input(class_->input_doc_extra);
448 void FormDocument::paper_apply()
450 BufferParams & params = lv_->buffer()->params;
452 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
453 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
454 params.use_geometry = fl_get_button(paper_->push_use_geometry);
455 if (fl_get_button(paper_->radio_landscape))
456 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
458 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
459 params.paperwidth = fl_get_input(paper_->input_custom_width);
460 params.paperheight = fl_get_input(paper_->input_custom_height);
461 params.leftmargin = fl_get_input(paper_->input_left_margin);
462 params.topmargin = fl_get_input(paper_->input_top_margin);
463 params.rightmargin = fl_get_input(paper_->input_right_margin);
464 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
465 params.headheight = fl_get_input(paper_->input_head_height);
466 params.headsep = fl_get_input(paper_->input_head_sep);
467 params.footskip = fl_get_input(paper_->input_foot_skip);
468 lv_->buffer()->setPaperStuff();
472 bool FormDocument::language_apply()
474 BufferParams & params = lv_->buffer()->params;
475 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
478 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
480 lga = InsetQuotes::EnglishQ;
483 lga = InsetQuotes::SwedishQ;
486 lga = InsetQuotes::GermanQ;
489 lga = InsetQuotes::PolishQ;
492 lga = InsetQuotes::FrenchQ;
495 lga = InsetQuotes::DanishQ;
498 params.quotes_language = lga;
499 if (fl_get_button(language_->radio_single))
500 params.quotes_times = InsetQuotes::SingleQ;
502 params.quotes_times = InsetQuotes::DoubleQ;
504 Language const * old_language = params.language_info;
505 params.language = combo_language->getline();
506 Languages::iterator lit = languages.find(params.language);
508 Language const * new_language;
509 if (lit != languages.end())
510 new_language = &(*lit).second;
512 new_language = default_language;
514 if (old_language != new_language
515 && old_language->RightToLeft() == new_language->RightToLeft()
516 && !lv_->buffer()->isMultiLingual())
517 lv_->buffer()->ChangeLanguage(old_language, new_language);
518 if (old_language != new_language) {
521 params.language_info = new_language;
522 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
528 bool FormDocument::options_apply()
530 BufferParams & params = lv_->buffer()->params;
533 params.graphicsDriver =
534 fl_get_choice_text(options_->choice_postscript_driver);
535 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
537 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
538 if (params.secnumdepth != tmpchar)
540 params.secnumdepth = tmpchar;
542 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
544 params.float_placement =
545 fl_get_input(options_->input_float_placement);
551 void FormDocument::bullets_apply()
553 /* update the bullet settings */
554 BufferParams & param = lv_->buffer()->params;
556 // a little bit of loop unrolling
557 param.user_defined_bullets[0] = param.temp_bullets[0];
558 param.user_defined_bullets[1] = param.temp_bullets[1];
559 param.user_defined_bullets[2] = param.temp_bullets[2];
560 param.user_defined_bullets[3] = param.temp_bullets[3];
564 void FormDocument::cancel()
566 // this avoids confusion when reopening
567 BufferParams & param = lv_->buffer()->params;
568 param.temp_bullets[0] = param.user_defined_bullets[0];
569 param.temp_bullets[1] = param.user_defined_bullets[1];
570 param.temp_bullets[2] = param.user_defined_bullets[2];
571 param.temp_bullets[3] = param.user_defined_bullets[3];
575 void FormDocument::update()
582 BufferParams const & params = lv_->buffer()->params;
584 class_update(params);
585 paper_update(params);
586 language_update(params);
587 options_update(params);
588 bullets_update(params);
592 void FormDocument::class_update(BufferParams const & params)
597 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
599 #ifdef USE_CLASS_COMBO
600 combo_doc_class->select_text(
601 textclasslist.DescOfClass(params.textclass).c_str());
603 fl_set_choice_text(class_->choice_doc_class,
604 textclasslist.DescOfClass(params.textclass).c_str());
606 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
607 fl_clear_choice(class_->choice_doc_fontsize);
608 fl_addto_choice(class_->choice_doc_fontsize, "default");
609 fl_addto_choice(class_->choice_doc_fontsize,
610 tclass.opt_fontsize().c_str());
611 fl_set_choice(class_->choice_doc_fontsize,
612 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
613 fl_clear_choice(class_->choice_doc_pagestyle);
614 fl_addto_choice(class_->choice_doc_pagestyle, "default");
615 fl_addto_choice(class_->choice_doc_pagestyle,
616 tclass.opt_pagestyle().c_str());
617 fl_set_choice(class_->choice_doc_pagestyle,
618 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
619 fl_set_button(class_->radio_doc_indent, 0);
620 fl_set_button(class_->radio_doc_skip, 0);
621 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
622 fl_set_button(class_->radio_doc_indent, 1);
624 fl_set_button(class_->radio_doc_skip, 1);
625 switch (params.getDefSkip().kind()) {
626 case VSpace::SMALLSKIP:
627 fl_set_choice (class_->choice_doc_skip, 1);
629 case VSpace::MEDSKIP:
630 fl_set_choice (class_->choice_doc_skip, 2);
632 case VSpace::BIGSKIP:
633 fl_set_choice (class_->choice_doc_skip, 3);
636 fl_set_choice (class_->choice_doc_skip, 4);
637 fl_set_input (class_->input_doc_skip,
638 params.getDefSkip().asLyXCommand().c_str());
641 fl_set_choice (class_->choice_doc_skip, 2);
644 fl_set_button(class_->radio_doc_sides_one, 0);
645 fl_set_button(class_->radio_doc_sides_two, 0);
646 if (params.sides == 2)
647 fl_set_button(class_->radio_doc_sides_two, 1);
649 fl_set_button(class_->radio_doc_sides_one, 1);
650 fl_set_button(class_->radio_doc_columns_one, 0);
651 fl_set_button(class_->radio_doc_columns_two, 0);
652 if (params.columns == 2)
653 fl_set_button(class_->radio_doc_columns_two, 1);
655 fl_set_button(class_->radio_doc_columns_one, 1);
656 fl_set_input(class_->input_doc_spacing, "");
657 switch (params.spacing.getSpace()) {
658 case Spacing::Default: // nothing bad should happen with this
659 case Spacing::Single:
661 fl_set_choice(class_->choice_doc_spacing, 1);
663 case Spacing::Onehalf:
665 fl_set_choice(class_->choice_doc_spacing, 2);
667 case Spacing::Double:
669 fl_set_choice(class_->choice_doc_spacing, 3);
673 fl_set_choice(class_->choice_doc_spacing, 4);
675 sprintf(sval,"%g",params.spacing.getValue());
676 fl_set_input(class_->input_doc_spacing, sval);
680 if (!params.options.empty())
681 fl_set_input(class_->input_doc_extra, params.options.c_str());
683 fl_set_input(class_->input_doc_extra, "");
687 void FormDocument::language_update(BufferParams const & params)
692 combo_language->select_text(params.language.c_str());
693 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
694 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
695 fl_set_button(language_->radio_single, 0);
696 fl_set_button(language_->radio_double, 0);
697 if (params.quotes_times == InsetQuotes::SingleQ)
698 fl_set_button(language_->radio_single, 1);
700 fl_set_button(language_->radio_double, 1);
704 void FormDocument::options_update(BufferParams const & params)
709 fl_set_choice_text(options_->choice_postscript_driver,
710 params.graphicsDriver.c_str());
711 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
712 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
713 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
714 if (!params.float_placement.empty())
715 fl_set_input(options_->input_float_placement,
716 params.float_placement.c_str());
718 fl_set_input(options_->input_float_placement, "");
722 void FormDocument::paper_update(BufferParams const & params)
727 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
728 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
729 fl_set_button(paper_->push_use_geometry, params.use_geometry);
730 fl_set_button(paper_->radio_portrait, 0);
731 fl_set_button(paper_->radio_landscape, 0);
732 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
733 fl_set_button(paper_->radio_landscape, 1);
735 fl_set_button(paper_->radio_portrait, 1);
736 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
737 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
738 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
739 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
740 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
741 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
742 fl_set_input(paper_->input_head_height, params.headheight.c_str());
743 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
744 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
745 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
749 void FormDocument::bullets_update(BufferParams const & params)
751 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
754 if (lv_->buffer()->isLinuxDoc()) {
755 fl_deactivate_object(fbullet);
756 fl_set_object_lcol(fbullet, FL_INACTIVE);
759 fl_activate_object(fbullet);
760 fl_set_object_lcol(fbullet, FL_BLACK);
762 if (lv_->buffer()->isReadonly()) {
763 fl_deactivate_object (bullets_->bmtable_bullet_panel);
764 fl_deactivate_object (bullets_->choice_bullet_size);
765 fl_deactivate_object (bullets_->input_bullet_latex);
767 fl_activate_object (bullets_->bmtable_bullet_panel);
768 fl_activate_object (bullets_->choice_bullet_size);
769 fl_activate_object (bullets_->input_bullet_latex);
772 fl_set_button(bullets_->radio_bullet_depth_1, 1);
773 fl_set_input(bullets_->input_bullet_latex,
774 params.user_defined_bullets[0].getText().c_str());
775 fl_set_choice(bullets_->choice_bullet_size,
776 params.user_defined_bullets[0].getSize() + 2);
780 void FormDocument::free()
785 #ifdef USE_CLASS_COMBO
786 delete combo_doc_class;
788 fl_free_form(class_->form);
793 fl_free_form(paper_->form);
798 delete combo_language;
799 fl_free_form(language_->form);
804 fl_free_form(options_->form);
809 fl_free_form(bullets_->form);
813 fl_free_form(dialog_->form);
820 int FormDocument::WMHideCB(FL_FORM * form, void *)
822 // Ensure that the signals (u and h) are disconnected even if the
823 // window manager is used to close the popup.
824 FormDocument * pre = static_cast<FormDocument*>(form->u_vdata);
831 void FormDocument::OKCB(FL_OBJECT * ob, long)
833 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
840 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
842 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
848 void FormDocument::CancelCB(FL_OBJECT * ob, long)
850 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
857 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
859 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
865 void FormDocument::InputCB(FL_OBJECT * ob, long)
867 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
868 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
872 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
874 FormDocument * pre = static_cast<FormDocument*>(v);
875 if (combox == pre->combo_doc_class)
876 pre->CheckChoiceClass(0, 0);
877 pre->bc_->valid(pre->CheckDocumentInput(0,0));
881 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
883 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
884 pre->CheckChoiceClass(ob,0);
885 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
889 void FormDocument::checkReadOnly()
891 if (bc_->readOnly(lv_->buffer()->isReadonly())) {
892 combo_doc_class->deactivate();
893 combo_language->deactivate();
894 fl_set_object_label(dialog_->text_warning,
895 _("Document is read-only."
896 " No changes to layout permitted."));
897 fl_show_object(dialog_->text_warning);
899 combo_doc_class->activate();
900 combo_language->activate();
901 fl_hide_object(dialog_->text_warning);
906 void FormDocument::checkMarginValues()
908 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
909 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
910 !strlen(fl_get_input(paper_->input_left_margin)) &&
911 !strlen(fl_get_input(paper_->input_right_margin)) &&
912 !strlen(fl_get_input(paper_->input_head_height)) &&
913 !strlen(fl_get_input(paper_->input_head_sep)) &&
914 !strlen(fl_get_input(paper_->input_foot_skip)) &&
915 !strlen(fl_get_input(paper_->input_custom_width)) &&
916 !strlen(fl_get_input(paper_->input_custom_height)));
918 fl_set_button(paper_->push_use_geometry, 1);
921 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
929 if (ob == paper_->choice_papersize2) {
930 val = fl_get_choice(paper_->choice_papersize2)-1;
931 if (val == BufferParams::VM_PAPER_DEFAULT) {
932 fl_set_button(paper_->push_use_geometry, 0);
935 if ((val != BufferParams::VM_PAPER_USLETTER) &&
936 (val != BufferParams::VM_PAPER_USLEGAL) &&
937 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
938 (val != BufferParams::VM_PAPER_A4) &&
939 (val != BufferParams::VM_PAPER_A5) &&
940 (val != BufferParams::VM_PAPER_B5)) {
941 fl_set_button(paper_->push_use_geometry, 1);
943 fl_set_choice(paper_->choice_paperpackage,
944 BufferParams::PACKAGE_NONE + 1);
946 } else if (ob == paper_->choice_paperpackage) {
947 val = fl_get_choice(paper_->choice_paperpackage)-1;
948 if (val != BufferParams::PACKAGE_NONE) {
949 fl_set_choice(paper_->choice_papersize2,
950 BufferParams::VM_PAPER_DEFAULT + 1);
951 fl_set_button(paper_->push_use_geometry, 0);
953 } else if (ob == class_->input_doc_spacing) {
954 input = fl_get_input(class_->input_doc_spacing);
956 fl_set_choice (class_->choice_doc_spacing, 1);
958 fl_set_choice(class_->choice_doc_spacing, 4);
961 // this has to be all out of if/elseif because it has to deactivate
962 // the document buttons and so the whole stuff has to be tested again.
963 str = fl_get_input(paper_->input_custom_width);
964 ok = ok && (str.empty() || isValidLength(str));
965 str = fl_get_input(paper_->input_custom_height);
966 ok = ok && (str.empty() || isValidLength(str));
967 str = fl_get_input(paper_->input_left_margin);
968 ok = ok && (str.empty() || isValidLength(str));
969 str = fl_get_input(paper_->input_right_margin);
970 ok = ok && (str.empty() || isValidLength(str));
971 str = fl_get_input(paper_->input_top_margin);
972 ok = ok && (str.empty() || isValidLength(str));
973 str = fl_get_input(paper_->input_bottom_margin);
974 ok = ok && (str.empty() || isValidLength(str));
975 str = fl_get_input(paper_->input_head_height);
976 ok = ok && (str.empty() || isValidLength(str));
977 str = fl_get_input(paper_->input_head_sep);
978 ok = ok && (str.empty() || isValidLength(str));
979 str = fl_get_input(paper_->input_foot_skip);
980 ok = ok && (str.empty() || isValidLength(str));
981 // "Synchronize" the choice and the input field, so that it
982 // is impossible to commit senseless data.
983 input = fl_get_input (class_->input_doc_skip);
984 if (ob == class_->input_doc_skip) {
986 fl_set_choice (class_->choice_doc_skip, 2);
987 } else if (isValidGlueLength (input)) {
988 fl_set_choice (class_->choice_doc_skip, 4);
990 fl_set_choice(class_->choice_doc_skip, 4);
994 if (*input && !isValidGlueLength(input))
997 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
999 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1000 fl_set_input (class_->input_doc_skip, "");
1002 input = fl_get_input(class_->input_doc_spacing);
1003 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1005 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1006 fl_set_input (class_->input_doc_spacing, "");
1011 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
1013 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1014 pre->ChoiceBulletSize(ob,0);
1015 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1019 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1021 BufferParams & param = lv_->buffer()->params;
1023 // convert from 1-6 range to -1-4
1024 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1025 fl_set_input(bullets_->input_bullet_latex,
1026 param.temp_bullets[current_bullet_depth].getText().c_str());
1030 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
1032 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1033 pre->InputBulletLaTeX(ob,0);
1034 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1038 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1040 BufferParams & param = lv_->buffer()->params;
1042 param.temp_bullets[current_bullet_depth].
1043 setText(fl_get_input(bullets_->input_bullet_latex));
1047 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
1049 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1050 pre->BulletDepth(ob,0);
1054 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
1056 /* Should I do the following: */
1057 /* 1. change to the panel that the current bullet belongs in */
1058 /* 2. show that bullet as selected */
1059 /* 3. change the size setting to the size of the bullet in Q.*/
1060 /* 4. display the latex equivalent in the latex box */
1062 /* I'm inclined to just go with 3 and 4 at the moment and */
1063 /* maybe try to support the others later */
1064 BufferParams & param = lv_->buffer()->params;
1066 switch (fl_get_button_numb(ob)) {
1068 // right mouse button resets to default
1069 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1071 current_bullet_depth = data;
1072 fl_set_input(bullets_->input_bullet_latex,
1073 param.temp_bullets[data].getText().c_str());
1074 fl_set_choice(bullets_->choice_bullet_size,
1075 param.temp_bullets[data].getSize() + 2);
1080 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
1082 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1083 pre->BulletPanel(ob,data);
1087 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
1089 /* Here we have to change the background pixmap to that selected */
1090 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1092 if (data != current_bullet_panel) {
1093 fl_freeze_form(bullets_->form);
1094 current_bullet_panel = data;
1096 /* free the current pixmap */
1097 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1100 /* display the new one */
1102 new_panel = "standard";
1105 new_panel = "amssymb";
1108 new_panel = "psnfss1";
1111 new_panel = "psnfss2";
1114 new_panel = "psnfss3";
1117 new_panel = "psnfss4";
1120 /* something very wrong happened */
1121 // play it safe for now but should be an exception
1122 current_bullet_panel = 0; // standard panel
1123 new_panel = "standard";
1126 new_panel += ".xpm";
1127 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1128 LibFileSearch("images", new_panel.c_str()).c_str());
1129 fl_redraw_object(bullets_->bmtable_bullet_panel);
1130 fl_unfreeze_form(bullets_->form);
1135 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1137 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1138 pre->BulletBMTable(ob,0);
1139 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1143 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1145 /* handle the user input by setting the current bullet depth's pixmap */
1146 /* to that extracted from the current chosen position of the BMTable */
1147 /* Don't forget to free the button's old pixmap first. */
1149 BufferParams & param = lv_->buffer()->params;
1150 int bmtable_button = fl_get_bmtable(ob);
1152 /* try to keep the button held down till another is pushed */
1153 /* fl_set_bmtable(ob, 1, bmtable_button); */
1154 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1155 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1156 fl_set_input(bullets_->input_bullet_latex,
1157 param.temp_bullets[current_bullet_depth].getText().c_str());
1161 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1164 ob = class_->choice_doc_class;
1166 ProhibitInput(lv_->view());
1170 #ifdef USE_CLASS_COMBO
1171 tc = combo_doc_class->get() - 1;
1172 tct = combo_doc_class->getline();
1174 tc = fl_get_choice(ob) - 1;
1175 tct = fl_get_choice_text(ob);
1177 if (textclasslist.Load(tc)) {
1178 if (AskQuestion(_("Should I set some parameters to"), tct,
1179 _("the defaults of this document class?"))) {
1180 BufferParams & params = lv_->buffer()->params;
1182 params.textclass = tc;
1183 params.useClassDefaults();
1184 UpdateLayoutDocument(params);
1187 // unable to load new style
1188 WriteAlert(_("Conversion Errors!"),
1189 _("Unable to switch to new document class."),
1190 _("Reverting to original document class."));
1191 #ifdef USE_CLASS_COMBO
1192 combo_doc_class->select(lv_->buffer()->params.textclass + 1);
1194 fl_set_choice(class_->choice_doc_class,
1195 lv_->buffer()->params.textclass + 1);
1198 AllowInput(lv_->view());
1202 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1208 class_update(params);
1209 paper_update(params);
1210 language_update(params);
1211 options_update(params);
1212 bullets_update(params);