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