1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 2000 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include "lyx_gui_misc.h"
20 #include FORMS_H_LOCATION
21 #include XPM_H_LOCATION
23 #include "FormDocument.h"
24 #include "form_document.h"
25 #include "xform_macros.h"
29 #include "tex-strings.h"
30 #include "bufferparams.h"
31 #include "insets/insetquotes.h"
34 #include "support/filetools.h"
37 #include "BufferView.h"
40 #include "CutAndPaste.h"
41 #include "bufferview_funcs.h"
42 #include "ButtonController.h"
44 #ifdef SIGC_CXX_NAMESPACES
48 #ifdef CXX_WORKING_NAMESPACES
49 using Liason::setMinibuffer;
52 C_RETURNCB(FormDocument, WMHideCB)
53 C_GENERICCB(FormDocument, InputCB)
54 C_GENERICCB(FormDocument, OKCB)
55 C_GENERICCB(FormDocument, ApplyCB)
56 C_GENERICCB(FormDocument, CancelCB)
57 C_GENERICCB(FormDocument, RestoreCB)
58 C_GENERICCB(FormDocument, ChoiceClassCB)
59 C_GENERICCB(FormDocument, BulletPanelCB)
60 C_GENERICCB(FormDocument, BulletDepthCB)
61 C_GENERICCB(FormDocument, InputBulletLaTeXCB)
62 C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
64 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
65 : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
66 bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
67 status(POPUP_UNMODIFIED) ,
68 bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
71 // let the popup be shown
72 // This is a permanent connection so we won't bother
73 // storing a copy because we won't be disconnecting.
74 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
75 current_bullet_depth = 0;
76 current_bullet_panel = 0;
79 FormDocument::~FormDocument()
85 void FormDocument::build()
90 dialog_ = build_tabbed_document();
92 // manage the restore, ok, apply and cancel/close buttons
93 bc_->setOK(dialog_->button_ok);
94 bc_->setApply(dialog_->button_apply);
95 bc_->setCancel(dialog_->button_cancel);
96 bc_->setUndoAll(dialog_->button_restore);
99 // the document paper form
100 paper_ = build_doc_paper();
101 fl_addto_choice(paper_->choice_papersize2,
102 _(" Default | Custom | USletter | USlegal "
103 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
104 fl_addto_choice(paper_->choice_paperpackage,
106 "| A4 small Margins (only portrait) "
107 "| A4 very small Margins (only portrait) "
108 "| A4 very wide margins (only portrait) "));
109 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
110 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
111 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
112 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
116 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
117 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
119 bc_->addReadOnly (paper_->choice_paperpackage);
120 bc_->addReadOnly (paper_->greoup_radio_orientation);
121 bc_->addReadOnly (paper_->radio_portrait);
122 bc_->addReadOnly (paper_->radio_landscape);
123 bc_->addReadOnly (paper_->choice_papersize2);
124 bc_->addReadOnly (paper_->push_use_geometry);
125 bc_->addReadOnly (paper_->input_custom_width);
126 bc_->addReadOnly (paper_->input_custom_height);
127 bc_->addReadOnly (paper_->input_top_margin);
128 bc_->addReadOnly (paper_->input_bottom_margin);
129 bc_->addReadOnly (paper_->input_left_margin);
130 bc_->addReadOnly (paper_->input_right_margin);
131 bc_->addReadOnly (paper_->input_head_height);
132 bc_->addReadOnly (paper_->input_head_sep);
133 bc_->addReadOnly (paper_->input_foot_skip);
135 // the document class form
136 class_ = build_doc_class();
137 fl_clear_choice(class_->choice_doc_class);
138 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
139 cit != textclasslist.end(); ++cit)
141 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
143 fl_addto_choice(class_->choice_doc_spacing,
144 _(" Single | OneHalf | Double | Other "));
145 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
146 for (n=0; tex_fonts[n][0]; ++n) {
147 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
149 fl_addto_choice(class_->choice_doc_pagestyle,
150 "default|empty|plain|headings|fancy");
151 fl_addto_choice(class_->choice_doc_skip,
152 _(" Smallskip | Medskip | Bigskip | Length "));
153 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
154 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
156 bc_->addReadOnly (class_->radio_doc_indent);
157 bc_->addReadOnly (class_->radio_doc_skip);
158 bc_->addReadOnly (class_->choice_doc_class);
159 bc_->addReadOnly (class_->choice_doc_pagestyle);
160 bc_->addReadOnly (class_->choice_doc_fonts);
161 bc_->addReadOnly (class_->choice_doc_fontsize);
162 bc_->addReadOnly (class_->radio_doc_sides_one);
163 bc_->addReadOnly (class_->radio_doc_sides_two);
164 bc_->addReadOnly (class_->radio_doc_columns_one);
165 bc_->addReadOnly (class_->radio_doc_columns_two);
166 bc_->addReadOnly (class_->input_doc_extra);
167 bc_->addReadOnly (class_->input_doc_skip);
168 bc_->addReadOnly (class_->choice_doc_skip);
169 bc_->addReadOnly (class_->choice_doc_spacing);
170 bc_->addReadOnly (class_->input_doc_spacing);
172 // the document language form
173 language_ = build_doc_language();
174 fl_addto_choice(language_->choice_inputenc,
175 "default|auto|latin1|latin2|latin5"
176 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
178 // The language is a combo-box and has to be inserted manually
179 FL_OBJECT * obj = language_->choice_language;
180 fl_addto_form(language_->form);
181 combo_language = new Combox(FL_COMBOX_DROPLIST);
182 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
183 combo_language->shortcut("#L",1);
185 // "default" is not part of the languages array any more.
186 combo_language->addto("default");
187 for(Languages::const_iterator cit = languages.begin();
188 cit != languages.end(); ++cit) {
189 combo_language->addto((*cit).second.lang().c_str());
192 fl_addto_choice(language_->choice_quotes_language,
193 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
194 " «text» | »text« "));
196 bc_->addReadOnly (language_->choice_language);
197 bc_->addReadOnly (language_->choice_inputenc);
199 // the document options form
200 options_ = build_doc_options();
201 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
202 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
203 fl_set_counter_step(options_->slider_secnumdepth,1,1);
204 fl_set_counter_step(options_->slider_tocdepth,1,1);
205 fl_set_counter_precision(options_->slider_secnumdepth, 0);
206 fl_set_counter_precision(options_->slider_tocdepth, 0);
207 for (n=0; tex_graphics[n][0]; ++n) {
208 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
211 bc_->addReadOnly (options_->slider_secnumdepth);
212 bc_->addReadOnly (options_->slider_tocdepth);
213 bc_->addReadOnly (options_->check_use_amsmath);
214 bc_->addReadOnly (options_->input_float_placement);
215 bc_->addReadOnly (options_->choice_postscript_driver);
217 // the document bullets form
218 bullets_ = build_doc_bullet();
219 fl_addto_choice(bullets_->choice_bullet_size,
220 _(" default | tiny | script | footnote | small |"
221 " normal | large | Large | LARGE | huge | Huge"));
222 fl_set_choice(bullets_->choice_bullet_size, 1);
223 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
224 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
226 fl_set_form_atclose(dialog_->form,
227 FormDocument::WMHideCB, 0);
228 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
230 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
232 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
234 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
236 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
238 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
239 lyxerr << _("Your version of libXpm is older than 4.7.\n"
240 "The `bullet' tab of the document popup "
241 "has been disabled") << '\n';
242 fl_deactivate_object(fbullet);
243 fl_set_object_lcol(fbullet, FL_INACTIVE);
247 void FormDocument::show()
252 update(); // make sure its up-to-date
253 if (dialog_->form->visible) {
254 fl_raise_form(dialog_->form);
256 fl_show_form(dialog_->form,
257 FL_PLACE_MOUSE | FL_FREE_SIZE,
258 FL_TRANSIENT, _("Document Layout"));
259 u_ = d_->updateBufferDependent.connect(
260 slot(this, &FormDocument::update));
261 h_ = d_->hideBufferDependent.connect(
262 slot(this, &FormDocument::hide));
266 void FormDocument::hide()
268 if (dialog_->form->visible) {
269 fl_hide_form(dialog_->form);
275 void FormDocument::apply()
277 if (!lv_->view()->available() || !dialog_)
283 redo = class_apply();
285 redo = language_apply() || redo;
286 redo = options_apply() || redo;
290 lv_->view()->redoCurrentBuffer();
292 lv_->buffer()->markDirty();
293 setMinibuffer(lv_, _("Document layout set"));
297 bool FormDocument::class_apply()
300 BufferParams ¶ms = lv_->buffer()->params;
302 // If default skip is a "Length" but there's no text in the
303 // input field, reset the kind to "Medskip", which is the default.
304 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
305 !*(fl_get_input (class_->input_doc_skip))) {
306 fl_set_choice (class_->choice_doc_skip, 2);
308 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
309 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
310 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
312 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
313 if (params.textclass != new_class) {
314 // try to load new_class
315 if (textclasslist.Load(new_class)) {
316 // successfully loaded
318 setMinibuffer(lv_, _("Converting document to new document class..."));
320 int ret = cap.SwitchLayoutsBetweenClasses(
321 params.textclass, new_class,
322 lv_->buffer()->paragraph);
326 s = _("One paragraph couldn't be converted");
329 s += _(" paragraphs couldn't be converted");
331 WriteAlert(_("Conversion Errors!"),s,
332 _("into chosen document class"));
335 params.textclass = new_class;
337 // problem changing class -- warn user and retain old style
338 WriteAlert(_("Conversion Errors!"),
339 _("Errors loading new document class."),
340 _("Reverting to original document class."));
341 fl_set_choice(class_->choice_doc_class,
342 params.textclass + 1);
345 char tmpsep = params.paragraph_separation;
346 if (fl_get_button(class_->radio_doc_indent))
347 params.paragraph_separation = BufferParams::PARSEP_INDENT;
349 params.paragraph_separation = BufferParams::PARSEP_SKIP;
350 if (tmpsep != params.paragraph_separation)
353 VSpace tmpdefskip = params.getDefSkip();
354 switch (fl_get_choice (class_->choice_doc_skip)) {
356 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
359 params.setDefSkip(VSpace(VSpace::MEDSKIP));
362 params.setDefSkip(VSpace(VSpace::BIGSKIP));
366 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
368 // DocumentDefskipCB assures that this never happens
370 params.setDefSkip(VSpace(VSpace::MEDSKIP));
373 if (!(tmpdefskip == params.getDefSkip()))
376 if (fl_get_button(class_->radio_doc_columns_two))
380 if (fl_get_button(class_->radio_doc_sides_two))
381 params.sides = LyXTextClass::TwoSides;
383 params.sides = LyXTextClass::OneSide;
385 Spacing tmpSpacing = params.spacing;
386 switch(fl_get_choice(class_->choice_doc_spacing)) {
388 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
389 params.spacing.set(Spacing::Single);
392 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
393 params.spacing.set(Spacing::Onehalf);
396 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
397 params.spacing.set(Spacing::Double);
400 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
401 params.spacing.set(Spacing::Other,
402 fl_get_input(class_->input_doc_spacing));
405 if (tmpSpacing != params.spacing)
408 params.options = fl_get_input(class_->input_doc_extra);
413 void FormDocument::paper_apply()
416 ¶ms = lv_->buffer()->params;
418 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
419 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
420 params.use_geometry = fl_get_button(paper_->push_use_geometry);
421 if (fl_get_button(paper_->radio_landscape))
422 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
424 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
425 params.paperwidth = fl_get_input(paper_->input_custom_width);
426 params.paperheight = fl_get_input(paper_->input_custom_height);
427 params.leftmargin = fl_get_input(paper_->input_left_margin);
428 params.topmargin = fl_get_input(paper_->input_top_margin);
429 params.rightmargin = fl_get_input(paper_->input_right_margin);
430 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
431 params.headheight = fl_get_input(paper_->input_head_height);
432 params.headsep = fl_get_input(paper_->input_head_sep);
433 params.footskip = fl_get_input(paper_->input_foot_skip);
434 lv_->buffer()->setPaperStuff();
437 bool FormDocument::language_apply()
440 ¶ms = lv_->buffer()->params;
441 InsetQuotes::quote_language
442 lga = InsetQuotes::EnglishQ;
445 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
447 lga = InsetQuotes::EnglishQ;
450 lga = InsetQuotes::SwedishQ;
453 lga = InsetQuotes::GermanQ;
456 lga = InsetQuotes::PolishQ;
459 lga = InsetQuotes::FrenchQ;
462 lga = InsetQuotes::DanishQ;
465 params.quotes_language = lga;
466 if (fl_get_button(language_->radio_single))
467 params.quotes_times = InsetQuotes::SingleQ;
469 params.quotes_times = InsetQuotes::DoubleQ;
471 Language const * old_language = params.language_info;
472 params.language = combo_language->getline();
473 Languages::iterator lit = languages.find(params.language);
475 Language const * new_language;
476 if (lit != languages.end())
477 new_language = &(*lit).second;
479 new_language = default_language;
481 if (old_language != new_language
482 && old_language->RightToLeft() == new_language->RightToLeft()
483 && !lv_->buffer()->isMultiLingual())
484 lv_->buffer()->ChangeLanguage(old_language, new_language);
485 if (old_language != new_language) {
488 params.language_info = new_language;
489 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
494 bool FormDocument::options_apply()
497 ¶ms = lv_->buffer()->params;
501 params.graphicsDriver =
502 fl_get_choice_text(options_->choice_postscript_driver);
503 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
505 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
506 if (params.secnumdepth != tmpchar)
508 params.secnumdepth = tmpchar;
510 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
512 params.float_placement =
513 fl_get_input(options_->input_float_placement);
518 void FormDocument::bullets_apply()
520 /* update the bullet settings */
521 BufferParams & param = lv_->buffer()->params;
523 // a little bit of loop unrolling
524 param.user_defined_bullets[0] = param.temp_bullets[0];
525 param.user_defined_bullets[1] = param.temp_bullets[1];
526 param.user_defined_bullets[2] = param.temp_bullets[2];
527 param.user_defined_bullets[3] = param.temp_bullets[3];
530 void FormDocument::cancel()
532 // this avoids confusion when reopening
533 BufferParams & param = lv_->buffer()->params;
534 param.temp_bullets[0] = param.user_defined_bullets[0];
535 param.temp_bullets[1] = param.user_defined_bullets[1];
536 param.temp_bullets[2] = param.user_defined_bullets[2];
537 param.temp_bullets[3] = param.user_defined_bullets[3];
540 void FormDocument::update()
548 const & params = lv_->buffer()->params;
550 class_update(params);
551 paper_update(params);
552 language_update(params);
553 options_update(params);
554 bullets_update(params);
557 void FormDocument::class_update(BufferParams const & params)
562 const & tclass = textclasslist.TextClass(params.textclass);
564 fl_set_choice_text(class_->choice_doc_class,
565 textclasslist.DescOfClass(params.textclass).c_str());
566 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
567 fl_clear_choice(class_->choice_doc_fontsize);
568 fl_addto_choice(class_->choice_doc_fontsize, "default");
569 fl_addto_choice(class_->choice_doc_fontsize,
570 tclass.opt_fontsize().c_str());
571 fl_set_choice(class_->choice_doc_fontsize,
572 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
573 fl_clear_choice(class_->choice_doc_pagestyle);
574 fl_addto_choice(class_->choice_doc_pagestyle, "default");
575 fl_addto_choice(class_->choice_doc_pagestyle,
576 tclass.opt_pagestyle().c_str());
577 fl_set_choice(class_->choice_doc_pagestyle,
578 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
579 fl_set_button(class_->radio_doc_indent, 0);
580 fl_set_button(class_->radio_doc_skip, 0);
581 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
582 fl_set_button(class_->radio_doc_indent, 1);
584 fl_set_button(class_->radio_doc_skip, 1);
585 switch (params.getDefSkip().kind()) {
586 case VSpace::SMALLSKIP:
587 fl_set_choice (class_->choice_doc_skip, 1);
589 case VSpace::MEDSKIP:
590 fl_set_choice (class_->choice_doc_skip, 2);
592 case VSpace::BIGSKIP:
593 fl_set_choice (class_->choice_doc_skip, 3);
596 fl_set_choice (class_->choice_doc_skip, 4);
597 fl_set_input (class_->input_doc_skip,
598 params.getDefSkip().asLyXCommand().c_str());
601 fl_set_choice (class_->choice_doc_skip, 2);
604 fl_set_button(class_->radio_doc_sides_one, 0);
605 fl_set_button(class_->radio_doc_sides_two, 0);
606 if (params.sides == 2)
607 fl_set_button(class_->radio_doc_sides_two, 1);
609 fl_set_button(class_->radio_doc_sides_one, 1);
610 fl_set_button(class_->radio_doc_columns_one, 0);
611 fl_set_button(class_->radio_doc_columns_two, 0);
612 if (params.columns == 2)
613 fl_set_button(class_->radio_doc_columns_two, 1);
615 fl_set_button(class_->radio_doc_columns_one, 1);
616 fl_set_input(class_->input_doc_spacing, "");
617 switch (params.spacing.getSpace()) {
618 case Spacing::Default: // nothing bad should happen with this
619 case Spacing::Single:
621 fl_set_choice(class_->choice_doc_spacing, 1);
623 case Spacing::Onehalf:
625 fl_set_choice(class_->choice_doc_spacing, 2);
627 case Spacing::Double:
629 fl_set_choice(class_->choice_doc_spacing, 3);
633 fl_set_choice(class_->choice_doc_spacing, 4);
635 sprintf(sval,"%g",params.spacing.getValue());
636 fl_set_input(class_->input_doc_spacing, sval);
640 if (!params.options.empty())
641 fl_set_input(class_->input_doc_extra, params.options.c_str());
643 fl_set_input(class_->input_doc_extra, "");
646 void FormDocument::language_update(BufferParams const & params)
651 combo_language->select_text(params.language.c_str());
652 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
653 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
654 fl_set_button(language_->radio_single, 0);
655 fl_set_button(language_->radio_double, 0);
656 if (params.quotes_times == InsetQuotes::SingleQ)
657 fl_set_button(language_->radio_single, 1);
659 fl_set_button(language_->radio_double, 1);
662 void FormDocument::options_update(BufferParams const & params)
667 fl_set_choice_text(options_->choice_postscript_driver,
668 params.graphicsDriver.c_str());
669 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
670 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
671 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
672 if (!params.float_placement.empty())
673 fl_set_input(options_->input_float_placement,
674 params.float_placement.c_str());
676 fl_set_input(options_->input_float_placement, "");
679 void FormDocument::paper_update(BufferParams const & params)
684 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
685 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
686 fl_set_button(paper_->push_use_geometry, params.use_geometry);
687 fl_set_button(paper_->radio_portrait, 0);
688 fl_set_button(paper_->radio_landscape, 0);
689 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
690 fl_set_button(paper_->radio_landscape, 1);
692 fl_set_button(paper_->radio_portrait, 1);
693 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
694 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
695 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
696 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
697 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
698 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
699 fl_set_input(paper_->input_head_height, params.headheight.c_str());
700 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
701 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
702 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
705 void FormDocument::bullets_update(BufferParams const & params)
707 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
710 if (lv_->buffer()->isLinuxDoc()) {
711 fl_deactivate_object(fbullet);
712 fl_set_object_lcol(fbullet, FL_INACTIVE);
715 fl_activate_object(fbullet);
716 fl_set_object_lcol(fbullet, FL_BLACK);
718 if (lv_->buffer()->isReadonly()) {
719 fl_deactivate_object (bullets_->bmtable_bullet_panel);
720 fl_deactivate_object (bullets_->choice_bullet_size);
721 fl_deactivate_object (bullets_->input_bullet_latex);
723 fl_activate_object (bullets_->bmtable_bullet_panel);
724 fl_activate_object (bullets_->choice_bullet_size);
725 fl_activate_object (bullets_->input_bullet_latex);
728 fl_set_button(bullets_->radio_bullet_depth_1, 1);
729 fl_set_input(bullets_->input_bullet_latex,
730 params.user_defined_bullets[0].c_str());
731 fl_set_choice(bullets_->choice_bullet_size,
732 params.user_defined_bullets[0].getSize() + 2);
735 void FormDocument::free()
740 fl_free_form(class_->form);
745 fl_free_form(paper_->form);
750 delete combo_language;
751 fl_free_form(language_->form);
756 fl_free_form(options_->form);
761 fl_free_form(bullets_->form);
765 fl_free_form(dialog_->form);
771 int FormDocument::WMHideCB(FL_FORM * form, void *)
773 // Ensure that the signals (u and h) are disconnected even if the
774 // window manager is used to close the popup.
775 FormDocument * pre = (FormDocument*)form->u_vdata;
781 void FormDocument::OKCB(FL_OBJECT * ob, long)
783 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
789 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
791 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
796 void FormDocument::CancelCB(FL_OBJECT * ob, long)
798 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
804 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
806 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
811 void FormDocument::InputCB(FL_OBJECT * ob, long)
813 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
814 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
817 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
819 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
820 pre->CheckChoiceClass(ob,0);
821 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
824 void FormDocument::checkReadOnly()
826 if (bc_->readOnly(lv_->buffer()->isReadonly())) {
827 combo_language->deactivate();
828 fl_set_object_label(dialog_->text_warning,
829 _("Document is read-only."
830 " No changes to layout permitted."));
831 fl_show_object(dialog_->text_warning);
833 combo_language->activate();
834 fl_hide_object(dialog_->text_warning);
838 void FormDocument::checkMarginValues()
842 allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
843 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
844 !strlen(fl_get_input(paper_->input_left_margin)) &&
845 !strlen(fl_get_input(paper_->input_right_margin)) &&
846 !strlen(fl_get_input(paper_->input_head_height)) &&
847 !strlen(fl_get_input(paper_->input_head_sep)) &&
848 !strlen(fl_get_input(paper_->input_foot_skip)) &&
849 !strlen(fl_get_input(paper_->input_custom_width)) &&
850 !strlen(fl_get_input(paper_->input_custom_height)));
852 fl_set_button(paper_->push_use_geometry, 1);
855 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
863 if (ob == paper_->choice_papersize2) {
864 val = fl_get_choice(paper_->choice_papersize2)-1;
865 if (val == BufferParams::VM_PAPER_DEFAULT) {
866 fl_set_button(paper_->push_use_geometry, 0);
869 if ((val != BufferParams::VM_PAPER_USLETTER) &&
870 (val != BufferParams::VM_PAPER_USLEGAL) &&
871 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
872 (val != BufferParams::VM_PAPER_A4) &&
873 (val != BufferParams::VM_PAPER_A5) &&
874 (val != BufferParams::VM_PAPER_B5)) {
875 fl_set_button(paper_->push_use_geometry, 1);
877 fl_set_choice(paper_->choice_paperpackage,
878 BufferParams::PACKAGE_NONE + 1);
880 } else if (ob == paper_->choice_paperpackage) {
881 val = fl_get_choice(paper_->choice_paperpackage)-1;
882 if (val != BufferParams::PACKAGE_NONE) {
883 fl_set_choice(paper_->choice_papersize2,
884 BufferParams::VM_PAPER_DEFAULT + 1);
885 fl_set_button(paper_->push_use_geometry, 0);
887 } else if (ob == class_->input_doc_spacing) {
888 input = fl_get_input(class_->input_doc_spacing);
890 fl_set_choice (class_->choice_doc_spacing, 1);
892 fl_set_choice(class_->choice_doc_spacing, 4);
895 // this has to be all out of if/elseif because it has to deactivate
896 // the document buttons and so the whole stuff has to be tested again.
897 str = fl_get_input(paper_->input_custom_width);
898 ok = ok && (str.empty() || isValidLength(str));
899 str = fl_get_input(paper_->input_custom_height);
900 ok = ok && (str.empty() || isValidLength(str));
901 str = fl_get_input(paper_->input_left_margin);
902 ok = ok && (str.empty() || isValidLength(str));
903 str = fl_get_input(paper_->input_right_margin);
904 ok = ok && (str.empty() || isValidLength(str));
905 str = fl_get_input(paper_->input_top_margin);
906 ok = ok && (str.empty() || isValidLength(str));
907 str = fl_get_input(paper_->input_bottom_margin);
908 ok = ok && (str.empty() || isValidLength(str));
909 str = fl_get_input(paper_->input_head_height);
910 ok = ok && (str.empty() || isValidLength(str));
911 str = fl_get_input(paper_->input_head_sep);
912 ok = ok && (str.empty() || isValidLength(str));
913 str = fl_get_input(paper_->input_foot_skip);
914 ok = ok && (str.empty() || isValidLength(str));
915 // "Synchronize" the choice and the input field, so that it
916 // is impossible to commit senseless data.
917 input = fl_get_input (class_->input_doc_skip);
918 if (ob == class_->input_doc_skip) {
920 fl_set_choice (class_->choice_doc_skip, 2);
921 } else if (isValidGlueLength (input)) {
922 fl_set_choice (class_->choice_doc_skip, 4);
924 fl_set_choice(class_->choice_doc_skip, 4);
928 if (*input && !isValidGlueLength(input))
931 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
933 else if (fl_get_choice(class_->choice_doc_skip) != 4)
934 fl_set_input (class_->input_doc_skip, "");
936 input = fl_get_input(class_->input_doc_spacing);
937 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
939 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
940 fl_set_input (class_->input_doc_spacing, "");
944 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
946 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
947 pre->ChoiceBulletSize(ob,0);
948 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
951 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
953 BufferParams & param = lv_->buffer()->params;
955 // convert from 1-6 range to -1-4
956 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
957 fl_set_input(bullets_->input_bullet_latex,
958 param.temp_bullets[current_bullet_depth].c_str());
961 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
963 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
964 pre->InputBulletLaTeX(ob,0);
965 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
968 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
970 BufferParams & param = lv_->buffer()->params;
972 param.temp_bullets[current_bullet_depth].
973 setText(fl_get_input(bullets_->input_bullet_latex));
976 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
978 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
979 pre->BulletDepth(ob,0);
982 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
984 /* Should I do the following: */
985 /* 1. change to the panel that the current bullet belongs in */
986 /* 2. show that bullet as selected */
987 /* 3. change the size setting to the size of the bullet in Q.*/
988 /* 4. display the latex equivalent in the latex box */
990 /* I'm inclined to just go with 3 and 4 at the moment and */
991 /* maybe try to support the others later */
992 BufferParams & param = lv_->buffer()->params;
994 switch (fl_get_button_numb(ob)) {
996 // right mouse button resets to default
997 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
999 current_bullet_depth = data;
1000 fl_set_input(bullets_->input_bullet_latex,
1001 param.temp_bullets[data].c_str());
1002 fl_set_choice(bullets_->choice_bullet_size,
1003 param.temp_bullets[data].getSize() + 2);
1007 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
1009 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1010 pre->BulletPanel(ob,data);
1013 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
1015 /* Here we have to change the background pixmap to that selected */
1016 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1018 if (data != current_bullet_panel) {
1019 fl_freeze_form(bullets_->form);
1020 current_bullet_panel = data;
1022 /* free the current pixmap */
1023 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1026 /* display the new one */
1028 new_panel = "standard";
1031 new_panel = "amssymb";
1034 new_panel = "psnfss1";
1037 new_panel = "psnfss2";
1040 new_panel = "psnfss3";
1043 new_panel = "psnfss4";
1046 /* something very wrong happened */
1047 // play it safe for now but should be an exception
1048 current_bullet_panel = 0; // standard panel
1049 new_panel = "standard";
1052 new_panel += ".xpm";
1053 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1054 LibFileSearch("images", new_panel.c_str()).c_str());
1055 fl_redraw_object(bullets_->bmtable_bullet_panel);
1056 fl_unfreeze_form(bullets_->form);
1060 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1062 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
1063 pre->BulletBMTable(ob,0);
1064 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1067 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1069 /* handle the user input by setting the current bullet depth's pixmap */
1070 /* to that extracted from the current chosen position of the BMTable */
1071 /* Don't forget to free the button's old pixmap first. */
1073 BufferParams & param = lv_->buffer()->params;
1074 int bmtable_button = fl_get_bmtable(ob);
1076 /* try to keep the button held down till another is pushed */
1077 /* fl_set_bmtable(ob, 1, bmtable_button); */
1078 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1079 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1080 fl_set_input(bullets_->input_bullet_latex,
1081 param.temp_bullets[current_bullet_depth].c_str());
1084 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1086 ProhibitInput(lv_->view());
1087 if (textclasslist.Load(fl_get_choice(ob)-1)) {
1088 if (AskQuestion(_("Should I set some parameters to"),
1089 fl_get_choice_text(ob),
1090 _("the defaults of this document class?"))) {
1091 BufferParams & params = lv_->buffer()->params;
1093 params.textclass = fl_get_choice(ob)-1;
1094 params.useClassDefaults();
1095 UpdateLayoutDocument(params);
1098 // unable to load new style
1099 WriteAlert(_("Conversion Errors!"),
1100 _("Unable to switch to new document class."),
1101 _("Reverting to original document class."));
1102 fl_set_choice(class_->choice_doc_class,
1103 lv_->view()->buffer()->params.textclass + 1);
1105 AllowInput(lv_->view());
1108 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1114 class_update(params);
1115 paper_update(params);
1116 language_update(params);
1117 options_update(params);
1118 bullets_update(params);