1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 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 // $Id: lyx_gui.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $
44 #if !defined(lint) && !defined(WITH_WARNINGS)
45 static char vcid[] = "$Id: lyx_gui.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
48 #ifdef TWO_COLOR_ICONS
49 #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_search *fd_form_search;
58 FD_form_character *fd_form_character;
59 FD_form_document *fd_form_document;
60 FD_form_paper *fd_form_paper;
61 FD_form_table_options *fd_form_table_options;
62 FD_form_table_extra *fd_form_table_extra;
63 FD_form_quotes *fd_form_quotes;
64 FD_form_preamble *fd_form_preamble;
65 FD_form_table *fd_form_table;
66 FD_form_print *fd_form_print;
67 FD_form_sendto *fd_form_sendto;
68 FD_form_figure *fd_form_figure;
69 FD_form_screen *fd_form_screen;
70 FD_form_toc *fd_form_toc;
71 FD_form_ref *fd_form_ref;
72 FD_LaTeXOptions *fd_latex_options; // from latexoptions.h
73 FD_LaTeXLog *fd_latex_log; // from latexoptions.h
74 Combox *combo_language;
76 extern LyXServer *lyxserver;
77 extern bool finished; // flag, that we are quitting the program
78 extern BufferList bufferlist;
82 {"-width", "*.width", XrmoptionSepArg, "690"},
83 {"-height", "*.height", XrmoptionSepArg, "510"},
84 {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
85 {"-ypos", "*.ypos", XrmoptionSepArg, "-1"},
86 {"-Reverse", "*.Reverse", XrmoptionNoArg, "1"},
87 {"-Mono", "*.Mono", XrmoptionNoArg, "1"},
88 {"-FastSelection", "*.FastSelection", XrmoptionNoArg, "1"},
89 {"-MathColor", "*.MathColor", XrmoptionSepArg, "blue"},
90 {"-MathFrameColor", "*.MathFrameColor", XrmoptionSepArg, "magenta"},
91 {"-FootColor", "*.FootColor", XrmoptionSepArg, "red"},
92 {"-NewLineColor", "*.NewLineColor", XrmoptionSepArg, "red"},
93 {"-LabelColor", "*.LabelColor", XrmoptionSepArg, "palegreen"},
94 {"-FillColor", "*.FillColor", XrmoptionSepArg, "magenta"},
95 {"-OnOffLineColor", "*.OnOffLineColor", XrmoptionSepArg, "magenta"},
96 {"-LatexColor", "*.LatexColor", XrmoptionSepArg, "red"},
97 {"-NoteColor", "*.NoteColor", XrmoptionSepArg, "yellow"},
98 {"-NoteFrameColor", "*.NoteFrameColor", XrmoptionSepArg, "black"},
99 {"-LightedColor", "*.LightedColor", XrmoptionSepArg, "gray80"},
100 {"-BackgroundColor", "*.BackgroundColor", XrmoptionSepArg, "linen"},
101 {"-SelectionColor", "*.SelectionColor", XrmoptionSepArg, "lightblue"}
111 bool cursor_follows_scrollbar;
113 char math_frame_color[32];
115 char new_line_color[32];
116 char label_color[32];
118 char on_off_line_color[32];
119 char latex_color[32];
121 char note_frame_color[32];
122 char lighted_color[32];
123 LString background_color;
125 char selection_color[32];
130 {"width", "widthClass", FL_INT, &width, "690"},
131 {"height", "heightClass", FL_INT, &height, "510"},
132 {"xpos", "xposClass", FL_INT, &xpos, "-1"},
133 {"ypos", "yposClass", FL_INT, &ypos, "-1"},
134 {"Reverse", "reverseClass", FL_INT, &reverse_video, "0"},
135 {"Mono", "monoClass", FL_INT, &mono_video, "0"},
136 {"FastSelection", "selectionClass", FL_INT, &fast_selection, "0"},
137 {"MathColor", "colorClass", FL_STRING, math_color, "blue", 31},
138 {"MathFrameColor", "colorClass", FL_STRING, math_frame_color, "magenta", 31},
139 {"FootColor", "colorClass", FL_STRING, foot_color, "red", 31},
140 {"NewLineColor", "colorClass", FL_STRING, new_line_color, "red", 31},
141 {"LabelColor", "colorClass", FL_STRING, label_color, "palegreen", 31},
142 {"FillColor", "colorClass", FL_STRING, fill_color, "magenta", 31},
143 {"OnOffLineColor", "colorClass", FL_STRING, on_off_line_color, "magenta", 31},
144 {"LatexColor", "colorClass", FL_STRING, latex_color, "red", 31},
145 {"NoteColor", "colorClass", FL_STRING, note_color, "yellow", 31},
146 {"NoteFrameColor", "colorClass", FL_STRING, note_frame_color, "black", 31},
147 {"LightedColor", "colorClass", FL_STRING, lighted_color, "gray80", 31},
148 {"BackgroundColor", "colorClass", FL_STRING, b_c, "linen", 31},
149 {"SelectionColor", "colorClass", FL_STRING, selection_color, "lightblue", 31}
153 static int LyX_XErrHandler(Display *display, XErrorEvent *xeev)
155 //#warning Please see if you can trigger this!
157 if (!bufferlist.isEmpty())
158 bufferlist.emergencyWriteAll();
160 // Get the reason for the crash.
162 XGetErrorText(display, xeev->error_code, etxt, 512);
164 // By doing an abort we get a nice backtrace. (hopefully)
166 return 0; // Solaris CC wants us to return something
170 LyXGUI::LyXGUI(LyX *owner, int *argc, char *argv[], bool GUI)
179 static const int num_res = sizeof(res)/sizeof(FL_resource);
180 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
181 fl_get_app_resources(res, num_res);
182 Display *display = fl_get_display();
184 lyxerr.print("LyX: unable to access X display, exiting");
187 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
188 // X Error handler install goes here
189 XSetErrorHandler(LyX_XErrHandler);
191 background_color = b_c;
193 // Make sure default screen is not larger than monitor
194 if (width == 690 && height == 510) {
195 Screen * scr=(DefaultScreenOfDisplay(fl_get_display()));
196 if (HeightOfScreen(scr)-24<height)
197 height = HeightOfScreen(scr)-24;
198 if (WidthOfScreen(scr)-8<width)
199 width = WidthOfScreen(scr)-8;
205 // A destructor is always necessary (asierra-970604)
207 // Lyxserver was created in this class so should be destroyed
208 // here. asierra-970604
219 void LyXGUI::setDefaults()
222 cntl.buttonFontSize = FL_NORMAL_SIZE;
223 cntl.browserFontSize = FL_NORMAL_SIZE;
224 cntl.labelFontSize = FL_NORMAL_SIZE;
225 cntl.choiceFontSize = FL_NORMAL_SIZE;
226 cntl.inputFontSize = FL_NORMAL_SIZE;
227 cntl.menuFontSize = FL_NORMAL_SIZE;
228 cntl.borderWidth = -1;
229 cntl.vclass = FL_DefaultVisual;
230 fl_set_defaults(FL_PDVisual
231 | FL_PDButtonFontSize
232 | FL_PDBrowserFontSize
234 | FL_PDChoiceFontSize
237 | FL_PDBorderWidth, &cntl);
241 // This is called after we have parsed lyxrc
249 // Set the font name for popups and menus
250 LString menufontname = lyxrc->menu_font_name
251 + "-*-*-*-?-*-*-*-*-"
253 // "?" means "scale that font"
254 LString popupfontname = lyxrc->popup_font_name
255 + "-*-*-*-?-*-*-*-*-"
258 if (fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str()) < 0)
261 char ** list = XListFonts(fl_display, menufontname.c_str(),
263 XFreeFontNames(list);
265 fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
268 lyxerr.print("Could not set menu font to " + menufontname);
271 if (fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str()) < 0)
273 list = XListFonts(fl_display, popupfontname.c_str(),
275 XFreeFontNames(list);
277 fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
280 lyxerr.print("Could not set popup font to " + popupfontname);
282 // put here (after fl_initialize) to avoid segfault. Cannot be done
283 // in setDefaults() (Matthias 140496)
284 // Moved from ::LyXGUI to ::init to allow popup font customization
286 fl_setpup_fontstyle(FL_NORMAL_STYLE);
287 fl_setpup_fontsize(FL_NORMAL_SIZE);
288 fl_setpup_color(FL_MCOL,FL_BLACK);
289 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
291 // all lyxrc settings has to be done here as lyxrc has not yet
292 // been read when the GUI is created (Jug)
295 fl_set_input(fd_form_print->input_printer,
296 lyxrc->printer.c_str());
299 if (!lyxrc->custom_export_command.empty())
300 fl_set_input(fd_form_sendto->input_cmd,
301 lyxrc->custom_export_command.c_str());
302 if (lyxrc->custom_export_format == "lyx")
303 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
304 else if (lyxrc->custom_export_format == "tex")
305 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
306 else if (lyxrc->custom_export_format == "dvi")
307 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
308 else if (lyxrc->custom_export_format == "ps")
309 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
310 else if (lyxrc->custom_export_format == "ascii")
311 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
313 // Update parameters.
316 // Initialize the views.
319 // in 0.12 the initialisation of the LyXServer must be done here
320 // 0.13 it should be moved again...
321 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc->lyxpipes);
323 // This is to make sure we get the selection color
325 // This is to make sure we set the background_pixels
330 void LyXGUI::create_forms()
332 lyxerr.debug("Initializing LyXView...");
333 lyxViews = new LyXView(width, height);
334 lyxerr.debug("Initializing LyXView...done");
336 // From here down should be done by somebody else. (Lgb)
343 fd_form_title = create_form_form_title();
344 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
345 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, NULL);
346 fl_addto_form(fd_form_title->form_title);
347 #ifdef TWO_COLOR_ICONS
348 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON,0,0,425,290,"");
349 fl_set_bitmapbutton_data(obj,banner_bw_width,
350 banner_bw_height, banner_bw_bits);
351 fl_set_object_color(obj,FL_WHITE,FL_BLACK);
353 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON,0,0,425,290,"");
354 fl_set_pixmapbutton_data(obj, (char**)banner);
356 fl_set_pixmapbutton_focus_outline(obj,3);
359 fl_set_button_shortcut(obj,"^M ^[",1);
360 fl_set_object_boxtype(obj,FL_NO_BOX);
361 fl_set_object_callback(obj,TimerCB,0);
363 obj = fl_add_text(FL_NORMAL_TEXT,248,265,170,16, LYX_VERSION);
364 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
365 #ifdef TWO_COLOR_ICONS
366 fl_set_object_color(obj,FL_WHITE,FL_WHITE);
367 fl_set_object_lcol(obj,FL_BLACK);
369 // fl_set_object_color(obj,FL_WHITE, FL_WHITE);
370 // fl_set_object_lcol(obj,FL_BLACK);
371 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
372 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
373 fl_set_object_color(obj,FL_FREE_COL2, FL_FREE_COL2);
374 fl_set_object_lcol(obj,FL_FREE_COL3);
376 fl_set_object_lalign(obj,FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
377 fl_set_object_lstyle(obj,FL_BOLD_STYLE);
380 // the paragraph form
381 fd_form_paragraph = create_form_form_paragraph();
382 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
383 CancelCloseBoxCB, NULL);
384 fl_addto_choice(fd_form_paragraph->choice_space_above,
385 _(" None | Defskip | Smallskip "
386 "| Medskip | Bigskip | VFill | Length "));
387 fl_addto_choice(fd_form_paragraph->choice_space_below,
388 _(" None | Defskip | Smallskip "
389 "| Medskip | Bigskip | VFill | Length "));
390 fl_set_input_return(fd_form_paragraph->input_space_above,
392 fl_set_input_return(fd_form_paragraph->input_space_below,
395 // the paragraph extra form
396 fd_form_paragraph_extra = create_form_form_paragraph_extra();
397 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
398 CancelCloseBoxCB, NULL);
399 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
401 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
405 fd_form_search = create_form_form_search();
406 fl_set_form_atclose(fd_form_search->form_search,
407 CancelCloseBoxCB, NULL);
409 // the character form
410 fd_form_character = create_form_form_character();
411 fl_set_form_atclose(fd_form_character->form_character,
412 CancelCloseBoxCB, NULL);
413 fl_addto_choice(fd_form_character->choice_family,
414 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
415 fl_addto_choice(fd_form_character->choice_series,
416 _(" No change %l| Medium | Bold %l| Reset "));
417 fl_addto_choice(fd_form_character->choice_shape,
418 _(" No change %l| Upright | Italic | Slanted | Small Caps "
420 fl_addto_choice(fd_form_character->choice_size,
421 _(" No change %l| Tiny | Smallest | Smaller | Small "
422 "| Normal | Large | Larger | Largest | Huge | Huger "
423 "%l| Increase | Decrease | Reset "));
424 fl_addto_choice(fd_form_character->choice_bar,
425 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
426 fl_addto_choice(fd_form_character->choice_color,
427 _(" No change %l| No color | Black | White | Red | Green "
428 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
431 fd_form_document = create_form_form_document();
432 fl_set_form_atclose(fd_form_document->form_document,
433 CancelCloseBoxCB, NULL);
434 fl_addto_choice(fd_form_document->choice_spacing,
435 _(" Single | OneHalf | Double | Other "));
437 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-1,5);
438 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1,5);
439 fl_set_counter_step(fd_form_document->slider_secnumdepth,1,1);
440 fl_set_counter_step(fd_form_document->slider_tocdepth,1,1);
441 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
442 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
443 fl_addto_form(fd_form_document->form_document);
444 combo_language = new Combox(FL_COMBOX_DROPLIST);
445 FL_OBJECT *ob = fd_form_document->choice_language;
446 combo_language->add(ob->x, ob->y, ob->w, ob->h, 200);
447 combo_language->shortcut("#G",1);
449 int n; // declared here because DEC cxx does not like multiple
450 // declarations of variables in for() loops (JMarc)
451 for (n=0; tex_babel[n][0]; n++) {
452 combo_language->addto(tex_babel[n]);
455 // not really necessary, but we can do it anyway.
456 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
458 for (n=0; tex_fonts[n][0]; n++) {
459 fl_addto_choice(fd_form_document->choice_fonts,tex_fonts[n]);
462 fl_addto_choice(fd_form_document->choice_inputenc,
463 "default|latin1|latin2|latin5"
464 "|koi8-r|koi8-u|cp866|cp1251");
466 for (n=0; tex_graphics[n][0]; n++) {
467 fl_addto_choice(fd_form_document->choice_postscript_driver,
470 // not really necessary, but we can do it anyway.
471 fl_addto_choice(fd_form_document->choice_pagestyle,
472 "default|empty|plain|headings|fancy");
473 fl_addto_choice(fd_form_document->choice_default_skip,
474 _(" Smallskip | Medskip | Bigskip | Length "));
475 fl_set_input_return(fd_form_document->input_default_skip,
479 fd_form_paper = create_form_form_paper();
480 fl_set_form_atclose(fd_form_paper->form_paper,
481 CancelCloseBoxCB, NULL);
482 fl_addto_choice(fd_form_paper->choice_papersize2,
483 _(" Default | Custom | USletter | USlegal "
484 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
485 fl_addto_choice(fd_form_paper->choice_paperpackage,
487 "| A4 small Margins (only portrait) "
488 "| A4 very small Margins (only portrait) "
489 "| A4 very wide margins (only portrait) "));
490 fl_set_input_return(fd_form_paper->input_custom_width,
492 fl_set_input_return(fd_form_paper->input_custom_height,
494 fl_set_input_return(fd_form_paper->input_top_margin,
496 fl_set_input_return(fd_form_paper->input_bottom_margin,
498 fl_set_input_return(fd_form_paper->input_left_margin,
500 fl_set_input_return(fd_form_paper->input_right_margin,
502 fl_set_input_return(fd_form_paper->input_head_height,
504 fl_set_input_return(fd_form_paper->input_head_sep,
506 fl_set_input_return(fd_form_paper->input_foot_skip,
509 // the table_options form
510 fd_form_table_options = create_form_form_table_options();
511 fl_set_form_atclose(fd_form_table_options->form_table_options,
512 CancelCloseBoxCB, NULL);
513 fl_set_input_return(fd_form_table_options->input_column_width,
516 // the table_extra form
517 fd_form_table_extra = create_form_form_table_extra();
518 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
519 CancelCloseBoxCB, NULL);
520 fl_set_input_return(fd_form_table_extra->input_special_alignment,
522 fl_set_input_return(fd_form_table_extra->input_special_multialign,
526 fd_form_quotes = create_form_form_quotes();
527 fl_set_form_atclose(fd_form_quotes->form_quotes,
528 CancelCloseBoxCB, NULL);
529 // Is it wrong of me to use « » instead of << >> ? (Lgb)
530 // Maybe if people use a font other than latin1... (JMarc)
531 fl_addto_choice(fd_form_quotes->choice_quotes_language,
532 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
535 fd_form_preamble = create_form_form_preamble();
536 fl_set_form_atclose(fd_form_preamble->form_preamble,
537 CancelCloseBoxCB, NULL);
540 fd_form_table = create_form_form_table();
541 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, NULL);
542 fl_set_slider_bounds(fd_form_table->slider_rows,1,50);
543 fl_set_slider_bounds(fd_form_table->slider_columns,1,50);
544 fl_set_slider_value(fd_form_table->slider_rows, 5);
545 fl_set_slider_value(fd_form_table->slider_columns, 5);
546 fl_set_slider_precision(fd_form_table->slider_rows, 0);
547 fl_set_slider_precision(fd_form_table->slider_columns, 0);
550 fd_form_print = create_form_form_print();
551 fl_set_form_atclose(fd_form_print->form_print, CancelCloseBoxCB, NULL);
552 fl_set_button(fd_form_print->radio_printer, 1);
553 fl_set_button(fd_form_print->radio_file, 0);
554 fl_set_button(fd_form_print->radio_order_normal, 1);
555 fl_set_button(fd_form_print->radio_order_reverse, 0);
556 fl_set_button(fd_form_print->radio_all_pages, 1);
557 fl_set_button(fd_form_print->radio_odd_pages, 0);
558 fl_set_button(fd_form_print->radio_even_pages, 0);
561 fd_form_sendto = create_form_form_sendto();
562 fl_set_form_atclose(fd_form_sendto->form_sendto,CancelCloseBoxCB,NULL);
565 fd_form_figure = create_form_form_figure();
566 fl_set_form_atclose(fd_form_figure->form_figure,
567 CancelCloseBoxCB, NULL);
568 fl_set_button(fd_form_figure->radio_postscript, 1);
571 fd_form_screen = create_form_form_screen();
572 fl_set_form_atclose(fd_form_screen->form_screen,
573 CancelCloseBoxCB, NULL);
576 fd_form_toc = create_form_form_toc();
577 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, NULL);
580 fd_form_ref = create_form_form_ref();
581 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, NULL);
583 // the latex options form
584 fd_latex_options = create_form_LaTeXOptions();
585 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
586 CancelCloseBoxCB, NULL);
588 // the latex log form
589 fd_latex_log = create_form_LaTeXLog();
590 fl_set_form_atclose(fd_latex_log->LaTeXLog,
591 CancelCloseBoxCB, NULL);
593 // Show the main & title form
594 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
595 int title_placement = FL_PLACE_CENTER;
596 // Did we get a valid position?
597 if (xpos>=0 && ypos>=0) {
598 lyxViews->setPosition(xpos, ypos);
599 // show the title form in the middle of the main form
600 fl_set_form_position(fd_form_title->form_title,
601 abs(xpos + (width/2) - (370 / 2)),
602 abs(ypos + (height/2) - (290 / 2)));
603 // The use of abs() above is a trick to ensure valid positions
604 main_placement = FL_PLACE_POSITION;
605 title_placement = FL_PLACE_GEOMETRY;
607 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
608 fl_show_form(fd_form_title->form_title,
609 title_placement, FL_NOBORDER,
611 fl_redraw_form(fd_form_title->form_title);
612 fl_raise_form(fd_form_title->form_title);
614 // Show the title form at most 7 secs (lowered from 10 secs)
615 fl_set_timer(fd_form_title->timer_title, 7);
619 void LyXGUI::runTime()
620 /* This will usually be toolkit (GUI) specific. This is
621 * also usually the XEvent dispatcher of the GUI. */
630 if (fl_check_forms() == FL_EVENT) {
631 lyxerr.print("LyX: This shouldn't happen...");
638 void LyXGUI::regBuf(Buffer *b)
640 lyxViews->currentView()->setBuffer(b);