1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
10 *======================================================*/
14 #include FORMS_H_LOCATION
15 #include XPM_H_LOCATION
18 #pragma implementation
21 #include "lyx_gui_misc.h"
23 #include "FormDocument.h"
24 #include "form_document.h"
28 #include "tex-strings.h"
29 #include "bufferparams.h"
30 #include "insets/insetquotes.h"
33 #include "support/filetools.h"
36 #include "BufferView.h"
39 #include "CutAndPaste.h"
40 #include "bufferview_funcs.h"
41 #include "xforms_helpers.h"
43 using Liason::setMinibuffer;
45 #define USE_CLASS_COMBO 1
47 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
48 : FormBaseBD(lv, d, _("Document Layout")), fbullet(0)
50 // let the popup be shown
51 // This is a permanent connection so we won't bother
52 // storing a copy because we won't be disconnecting.
53 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
57 void FormDocument::redraw()
59 if( form() && form()->visible )
60 fl_redraw_form( form() );
64 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
65 if (outer_form && outer_form->visible)
66 fl_redraw_form( outer_form );
70 FL_FORM * FormDocument::form() const
72 if (dialog_.get()) return dialog_->form;
77 void FormDocument::build()
82 dialog_.reset(build_tabbed_document());
84 // Manage the restore, ok, apply, restore and cancel/close buttons
85 bc().setOK(dialog_->button_ok);
86 bc().setApply(dialog_->button_apply);
87 bc().setCancel(dialog_->button_cancel);
88 bc().setUndoAll(dialog_->button_restore);
91 // Workaround dumb xforms sizing bug
95 // the document paper form
96 paper_.reset(build_doc_paper());
97 fl_addto_choice(paper_->choice_papersize2,
98 _(" Default | Custom | USletter | USlegal "
99 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
100 fl_addto_choice(paper_->choice_paperpackage,
102 "| A4 small Margins (only portrait) "
103 "| A4 very small Margins (only portrait) "
104 "| A4 very wide margins (only portrait) "));
105 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
106 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
107 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
108 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
109 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
115 bc().addReadOnly (paper_->choice_paperpackage);
116 bc().addReadOnly (paper_->greoup_radio_orientation);
117 bc().addReadOnly (paper_->radio_portrait);
118 bc().addReadOnly (paper_->radio_landscape);
119 bc().addReadOnly (paper_->choice_papersize2);
120 bc().addReadOnly (paper_->push_use_geometry);
121 bc().addReadOnly (paper_->input_custom_width);
122 bc().addReadOnly (paper_->input_custom_height);
123 bc().addReadOnly (paper_->input_top_margin);
124 bc().addReadOnly (paper_->input_bottom_margin);
125 bc().addReadOnly (paper_->input_left_margin);
126 bc().addReadOnly (paper_->input_right_margin);
127 bc().addReadOnly (paper_->input_head_height);
128 bc().addReadOnly (paper_->input_head_sep);
129 bc().addReadOnly (paper_->input_foot_skip);
131 // the document class form
132 class_.reset(build_doc_class());
135 #ifdef USE_CLASS_COMBO
136 // The language is a combo-box and has to be inserted manually
137 obj = class_->choice_doc_class;
138 fl_deactivate_object(obj);
139 fl_addto_form(class_->form);
140 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
141 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
142 dialog_->tabbed_folder);
143 combo_doc_class->shortcut("#C",1);
144 combo_doc_class->setcallback(ComboInputCB, this);
146 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
147 cit != textclasslist.end(); ++cit)
149 combo_doc_class->addto((*cit).description());
152 fl_clear_choice(class_->choice_doc_class);
153 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
154 cit != textclasslist.end(); ++cit)
156 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
159 fl_addto_choice(class_->choice_doc_spacing,
160 _(" Single | OneHalf | Double | Other "));
161 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
162 for (n=0; tex_fonts[n][0]; ++n) {
163 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
165 fl_addto_choice(class_->choice_doc_pagestyle,
166 "default|empty|plain|headings|fancy");
167 fl_addto_choice(class_->choice_doc_skip,
168 _(" Smallskip | Medskip | Bigskip | Length "));
169 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
170 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
171 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
173 bc().addReadOnly (class_->radio_doc_indent);
174 bc().addReadOnly (class_->radio_doc_skip);
175 #ifndef USE_CLASS_COMBO
176 bc().addReadOnly (class_->choice_doc_class);
178 bc().addReadOnly (class_->choice_doc_pagestyle);
179 bc().addReadOnly (class_->choice_doc_fonts);
180 bc().addReadOnly (class_->choice_doc_fontsize);
181 bc().addReadOnly (class_->radio_doc_sides_one);
182 bc().addReadOnly (class_->radio_doc_sides_two);
183 bc().addReadOnly (class_->radio_doc_columns_one);
184 bc().addReadOnly (class_->radio_doc_columns_two);
185 bc().addReadOnly (class_->input_doc_extra);
186 bc().addReadOnly (class_->input_doc_skip);
187 bc().addReadOnly (class_->choice_doc_skip);
188 bc().addReadOnly (class_->choice_doc_spacing);
189 bc().addReadOnly (class_->input_doc_spacing);
191 // the document language form
192 language_.reset(build_doc_language());
193 fl_addto_choice(language_->choice_inputenc,
194 "default|auto|latin1|latin2|latin5"
195 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
197 // The language is a combo-box and has to be inserted manually
198 obj = language_->choice_language;
199 fl_deactivate_object(obj);
200 fl_addto_form(language_->form);
201 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
202 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
203 dialog_->tabbed_folder);
204 combo_language->shortcut("#L",1);
205 combo_language->setcallback(ComboInputCB, this);
208 for (Languages::const_iterator cit = languages.begin();
209 cit != languages.end(); ++cit) {
210 combo_language->addto((*cit).second.lang());
213 fl_addto_choice(language_->choice_quotes_language,
214 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
215 " «text» | »text« "));
217 bc().addReadOnly (language_->choice_inputenc);
219 // the document options form
220 options_.reset(build_doc_options());
221 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
222 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
223 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
224 fl_set_counter_step(options_->slider_secnumdepth,1,1);
225 fl_set_counter_step(options_->slider_tocdepth,1,1);
226 fl_set_counter_precision(options_->slider_secnumdepth, 0);
227 fl_set_counter_precision(options_->slider_tocdepth, 0);
228 for (n=0; tex_graphics[n][0]; ++n) {
229 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
232 bc().addReadOnly (options_->slider_secnumdepth);
233 bc().addReadOnly (options_->slider_tocdepth);
234 bc().addReadOnly (options_->check_use_amsmath);
235 bc().addReadOnly (options_->input_float_placement);
236 bc().addReadOnly (options_->choice_postscript_driver);
238 // the document bullets form
239 bullets_.reset(build_doc_bullet());
240 fl_addto_choice(bullets_->choice_bullet_size,
241 _(" default | tiny | script | footnote | small |"
242 " normal | large | Large | LARGE | huge | Huge"));
243 fl_set_choice(bullets_->choice_bullet_size, 1);
244 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
245 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
247 bc().addReadOnly (bullets_->bmtable_bullet_panel);
248 bc().addReadOnly (bullets_->choice_bullet_size);
249 bc().addReadOnly (bullets_->input_bullet_latex);
251 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
253 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
255 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
257 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
259 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
261 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
262 lyxerr << _("Your version of libXpm is older than 4.7.\n"
263 "The `bullet' tab of the document popup "
264 "has been disabled") << '\n';
265 fl_deactivate_object(fbullet);
266 fl_set_object_lcol(fbullet, FL_INACTIVE);
271 void FormDocument::apply()
273 if (!lv_->view()->available() || !dialog_.get())
276 bool redo = class_apply();
278 redo = language_apply() || redo;
279 redo = options_apply() || redo;
283 lv_->view()->redoCurrentBuffer();
285 lv_->buffer()->markDirty();
286 setMinibuffer(lv_, _("Document layout set"));
290 void FormDocument::cancel()
292 // this avoids confusion when reopening
293 BufferParams & param = lv_->buffer()->params;
294 param.temp_bullets[0] = param.user_defined_bullets[0];
295 param.temp_bullets[1] = param.user_defined_bullets[1];
296 param.temp_bullets[2] = param.user_defined_bullets[2];
297 param.temp_bullets[3] = param.user_defined_bullets[3];
302 void FormDocument::update()
309 BufferParams const & params = lv_->buffer()->params;
311 class_update(params);
312 paper_update(params);
313 language_update(params);
314 options_update(params);
315 bullets_update(params);
319 bool FormDocument::input( FL_OBJECT * ob, long data )
321 State cb = static_cast<State>( data );
324 case CHECKCHOICECLASS:
325 CheckChoiceClass(ob, 0);
327 case CHOICEBULLETSIZE:
328 ChoiceBulletSize(ob, 0);
330 case INPUTBULLETLATEX:
331 InputBulletLaTeX(ob, 0);
348 BulletBMTable(ob, 0);
356 case CHECKCHOICECLASS:
357 case CHOICEBULLETSIZE:
358 case INPUTBULLETLATEX:
360 return CheckDocumentInput(ob, 0);
369 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
371 FormDocument * pre = static_cast<FormDocument*>(v);
372 if (combox == pre->combo_doc_class.get())
373 pre->CheckChoiceClass(0, 0);
374 pre->bc().valid(pre->CheckDocumentInput(0,0));
378 bool FormDocument::class_apply()
381 BufferParams ¶ms = lv_->buffer()->params;
383 // If default skip is a "Length" but there's no text in the
384 // input field, reset the kind to "Medskip", which is the default.
385 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
386 !*(fl_get_input (class_->input_doc_skip))) {
387 fl_set_choice (class_->choice_doc_skip, 2);
389 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
390 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
391 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
393 #ifdef USE_CLASS_COMBO
394 unsigned int const new_class = combo_doc_class->get() - 1;
396 unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
399 if (params.textclass != new_class) {
400 // try to load new_class
401 if (textclasslist.Load(new_class)) {
402 // successfully loaded
404 setMinibuffer(lv_, _("Converting document to new document class..."));
406 int ret = cap.SwitchLayoutsBetweenClasses(
407 params.textclass, new_class,
408 lv_->buffer()->paragraph);
412 s = _("One paragraph couldn't be converted");
415 s += _(" paragraphs couldn't be converted");
417 WriteAlert(_("Conversion Errors!"),s,
418 _("into chosen document class"));
421 params.textclass = new_class;
423 // problem changing class -- warn user and retain old style
424 WriteAlert(_("Conversion Errors!"),
425 _("Errors loading new document class."),
426 _("Reverting to original document class."));
427 #ifdef USE_CLASS_COMBO
428 combo_doc_class->select(int(params.textclass) + 1);
430 fl_set_choice(class_->choice_doc_class,
431 params.textclass + 1);
435 BufferParams::PARSEP tmpsep = params.paragraph_separation;
436 if (fl_get_button(class_->radio_doc_indent))
437 params.paragraph_separation = BufferParams::PARSEP_INDENT;
439 params.paragraph_separation = BufferParams::PARSEP_SKIP;
440 if (tmpsep != params.paragraph_separation)
443 VSpace tmpdefskip = params.getDefSkip();
444 switch (fl_get_choice (class_->choice_doc_skip)) {
446 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
449 params.setDefSkip(VSpace(VSpace::MEDSKIP));
452 params.setDefSkip(VSpace(VSpace::BIGSKIP));
456 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
458 // DocumentDefskipCB assures that this never happens
460 params.setDefSkip(VSpace(VSpace::MEDSKIP));
463 if (!(tmpdefskip == params.getDefSkip()))
466 if (fl_get_button(class_->radio_doc_columns_two))
470 if (fl_get_button(class_->radio_doc_sides_two))
471 params.sides = LyXTextClass::TwoSides;
473 params.sides = LyXTextClass::OneSide;
475 Spacing tmpSpacing = params.spacing;
476 switch (fl_get_choice(class_->choice_doc_spacing)) {
478 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
479 params.spacing.set(Spacing::Single);
482 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
483 params.spacing.set(Spacing::Onehalf);
486 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
487 params.spacing.set(Spacing::Double);
490 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
491 params.spacing.set(Spacing::Other,
492 fl_get_input(class_->input_doc_spacing));
495 if (tmpSpacing != params.spacing)
498 params.options = fl_get_input(class_->input_doc_extra);
504 void FormDocument::paper_apply()
506 BufferParams & params = lv_->buffer()->params;
509 static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
510 params.paperpackage =
511 static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
512 params.use_geometry = fl_get_button(paper_->push_use_geometry);
513 if (fl_get_button(paper_->radio_landscape))
514 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
516 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
517 params.paperwidth = fl_get_input(paper_->input_custom_width);
518 params.paperheight = fl_get_input(paper_->input_custom_height);
519 params.leftmargin = fl_get_input(paper_->input_left_margin);
520 params.topmargin = fl_get_input(paper_->input_top_margin);
521 params.rightmargin = fl_get_input(paper_->input_right_margin);
522 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
523 params.headheight = fl_get_input(paper_->input_head_height);
524 params.headsep = fl_get_input(paper_->input_head_sep);
525 params.footskip = fl_get_input(paper_->input_foot_skip);
526 lv_->buffer()->setPaperStuff();
530 bool FormDocument::language_apply()
532 BufferParams & params = lv_->buffer()->params;
533 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
536 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
538 lga = InsetQuotes::EnglishQ;
541 lga = InsetQuotes::SwedishQ;
544 lga = InsetQuotes::GermanQ;
547 lga = InsetQuotes::PolishQ;
550 lga = InsetQuotes::FrenchQ;
553 lga = InsetQuotes::DanishQ;
556 params.quotes_language = lga;
557 if (fl_get_button(language_->radio_single))
558 params.quotes_times = InsetQuotes::SingleQ;
560 params.quotes_times = InsetQuotes::DoubleQ;
562 Language const * old_language = params.language;
563 Language const * new_language =
564 languages.getLanguage(combo_language->getline());
566 new_language = default_language;
568 if (old_language != new_language
569 && old_language->RightToLeft() == new_language->RightToLeft()
570 && !lv_->buffer()->isMultiLingual())
571 lv_->buffer()->ChangeLanguage(old_language, new_language);
572 if (old_language != new_language) {
575 params.language = new_language;
576 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
582 bool FormDocument::options_apply()
584 BufferParams & params = lv_->buffer()->params;
587 params.graphicsDriver =
588 fl_get_choice_text(options_->choice_postscript_driver);
589 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
591 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
592 if (params.secnumdepth != tmpchar)
594 params.secnumdepth = tmpchar;
596 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
598 params.float_placement =
599 fl_get_input(options_->input_float_placement);
605 void FormDocument::bullets_apply()
607 /* update the bullet settings */
608 BufferParams & param = lv_->buffer()->params;
610 // a little bit of loop unrolling
611 param.user_defined_bullets[0] = param.temp_bullets[0];
612 param.user_defined_bullets[1] = param.temp_bullets[1];
613 param.user_defined_bullets[2] = param.temp_bullets[2];
614 param.user_defined_bullets[3] = param.temp_bullets[3];
618 void FormDocument::class_update(BufferParams const & params)
623 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
625 #ifdef USE_CLASS_COMBO
626 combo_doc_class->select_text(
627 textclasslist.DescOfClass(params.textclass));
629 fl_set_choice_text(class_->choice_doc_class,
630 textclasslist.DescOfClass(params.textclass).c_str());
632 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
633 fl_clear_choice(class_->choice_doc_fontsize);
634 fl_addto_choice(class_->choice_doc_fontsize, "default");
635 fl_addto_choice(class_->choice_doc_fontsize,
636 tclass.opt_fontsize().c_str());
637 fl_set_choice(class_->choice_doc_fontsize,
638 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
639 fl_clear_choice(class_->choice_doc_pagestyle);
640 fl_addto_choice(class_->choice_doc_pagestyle, "default");
641 fl_addto_choice(class_->choice_doc_pagestyle,
642 tclass.opt_pagestyle().c_str());
643 fl_set_choice(class_->choice_doc_pagestyle,
644 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
645 fl_set_button(class_->radio_doc_indent, 0);
646 fl_set_button(class_->radio_doc_skip, 0);
647 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
648 fl_set_button(class_->radio_doc_indent, 1);
650 fl_set_button(class_->radio_doc_skip, 1);
651 switch (params.getDefSkip().kind()) {
652 case VSpace::SMALLSKIP:
653 fl_set_choice (class_->choice_doc_skip, 1);
655 case VSpace::MEDSKIP:
656 fl_set_choice (class_->choice_doc_skip, 2);
658 case VSpace::BIGSKIP:
659 fl_set_choice (class_->choice_doc_skip, 3);
662 fl_set_choice (class_->choice_doc_skip, 4);
663 fl_set_input (class_->input_doc_skip,
664 params.getDefSkip().asLyXCommand().c_str());
667 fl_set_choice (class_->choice_doc_skip, 2);
670 fl_set_button(class_->radio_doc_sides_one, 0);
671 fl_set_button(class_->radio_doc_sides_two, 0);
672 if (params.sides == LyXTextClass::TwoSides)
673 fl_set_button(class_->radio_doc_sides_two, 1);
675 fl_set_button(class_->radio_doc_sides_one, 1);
676 fl_set_button(class_->radio_doc_columns_one, 0);
677 fl_set_button(class_->radio_doc_columns_two, 0);
678 if (params.columns == 2)
679 fl_set_button(class_->radio_doc_columns_two, 1);
681 fl_set_button(class_->radio_doc_columns_one, 1);
682 fl_set_input(class_->input_doc_spacing, "");
683 switch (params.spacing.getSpace()) {
684 case Spacing::Default: // nothing bad should happen with this
685 case Spacing::Single:
687 fl_set_choice(class_->choice_doc_spacing, 1);
689 case Spacing::Onehalf:
691 fl_set_choice(class_->choice_doc_spacing, 2);
693 case Spacing::Double:
695 fl_set_choice(class_->choice_doc_spacing, 3);
699 fl_set_choice(class_->choice_doc_spacing, 4);
701 sprintf(sval,"%g",params.spacing.getValue());
702 fl_set_input(class_->input_doc_spacing, sval);
706 if (!params.options.empty())
707 fl_set_input(class_->input_doc_extra, params.options.c_str());
709 fl_set_input(class_->input_doc_extra, "");
713 void FormDocument::language_update(BufferParams const & params)
715 if (!language_.get())
718 combo_language->select_text(params.language->lang());
719 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
720 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
721 fl_set_button(language_->radio_single, 0);
722 fl_set_button(language_->radio_double, 0);
723 if (params.quotes_times == InsetQuotes::SingleQ)
724 fl_set_button(language_->radio_single, 1);
726 fl_set_button(language_->radio_double, 1);
730 void FormDocument::options_update(BufferParams const & params)
735 fl_set_choice_text(options_->choice_postscript_driver,
736 params.graphicsDriver.c_str());
737 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
738 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
739 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
740 if (!params.float_placement.empty())
741 fl_set_input(options_->input_float_placement,
742 params.float_placement.c_str());
744 fl_set_input(options_->input_float_placement, "");
748 void FormDocument::paper_update(BufferParams const & params)
753 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
754 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
755 fl_set_button(paper_->push_use_geometry, params.use_geometry);
756 fl_set_button(paper_->radio_portrait, 0);
757 fl_set_button(paper_->radio_landscape, 0);
758 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
759 fl_set_button(paper_->radio_landscape, 1);
761 fl_set_button(paper_->radio_portrait, 1);
762 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
763 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
764 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
765 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
766 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
767 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
768 fl_set_input(paper_->input_head_height, params.headheight.c_str());
769 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
770 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
771 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
775 void FormDocument::bullets_update(BufferParams const & params)
777 if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
780 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
781 setEnabled(fbullet, !isLinuxDoc);
783 if (isLinuxDoc) return;
785 fl_set_button(bullets_->radio_bullet_depth_1, 1);
786 fl_set_input(bullets_->input_bullet_latex,
787 params.user_defined_bullets[0].getText().c_str());
788 fl_set_choice(bullets_->choice_bullet_size,
789 params.user_defined_bullets[0].getSize() + 2);
793 void FormDocument::checkReadOnly()
795 if (bc().readOnly(lv_->buffer()->isReadonly())) {
796 combo_doc_class->deactivate();
797 combo_language->deactivate();
798 fl_set_object_label(dialog_->text_warning,
799 _("Document is read-only."
800 " No changes to layout permitted."));
801 fl_show_object(dialog_->text_warning);
803 combo_doc_class->activate();
804 combo_language->activate();
805 fl_hide_object(dialog_->text_warning);
810 void FormDocument::checkMarginValues()
812 bool const not_empty =
813 strlen(fl_get_input(paper_->input_top_margin)) ||
814 strlen(fl_get_input(paper_->input_bottom_margin)) ||
815 strlen(fl_get_input(paper_->input_left_margin)) ||
816 strlen(fl_get_input(paper_->input_right_margin)) ||
817 strlen(fl_get_input(paper_->input_head_height)) ||
818 strlen(fl_get_input(paper_->input_head_sep)) ||
819 strlen(fl_get_input(paper_->input_foot_skip)) ||
820 strlen(fl_get_input(paper_->input_custom_width)) ||
821 strlen(fl_get_input(paper_->input_custom_height));
823 fl_set_button(paper_->push_use_geometry, 1);
827 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
835 if (ob == paper_->choice_papersize2) {
836 val = fl_get_choice(paper_->choice_papersize2)-1;
837 if (val == BufferParams::VM_PAPER_DEFAULT) {
838 fl_set_button(paper_->push_use_geometry, 0);
841 if ((val != BufferParams::VM_PAPER_USLETTER) &&
842 (val != BufferParams::VM_PAPER_USLEGAL) &&
843 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
844 (val != BufferParams::VM_PAPER_A4) &&
845 (val != BufferParams::VM_PAPER_A5) &&
846 (val != BufferParams::VM_PAPER_B5)) {
847 fl_set_button(paper_->push_use_geometry, 1);
849 fl_set_choice(paper_->choice_paperpackage,
850 BufferParams::PACKAGE_NONE + 1);
852 } else if (ob == paper_->choice_paperpackage) {
853 val = fl_get_choice(paper_->choice_paperpackage)-1;
854 if (val != BufferParams::PACKAGE_NONE) {
855 fl_set_choice(paper_->choice_papersize2,
856 BufferParams::VM_PAPER_DEFAULT + 1);
857 fl_set_button(paper_->push_use_geometry, 0);
859 } else if (ob == class_->input_doc_spacing) {
860 input = fl_get_input(class_->input_doc_spacing);
862 fl_set_choice (class_->choice_doc_spacing, 1);
864 fl_set_choice(class_->choice_doc_spacing, 4);
867 // this has to be all out of if/elseif because it has to deactivate
868 // the document buttons and so the whole stuff has to be tested again.
869 str = fl_get_input(paper_->input_custom_width);
870 ok = ok && (str.empty() || isValidLength(str));
871 str = fl_get_input(paper_->input_custom_height);
872 ok = ok && (str.empty() || isValidLength(str));
873 str = fl_get_input(paper_->input_left_margin);
874 ok = ok && (str.empty() || isValidLength(str));
875 str = fl_get_input(paper_->input_right_margin);
876 ok = ok && (str.empty() || isValidLength(str));
877 str = fl_get_input(paper_->input_top_margin);
878 ok = ok && (str.empty() || isValidLength(str));
879 str = fl_get_input(paper_->input_bottom_margin);
880 ok = ok && (str.empty() || isValidLength(str));
881 str = fl_get_input(paper_->input_head_height);
882 ok = ok && (str.empty() || isValidLength(str));
883 str = fl_get_input(paper_->input_head_sep);
884 ok = ok && (str.empty() || isValidLength(str));
885 str = fl_get_input(paper_->input_foot_skip);
886 ok = ok && (str.empty() || isValidLength(str));
887 // "Synchronize" the choice and the input field, so that it
888 // is impossible to commit senseless data.
889 input = fl_get_input (class_->input_doc_skip);
890 if (ob == class_->input_doc_skip) {
892 fl_set_choice (class_->choice_doc_skip, 2);
893 } else if (isValidGlueLength (input)) {
894 fl_set_choice (class_->choice_doc_skip, 4);
896 fl_set_choice(class_->choice_doc_skip, 4);
900 if (*input && !isValidGlueLength(input))
903 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
905 else if (fl_get_choice(class_->choice_doc_skip) != 4)
906 fl_set_input (class_->input_doc_skip, "");
908 input = fl_get_input(class_->input_doc_spacing);
909 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
911 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
912 fl_set_input (class_->input_doc_spacing, "");
917 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
919 BufferParams & param = lv_->buffer()->params;
921 // convert from 1-6 range to -1-4
922 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
923 fl_set_input(bullets_->input_bullet_latex,
924 param.temp_bullets[current_bullet_depth].getText().c_str());
928 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
930 BufferParams & param = lv_->buffer()->params;
932 param.temp_bullets[current_bullet_depth].
933 setText(fl_get_input(bullets_->input_bullet_latex));
937 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
939 /* Should I do the following: */
940 /* 1. change to the panel that the current bullet belongs in */
941 /* 2. show that bullet as selected */
942 /* 3. change the size setting to the size of the bullet in Q.*/
943 /* 4. display the latex equivalent in the latex box */
945 /* I'm inclined to just go with 3 and 4 at the moment and */
946 /* maybe try to support the others later */
947 BufferParams & param = lv_->buffer()->params;
950 if (cb == BULLETDEPTH1 )
952 else if (cb == BULLETDEPTH2 )
954 else if (cb == BULLETDEPTH3 )
956 else if (cb == BULLETDEPTH4 )
959 switch (fl_get_button_numb(ob)) {
961 // right mouse button resets to default
962 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
964 current_bullet_depth = data;
965 fl_set_input(bullets_->input_bullet_latex,
966 param.temp_bullets[data].getText().c_str());
967 fl_set_choice(bullets_->choice_bullet_size,
968 param.temp_bullets[data].getSize() + 2);
973 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
975 /* Here we have to change the background pixmap to that selected */
976 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
979 if (cb == BULLETPANEL1 )
981 else if (cb == BULLETPANEL2 )
983 else if (cb == BULLETPANEL3 )
985 else if (cb == BULLETPANEL4 )
987 else if (cb == BULLETPANEL5 )
989 else if (cb == BULLETPANEL6 )
992 if (data != current_bullet_panel) {
993 fl_freeze_form(bullets_->form);
994 current_bullet_panel = data;
996 /* free the current pixmap */
997 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1000 /* display the new one */
1002 new_panel = "standard";
1005 new_panel = "amssymb";
1008 new_panel = "psnfss1";
1011 new_panel = "psnfss2";
1014 new_panel = "psnfss3";
1017 new_panel = "psnfss4";
1020 /* something very wrong happened */
1021 // play it safe for now but should be an exception
1022 current_bullet_panel = 0; // standard panel
1023 new_panel = "standard";
1026 new_panel += ".xpm";
1027 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1028 LibFileSearch("images", new_panel).c_str());
1029 fl_redraw_object(bullets_->bmtable_bullet_panel);
1030 fl_unfreeze_form(bullets_->form);
1035 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1037 /* handle the user input by setting the current bullet depth's pixmap */
1038 /* to that extracted from the current chosen position of the BMTable */
1039 /* Don't forget to free the button's old pixmap first. */
1041 BufferParams & param = lv_->buffer()->params;
1042 int bmtable_button = fl_get_bmtable(ob);
1044 /* try to keep the button held down till another is pushed */
1045 /* fl_set_bmtable(ob, 1, bmtable_button); */
1046 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1047 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1048 fl_set_input(bullets_->input_bullet_latex,
1049 param.temp_bullets[current_bullet_depth].getText().c_str());
1053 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1056 ob = class_->choice_doc_class;
1058 ProhibitInput(lv_->view());
1060 #ifdef USE_CLASS_COMBO
1061 unsigned int tc = combo_doc_class->get() - 1;
1062 string tct = combo_doc_class->getline();
1064 int tc = fl_get_choice(ob) - 1;
1065 string tct = fl_get_choice_text(ob);
1067 if (textclasslist.Load(tc)) {
1068 // we use a copy of the bufferparams because we do not
1069 // want to modify them yet.
1070 BufferParams params = lv_->buffer()->params;
1072 if (params.textclass != tc
1073 && AskQuestion(_("Should I set some parameters to"),
1074 _("the defaults of this document class?"))) {
1075 params.textclass = tc;
1076 params.useClassDefaults();
1077 UpdateLayoutDocument(params);
1080 // unable to load new style
1081 WriteAlert(_("Conversion Errors!"),
1082 _("Unable to switch to new document class."),
1083 _("Reverting to original document class."));
1084 #ifdef USE_CLASS_COMBO
1085 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1087 fl_set_choice(class_->choice_doc_class,
1088 lv_->buffer()->params.textclass + 1);
1091 AllowInput(lv_->view());
1095 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1101 class_update(params);
1102 paper_update(params);
1103 language_update(params);
1104 options_update(params);
1105 bullets_update(params);