1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 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"
34 #include "support/lstrings.h"
39 #include "BufferView.h"
42 #include "CutAndPaste.h"
43 #include "bufferview_funcs.h"
44 #include "xforms_helpers.h"
46 #include "input_validators.h" // fl_unsigned_float_filter
48 using Liason::setMinibuffer;
51 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
52 : FormBaseBD(lv, d, _("Document Layout")),
53 ActCell(0), Confirmed(0),
54 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
56 // let the dialog be shown
57 // This is a permanent connection so we won't bother
58 // storing a copy because we won't be disconnecting.
59 d->showDocument.connect(slot(this, &FormDocument::show));
63 void FormDocument::redraw()
65 if( form() && form()->visible )
66 fl_redraw_form( form() );
70 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
71 if (outer_form && outer_form->visible)
72 fl_redraw_form( outer_form );
76 FL_FORM * FormDocument::form() const
78 if (dialog_.get()) return dialog_->form;
83 void FormDocument::build()
88 dialog_.reset(build_tabbed_document());
90 // Manage the restore, ok, apply, restore and cancel/close buttons
91 bc().setOK(dialog_->button_ok);
92 bc().setApply(dialog_->button_apply);
93 bc().setCancel(dialog_->button_cancel);
94 bc().setRestore(dialog_->button_restore);
95 bc().addReadOnly (dialog_->button_save_defaults);
96 bc().addReadOnly (dialog_->button_reset_defaults);
98 // the document paper form
99 paper_.reset(build_doc_paper());
100 fl_addto_choice(paper_->choice_papersize,
101 _(" Default | Custom | USletter | USlegal "
102 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
103 fl_addto_choice(paper_->choice_paperpackage,
106 "| Very small Margins "
107 "| Very wide Margins "));
109 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
110 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
119 // Set input filters on width and height to make them accept only
121 fl_set_input_filter(paper_->input_custom_width,
122 fl_unsigned_float_filter);
123 fl_set_input_filter(paper_->input_custom_height,
124 fl_unsigned_float_filter);
125 fl_set_input_filter(paper_->input_top_margin,
126 fl_unsigned_float_filter);
127 fl_set_input_filter(paper_->input_bottom_margin,
128 fl_unsigned_float_filter);
129 fl_set_input_filter(paper_->input_left_margin,
130 fl_unsigned_float_filter);
131 fl_set_input_filter(paper_->input_right_margin,
132 fl_unsigned_float_filter);
133 fl_set_input_filter(paper_->input_head_height,
134 fl_unsigned_float_filter);
135 fl_set_input_filter(paper_->input_head_sep,
136 fl_unsigned_float_filter);
137 fl_set_input_filter(paper_->input_foot_skip,
138 fl_unsigned_float_filter);
140 // Create the contents of the unit choices
141 string const units = " cm | inch ";
143 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
144 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
145 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
146 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
147 fl_addto_choice(paper_->choice_left_margin_units, units.c_str());
148 fl_addto_choice(paper_->choice_right_margin_units, units.c_str());
149 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
150 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
151 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
153 bc().addReadOnly (paper_->choice_paperpackage);
154 bc().addReadOnly (paper_->group_radio_orientation);
155 bc().addReadOnly (paper_->radio_portrait);
156 bc().addReadOnly (paper_->radio_landscape);
157 bc().addReadOnly (paper_->choice_papersize);
158 bc().addReadOnly (paper_->check_use_geometry);
159 bc().addReadOnly (paper_->input_custom_width);
160 bc().addReadOnly (paper_->input_custom_height);
161 bc().addReadOnly (paper_->input_top_margin);
162 bc().addReadOnly (paper_->input_bottom_margin);
163 bc().addReadOnly (paper_->input_left_margin);
164 bc().addReadOnly (paper_->input_right_margin);
165 bc().addReadOnly (paper_->input_head_height);
166 bc().addReadOnly (paper_->input_head_sep);
167 bc().addReadOnly (paper_->input_foot_skip);
169 // the document class form
170 class_.reset(build_doc_class());
173 // The language is a combo-box and has to be inserted manually
174 obj = class_->choice_doc_class;
175 fl_deactivate_object(obj);
176 fl_addto_form(class_->form);
177 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
178 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
179 dialog_->tabbed_folder);
180 combo_doc_class->shortcut("#C",1);
181 combo_doc_class->setcallback(ComboInputCB, this);
183 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
184 cit != textclasslist.end(); ++cit) {
185 combo_doc_class->addto(cit->description());
188 fl_addto_choice(class_->choice_doc_spacing,
189 _(" Single | OneHalf | Double | Other "));
190 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
191 for (n=0; tex_fonts[n][0]; ++n) {
192 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
194 fl_addto_choice(class_->choice_doc_pagestyle,
195 "default|empty|plain|headings|fancy");
196 fl_addto_choice(class_->choice_doc_skip,
197 _(" Smallskip | Medskip | Bigskip | Length "));
198 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
199 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
200 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
202 bc().addReadOnly (class_->radio_doc_indent);
203 bc().addReadOnly (class_->radio_doc_skip);
205 bc().addReadOnly (class_->choice_doc_pagestyle);
206 bc().addReadOnly (class_->choice_doc_fonts);
207 bc().addReadOnly (class_->choice_doc_fontsize);
208 bc().addReadOnly (class_->radio_doc_sides_one);
209 bc().addReadOnly (class_->radio_doc_sides_two);
210 bc().addReadOnly (class_->radio_doc_columns_one);
211 bc().addReadOnly (class_->radio_doc_columns_two);
212 bc().addReadOnly (class_->input_doc_extra);
213 bc().addReadOnly (class_->input_doc_skip);
214 bc().addReadOnly (class_->choice_doc_skip);
215 bc().addReadOnly (class_->choice_doc_spacing);
216 bc().addReadOnly (class_->input_doc_spacing);
218 // the document language form
219 language_.reset(build_doc_language());
220 fl_addto_choice(language_->choice_inputenc,
221 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
222 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
224 // The language is a combo-box and has to be inserted manually
225 obj = language_->choice_language;
226 fl_deactivate_object(obj);
227 fl_addto_form(language_->form);
228 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
229 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
230 dialog_->tabbed_folder);
231 combo_language->shortcut("#L",1);
232 combo_language->setcallback(ComboInputCB, this);
235 for (Languages::const_iterator cit = languages.begin();
236 cit != languages.end(); ++cit) {
237 combo_language->addto(cit->second.lang());
240 fl_addto_choice(language_->choice_quotes_language,
241 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
242 " «text» | »text« "));
244 bc().addReadOnly (language_->choice_inputenc);
245 bc().addReadOnly (language_->choice_quotes_language);
246 bc().addReadOnly (language_->radio_single);
247 bc().addReadOnly (language_->radio_double);
249 // the document options form
250 options_.reset(build_doc_options());
251 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
252 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
253 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
254 fl_set_counter_step(options_->slider_secnumdepth,1,1);
255 fl_set_counter_step(options_->slider_tocdepth,1,1);
256 fl_set_counter_precision(options_->slider_secnumdepth, 0);
257 fl_set_counter_precision(options_->slider_tocdepth, 0);
258 for (n=0; tex_graphics[n][0]; ++n) {
259 fl_addto_choice(options_->choice_postscript_driver,
262 fl_addto_choice(options_->choice_citation_format,
263 _(" Author-year | Numerical "));
265 bc_.addReadOnly (options_->slider_secnumdepth);
266 bc_.addReadOnly (options_->slider_tocdepth);
267 bc_.addReadOnly (options_->check_use_amsmath);
268 bc_.addReadOnly (options_->check_use_natbib);
269 bc_.addReadOnly (options_->choice_citation_format);
270 bc_.addReadOnly (options_->input_float_placement);
271 bc_.addReadOnly (options_->choice_postscript_driver);
273 // the document bullets form
274 bullets_.reset(build_doc_bullet());
275 fl_addto_choice(bullets_->choice_bullet_size,
276 _(" default | tiny | script | footnote | small |"
277 " normal | large | Large | LARGE | huge | Huge"));
278 fl_set_choice(bullets_->choice_bullet_size, 1);
279 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
280 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
282 bc().addReadOnly (bullets_->bmtable_bullet_panel);
283 bc().addReadOnly (bullets_->choice_bullet_size);
284 bc().addReadOnly (bullets_->input_bullet_latex);
285 bc().addReadOnly (bullets_->radio_bullet_depth);
286 bc().addReadOnly (bullets_->radio_bullet_panel);
288 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
290 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
292 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
294 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
296 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
298 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
299 lyxerr << _("Your version of libXpm is older than 4.7.\n"
300 "The `bullet' tab of the document dialog "
301 "has been disabled") << '\n';
302 fl_deactivate_object(fbullet);
303 fl_set_object_lcol(fbullet, FL_INACTIVE);
308 void FormDocument::apply()
310 if (!lv_->view()->available() || !dialog_.get())
313 bool redo = class_apply();
315 redo = language_apply() || redo;
316 redo = options_apply() || redo;
320 lv_->view()->redoCurrentBuffer();
322 lv_->buffer()->markDirty();
323 setMinibuffer(lv_, _("Document layout set"));
327 void FormDocument::cancel()
329 // this avoids confusion when reopening
330 BufferParams & param = lv_->buffer()->params;
331 param.temp_bullets[0] = param.user_defined_bullets[0];
332 param.temp_bullets[1] = param.user_defined_bullets[1];
333 param.temp_bullets[2] = param.user_defined_bullets[2];
334 param.temp_bullets[3] = param.user_defined_bullets[3];
339 void FormDocument::update()
346 BufferParams const & params = lv_->buffer()->params;
348 setEnabled(dialog_->button_reset_defaults,
349 !params.hasClassDefaults());
351 class_update(params);
352 paper_update(params);
353 language_update(params);
354 options_update(params);
355 bullets_update(params);
359 bool FormDocument::input( FL_OBJECT * ob, long data )
361 State cb = static_cast<State>( data );
364 case CHECKCHOICECLASS:
365 CheckChoiceClass(ob, 0);
367 case CHOICEBULLETSIZE:
368 ChoiceBulletSize(ob, 0);
370 case INPUTBULLETLATEX:
371 InputBulletLaTeX(ob, 0);
388 BulletBMTable(ob, 0);
394 if (ob == options_->check_use_natbib) {
395 setEnabled(options_->choice_citation_format,
396 fl_get_button(options_->check_use_natbib));
399 if (ob == dialog_->button_save_defaults) {
400 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
403 if (ob == dialog_->button_reset_defaults) {
404 BufferParams params = lv_->buffer()->params;
405 params.textclass = combo_doc_class->get() - 1;
406 params.useClassDefaults();
407 UpdateLayoutDocument(params);
410 if (ob == paper_->radio_landscape)
411 fl_set_choice(paper_->choice_paperpackage,
412 BufferParams::PACKAGE_NONE + 1);
414 if (ob == paper_->choice_papersize) {
416 fl_get_choice(paper_->choice_papersize) == 2;
418 fl_get_choice(paper_->choice_papersize) == 6;
420 fl_get_choice(paper_->choice_papersize) == 9;
422 fl_get_choice(paper_->choice_papersize) == 10;
424 fl_set_button(paper_->radio_portrait, int(custom));
426 bool const use_geom = (custom || a3size || b3size || b4size);
428 fl_set_button(paper_->check_use_geometry, int(use_geom));
430 setEnabled(paper_->input_top_margin, use_geom);
431 setEnabled(paper_->input_bottom_margin, use_geom);
432 setEnabled(paper_->input_left_margin, use_geom);
433 setEnabled(paper_->input_right_margin, use_geom);
434 setEnabled(paper_->input_head_height, use_geom);
435 setEnabled(paper_->input_head_sep, use_geom);
436 setEnabled(paper_->input_foot_skip, use_geom);
437 setEnabled(paper_->choice_top_margin_units, use_geom);
438 setEnabled(paper_->choice_bottom_margin_units, use_geom);
439 setEnabled(paper_->choice_left_margin_units, use_geom);
440 setEnabled(paper_->choice_right_margin_units, use_geom);
441 setEnabled(paper_->choice_head_height_units, use_geom);
442 setEnabled(paper_->choice_head_sep_units, use_geom);
443 setEnabled(paper_->choice_foot_skip_units, use_geom);
444 setEnabled(paper_->choice_custom_width_units, use_geom);
445 setEnabled(paper_->choice_custom_height_units, use_geom);
447 setEnabled(paper_->input_custom_width, custom);
448 setEnabled(paper_->input_custom_height, custom);
449 setEnabled(paper_->choice_custom_width_units, custom);
450 setEnabled(paper_->choice_custom_height_units, custom);
451 setEnabled(paper_->radio_portrait, !custom);
452 setEnabled(paper_->radio_landscape, !custom);
455 if (ob == paper_->choice_papersize ||
456 ob == paper_->radio_portrait ||
457 ob == paper_->radio_landscape) {
459 setEnabled(paper_->choice_paperpackage,
460 //either default papersize (preferences)
461 //or document papersize has to be A4
462 (fl_get_choice(paper_->choice_papersize) == 7
463 || fl_get_choice(paper_->choice_papersize) == 1
464 && lyxrc.default_papersize == 5)
465 && fl_get_button(paper_->radio_portrait));
468 if (ob == paper_->choice_paperpackage) {
469 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
470 fl_set_button(paper_->check_use_geometry, 0);
472 setEnabled(paper_->input_top_margin, false);
473 setEnabled(paper_->input_bottom_margin, false);
474 setEnabled(paper_->input_left_margin, false);
475 setEnabled(paper_->input_right_margin, false);
476 setEnabled(paper_->input_head_height, false);
477 setEnabled(paper_->input_head_sep, false);
478 setEnabled(paper_->input_foot_skip, false);
479 setEnabled(paper_->choice_top_margin_units, false);
480 setEnabled(paper_->choice_bottom_margin_units, false);
481 setEnabled(paper_->choice_left_margin_units, false);
482 setEnabled(paper_->choice_right_margin_units, false);
483 setEnabled(paper_->choice_head_height_units, false);
484 setEnabled(paper_->choice_head_sep_units, false);
485 setEnabled(paper_->choice_foot_skip_units, false);
489 if (ob == paper_->check_use_geometry) {
490 //don't allow switching geometry off in custom papersize mode
491 //nor in A3, B3, and B4
492 int const choice = fl_get_choice(paper_->choice_papersize);
493 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
494 fl_set_button(paper_->check_use_geometry, 1);
496 fl_set_choice(paper_->choice_paperpackage,
497 BufferParams::PACKAGE_NONE + 1);
499 bool const use_geom = fl_get_button(paper_->check_use_geometry);
500 setEnabled(paper_->input_top_margin, use_geom);
501 setEnabled(paper_->input_bottom_margin, use_geom);
502 setEnabled(paper_->input_left_margin, use_geom);
503 setEnabled(paper_->input_right_margin, use_geom);
504 setEnabled(paper_->input_head_height, use_geom);
505 setEnabled(paper_->input_head_sep, use_geom);
506 setEnabled(paper_->input_foot_skip, use_geom);
507 setEnabled(paper_->choice_top_margin_units, use_geom);
508 setEnabled(paper_->choice_bottom_margin_units, use_geom);
509 setEnabled(paper_->choice_left_margin_units, use_geom);
510 setEnabled(paper_->choice_right_margin_units, use_geom);
511 setEnabled(paper_->choice_head_height_units, use_geom);
512 setEnabled(paper_->choice_head_sep_units, use_geom);
513 setEnabled(paper_->choice_foot_skip_units, use_geom);
516 setEnabled(dialog_->button_reset_defaults,
517 lv_->buffer()->params.hasClassDefaults());
521 case CHECKCHOICECLASS:
522 case CHOICEBULLETSIZE:
523 case INPUTBULLETLATEX:
525 return CheckDocumentInput(ob, 0);
534 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
536 FormDocument * pre = static_cast<FormDocument*>(v);
537 if (combox == pre->combo_doc_class.get())
538 pre->CheckChoiceClass(0, 0);
539 pre->bc().valid(pre->CheckDocumentInput(0,0));
543 bool FormDocument::class_apply()
546 BufferParams ¶ms = lv_->buffer()->params;
548 // If default skip is a "Length" but there's no text in the
549 // input field, reset the kind to "Medskip", which is the default.
550 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
551 !*(fl_get_input (class_->input_doc_skip))) {
552 fl_set_choice (class_->choice_doc_skip, 2);
554 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
555 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
556 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
558 unsigned int const new_class = combo_doc_class->get() - 1;
560 if (params.textclass != new_class) {
561 // try to load new_class
562 if (textclasslist.Load(new_class)) {
563 // successfully loaded
565 setMinibuffer(lv_, _("Converting document to new document class..."));
566 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
567 params.textclass, new_class,
568 lv_->buffer()->paragraph);
572 s = _("One paragraph couldn't be converted");
575 s += _(" paragraphs couldn't be converted");
577 WriteAlert(_("Conversion Errors!"),s,
578 _("into chosen document class"));
581 params.textclass = new_class;
583 // problem changing class -- warn user and retain old style
584 WriteAlert(_("Conversion Errors!"),
585 _("Errors loading new document class."),
586 _("Reverting to original document class."));
587 combo_doc_class->select(int(params.textclass) + 1);
590 BufferParams::PARSEP tmpsep = params.paragraph_separation;
591 if (fl_get_button(class_->radio_doc_indent))
592 params.paragraph_separation = BufferParams::PARSEP_INDENT;
594 params.paragraph_separation = BufferParams::PARSEP_SKIP;
595 if (tmpsep != params.paragraph_separation)
598 VSpace tmpdefskip = params.getDefSkip();
599 switch (fl_get_choice (class_->choice_doc_skip)) {
601 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
604 params.setDefSkip(VSpace(VSpace::MEDSKIP));
607 params.setDefSkip(VSpace(VSpace::BIGSKIP));
611 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
613 // DocumentDefskipCB assures that this never happens
615 params.setDefSkip(VSpace(VSpace::MEDSKIP));
618 if (!(tmpdefskip == params.getDefSkip()))
621 if (fl_get_button(class_->radio_doc_columns_two))
625 if (fl_get_button(class_->radio_doc_sides_two))
626 params.sides = LyXTextClass::TwoSides;
628 params.sides = LyXTextClass::OneSide;
630 Spacing tmpSpacing = params.spacing;
631 switch (fl_get_choice(class_->choice_doc_spacing)) {
633 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
634 params.spacing.set(Spacing::Single);
637 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
638 params.spacing.set(Spacing::Onehalf);
641 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
642 params.spacing.set(Spacing::Double);
645 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
646 params.spacing.set(Spacing::Other,
647 fl_get_input(class_->input_doc_spacing));
650 if (tmpSpacing != params.spacing)
653 params.options = fl_get_input(class_->input_doc_extra);
659 void FormDocument::paper_apply()
661 BufferParams & params = lv_->buffer()->params;
663 params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
665 params.paperpackage =
666 char(fl_get_choice(paper_->choice_paperpackage)-1);
668 // set params.papersize from params.papersize2 and params.paperpackage
669 lv_->buffer()->setPaperStuff();
671 params.use_geometry = fl_get_button(paper_->check_use_geometry);
673 if (fl_get_button(paper_->radio_landscape))
674 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
676 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
679 getLengthFromWidgets(paper_->input_custom_width,
680 paper_->choice_custom_width_units);
683 getLengthFromWidgets(paper_->input_custom_height,
684 paper_->choice_custom_height_units);
687 getLengthFromWidgets(paper_->input_left_margin,
688 paper_->choice_left_margin_units);
691 getLengthFromWidgets(paper_->input_top_margin,
692 paper_->choice_top_margin_units);
695 getLengthFromWidgets(paper_->input_right_margin,
696 paper_->choice_right_margin_units);
698 params.bottommargin =
699 getLengthFromWidgets(paper_->input_bottom_margin,
700 paper_->choice_bottom_margin_units);
703 getLengthFromWidgets(paper_->input_head_height,
704 paper_->choice_head_height_units);
707 getLengthFromWidgets(paper_->input_head_sep,
708 paper_->choice_head_sep_units);
711 getLengthFromWidgets(paper_->input_foot_skip,
712 paper_->choice_foot_skip_units);
716 bool FormDocument::language_apply()
718 BufferParams & params = lv_->buffer()->params;
719 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
722 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
724 lga = InsetQuotes::EnglishQ;
727 lga = InsetQuotes::SwedishQ;
730 lga = InsetQuotes::GermanQ;
733 lga = InsetQuotes::PolishQ;
736 lga = InsetQuotes::FrenchQ;
739 lga = InsetQuotes::DanishQ;
742 params.quotes_language = lga;
743 if (fl_get_button(language_->radio_single))
744 params.quotes_times = InsetQuotes::SingleQ;
746 params.quotes_times = InsetQuotes::DoubleQ;
748 Language const * old_language = params.language;
749 Language const * new_language =
750 languages.getLanguage(combo_language->getline());
752 new_language = default_language;
754 if (old_language != new_language
755 && old_language->RightToLeft() == new_language->RightToLeft()
756 && !lv_->buffer()->isMultiLingual())
757 lv_->buffer()->changeLanguage(old_language, new_language);
758 if (old_language != new_language) {
761 params.language = new_language;
762 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
768 bool FormDocument::options_apply()
770 BufferParams & params = lv_->buffer()->params;
773 params.graphicsDriver =
774 fl_get_choice_text(options_->choice_postscript_driver);
775 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
776 params.use_natbib = fl_get_button(options_->check_use_natbib);
777 params.use_numerical_citations =
778 fl_get_choice(options_->choice_citation_format)-1;
780 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
781 if (params.secnumdepth != tmpchar)
783 params.secnumdepth = tmpchar;
785 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
787 params.float_placement =
788 fl_get_input(options_->input_float_placement);
794 void FormDocument::bullets_apply()
796 /* update the bullet settings */
797 BufferParams & param = lv_->buffer()->params;
799 // a little bit of loop unrolling
800 param.user_defined_bullets[0] = param.temp_bullets[0];
801 param.user_defined_bullets[1] = param.temp_bullets[1];
802 param.user_defined_bullets[2] = param.temp_bullets[2];
803 param.user_defined_bullets[3] = param.temp_bullets[3];
807 void FormDocument::class_update(BufferParams const & params)
812 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
814 combo_doc_class->select(
815 textclasslist.DescOfClass(params.textclass));
816 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
817 fl_clear_choice(class_->choice_doc_fontsize);
818 fl_addto_choice(class_->choice_doc_fontsize, "default");
819 fl_addto_choice(class_->choice_doc_fontsize,
820 tclass.opt_fontsize().c_str());
821 fl_set_choice(class_->choice_doc_fontsize,
822 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
823 fl_clear_choice(class_->choice_doc_pagestyle);
824 fl_addto_choice(class_->choice_doc_pagestyle, "default");
825 fl_addto_choice(class_->choice_doc_pagestyle,
826 tclass.opt_pagestyle().c_str());
827 fl_set_choice(class_->choice_doc_pagestyle,
828 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
829 fl_set_button(class_->radio_doc_indent, 0);
830 fl_set_button(class_->radio_doc_skip, 0);
831 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
832 fl_set_button(class_->radio_doc_indent, 1);
834 fl_set_button(class_->radio_doc_skip, 1);
835 switch (params.getDefSkip().kind()) {
836 case VSpace::SMALLSKIP:
837 fl_set_choice (class_->choice_doc_skip, 1);
839 case VSpace::MEDSKIP:
840 fl_set_choice (class_->choice_doc_skip, 2);
842 case VSpace::BIGSKIP:
843 fl_set_choice (class_->choice_doc_skip, 3);
846 fl_set_choice (class_->choice_doc_skip, 4);
847 fl_set_input (class_->input_doc_skip,
848 params.getDefSkip().asLyXCommand().c_str());
851 fl_set_choice (class_->choice_doc_skip, 2);
854 fl_set_button(class_->radio_doc_sides_one, 0);
855 fl_set_button(class_->radio_doc_sides_two, 0);
856 if (params.sides == LyXTextClass::TwoSides)
857 fl_set_button(class_->radio_doc_sides_two, 1);
859 fl_set_button(class_->radio_doc_sides_one, 1);
860 fl_set_button(class_->radio_doc_columns_one, 0);
861 fl_set_button(class_->radio_doc_columns_two, 0);
862 if (params.columns == 2)
863 fl_set_button(class_->radio_doc_columns_two, 1);
865 fl_set_button(class_->radio_doc_columns_one, 1);
866 fl_set_input(class_->input_doc_spacing, "");
867 switch (params.spacing.getSpace()) {
868 case Spacing::Default: // nothing bad should happen with this
869 case Spacing::Single:
871 fl_set_choice(class_->choice_doc_spacing, 1);
873 case Spacing::Onehalf:
875 fl_set_choice(class_->choice_doc_spacing, 2);
877 case Spacing::Double:
879 fl_set_choice(class_->choice_doc_spacing, 3);
883 fl_set_choice(class_->choice_doc_spacing, 4);
885 sprintf(sval,"%g",params.spacing.getValue());
886 fl_set_input(class_->input_doc_spacing, sval);
890 if (!params.options.empty())
891 fl_set_input(class_->input_doc_extra, params.options.c_str());
893 fl_set_input(class_->input_doc_extra, "");
897 void FormDocument::language_update(BufferParams const & params)
899 if (!language_.get())
902 combo_language->select(params.language->lang());
903 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
904 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
905 fl_set_button(language_->radio_single, 0);
906 fl_set_button(language_->radio_double, 0);
907 if (params.quotes_times == InsetQuotes::SingleQ)
908 fl_set_button(language_->radio_single, 1);
910 fl_set_button(language_->radio_double, 1);
914 void FormDocument::options_update(BufferParams const & params)
919 fl_set_choice_text(options_->choice_postscript_driver,
920 params.graphicsDriver.c_str());
921 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
922 fl_set_button(options_->check_use_natbib, params.use_natbib);
923 fl_set_choice(options_->choice_citation_format,
924 int(params.use_numerical_citations)+1);
925 setEnabled(options_->choice_citation_format, params.use_natbib);
926 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
927 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
928 if (!params.float_placement.empty())
929 fl_set_input(options_->input_float_placement,
930 params.float_placement.c_str());
932 fl_set_input(options_->input_float_placement, "");
936 void FormDocument::paper_update(BufferParams const & params)
941 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
942 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
943 fl_set_button(paper_->check_use_geometry, params.use_geometry);
945 bool const useCustom = fl_get_choice(paper_->choice_papersize) == 2;
946 bool const useGeom = fl_get_button(paper_->check_use_geometry);
948 fl_set_button(paper_->radio_portrait, 0);
949 setEnabled(paper_->radio_portrait, !useCustom);
950 fl_set_button(paper_->radio_landscape, 0);
951 setEnabled(paper_->radio_landscape, !useCustom);
953 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
954 fl_set_button(paper_->radio_landscape, 1);
956 fl_set_button(paper_->radio_portrait, 1);
957 setEnabled(paper_->choice_paperpackage,
958 //either default papersize (preferences)
959 //or document papersize has to be A4
960 (fl_get_choice(paper_->choice_papersize) == 7
961 || fl_get_choice(paper_->choice_papersize) == 1
962 && lyxrc.default_papersize == 5)
963 && fl_get_button(paper_->radio_portrait));
965 updateWidgetsFromLengthString(paper_->input_custom_width,
966 paper_->choice_custom_width_units,
968 setEnabled(paper_->input_custom_width, useCustom);
969 setEnabled(paper_->choice_custom_width_units, useCustom);
971 updateWidgetsFromLengthString(paper_->input_custom_height,
972 paper_->choice_custom_height_units,
974 setEnabled(paper_->input_custom_height, useCustom);
975 setEnabled(paper_->choice_custom_height_units, useCustom);
977 updateWidgetsFromLengthString(paper_->input_left_margin,
978 paper_->choice_left_margin_units,
980 setEnabled(paper_->input_left_margin, useGeom);
981 setEnabled(paper_->choice_left_margin_units, useGeom);
983 updateWidgetsFromLengthString(paper_->input_top_margin,
984 paper_->choice_top_margin_units,
986 setEnabled(paper_->input_top_margin, useGeom);
987 setEnabled(paper_->choice_top_margin_units, useGeom);
989 updateWidgetsFromLengthString(paper_->input_right_margin,
990 paper_->choice_right_margin_units,
992 setEnabled(paper_->input_right_margin, useGeom);
993 setEnabled(paper_->choice_right_margin_units, useGeom);
995 updateWidgetsFromLengthString(paper_->input_bottom_margin,
996 paper_->choice_bottom_margin_units,
997 params.bottommargin);
998 setEnabled(paper_->input_bottom_margin, useGeom);
999 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1001 updateWidgetsFromLengthString(paper_->input_head_height,
1002 paper_->choice_head_height_units,
1004 setEnabled(paper_->input_head_height, useGeom);
1005 setEnabled(paper_->choice_head_height_units, useGeom);
1007 updateWidgetsFromLengthString(paper_->input_head_sep,
1008 paper_->choice_head_sep_units,
1010 setEnabled(paper_->input_head_sep, useGeom);
1011 setEnabled(paper_->choice_head_sep_units, useGeom);
1013 updateWidgetsFromLengthString(paper_->input_foot_skip,
1014 paper_->choice_foot_skip_units,
1016 setEnabled(paper_->input_foot_skip, useGeom);
1017 setEnabled(paper_->choice_foot_skip_units, useGeom);
1019 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1023 void FormDocument::bullets_update(BufferParams const & params)
1025 if (!bullets_.get() ||
1027 (XpmVersion==4 && XpmRevision<7)))
1030 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1031 setEnabled(fbullet, !isLinuxDoc);
1033 if (isLinuxDoc) return;
1035 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1036 fl_set_input(bullets_->input_bullet_latex,
1037 params.user_defined_bullets[0].getText().c_str());
1038 fl_set_choice(bullets_->choice_bullet_size,
1039 params.user_defined_bullets[0].getSize() + 2);
1043 void FormDocument::checkReadOnly()
1045 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1046 combo_doc_class->deactivate();
1047 combo_language->deactivate();
1048 fl_set_object_label(dialog_->text_warning,
1049 _("Document is read-only."
1050 " No changes to layout permitted."));
1051 fl_show_object(dialog_->text_warning);
1053 combo_doc_class->activate();
1054 combo_language->activate();
1055 fl_hide_object(dialog_->text_warning);
1060 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
1066 // "Synchronize" the choice and the input field, so that it
1067 // is impossible to commit senseless data.
1068 input = fl_get_input (class_->input_doc_skip);
1069 if (ob == class_->input_doc_skip) {
1071 fl_set_choice (class_->choice_doc_skip, 2);
1072 } else if (isValidGlueLength (input)) {
1073 fl_set_choice (class_->choice_doc_skip, 4);
1075 fl_set_choice(class_->choice_doc_skip, 4);
1079 if (*input && !isValidGlueLength(input))
1083 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1085 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1086 fl_set_input (class_->input_doc_skip, "");
1088 input = fl_get_input(class_->input_doc_spacing);
1089 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1091 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1092 fl_set_input (class_->input_doc_spacing, "");
1097 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1099 BufferParams & param = lv_->buffer()->params;
1101 // convert from 1-6 range to -1-4
1102 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1103 fl_set_input(bullets_->input_bullet_latex,
1104 param.temp_bullets[current_bullet_depth].getText().c_str());
1108 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1110 BufferParams & param = lv_->buffer()->params;
1112 param.temp_bullets[current_bullet_depth].
1113 setText(fl_get_input(bullets_->input_bullet_latex));
1117 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1119 /* Should I do the following: */
1120 /* 1. change to the panel that the current bullet belongs in */
1121 /* 2. show that bullet as selected */
1122 /* 3. change the size setting to the size of the bullet in Q.*/
1123 /* 4. display the latex equivalent in the latex box */
1125 /* I'm inclined to just go with 3 and 4 at the moment and */
1126 /* maybe try to support the others later */
1127 BufferParams & param = lv_->buffer()->params;
1130 if (cb == BULLETDEPTH1 )
1132 else if (cb == BULLETDEPTH2 )
1134 else if (cb == BULLETDEPTH3 )
1136 else if (cb == BULLETDEPTH4 )
1139 switch (fl_get_button_numb(ob)) {
1141 // right mouse button resets to default
1142 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1144 current_bullet_depth = data;
1145 fl_set_input(bullets_->input_bullet_latex,
1146 param.temp_bullets[data].getText().c_str());
1147 fl_set_choice(bullets_->choice_bullet_size,
1148 param.temp_bullets[data].getSize() + 2);
1153 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1155 /* Here we have to change the background pixmap to that selected */
1156 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1159 if (cb == BULLETPANEL1 )
1161 else if (cb == BULLETPANEL2 )
1163 else if (cb == BULLETPANEL3 )
1165 else if (cb == BULLETPANEL4 )
1167 else if (cb == BULLETPANEL5 )
1169 else if (cb == BULLETPANEL6 )
1172 if (data != current_bullet_panel) {
1173 fl_freeze_form(bullets_->form);
1174 current_bullet_panel = data;
1176 /* free the current pixmap */
1177 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1180 /* display the new one */
1182 new_panel = "standard";
1185 new_panel = "amssymb";
1188 new_panel = "psnfss1";
1191 new_panel = "psnfss2";
1194 new_panel = "psnfss3";
1197 new_panel = "psnfss4";
1200 /* something very wrong happened */
1201 // play it safe for now but should be an exception
1202 current_bullet_panel = 0; // standard panel
1203 new_panel = "standard";
1206 new_panel += ".xpm";
1207 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1208 LibFileSearch("images", new_panel).c_str());
1209 fl_redraw_object(bullets_->bmtable_bullet_panel);
1210 fl_unfreeze_form(bullets_->form);
1215 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1217 /* handle the user input by setting the current bullet depth's pixmap */
1218 /* to that extracted from the current chosen position of the BMTable */
1219 /* Don't forget to free the button's old pixmap first. */
1221 BufferParams & param = lv_->buffer()->params;
1222 int bmtable_button = fl_get_bmtable(ob);
1224 /* try to keep the button held down till another is pushed */
1225 /* fl_set_bmtable(ob, 1, bmtable_button); */
1226 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1227 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1228 fl_set_input(bullets_->input_bullet_latex,
1229 param.temp_bullets[current_bullet_depth].getText().c_str());
1233 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1236 ob = class_->choice_doc_class;
1238 lv_->prohibitInput();
1240 unsigned int tc = combo_doc_class->get() - 1;
1241 if (textclasslist.Load(tc)) {
1242 // we use a copy of the bufferparams because we do not
1243 // want to modify them yet.
1244 BufferParams params = lv_->buffer()->params;
1246 if (lyxrc.auto_reset_options) {
1247 params.textclass = tc;
1248 params.useClassDefaults();
1249 UpdateLayoutDocument(params);
1252 // unable to load new style
1253 WriteAlert(_("Conversion Errors!"),
1254 _("Unable to switch to new document class."),
1255 _("Reverting to original document class."));
1256 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1262 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1268 class_update(params);
1269 paper_update(params);
1270 language_update(params);
1271 options_update(params);
1272 bullets_update(params);