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;
70 Combox * combo_language2;
72 extern LyXServer * lyxserver;
73 extern bool finished; // flag, that we are quitting the program
74 extern BufferList bufferlist;
78 {"-width", "*.width", XrmoptionSepArg, "690"},
79 {"-height", "*.height", XrmoptionSepArg, "510"},
80 {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
81 {"-ypos", "*.ypos", XrmoptionSepArg, "-1"}
88 bool cursor_follows_scrollbar;
93 {"width", "widthClass", FL_INT, &width, "690", 0},
94 {"height", "heightClass", FL_INT, &height, "510", 0},
95 {"xpos", "xposClass", FL_INT, &xpos, "-1", 0},
96 {"ypos", "yposClass", FL_INT, &ypos, "-1", 0}
100 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
102 //#warning Please see if you can trigger this!
104 if (!bufferlist.empty())
105 bufferlist.emergencyWriteAll();
107 // Get the reason for the crash.
109 XGetErrorText(display, xeev->error_code, etxt, 512);
110 lyxerr << etxt << endl;
111 // By doing an abort we get a nice backtrace. (hopefully)
113 return 0; // Solaris CC wants us to return something
117 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
118 : _owner(owner), lyxViews(0)
126 static const int num_res = sizeof(res)/sizeof(FL_resource);
127 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
128 fl_get_app_resources(res, num_res);
130 Display * display = fl_get_display();
132 lyxerr << "LyX: unable to access X display, exiting" << endl;
135 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
136 // X Error handler install goes here
137 XSetErrorHandler(LyX_XErrHandler);
139 // Make sure default screen is not larger than monitor
140 if (width == 690 && height == 510) {
141 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
142 if (HeightOfScreen(scr) - 24 < height)
143 height = HeightOfScreen(scr) - 24;
144 if (WidthOfScreen(scr) - 8 < width)
145 width = WidthOfScreen(scr) - 8;
148 // Initialize the LyXColorHandler
149 lyxColorHandler = new LyXColorHandler;
153 // A destructor is always necessary (asierra-970604)
156 // Lyxserver was created in this class so should be destroyed
157 // here. asierra-970604
167 void LyXGUI::setDefaults()
170 cntl.buttonFontSize = FL_NORMAL_SIZE;
171 cntl.browserFontSize = FL_NORMAL_SIZE;
172 cntl.labelFontSize = FL_NORMAL_SIZE;
173 cntl.choiceFontSize = FL_NORMAL_SIZE;
174 cntl.inputFontSize = FL_NORMAL_SIZE;
175 cntl.menuFontSize = FL_NORMAL_SIZE;
176 cntl.borderWidth = -1;
177 cntl.vclass = FL_DefaultVisual;
178 fl_set_defaults(FL_PDVisual
179 | FL_PDButtonFontSize
180 | FL_PDBrowserFontSize
182 | FL_PDChoiceFontSize
185 | FL_PDBorderWidth, &cntl);
189 // This is called after we have parsed lyxrc
197 if (lyxrc.font_norm_menu.empty())
198 lyxrc.font_norm_menu = lyxrc.font_norm;
199 // Set the font name for popups and menus
200 string menufontname = lyxrc.menu_font_name
201 + "-*-*-*-?-*-*-*-*-"
202 + lyxrc.font_norm_menu;
203 // "?" means "scale that font"
204 string popupfontname = lyxrc.popup_font_name
205 + "-*-*-*-?-*-*-*-*-"
206 + lyxrc.font_norm_menu;
208 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
209 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
211 lyxerr << "Could not set menu font to "
212 << menufontname << endl;
215 lyxerr << "Could not set popup font to "
216 << popupfontname << endl;
218 if (bold < 0 && normal < 0) {
219 lyxerr << "Using 'helvetica' font for menus" << endl;
220 bold = fl_set_font_name(FL_BOLD_STYLE,
221 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
222 normal = fl_set_font_name(FL_NORMAL_STYLE,
223 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
224 if (bold < 0 && normal < 0) {
225 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
226 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
230 // put here (after fl_initialize) to avoid segfault. Cannot be done
231 // in setDefaults() (Matthias 140496)
232 // Moved from ::LyXGUI to ::init to allow popup font customization
234 fl_setpup_fontstyle(FL_NORMAL_STYLE);
235 fl_setpup_fontsize(FL_NORMAL_SIZE);
236 fl_setpup_color(FL_MCOL, FL_BLACK);
237 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
239 // all lyxrc settings has to be done here as lyxrc has not yet
240 // been read when the GUI is created (Jug)
243 fl_set_input(fd_form_print->input_printer,
244 lyxrc.printer.c_str());
247 if (!lyxrc.custom_export_command.empty())
248 fl_set_input(fd_form_sendto->input_cmd,
249 lyxrc.custom_export_command.c_str());
250 if (lyxrc.custom_export_format == "lyx")
251 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
252 else if (lyxrc.custom_export_format == "tex")
253 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
254 else if (lyxrc.custom_export_format == "dvi")
255 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
256 else if (lyxrc.custom_export_format == "ps")
257 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
258 else if (lyxrc.custom_export_format == "ascii")
259 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
261 // Update parameters.
264 // Initialize the views.
267 // in 0.12 the initialisation of the LyXServer must be done here
268 // 0.13 it should be moved again...
269 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
273 void LyXGUI::create_forms()
275 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
276 lyxViews = new LyXView(width, height);
277 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
279 // From here down should be done by somebody else. (Lgb)
286 if (lyxrc.show_banner) {
287 fd_form_title = create_form_form_title();
288 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
289 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
290 fl_addto_form(fd_form_title->form_title);
291 #ifdef TWO_COLOR_ICONS
292 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
293 fl_set_bitmapbutton_data(obj, banner_bw_width,
294 banner_bw_height, banner_bw_bits);
295 fl_set_object_color(obj, FL_WHITE, FL_BLACK);
297 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
298 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
300 fl_set_pixmapbutton_focus_outline(obj, 3);
302 fl_set_button_shortcut(obj, "^M ^[", 1);
303 fl_set_object_boxtype(obj, FL_NO_BOX);
304 fl_set_object_callback(obj, TimerCB, 0);
306 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
307 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
308 #ifdef TWO_COLOR_ICONS
309 fl_set_object_color(obj, FL_WHITE, FL_WHITE);
310 fl_set_object_lcol(obj, FL_BLACK);
312 // fl_set_object_color(obj, FL_WHITE, FL_WHITE);
313 // fl_set_object_lcol(obj, FL_BLACK);
314 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
315 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
316 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
317 fl_set_object_lcol(obj, FL_FREE_COL3);
319 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
320 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
324 // the paragraph form
325 fd_form_paragraph = create_form_form_paragraph();
326 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
327 CancelCloseBoxCB, 0);
328 fl_addto_choice(fd_form_paragraph->choice_space_above,
329 _(" None | Defskip | Smallskip "
330 "| Medskip | Bigskip | VFill | Length "));
331 fl_addto_choice(fd_form_paragraph->choice_space_below,
332 _(" None | Defskip | Smallskip "
333 "| Medskip | Bigskip | VFill | Length "));
334 fl_set_input_return(fd_form_paragraph->input_space_above,
336 fl_set_input_return(fd_form_paragraph->input_space_below,
339 // the paragraph extra form
340 fd_form_paragraph_extra = create_form_form_paragraph_extra();
341 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
342 CancelCloseBoxCB, 0);
343 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
345 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
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 fl_addto_form(fd_form_character->form_character);
372 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
373 FL_OBJECT * ob = fd_form_character->choice_language;
374 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
375 combo_language2->shortcut("#L", 1);
379 fd_form_document = create_form_form_document();
380 fl_set_form_atclose(fd_form_document->form_document,
381 CancelCloseBoxCB, 0);
382 fl_addto_choice(fd_form_document->choice_spacing,
383 _(" Single | OneHalf | Double | Other "));
385 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
386 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
387 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
388 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
389 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
390 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
391 fl_addto_form(fd_form_document->form_document);
392 combo_language = new Combox(FL_COMBOX_DROPLIST);
393 ob = fd_form_document->choice_language;
394 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
395 combo_language->shortcut("#G", 1);
398 // "default" is not part of the languages array any more.
399 combo_language->addto("default");
400 combo_language2->addto("No change");
401 for(Languages::const_iterator cit = languages.begin();
402 cit != languages.end(); ++cit) {
403 combo_language->addto((*cit).second.lang.c_str());
404 combo_language2->addto((*cit).second.lang.c_str());
406 combo_language2->select_text("No change");
408 // not really necessary, but we can do it anyway.
409 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
411 for (n = 0; tex_fonts[n][0]; ++n) {
412 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
415 fl_addto_choice(fd_form_document->choice_inputenc,
416 "default|latin1|latin2|latin5"
417 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
419 for (n = 0; tex_graphics[n][0]; ++n) {
420 fl_addto_choice(fd_form_document->choice_postscript_driver,
423 // not really necessary, but we can do it anyway.
424 fl_addto_choice(fd_form_document->choice_pagestyle,
425 "default|empty|plain|headings|fancy");
426 fl_addto_choice(fd_form_document->choice_default_skip,
427 _(" Smallskip | Medskip | Bigskip | Length "));
428 fl_set_input_return(fd_form_document->input_default_skip,
430 fl_set_form_minsize(fd_form_document->form_document,
431 fd_form_document->form_document->w,
432 fd_form_document->form_document->h);
435 fd_form_paper = create_form_form_paper();
436 fl_set_form_atclose(fd_form_paper->form_paper,
437 CancelCloseBoxCB, 0);
438 fl_addto_choice(fd_form_paper->choice_papersize2,
439 _(" Default | Custom | USletter | USlegal "
440 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
441 fl_addto_choice(fd_form_paper->choice_paperpackage,
443 "| A4 small Margins (only portrait) "
444 "| A4 very small Margins (only portrait) "
445 "| A4 very wide margins (only portrait) "));
446 fl_set_input_return(fd_form_paper->input_custom_width,
448 fl_set_input_return(fd_form_paper->input_custom_height,
450 fl_set_input_return(fd_form_paper->input_top_margin,
452 fl_set_input_return(fd_form_paper->input_bottom_margin,
454 fl_set_input_return(fd_form_paper->input_left_margin,
456 fl_set_input_return(fd_form_paper->input_right_margin,
458 fl_set_input_return(fd_form_paper->input_head_height,
460 fl_set_input_return(fd_form_paper->input_head_sep,
462 fl_set_input_return(fd_form_paper->input_foot_skip,
465 // the table_options form
466 fd_form_table_options = create_form_form_table_options();
467 fl_set_form_atclose(fd_form_table_options->form_table_options,
468 CancelCloseBoxCB, 0);
469 fl_set_input_return(fd_form_table_options->input_column_width,
472 // the table_extra form
473 fd_form_table_extra = create_form_form_table_extra();
474 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
475 CancelCloseBoxCB, 0);
476 fl_set_input_return(fd_form_table_extra->input_special_alignment,
478 fl_set_input_return(fd_form_table_extra->input_special_multialign,
482 fd_form_quotes = create_form_form_quotes();
483 fl_set_form_atclose(fd_form_quotes->form_quotes,
484 CancelCloseBoxCB, 0);
485 // Is it wrong of me to use « » instead of << >> ? (Lgb)
486 // Maybe if people use a font other than latin1... (JMarc)
487 fl_addto_choice(fd_form_quotes->choice_quotes_language,
488 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
491 fd_form_preamble = create_form_form_preamble();
492 fl_set_form_atclose(fd_form_preamble->form_preamble,
493 CancelCloseBoxCB, 0);
496 fd_form_table = create_form_form_table();
497 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
498 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
499 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
500 fl_set_slider_value(fd_form_table->slider_rows, 5);
501 fl_set_slider_value(fd_form_table->slider_columns, 5);
502 fl_set_slider_precision(fd_form_table->slider_rows, 0);
503 fl_set_slider_precision(fd_form_table->slider_columns, 0);
506 fd_form_print = create_form_form_print();
507 fl_set_form_atclose(fd_form_print->form_print, CancelCloseBoxCB, 0);
508 fl_set_button(fd_form_print->radio_printer, 1);
509 fl_set_button(fd_form_print->radio_file, 0);
510 fl_set_button(fd_form_print->radio_order_normal, 1);
511 fl_set_button(fd_form_print->radio_order_reverse, 0);
512 fl_set_button(fd_form_print->radio_all_pages, 1);
513 fl_set_button(fd_form_print->radio_odd_pages, 0);
514 fl_set_button(fd_form_print->radio_even_pages, 0);
517 fd_form_sendto = create_form_form_sendto();
518 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
521 fd_form_figure = create_form_form_figure();
522 fl_set_form_atclose(fd_form_figure->form_figure,
523 CancelCloseBoxCB, 0);
524 fl_set_button(fd_form_figure->radio_postscript, 1);
527 fd_form_screen = create_form_form_screen();
528 fl_set_form_atclose(fd_form_screen->form_screen,
529 CancelCloseBoxCB, 0);
532 fd_form_toc = create_form_form_toc();
533 fl_addto_choice(fd_form_toc->toctype,
534 _(" TOC | LOF | LOT | LOA "));
535 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
538 fd_form_ref = create_form_form_ref();
539 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
540 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
541 fd_form_ref->form_ref->h);
543 // the latex options form
544 fd_latex_options = create_form_LaTeXOptions();
545 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
546 CancelCloseBoxCB, 0);
548 // the latex log form
549 fd_latex_log = create_form_LaTeXLog();
550 fl_set_form_atclose(fd_latex_log->LaTeXLog,
551 CancelCloseBoxCB, 0);
553 // Show the main & title form
554 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
555 int title_placement = FL_PLACE_CENTER;
556 // Did we get a valid position?
557 if (xpos>= 0 && ypos>= 0) {
558 lyxViews->setPosition(xpos, ypos);
559 if (lyxrc.show_banner) {
560 // show the title form in the middle of the main form
561 fl_set_form_position(fd_form_title->form_title,
562 abs(xpos + (width/2) - (370 / 2)),
563 abs(ypos + (height/2) - (290 / 2)));
564 title_placement = FL_PLACE_GEOMETRY;
565 // The use of abs() above is a trick to ensure
568 main_placement = FL_PLACE_POSITION;
570 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
571 if (lyxrc.show_banner) {
572 fl_show_form(fd_form_title->form_title,
573 title_placement, FL_NOBORDER,
575 fl_redraw_form(fd_form_title->form_title);
576 fl_raise_form(fd_form_title->form_title);
578 // Show the title form at most 7 secs (lowered from 10 secs)
579 fl_set_timer(fd_form_title->timer_title, 7);
584 void LyXGUI::runTime()
585 /* This will usually be toolkit (GUI) specific. This is
586 * also usually the XEvent dispatcher of the GUI. */
595 if (fl_check_forms() == FL_EVENT) {
596 lyxerr << "LyX: This shouldn't happen..." << endl;
603 void LyXGUI::regBuf(Buffer * b)
605 lyxViews->view()->buffer(b);
608 LyXView * LyXGUI::getLyXView() const