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 #ifdef DO_USE_DEFAULT_LANGUAGE
213 combo_language->addto("default");
215 for(Languages::iterator cit = languages.begin();
216 cit != languages.end(); ++cit) {
217 combo_language->addto((*cit).second.lang().c_str());
220 fl_addto_choice(language_->choice_quotes_language,
221 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
222 " «text» | »text« "));
224 bc_->addReadOnly (language_->choice_language);
225 bc_->addReadOnly (language_->choice_inputenc);
227 // the document options form
228 options_ = build_doc_options();
229 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
230 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
231 fl_set_counter_step(options_->slider_secnumdepth,1,1);
232 fl_set_counter_step(options_->slider_tocdepth,1,1);
233 fl_set_counter_precision(options_->slider_secnumdepth, 0);
234 fl_set_counter_precision(options_->slider_tocdepth, 0);
235 for (n=0; tex_graphics[n][0]; ++n) {
236 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
239 bc_->addReadOnly (options_->slider_secnumdepth);
240 bc_->addReadOnly (options_->slider_tocdepth);
241 bc_->addReadOnly (options_->check_use_amsmath);
242 bc_->addReadOnly (options_->input_float_placement);
243 bc_->addReadOnly (options_->choice_postscript_driver);
245 // the document bullets form
246 bullets_ = build_doc_bullet();
247 fl_addto_choice(bullets_->choice_bullet_size,
248 _(" default | tiny | script | footnote | small |"
249 " normal | large | Large | LARGE | huge | Huge"));
250 fl_set_choice(bullets_->choice_bullet_size, 1);
251 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
252 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
254 fl_set_form_atclose(dialog_->form,
255 C_FormDocumentWMHideCB, 0);
256 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
258 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
260 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
262 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
264 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
266 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
267 lyxerr << _("Your version of libXpm is older than 4.7.\n"
268 "The `bullet' tab of the document popup "
269 "has been disabled") << '\n';
270 fl_deactivate_object(fbullet);
271 fl_set_object_lcol(fbullet, FL_INACTIVE);
276 void FormDocument::show()
281 update(); // make sure its up-to-date
282 if (dialog_->form->visible) {
283 fl_raise_form(dialog_->form);
285 fl_show_form(dialog_->form,
286 FL_PLACE_MOUSE | FL_FREE_SIZE,
287 FL_TRANSIENT, _("Document Layout"));
288 u_ = d_->updateBufferDependent.connect(
289 slot(this, &FormDocument::update));
290 h_ = d_->hideBufferDependent.connect(
291 slot(this, &FormDocument::hide));
296 void FormDocument::hide()
298 if (dialog_->form->visible) {
299 fl_hide_form(dialog_->form);
306 void FormDocument::apply()
308 if (!lv_->view()->available() || !dialog_)
311 bool redo = class_apply();
313 redo = language_apply() || redo;
314 redo = options_apply() || redo;
318 lv_->view()->redoCurrentBuffer();
320 lv_->buffer()->markDirty();
321 setMinibuffer(lv_, _("Document layout set"));
325 bool FormDocument::class_apply()
328 BufferParams ¶ms = lv_->buffer()->params;
330 // If default skip is a "Length" but there's no text in the
331 // input field, reset the kind to "Medskip", which is the default.
332 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
333 !*(fl_get_input (class_->input_doc_skip))) {
334 fl_set_choice (class_->choice_doc_skip, 2);
336 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
337 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
338 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
340 #ifdef USE_CLASS_COMBO
341 unsigned int new_class = combo_doc_class->get() - 1;
343 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
345 if (params.textclass != new_class) {
346 // try to load new_class
347 if (textclasslist.Load(new_class)) {
348 // successfully loaded
350 setMinibuffer(lv_, _("Converting document to new document class..."));
352 int ret = cap.SwitchLayoutsBetweenClasses(
353 params.textclass, new_class,
354 lv_->buffer()->paragraph);
358 s = _("One paragraph couldn't be converted");
361 s += _(" paragraphs couldn't be converted");
363 WriteAlert(_("Conversion Errors!"),s,
364 _("into chosen document class"));
367 params.textclass = new_class;
369 // problem changing class -- warn user and retain old style
370 WriteAlert(_("Conversion Errors!"),
371 _("Errors loading new document class."),
372 _("Reverting to original document class."));
373 #ifdef USE_CLASS_COMBO
374 combo_doc_class->select(params.textclass + 1);
376 fl_set_choice(class_->choice_doc_class,
377 params.textclass + 1);
381 char tmpsep = params.paragraph_separation;
382 if (fl_get_button(class_->radio_doc_indent))
383 params.paragraph_separation = BufferParams::PARSEP_INDENT;
385 params.paragraph_separation = BufferParams::PARSEP_SKIP;
386 if (tmpsep != params.paragraph_separation)
389 VSpace tmpdefskip = params.getDefSkip();
390 switch (fl_get_choice (class_->choice_doc_skip)) {
392 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
395 params.setDefSkip(VSpace(VSpace::MEDSKIP));
398 params.setDefSkip(VSpace(VSpace::BIGSKIP));
402 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
404 // DocumentDefskipCB assures that this never happens
406 params.setDefSkip(VSpace(VSpace::MEDSKIP));
409 if (!(tmpdefskip == params.getDefSkip()))
412 if (fl_get_button(class_->radio_doc_columns_two))
416 if (fl_get_button(class_->radio_doc_sides_two))
417 params.sides = LyXTextClass::TwoSides;
419 params.sides = LyXTextClass::OneSide;
421 Spacing tmpSpacing = params.spacing;
422 switch(fl_get_choice(class_->choice_doc_spacing)) {
424 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
425 params.spacing.set(Spacing::Single);
428 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
429 params.spacing.set(Spacing::Onehalf);
432 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
433 params.spacing.set(Spacing::Double);
436 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
437 params.spacing.set(Spacing::Other,
438 fl_get_input(class_->input_doc_spacing));
441 if (tmpSpacing != params.spacing)
444 params.options = fl_get_input(class_->input_doc_extra);
450 void FormDocument::paper_apply()
452 BufferParams & params = lv_->buffer()->params;
454 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
455 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
456 params.use_geometry = fl_get_button(paper_->push_use_geometry);
457 if (fl_get_button(paper_->radio_landscape))
458 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
460 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
461 params.paperwidth = fl_get_input(paper_->input_custom_width);
462 params.paperheight = fl_get_input(paper_->input_custom_height);
463 params.leftmargin = fl_get_input(paper_->input_left_margin);
464 params.topmargin = fl_get_input(paper_->input_top_margin);
465 params.rightmargin = fl_get_input(paper_->input_right_margin);
466 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
467 params.headheight = fl_get_input(paper_->input_head_height);
468 params.headsep = fl_get_input(paper_->input_head_sep);
469 params.footskip = fl_get_input(paper_->input_foot_skip);
470 lv_->buffer()->setPaperStuff();
474 bool FormDocument::language_apply()
476 BufferParams & params = lv_->buffer()->params;
477 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
480 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
482 lga = InsetQuotes::EnglishQ;
485 lga = InsetQuotes::SwedishQ;
488 lga = InsetQuotes::GermanQ;
491 lga = InsetQuotes::PolishQ;
494 lga = InsetQuotes::FrenchQ;
497 lga = InsetQuotes::DanishQ;
500 params.quotes_language = lga;
501 if (fl_get_button(language_->radio_single))
502 params.quotes_times = InsetQuotes::SingleQ;
504 params.quotes_times = InsetQuotes::DoubleQ;
506 Language const * old_language = params.language_info;
507 params.language = combo_language->getline();
508 Languages::iterator lit = languages.find(params.language);
510 Language const * new_language;
511 if (lit != languages.end())
512 new_language = &(*lit).second;
514 new_language = default_language;
516 if (old_language != new_language
517 && old_language->RightToLeft() == new_language->RightToLeft()
518 && !lv_->buffer()->isMultiLingual())
519 lv_->buffer()->ChangeLanguage(old_language, new_language);
520 if (old_language != new_language) {
523 params.language_info = new_language;
524 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
530 bool FormDocument::options_apply()
532 BufferParams & params = lv_->buffer()->params;
535 params.graphicsDriver =
536 fl_get_choice_text(options_->choice_postscript_driver);
537 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
539 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
540 if (params.secnumdepth != tmpchar)
542 params.secnumdepth = tmpchar;
544 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
546 params.float_placement =
547 fl_get_input(options_->input_float_placement);
553 void FormDocument::bullets_apply()
555 /* update the bullet settings */
556 BufferParams & param = lv_->buffer()->params;
558 // a little bit of loop unrolling
559 param.user_defined_bullets[0] = param.temp_bullets[0];
560 param.user_defined_bullets[1] = param.temp_bullets[1];
561 param.user_defined_bullets[2] = param.temp_bullets[2];
562 param.user_defined_bullets[3] = param.temp_bullets[3];
566 void FormDocument::cancel()
568 // this avoids confusion when reopening
569 BufferParams & param = lv_->buffer()->params;
570 param.temp_bullets[0] = param.user_defined_bullets[0];
571 param.temp_bullets[1] = param.user_defined_bullets[1];
572 param.temp_bullets[2] = param.user_defined_bullets[2];
573 param.temp_bullets[3] = param.user_defined_bullets[3];
577 void FormDocument::update()
584 BufferParams const & params = lv_->buffer()->params;
586 class_update(params);
587 paper_update(params);
588 language_update(params);
589 options_update(params);
590 bullets_update(params);
594 void FormDocument::class_update(BufferParams const & params)
599 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
601 #ifdef USE_CLASS_COMBO
602 combo_doc_class->select_text(
603 textclasslist.DescOfClass(params.textclass).c_str());
605 fl_set_choice_text(class_->choice_doc_class,
606 textclasslist.DescOfClass(params.textclass).c_str());
608 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
609 fl_clear_choice(class_->choice_doc_fontsize);
610 fl_addto_choice(class_->choice_doc_fontsize, "default");
611 fl_addto_choice(class_->choice_doc_fontsize,
612 tclass.opt_fontsize().c_str());
613 fl_set_choice(class_->choice_doc_fontsize,
614 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
615 fl_clear_choice(class_->choice_doc_pagestyle);
616 fl_addto_choice(class_->choice_doc_pagestyle, "default");
617 fl_addto_choice(class_->choice_doc_pagestyle,
618 tclass.opt_pagestyle().c_str());
619 fl_set_choice(class_->choice_doc_pagestyle,
620 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
621 fl_set_button(class_->radio_doc_indent, 0);
622 fl_set_button(class_->radio_doc_skip, 0);
623 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
624 fl_set_button(class_->radio_doc_indent, 1);
626 fl_set_button(class_->radio_doc_skip, 1);
627 switch (params.getDefSkip().kind()) {
628 case VSpace::SMALLSKIP:
629 fl_set_choice (class_->choice_doc_skip, 1);
631 case VSpace::MEDSKIP:
632 fl_set_choice (class_->choice_doc_skip, 2);
634 case VSpace::BIGSKIP:
635 fl_set_choice (class_->choice_doc_skip, 3);
638 fl_set_choice (class_->choice_doc_skip, 4);
639 fl_set_input (class_->input_doc_skip,
640 params.getDefSkip().asLyXCommand().c_str());
643 fl_set_choice (class_->choice_doc_skip, 2);
646 fl_set_button(class_->radio_doc_sides_one, 0);
647 fl_set_button(class_->radio_doc_sides_two, 0);
648 if (params.sides == 2)
649 fl_set_button(class_->radio_doc_sides_two, 1);
651 fl_set_button(class_->radio_doc_sides_one, 1);
652 fl_set_button(class_->radio_doc_columns_one, 0);
653 fl_set_button(class_->radio_doc_columns_two, 0);
654 if (params.columns == 2)
655 fl_set_button(class_->radio_doc_columns_two, 1);
657 fl_set_button(class_->radio_doc_columns_one, 1);
658 fl_set_input(class_->input_doc_spacing, "");
659 switch (params.spacing.getSpace()) {
660 case Spacing::Default: // nothing bad should happen with this
661 case Spacing::Single:
663 fl_set_choice(class_->choice_doc_spacing, 1);
665 case Spacing::Onehalf:
667 fl_set_choice(class_->choice_doc_spacing, 2);
669 case Spacing::Double:
671 fl_set_choice(class_->choice_doc_spacing, 3);
675 fl_set_choice(class_->choice_doc_spacing, 4);
677 sprintf(sval,"%g",params.spacing.getValue());
678 fl_set_input(class_->input_doc_spacing, sval);
682 if (!params.options.empty())
683 fl_set_input(class_->input_doc_extra, params.options.c_str());
685 fl_set_input(class_->input_doc_extra, "");
689 void FormDocument::language_update(BufferParams const & params)
694 combo_language->select_text(params.language.c_str());
695 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
696 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
697 fl_set_button(language_->radio_single, 0);
698 fl_set_button(language_->radio_double, 0);
699 if (params.quotes_times == InsetQuotes::SingleQ)
700 fl_set_button(language_->radio_single, 1);
702 fl_set_button(language_->radio_double, 1);
706 void FormDocument::options_update(BufferParams const & params)
711 fl_set_choice_text(options_->choice_postscript_driver,
712 params.graphicsDriver.c_str());
713 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
714 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
715 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
716 if (!params.float_placement.empty())
717 fl_set_input(options_->input_float_placement,
718 params.float_placement.c_str());
720 fl_set_input(options_->input_float_placement, "");
724 void FormDocument::paper_update(BufferParams const & params)
729 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
730 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
731 fl_set_button(paper_->push_use_geometry, params.use_geometry);
732 fl_set_button(paper_->radio_portrait, 0);
733 fl_set_button(paper_->radio_landscape, 0);
734 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
735 fl_set_button(paper_->radio_landscape, 1);
737 fl_set_button(paper_->radio_portrait, 1);
738 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
739 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
740 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
741 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
742 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
743 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
744 fl_set_input(paper_->input_head_height, params.headheight.c_str());
745 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
746 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
747 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
751 void FormDocument::bullets_update(BufferParams const & params)
753 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
756 if (lv_->buffer()->isLinuxDoc()) {
757 fl_deactivate_object(fbullet);
758 fl_set_object_lcol(fbullet, FL_INACTIVE);
761 fl_activate_object(fbullet);
762 fl_set_object_lcol(fbullet, FL_BLACK);
764 if (lv_->buffer()->isReadonly()) {
765 fl_deactivate_object (bullets_->bmtable_bullet_panel);
766 fl_deactivate_object (bullets_->choice_bullet_size);
767 fl_deactivate_object (bullets_->input_bullet_latex);
769 fl_activate_object (bullets_->bmtable_bullet_panel);
770 fl_activate_object (bullets_->choice_bullet_size);
771 fl_activate_object (bullets_->input_bullet_latex);
774 fl_set_button(bullets_->radio_bullet_depth_1, 1);
775 fl_set_input(bullets_->input_bullet_latex,
776 params.user_defined_bullets[0].getText().c_str());
777 fl_set_choice(bullets_->choice_bullet_size,
778 params.user_defined_bullets[0].getSize() + 2);
782 void FormDocument::free()
787 #ifdef USE_CLASS_COMBO
788 delete combo_doc_class;
790 fl_free_form(class_->form);
795 fl_free_form(paper_->form);
800 delete combo_language;
801 fl_free_form(language_->form);
806 fl_free_form(options_->form);
811 fl_free_form(bullets_->form);
815 fl_free_form(dialog_->form);
822 int FormDocument::WMHideCB(FL_FORM * form, void *)
824 // Ensure that the signals (u and h) are disconnected even if the
825 // window manager is used to close the popup.
826 FormDocument * pre = static_cast<FormDocument*>(form->u_vdata);
833 void FormDocument::OKCB(FL_OBJECT * ob, long)
835 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
842 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
844 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
850 void FormDocument::CancelCB(FL_OBJECT * ob, long)
852 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
859 void FormDocument::RestoreCB(FL_OBJECT * ob, long)
861 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
867 void FormDocument::InputCB(FL_OBJECT * ob, long)
869 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
870 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
874 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
876 FormDocument * pre = static_cast<FormDocument*>(v);
877 if (combox == pre->combo_doc_class)
878 pre->CheckChoiceClass(0, 0);
879 pre->bc_->valid(pre->CheckDocumentInput(0,0));
883 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
885 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
886 pre->CheckChoiceClass(ob,0);
887 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
891 void FormDocument::checkReadOnly()
893 if (bc_->readOnly(lv_->buffer()->isReadonly())) {
894 combo_doc_class->deactivate();
895 combo_language->deactivate();
896 fl_set_object_label(dialog_->text_warning,
897 _("Document is read-only."
898 " No changes to layout permitted."));
899 fl_show_object(dialog_->text_warning);
901 combo_doc_class->activate();
902 combo_language->activate();
903 fl_hide_object(dialog_->text_warning);
908 void FormDocument::checkMarginValues()
910 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
911 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
912 !strlen(fl_get_input(paper_->input_left_margin)) &&
913 !strlen(fl_get_input(paper_->input_right_margin)) &&
914 !strlen(fl_get_input(paper_->input_head_height)) &&
915 !strlen(fl_get_input(paper_->input_head_sep)) &&
916 !strlen(fl_get_input(paper_->input_foot_skip)) &&
917 !strlen(fl_get_input(paper_->input_custom_width)) &&
918 !strlen(fl_get_input(paper_->input_custom_height)));
920 fl_set_button(paper_->push_use_geometry, 1);
923 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
931 if (ob == paper_->choice_papersize2) {
932 val = fl_get_choice(paper_->choice_papersize2)-1;
933 if (val == BufferParams::VM_PAPER_DEFAULT) {
934 fl_set_button(paper_->push_use_geometry, 0);
937 if ((val != BufferParams::VM_PAPER_USLETTER) &&
938 (val != BufferParams::VM_PAPER_USLEGAL) &&
939 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
940 (val != BufferParams::VM_PAPER_A4) &&
941 (val != BufferParams::VM_PAPER_A5) &&
942 (val != BufferParams::VM_PAPER_B5)) {
943 fl_set_button(paper_->push_use_geometry, 1);
945 fl_set_choice(paper_->choice_paperpackage,
946 BufferParams::PACKAGE_NONE + 1);
948 } else if (ob == paper_->choice_paperpackage) {
949 val = fl_get_choice(paper_->choice_paperpackage)-1;
950 if (val != BufferParams::PACKAGE_NONE) {
951 fl_set_choice(paper_->choice_papersize2,
952 BufferParams::VM_PAPER_DEFAULT + 1);
953 fl_set_button(paper_->push_use_geometry, 0);
955 } else if (ob == class_->input_doc_spacing) {
956 input = fl_get_input(class_->input_doc_spacing);
958 fl_set_choice (class_->choice_doc_spacing, 1);
960 fl_set_choice(class_->choice_doc_spacing, 4);
963 // this has to be all out of if/elseif because it has to deactivate
964 // the document buttons and so the whole stuff has to be tested again.
965 str = fl_get_input(paper_->input_custom_width);
966 ok = ok && (str.empty() || isValidLength(str));
967 str = fl_get_input(paper_->input_custom_height);
968 ok = ok && (str.empty() || isValidLength(str));
969 str = fl_get_input(paper_->input_left_margin);
970 ok = ok && (str.empty() || isValidLength(str));
971 str = fl_get_input(paper_->input_right_margin);
972 ok = ok && (str.empty() || isValidLength(str));
973 str = fl_get_input(paper_->input_top_margin);
974 ok = ok && (str.empty() || isValidLength(str));
975 str = fl_get_input(paper_->input_bottom_margin);
976 ok = ok && (str.empty() || isValidLength(str));
977 str = fl_get_input(paper_->input_head_height);
978 ok = ok && (str.empty() || isValidLength(str));
979 str = fl_get_input(paper_->input_head_sep);
980 ok = ok && (str.empty() || isValidLength(str));
981 str = fl_get_input(paper_->input_foot_skip);
982 ok = ok && (str.empty() || isValidLength(str));
983 // "Synchronize" the choice and the input field, so that it
984 // is impossible to commit senseless data.
985 input = fl_get_input (class_->input_doc_skip);
986 if (ob == class_->input_doc_skip) {
988 fl_set_choice (class_->choice_doc_skip, 2);
989 } else if (isValidGlueLength (input)) {
990 fl_set_choice (class_->choice_doc_skip, 4);
992 fl_set_choice(class_->choice_doc_skip, 4);
996 if (*input && !isValidGlueLength(input))
999 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1001 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1002 fl_set_input (class_->input_doc_skip, "");
1004 input = fl_get_input(class_->input_doc_spacing);
1005 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1007 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1008 fl_set_input (class_->input_doc_spacing, "");
1013 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
1015 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1016 pre->ChoiceBulletSize(ob,0);
1017 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1021 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1023 BufferParams & param = lv_->buffer()->params;
1025 // convert from 1-6 range to -1-4
1026 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1027 fl_set_input(bullets_->input_bullet_latex,
1028 param.temp_bullets[current_bullet_depth].getText().c_str());
1032 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
1034 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1035 pre->InputBulletLaTeX(ob,0);
1036 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1040 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1042 BufferParams & param = lv_->buffer()->params;
1044 param.temp_bullets[current_bullet_depth].
1045 setText(fl_get_input(bullets_->input_bullet_latex));
1049 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
1051 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1052 pre->BulletDepth(ob,0);
1056 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
1058 /* Should I do the following: */
1059 /* 1. change to the panel that the current bullet belongs in */
1060 /* 2. show that bullet as selected */
1061 /* 3. change the size setting to the size of the bullet in Q.*/
1062 /* 4. display the latex equivalent in the latex box */
1064 /* I'm inclined to just go with 3 and 4 at the moment and */
1065 /* maybe try to support the others later */
1066 BufferParams & param = lv_->buffer()->params;
1068 switch (fl_get_button_numb(ob)) {
1070 // right mouse button resets to default
1071 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1073 current_bullet_depth = data;
1074 fl_set_input(bullets_->input_bullet_latex,
1075 param.temp_bullets[data].getText().c_str());
1076 fl_set_choice(bullets_->choice_bullet_size,
1077 param.temp_bullets[data].getSize() + 2);
1082 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
1084 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1085 pre->BulletPanel(ob,data);
1089 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
1091 /* Here we have to change the background pixmap to that selected */
1092 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1094 if (data != current_bullet_panel) {
1095 fl_freeze_form(bullets_->form);
1096 current_bullet_panel = data;
1098 /* free the current pixmap */
1099 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1102 /* display the new one */
1104 new_panel = "standard";
1107 new_panel = "amssymb";
1110 new_panel = "psnfss1";
1113 new_panel = "psnfss2";
1116 new_panel = "psnfss3";
1119 new_panel = "psnfss4";
1122 /* something very wrong happened */
1123 // play it safe for now but should be an exception
1124 current_bullet_panel = 0; // standard panel
1125 new_panel = "standard";
1128 new_panel += ".xpm";
1129 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1130 LibFileSearch("images", new_panel.c_str()).c_str());
1131 fl_redraw_object(bullets_->bmtable_bullet_panel);
1132 fl_unfreeze_form(bullets_->form);
1137 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1139 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1140 pre->BulletBMTable(ob,0);
1141 pre->bc_->valid(pre->CheckDocumentInput(ob,0));
1145 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1147 /* handle the user input by setting the current bullet depth's pixmap */
1148 /* to that extracted from the current chosen position of the BMTable */
1149 /* Don't forget to free the button's old pixmap first. */
1151 BufferParams & param = lv_->buffer()->params;
1152 int bmtable_button = fl_get_bmtable(ob);
1154 /* try to keep the button held down till another is pushed */
1155 /* fl_set_bmtable(ob, 1, bmtable_button); */
1156 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1157 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1158 fl_set_input(bullets_->input_bullet_latex,
1159 param.temp_bullets[current_bullet_depth].getText().c_str());
1163 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1166 ob = class_->choice_doc_class;
1168 ProhibitInput(lv_->view());
1172 #ifdef USE_CLASS_COMBO
1173 tc = combo_doc_class->get() - 1;
1174 tct = combo_doc_class->getline();
1176 tc = fl_get_choice(ob) - 1;
1177 tct = fl_get_choice_text(ob);
1179 if (textclasslist.Load(tc)) {
1180 if (AskQuestion(_("Should I set some parameters to"), tct,
1181 _("the defaults of this document class?"))) {
1182 BufferParams & params = lv_->buffer()->params;
1184 params.textclass = tc;
1185 params.useClassDefaults();
1186 UpdateLayoutDocument(params);
1189 // unable to load new style
1190 WriteAlert(_("Conversion Errors!"),
1191 _("Unable to switch to new document class."),
1192 _("Reverting to original document class."));
1193 #ifdef USE_CLASS_COMBO
1194 combo_doc_class->select(lv_->buffer()->params.textclass + 1);
1196 fl_set_choice(class_->choice_doc_class,
1197 lv_->buffer()->params.textclass + 1);
1200 AllowInput(lv_->view());
1204 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1210 class_update(params);
1211 paper_update(params);
1212 language_update(params);
1213 options_update(params);
1214 bullets_update(params);