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"
19 #include FORMS_H_LOCATION
20 #include XPM_H_LOCATION
22 #include "FormDocument.h"
23 #include "form_document.h"
27 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "insets/insetquotes.h"
32 #include "support/filetools.h"
35 #include "BufferView.h"
38 #include "CutAndPaste.h"
39 #include "bufferview_funcs.h"
41 #ifdef CXX_WORKING_NAMESPACES
42 using Liason::setMinibuffer;
45 #define USE_CLASS_COMBO 1
47 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
48 : FormBase(lv, d, _("Document Layout"), BUFFER_DEPENDENT, UPDATE,
49 new NoRepeatedApplyReadOnlyPolicy),
50 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
51 bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
52 fbullet(0), combo_language(0), combo_doc_class(0)
54 // let the popup be shown
55 // This is a permanent connection so we won't bother
56 // storing a copy because we won't be disconnecting.
57 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
61 FormDocument::~FormDocument()
63 #ifdef USE_CLASS_COMBO
64 delete combo_doc_class;
68 delete combo_language;
76 FL_FORM * FormDocument::form() const
78 if (dialog_) return dialog_->form;
83 void FormDocument::build()
88 dialog_ = build_tabbed_document();
90 // manage the restore, ok, apply and cancel/close buttons
91 bc_.setOK(dialog_->button_ok);
92 bc_.setApply(dialog_->button_apply);
93 bc_.setCancel(dialog_->button_cancel);
94 bc_.setUndoAll(dialog_->button_restore);
97 // the document paper form
98 paper_ = build_doc_paper();
99 fl_addto_choice(paper_->choice_papersize2,
100 _(" Default | Custom | USletter | USlegal "
101 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
102 fl_addto_choice(paper_->choice_paperpackage,
104 "| A4 small Margins (only portrait) "
105 "| A4 very small Margins (only portrait) "
106 "| A4 very wide margins (only portrait) "));
107 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
108 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
109 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
110 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
111 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
112 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
113 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
114 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
115 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
117 bc_.addReadOnly (paper_->choice_paperpackage);
118 bc_.addReadOnly (paper_->greoup_radio_orientation);
119 bc_.addReadOnly (paper_->radio_portrait);
120 bc_.addReadOnly (paper_->radio_landscape);
121 bc_.addReadOnly (paper_->choice_papersize2);
122 bc_.addReadOnly (paper_->push_use_geometry);
123 bc_.addReadOnly (paper_->input_custom_width);
124 bc_.addReadOnly (paper_->input_custom_height);
125 bc_.addReadOnly (paper_->input_top_margin);
126 bc_.addReadOnly (paper_->input_bottom_margin);
127 bc_.addReadOnly (paper_->input_left_margin);
128 bc_.addReadOnly (paper_->input_right_margin);
129 bc_.addReadOnly (paper_->input_head_height);
130 bc_.addReadOnly (paper_->input_head_sep);
131 bc_.addReadOnly (paper_->input_foot_skip);
133 // the document class form
134 class_ = build_doc_class();
137 #ifdef USE_CLASS_COMBO
138 // The language is a combo-box and has to be inserted manually
139 obj = class_->choice_doc_class;
140 fl_addto_form(class_->form);
141 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
142 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400);
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_skip, FL_RETURN_ALWAYS);
170 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
172 bc_.addReadOnly (class_->radio_doc_indent);
173 bc_.addReadOnly (class_->radio_doc_skip);
174 #ifndef USE_CLASS_COMBO
175 bc_.addReadOnly (class_->choice_doc_class);
177 bc_.addReadOnly (class_->choice_doc_pagestyle);
178 bc_.addReadOnly (class_->choice_doc_fonts);
179 bc_.addReadOnly (class_->choice_doc_fontsize);
180 bc_.addReadOnly (class_->radio_doc_sides_one);
181 bc_.addReadOnly (class_->radio_doc_sides_two);
182 bc_.addReadOnly (class_->radio_doc_columns_one);
183 bc_.addReadOnly (class_->radio_doc_columns_two);
184 bc_.addReadOnly (class_->input_doc_extra);
185 bc_.addReadOnly (class_->input_doc_skip);
186 bc_.addReadOnly (class_->choice_doc_skip);
187 bc_.addReadOnly (class_->choice_doc_spacing);
188 bc_.addReadOnly (class_->input_doc_spacing);
190 // the document language form
191 language_ = build_doc_language();
192 fl_addto_choice(language_->choice_inputenc,
193 "default|auto|latin1|latin2|latin5"
194 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
196 // The language is a combo-box and has to be inserted manually
197 obj = language_->choice_language;
198 fl_addto_form(language_->form);
199 combo_language = new Combox(FL_COMBOX_DROPLIST);
200 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400);
201 combo_language->shortcut("#L",1);
202 combo_language->setcallback(ComboInputCB, this);
204 // "default" is not part of the languages array any more.
205 #ifdef DO_USE_DEFAULT_LANGUAGE
206 combo_language->addto("default");
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_language);
218 bc_.addReadOnly (language_->choice_inputenc);
220 // the document options form
221 options_ = build_doc_options();
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_ = 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_)
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)
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;
398 if (params.textclass != new_class) {
399 // try to load new_class
400 if (textclasslist.Load(new_class)) {
401 // successfully loaded
403 setMinibuffer(lv_, _("Converting document to new document class..."));
405 int ret = cap.SwitchLayoutsBetweenClasses(
406 params.textclass, new_class,
407 lv_->buffer()->paragraph);
411 s = _("One paragraph couldn't be converted");
414 s += _(" paragraphs couldn't be converted");
416 WriteAlert(_("Conversion Errors!"),s,
417 _("into chosen document class"));
420 params.textclass = new_class;
422 // problem changing class -- warn user and retain old style
423 WriteAlert(_("Conversion Errors!"),
424 _("Errors loading new document class."),
425 _("Reverting to original document class."));
426 #ifdef USE_CLASS_COMBO
427 combo_doc_class->select(params.textclass + 1);
429 fl_set_choice(class_->choice_doc_class,
430 params.textclass + 1);
434 char tmpsep = params.paragraph_separation;
435 if (fl_get_button(class_->radio_doc_indent))
436 params.paragraph_separation = BufferParams::PARSEP_INDENT;
438 params.paragraph_separation = BufferParams::PARSEP_SKIP;
439 if (tmpsep != params.paragraph_separation)
442 VSpace tmpdefskip = params.getDefSkip();
443 switch (fl_get_choice (class_->choice_doc_skip)) {
445 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
448 params.setDefSkip(VSpace(VSpace::MEDSKIP));
451 params.setDefSkip(VSpace(VSpace::BIGSKIP));
455 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
457 // DocumentDefskipCB assures that this never happens
459 params.setDefSkip(VSpace(VSpace::MEDSKIP));
462 if (!(tmpdefskip == params.getDefSkip()))
465 if (fl_get_button(class_->radio_doc_columns_two))
469 if (fl_get_button(class_->radio_doc_sides_two))
470 params.sides = LyXTextClass::TwoSides;
472 params.sides = LyXTextClass::OneSide;
474 Spacing tmpSpacing = params.spacing;
475 switch(fl_get_choice(class_->choice_doc_spacing)) {
477 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
478 params.spacing.set(Spacing::Single);
481 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
482 params.spacing.set(Spacing::Onehalf);
485 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
486 params.spacing.set(Spacing::Double);
489 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
490 params.spacing.set(Spacing::Other,
491 fl_get_input(class_->input_doc_spacing));
494 if (tmpSpacing != params.spacing)
497 params.options = fl_get_input(class_->input_doc_extra);
503 void FormDocument::paper_apply()
505 BufferParams & params = lv_->buffer()->params;
507 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
508 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
509 params.use_geometry = fl_get_button(paper_->push_use_geometry);
510 if (fl_get_button(paper_->radio_landscape))
511 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
513 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
514 params.paperwidth = fl_get_input(paper_->input_custom_width);
515 params.paperheight = fl_get_input(paper_->input_custom_height);
516 params.leftmargin = fl_get_input(paper_->input_left_margin);
517 params.topmargin = fl_get_input(paper_->input_top_margin);
518 params.rightmargin = fl_get_input(paper_->input_right_margin);
519 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
520 params.headheight = fl_get_input(paper_->input_head_height);
521 params.headsep = fl_get_input(paper_->input_head_sep);
522 params.footskip = fl_get_input(paper_->input_foot_skip);
523 lv_->buffer()->setPaperStuff();
527 bool FormDocument::language_apply()
529 BufferParams & params = lv_->buffer()->params;
530 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
533 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
535 lga = InsetQuotes::EnglishQ;
538 lga = InsetQuotes::SwedishQ;
541 lga = InsetQuotes::GermanQ;
544 lga = InsetQuotes::PolishQ;
547 lga = InsetQuotes::FrenchQ;
550 lga = InsetQuotes::DanishQ;
553 params.quotes_language = lga;
554 if (fl_get_button(language_->radio_single))
555 params.quotes_times = InsetQuotes::SingleQ;
557 params.quotes_times = InsetQuotes::DoubleQ;
559 Language const * old_language = params.language;
560 Language const * new_language =
561 languages.getLanguage(combo_language->getline());
563 new_language = default_language;
565 if (old_language != new_language
566 && old_language->RightToLeft() == new_language->RightToLeft()
567 && !lv_->buffer()->isMultiLingual())
568 lv_->buffer()->ChangeLanguage(old_language, new_language);
569 if (old_language != new_language) {
572 params.language = new_language;
573 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
579 bool FormDocument::options_apply()
581 BufferParams & params = lv_->buffer()->params;
584 params.graphicsDriver =
585 fl_get_choice_text(options_->choice_postscript_driver);
586 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
588 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
589 if (params.secnumdepth != tmpchar)
591 params.secnumdepth = tmpchar;
593 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
595 params.float_placement =
596 fl_get_input(options_->input_float_placement);
602 void FormDocument::bullets_apply()
604 /* update the bullet settings */
605 BufferParams & param = lv_->buffer()->params;
607 // a little bit of loop unrolling
608 param.user_defined_bullets[0] = param.temp_bullets[0];
609 param.user_defined_bullets[1] = param.temp_bullets[1];
610 param.user_defined_bullets[2] = param.temp_bullets[2];
611 param.user_defined_bullets[3] = param.temp_bullets[3];
615 void FormDocument::class_update(BufferParams const & params)
620 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
622 #ifdef USE_CLASS_COMBO
623 combo_doc_class->select_text(
624 textclasslist.DescOfClass(params.textclass));
626 fl_set_choice_text(class_->choice_doc_class,
627 textclasslist.DescOfClass(params.textclass).c_str());
629 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
630 fl_clear_choice(class_->choice_doc_fontsize);
631 fl_addto_choice(class_->choice_doc_fontsize, "default");
632 fl_addto_choice(class_->choice_doc_fontsize,
633 tclass.opt_fontsize().c_str());
634 fl_set_choice(class_->choice_doc_fontsize,
635 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
636 fl_clear_choice(class_->choice_doc_pagestyle);
637 fl_addto_choice(class_->choice_doc_pagestyle, "default");
638 fl_addto_choice(class_->choice_doc_pagestyle,
639 tclass.opt_pagestyle().c_str());
640 fl_set_choice(class_->choice_doc_pagestyle,
641 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
642 fl_set_button(class_->radio_doc_indent, 0);
643 fl_set_button(class_->radio_doc_skip, 0);
644 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
645 fl_set_button(class_->radio_doc_indent, 1);
647 fl_set_button(class_->radio_doc_skip, 1);
648 switch (params.getDefSkip().kind()) {
649 case VSpace::SMALLSKIP:
650 fl_set_choice (class_->choice_doc_skip, 1);
652 case VSpace::MEDSKIP:
653 fl_set_choice (class_->choice_doc_skip, 2);
655 case VSpace::BIGSKIP:
656 fl_set_choice (class_->choice_doc_skip, 3);
659 fl_set_choice (class_->choice_doc_skip, 4);
660 fl_set_input (class_->input_doc_skip,
661 params.getDefSkip().asLyXCommand().c_str());
664 fl_set_choice (class_->choice_doc_skip, 2);
667 fl_set_button(class_->radio_doc_sides_one, 0);
668 fl_set_button(class_->radio_doc_sides_two, 0);
669 if (params.sides == 2)
670 fl_set_button(class_->radio_doc_sides_two, 1);
672 fl_set_button(class_->radio_doc_sides_one, 1);
673 fl_set_button(class_->radio_doc_columns_one, 0);
674 fl_set_button(class_->radio_doc_columns_two, 0);
675 if (params.columns == 2)
676 fl_set_button(class_->radio_doc_columns_two, 1);
678 fl_set_button(class_->radio_doc_columns_one, 1);
679 fl_set_input(class_->input_doc_spacing, "");
680 switch (params.spacing.getSpace()) {
681 case Spacing::Default: // nothing bad should happen with this
682 case Spacing::Single:
684 fl_set_choice(class_->choice_doc_spacing, 1);
686 case Spacing::Onehalf:
688 fl_set_choice(class_->choice_doc_spacing, 2);
690 case Spacing::Double:
692 fl_set_choice(class_->choice_doc_spacing, 3);
696 fl_set_choice(class_->choice_doc_spacing, 4);
698 sprintf(sval,"%g",params.spacing.getValue());
699 fl_set_input(class_->input_doc_spacing, sval);
703 if (!params.options.empty())
704 fl_set_input(class_->input_doc_extra, params.options.c_str());
706 fl_set_input(class_->input_doc_extra, "");
710 void FormDocument::language_update(BufferParams const & params)
715 combo_language->select_text(params.language->lang());
716 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
717 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
718 fl_set_button(language_->radio_single, 0);
719 fl_set_button(language_->radio_double, 0);
720 if (params.quotes_times == InsetQuotes::SingleQ)
721 fl_set_button(language_->radio_single, 1);
723 fl_set_button(language_->radio_double, 1);
727 void FormDocument::options_update(BufferParams const & params)
732 fl_set_choice_text(options_->choice_postscript_driver,
733 params.graphicsDriver.c_str());
734 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
735 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
736 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
737 if (!params.float_placement.empty())
738 fl_set_input(options_->input_float_placement,
739 params.float_placement.c_str());
741 fl_set_input(options_->input_float_placement, "");
745 void FormDocument::paper_update(BufferParams const & params)
750 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
751 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
752 fl_set_button(paper_->push_use_geometry, params.use_geometry);
753 fl_set_button(paper_->radio_portrait, 0);
754 fl_set_button(paper_->radio_landscape, 0);
755 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
756 fl_set_button(paper_->radio_landscape, 1);
758 fl_set_button(paper_->radio_portrait, 1);
759 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
760 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
761 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
762 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
763 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
764 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
765 fl_set_input(paper_->input_head_height, params.headheight.c_str());
766 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
767 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
768 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
772 void FormDocument::bullets_update(BufferParams const & params)
774 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
777 if (lv_->buffer()->isLinuxDoc()) {
778 fl_deactivate_object(fbullet);
779 fl_set_object_lcol(fbullet, FL_INACTIVE);
782 fl_activate_object(fbullet);
783 fl_set_object_lcol(fbullet, FL_BLACK);
786 fl_set_button(bullets_->radio_bullet_depth_1, 1);
787 fl_set_input(bullets_->input_bullet_latex,
788 params.user_defined_bullets[0].getText().c_str());
789 fl_set_choice(bullets_->choice_bullet_size,
790 params.user_defined_bullets[0].getSize() + 2);
794 void FormDocument::checkReadOnly()
796 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
797 combo_doc_class->deactivate();
798 combo_language->deactivate();
799 fl_set_object_label(dialog_->text_warning,
800 _("Document is read-only."
801 " No changes to layout permitted."));
802 fl_show_object(dialog_->text_warning);
804 combo_doc_class->activate();
805 combo_language->activate();
806 fl_hide_object(dialog_->text_warning);
811 void FormDocument::checkMarginValues()
813 int const allEmpty = (!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);
826 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
834 if (ob == paper_->choice_papersize2) {
835 val = fl_get_choice(paper_->choice_papersize2)-1;
836 if (val == BufferParams::VM_PAPER_DEFAULT) {
837 fl_set_button(paper_->push_use_geometry, 0);
840 if ((val != BufferParams::VM_PAPER_USLETTER) &&
841 (val != BufferParams::VM_PAPER_USLEGAL) &&
842 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
843 (val != BufferParams::VM_PAPER_A4) &&
844 (val != BufferParams::VM_PAPER_A5) &&
845 (val != BufferParams::VM_PAPER_B5)) {
846 fl_set_button(paper_->push_use_geometry, 1);
848 fl_set_choice(paper_->choice_paperpackage,
849 BufferParams::PACKAGE_NONE + 1);
851 } else if (ob == paper_->choice_paperpackage) {
852 val = fl_get_choice(paper_->choice_paperpackage)-1;
853 if (val != BufferParams::PACKAGE_NONE) {
854 fl_set_choice(paper_->choice_papersize2,
855 BufferParams::VM_PAPER_DEFAULT + 1);
856 fl_set_button(paper_->push_use_geometry, 0);
858 } else if (ob == class_->input_doc_spacing) {
859 input = fl_get_input(class_->input_doc_spacing);
861 fl_set_choice (class_->choice_doc_spacing, 1);
863 fl_set_choice(class_->choice_doc_spacing, 4);
866 // this has to be all out of if/elseif because it has to deactivate
867 // the document buttons and so the whole stuff has to be tested again.
868 str = fl_get_input(paper_->input_custom_width);
869 ok = ok && (str.empty() || isValidLength(str));
870 str = fl_get_input(paper_->input_custom_height);
871 ok = ok && (str.empty() || isValidLength(str));
872 str = fl_get_input(paper_->input_left_margin);
873 ok = ok && (str.empty() || isValidLength(str));
874 str = fl_get_input(paper_->input_right_margin);
875 ok = ok && (str.empty() || isValidLength(str));
876 str = fl_get_input(paper_->input_top_margin);
877 ok = ok && (str.empty() || isValidLength(str));
878 str = fl_get_input(paper_->input_bottom_margin);
879 ok = ok && (str.empty() || isValidLength(str));
880 str = fl_get_input(paper_->input_head_height);
881 ok = ok && (str.empty() || isValidLength(str));
882 str = fl_get_input(paper_->input_head_sep);
883 ok = ok && (str.empty() || isValidLength(str));
884 str = fl_get_input(paper_->input_foot_skip);
885 ok = ok && (str.empty() || isValidLength(str));
886 // "Synchronize" the choice and the input field, so that it
887 // is impossible to commit senseless data.
888 input = fl_get_input (class_->input_doc_skip);
889 if (ob == class_->input_doc_skip) {
891 fl_set_choice (class_->choice_doc_skip, 2);
892 } else if (isValidGlueLength (input)) {
893 fl_set_choice (class_->choice_doc_skip, 4);
895 fl_set_choice(class_->choice_doc_skip, 4);
899 if (*input && !isValidGlueLength(input))
902 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
904 else if (fl_get_choice(class_->choice_doc_skip) != 4)
905 fl_set_input (class_->input_doc_skip, "");
907 input = fl_get_input(class_->input_doc_spacing);
908 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
910 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
911 fl_set_input (class_->input_doc_spacing, "");
916 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
918 BufferParams & param = lv_->buffer()->params;
920 // convert from 1-6 range to -1-4
921 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
922 fl_set_input(bullets_->input_bullet_latex,
923 param.temp_bullets[current_bullet_depth].getText().c_str());
927 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
929 BufferParams & param = lv_->buffer()->params;
931 param.temp_bullets[current_bullet_depth].
932 setText(fl_get_input(bullets_->input_bullet_latex));
936 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
938 /* Should I do the following: */
939 /* 1. change to the panel that the current bullet belongs in */
940 /* 2. show that bullet as selected */
941 /* 3. change the size setting to the size of the bullet in Q.*/
942 /* 4. display the latex equivalent in the latex box */
944 /* I'm inclined to just go with 3 and 4 at the moment and */
945 /* maybe try to support the others later */
946 BufferParams & param = lv_->buffer()->params;
949 if( cb == BULLETDEPTH1 )
951 else if ( cb == BULLETDEPTH2 )
953 else if ( cb == BULLETDEPTH3 )
955 else if ( cb == BULLETDEPTH4 )
958 switch (fl_get_button_numb(ob)) {
960 // right mouse button resets to default
961 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
963 current_bullet_depth = data;
964 fl_set_input(bullets_->input_bullet_latex,
965 param.temp_bullets[data].getText().c_str());
966 fl_set_choice(bullets_->choice_bullet_size,
967 param.temp_bullets[data].getSize() + 2);
972 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
974 /* Here we have to change the background pixmap to that selected */
975 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
978 if( cb == BULLETPANEL1 )
980 else if ( cb == BULLETPANEL2 )
982 else if ( cb == BULLETPANEL3 )
984 else if ( cb == BULLETPANEL4 )
986 else if ( cb == BULLETPANEL5 )
988 else if ( cb == BULLETPANEL6 )
991 if (data != current_bullet_panel) {
992 fl_freeze_form(bullets_->form);
993 current_bullet_panel = data;
995 /* free the current pixmap */
996 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
999 /* display the new one */
1001 new_panel = "standard";
1004 new_panel = "amssymb";
1007 new_panel = "psnfss1";
1010 new_panel = "psnfss2";
1013 new_panel = "psnfss3";
1016 new_panel = "psnfss4";
1019 /* something very wrong happened */
1020 // play it safe for now but should be an exception
1021 current_bullet_panel = 0; // standard panel
1022 new_panel = "standard";
1025 new_panel += ".xpm";
1026 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1027 LibFileSearch("images", new_panel).c_str());
1028 fl_redraw_object(bullets_->bmtable_bullet_panel);
1029 fl_unfreeze_form(bullets_->form);
1034 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1036 /* handle the user input by setting the current bullet depth's pixmap */
1037 /* to that extracted from the current chosen position of the BMTable */
1038 /* Don't forget to free the button's old pixmap first. */
1040 BufferParams & param = lv_->buffer()->params;
1041 int bmtable_button = fl_get_bmtable(ob);
1043 /* try to keep the button held down till another is pushed */
1044 /* fl_set_bmtable(ob, 1, bmtable_button); */
1045 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1046 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1047 fl_set_input(bullets_->input_bullet_latex,
1048 param.temp_bullets[current_bullet_depth].getText().c_str());
1052 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1055 ob = class_->choice_doc_class;
1057 ProhibitInput(lv_->view());
1059 #ifdef USE_CLASS_COMBO
1060 int tc = combo_doc_class->get() - 1;
1061 string tct = combo_doc_class->getline();
1063 int tc = fl_get_choice(ob) - 1;
1064 string tct = fl_get_choice_text(ob);
1066 if (textclasslist.Load(tc)) {
1067 if (AskQuestion(_("Should I set some parameters to"), tct,
1068 _("the defaults of this document class?"))) {
1069 BufferParams & params = lv_->buffer()->params;
1071 params.textclass = tc;
1072 params.useClassDefaults();
1073 UpdateLayoutDocument(params);
1076 // unable to load new style
1077 WriteAlert(_("Conversion Errors!"),
1078 _("Unable to switch to new document class."),
1079 _("Reverting to original document class."));
1080 #ifdef USE_CLASS_COMBO
1081 combo_doc_class->select(lv_->buffer()->params.textclass + 1);
1083 fl_set_choice(class_->choice_doc_class,
1084 lv_->buffer()->params.textclass + 1);
1087 AllowInput(lv_->view());
1091 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1097 class_update(params);
1098 paper_update(params);
1099 language_update(params);
1100 options_update(params);
1101 bullets_update(params);