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
19 #include FORMS_H_LOCATION
24 #include "layout_forms.h"
25 #include "print_form.h"
26 #include "tex-strings.h"
28 #include "latexoptions.h"
33 #include "lyxserver.h"
36 #include "lyx_gui_misc.h"
37 #include "lyxlookup.h"
38 #include "bufferlist.h"
40 #include "ColorHandler.h"
42 #ifdef TWO_COLOR_ICONS
43 #include "banner_bw.xbm"
50 FD_form_title * fd_form_title;
51 FD_form_paragraph * fd_form_paragraph;
52 FD_form_paragraph_extra * fd_form_paragraph_extra;
53 FD_form_character * fd_form_character;
54 FD_form_document * fd_form_document;
55 FD_form_paper * fd_form_paper;
56 FD_form_table_options * fd_form_table_options;
57 FD_form_table_extra * fd_form_table_extra;
58 FD_form_quotes * fd_form_quotes;
59 FD_form_preamble * fd_form_preamble;
60 FD_form_table * fd_form_table;
61 FD_form_print * fd_form_print;
62 FD_form_sendto * fd_form_sendto;
63 FD_form_figure * fd_form_figure;
64 FD_form_screen * fd_form_screen;
65 FD_form_toc * fd_form_toc;
66 FD_form_ref * fd_form_ref;
67 FD_LaTeXOptions * fd_latex_options; // from latexoptions.h
68 FD_LaTeXLog * fd_latex_log; // from latexoptions.h
69 Combox * combo_language;
71 extern LyXServer * lyxserver;
72 extern bool finished; // flag, that we are quitting the program
73 extern BufferList bufferlist;
77 {"-width", "*.width", XrmoptionSepArg, "690"},
78 {"-height", "*.height", XrmoptionSepArg, "510"},
79 {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
80 {"-ypos", "*.ypos", XrmoptionSepArg, "-1"},
81 {"-MathColor", "*.MathColor", XrmoptionSepArg, "blue"},
82 {"-MathFrameColor", "*.MathFrameColor", XrmoptionSepArg, "magenta"},
83 {"-FootColor", "*.FootColor", XrmoptionSepArg, "red"},
84 {"-NewLineColor", "*.NewLineColor", XrmoptionSepArg, "red"},
85 {"-LabelColor", "*.LabelColor", XrmoptionSepArg, "palegreen"},
86 {"-FillColor", "*.FillColor", XrmoptionSepArg, "magenta"},
87 {"-OnOffLineColor", "*.OnOffLineColor", XrmoptionSepArg, "magenta"},
88 {"-LatexColor", "*.LatexColor", XrmoptionSepArg, "red"},
89 {"-NoteColor", "*.NoteColor", XrmoptionSepArg, "yellow"},
90 {"-NoteFrameColor", "*.NoteFrameColor", XrmoptionSepArg, "black"},
91 {"-LightedColor", "*.LightedColor", XrmoptionSepArg, "gray80"},
92 {"-BackgroundColor", "*.BackgroundColor", XrmoptionSepArg, "linen"},
93 {"-SelectionColor", "*.SelectionColor", XrmoptionSepArg, "lightblue"}
100 bool cursor_follows_scrollbar;
102 char math_frame_color[32];
104 char new_line_color[32];
105 char label_color[32];
107 char on_off_line_color[32];
108 char latex_color[32];
110 char note_frame_color[32];
111 char lighted_color[32];
112 string background_color;
114 char selection_color[32];
119 {"width", "widthClass", FL_INT, &width, "690", 0},
120 {"height", "heightClass", FL_INT, &height, "510", 0},
121 {"xpos", "xposClass", FL_INT, &xpos, "-1", 0},
122 {"ypos", "yposClass", FL_INT, &ypos, "-1", 0},
123 {"MathColor", "colorClass", FL_STRING, math_color, "blue", 31},
124 {"MathFrameColor", "colorClass", FL_STRING, math_frame_color, "magenta", 31},
125 {"FootColor", "colorClass", FL_STRING, foot_color, "red", 31},
126 {"NewLineColor", "colorClass", FL_STRING, new_line_color, "red", 31},
127 {"LabelColor", "colorClass", FL_STRING, label_color, "palegreen", 31},
128 {"FillColor", "colorClass", FL_STRING, fill_color, "magenta", 31},
129 {"OnOffLineColor", "colorClass", FL_STRING, on_off_line_color, "magenta", 31},
130 {"LatexColor", "colorClass", FL_STRING, latex_color, "red", 31},
131 {"NoteColor", "colorClass", FL_STRING, note_color, "yellow", 31},
132 {"NoteFrameColor", "colorClass", FL_STRING, note_frame_color, "black", 31},
133 {"LightedColor", "colorClass", FL_STRING, lighted_color, "gray80", 31},
134 {"BackgroundColor", "colorClass", FL_STRING, b_c, "linen", 31},
135 {"SelectionColor", "colorClass", FL_STRING, selection_color, "lightblue", 31}
139 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
141 //#warning Please see if you can trigger this!
143 if (!bufferlist.empty())
144 bufferlist.emergencyWriteAll();
146 // Get the reason for the crash.
148 XGetErrorText(display, xeev->error_code, etxt, 512);
149 lyxerr << etxt << endl;
150 // By doing an abort we get a nice backtrace. (hopefully)
152 return 0; // Solaris CC wants us to return something
156 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
165 static const int num_res = sizeof(res)/sizeof(FL_resource);
166 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
167 fl_get_app_resources(res, num_res);
169 Display * display = fl_get_display();
171 lyxerr << "LyX: unable to access X display, exiting" << endl;
174 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
175 // X Error handler install goes here
176 XSetErrorHandler(LyX_XErrHandler);
178 background_color = b_c;
180 // Make sure default screen is not larger than monitor
181 if (width == 690 && height == 510) {
182 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
183 if (HeightOfScreen(scr) - 24 < height)
184 height = HeightOfScreen(scr) - 24;
185 if (WidthOfScreen(scr) - 8 < width)
186 width = WidthOfScreen(scr) - 8;
189 // Initialize the LyXColorHandler
190 lyxColorHandler = new LyXColorHandler;
194 // A destructor is always necessary (asierra-970604)
197 // Lyxserver was created in this class so should be destroyed
198 // here. asierra-970604
206 void LyXGUI::setDefaults()
209 cntl.buttonFontSize = FL_NORMAL_SIZE;
210 cntl.browserFontSize = FL_NORMAL_SIZE;
211 cntl.labelFontSize = FL_NORMAL_SIZE;
212 cntl.choiceFontSize = FL_NORMAL_SIZE;
213 cntl.inputFontSize = FL_NORMAL_SIZE;
214 cntl.menuFontSize = FL_NORMAL_SIZE;
215 cntl.borderWidth = -1;
216 cntl.vclass = FL_DefaultVisual;
217 fl_set_defaults(FL_PDVisual
218 | FL_PDButtonFontSize
219 | FL_PDBrowserFontSize
221 | FL_PDChoiceFontSize
224 | FL_PDBorderWidth, &cntl);
228 // This is called after we have parsed lyxrc
236 if (lyxrc.font_norm_menu.empty())
237 lyxrc.font_norm_menu = lyxrc.font_norm;
238 // Set the font name for popups and menus
239 string menufontname = lyxrc.menu_font_name
240 + "-*-*-*-?-*-*-*-*-"
241 + lyxrc.font_norm_menu;
242 // "?" means "scale that font"
243 string popupfontname = lyxrc.popup_font_name
244 + "-*-*-*-?-*-*-*-*-"
245 + lyxrc.font_norm_menu;
247 if (fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str()) < 0)
248 lyxerr << "Could not set menu font to "
249 << menufontname << endl;
251 if (fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str()) < 0)
252 lyxerr << "Could not set popup font to "
253 << popupfontname << endl;
255 // put here (after fl_initialize) to avoid segfault. Cannot be done
256 // in setDefaults() (Matthias 140496)
257 // Moved from ::LyXGUI to ::init to allow popup font customization
259 fl_setpup_fontstyle(FL_NORMAL_STYLE);
260 fl_setpup_fontsize(FL_NORMAL_SIZE);
261 fl_setpup_color(FL_MCOL, FL_BLACK);
262 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
264 // all lyxrc settings has to be done here as lyxrc has not yet
265 // been read when the GUI is created (Jug)
268 fl_set_input(fd_form_print->input_printer,
269 lyxrc.printer.c_str());
272 if (!lyxrc.custom_export_command.empty())
273 fl_set_input(fd_form_sendto->input_cmd,
274 lyxrc.custom_export_command.c_str());
275 if (lyxrc.custom_export_format == "lyx")
276 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
277 else if (lyxrc.custom_export_format == "tex")
278 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
279 else if (lyxrc.custom_export_format == "dvi")
280 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
281 else if (lyxrc.custom_export_format == "ps")
282 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
283 else if (lyxrc.custom_export_format == "ascii")
284 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
286 // Update parameters.
289 // Initialize the views.
292 // in 0.12 the initialisation of the LyXServer must be done here
293 // 0.13 it should be moved again...
294 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
298 void LyXGUI::create_forms()
300 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
301 lyxViews = new LyXView(width, height);
302 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
304 // From here down should be done by somebody else. (Lgb)
311 if (lyxrc.show_banner) {
312 fd_form_title = create_form_form_title();
313 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
314 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
315 fl_addto_form(fd_form_title->form_title);
316 #ifdef TWO_COLOR_ICONS
317 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
318 fl_set_bitmapbutton_data(obj, banner_bw_width,
319 banner_bw_height, banner_bw_bits);
320 fl_set_object_color(obj, FL_WHITE, FL_BLACK);
322 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
323 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
325 fl_set_pixmapbutton_focus_outline(obj, 3);
327 fl_set_button_shortcut(obj, "^M ^[", 1);
328 fl_set_object_boxtype(obj, FL_NO_BOX);
329 fl_set_object_callback(obj, TimerCB, 0);
331 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
332 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
333 #ifdef TWO_COLOR_ICONS
334 fl_set_object_color(obj, FL_WHITE, FL_WHITE);
335 fl_set_object_lcol(obj, FL_BLACK);
337 // fl_set_object_color(obj, FL_WHITE, FL_WHITE);
338 // fl_set_object_lcol(obj, FL_BLACK);
339 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
340 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
341 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
342 fl_set_object_lcol(obj, FL_FREE_COL3);
344 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
345 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
349 // the paragraph form
350 fd_form_paragraph = create_form_form_paragraph();
351 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
352 CancelCloseBoxCB, 0);
353 fl_addto_choice(fd_form_paragraph->choice_space_above,
354 _(" None | Defskip | Smallskip "
355 "| Medskip | Bigskip | VFill | Length "));
356 fl_addto_choice(fd_form_paragraph->choice_space_below,
357 _(" None | Defskip | Smallskip "
358 "| Medskip | Bigskip | VFill | Length "));
359 fl_set_input_return(fd_form_paragraph->input_space_above,
361 fl_set_input_return(fd_form_paragraph->input_space_below,
364 // the paragraph extra form
365 fd_form_paragraph_extra = create_form_form_paragraph_extra();
366 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
367 CancelCloseBoxCB, 0);
368 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
370 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
373 // the character form
374 fd_form_character = create_form_form_character();
375 fl_set_form_atclose(fd_form_character->form_character,
376 CancelCloseBoxCB, 0);
377 fl_addto_choice(fd_form_character->choice_family,
378 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
379 fl_addto_choice(fd_form_character->choice_series,
380 _(" No change %l| Medium | Bold %l| Reset "));
381 fl_addto_choice(fd_form_character->choice_shape,
382 _(" No change %l| Upright | Italic | Slanted | Small Caps "
384 fl_addto_choice(fd_form_character->choice_size,
385 _(" No change %l| Tiny | Smallest | Smaller | Small "
386 "| Normal | Large | Larger | Largest | Huge | Huger "
387 "%l| Increase | Decrease | Reset "));
388 fl_addto_choice(fd_form_character->choice_bar,
389 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
390 fl_addto_choice(fd_form_character->choice_color,
391 _(" No change %l| No color | Black | White | Red | Green "
392 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
393 fl_set_form_minsize(fd_form_character->form_character,
394 fd_form_character->form_character->w,
395 fd_form_character->form_character->h);
398 fd_form_document = create_form_form_document();
399 fl_set_form_atclose(fd_form_document->form_document,
400 CancelCloseBoxCB, 0);
401 fl_addto_choice(fd_form_document->choice_spacing,
402 _(" Single | OneHalf | Double | Other "));
404 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-1, 5);
405 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
406 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
407 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
408 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
409 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
410 fl_addto_form(fd_form_document->form_document);
411 combo_language = new Combox(FL_COMBOX_DROPLIST);
412 FL_OBJECT * ob = fd_form_document->choice_language;
413 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
414 combo_language->shortcut("#G", 1);
417 // "default" is not part of the languages array any more.
418 combo_language->addto("default");
419 for(Languages::const_iterator cit = languages.begin();
420 cit != languages.end(); ++cit) {
421 combo_language->addto((*cit).second.lang.c_str());
424 // not really necessary, but we can do it anyway.
425 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
427 for (n = 0; tex_fonts[n][0]; ++n) {
428 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
431 fl_addto_choice(fd_form_document->choice_inputenc,
432 "default|latin1|latin2|latin5"
433 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
435 for (n = 0; tex_graphics[n][0]; ++n) {
436 fl_addto_choice(fd_form_document->choice_postscript_driver,
439 // not really necessary, but we can do it anyway.
440 fl_addto_choice(fd_form_document->choice_pagestyle,
441 "default|empty|plain|headings|fancy");
442 fl_addto_choice(fd_form_document->choice_default_skip,
443 _(" Smallskip | Medskip | Bigskip | Length "));
444 fl_set_input_return(fd_form_document->input_default_skip,
446 fl_set_form_minsize(fd_form_document->form_document,
447 fd_form_document->form_document->w,
448 fd_form_document->form_document->h);
451 fd_form_paper = create_form_form_paper();
452 fl_set_form_atclose(fd_form_paper->form_paper,
453 CancelCloseBoxCB, 0);
454 fl_addto_choice(fd_form_paper->choice_papersize2,
455 _(" Default | Custom | USletter | USlegal "
456 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
457 fl_addto_choice(fd_form_paper->choice_paperpackage,
459 "| A4 small Margins (only portrait) "
460 "| A4 very small Margins (only portrait) "
461 "| A4 very wide margins (only portrait) "));
462 fl_set_input_return(fd_form_paper->input_custom_width,
464 fl_set_input_return(fd_form_paper->input_custom_height,
466 fl_set_input_return(fd_form_paper->input_top_margin,
468 fl_set_input_return(fd_form_paper->input_bottom_margin,
470 fl_set_input_return(fd_form_paper->input_left_margin,
472 fl_set_input_return(fd_form_paper->input_right_margin,
474 fl_set_input_return(fd_form_paper->input_head_height,
476 fl_set_input_return(fd_form_paper->input_head_sep,
478 fl_set_input_return(fd_form_paper->input_foot_skip,
481 // the table_options form
482 fd_form_table_options = create_form_form_table_options();
483 fl_set_form_atclose(fd_form_table_options->form_table_options,
484 CancelCloseBoxCB, 0);
485 fl_set_input_return(fd_form_table_options->input_column_width,
488 // the table_extra form
489 fd_form_table_extra = create_form_form_table_extra();
490 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
491 CancelCloseBoxCB, 0);
492 fl_set_input_return(fd_form_table_extra->input_special_alignment,
494 fl_set_input_return(fd_form_table_extra->input_special_multialign,
498 fd_form_quotes = create_form_form_quotes();
499 fl_set_form_atclose(fd_form_quotes->form_quotes,
500 CancelCloseBoxCB, 0);
501 // Is it wrong of me to use « » instead of << >> ? (Lgb)
502 // Maybe if people use a font other than latin1... (JMarc)
503 fl_addto_choice(fd_form_quotes->choice_quotes_language,
504 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
507 fd_form_preamble = create_form_form_preamble();
508 fl_set_form_atclose(fd_form_preamble->form_preamble,
509 CancelCloseBoxCB, 0);
512 fd_form_table = create_form_form_table();
513 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
514 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
515 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
516 fl_set_slider_value(fd_form_table->slider_rows, 5);
517 fl_set_slider_value(fd_form_table->slider_columns, 5);
518 fl_set_slider_precision(fd_form_table->slider_rows, 0);
519 fl_set_slider_precision(fd_form_table->slider_columns, 0);
522 fd_form_print = create_form_form_print();
523 fl_set_form_atclose(fd_form_print->form_print, CancelCloseBoxCB, 0);
524 fl_set_button(fd_form_print->radio_printer, 1);
525 fl_set_button(fd_form_print->radio_file, 0);
526 fl_set_button(fd_form_print->radio_order_normal, 1);
527 fl_set_button(fd_form_print->radio_order_reverse, 0);
528 fl_set_button(fd_form_print->radio_all_pages, 1);
529 fl_set_button(fd_form_print->radio_odd_pages, 0);
530 fl_set_button(fd_form_print->radio_even_pages, 0);
533 fd_form_sendto = create_form_form_sendto();
534 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
537 fd_form_figure = create_form_form_figure();
538 fl_set_form_atclose(fd_form_figure->form_figure,
539 CancelCloseBoxCB, 0);
540 fl_set_button(fd_form_figure->radio_postscript, 1);
543 fd_form_screen = create_form_form_screen();
544 fl_set_form_atclose(fd_form_screen->form_screen,
545 CancelCloseBoxCB, 0);
548 fd_form_toc = create_form_form_toc();
549 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
552 fd_form_ref = create_form_form_ref();
553 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
554 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
555 fd_form_ref->form_ref->h);
557 // the latex options form
558 fd_latex_options = create_form_LaTeXOptions();
559 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
560 CancelCloseBoxCB, 0);
562 // the latex log form
563 fd_latex_log = create_form_LaTeXLog();
564 fl_set_form_atclose(fd_latex_log->LaTeXLog,
565 CancelCloseBoxCB, 0);
567 // Show the main & title form
568 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
569 int title_placement = FL_PLACE_CENTER;
570 // Did we get a valid position?
571 if (xpos>= 0 && ypos>= 0) {
572 lyxViews->setPosition(xpos, ypos);
573 if (lyxrc.show_banner) {
574 // show the title form in the middle of the main form
575 fl_set_form_position(fd_form_title->form_title,
576 abs(xpos + (width/2) - (370 / 2)),
577 abs(ypos + (height/2) - (290 / 2)));
578 title_placement = FL_PLACE_GEOMETRY;
579 // The use of abs() above is a trick to ensure
582 main_placement = FL_PLACE_POSITION;
584 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
585 if (lyxrc.show_banner) {
586 fl_show_form(fd_form_title->form_title,
587 title_placement, FL_NOBORDER,
589 fl_redraw_form(fd_form_title->form_title);
590 fl_raise_form(fd_form_title->form_title);
592 // Show the title form at most 7 secs (lowered from 10 secs)
593 fl_set_timer(fd_form_title->timer_title, 7);
598 void LyXGUI::runTime()
599 /* This will usually be toolkit (GUI) specific. This is
600 * also usually the XEvent dispatcher of the GUI. */
609 if (fl_check_forms() == FL_EVENT) {
610 lyxerr << "LyX: This shouldn't happen..." << endl;
617 void LyXGUI::regBuf(Buffer * b)
619 lyxViews->view()->buffer(b);