1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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"
37 #include "lyx_gui_misc.h"
39 #include "lyxlookup.h"
40 #include "bufferlist.h"
42 #ifdef TWO_COLOR_ICONS
43 #include "banner_bw.xbm"
48 FD_form_title *fd_form_title;
49 FD_form_paragraph *fd_form_paragraph;
50 FD_form_paragraph_extra *fd_form_paragraph_extra;
51 FD_form_search *fd_form_search;
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 {"-Reverse", "*.Reverse", XrmoptionNoArg, "1"},
81 {"-Mono", "*.Mono", XrmoptionNoArg, "1"},
82 {"-FastSelection", "*.FastSelection", XrmoptionNoArg, "1"},
83 {"-MathColor", "*.MathColor", XrmoptionSepArg, "blue"},
84 {"-MathFrameColor", "*.MathFrameColor", XrmoptionSepArg, "magenta"},
85 {"-FootColor", "*.FootColor", XrmoptionSepArg, "red"},
86 {"-NewLineColor", "*.NewLineColor", XrmoptionSepArg, "red"},
87 {"-LabelColor", "*.LabelColor", XrmoptionSepArg, "palegreen"},
88 {"-FillColor", "*.FillColor", XrmoptionSepArg, "magenta"},
89 {"-OnOffLineColor", "*.OnOffLineColor", XrmoptionSepArg, "magenta"},
90 {"-LatexColor", "*.LatexColor", XrmoptionSepArg, "red"},
91 {"-NoteColor", "*.NoteColor", XrmoptionSepArg, "yellow"},
92 {"-NoteFrameColor", "*.NoteFrameColor", XrmoptionSepArg, "black"},
93 {"-LightedColor", "*.LightedColor", XrmoptionSepArg, "gray80"},
94 {"-BackgroundColor", "*.BackgroundColor", XrmoptionSepArg, "linen"},
95 {"-SelectionColor", "*.SelectionColor", XrmoptionSepArg, "lightblue"}
105 bool cursor_follows_scrollbar;
107 char math_frame_color[32];
109 char new_line_color[32];
110 char label_color[32];
112 char on_off_line_color[32];
113 char latex_color[32];
115 char note_frame_color[32];
116 char lighted_color[32];
117 string background_color;
119 char selection_color[32];
124 {"width", "widthClass", FL_INT, &width, "690"},
125 {"height", "heightClass", FL_INT, &height, "510"},
126 {"xpos", "xposClass", FL_INT, &xpos, "-1"},
127 {"ypos", "yposClass", FL_INT, &ypos, "-1"},
128 {"Reverse", "reverseClass", FL_INT, &reverse_video, "0"},
129 {"Mono", "monoClass", FL_INT, &mono_video, "0"},
130 {"FastSelection", "selectionClass", FL_INT, &fast_selection, "0"},
131 {"MathColor", "colorClass", FL_STRING, math_color, "blue", 31},
132 {"MathFrameColor", "colorClass", FL_STRING, math_frame_color, "magenta", 31},
133 {"FootColor", "colorClass", FL_STRING, foot_color, "red", 31},
134 {"NewLineColor", "colorClass", FL_STRING, new_line_color, "red", 31},
135 {"LabelColor", "colorClass", FL_STRING, label_color, "palegreen", 31},
136 {"FillColor", "colorClass", FL_STRING, fill_color, "magenta", 31},
137 {"OnOffLineColor", "colorClass", FL_STRING, on_off_line_color, "magenta", 31},
138 {"LatexColor", "colorClass", FL_STRING, latex_color, "red", 31},
139 {"NoteColor", "colorClass", FL_STRING, note_color, "yellow", 31},
140 {"NoteFrameColor", "colorClass", FL_STRING, note_frame_color, "black", 31},
141 {"LightedColor", "colorClass", FL_STRING, lighted_color, "gray80", 31},
142 {"BackgroundColor", "colorClass", FL_STRING, b_c, "linen", 31},
143 {"SelectionColor", "colorClass", FL_STRING, selection_color, "lightblue", 31}
147 extern "C" int LyX_XErrHandler(Display *display, XErrorEvent *xeev)
149 //#warning Please see if you can trigger this!
151 if (!bufferlist.isEmpty())
152 bufferlist.emergencyWriteAll();
154 // Get the reason for the crash.
156 XGetErrorText(display, xeev->error_code, etxt, 512);
157 lyxerr << etxt << endl;
158 // By doing an abort we get a nice backtrace. (hopefully)
160 return 0; // Solaris CC wants us to return something
164 LyXGUI::LyXGUI(LyX *owner, int *argc, char *argv[], bool GUI)
173 static const int num_res = sizeof(res)/sizeof(FL_resource);
174 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
175 fl_get_app_resources(res, num_res);
176 Display *display = fl_get_display();
178 lyxerr << "LyX: unable to access X display, exiting" << endl;
181 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
182 // X Error handler install goes here
183 XSetErrorHandler(LyX_XErrHandler);
185 background_color = b_c;
187 // Make sure default screen is not larger than monitor
188 if (width == 690 && height == 510) {
189 Screen * scr=(DefaultScreenOfDisplay(fl_get_display()));
190 if (HeightOfScreen(scr)-24<height)
191 height = HeightOfScreen(scr)-24;
192 if (WidthOfScreen(scr)-8<width)
193 width = WidthOfScreen(scr)-8;
199 // A destructor is always necessary (asierra-970604)
201 // Lyxserver was created in this class so should be destroyed
202 // here. asierra-970604
213 void LyXGUI::setDefaults()
216 cntl.buttonFontSize = FL_NORMAL_SIZE;
217 cntl.browserFontSize = FL_NORMAL_SIZE;
218 cntl.labelFontSize = FL_NORMAL_SIZE;
219 cntl.choiceFontSize = FL_NORMAL_SIZE;
220 cntl.inputFontSize = FL_NORMAL_SIZE;
221 cntl.menuFontSize = FL_NORMAL_SIZE;
222 cntl.borderWidth = -1;
223 cntl.vclass = FL_DefaultVisual;
224 fl_set_defaults(FL_PDVisual
225 | FL_PDButtonFontSize
226 | FL_PDBrowserFontSize
228 | FL_PDChoiceFontSize
231 | FL_PDBorderWidth, &cntl);
235 // This is called after we have parsed lyxrc
243 // Set the font name for popups and menus
244 string menufontname = lyxrc->menu_font_name
245 + "-*-*-*-?-*-*-*-*-"
247 // "?" means "scale that font"
248 string popupfontname = lyxrc->popup_font_name
249 + "-*-*-*-?-*-*-*-*-"
252 if (fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str()) < 0)
255 char ** list = XListFonts(fl_display, menufontname.c_str(),
257 XFreeFontNames(list);
259 fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
262 lyxerr << "Could not set menu font to "
263 << menufontname << endl;
266 if (fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str()) < 0)
268 list = XListFonts(fl_display, popupfontname.c_str(),
270 XFreeFontNames(list);
272 fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
275 lyxerr << "Could not set popup font to "
276 << popupfontname << endl;
278 // put here (after fl_initialize) to avoid segfault. Cannot be done
279 // in setDefaults() (Matthias 140496)
280 // Moved from ::LyXGUI to ::init to allow popup font customization
282 fl_setpup_fontstyle(FL_NORMAL_STYLE);
283 fl_setpup_fontsize(FL_NORMAL_SIZE);
284 fl_setpup_color(FL_MCOL,FL_BLACK);
285 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
287 // all lyxrc settings has to be done here as lyxrc has not yet
288 // been read when the GUI is created (Jug)
291 fl_set_input(fd_form_print->input_printer,
292 lyxrc->printer.c_str());
295 if (!lyxrc->custom_export_command.empty())
296 fl_set_input(fd_form_sendto->input_cmd,
297 lyxrc->custom_export_command.c_str());
298 if (lyxrc->custom_export_format == "lyx")
299 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
300 else if (lyxrc->custom_export_format == "tex")
301 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
302 else if (lyxrc->custom_export_format == "dvi")
303 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
304 else if (lyxrc->custom_export_format == "ps")
305 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
306 else if (lyxrc->custom_export_format == "ascii")
307 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
309 // Update parameters.
312 // Initialize the views.
315 // in 0.12 the initialisation of the LyXServer must be done here
316 // 0.13 it should be moved again...
317 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc->lyxpipes);
319 // This is to make sure we get the selection color
321 // This is to make sure we set the background_pixels
326 void LyXGUI::create_forms()
328 lyxerr.debug() << "Initializing LyXView..." << endl;
329 lyxViews = new LyXView(width, height);
330 lyxerr.debug() << "Initializing LyXView...done" << endl;
332 // From here down should be done by somebody else. (Lgb)
339 fd_form_title = create_form_form_title();
340 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
341 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
342 fl_addto_form(fd_form_title->form_title);
343 #ifdef TWO_COLOR_ICONS
344 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON,0,0,425,290,"");
345 fl_set_bitmapbutton_data(obj,banner_bw_width,
346 banner_bw_height, banner_bw_bits);
347 fl_set_object_color(obj,FL_WHITE,FL_BLACK);
349 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON,0,0,425,290,"");
350 fl_set_pixmapbutton_data(obj, (char**)banner);
352 fl_set_pixmapbutton_focus_outline(obj,3);
355 fl_set_button_shortcut(obj,"^M ^[",1);
356 fl_set_object_boxtype(obj,FL_NO_BOX);
357 fl_set_object_callback(obj,TimerCB,0);
359 obj = fl_add_text(FL_NORMAL_TEXT,248,265,170,16, LYX_VERSION);
360 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
361 #ifdef TWO_COLOR_ICONS
362 fl_set_object_color(obj,FL_WHITE,FL_WHITE);
363 fl_set_object_lcol(obj,FL_BLACK);
365 // fl_set_object_color(obj,FL_WHITE, FL_WHITE);
366 // fl_set_object_lcol(obj,FL_BLACK);
367 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
368 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
369 fl_set_object_color(obj,FL_FREE_COL2, FL_FREE_COL2);
370 fl_set_object_lcol(obj,FL_FREE_COL3);
372 fl_set_object_lalign(obj,FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
373 fl_set_object_lstyle(obj,FL_BOLD_STYLE);
376 // the paragraph form
377 fd_form_paragraph = create_form_form_paragraph();
378 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
379 CancelCloseBoxCB, 0);
380 fl_addto_choice(fd_form_paragraph->choice_space_above,
381 _(" None | Defskip | Smallskip "
382 "| Medskip | Bigskip | VFill | Length "));
383 fl_addto_choice(fd_form_paragraph->choice_space_below,
384 _(" None | Defskip | Smallskip "
385 "| Medskip | Bigskip | VFill | Length "));
386 fl_set_input_return(fd_form_paragraph->input_space_above,
388 fl_set_input_return(fd_form_paragraph->input_space_below,
391 // the paragraph extra form
392 fd_form_paragraph_extra = create_form_form_paragraph_extra();
393 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
394 CancelCloseBoxCB, 0);
395 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
397 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
401 fd_form_search = create_form_form_search();
402 fl_set_form_atclose(fd_form_search->form_search,
403 CancelCloseBoxCB, 0);
405 // the character form
406 fd_form_character = create_form_form_character();
407 fl_set_form_atclose(fd_form_character->form_character,
408 CancelCloseBoxCB, 0);
409 fl_addto_choice(fd_form_character->choice_family,
410 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
411 fl_addto_choice(fd_form_character->choice_series,
412 _(" No change %l| Medium | Bold %l| Reset "));
413 fl_addto_choice(fd_form_character->choice_shape,
414 _(" No change %l| Upright | Italic | Slanted | Small Caps "
416 fl_addto_choice(fd_form_character->choice_size,
417 _(" No change %l| Tiny | Smallest | Smaller | Small "
418 "| Normal | Large | Larger | Largest | Huge | Huger "
419 "%l| Increase | Decrease | Reset "));
420 fl_addto_choice(fd_form_character->choice_bar,
421 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
422 fl_addto_choice(fd_form_character->choice_color,
423 _(" No change %l| No color | Black | White | Red | Green "
424 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
425 fl_set_form_minsize(fd_form_character->form_character,
426 fd_form_character->form_character->w,
427 fd_form_character->form_character->h);
430 fd_form_document = create_form_form_document();
431 fl_set_form_atclose(fd_form_document->form_document,
432 CancelCloseBoxCB, 0);
433 fl_addto_choice(fd_form_document->choice_spacing,
434 _(" Single | OneHalf | Double | Other "));
436 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-1,5);
437 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1,5);
438 fl_set_counter_step(fd_form_document->slider_secnumdepth,1,1);
439 fl_set_counter_step(fd_form_document->slider_tocdepth,1,1);
440 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
441 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
442 fl_addto_form(fd_form_document->form_document);
443 combo_language = new Combox(FL_COMBOX_DROPLIST);
444 FL_OBJECT *ob = fd_form_document->choice_language;
445 combo_language->add(ob->x, ob->y, ob->w, ob->h, 200);
446 combo_language->shortcut("#G",1);
448 int n; // declared here because DEC cxx does not like multiple
449 // declarations of variables in for() loops (JMarc)
450 for (n=0; tex_babel[n][0]; n++) {
451 combo_language->addto(tex_babel[n]);
454 // not really necessary, but we can do it anyway.
455 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
457 for (n=0; tex_fonts[n][0]; n++) {
458 fl_addto_choice(fd_form_document->choice_fonts,tex_fonts[n]);
461 fl_addto_choice(fd_form_document->choice_inputenc,
462 "default|latin1|latin2|latin5"
463 "|koi8-r|koi8-u|cp866|cp1251");
465 for (n=0; tex_graphics[n][0]; n++) {
466 fl_addto_choice(fd_form_document->choice_postscript_driver,
469 // not really necessary, but we can do it anyway.
470 fl_addto_choice(fd_form_document->choice_pagestyle,
471 "default|empty|plain|headings|fancy");
472 fl_addto_choice(fd_form_document->choice_default_skip,
473 _(" Smallskip | Medskip | Bigskip | Length "));
474 fl_set_input_return(fd_form_document->input_default_skip,
476 fl_set_form_minsize(fd_form_document->form_document,
477 fd_form_document->form_document->w,
478 fd_form_document->form_document->h);
481 fd_form_paper = create_form_form_paper();
482 fl_set_form_atclose(fd_form_paper->form_paper,
483 CancelCloseBoxCB, 0);
484 fl_addto_choice(fd_form_paper->choice_papersize2,
485 _(" Default | Custom | USletter | USlegal "
486 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
487 fl_addto_choice(fd_form_paper->choice_paperpackage,
489 "| A4 small Margins (only portrait) "
490 "| A4 very small Margins (only portrait) "
491 "| A4 very wide margins (only portrait) "));
492 fl_set_input_return(fd_form_paper->input_custom_width,
494 fl_set_input_return(fd_form_paper->input_custom_height,
496 fl_set_input_return(fd_form_paper->input_top_margin,
498 fl_set_input_return(fd_form_paper->input_bottom_margin,
500 fl_set_input_return(fd_form_paper->input_left_margin,
502 fl_set_input_return(fd_form_paper->input_right_margin,
504 fl_set_input_return(fd_form_paper->input_head_height,
506 fl_set_input_return(fd_form_paper->input_head_sep,
508 fl_set_input_return(fd_form_paper->input_foot_skip,
511 // the table_options form
512 fd_form_table_options = create_form_form_table_options();
513 fl_set_form_atclose(fd_form_table_options->form_table_options,
514 CancelCloseBoxCB, 0);
515 fl_set_input_return(fd_form_table_options->input_column_width,
518 // the table_extra form
519 fd_form_table_extra = create_form_form_table_extra();
520 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
521 CancelCloseBoxCB, 0);
522 fl_set_input_return(fd_form_table_extra->input_special_alignment,
524 fl_set_input_return(fd_form_table_extra->input_special_multialign,
528 fd_form_quotes = create_form_form_quotes();
529 fl_set_form_atclose(fd_form_quotes->form_quotes,
530 CancelCloseBoxCB, 0);
531 // Is it wrong of me to use « » instead of << >> ? (Lgb)
532 // Maybe if people use a font other than latin1... (JMarc)
533 fl_addto_choice(fd_form_quotes->choice_quotes_language,
534 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
537 fd_form_preamble = create_form_form_preamble();
538 fl_set_form_atclose(fd_form_preamble->form_preamble,
539 CancelCloseBoxCB, 0);
542 fd_form_table = create_form_form_table();
543 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
544 fl_set_slider_bounds(fd_form_table->slider_rows,1,50);
545 fl_set_slider_bounds(fd_form_table->slider_columns,1,50);
546 fl_set_slider_value(fd_form_table->slider_rows, 5);
547 fl_set_slider_value(fd_form_table->slider_columns, 5);
548 fl_set_slider_precision(fd_form_table->slider_rows, 0);
549 fl_set_slider_precision(fd_form_table->slider_columns, 0);
552 fd_form_print = create_form_form_print();
553 fl_set_form_atclose(fd_form_print->form_print, CancelCloseBoxCB, 0);
554 fl_set_button(fd_form_print->radio_printer, 1);
555 fl_set_button(fd_form_print->radio_file, 0);
556 fl_set_button(fd_form_print->radio_order_normal, 1);
557 fl_set_button(fd_form_print->radio_order_reverse, 0);
558 fl_set_button(fd_form_print->radio_all_pages, 1);
559 fl_set_button(fd_form_print->radio_odd_pages, 0);
560 fl_set_button(fd_form_print->radio_even_pages, 0);
563 fd_form_sendto = create_form_form_sendto();
564 fl_set_form_atclose(fd_form_sendto->form_sendto,CancelCloseBoxCB,0);
567 fd_form_figure = create_form_form_figure();
568 fl_set_form_atclose(fd_form_figure->form_figure,
569 CancelCloseBoxCB, 0);
570 fl_set_button(fd_form_figure->radio_postscript, 1);
573 fd_form_screen = create_form_form_screen();
574 fl_set_form_atclose(fd_form_screen->form_screen,
575 CancelCloseBoxCB, 0);
578 fd_form_toc = create_form_form_toc();
579 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
582 fd_form_ref = create_form_form_ref();
583 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
584 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
585 fd_form_ref->form_ref->h);
587 // the latex options form
588 fd_latex_options = create_form_LaTeXOptions();
589 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
590 CancelCloseBoxCB, 0);
592 // the latex log form
593 fd_latex_log = create_form_LaTeXLog();
594 fl_set_form_atclose(fd_latex_log->LaTeXLog,
595 CancelCloseBoxCB, 0);
597 // Show the main & title form
598 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
599 int title_placement = FL_PLACE_CENTER;
600 // Did we get a valid position?
601 if (xpos>=0 && ypos>=0) {
602 lyxViews->setPosition(xpos, ypos);
603 // show the title form in the middle of the main form
604 fl_set_form_position(fd_form_title->form_title,
605 abs(xpos + (width/2) - (370 / 2)),
606 abs(ypos + (height/2) - (290 / 2)));
607 // The use of abs() above is a trick to ensure valid positions
608 main_placement = FL_PLACE_POSITION;
609 title_placement = FL_PLACE_GEOMETRY;
611 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
612 fl_show_form(fd_form_title->form_title,
613 title_placement, FL_NOBORDER,
615 fl_redraw_form(fd_form_title->form_title);
616 fl_raise_form(fd_form_title->form_title);
618 // Show the title form at most 7 secs (lowered from 10 secs)
619 fl_set_timer(fd_form_title->timer_title, 7);
623 void LyXGUI::runTime()
624 /* This will usually be toolkit (GUI) specific. This is
625 * also usually the XEvent dispatcher of the GUI. */
634 if (fl_check_forms() == FL_EVENT) {
635 lyxerr << "LyX: This shouldn't happen..." << endl;
642 void LyXGUI::regBuf(Buffer *b)
644 lyxViews->currentView()->setBuffer(b);