1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
24 #include FORMS_H_LOCATION
28 #include "layout_forms.h"
29 #include "print_form.h"
30 #include "tex-strings.h"
32 #include "latexoptions.h"
37 #include "lyxserver.h"
40 #include "lyx_gui_misc.h"
41 #include "lyxlookup.h"
42 #include "bufferlist.h"
44 #include "ColorHandler.h"
46 #ifdef TWO_COLOR_ICONS
47 #include "banner_bw.xbm"
54 FD_form_title * fd_form_title;
55 FD_form_paragraph * fd_form_paragraph;
56 FD_form_paragraph_extra * fd_form_paragraph_extra;
57 FD_form_character * fd_form_character;
58 FD_form_document * fd_form_document;
59 FD_form_paper * fd_form_paper;
60 FD_form_table_options * fd_form_table_options;
61 FD_form_table_extra * fd_form_table_extra;
62 FD_form_quotes * fd_form_quotes;
63 FD_form_preamble * fd_form_preamble;
64 FD_form_table * fd_form_table;
65 FD_form_sendto * fd_form_sendto;
66 FD_form_figure * fd_form_figure;
67 FD_form_screen * fd_form_screen;
68 FD_form_toc * fd_form_toc;
69 FD_form_ref * fd_form_ref;
70 FD_LaTeXOptions * fd_latex_options; // from latexoptions.h
71 FD_LaTeXLog * fd_latex_log; // from latexoptions.h
72 Combox * combo_language;
73 Combox * combo_language2;
75 extern LyXServer * lyxserver;
76 extern bool finished; // flag, that we are quitting the program
77 extern BufferList bufferlist;
81 {"-width", "*.width", XrmoptionSepArg, "690"},
82 {"-height", "*.height", XrmoptionSepArg, "510"},
83 {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
84 {"-ypos", "*.ypos", XrmoptionSepArg, "-1"}
91 bool cursor_follows_scrollbar;
96 {"width", "widthClass", FL_INT, &width, "690", 0},
97 {"height", "heightClass", FL_INT, &height, "510", 0},
98 {"xpos", "xposClass", FL_INT, &xpos, "-1", 0},
99 {"ypos", "yposClass", FL_INT, &ypos, "-1", 0}
103 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
105 //#warning Please see if you can trigger this!
107 if (!bufferlist.empty())
108 bufferlist.emergencyWriteAll();
110 // Get the reason for the crash.
112 XGetErrorText(display, xeev->error_code, etxt, 512);
113 lyxerr << etxt << endl;
114 // By doing an abort we get a nice backtrace. (hopefully)
116 return 0; // Solaris CC wants us to return something
120 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
121 : _owner(owner), lyxViews(0)
129 static const int num_res = sizeof(res)/sizeof(FL_resource);
130 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
131 fl_get_app_resources(res, num_res);
133 Display * display = fl_get_display();
135 lyxerr << "LyX: unable to access X display, exiting" << endl;
138 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
139 // X Error handler install goes here
140 XSetErrorHandler(LyX_XErrHandler);
142 // Make sure default screen is not larger than monitor
143 if (width == 690 && height == 510) {
144 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
145 if (HeightOfScreen(scr) - 24 < height)
146 height = HeightOfScreen(scr) - 24;
147 if (WidthOfScreen(scr) - 8 < width)
148 width = WidthOfScreen(scr) - 8;
151 // Initialize the LyXColorHandler
152 lyxColorHandler = new LyXColorHandler;
156 // A destructor is always necessary (asierra-970604)
159 // Lyxserver was created in this class so should be destroyed
160 // here. asierra-970604
170 void LyXGUI::setDefaults()
173 cntl.buttonFontSize = FL_NORMAL_SIZE;
174 cntl.browserFontSize = FL_NORMAL_SIZE;
175 cntl.labelFontSize = FL_NORMAL_SIZE;
176 cntl.choiceFontSize = FL_NORMAL_SIZE;
177 cntl.inputFontSize = FL_NORMAL_SIZE;
178 cntl.menuFontSize = FL_NORMAL_SIZE;
179 cntl.borderWidth = -1;
180 cntl.vclass = FL_DefaultVisual;
181 fl_set_defaults(FL_PDVisual
182 | FL_PDButtonFontSize
183 | FL_PDBrowserFontSize
185 | FL_PDChoiceFontSize
188 | FL_PDBorderWidth, &cntl);
192 // This is called after we have parsed lyxrc
200 if (lyxrc.font_norm_menu.empty())
201 lyxrc.font_norm_menu = lyxrc.font_norm;
202 // Set the font name for popups and menus
203 string menufontname = lyxrc.menu_font_name
204 + "-*-*-*-?-*-*-*-*-"
205 + lyxrc.font_norm_menu;
206 // "?" means "scale that font"
207 string popupfontname = lyxrc.popup_font_name
208 + "-*-*-*-?-*-*-*-*-"
209 + lyxrc.font_norm_menu;
211 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
212 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
214 lyxerr << "Could not set menu font to "
215 << menufontname << endl;
218 lyxerr << "Could not set popup font to "
219 << popupfontname << endl;
221 if (bold < 0 && normal < 0) {
222 lyxerr << "Using 'helvetica' font for menus" << endl;
223 bold = fl_set_font_name(FL_BOLD_STYLE,
224 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
225 normal = fl_set_font_name(FL_NORMAL_STYLE,
226 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
227 if (bold < 0 && normal < 0) {
228 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
229 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
233 // put here (after fl_initialize) to avoid segfault. Cannot be done
234 // in setDefaults() (Matthias 140496)
235 // Moved from ::LyXGUI to ::init to allow popup font customization
237 fl_setpup_fontstyle(FL_NORMAL_STYLE);
238 fl_setpup_fontsize(FL_NORMAL_SIZE);
239 fl_setpup_color(FL_MCOL, FL_BLACK);
240 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
242 // all lyxrc settings has to be done here as lyxrc has not yet
243 // been read when the GUI is created (Jug)
246 if (!lyxrc.custom_export_command.empty())
247 fl_set_input(fd_form_sendto->input_cmd,
248 lyxrc.custom_export_command.c_str());
249 if (lyxrc.custom_export_format == "lyx")
250 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
251 else if (lyxrc.custom_export_format == "tex")
252 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
253 else if (lyxrc.custom_export_format == "dvi")
254 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
255 else if (lyxrc.custom_export_format == "ps")
256 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
257 else if (lyxrc.custom_export_format == "ascii")
258 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
260 // Update parameters.
263 // Initialize the views.
266 // in 0.12 the initialisation of the LyXServer must be done here
267 // 0.13 it should be moved again...
268 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
272 void LyXGUI::create_forms()
274 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
275 lyxViews = new LyXView(width, height);
276 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
278 // From here down should be done by somebody else. (Lgb)
285 if (lyxrc.show_banner) {
286 fd_form_title = create_form_form_title();
287 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
288 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
289 fl_addto_form(fd_form_title->form_title);
290 #ifdef TWO_COLOR_ICONS
291 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
292 fl_set_bitmapbutton_data(obj, banner_bw_width,
293 banner_bw_height, banner_bw_bits);
294 fl_set_object_color(obj, FL_WHITE, FL_BLACK);
296 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
297 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
299 fl_set_pixmapbutton_focus_outline(obj, 3);
301 fl_set_button_shortcut(obj, "^M ^[", 1);
302 fl_set_object_boxtype(obj, FL_NO_BOX);
303 fl_set_object_callback(obj, TimerCB, 0);
305 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
306 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
307 #ifdef TWO_COLOR_ICONS
308 fl_set_object_color(obj, FL_WHITE, FL_WHITE);
309 fl_set_object_lcol(obj, FL_BLACK);
311 // fl_set_object_color(obj, FL_WHITE, FL_WHITE);
312 // fl_set_object_lcol(obj, FL_BLACK);
313 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
314 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
315 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
316 fl_set_object_lcol(obj, FL_FREE_COL3);
318 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
319 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
323 // the paragraph form
324 fd_form_paragraph = create_form_form_paragraph();
325 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
326 CancelCloseBoxCB, 0);
327 fl_addto_choice(fd_form_paragraph->choice_space_above,
328 _(" None | Defskip | Smallskip "
329 "| Medskip | Bigskip | VFill | Length "));
330 fl_addto_choice(fd_form_paragraph->choice_space_below,
331 _(" None | Defskip | Smallskip "
332 "| Medskip | Bigskip | VFill | Length "));
333 fl_set_input_return(fd_form_paragraph->input_space_above,
335 fl_set_input_return(fd_form_paragraph->input_space_below,
338 // the paragraph extra form
339 fd_form_paragraph_extra = create_form_form_paragraph_extra();
340 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
341 CancelCloseBoxCB, 0);
342 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
344 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
346 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
348 // the character form
349 fd_form_character = create_form_form_character();
350 fl_set_form_atclose(fd_form_character->form_character,
351 CancelCloseBoxCB, 0);
352 fl_addto_choice(fd_form_character->choice_family,
353 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
354 fl_addto_choice(fd_form_character->choice_series,
355 _(" No change %l| Medium | Bold %l| Reset "));
356 fl_addto_choice(fd_form_character->choice_shape,
357 _(" No change %l| Upright | Italic | Slanted | Small Caps "
359 fl_addto_choice(fd_form_character->choice_size,
360 _(" No change %l| Tiny | Smallest | Smaller | Small "
361 "| Normal | Large | Larger | Largest | Huge | Huger "
362 "%l| Increase | Decrease | Reset "));
363 fl_addto_choice(fd_form_character->choice_bar,
364 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
365 fl_addto_choice(fd_form_character->choice_color,
366 _(" No change %l| No color | Black | White | Red | Green "
367 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
368 fl_set_form_minsize(fd_form_character->form_character,
369 fd_form_character->form_character->w,
370 fd_form_character->form_character->h);
371 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
372 fl_addto_form(fd_form_character->form_character);
373 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
374 FL_OBJECT * ob = fd_form_character->choice_language;
375 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
376 combo_language2->shortcut("#L", 1);
378 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
381 fd_form_document = create_form_form_document();
382 fl_set_form_atclose(fd_form_document->form_document,
383 CancelCloseBoxCB, 0);
384 fl_addto_choice(fd_form_document->choice_spacing,
385 _(" Single | OneHalf | Double | Other "));
387 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
388 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
389 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
390 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
391 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
392 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
393 fl_addto_form(fd_form_document->form_document);
394 combo_language = new Combox(FL_COMBOX_DROPLIST);
395 ob = fd_form_document->choice_language;
396 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
397 combo_language->shortcut("#G", 1);
400 // "default" is not part of the languages array any more.
401 combo_language->addto("default");
402 combo_language2->addto(_("No change"));
403 combo_language2->addto(_("Reset"));
404 for(Languages::const_iterator cit = languages.begin();
405 cit != languages.end(); ++cit) {
406 combo_language->addto((*cit).second.lang().c_str());
407 combo_language2->addto((*cit).second.lang().c_str());
409 combo_language2->select_text("No change");
411 // not really necessary, but we can do it anyway.
412 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
414 for (n = 0; tex_fonts[n][0]; ++n) {
415 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
418 fl_addto_choice(fd_form_document->choice_inputenc,
419 "default|latin1|latin2|latin5"
420 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
422 for (n = 0; tex_graphics[n][0]; ++n) {
423 fl_addto_choice(fd_form_document->choice_postscript_driver,
426 // not really necessary, but we can do it anyway.
427 fl_addto_choice(fd_form_document->choice_pagestyle,
428 "default|empty|plain|headings|fancy");
429 fl_addto_choice(fd_form_document->choice_default_skip,
430 _(" Smallskip | Medskip | Bigskip | Length "));
431 fl_set_input_return(fd_form_document->input_default_skip,
433 fl_set_form_minsize(fd_form_document->form_document,
434 fd_form_document->form_document->w,
435 fd_form_document->form_document->h);
436 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
439 fd_form_paper = create_form_form_paper();
440 fl_set_form_atclose(fd_form_paper->form_paper,
441 CancelCloseBoxCB, 0);
442 fl_addto_choice(fd_form_paper->choice_papersize2,
443 _(" Default | Custom | USletter | USlegal "
444 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
445 fl_addto_choice(fd_form_paper->choice_paperpackage,
447 "| A4 small Margins (only portrait) "
448 "| A4 very small Margins (only portrait) "
449 "| A4 very wide margins (only portrait) "));
450 fl_set_input_return(fd_form_paper->input_custom_width,
452 fl_set_input_return(fd_form_paper->input_custom_height,
454 fl_set_input_return(fd_form_paper->input_top_margin,
456 fl_set_input_return(fd_form_paper->input_bottom_margin,
458 fl_set_input_return(fd_form_paper->input_left_margin,
460 fl_set_input_return(fd_form_paper->input_right_margin,
462 fl_set_input_return(fd_form_paper->input_head_height,
464 fl_set_input_return(fd_form_paper->input_head_sep,
466 fl_set_input_return(fd_form_paper->input_foot_skip,
468 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
470 // the table_options form
471 fd_form_table_options = create_form_form_table_options();
472 fl_set_form_atclose(fd_form_table_options->form_table_options,
473 CancelCloseBoxCB, 0);
474 fl_set_input_return(fd_form_table_options->input_column_width,
477 // the table_extra form
478 fd_form_table_extra = create_form_form_table_extra();
479 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
480 CancelCloseBoxCB, 0);
481 fl_set_input_return(fd_form_table_extra->input_special_alignment,
483 fl_set_input_return(fd_form_table_extra->input_special_multialign,
485 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
488 fd_form_quotes = create_form_form_quotes();
489 fl_set_form_atclose(fd_form_quotes->form_quotes,
490 CancelCloseBoxCB, 0);
491 // Is it wrong of me to use « » instead of << >> ? (Lgb)
492 // Maybe if people use a font other than latin1... (JMarc)
493 fl_addto_choice(fd_form_quotes->choice_quotes_language,
494 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
497 fd_form_preamble = create_form_form_preamble();
498 fl_set_form_atclose(fd_form_preamble->form_preamble,
499 CancelCloseBoxCB, 0);
502 fd_form_table = create_form_form_table();
503 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
504 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
505 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
506 fl_set_slider_value(fd_form_table->slider_rows, 5);
507 fl_set_slider_value(fd_form_table->slider_columns, 5);
508 fl_set_slider_precision(fd_form_table->slider_rows, 0);
509 fl_set_slider_precision(fd_form_table->slider_columns, 0);
510 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
513 fd_form_sendto = create_form_form_sendto();
514 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
517 fd_form_figure = create_form_form_figure();
518 fl_set_form_atclose(fd_form_figure->form_figure,
519 CancelCloseBoxCB, 0);
520 fl_set_button(fd_form_figure->radio_postscript, 1);
523 fd_form_screen = create_form_form_screen();
524 fl_set_form_atclose(fd_form_screen->form_screen,
525 CancelCloseBoxCB, 0);
528 fd_form_toc = create_form_form_toc();
529 fl_addto_choice(fd_form_toc->toctype,
530 _(" TOC | LOF | LOT | LOA "));
531 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
534 fd_form_ref = create_form_form_ref();
535 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
536 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
537 fd_form_ref->form_ref->h);
539 // the latex options form
540 fd_latex_options = create_form_LaTeXOptions();
541 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
542 CancelCloseBoxCB, 0);
544 // the latex log form
545 fd_latex_log = create_form_LaTeXLog();
546 fl_set_form_atclose(fd_latex_log->LaTeXLog,
547 CancelCloseBoxCB, 0);
549 // Show the main & title form
550 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
551 int title_placement = FL_PLACE_CENTER;
552 // Did we get a valid position?
553 if (xpos>= 0 && ypos>= 0) {
554 lyxViews->setPosition(xpos, ypos);
555 if (lyxrc.show_banner) {
556 // show the title form in the middle of the main form
557 fl_set_form_position(fd_form_title->form_title,
558 abs(xpos + (width/2) - (370 / 2)),
559 abs(ypos + (height/2) - (290 / 2)));
560 title_placement = FL_PLACE_GEOMETRY;
561 // The use of abs() above is a trick to ensure
564 main_placement = FL_PLACE_POSITION;
566 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
567 if (lyxrc.show_banner) {
568 fl_show_form(fd_form_title->form_title,
569 title_placement, FL_NOBORDER,
571 fl_redraw_form(fd_form_title->form_title);
572 fl_raise_form(fd_form_title->form_title);
574 // Show the title form at most 7 secs (lowered from 10 secs)
575 fl_set_timer(fd_form_title->timer_title, 7);
580 void LyXGUI::runTime()
581 /* This will usually be toolkit (GUI) specific. This is
582 * also usually the XEvent dispatcher of the GUI. */
592 kapp->processEvents();
594 if (fl_check_forms() == FL_EVENT) {
595 lyxerr << "LyX: This shouldn't happen..." << endl;
602 void LyXGUI::regBuf(Buffer * b)
604 lyxViews->view()->buffer(b);
607 LyXView * LyXGUI::getLyXView() const