2 * FormDocument Interface Class Implementation
11 #include "lyx_gui_misc.h"
13 #include FORMS_H_LOCATION
14 #include XPM_H_LOCATION
16 #include "FormDocument.h"
17 #include "form_document.h"
18 #include "xform_macros.h"
22 #include "tex-strings.h"
23 #include "bufferparams.h"
24 #include "insets/insetquotes.h"
27 #include "support/filetools.h"
30 #include "BufferView.h"
33 #include "CutAndPaste.h"
35 #ifdef SIGC_CXX_NAMESPACES
39 #ifdef CXX_WORKING_NAMESPACES
40 using Liason::setMinibuffer;
43 C_RETURNCB(FormDocument, WMHideCB)
44 C_GENERICCB(FormDocument, InputCB)
45 C_GENERICCB(FormDocument, OKCB)
46 C_GENERICCB(FormDocument, ApplyCB)
47 C_GENERICCB(FormDocument, CancelCB)
49 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
50 : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
51 bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
52 status(POPUP_UNMODIFIED)
54 // let the popup be shown
55 // This is a permanent connection so we won't bother
56 // storing a copy because we won't be disconnecting.
57 d->showLayoutDocument.connect(slot(this, &FormDocument::show));
58 current_bullet_depth = 0;
59 current_bullet_panel = 0;
62 FormDocument::~FormDocument()
67 void FormDocument::build()
72 dialog_ = build_tabbed_document();
74 // the document paper form
75 paper_ = build_doc_paper();
76 fl_addto_choice(paper_->choice_papersize2,
77 _(" Default | Custom | USletter | USlegal "
78 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
79 fl_addto_choice(paper_->choice_paperpackage,
81 "| A4 small Margins (only portrait) "
82 "| A4 very small Margins (only portrait) "
83 "| A4 very wide margins (only portrait) "));
84 fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
85 fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
86 fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
87 fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
88 fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
89 fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
90 fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
91 fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
92 fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
94 // the document class form
95 class_ = build_doc_class();
96 fl_clear_choice(class_->choice_doc_class);
97 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
98 cit != textclasslist.end(); ++cit)
100 fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
102 fl_addto_choice(class_->choice_doc_spacing,
103 _(" Single | OneHalf | Double | Other "));
104 fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
105 for (n=0; tex_fonts[n][0]; ++n) {
106 fl_addto_choice(class_->choice_doc_fonts,tex_fonts[n]);
108 fl_addto_choice(class_->choice_doc_pagestyle,
109 "default|empty|plain|headings|fancy");
110 fl_addto_choice(class_->choice_doc_skip,
111 _(" Smallskip | Medskip | Bigskip | Length "));
112 fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
114 // the document language form
115 language_ = build_doc_language();
116 fl_addto_choice(language_->choice_inputenc,
117 "default|auto|latin1|latin2|latin5"
118 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
120 // The language is a combo-box and has to be inserted manually
121 FL_OBJECT * obj = language_->choice_language;
122 fl_addto_form(language_->form_doc_language);
123 combo_language = new Combox(FL_COMBOX_DROPLIST);
124 combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
125 combo_language->shortcut("#L",1);
127 // "default" is not part of the languages array any more.
128 combo_language->addto("default");
129 for(Languages::const_iterator cit = languages.begin();
130 cit != languages.end(); ++cit) {
131 combo_language->addto((*cit).second.lang().c_str());
134 fl_addto_choice(language_->choice_quotes_language,
135 _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
136 " «text» | »text« "));
138 // the document options form
139 options_ = build_doc_options();
140 fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
141 fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
142 fl_set_counter_step(options_->slider_secnumdepth,1,1);
143 fl_set_counter_step(options_->slider_tocdepth,1,1);
144 fl_set_counter_precision(options_->slider_secnumdepth, 0);
145 fl_set_counter_precision(options_->slider_tocdepth, 0);
146 for (n=0; tex_graphics[n][0]; ++n) {
147 fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
150 // the document bullets form
151 bullets_ = build_doc_bullet();
152 fl_addto_choice(bullets_->choice_bullet_size,
153 _(" default | tiny | script | footnote | small |"
154 " normal | large | Large | LARGE | huge | Huge"));
155 fl_set_choice(bullets_->choice_bullet_size, 1);
156 fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
157 fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
159 fl_set_form_atclose(dialog_->form_tabbed_document,
160 FormDocument::WMHideCB, 0);
161 fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
162 class_->form_doc_class);
163 fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
164 paper_->form_doc_paper);
165 fl_addto_tabfolder(dialog_->tabbed_folder,_("Language"),
166 language_->form_doc_language);
167 fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"),
168 options_->form_doc_options);
169 fbullet = fl_addto_tabfolder(dialog_->tabbed_folder,_("Bullets"),
170 bullets_->form_doc_bullet);
171 if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
172 lyxerr << _("Your version of libXpm is older than 4.7.\n"
173 "The `bullet' tab of the document popup "
174 "has been disabled") << '\n';
175 fl_deactivate_object(fbullet);
176 fl_set_object_lcol(fbullet, FL_INACTIVE);
180 void FormDocument::show()
185 update(); // make sure its up-to-date
186 if (dialog_->form_tabbed_document->visible) {
187 fl_raise_form(dialog_->form_tabbed_document);
189 fl_show_form(dialog_->form_tabbed_document,
190 FL_PLACE_MOUSE | FL_FREE_SIZE,
191 FL_TRANSIENT, _("Document Layout"));
192 u_ = d_->updateBufferDependent.connect(
193 slot(this, &FormDocument::update));
194 h_ = d_->hideBufferDependent.connect(
195 slot(this, &FormDocument::hide));
199 void FormDocument::hide()
201 if (dialog_->form_tabbed_document->visible) {
202 fl_hide_form(dialog_->form_tabbed_document);
208 void FormDocument::apply()
210 if (!lv_->view()->available() || !dialog_)
216 redo = class_apply();
218 redo = language_apply() || redo;
219 redo = options_apply() || redo;
223 lv_->view()->redoCurrentBuffer();
225 lv_->buffer()->markDirty();
226 setMinibuffer(lv_, _("Document layout set"));
230 bool FormDocument::class_apply()
233 BufferParams ¶ms = lv_->buffer()->params;
235 // If default skip is a "Length" but there's no text in the
236 // input field, reset the kind to "Medskip", which is the default.
237 if ((fl_get_choice (class_->choice_doc_skip) == 4) &&
238 !*(fl_get_input (class_->input_doc_skip))) {
239 fl_set_choice (class_->choice_doc_skip, 2);
241 params.fonts = fl_get_choice_text(class_->choice_doc_fonts);
242 params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
243 params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
245 unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
246 if (params.textclass != new_class) {
247 // try to load new_class
248 if (textclasslist.Load(new_class)) {
249 // successfully loaded
251 setMinibuffer(lv_, _("Converting document to new document class..."));
253 int ret = cap.SwitchLayoutsBetweenClasses(
254 params.textclass, new_class,
255 lv_->buffer()->paragraph);
259 s = _("One paragraph couldn't be converted");
262 s += _(" paragraphs couldn't be converted");
264 WriteAlert(_("Conversion Errors!"),s,
265 _("into chosen document class"));
268 params.textclass = new_class;
270 // problem changing class -- warn user and retain old style
271 WriteAlert(_("Conversion Errors!"),
272 _("Errors loading new document class."),
273 _("Reverting to original document class."));
274 fl_set_choice(class_->choice_doc_class,
275 params.textclass + 1);
278 char tmpsep = params.paragraph_separation;
279 if (fl_get_button(class_->radio_doc_indent))
280 params.paragraph_separation = BufferParams::PARSEP_INDENT;
282 params.paragraph_separation = BufferParams::PARSEP_SKIP;
283 if (tmpsep != params.paragraph_separation)
286 VSpace tmpdefskip = params.getDefSkip();
287 switch (fl_get_choice (class_->choice_doc_skip)) {
289 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
292 params.setDefSkip(VSpace(VSpace::MEDSKIP));
295 params.setDefSkip(VSpace(VSpace::BIGSKIP));
299 (VSpace(LyXGlueLength(fl_get_input(class_->input_doc_skip))));
301 // DocumentDefskipCB assures that this never happens
303 params.setDefSkip(VSpace(VSpace::MEDSKIP));
306 if (!(tmpdefskip == params.getDefSkip()))
309 if (fl_get_button(class_->radio_doc_columns_two))
313 if (fl_get_button(class_->radio_doc_sides_two))
314 params.sides = LyXTextClass::TwoSides;
316 params.sides = LyXTextClass::OneSide;
318 Spacing tmpSpacing = params.spacing;
319 switch(fl_get_choice(class_->choice_doc_spacing)) {
321 lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
322 params.spacing.set(Spacing::Single);
325 lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
326 params.spacing.set(Spacing::Onehalf);
329 lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
330 params.spacing.set(Spacing::Double);
333 lyxerr[Debug::INFO] << "Spacing: OTHER\n";
334 params.spacing.set(Spacing::Other,
335 fl_get_input(class_->input_doc_spacing));
338 if (tmpSpacing != params.spacing)
341 params.options = fl_get_input(class_->input_doc_extra);
346 void FormDocument::paper_apply()
349 ¶ms = lv_->buffer()->params;
351 params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
352 params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
353 params.use_geometry = fl_get_button(paper_->push_use_geometry);
354 if (fl_get_button(paper_->radio_landscape))
355 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
357 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
358 params.paperwidth = fl_get_input(paper_->input_custom_width);
359 params.paperheight = fl_get_input(paper_->input_custom_height);
360 params.leftmargin = fl_get_input(paper_->input_left_margin);
361 params.topmargin = fl_get_input(paper_->input_top_margin);
362 params.rightmargin = fl_get_input(paper_->input_right_margin);
363 params.bottommargin = fl_get_input(paper_->input_bottom_margin);
364 params.headheight = fl_get_input(paper_->input_head_height);
365 params.headsep = fl_get_input(paper_->input_head_sep);
366 params.footskip = fl_get_input(paper_->input_foot_skip);
367 lv_->buffer()->setPaperStuff();
370 bool FormDocument::language_apply()
373 ¶ms = lv_->buffer()->params;
374 InsetQuotes::quote_language
375 lga = InsetQuotes::EnglishQ;
378 switch(fl_get_choice(language_->choice_quotes_language) - 1) {
380 lga = InsetQuotes::EnglishQ;
383 lga = InsetQuotes::SwedishQ;
386 lga = InsetQuotes::GermanQ;
389 lga = InsetQuotes::PolishQ;
392 lga = InsetQuotes::FrenchQ;
395 lga = InsetQuotes::DanishQ;
398 params.quotes_language = lga;
399 if (fl_get_button(language_->radio_single))
400 params.quotes_times = InsetQuotes::SingleQ;
402 params.quotes_times = InsetQuotes::DoubleQ;
404 Language const * old_language = params.language_info;
405 params.language = combo_language->getline();
406 Languages::iterator lit = languages.find(params.language);
408 Language const * new_language;
409 if (lit != languages.end())
410 new_language = &(*lit).second;
412 new_language = default_language;
414 if (old_language != new_language
415 && old_language->RightToLeft() == new_language->RightToLeft()
416 && !lv_->buffer()->isMultiLingual())
417 lv_->buffer()->ChangeLanguage(old_language, new_language);
418 if (old_language != new_language) {
421 params.language_info = new_language;
422 params.inputenc = fl_get_choice_text(language_->choice_inputenc);
427 bool FormDocument::options_apply()
430 ¶ms = lv_->buffer()->params;
434 params.graphicsDriver =
435 fl_get_choice_text(options_->choice_postscript_driver);
436 params.use_amsmath = fl_get_button(options_->check_use_amsmath);
438 int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
439 if (params.secnumdepth != tmpchar)
441 params.secnumdepth = tmpchar;
443 params.tocdepth = int(fl_get_counter_value(options_->slider_tocdepth));
445 params.float_placement =
446 fl_get_input(options_->input_float_placement);
451 void FormDocument::bullets_apply()
453 /* update the bullet settings */
454 BufferParams & param = lv_->buffer()->params;
456 // a little bit of loop unrolling
457 param.user_defined_bullets[0] = param.temp_bullets[0];
458 param.user_defined_bullets[1] = param.temp_bullets[1];
459 param.user_defined_bullets[2] = param.temp_bullets[2];
460 param.user_defined_bullets[3] = param.temp_bullets[3];
463 void FormDocument::cancel()
465 // this avoids confusion when reopening
466 BufferParams & param = lv_->buffer()->params;
467 param.temp_bullets[0] = param.user_defined_bullets[0];
468 param.temp_bullets[1] = param.user_defined_bullets[1];
469 param.temp_bullets[2] = param.user_defined_bullets[2];
470 param.temp_bullets[3] = param.user_defined_bullets[3];
473 void FormDocument::update()
477 fl_hide_object(dialog_->text_warning);
478 EnableDocumentLayout();
479 if (lv_->buffer()->isReadonly()) {
480 DisableDocumentLayout();
481 fl_set_object_label(dialog_->text_warning,
482 _("Document is read-only."
483 " No changes to layout permitted."));
484 fl_show_object(dialog_->text_warning);
493 void FormDocument::class_update()
498 const & params = lv_->buffer()->params;
500 const & tclass = textclasslist.TextClass(params.textclass);
502 fl_set_choice_text(class_->choice_doc_class,
503 textclasslist.DescOfClass(params.textclass).c_str());
504 fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
505 fl_clear_choice(class_->choice_doc_fontsize);
506 fl_addto_choice(class_->choice_doc_fontsize, "default");
507 fl_addto_choice(class_->choice_doc_fontsize,
508 tclass.opt_fontsize().c_str());
509 fl_set_choice(class_->choice_doc_fontsize,
510 tokenPos(tclass.opt_fontsize(), '|', params.fontsize)+2);
511 fl_clear_choice(class_->choice_doc_pagestyle);
512 fl_addto_choice(class_->choice_doc_pagestyle, "default");
513 fl_addto_choice(class_->choice_doc_pagestyle,
514 tclass.opt_pagestyle().c_str());
515 fl_set_choice(class_->choice_doc_pagestyle,
516 tokenPos(tclass.opt_pagestyle(), '|', params.pagestyle)+2);
517 fl_set_button(class_->radio_doc_indent, 0);
518 fl_set_button(class_->radio_doc_skip, 0);
519 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
520 fl_set_button(class_->radio_doc_indent, 1);
522 fl_set_button(class_->radio_doc_skip, 1);
523 switch (params.getDefSkip().kind()) {
524 case VSpace::SMALLSKIP:
525 fl_set_choice (class_->choice_doc_skip, 1);
527 case VSpace::MEDSKIP:
528 fl_set_choice (class_->choice_doc_skip, 2);
530 case VSpace::BIGSKIP:
531 fl_set_choice (class_->choice_doc_skip, 3);
534 fl_set_choice (class_->choice_doc_skip, 4);
535 fl_set_input (class_->input_doc_skip,
536 params.getDefSkip().asLyXCommand().c_str());
539 fl_set_choice (class_->choice_doc_skip, 2);
542 fl_set_button(class_->radio_doc_sides_one, 0);
543 fl_set_button(class_->radio_doc_sides_two, 0);
544 if (params.sides == 2)
545 fl_set_button(class_->radio_doc_sides_two, 1);
547 fl_set_button(class_->radio_doc_sides_one, 1);
548 fl_set_button(class_->radio_doc_columns_one, 0);
549 fl_set_button(class_->radio_doc_columns_two, 0);
550 if (params.columns == 2)
551 fl_set_button(class_->radio_doc_columns_two, 1);
553 fl_set_button(class_->radio_doc_columns_one, 1);
554 fl_set_input(class_->input_doc_spacing, "");
555 switch (params.spacing.getSpace()) {
556 case Spacing::Default: // nothing bad should happen with this
557 case Spacing::Single:
559 fl_set_choice(class_->choice_doc_spacing, 1);
561 case Spacing::Onehalf:
563 fl_set_choice(class_->choice_doc_spacing, 2);
565 case Spacing::Double:
567 fl_set_choice(class_->choice_doc_spacing, 3);
571 fl_set_choice(class_->choice_doc_spacing, 4);
573 sprintf(sval,"%g",params.spacing.getValue());
574 fl_set_input(class_->input_doc_spacing, sval);
578 if (!params.options.empty())
579 fl_set_input(class_->input_doc_extra, params.options.c_str());
581 fl_set_input(class_->input_doc_extra, "");
584 void FormDocument::language_update()
590 ¶ms = lv_->buffer()->params;
592 combo_language->select_text(params.language.c_str());
593 fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
594 fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
595 fl_set_button(language_->radio_single, 0);
596 fl_set_button(language_->radio_double, 0);
597 if (params.quotes_times == InsetQuotes::SingleQ)
598 fl_set_button(language_->radio_single, 1);
600 fl_set_button(language_->radio_double, 1);
603 void FormDocument::options_update()
609 ¶ms = lv_->buffer()->params;
611 fl_set_choice_text(options_->choice_postscript_driver,
612 params.graphicsDriver.c_str());
613 fl_set_button(options_->check_use_amsmath, params.use_amsmath);
614 fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
615 fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
616 if (!params.float_placement.empty())
617 fl_set_input(options_->input_float_placement,
618 params.float_placement.c_str());
620 fl_set_input(options_->input_float_placement, "");
623 void FormDocument::paper_update()
628 ¶ms = lv_->buffer()->params;
630 fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
631 fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1);
632 fl_set_button(paper_->push_use_geometry, params.use_geometry);
633 fl_set_button(paper_->radio_portrait, 0);
634 fl_set_button(paper_->radio_landscape, 0);
635 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
636 fl_set_button(paper_->radio_landscape, 1);
638 fl_set_button(paper_->radio_portrait, 1);
639 fl_set_input(paper_->input_custom_width, params.paperwidth.c_str());
640 fl_set_input(paper_->input_custom_height, params.paperheight.c_str());
641 fl_set_input(paper_->input_left_margin, params.leftmargin.c_str());
642 fl_set_input(paper_->input_top_margin, params.topmargin.c_str());
643 fl_set_input(paper_->input_right_margin, params.rightmargin.c_str());
644 fl_set_input(paper_->input_bottom_margin, params.bottommargin.c_str());
645 fl_set_input(paper_->input_head_height, params.headheight.c_str());
646 fl_set_input(paper_->input_head_sep, params.headsep.c_str());
647 fl_set_input(paper_->input_foot_skip, params.footskip.c_str());
648 fl_set_focus_object(paper_->form_doc_paper, paper_->choice_papersize2);
651 void FormDocument::bullets_update()
653 if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
656 if (lv_->buffer()->isLinuxDoc()) {
657 fl_deactivate_object(fbullet);
658 fl_set_object_lcol(fbullet, FL_INACTIVE);
661 fl_activate_object(fbullet);
662 fl_set_object_lcol(fbullet, FL_BLACK);
664 if (lv_->buffer()->isReadonly()) {
665 fl_deactivate_object (bullets_->bmtable_bullet_panel);
666 fl_deactivate_object (bullets_->choice_bullet_size);
667 fl_deactivate_object (bullets_->input_bullet_latex);
669 fl_activate_object (bullets_->bmtable_bullet_panel);
670 fl_activate_object (bullets_->choice_bullet_size);
671 fl_activate_object (bullets_->input_bullet_latex);
675 ¶ms = lv_->buffer()->params;
677 fl_set_button(bullets_->radio_bullet_depth_1, 1);
678 fl_set_input(bullets_->input_bullet_latex,
679 params.user_defined_bullets[0].c_str());
680 fl_set_choice(bullets_->choice_bullet_size,
681 params.user_defined_bullets[0].getSize() + 2);
684 void FormDocument::free()
689 fl_free_form(class_->form_doc_class);
694 fl_free_form(paper_->form_doc_paper);
699 delete combo_language;
700 fl_free_form(language_->form_doc_language);
705 fl_free_form(options_->form_doc_options);
710 fl_free_form(bullets_->form_doc_bullet);
714 fl_free_form(dialog_->form_tabbed_document);
720 int FormDocument::WMHideCB(FL_FORM * form, void *)
722 // Ensure that the signals (u and h) are disconnected even if the
723 // window manager is used to close the popup.
724 FormDocument * pre = (FormDocument*)form->u_vdata;
729 void FormDocument::CancelCB(FL_OBJECT * ob, long)
731 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
736 void FormDocument::ApplyCB(FL_OBJECT * ob, long)
738 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
742 void FormDocument::OKCB(FL_OBJECT * ob, long)
744 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
749 void FormDocument::InputCB(FL_OBJECT * ob, long)
751 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
752 pre->CheckDocumentInput(ob,0);
755 void FormDocument::checkMarginValues()
759 allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
760 !strlen(fl_get_input(paper_->input_bottom_margin)) &&
761 !strlen(fl_get_input(paper_->input_left_margin)) &&
762 !strlen(fl_get_input(paper_->input_right_margin)) &&
763 !strlen(fl_get_input(paper_->input_head_height)) &&
764 !strlen(fl_get_input(paper_->input_head_sep)) &&
765 !strlen(fl_get_input(paper_->input_foot_skip)) &&
766 !strlen(fl_get_input(paper_->input_custom_width)) &&
767 !strlen(fl_get_input(paper_->input_custom_height)));
769 fl_set_button(paper_->push_use_geometry, 1);
772 void FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
779 ActivateDocumentButtons();
781 if (ob == paper_->choice_papersize2) {
782 val = fl_get_choice(paper_->choice_papersize2)-1;
783 if (val == BufferParams::VM_PAPER_DEFAULT) {
784 fl_set_button(paper_->push_use_geometry, 0);
787 if ((val != BufferParams::VM_PAPER_USLETTER) &&
788 (val != BufferParams::VM_PAPER_USLEGAL) &&
789 (val != BufferParams::VM_PAPER_USEXECUTIVE) &&
790 (val != BufferParams::VM_PAPER_A4) &&
791 (val != BufferParams::VM_PAPER_A5) &&
792 (val != BufferParams::VM_PAPER_B5)) {
793 fl_set_button(paper_->push_use_geometry, 1);
795 fl_set_choice(paper_->choice_paperpackage,
796 BufferParams::PACKAGE_NONE + 1);
798 } else if (ob == paper_->choice_paperpackage) {
799 val = fl_get_choice(paper_->choice_paperpackage)-1;
800 if (val != BufferParams::PACKAGE_NONE) {
801 fl_set_choice(paper_->choice_papersize2,
802 BufferParams::VM_PAPER_DEFAULT + 1);
803 fl_set_button(paper_->push_use_geometry, 0);
805 } else if (ob == class_->input_doc_spacing) {
806 input = fl_get_input(class_->input_doc_spacing);
808 fl_set_choice (class_->choice_doc_spacing, 1);
810 fl_set_choice(class_->choice_doc_spacing, 4);
813 // this has to be all out of if/elseif because it has to deactivate
814 // the document buttons and so the whole stuff has to be tested again.
815 str = fl_get_input(paper_->input_custom_width);
816 ok = ok && (str.empty() || isValidLength(str));
817 str = fl_get_input(paper_->input_custom_height);
818 ok = ok && (str.empty() || isValidLength(str));
819 str = fl_get_input(paper_->input_left_margin);
820 ok = ok && (str.empty() || isValidLength(str));
821 str = fl_get_input(paper_->input_right_margin);
822 ok = ok && (str.empty() || isValidLength(str));
823 str = fl_get_input(paper_->input_top_margin);
824 ok = ok && (str.empty() || isValidLength(str));
825 str = fl_get_input(paper_->input_bottom_margin);
826 ok = ok && (str.empty() || isValidLength(str));
827 str = fl_get_input(paper_->input_head_height);
828 ok = ok && (str.empty() || isValidLength(str));
829 str = fl_get_input(paper_->input_head_sep);
830 ok = ok && (str.empty() || isValidLength(str));
831 str = fl_get_input(paper_->input_foot_skip);
832 ok = ok && (str.empty() || isValidLength(str));
833 // "Synchronize" the choice and the input field, so that it
834 // is impossible to commit senseless data.
835 input = fl_get_input (class_->input_doc_skip);
836 if (ob == class_->input_doc_skip) {
838 fl_set_choice (class_->choice_doc_skip, 2);
839 } else if (isValidGlueLength (input)) {
840 fl_set_choice (class_->choice_doc_skip, 4);
842 fl_set_choice(class_->choice_doc_skip, 4);
846 if (*input && !isValidGlueLength(input))
849 if ((fl_get_choice(class_->choice_doc_skip) == 4) && !*input)
851 else if (fl_get_choice(class_->choice_doc_skip) != 4)
852 fl_set_input (class_->input_doc_skip, "");
854 fprintf(stderr,"%d\n",fl_get_choice(class_->choice_doc_spacing));
855 if ((fl_get_choice(class_->choice_doc_spacing) == 4) && !*input)
857 else if (fl_get_choice(class_->choice_doc_spacing) != 4)
858 fl_set_input (class_->input_doc_spacing, "");
860 DeactivateDocumentButtons();
863 void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
865 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
866 pre->ChoiceBulletSize(ob,0);
869 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
871 BufferParams & param = lv_->buffer()->params;
873 // convert from 1-6 range to -1-4
874 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
875 fl_set_input(bullets_->input_bullet_latex,
876 param.temp_bullets[current_bullet_depth].c_str());
879 void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
881 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
882 pre->InputBulletLaTeX(ob,0);
885 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
887 BufferParams & param = lv_->buffer()->params;
889 param.temp_bullets[current_bullet_depth].
890 setText(fl_get_input(bullets_->input_bullet_latex));
893 void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
895 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
896 pre->BulletDepth(ob,0);
899 void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
901 /* Should I do the following: */
902 /* 1. change to the panel that the current bullet belongs in */
903 /* 2. show that bullet as selected */
904 /* 3. change the size setting to the size of the bullet in Q.*/
905 /* 4. display the latex equivalent in the latex box */
907 /* I'm inclined to just go with 3 and 4 at the moment and */
908 /* maybe try to support the others later */
909 BufferParams & param = lv_->buffer()->params;
911 switch (fl_get_button_numb(ob)) {
913 // right mouse button resets to default
914 param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
916 current_bullet_depth = data;
917 fl_set_input(bullets_->input_bullet_latex,
918 param.temp_bullets[data].c_str());
919 fl_set_choice(bullets_->choice_bullet_size,
920 param.temp_bullets[data].getSize() + 2);
924 void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
926 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
927 pre->BulletPanel(ob,data);
930 void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
932 /* Here we have to change the background pixmap to that selected */
933 /* by the user. (eg. standard.xpm, psnfss1.xpm etc...) */
935 if (data != current_bullet_panel) {
936 fl_freeze_form(bullets_->form_doc_bullet);
937 current_bullet_panel = data;
939 /* free the current pixmap */
940 fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
943 /* display the new one */
945 new_panel = "standard";
948 new_panel = "amssymb";
951 new_panel = "psnfss1";
954 new_panel = "psnfss2";
957 new_panel = "psnfss3";
960 new_panel = "psnfss4";
963 /* something very wrong happened */
964 // play it safe for now but should be an exception
965 current_bullet_panel = 0; // standard panel
966 new_panel = "standard";
970 fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
971 LibFileSearch("images", new_panel.c_str()).c_str());
972 fl_redraw_object(bullets_->bmtable_bullet_panel);
973 fl_unfreeze_form(bullets_->form_doc_bullet);
977 void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
979 FormDocument * pre = (FormDocument*)ob->form->u_vdata;
980 pre->BulletBMTable(ob,0);
983 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
985 /* handle the user input by setting the current bullet depth's pixmap */
986 /* to that extracted from the current chosen position of the BMTable */
987 /* Don't forget to free the button's old pixmap first. */
989 BufferParams & param = lv_->buffer()->params;
990 int bmtable_button = fl_get_bmtable(ob);
992 /* try to keep the button held down till another is pushed */
993 /* fl_set_bmtable(ob, 1, bmtable_button); */
994 param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
995 param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
996 fl_set_input(bullets_->input_bullet_latex,
997 param.temp_bullets[current_bullet_depth].c_str());
1000 void FormDocument::DeactivateDocumentButtons()
1002 fl_deactivate_object(dialog_->button_ok);
1003 fl_deactivate_object(dialog_->button_apply);
1004 fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
1005 fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
1008 void FormDocument::ActivateDocumentButtons()
1010 fl_activate_object(dialog_->button_ok);
1011 fl_activate_object(dialog_->button_apply);
1012 fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
1013 fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
1016 void FormDocument::EnableDocumentLayout()
1018 ActivateDocumentButtons ();
1019 fl_activate_object (class_->radio_doc_indent);
1020 fl_activate_object (class_->radio_doc_skip);
1021 fl_activate_object (class_->choice_doc_class);
1022 fl_activate_object (class_->choice_doc_pagestyle);
1023 fl_activate_object (class_->choice_doc_fonts);
1024 fl_activate_object (class_->choice_doc_fontsize);
1025 fl_activate_object (class_->radio_doc_sides_one);
1026 fl_activate_object (class_->radio_doc_sides_two);
1027 fl_activate_object (class_->radio_doc_columns_one);
1028 fl_activate_object (class_->radio_doc_columns_two);
1029 fl_activate_object (class_->input_doc_extra);
1030 fl_activate_object (class_->input_doc_skip);
1031 fl_activate_object (class_->choice_doc_skip);
1032 fl_activate_object (class_->choice_doc_spacing);
1033 fl_activate_object (class_->input_doc_spacing);
1035 fl_activate_object (language_->choice_language);
1036 combo_language->activate();
1037 fl_activate_object (language_->choice_language);
1038 fl_activate_object (language_->choice_inputenc);
1040 fl_activate_object (options_->slider_secnumdepth);
1041 fl_activate_object (options_->slider_tocdepth);
1042 fl_activate_object (options_->check_use_amsmath);
1043 fl_activate_object (options_->input_float_placement);
1044 fl_activate_object (options_->choice_postscript_driver);
1046 fl_activate_object (paper_->choice_paperpackage);
1047 fl_activate_object (paper_->greoup_radio_orientation);
1048 fl_activate_object (paper_->radio_portrait);
1049 fl_activate_object (paper_->radio_landscape);
1050 fl_activate_object (paper_->choice_papersize2);
1051 fl_activate_object (paper_->push_use_geometry);
1052 fl_activate_object (paper_->input_custom_width);
1053 fl_activate_object (paper_->input_custom_height);
1054 fl_activate_object (paper_->input_top_margin);
1055 fl_activate_object (paper_->input_bottom_margin);
1056 fl_activate_object (paper_->input_left_margin);
1057 fl_activate_object (paper_->input_right_margin);
1058 fl_activate_object (paper_->input_head_height);
1059 fl_activate_object (paper_->input_head_sep);
1060 fl_activate_object (paper_->input_foot_skip);
1063 void FormDocument::DisableDocumentLayout()
1065 DeactivateDocumentButtons ();
1066 fl_deactivate_object (class_->radio_doc_indent);
1067 fl_deactivate_object (class_->radio_doc_skip);
1068 fl_deactivate_object (class_->choice_doc_class);
1069 fl_deactivate_object (class_->choice_doc_pagestyle);
1070 fl_deactivate_object (class_->choice_doc_fonts);
1071 fl_deactivate_object (class_->choice_doc_fontsize);
1072 fl_deactivate_object (class_->radio_doc_sides_one);
1073 fl_deactivate_object (class_->radio_doc_sides_two);
1074 fl_deactivate_object (class_->radio_doc_columns_one);
1075 fl_deactivate_object (class_->radio_doc_columns_two);
1076 fl_deactivate_object (class_->input_doc_extra);
1077 fl_deactivate_object (class_->input_doc_skip);
1078 fl_deactivate_object (class_->choice_doc_skip);
1079 fl_deactivate_object (class_->choice_doc_spacing);
1080 fl_deactivate_object (class_->input_doc_spacing);
1082 fl_deactivate_object (language_->choice_language);
1083 combo_language->deactivate();
1084 fl_deactivate_object (language_->choice_inputenc);
1086 fl_deactivate_object (options_->slider_secnumdepth);
1087 fl_deactivate_object (options_->slider_tocdepth);
1088 fl_deactivate_object (options_->check_use_amsmath);
1089 fl_deactivate_object (options_->input_float_placement);
1090 fl_deactivate_object (options_->choice_postscript_driver);
1092 fl_deactivate_object (paper_->choice_paperpackage);
1093 fl_deactivate_object (paper_->greoup_radio_orientation);
1094 fl_deactivate_object (paper_->radio_portrait);
1095 fl_deactivate_object (paper_->radio_landscape);
1096 fl_deactivate_object (paper_->choice_papersize2);
1097 fl_deactivate_object (paper_->push_use_geometry);
1098 fl_deactivate_object (paper_->input_custom_width);
1099 fl_deactivate_object (paper_->input_custom_height);
1100 fl_deactivate_object (paper_->input_top_margin);
1101 fl_deactivate_object (paper_->input_bottom_margin);
1102 fl_deactivate_object (paper_->input_left_margin);
1103 fl_deactivate_object (paper_->input_right_margin);
1104 fl_deactivate_object (paper_->input_head_height);
1105 fl_deactivate_object (paper_->input_head_sep);
1106 fl_deactivate_object (paper_->input_foot_skip);
1109 void FormDocument::SetDocumentClassChoice(vector<string> const & choices)
1111 vector<string>::const_iterator cit = choices.begin();
1113 fl_clear_choice(class_->choice_doc_class);
1114 for (; cit != choices.end(); ++cit)
1115 fl_addto_choice(class_->choice_doc_class,(*cit).c_str());