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"
24 #include "xform_macros.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"
42 #ifdef SIGC_CXX_NAMESPACES
46 #ifdef CXX_WORKING_NAMESPACES
47 using Liason::setMinibuffer;
50 #define USE_CLASS_COMBO 1
52 C_GENERICCB(FormDocument, InputCB)
53 C_GENERICCB(FormDocument, ChoiceClassCB)
54 C_GENERICCB(FormDocument, BulletPanelCB)
55 C_GENERICCB(FormDocument, BulletDepthCB)
56 C_GENERICCB(FormDocument, InputBulletLaTeXCB)
57 C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
60 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
61 : FormBase(lv, d, BUFFER_DEPENDENT, _("Document Layout"),
62 new NoRepeatedApplyReadOnlyPolicy),
63 dialog_(0), paper_(0), class_(0), language_(0), options_(0),
64 bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
65 fbullet(0), combo_language(0), combo_doc_class(0)
67 // let the popup be shown
68 // This is a permanent connection so we won't bother
69 // storing a copy because we won't be disconnecting.
70 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
74 FormDocument::~FormDocument()
76 #ifdef USE_CLASS_COMBO
77 delete combo_doc_class;
81 delete combo_language;
89 FL_FORM * FormDocument::form() const
91 if (dialog_) return dialog_->form;
96 void FormDocument::build()
101 dialog_ = build_tabbed_document();
103 // manage the restore, ok, apply and cancel/close buttons
104 bc_.setOK(dialog_->button_ok);
105 bc_.setApply(dialog_->button_apply);
106 bc_.setCancel(dialog_->button_cancel);
107 bc_.setUndoAll(dialog_->button_restore);
110 // the document paper form
111 paper_ = build_doc_paper();
112 fl_addto_choice(paper_->choice_papersize2,
113 _(" Default | Custom | USletter | USlegal "
114 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
115 fl_addto_choice(paper_->choice_paperpackage,
117 "| A4 small Margins (only portrait) "
118 "| A4 very small Margins (only portrait) "
119 "| A4 very wide margins (only portrait) "));
120 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
121 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
122 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
123 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
124 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
125 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
126 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
127 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
128 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
130 bc_.addReadOnly (paper_->choice_paperpackage);
131 bc_.addReadOnly (paper_->greoup_radio_orientation);
132 bc_.addReadOnly (paper_->radio_portrait);
133 bc_.addReadOnly (paper_->radio_landscape);
134 bc_.addReadOnly (paper_->choice_papersize2);
135 bc_.addReadOnly (paper_->push_use_geometry);
136 bc_.addReadOnly (paper_->input_custom_width);
137 bc_.addReadOnly (paper_->input_custom_height);
138 bc_.addReadOnly (paper_->input_top_margin);
139 bc_.addReadOnly (paper_->input_bottom_margin);
140 bc_.addReadOnly (paper_->input_left_margin);
141 bc_.addReadOnly (paper_->input_right_margin);
142 bc_.addReadOnly (paper_->input_head_height);
143 bc_.addReadOnly (paper_->input_head_sep);
144 bc_.addReadOnly (paper_->input_foot_skip);
146 // the document class form
147 class_ = build_doc_class();
150 #ifdef USE_CLASS_COMBO
151 // The language is a combo-box and has to be inserted manually
152 obj = class_->choice_doc_class;
153 fl_addto_form(class_->form);
154 combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
155 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 200);
156 combo_doc_class->shortcut("#C",1);
157 combo_doc_class->setcallback(ComboInputCB, this);
159 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
160 cit != textclasslist.end(); ++cit)
162 combo_doc_class->addto((*cit).description().c_str());
165 fl_clear_choice(class_->choice_doc_class);
166 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
167 cit != textclasslist.end(); ++cit)
169 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
172 fl_addto_choice(class_->choice_doc_spacing,
173 _(" Single | OneHalf | Double | Other "));
174 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
175 for (n=0; tex_fonts[n][0]; ++n) {
176 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
178 fl_addto_choice(class_->choice_doc_pagestyle,
179 "default|empty|plain|headings|fancy");
180 fl_addto_choice(class_->choice_doc_skip,
181 _(" Smallskip | Medskip | Bigskip | Length "));
182 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
183 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
185 bc_.addReadOnly (class_->radio_doc_indent);
186 bc_.addReadOnly (class_->radio_doc_skip);
187 #ifndef USE_CLASS_COMBO
188 bc_.addReadOnly (class_->choice_doc_class);
190 bc_.addReadOnly (class_->choice_doc_pagestyle);
191 bc_.addReadOnly (class_->choice_doc_fonts);
192 bc_.addReadOnly (class_->choice_doc_fontsize);
193 bc_.addReadOnly (class_->radio_doc_sides_one);
194 bc_.addReadOnly (class_->radio_doc_sides_two);
195 bc_.addReadOnly (class_->radio_doc_columns_one);
196 bc_.addReadOnly (class_->radio_doc_columns_two);
197 bc_.addReadOnly (class_->input_doc_extra);
198 bc_.addReadOnly (class_->input_doc_skip);
199 bc_.addReadOnly (class_->choice_doc_skip);
200 bc_.addReadOnly (class_->choice_doc_spacing);
201 bc_.addReadOnly (class_->input_doc_spacing);
203 // the document language form
204 language_ = build_doc_language();
205 fl_addto_choice(language_->choice_inputenc,
206 "default|auto|latin1|latin2|latin5"
207 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
209 // The language is a combo-box and has to be inserted manually
210 obj = language_->choice_language;
211 fl_addto_form(language_->form);
212 combo_language = new Combox(FL_COMBOX_DROPLIST);
213 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
214 combo_language->shortcut("#L",1);
215 combo_language->setcallback(ComboInputCB, this);
217 // "default" is not part of the languages array any more.
218 #ifdef DO_USE_DEFAULT_LANGUAGE
219 combo_language->addto("default");
221 for(Languages::iterator cit = languages.begin();
222 cit != languages.end(); ++cit) {
223 combo_language->addto((*cit).second.lang().c_str());
226 fl_addto_choice(language_->choice_quotes_language,
227 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
228 " «text» | »text« "));
230 bc_.addReadOnly (language_->choice_language);
231 bc_.addReadOnly (language_->choice_inputenc);
233 // the document options form
234 options_ = build_doc_options();
235 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
236 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
237 fl_set_counter_step(options_->slider_secnumdepth,1,1);
238 fl_set_counter_step(options_->slider_tocdepth,1,1);
239 fl_set_counter_precision(options_->slider_secnumdepth, 0);
240 fl_set_counter_precision(options_->slider_tocdepth, 0);
241 for (n=0; tex_graphics[n][0]; ++n) {
242 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
245 bc_.addReadOnly (options_->slider_secnumdepth);
246 bc_.addReadOnly (options_->slider_tocdepth);
247 bc_.addReadOnly (options_->check_use_amsmath);
248 bc_.addReadOnly (options_->input_float_placement);
249 bc_.addReadOnly (options_->choice_postscript_driver);
251 // the document bullets form
252 bullets_ = build_doc_bullet();
253 fl_addto_choice(bullets_->choice_bullet_size,
254 _(" default | tiny | script | footnote | small |"
255 " normal | large | Large | LARGE | huge | Huge"));
256 fl_set_choice(bullets_->choice_bullet_size, 1);
257 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
258 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
260 bc_.addReadOnly (bullets_->bmtable_bullet_panel);
261 bc_.addReadOnly (bullets_->choice_bullet_size);
262 bc_.addReadOnly (bullets_->input_bullet_latex);
264 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
266 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
268 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
270 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
272 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
274 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
275 lyxerr << _("Your version of libXpm is older than 4.7.\n"
276 "The `bullet' tab of the document popup "
277 "has been disabled") << '\n';
278 fl_deactivate_object(fbullet);
279 fl_set_object_lcol(fbullet, FL_INACTIVE);
284 void FormDocument::apply()
286 if (!lv_->view()->available() || !dialog_)
289 bool redo = class_apply();
291 redo = language_apply() || redo;
292 redo = options_apply() || redo;
296 lv_->view()->redoCurrentBuffer();
298 lv_->buffer()->markDirty();
299 setMinibuffer(lv_, _("Document layout set"));
303 bool FormDocument::class_apply()
306 BufferParams ¶ms = lv_->buffer()->params;
308 // If default skip is a "Length" but there's no text in the
309 // input field, reset the kind to "Medskip", which is the default.
310 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
311 !*(fl_get_input (class_->input_doc_skip))) {
312 fl_set_choice (class_->choice_doc_skip, 2);
314 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
315 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
316 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
318 #ifdef USE_CLASS_COMBO
319 unsigned int new_class = combo_doc_class->get() - 1;
321 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
323 if (params.textclass != new_class) {
324 // try to load new_class
325 if (textclasslist.Load(new_class)) {
326 // successfully loaded
328 setMinibuffer(lv_, _("Converting document to new document class..."));
330 int ret = cap.SwitchLayoutsBetweenClasses(
331 params.textclass, new_class,
332 lv_->buffer()->paragraph);
336 s = _("One paragraph couldn't be converted");
339 s += _(" paragraphs couldn't be converted");
341 WriteAlert(_("Conversion Errors!"),s,
342 _("into chosen document class"));
345 params.textclass = new_class;
347 // problem changing class -- warn user and retain old style
348 WriteAlert(_("Conversion Errors!"),
349 _("Errors loading new document class."),
350 _("Reverting to original document class."));
351 #ifdef USE_CLASS_COMBO
352 combo_doc_class->select(params.textclass + 1);
354 fl_set_choice(class_->choice_doc_class,
355 params.textclass + 1);
359 char tmpsep = params.paragraph_separation;
360 if (fl_get_button(class_->radio_doc_indent))
361 params.paragraph_separation = BufferParams::PARSEP_INDENT;
363 params.paragraph_separation = BufferParams::PARSEP_SKIP;
364 if (tmpsep != params.paragraph_separation)
367 VSpace tmpdefskip = params.getDefSkip();
368 switch (fl_get_choice (class_->choice_doc_skip)) {
370 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
373 params.setDefSkip(VSpace(VSpace::MEDSKIP));
376 params.setDefSkip(VSpace(VSpace::BIGSKIP));
380 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
382 // DocumentDefskipCB assures that this never happens
384 params.setDefSkip(VSpace(VSpace::MEDSKIP));
387 if (!(tmpdefskip == params.getDefSkip()))
390 if (fl_get_button(class_->radio_doc_columns_two))
394 if (fl_get_button(class_->radio_doc_sides_two))
395 params.sides = LyXTextClass::TwoSides;
397 params.sides = LyXTextClass::OneSide;
399 Spacing tmpSpacing = params.spacing;
400 switch(fl_get_choice(class_->choice_doc_spacing)) {
402 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
403 params.spacing.set(Spacing::Single);
406 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
407 params.spacing.set(Spacing::Onehalf);
410 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
411 params.spacing.set(Spacing::Double);
414 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
415 params.spacing.set(Spacing::Other,
416 fl_get_input(class_->input_doc_spacing));
419 if (tmpSpacing != params.spacing)
422 params.options = fl_get_input(class_->input_doc_extra);
428 void FormDocument::paper_apply()
430 BufferParams & params = lv_->buffer()->params;
432 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
433 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
434 params.use_geometry = fl_get_button(paper_->push_use_geometry);
435 if (fl_get_button(paper_->radio_landscape))
436 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
438 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
439 params.paperwidth = fl_get_input(paper_->input_custom_width);
440 params.paperheight = fl_get_input(paper_->input_custom_height);
441 params.leftmargin = fl_get_input(paper_->input_left_margin);
442 params.topmargin = fl_get_input(paper_->input_top_margin);
443 params.rightmargin = fl_get_input(paper_->input_right_margin);
444 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
445 params.headheight = fl_get_input(paper_->input_head_height);
446 params.headsep = fl_get_input(paper_->input_head_sep);
447 params.footskip = fl_get_input(paper_->input_foot_skip);
448 lv_->buffer()->setPaperStuff();
452 bool FormDocument::language_apply()
454 BufferParams & params = lv_->buffer()->params;
455 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
458 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
460 lga = InsetQuotes::EnglishQ;
463 lga = InsetQuotes::SwedishQ;
466 lga = InsetQuotes::GermanQ;
469 lga = InsetQuotes::PolishQ;
472 lga = InsetQuotes::FrenchQ;
475 lga = InsetQuotes::DanishQ;
478 params.quotes_language = lga;
479 if (fl_get_button(language_->radio_single))
480 params.quotes_times = InsetQuotes::SingleQ;
482 params.quotes_times = InsetQuotes::DoubleQ;
484 Language const * old_language = params.language_info;
485 params.language = combo_language->getline();
486 Languages::iterator lit = languages.find(params.language);
488 Language const * new_language;
489 if (lit != languages.end())
490 new_language = &(*lit).second;
492 new_language = default_language;
494 if (old_language != new_language
495 && old_language->RightToLeft() == new_language->RightToLeft()
496 && !lv_->buffer()->isMultiLingual())
497 lv_->buffer()->ChangeLanguage(old_language, new_language);
498 if (old_language != new_language) {
501 params.language_info = new_language;
502 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
508 bool FormDocument::options_apply()
510 BufferParams & params = lv_->buffer()->params;
513 params.graphicsDriver =
514 fl_get_choice_text(options_->choice_postscript_driver);
515 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
517 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
518 if (params.secnumdepth != tmpchar)
520 params.secnumdepth = tmpchar;
522 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
524 params.float_placement =
525 fl_get_input(options_->input_float_placement);
531 void FormDocument::bullets_apply()
533 /* update the bullet settings */
534 BufferParams & param = lv_->buffer()->params;
536 // a little bit of loop unrolling
537 param.user_defined_bullets[0] = param.temp_bullets[0];
538 param.user_defined_bullets[1] = param.temp_bullets[1];
539 param.user_defined_bullets[2] = param.temp_bullets[2];
540 param.user_defined_bullets[3] = param.temp_bullets[3];
544 void FormDocument::cancel()
546 // this avoids confusion when reopening
547 BufferParams & param = lv_->buffer()->params;
548 param.temp_bullets[0] = param.user_defined_bullets[0];
549 param.temp_bullets[1] = param.user_defined_bullets[1];
550 param.temp_bullets[2] = param.user_defined_bullets[2];
551 param.temp_bullets[3] = param.user_defined_bullets[3];
556 void FormDocument::update()
563 BufferParams const & params = lv_->buffer()->params;
565 class_update(params);
566 paper_update(params);
567 language_update(params);
568 options_update(params);
569 bullets_update(params);
573 void FormDocument::class_update(BufferParams const & params)
578 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
580 #ifdef USE_CLASS_COMBO
581 combo_doc_class->select_text(
582 textclasslist.DescOfClass(params.textclass).c_str());
584 fl_set_choice_text(class_->choice_doc_class,
585 textclasslist.DescOfClass(params.textclass).c_str());
587 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
588 fl_clear_choice(class_->choice_doc_fontsize);
589 fl_addto_choice(class_->choice_doc_fontsize, "default");
590 fl_addto_choice(class_->choice_doc_fontsize,
591 tclass.opt_fontsize().c_str());
592 fl_set_choice(class_->choice_doc_fontsize,
593 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
594 fl_clear_choice(class_->choice_doc_pagestyle);
595 fl_addto_choice(class_->choice_doc_pagestyle, "default");
596 fl_addto_choice(class_->choice_doc_pagestyle,
597 tclass.opt_pagestyle().c_str());
598 fl_set_choice(class_->choice_doc_pagestyle,
599 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
600 fl_set_button(class_->radio_doc_indent, 0);
601 fl_set_button(class_->radio_doc_skip, 0);
602 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
603 fl_set_button(class_->radio_doc_indent, 1);
605 fl_set_button(class_->radio_doc_skip, 1);
606 switch (params.getDefSkip().kind()) {
607 case VSpace::SMALLSKIP:
608 fl_set_choice (class_->choice_doc_skip, 1);
610 case VSpace::MEDSKIP:
611 fl_set_choice (class_->choice_doc_skip, 2);
613 case VSpace::BIGSKIP:
614 fl_set_choice (class_->choice_doc_skip, 3);
617 fl_set_choice (class_->choice_doc_skip, 4);
618 fl_set_input (class_->input_doc_skip,
619 params.getDefSkip().asLyXCommand().c_str());
622 fl_set_choice (class_->choice_doc_skip, 2);
625 fl_set_button(class_->radio_doc_sides_one, 0);
626 fl_set_button(class_->radio_doc_sides_two, 0);
627 if (params.sides == 2)
628 fl_set_button(class_->radio_doc_sides_two, 1);
630 fl_set_button(class_->radio_doc_sides_one, 1);
631 fl_set_button(class_->radio_doc_columns_one, 0);
632 fl_set_button(class_->radio_doc_columns_two, 0);
633 if (params.columns == 2)
634 fl_set_button(class_->radio_doc_columns_two, 1);
636 fl_set_button(class_->radio_doc_columns_one, 1);
637 fl_set_input(class_->input_doc_spacing, "");
638 switch (params.spacing.getSpace()) {
639 case Spacing::Default: // nothing bad should happen with this
640 case Spacing::Single:
642 fl_set_choice(class_->choice_doc_spacing, 1);
644 case Spacing::Onehalf:
646 fl_set_choice(class_->choice_doc_spacing, 2);
648 case Spacing::Double:
650 fl_set_choice(class_->choice_doc_spacing, 3);
654 fl_set_choice(class_->choice_doc_spacing, 4);
656 sprintf(sval,"%g",params.spacing.getValue());
657 fl_set_input(class_->input_doc_spacing, sval);
661 if (!params.options.empty())
662 fl_set_input(class_->input_doc_extra, params.options.c_str());
664 fl_set_input(class_->input_doc_extra, "");
668 void FormDocument::language_update(BufferParams const & params)
673 combo_language->select_text(params.language.c_str());
674 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
675 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
676 fl_set_button(language_->radio_single, 0);
677 fl_set_button(language_->radio_double, 0);
678 if (params.quotes_times == InsetQuotes::SingleQ)
679 fl_set_button(language_->radio_single, 1);
681 fl_set_button(language_->radio_double, 1);
685 void FormDocument::options_update(BufferParams const & params)
690 fl_set_choice_text(options_->choice_postscript_driver,
691 params.graphicsDriver.c_str());
692 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
693 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
694 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
695 if (!params.float_placement.empty())
696 fl_set_input(options_->input_float_placement,
697 params.float_placement.c_str());
699 fl_set_input(options_->input_float_placement, "");
703 void FormDocument::paper_update(BufferParams const & params)
708 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
709 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
710 fl_set_button(paper_->push_use_geometry, params.use_geometry);
711 fl_set_button(paper_->radio_portrait, 0);
712 fl_set_button(paper_->radio_landscape, 0);
713 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
714 fl_set_button(paper_->radio_landscape, 1);
716 fl_set_button(paper_->radio_portrait, 1);
717 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
718 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
719 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
720 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
721 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
722 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
723 fl_set_input(paper_->input_head_height, params.headheight.c_str());
724 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
725 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
726 fl_set_focus_object(paper_->form, paper_->choice_papersize2);
730 void FormDocument::bullets_update(BufferParams const & params)
732 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
735 if (lv_->buffer()->isLinuxDoc()) {
736 fl_deactivate_object(fbullet);
737 fl_set_object_lcol(fbullet, FL_INACTIVE);
740 fl_activate_object(fbullet);
741 fl_set_object_lcol(fbullet, FL_BLACK);
744 fl_set_button(bullets_->radio_bullet_depth_1, 1);
745 fl_set_input(bullets_->input_bullet_latex,
746 params.user_defined_bullets[0].getText().c_str());
747 fl_set_choice(bullets_->choice_bullet_size,
748 params.user_defined_bullets[0].getSize() + 2);
752 void FormDocument::InputCB(FL_OBJECT * ob, long)
754 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
755 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
759 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
761 FormDocument * pre = static_cast<FormDocument*>(v);
762 if (combox == pre->combo_doc_class)
763 pre->CheckChoiceClass(0, 0);
764 pre->bc_.valid(pre->CheckDocumentInput(0,0));
768 void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
770 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
771 pre->CheckChoiceClass(ob,0);
772 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
776 void FormDocument::checkReadOnly()
778 if (bc_.readOnly(lv_->buffer()->isReadonly())) {
779 combo_doc_class->deactivate();
780 combo_language->deactivate();
781 fl_set_object_label(dialog_->text_warning,
782 _("Document is read-only."
783 " No changes to layout permitted."));
784 fl_show_object(dialog_->text_warning);
786 combo_doc_class->activate();
787 combo_language->activate();
788 fl_hide_object(dialog_->text_warning);
793 void FormDocument::checkMarginValues()
795 int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
796 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
797 !strlen(fl_get_input(paper_->input_left_margin)) &&
798 !strlen(fl_get_input(paper_->input_right_margin)) &&
799 !strlen(fl_get_input(paper_->input_head_height)) &&
800 !strlen(fl_get_input(paper_->input_head_sep)) &&
801 !strlen(fl_get_input(paper_->input_foot_skip)) &&
802 !strlen(fl_get_input(paper_->input_custom_width)) &&
803 !strlen(fl_get_input(paper_->input_custom_height)));
805 fl_set_button(paper_->push_use_geometry, 1);
808 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
816 if (ob == paper_->choice_papersize2) {
817 val = fl_get_choice(paper_->choice_papersize2)-1;
818 if (val == BufferParams::VM_PAPER_DEFAULT) {
819 fl_set_button(paper_->push_use_geometry, 0);
822 if ((val != BufferParams::VM_PAPER_USLETTER) &&
823 (val != BufferParams::VM_PAPER_USLEGAL) &&
824 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
825 (val != BufferParams::VM_PAPER_A4) &&
826 (val != BufferParams::VM_PAPER_A5) &&
827 (val != BufferParams::VM_PAPER_B5)) {
828 fl_set_button(paper_->push_use_geometry, 1);
830 fl_set_choice(paper_->choice_paperpackage,
831 BufferParams::PACKAGE_NONE + 1);
833 } else if (ob == paper_->choice_paperpackage) {
834 val = fl_get_choice(paper_->choice_paperpackage)-1;
835 if (val != BufferParams::PACKAGE_NONE) {
836 fl_set_choice(paper_->choice_papersize2,
837 BufferParams::VM_PAPER_DEFAULT + 1);
838 fl_set_button(paper_->push_use_geometry, 0);
840 } else if (ob == class_->input_doc_spacing) {
841 input = fl_get_input(class_->input_doc_spacing);
843 fl_set_choice (class_->choice_doc_spacing, 1);
845 fl_set_choice(class_->choice_doc_spacing, 4);
848 // this has to be all out of if/elseif because it has to deactivate
849 // the document buttons and so the whole stuff has to be tested again.
850 str = fl_get_input(paper_->input_custom_width);
851 ok = ok && (str.empty() || isValidLength(str));
852 str = fl_get_input(paper_->input_custom_height);
853 ok = ok && (str.empty() || isValidLength(str));
854 str = fl_get_input(paper_->input_left_margin);
855 ok = ok && (str.empty() || isValidLength(str));
856 str = fl_get_input(paper_->input_right_margin);
857 ok = ok && (str.empty() || isValidLength(str));
858 str = fl_get_input(paper_->input_top_margin);
859 ok = ok && (str.empty() || isValidLength(str));
860 str = fl_get_input(paper_->input_bottom_margin);
861 ok = ok && (str.empty() || isValidLength(str));
862 str = fl_get_input(paper_->input_head_height);
863 ok = ok && (str.empty() || isValidLength(str));
864 str = fl_get_input(paper_->input_head_sep);
865 ok = ok && (str.empty() || isValidLength(str));
866 str = fl_get_input(paper_->input_foot_skip);
867 ok = ok && (str.empty() || isValidLength(str));
868 // "Synchronize" the choice and the input field, so that it
869 // is impossible to commit senseless data.
870 input = fl_get_input (class_->input_doc_skip);
871 if (ob == class_->input_doc_skip) {
873 fl_set_choice (class_->choice_doc_skip, 2);
874 } else if (isValidGlueLength (input)) {
875 fl_set_choice (class_->choice_doc_skip, 4);
877 fl_set_choice(class_->choice_doc_skip, 4);
881 if (*input && !isValidGlueLength(input))
884 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
886 else if (fl_get_choice(class_->choice_doc_skip) != 4)
887 fl_set_input (class_->input_doc_skip, "");
889 input = fl_get_input(class_->input_doc_spacing);
890 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
892 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
893 fl_set_input (class_->input_doc_spacing, "");
898 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
900 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
901 pre->ChoiceBulletSize(ob,0);
902 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
906 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
908 BufferParams & param = lv_->buffer()->params;
910 // convert from 1-6 range to -1-4
911 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
912 fl_set_input(bullets_->input_bullet_latex,
913 param.temp_bullets[current_bullet_depth].getText().c_str());
917 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
919 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
920 pre->InputBulletLaTeX(ob,0);
921 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
925 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
927 BufferParams & param = lv_->buffer()->params;
929 param.temp_bullets[current_bullet_depth].
930 setText(fl_get_input(bullets_->input_bullet_latex));
934 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long data)
936 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
937 pre->BulletDepth(ob, data);
941 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
943 /* Should I do the following: */
944 /* 1. change to the panel that the current bullet belongs in */
945 /* 2. show that bullet as selected */
946 /* 3. change the size setting to the size of the bullet in Q.*/
947 /* 4. display the latex equivalent in the latex box */
949 /* I'm inclined to just go with 3 and 4 at the moment and */
950 /* maybe try to support the others later */
951 BufferParams & param = lv_->buffer()->params;
953 switch (fl_get_button_numb(ob)) {
955 // right mouse button resets to default
956 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
958 current_bullet_depth = data;
959 fl_set_input(bullets_->input_bullet_latex,
960 param.temp_bullets[data].getText().c_str());
961 fl_set_choice(bullets_->choice_bullet_size,
962 param.temp_bullets[data].getSize() + 2);
967 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
969 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
970 pre->BulletPanel(ob,data);
974 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
976 /* Here we have to change the background pixmap to that selected */
977 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
979 if (data != current_bullet_panel) {
980 fl_freeze_form(bullets_->form);
981 current_bullet_panel = data;
983 /* free the current pixmap */
984 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
987 /* display the new one */
989 new_panel = "standard";
992 new_panel = "amssymb";
995 new_panel = "psnfss1";
998 new_panel = "psnfss2";
1001 new_panel = "psnfss3";
1004 new_panel = "psnfss4";
1007 /* something very wrong happened */
1008 // play it safe for now but should be an exception
1009 current_bullet_panel = 0; // standard panel
1010 new_panel = "standard";
1013 new_panel += ".xpm";
1014 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1015 LibFileSearch("images", new_panel.c_str()).c_str());
1016 fl_redraw_object(bullets_->bmtable_bullet_panel);
1017 fl_unfreeze_form(bullets_->form);
1022 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
1024 FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
1025 pre->BulletBMTable(ob,0);
1026 pre->bc_.valid(pre->CheckDocumentInput(ob,0));
1030 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1032 /* handle the user input by setting the current bullet depth's pixmap */
1033 /* to that extracted from the current chosen position of the BMTable */
1034 /* Don't forget to free the button's old pixmap first. */
1036 BufferParams & param = lv_->buffer()->params;
1037 int bmtable_button = fl_get_bmtable(ob);
1039 /* try to keep the button held down till another is pushed */
1040 /* fl_set_bmtable(ob, 1, bmtable_button); */
1041 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1042 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1043 fl_set_input(bullets_->input_bullet_latex,
1044 param.temp_bullets[current_bullet_depth].getText().c_str());
1048 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1051 ob = class_->choice_doc_class;
1053 ProhibitInput(lv_->view());
1057 #ifdef USE_CLASS_COMBO
1058 tc = combo_doc_class->get() - 1;
1059 tct = combo_doc_class->getline();
1061 tc = fl_get_choice(ob) - 1;
1062 tct = fl_get_choice_text(ob);
1064 if (textclasslist.Load(tc)) {
1065 if (AskQuestion(_("Should I set some parameters to"), tct,
1066 _("the defaults of this document class?"))) {
1067 BufferParams & params = lv_->buffer()->params;
1069 params.textclass = tc;
1070 params.useClassDefaults();
1071 UpdateLayoutDocument(params);
1074 // unable to load new style
1075 WriteAlert(_("Conversion Errors!"),
1076 _("Unable to switch to new document class."),
1077 _("Reverting to original document class."));
1078 #ifdef USE_CLASS_COMBO
1079 combo_doc_class->select(lv_->buffer()->params.textclass + 1);
1081 fl_set_choice(class_->choice_doc_class,
1082 lv_->buffer()->params.textclass + 1);
1085 AllowInput(lv_->view());
1089 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1095 class_update(params);
1096 paper_update(params);
1097 language_update(params);
1098 options_update(params);
1099 bullets_update(params);