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
47 #include "helper_funcs.h"
49 using Liason::setMinibuffer;
52 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
53 : FormBaseBD(lv, d, _("Document Layout")),
54 ActCell(0), Confirmed(0),
55 current_bullet_panel(0), current_bullet_depth(0), fbullet(0)
57 // let the dialog be shown
58 // This is a permanent connection so we won't bother
59 // storing a copy because we won't be disconnecting.
60 d->showDocument.connect(slot(this, &FormDocument::show));
64 void FormDocument::redraw()
66 if( form() && form()->visible )
67 fl_redraw_form( form() );
71 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
72 if (outer_form && outer_form->visible)
73 fl_redraw_form( outer_form );
77 FL_FORM * FormDocument::form() const
79 if (dialog_.get()) return dialog_->form;
84 void FormDocument::build()
89 dialog_.reset(build_tabbed_document());
91 // Manage the restore, ok, apply, restore and cancel/close buttons
92 bc().setOK(dialog_->button_ok);
93 bc().setApply(dialog_->button_apply);
94 bc().setCancel(dialog_->button_cancel);
95 bc().setRestore(dialog_->button_restore);
96 bc().addReadOnly (dialog_->button_save_defaults);
97 bc().addReadOnly (dialog_->button_reset_defaults);
99 // the document paper form
100 paper_.reset(build_doc_paper());
101 fl_addto_choice(paper_->choice_papersize,
102 _(" Default | Custom | USletter | USlegal "
103 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
104 fl_addto_choice(paper_->choice_paperpackage,
107 "| Very small Margins "
108 "| Very wide Margins "));
110 fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
111 fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
112 fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
113 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
114 fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
115 fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
116 fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
117 fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
118 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
120 // Set input filters on width and height to make them accept only
122 fl_set_input_filter(paper_->input_custom_width,
123 fl_unsigned_float_filter);
124 fl_set_input_filter(paper_->input_custom_height,
125 fl_unsigned_float_filter);
126 fl_set_input_filter(paper_->input_top_margin,
127 fl_unsigned_float_filter);
128 fl_set_input_filter(paper_->input_bottom_margin,
129 fl_unsigned_float_filter);
130 fl_set_input_filter(paper_->input_left_margin,
131 fl_unsigned_float_filter);
132 fl_set_input_filter(paper_->input_right_margin,
133 fl_unsigned_float_filter);
134 fl_set_input_filter(paper_->input_head_height,
135 fl_unsigned_float_filter);
136 fl_set_input_filter(paper_->input_head_sep,
137 fl_unsigned_float_filter);
138 fl_set_input_filter(paper_->input_foot_skip,
139 fl_unsigned_float_filter);
141 // Create the contents of the unit choices
142 // Don't include the "%" terms...
143 std::vector<string> units_vec = getLatexUnits();
144 for (std::vector<string>::iterator it = units_vec.begin();
145 it != units_vec.end(); ++it) {
146 if (contains(*it, "%"))
147 it = units_vec.erase(it, it+1) - 1;
149 string units = getStringFromVector(units_vec, "|");
151 fl_addto_choice(paper_->choice_custom_width_units, units.c_str());
152 fl_addto_choice(paper_->choice_custom_height_units, units.c_str());
153 fl_addto_choice(paper_->choice_top_margin_units, units.c_str());
154 fl_addto_choice(paper_->choice_bottom_margin_units, units.c_str());
155 fl_addto_choice(paper_->choice_left_margin_units, units.c_str());
156 fl_addto_choice(paper_->choice_right_margin_units, units.c_str());
157 fl_addto_choice(paper_->choice_head_height_units, units.c_str());
158 fl_addto_choice(paper_->choice_head_sep_units, units.c_str());
159 fl_addto_choice(paper_->choice_foot_skip_units, units.c_str());
161 bc().addReadOnly (paper_->choice_paperpackage);
162 bc().addReadOnly (paper_->group_radio_orientation);
163 bc().addReadOnly (paper_->radio_portrait);
164 bc().addReadOnly (paper_->radio_landscape);
165 bc().addReadOnly (paper_->choice_papersize);
166 bc().addReadOnly (paper_->check_use_geometry);
167 bc().addReadOnly (paper_->input_custom_width);
168 bc().addReadOnly (paper_->input_custom_height);
169 bc().addReadOnly (paper_->input_top_margin);
170 bc().addReadOnly (paper_->input_bottom_margin);
171 bc().addReadOnly (paper_->input_left_margin);
172 bc().addReadOnly (paper_->input_right_margin);
173 bc().addReadOnly (paper_->input_head_height);
174 bc().addReadOnly (paper_->input_head_sep);
175 bc().addReadOnly (paper_->input_foot_skip);
177 // the document class form
178 class_.reset(build_doc_class());
181 // The language is a combo-box and has to be inserted manually
182 obj = class_->choice_doc_class;
183 fl_deactivate_object(obj);
184 fl_addto_form(class_->form);
185 combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
186 combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
187 dialog_->tabbed_folder);
188 combo_doc_class->shortcut("#C",1);
189 combo_doc_class->setcallback(ComboInputCB, this);
191 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
192 cit != textclasslist.end(); ++cit) {
193 combo_doc_class->addto(cit->description());
196 fl_addto_choice(class_->choice_doc_spacing,
197 _(" Single | OneHalf | Double | Other "));
198 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
199 for (n=0; tex_fonts[n][0]; ++n) {
200 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
202 fl_addto_choice(class_->choice_doc_pagestyle,
203 "default|empty|plain|headings|fancy");
204 fl_addto_choice(class_->choice_doc_skip,
205 _(" Smallskip | Medskip | Bigskip | Length "));
206 fl_addto_choice(class_->choice_default_skip_units, units.c_str());
207 fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
208 fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
209 fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
211 // Set input filters on doc skip to make it accept only
213 fl_set_input_filter(class_->input_doc_skip,
214 fl_unsigned_float_filter);
216 bc().addReadOnly (class_->radio_doc_indent);
217 bc().addReadOnly (class_->radio_doc_skip);
219 bc().addReadOnly (class_->choice_doc_pagestyle);
220 bc().addReadOnly (class_->choice_doc_fonts);
221 bc().addReadOnly (class_->choice_doc_fontsize);
222 bc().addReadOnly (class_->radio_doc_sides_one);
223 bc().addReadOnly (class_->radio_doc_sides_two);
224 bc().addReadOnly (class_->radio_doc_columns_one);
225 bc().addReadOnly (class_->radio_doc_columns_two);
226 bc().addReadOnly (class_->input_doc_extra);
227 bc().addReadOnly (class_->input_doc_skip);
228 bc().addReadOnly (class_->choice_doc_skip);
229 bc().addReadOnly (class_->choice_doc_spacing);
230 bc().addReadOnly (class_->input_doc_spacing);
232 // the document language form
233 language_.reset(build_doc_language());
234 fl_addto_choice(language_->choice_inputenc,
235 "default|auto|latin1|latin2|latin3|latin4|latin5|latin9"
236 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
238 // The language is a combo-box and has to be inserted manually
239 obj = language_->choice_language;
240 fl_deactivate_object(obj);
241 fl_addto_form(language_->form);
242 combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
243 combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
244 dialog_->tabbed_folder);
245 combo_language->shortcut("#L",1);
246 combo_language->setcallback(ComboInputCB, this);
249 for (Languages::const_iterator cit = languages.begin();
250 cit != languages.end(); ++cit) {
251 combo_language->addto(cit->second.lang());
254 fl_addto_choice(language_->choice_quotes_language,
255 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
256 " «text» | »text« "));
258 bc().addReadOnly (language_->choice_inputenc);
259 bc().addReadOnly (language_->choice_quotes_language);
260 bc().addReadOnly (language_->radio_single);
261 bc().addReadOnly (language_->radio_double);
263 // the document options form
264 options_.reset(build_doc_options());
265 fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
266 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
267 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
268 fl_set_counter_step(options_->slider_secnumdepth,1,1);
269 fl_set_counter_step(options_->slider_tocdepth,1,1);
270 fl_set_counter_precision(options_->slider_secnumdepth, 0);
271 fl_set_counter_precision(options_->slider_tocdepth, 0);
272 for (n=0; tex_graphics[n][0]; ++n) {
273 fl_addto_choice(options_->choice_postscript_driver,
276 fl_addto_choice(options_->choice_citation_format,
277 _(" Author-year | Numerical "));
279 bc_.addReadOnly (options_->slider_secnumdepth);
280 bc_.addReadOnly (options_->slider_tocdepth);
281 bc_.addReadOnly (options_->check_use_amsmath);
282 bc_.addReadOnly (options_->check_use_natbib);
283 bc_.addReadOnly (options_->choice_citation_format);
284 bc_.addReadOnly (options_->input_float_placement);
285 bc_.addReadOnly (options_->choice_postscript_driver);
287 // the document bullets form
288 bullets_.reset(build_doc_bullet());
289 fl_addto_choice(bullets_->choice_bullet_size,
290 _(" default | tiny | script | footnote | small |"
291 " normal | large | Large | LARGE | huge | Huge"));
292 fl_set_choice(bullets_->choice_bullet_size, 1);
293 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
294 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
296 bc().addReadOnly (bullets_->bmtable_bullet_panel);
297 bc().addReadOnly (bullets_->choice_bullet_size);
298 bc().addReadOnly (bullets_->input_bullet_latex);
299 bc().addReadOnly (bullets_->radio_bullet_depth);
300 bc().addReadOnly (bullets_->radio_bullet_panel);
302 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
304 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
306 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
308 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
310 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
312 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
313 lyxerr << _("Your version of libXpm is older than 4.7.\n"
314 "The `bullet' tab of the document dialog "
315 "has been disabled") << '\n';
316 fl_deactivate_object(fbullet);
317 fl_set_object_lcol(fbullet, FL_INACTIVE);
322 void FormDocument::apply()
324 if (!lv_->view()->available() || !dialog_.get())
327 bool redo = class_apply();
329 redo = language_apply() || redo;
330 redo = options_apply() || redo;
334 lv_->view()->redoCurrentBuffer();
336 lv_->buffer()->markDirty();
337 setMinibuffer(lv_, _("Document layout set"));
341 void FormDocument::cancel()
343 // this avoids confusion when reopening
344 BufferParams & param = lv_->buffer()->params;
345 param.temp_bullets[0] = param.user_defined_bullets[0];
346 param.temp_bullets[1] = param.user_defined_bullets[1];
347 param.temp_bullets[2] = param.user_defined_bullets[2];
348 param.temp_bullets[3] = param.user_defined_bullets[3];
353 void FormDocument::update()
360 BufferParams const & params = lv_->buffer()->params;
362 setEnabled(dialog_->button_reset_defaults,
363 !params.hasClassDefaults());
365 class_update(params);
366 paper_update(params);
367 language_update(params);
368 options_update(params);
369 bullets_update(params);
373 bool FormDocument::input( FL_OBJECT * ob, long data )
375 State cb = static_cast<State>( data );
378 case CHECKCHOICECLASS:
379 CheckChoiceClass(ob, 0);
381 case CHOICEBULLETSIZE:
382 ChoiceBulletSize(ob, 0);
384 case INPUTBULLETLATEX:
385 InputBulletLaTeX(ob, 0);
402 BulletBMTable(ob, 0);
408 bool const length_input = fl_get_choice(class_->choice_doc_skip) == 4;
409 if (ob == class_->choice_doc_skip) {
410 setEnabled(class_->input_doc_skip, length_input);
411 setEnabled(class_->choice_default_skip_units, length_input);
414 if (ob == class_->choice_doc_spacing)
415 setEnabled(class_->input_doc_spacing,
416 fl_get_choice(class_->choice_doc_spacing) == 4);
418 bool const skip_used = fl_get_button(class_->radio_doc_skip);
419 if (ob == class_->radio_doc_skip ||
420 ob == class_->radio_doc_indent) {
421 setEnabled(class_->choice_doc_skip, skip_used);
422 setEnabled(class_->input_doc_skip, skip_used);
423 setEnabled(class_->choice_default_skip_units, skip_used);
424 // Default unit choice is cm if metric, inches if US paper.
425 int const paperchoice = fl_get_choice(paper_->choice_papersize);
426 bool const metric = paperchoice < 3 || paperchoice > 5;
427 int const default_unit = metric ? 8 : 9;
428 if (strip(fl_get_input(class_->input_doc_skip)).empty())
429 fl_set_choice(class_->choice_default_skip_units,
433 if (ob == options_->check_use_natbib) {
434 setEnabled(options_->choice_citation_format,
435 fl_get_button(options_->check_use_natbib));
438 if (ob == dialog_->button_save_defaults) {
439 lv_->getLyXFunc()->dispatch(LFUN_LAYOUT_SAVE_DEFAULT);
442 if (ob == dialog_->button_reset_defaults) {
443 BufferParams params = lv_->buffer()->params;
444 params.textclass = combo_doc_class->get() - 1;
445 params.useClassDefaults();
446 UpdateLayoutDocument(params);
449 if (ob == paper_->radio_landscape)
450 fl_set_choice(paper_->choice_paperpackage,
451 BufferParams::PACKAGE_NONE + 1);
453 if (ob == paper_->choice_papersize) {
454 int const paperchoice = fl_get_choice(paper_->choice_papersize);
455 bool const custom = paperchoice == 2;
456 bool const a3size = paperchoice == 6;
457 bool const b3size = paperchoice == 9;
458 bool const b4size = paperchoice == 10;
461 fl_set_button(paper_->radio_portrait, 1);
463 bool const use_geom = (custom || a3size || b3size || b4size);
465 fl_set_button(paper_->check_use_geometry, int(use_geom));
467 setEnabled(paper_->input_top_margin, use_geom);
468 setEnabled(paper_->input_bottom_margin, use_geom);
469 setEnabled(paper_->input_left_margin, use_geom);
470 setEnabled(paper_->input_right_margin, use_geom);
471 setEnabled(paper_->input_head_height, use_geom);
472 setEnabled(paper_->input_head_sep, use_geom);
473 setEnabled(paper_->input_foot_skip, use_geom);
474 setEnabled(paper_->choice_top_margin_units, use_geom);
475 setEnabled(paper_->choice_bottom_margin_units, use_geom);
476 setEnabled(paper_->choice_left_margin_units, use_geom);
477 setEnabled(paper_->choice_right_margin_units, use_geom);
478 setEnabled(paper_->choice_head_height_units, use_geom);
479 setEnabled(paper_->choice_head_sep_units, use_geom);
480 setEnabled(paper_->choice_foot_skip_units, use_geom);
481 setEnabled(paper_->choice_custom_width_units, use_geom);
482 setEnabled(paper_->choice_custom_height_units, use_geom);
484 setEnabled(paper_->input_custom_width, custom);
485 setEnabled(paper_->input_custom_height, custom);
486 setEnabled(paper_->choice_custom_width_units, custom);
487 setEnabled(paper_->choice_custom_height_units, custom);
488 setEnabled(paper_->radio_portrait, !custom);
489 setEnabled(paper_->radio_landscape, !custom);
491 // Default unit choice is cm if metric, inches if US paper.
492 bool const metric = paperchoice < 3 || paperchoice > 5;
493 int const default_unit = metric ? 8 : 9;
494 if (strip(fl_get_input(paper_->input_custom_width)).empty())
495 fl_set_choice(paper_->choice_custom_width_units,
497 if (strip(fl_get_input(paper_->input_custom_height)).empty())
498 fl_set_choice(paper_->choice_custom_height_units,
500 if (strip(fl_get_input(paper_->input_top_margin)).empty())
501 fl_set_choice(paper_->choice_top_margin_units,
503 if (strip(fl_get_input(paper_->input_bottom_margin)).empty())
504 fl_set_choice(paper_->choice_bottom_margin_units,
506 if (strip(fl_get_input(paper_->input_left_margin)).empty())
507 fl_set_choice(paper_->choice_left_margin_units,
509 if (strip(fl_get_input(paper_->input_right_margin)).empty())
510 fl_set_choice(paper_->choice_right_margin_units,
512 if (strip(fl_get_input(paper_->input_head_height)).empty())
513 fl_set_choice(paper_->choice_head_height_units,
515 if (strip(fl_get_input(paper_->input_head_sep)).empty())
516 fl_set_choice(paper_->choice_head_sep_units,
518 if (strip(fl_get_input(paper_->input_foot_skip)).empty())
519 fl_set_choice(paper_->choice_foot_skip_units,
523 if (ob == paper_->choice_papersize ||
524 ob == paper_->radio_portrait ||
525 ob == paper_->radio_landscape) {
527 setEnabled(paper_->choice_paperpackage,
528 //either default papersize (preferences)
529 //or document papersize has to be A4
530 (fl_get_choice(paper_->choice_papersize) == 7
531 || fl_get_choice(paper_->choice_papersize) == 1
532 && lyxrc.default_papersize == 5)
533 && fl_get_button(paper_->radio_portrait));
536 if (ob == paper_->choice_paperpackage) {
537 if (fl_get_choice(paper_->choice_paperpackage) != 1) {
538 fl_set_button(paper_->check_use_geometry, 0);
540 setEnabled(paper_->input_top_margin, false);
541 setEnabled(paper_->input_bottom_margin, false);
542 setEnabled(paper_->input_left_margin, false);
543 setEnabled(paper_->input_right_margin, false);
544 setEnabled(paper_->input_head_height, false);
545 setEnabled(paper_->input_head_sep, false);
546 setEnabled(paper_->input_foot_skip, false);
547 setEnabled(paper_->choice_top_margin_units, false);
548 setEnabled(paper_->choice_bottom_margin_units, false);
549 setEnabled(paper_->choice_left_margin_units, false);
550 setEnabled(paper_->choice_right_margin_units, false);
551 setEnabled(paper_->choice_head_height_units, false);
552 setEnabled(paper_->choice_head_sep_units, false);
553 setEnabled(paper_->choice_foot_skip_units, false);
557 if (ob == paper_->check_use_geometry) {
558 //don't allow switching geometry off in custom papersize mode
559 //nor in A3, B3, and B4
560 int const choice = fl_get_choice(paper_->choice_papersize);
561 if (choice == 2 || choice == 6 || choice == 9 || choice == 10)
562 fl_set_button(paper_->check_use_geometry, 1);
564 fl_set_choice(paper_->choice_paperpackage,
565 BufferParams::PACKAGE_NONE + 1);
567 bool const use_geom = fl_get_button(paper_->check_use_geometry);
568 setEnabled(paper_->input_top_margin, use_geom);
569 setEnabled(paper_->input_bottom_margin, use_geom);
570 setEnabled(paper_->input_left_margin, use_geom);
571 setEnabled(paper_->input_right_margin, use_geom);
572 setEnabled(paper_->input_head_height, use_geom);
573 setEnabled(paper_->input_head_sep, use_geom);
574 setEnabled(paper_->input_foot_skip, use_geom);
575 setEnabled(paper_->choice_top_margin_units, use_geom);
576 setEnabled(paper_->choice_bottom_margin_units, use_geom);
577 setEnabled(paper_->choice_left_margin_units, use_geom);
578 setEnabled(paper_->choice_right_margin_units, use_geom);
579 setEnabled(paper_->choice_head_height_units, use_geom);
580 setEnabled(paper_->choice_head_sep_units, use_geom);
581 setEnabled(paper_->choice_foot_skip_units, use_geom);
584 setEnabled(dialog_->button_reset_defaults,
585 lv_->buffer()->params.hasClassDefaults());
589 case CHECKCHOICECLASS:
590 case CHOICEBULLETSIZE:
591 case INPUTBULLETLATEX:
593 return CheckDocumentInput(ob, 0);
602 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
604 FormDocument * pre = static_cast<FormDocument*>(v);
605 if (combox == pre->combo_doc_class.get())
606 pre->CheckChoiceClass(0, 0);
607 pre->bc().valid(pre->CheckDocumentInput(0,0));
611 bool FormDocument::class_apply()
614 BufferParams ¶ms = lv_->buffer()->params;
616 // If default skip is a "Length" but there's no text in the
617 // input field, reset the kind to "Medskip", which is the default.
618 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
619 !*(fl_get_input (class_->input_doc_skip))) {
620 fl_set_choice (class_->choice_doc_skip, 2);
622 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
623 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
624 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
626 unsigned int const new_class = combo_doc_class->get() - 1;
628 if (params.textclass != new_class) {
629 // try to load new_class
630 if (textclasslist.Load(new_class)) {
631 // successfully loaded
633 setMinibuffer(lv_, _("Converting document to new document class..."));
634 int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
635 params.textclass, new_class,
636 lv_->buffer()->paragraph);
640 s = _("One paragraph couldn't be converted");
643 s += _(" paragraphs couldn't be converted");
645 WriteAlert(_("Conversion Errors!"),s,
646 _("into chosen document class"));
649 params.textclass = new_class;
651 // problem changing class -- warn user and retain old style
652 WriteAlert(_("Conversion Errors!"),
653 _("Errors loading new document class."),
654 _("Reverting to original document class."));
655 combo_doc_class->select(int(params.textclass) + 1);
658 BufferParams::PARSEP tmpsep = params.paragraph_separation;
659 if (fl_get_button(class_->radio_doc_indent))
660 params.paragraph_separation = BufferParams::PARSEP_INDENT;
662 params.paragraph_separation = BufferParams::PARSEP_SKIP;
663 if (tmpsep != params.paragraph_separation)
666 VSpace tmpdefskip = params.getDefSkip();
667 switch (fl_get_choice (class_->choice_doc_skip)) {
669 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
672 params.setDefSkip(VSpace(VSpace::MEDSKIP));
675 params.setDefSkip(VSpace(VSpace::BIGSKIP));
679 string const length =
680 getLengthFromWidgets(class_->input_doc_skip,
681 class_->choice_default_skip_units);
683 params.setDefSkip(VSpace(LyXGlueLength(length)));
687 // DocumentDefskipCB assures that this never happens
688 params.setDefSkip(VSpace(VSpace::MEDSKIP));
691 if (!(tmpdefskip == params.getDefSkip()))
694 if (fl_get_button(class_->radio_doc_columns_two))
698 if (fl_get_button(class_->radio_doc_sides_two))
699 params.sides = LyXTextClass::TwoSides;
701 params.sides = LyXTextClass::OneSide;
703 Spacing tmpSpacing = params.spacing;
704 switch (fl_get_choice(class_->choice_doc_spacing)) {
706 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
707 params.spacing.set(Spacing::Single);
710 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
711 params.spacing.set(Spacing::Onehalf);
714 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
715 params.spacing.set(Spacing::Double);
718 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
719 params.spacing.set(Spacing::Other,
720 fl_get_input(class_->input_doc_spacing));
723 if (tmpSpacing != params.spacing)
726 params.options = fl_get_input(class_->input_doc_extra);
732 void FormDocument::paper_apply()
734 BufferParams & params = lv_->buffer()->params;
736 params.papersize2 = char(fl_get_choice(paper_->choice_papersize)-1);
738 params.paperpackage =
739 char(fl_get_choice(paper_->choice_paperpackage)-1);
741 // set params.papersize from params.papersize2 and params.paperpackage
742 lv_->buffer()->setPaperStuff();
744 params.use_geometry = fl_get_button(paper_->check_use_geometry);
746 if (fl_get_button(paper_->radio_landscape))
747 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
749 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
752 getLengthFromWidgets(paper_->input_custom_width,
753 paper_->choice_custom_width_units);
756 getLengthFromWidgets(paper_->input_custom_height,
757 paper_->choice_custom_height_units);
760 getLengthFromWidgets(paper_->input_left_margin,
761 paper_->choice_left_margin_units);
764 getLengthFromWidgets(paper_->input_top_margin,
765 paper_->choice_top_margin_units);
768 getLengthFromWidgets(paper_->input_right_margin,
769 paper_->choice_right_margin_units);
771 params.bottommargin =
772 getLengthFromWidgets(paper_->input_bottom_margin,
773 paper_->choice_bottom_margin_units);
776 getLengthFromWidgets(paper_->input_head_height,
777 paper_->choice_head_height_units);
780 getLengthFromWidgets(paper_->input_head_sep,
781 paper_->choice_head_sep_units);
784 getLengthFromWidgets(paper_->input_foot_skip,
785 paper_->choice_foot_skip_units);
789 bool FormDocument::language_apply()
791 BufferParams & params = lv_->buffer()->params;
792 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
795 switch (fl_get_choice(language_->choice_quotes_language) - 1) {
797 lga = InsetQuotes::EnglishQ;
800 lga = InsetQuotes::SwedishQ;
803 lga = InsetQuotes::GermanQ;
806 lga = InsetQuotes::PolishQ;
809 lga = InsetQuotes::FrenchQ;
812 lga = InsetQuotes::DanishQ;
815 params.quotes_language = lga;
816 if (fl_get_button(language_->radio_single))
817 params.quotes_times = InsetQuotes::SingleQ;
819 params.quotes_times = InsetQuotes::DoubleQ;
821 Language const * old_language = params.language;
822 Language const * new_language =
823 languages.getLanguage(combo_language->getline());
825 new_language = default_language;
827 if (old_language != new_language
828 && old_language->RightToLeft() == new_language->RightToLeft()
829 && !lv_->buffer()->isMultiLingual())
830 lv_->buffer()->changeLanguage(old_language, new_language);
831 if (old_language != new_language) {
834 params.language = new_language;
835 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
841 bool FormDocument::options_apply()
843 BufferParams & params = lv_->buffer()->params;
846 params.graphicsDriver =
847 fl_get_choice_text(options_->choice_postscript_driver);
848 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
849 params.use_natbib = fl_get_button(options_->check_use_natbib);
850 params.use_numerical_citations =
851 fl_get_choice(options_->choice_citation_format)-1;
853 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
854 if (params.secnumdepth != tmpchar)
856 params.secnumdepth = tmpchar;
858 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
860 params.float_placement =
861 fl_get_input(options_->input_float_placement);
867 void FormDocument::bullets_apply()
869 /* update the bullet settings */
870 BufferParams & param = lv_->buffer()->params;
872 // a little bit of loop unrolling
873 param.user_defined_bullets[0] = param.temp_bullets[0];
874 param.user_defined_bullets[1] = param.temp_bullets[1];
875 param.user_defined_bullets[2] = param.temp_bullets[2];
876 param.user_defined_bullets[3] = param.temp_bullets[3];
880 void FormDocument::class_update(BufferParams const & params)
885 LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
887 combo_doc_class->select(
888 textclasslist.DescOfClass(params.textclass));
889 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
890 fl_clear_choice(class_->choice_doc_fontsize);
891 fl_addto_choice(class_->choice_doc_fontsize, "default");
892 fl_addto_choice(class_->choice_doc_fontsize,
893 tclass.opt_fontsize().c_str());
894 fl_set_choice(class_->choice_doc_fontsize,
895 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
896 fl_clear_choice(class_->choice_doc_pagestyle);
897 fl_addto_choice(class_->choice_doc_pagestyle, "default");
898 fl_addto_choice(class_->choice_doc_pagestyle,
899 tclass.opt_pagestyle().c_str());
900 fl_set_choice(class_->choice_doc_pagestyle,
901 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
902 fl_set_button(class_->radio_doc_indent, 0);
903 fl_set_button(class_->radio_doc_skip, 0);
904 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
905 fl_set_button(class_->radio_doc_indent, 1);
907 fl_set_button(class_->radio_doc_skip, 1);
909 bool const input_length = fl_get_choice(class_->choice_doc_skip) == 4;
910 setEnabled(class_->choice_default_skip_units, input_length);
911 setEnabled(class_->input_doc_skip, input_length);
913 switch (params.getDefSkip().kind()) {
914 case VSpace::SMALLSKIP:
915 fl_set_choice (class_->choice_doc_skip, 1);
917 case VSpace::MEDSKIP:
918 fl_set_choice (class_->choice_doc_skip, 2);
920 case VSpace::BIGSKIP:
921 fl_set_choice (class_->choice_doc_skip, 3);
925 int const paperchoice = params.papersize2 + 1;
926 bool const metric = paperchoice < 3 || paperchoice > 5;
927 string const default_unit = metric ? "cm" : "in";
928 string const length = params.getDefSkip().asLyXCommand();
929 updateWidgetsFromLengthString(class_->input_doc_skip,
930 class_->choice_default_skip_units,
931 length, default_unit);
935 fl_set_choice (class_->choice_doc_skip, 2);
938 fl_set_button(class_->radio_doc_sides_one, 0);
939 fl_set_button(class_->radio_doc_sides_two, 0);
940 setEnabled(class_->choice_doc_skip,
941 fl_get_button(class_->radio_doc_skip));
943 if (params.sides == LyXTextClass::TwoSides)
944 fl_set_button(class_->radio_doc_sides_two, 1);
946 fl_set_button(class_->radio_doc_sides_one, 1);
947 fl_set_button(class_->radio_doc_columns_one, 0);
948 fl_set_button(class_->radio_doc_columns_two, 0);
949 if (params.columns == 2)
950 fl_set_button(class_->radio_doc_columns_two, 1);
952 fl_set_button(class_->radio_doc_columns_one, 1);
953 fl_set_input(class_->input_doc_spacing, "");
955 setEnabled(class_->input_doc_spacing, input_length);
957 switch (params.spacing.getSpace()) {
958 case Spacing::Default: // nothing bad should happen with this
959 case Spacing::Single:
961 fl_set_choice(class_->choice_doc_spacing, 1);
963 case Spacing::Onehalf:
965 fl_set_choice(class_->choice_doc_spacing, 2);
967 case Spacing::Double:
969 fl_set_choice(class_->choice_doc_spacing, 3);
973 fl_set_choice(class_->choice_doc_spacing, 4);
975 sprintf(sval,"%g",params.spacing.getValue());
976 fl_set_input(class_->input_doc_spacing, sval);
980 if (!params.options.empty())
981 fl_set_input(class_->input_doc_extra, params.options.c_str());
983 fl_set_input(class_->input_doc_extra, "");
987 void FormDocument::language_update(BufferParams const & params)
989 if (!language_.get())
992 combo_language->select(params.language->lang());
993 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
994 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
995 fl_set_button(language_->radio_single, 0);
996 fl_set_button(language_->radio_double, 0);
997 if (params.quotes_times == InsetQuotes::SingleQ)
998 fl_set_button(language_->radio_single, 1);
1000 fl_set_button(language_->radio_double, 1);
1004 void FormDocument::options_update(BufferParams const & params)
1006 if (!options_.get())
1009 fl_set_choice_text(options_->choice_postscript_driver,
1010 params.graphicsDriver.c_str());
1011 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
1012 fl_set_button(options_->check_use_natbib, params.use_natbib);
1013 fl_set_choice(options_->choice_citation_format,
1014 int(params.use_numerical_citations)+1);
1015 setEnabled(options_->choice_citation_format, params.use_natbib);
1016 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
1017 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
1018 if (!params.float_placement.empty())
1019 fl_set_input(options_->input_float_placement,
1020 params.float_placement.c_str());
1022 fl_set_input(options_->input_float_placement, "");
1026 void FormDocument::paper_update(BufferParams const & params)
1031 fl_set_choice(paper_->choice_papersize, params.papersize2 + 1);
1032 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
1033 fl_set_button(paper_->check_use_geometry, params.use_geometry);
1035 int const paperchoice = fl_get_choice(paper_->choice_papersize);
1036 bool const useCustom = paperchoice == 2;
1037 bool const useGeom = fl_get_button(paper_->check_use_geometry);
1039 fl_set_button(paper_->radio_portrait, 0);
1040 setEnabled(paper_->radio_portrait, !useCustom);
1041 fl_set_button(paper_->radio_landscape, 0);
1042 setEnabled(paper_->radio_landscape, !useCustom);
1044 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1045 fl_set_button(paper_->radio_landscape, 1);
1047 fl_set_button(paper_->radio_portrait, 1);
1048 setEnabled(paper_->choice_paperpackage,
1049 //either default papersize (preferences)
1050 //or document papersize has to be A4
1052 || paperchoice == 1 && lyxrc.default_papersize == 5)
1053 && fl_get_button(paper_->radio_portrait));
1055 // Default unit choice is cm if metric, inches if US paper.
1056 bool const metric = paperchoice < 3 || paperchoice > 5;
1057 string const default_unit = metric ? "cm" : "in";
1058 updateWidgetsFromLengthString(paper_->input_custom_width,
1059 paper_->choice_custom_width_units,
1060 params.paperwidth, default_unit);
1061 setEnabled(paper_->input_custom_width, useCustom);
1062 setEnabled(paper_->choice_custom_width_units, useCustom);
1064 updateWidgetsFromLengthString(paper_->input_custom_height,
1065 paper_->choice_custom_height_units,
1066 params.paperheight, default_unit);
1067 setEnabled(paper_->input_custom_height, useCustom);
1068 setEnabled(paper_->choice_custom_height_units, useCustom);
1070 updateWidgetsFromLengthString(paper_->input_left_margin,
1071 paper_->choice_left_margin_units,
1072 params.leftmargin, default_unit);
1073 setEnabled(paper_->input_left_margin, useGeom);
1074 setEnabled(paper_->choice_left_margin_units, useGeom);
1076 updateWidgetsFromLengthString(paper_->input_top_margin,
1077 paper_->choice_top_margin_units,
1078 params.topmargin, default_unit);
1079 setEnabled(paper_->input_top_margin, useGeom);
1080 setEnabled(paper_->choice_top_margin_units, useGeom);
1082 updateWidgetsFromLengthString(paper_->input_right_margin,
1083 paper_->choice_right_margin_units,
1084 params.rightmargin, default_unit);
1085 setEnabled(paper_->input_right_margin, useGeom);
1086 setEnabled(paper_->choice_right_margin_units, useGeom);
1088 updateWidgetsFromLengthString(paper_->input_bottom_margin,
1089 paper_->choice_bottom_margin_units,
1090 params.bottommargin, default_unit);
1091 setEnabled(paper_->input_bottom_margin, useGeom);
1092 setEnabled(paper_->choice_bottom_margin_units, useGeom);
1094 updateWidgetsFromLengthString(paper_->input_head_height,
1095 paper_->choice_head_height_units,
1096 params.headheight, default_unit);
1097 setEnabled(paper_->input_head_height, useGeom);
1098 setEnabled(paper_->choice_head_height_units, useGeom);
1100 updateWidgetsFromLengthString(paper_->input_head_sep,
1101 paper_->choice_head_sep_units,
1102 params.headsep, default_unit);
1103 setEnabled(paper_->input_head_sep, useGeom);
1104 setEnabled(paper_->choice_head_sep_units, useGeom);
1106 updateWidgetsFromLengthString(paper_->input_foot_skip,
1107 paper_->choice_foot_skip_units,
1108 params.footskip, default_unit);
1109 setEnabled(paper_->input_foot_skip, useGeom);
1110 setEnabled(paper_->choice_foot_skip_units, useGeom);
1112 fl_set_focus_object(paper_->form, paper_->choice_papersize);
1116 void FormDocument::bullets_update(BufferParams const & params)
1118 if (!bullets_.get() ||
1120 (XpmVersion==4 && XpmRevision<7)))
1123 bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
1124 setEnabled(fbullet, !isLinuxDoc);
1126 if (isLinuxDoc) return;
1128 fl_set_button(bullets_->radio_bullet_depth_1, 1);
1129 fl_set_input(bullets_->input_bullet_latex,
1130 params.user_defined_bullets[0].getText().c_str());
1131 fl_set_choice(bullets_->choice_bullet_size,
1132 params.user_defined_bullets[0].getSize() + 2);
1136 void FormDocument::checkReadOnly()
1138 if (bc().readOnly(lv_->buffer()->isReadonly())) {
1139 combo_doc_class->deactivate();
1140 combo_language->deactivate();
1141 fl_set_object_label(dialog_->text_warning,
1142 _("Document is read-only."
1143 " No changes to layout permitted."));
1144 fl_show_object(dialog_->text_warning);
1146 combo_doc_class->activate();
1147 combo_language->activate();
1148 fl_hide_object(dialog_->text_warning);
1153 bool FormDocument::CheckDocumentInput(FL_OBJECT *, long)
1159 // "Synchronize" the choice and the input field, so that it
1160 // is impossible to commit senseless data.
1161 input = fl_get_input (class_->input_doc_skip);
1162 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
1164 else if (fl_get_choice(class_->choice_doc_skip) != 4)
1165 fl_set_input (class_->input_doc_skip, "");
1167 input = fl_get_input(class_->input_doc_spacing);
1168 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
1170 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
1171 fl_set_input (class_->input_doc_spacing, "");
1176 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
1178 BufferParams & param = lv_->buffer()->params;
1180 // convert from 1-6 range to -1-4
1181 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
1182 fl_set_input(bullets_->input_bullet_latex,
1183 param.temp_bullets[current_bullet_depth].getText().c_str());
1187 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
1189 BufferParams & param = lv_->buffer()->params;
1191 param.temp_bullets[current_bullet_depth].
1192 setText(fl_get_input(bullets_->input_bullet_latex));
1196 void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
1198 /* Should I do the following: */
1199 /* 1. change to the panel that the current bullet belongs in */
1200 /* 2. show that bullet as selected */
1201 /* 3. change the size setting to the size of the bullet in Q.*/
1202 /* 4. display the latex equivalent in the latex box */
1204 /* I'm inclined to just go with 3 and 4 at the moment and */
1205 /* maybe try to support the others later */
1206 BufferParams & param = lv_->buffer()->params;
1209 if (cb == BULLETDEPTH1 )
1211 else if (cb == BULLETDEPTH2 )
1213 else if (cb == BULLETDEPTH3 )
1215 else if (cb == BULLETDEPTH4 )
1218 switch (fl_get_button_numb(ob)) {
1220 // right mouse button resets to default
1221 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
1223 current_bullet_depth = data;
1224 fl_set_input(bullets_->input_bullet_latex,
1225 param.temp_bullets[data].getText().c_str());
1226 fl_set_choice(bullets_->choice_bullet_size,
1227 param.temp_bullets[data].getSize() + 2);
1232 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
1234 /* Here we have to change the background pixmap to that selected */
1235 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
1238 if (cb == BULLETPANEL1 )
1240 else if (cb == BULLETPANEL2 )
1242 else if (cb == BULLETPANEL3 )
1244 else if (cb == BULLETPANEL4 )
1246 else if (cb == BULLETPANEL5 )
1248 else if (cb == BULLETPANEL6 )
1251 if (data != current_bullet_panel) {
1252 fl_freeze_form(bullets_->form);
1253 current_bullet_panel = data;
1255 /* free the current pixmap */
1256 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
1259 /* display the new one */
1261 new_panel = "standard";
1264 new_panel = "amssymb";
1267 new_panel = "psnfss1";
1270 new_panel = "psnfss2";
1273 new_panel = "psnfss3";
1276 new_panel = "psnfss4";
1279 /* something very wrong happened */
1280 // play it safe for now but should be an exception
1281 current_bullet_panel = 0; // standard panel
1282 new_panel = "standard";
1285 new_panel += ".xpm";
1286 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
1287 LibFileSearch("images", new_panel).c_str());
1288 fl_redraw_object(bullets_->bmtable_bullet_panel);
1289 fl_unfreeze_form(bullets_->form);
1294 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
1296 /* handle the user input by setting the current bullet depth's pixmap */
1297 /* to that extracted from the current chosen position of the BMTable */
1298 /* Don't forget to free the button's old pixmap first. */
1300 BufferParams & param = lv_->buffer()->params;
1301 int bmtable_button = fl_get_bmtable(ob);
1303 /* try to keep the button held down till another is pushed */
1304 /* fl_set_bmtable(ob, 1, bmtable_button); */
1305 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
1306 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
1307 fl_set_input(bullets_->input_bullet_latex,
1308 param.temp_bullets[current_bullet_depth].getText().c_str());
1312 void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
1315 ob = class_->choice_doc_class;
1317 lv_->prohibitInput();
1319 unsigned int tc = combo_doc_class->get() - 1;
1320 if (textclasslist.Load(tc)) {
1321 // we use a copy of the bufferparams because we do not
1322 // want to modify them yet.
1323 BufferParams params = lv_->buffer()->params;
1325 if (lyxrc.auto_reset_options) {
1326 params.textclass = tc;
1327 params.useClassDefaults();
1328 UpdateLayoutDocument(params);
1331 // unable to load new style
1332 WriteAlert(_("Conversion Errors!"),
1333 _("Unable to switch to new document class."),
1334 _("Reverting to original document class."));
1335 combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
1341 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
1347 class_update(params);
1348 paper_update(params);
1349 language_update(params);
1350 options_update(params);
1351 bullets_update(params);