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
24 #include FORMS_H_LOCATION
28 #include "layout_forms.h"
29 #include "print_form.h"
30 #include "tex-strings.h"
37 #include "lyxserver.h"
40 #include "lyx_gui_misc.h"
41 #include "lyxlookup.h"
42 #include "bufferlist.h"
44 #include "ColorHandler.h"
46 #ifdef TWO_COLOR_ICONS
47 #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_character * fd_form_character;
58 FD_form_document * fd_form_document;
59 FD_form_paper * fd_form_paper;
60 FD_form_table_options * fd_form_table_options;
61 FD_form_table_extra * fd_form_table_extra;
62 FD_form_quotes * fd_form_quotes;
63 FD_form_preamble * fd_form_preamble;
64 FD_form_table * fd_form_table;
65 FD_form_sendto * fd_form_sendto;
66 FD_form_figure * fd_form_figure;
67 FD_form_screen * fd_form_screen;
68 FD_form_toc * fd_form_toc;
69 FD_form_ref * fd_form_ref;
70 FD_LaTeXLog * fd_latex_log; // from log_form.h
71 Combox * combo_language;
72 Combox * combo_language2;
74 extern LyXServer * lyxserver;
75 extern bool finished; // flag, that we are quitting the program
76 extern BufferList bufferlist;
80 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
83 static int width = 690;
84 static int height = 510;
87 static char geometry[40];
88 bool cursor_follows_scrollbar;
93 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
97 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
99 //#warning Please see if you can trigger this!
101 if (!bufferlist.empty())
102 bufferlist.emergencyWriteAll();
104 // Get the reason for the crash.
106 XGetErrorText(display, xeev->error_code, etxt, 512);
107 lyxerr << etxt << endl;
108 // By doing an abort we get a nice backtrace. (hopefully)
110 return 0; // Solaris CC wants us to return something
114 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
115 : _owner(owner), lyxViews(0)
123 static const int num_res = sizeof(res)/sizeof(FL_resource);
124 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
125 fl_get_app_resources(res, num_res);
127 static const int geometryBitmask = XParseGeometry( geometry,
130 (unsigned int *) &width,
131 (unsigned int *) &height
134 Display * display = fl_get_display();
136 lyxerr << "LyX: unable to access X display, exiting" << endl;
139 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
140 // X Error handler install goes here
141 XSetErrorHandler(LyX_XErrHandler);
143 // A width less than 590 pops up an awkward main window
144 // The minimal values of width/height (590/400) are defined in
146 if (width < 590) width = 590;
147 if (height < 400) height = 400;
149 // If width is not set by geometry, check it against monitor width
150 if ( !(geometryBitmask & 4) ) {
151 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
152 if (WidthOfScreen(scr) - 8 < width)
153 width = WidthOfScreen(scr) - 8;
156 // If height is not set by geometry, check it against monitor height
157 if ( !(geometryBitmask & 8) ) {
158 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
159 if (HeightOfScreen(scr) - 24 < height)
160 height = HeightOfScreen(scr) - 24;
163 // Recalculate xpos if it's negative
164 if (geometryBitmask & 16)
165 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
167 // Recalculate ypos if it's negative
168 if (geometryBitmask & 32)
169 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
171 // Initialize the LyXColorHandler
172 lyxColorHandler = new LyXColorHandler;
176 // A destructor is always necessary (asierra-970604)
179 // Lyxserver was created in this class so should be destroyed
180 // here. asierra-970604
190 void LyXGUI::setDefaults()
193 cntl.buttonFontSize = FL_NORMAL_SIZE;
194 cntl.browserFontSize = FL_NORMAL_SIZE;
195 cntl.labelFontSize = FL_NORMAL_SIZE;
196 cntl.choiceFontSize = FL_NORMAL_SIZE;
197 cntl.inputFontSize = FL_NORMAL_SIZE;
198 cntl.menuFontSize = FL_NORMAL_SIZE;
199 cntl.borderWidth = -1;
200 cntl.vclass = FL_DefaultVisual;
201 fl_set_defaults(FL_PDVisual
202 | FL_PDButtonFontSize
203 | FL_PDBrowserFontSize
205 | FL_PDChoiceFontSize
208 | FL_PDBorderWidth, &cntl);
212 // This is called after we have parsed lyxrc
220 if (lyxrc.font_norm_menu.empty())
221 lyxrc.font_norm_menu = lyxrc.font_norm;
222 // Set the font name for popups and menus
223 string menufontname = lyxrc.menu_font_name
224 + "-*-*-*-?-*-*-*-*-"
225 + lyxrc.font_norm_menu;
226 // "?" means "scale that font"
227 string popupfontname = lyxrc.popup_font_name
228 + "-*-*-*-?-*-*-*-*-"
229 + lyxrc.font_norm_menu;
231 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
232 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
234 lyxerr << "Could not set menu font to "
235 << menufontname << endl;
238 lyxerr << "Could not set popup font to "
239 << popupfontname << endl;
241 if (bold < 0 && normal < 0) {
242 lyxerr << "Using 'helvetica' font for menus" << endl;
243 bold = fl_set_font_name(FL_BOLD_STYLE,
244 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
245 normal = fl_set_font_name(FL_NORMAL_STYLE,
246 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
247 if (bold < 0 && normal < 0) {
248 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
249 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
253 // put here (after fl_initialize) to avoid segfault. Cannot be done
254 // in setDefaults() (Matthias 140496)
255 // Moved from ::LyXGUI to ::init to allow popup font customization
257 fl_setpup_fontstyle(FL_NORMAL_STYLE);
258 fl_setpup_fontsize(FL_NORMAL_SIZE);
259 fl_setpup_color(FL_MCOL, FL_BLACK);
260 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
262 // all lyxrc settings has to be done here as lyxrc has not yet
263 // been read when the GUI is created (Jug)
266 if (!lyxrc.custom_export_command.empty())
267 fl_set_input(fd_form_sendto->input_cmd,
268 lyxrc.custom_export_command.c_str());
269 if (lyxrc.custom_export_format == "lyx")
270 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
271 else if (lyxrc.custom_export_format == "tex")
272 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
273 else if (lyxrc.custom_export_format == "dvi")
274 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
275 else if (lyxrc.custom_export_format == "ps")
276 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
277 else if (lyxrc.custom_export_format == "ascii")
278 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
280 // Update parameters.
283 // Initialize the views.
286 // in 0.12 the initialisation of the LyXServer must be done here
287 // 0.13 it should be moved again...
288 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
292 void LyXGUI::create_forms()
294 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
295 lyxViews = new LyXView(width, height);
296 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
298 // From here down should be done by somebody else. (Lgb)
305 if (lyxrc.show_banner) {
306 fd_form_title = create_form_form_title();
307 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
308 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
309 fl_addto_form(fd_form_title->form_title);
310 #ifdef TWO_COLOR_ICONS
311 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
312 fl_set_bitmapbutton_data(obj, banner_bw_width,
313 banner_bw_height, banner_bw_bits);
314 fl_set_object_color(obj, FL_WHITE, FL_BLACK);
316 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
317 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
319 fl_set_pixmapbutton_focus_outline(obj, 3);
321 fl_set_button_shortcut(obj, "^M ^[", 1);
322 fl_set_object_boxtype(obj, FL_NO_BOX);
323 fl_set_object_callback(obj, TimerCB, 0);
325 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
326 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
327 #ifdef TWO_COLOR_ICONS
328 fl_set_object_color(obj, FL_WHITE, FL_WHITE);
329 fl_set_object_lcol(obj, FL_BLACK);
331 // fl_set_object_color(obj, FL_WHITE, FL_WHITE);
332 // fl_set_object_lcol(obj, FL_BLACK);
333 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
334 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
335 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
336 fl_set_object_lcol(obj, FL_FREE_COL3);
338 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
339 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
343 // the paragraph form
344 fd_form_paragraph = create_form_form_paragraph();
345 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
346 CancelCloseBoxCB, 0);
347 fl_addto_choice(fd_form_paragraph->choice_space_above,
348 _(" None | Defskip | Smallskip "
349 "| Medskip | Bigskip | VFill | Length "));
350 fl_addto_choice(fd_form_paragraph->choice_space_below,
351 _(" None | Defskip | Smallskip "
352 "| Medskip | Bigskip | VFill | Length "));
353 fl_set_input_return(fd_form_paragraph->input_space_above,
355 fl_set_input_return(fd_form_paragraph->input_space_below,
358 // the paragraph extra form
359 fd_form_paragraph_extra = create_form_form_paragraph_extra();
360 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
361 CancelCloseBoxCB, 0);
362 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
364 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
366 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
368 // the character form
369 fd_form_character = create_form_form_character();
370 fl_set_form_atclose(fd_form_character->form_character,
371 CancelCloseBoxCB, 0);
372 fl_addto_choice(fd_form_character->choice_family,
373 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
374 fl_addto_choice(fd_form_character->choice_series,
375 _(" No change %l| Medium | Bold %l| Reset "));
376 fl_addto_choice(fd_form_character->choice_shape,
377 _(" No change %l| Upright | Italic | Slanted | Small Caps "
379 fl_addto_choice(fd_form_character->choice_size,
380 _(" No change %l| Tiny | Smallest | Smaller | Small "
381 "| Normal | Large | Larger | Largest | Huge | Huger "
382 "%l| Increase | Decrease | Reset "));
383 fl_addto_choice(fd_form_character->choice_bar,
384 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
385 fl_addto_choice(fd_form_character->choice_color,
386 _(" No change %l| No color | Black | White | Red | Green "
387 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
388 fl_set_form_minsize(fd_form_character->form_character,
389 fd_form_character->form_character->w,
390 fd_form_character->form_character->h);
391 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
392 fl_addto_form(fd_form_character->form_character);
393 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
394 FL_OBJECT * ob = fd_form_character->choice_language;
395 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
396 combo_language2->shortcut("#L", 1);
398 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
401 fd_form_document = create_form_form_document();
402 fl_set_form_atclose(fd_form_document->form_document,
403 CancelCloseBoxCB, 0);
404 fl_addto_choice(fd_form_document->choice_spacing,
405 _(" Single | OneHalf | Double | Other "));
407 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
408 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
409 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
410 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
411 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
412 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
413 fl_addto_form(fd_form_document->form_document);
414 combo_language = new Combox(FL_COMBOX_DROPLIST);
415 ob = fd_form_document->choice_language;
416 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
417 combo_language->shortcut("#G", 1);
420 // "default" is not part of the languages array any more.
421 combo_language->addto("default");
422 combo_language2->addto(_("No change"));
423 combo_language2->addto(_("Reset"));
424 for(Languages::const_iterator cit = languages.begin();
425 cit != languages.end(); ++cit) {
426 combo_language->addto((*cit).second.lang().c_str());
427 combo_language2->addto((*cit).second.lang().c_str());
429 combo_language2->select_text("No change");
431 // not really necessary, but we can do it anyway.
432 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
434 for (n = 0; tex_fonts[n][0]; ++n) {
435 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
438 fl_addto_choice(fd_form_document->choice_inputenc,
439 "default|auto|latin1|latin2|latin5"
440 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
442 for (n = 0; tex_graphics[n][0]; ++n) {
443 fl_addto_choice(fd_form_document->choice_postscript_driver,
446 // not really necessary, but we can do it anyway.
447 fl_addto_choice(fd_form_document->choice_pagestyle,
448 "default|empty|plain|headings|fancy");
449 fl_addto_choice(fd_form_document->choice_default_skip,
450 _(" Smallskip | Medskip | Bigskip | Length "));
451 fl_set_input_return(fd_form_document->input_default_skip,
453 fl_set_form_minsize(fd_form_document->form_document,
454 fd_form_document->form_document->w,
455 fd_form_document->form_document->h);
456 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
459 fd_form_paper = create_form_form_paper();
460 fl_set_form_atclose(fd_form_paper->form_paper,
461 CancelCloseBoxCB, 0);
462 fl_addto_choice(fd_form_paper->choice_papersize2,
463 _(" Default | Custom | USletter | USlegal "
464 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
465 fl_addto_choice(fd_form_paper->choice_paperpackage,
467 "| A4 small Margins (only portrait) "
468 "| A4 very small Margins (only portrait) "
469 "| A4 very wide margins (only portrait) "));
470 fl_set_input_return(fd_form_paper->input_custom_width,
472 fl_set_input_return(fd_form_paper->input_custom_height,
474 fl_set_input_return(fd_form_paper->input_top_margin,
476 fl_set_input_return(fd_form_paper->input_bottom_margin,
478 fl_set_input_return(fd_form_paper->input_left_margin,
480 fl_set_input_return(fd_form_paper->input_right_margin,
482 fl_set_input_return(fd_form_paper->input_head_height,
484 fl_set_input_return(fd_form_paper->input_head_sep,
486 fl_set_input_return(fd_form_paper->input_foot_skip,
488 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
490 // the table_options form
491 fd_form_table_options = create_form_form_table_options();
492 fl_set_form_atclose(fd_form_table_options->form_table_options,
493 CancelCloseBoxCB, 0);
494 fl_set_input_return(fd_form_table_options->input_column_width,
497 // the table_extra form
498 fd_form_table_extra = create_form_form_table_extra();
499 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
500 CancelCloseBoxCB, 0);
501 fl_set_input_return(fd_form_table_extra->input_special_alignment,
503 fl_set_input_return(fd_form_table_extra->input_special_multialign,
505 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
508 fd_form_quotes = create_form_form_quotes();
509 fl_set_form_atclose(fd_form_quotes->form_quotes,
510 CancelCloseBoxCB, 0);
511 // Is it wrong of me to use « » instead of << >> ? (Lgb)
512 // Maybe if people use a font other than latin1... (JMarc)
513 fl_addto_choice(fd_form_quotes->choice_quotes_language,
514 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
517 fd_form_preamble = create_form_form_preamble();
518 fl_set_form_atclose(fd_form_preamble->form_preamble,
519 CancelCloseBoxCB, 0);
523 fd_form_table = create_form_form_table();
524 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
525 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
526 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
527 fl_set_slider_value(fd_form_table->slider_rows, 5);
528 fl_set_slider_value(fd_form_table->slider_columns, 5);
529 fl_set_slider_precision(fd_form_table->slider_rows, 0);
530 fl_set_slider_precision(fd_form_table->slider_columns, 0);
531 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
535 fd_form_sendto = create_form_form_sendto();
536 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
539 fd_form_figure = create_form_form_figure();
540 fl_set_form_atclose(fd_form_figure->form_figure,
541 CancelCloseBoxCB, 0);
542 fl_set_button(fd_form_figure->radio_postscript, 1);
545 fd_form_screen = create_form_form_screen();
546 fl_set_form_atclose(fd_form_screen->form_screen,
547 CancelCloseBoxCB, 0);
550 fd_form_toc = create_form_form_toc();
551 fl_addto_choice(fd_form_toc->toctype,
552 _(" TOC | LOF | LOT | LOA "));
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 log form
562 fd_latex_log = create_form_LaTeXLog();
563 fl_set_form_atclose(fd_latex_log->LaTeXLog,
564 CancelCloseBoxCB, 0);
566 // Show the main & title form
567 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
568 int title_placement = FL_PLACE_CENTER;
569 // Did we get a valid position?
570 if (xpos>= 0 && ypos>= 0) {
571 lyxViews->setPosition(xpos, ypos);
572 if (lyxrc.show_banner) {
573 // show the title form in the middle of the main form
574 fl_set_form_position(fd_form_title->form_title,
575 abs(xpos + (width/2) - (370 / 2)),
576 abs(ypos + (height/2) - (290 / 2)));
577 title_placement = FL_PLACE_GEOMETRY;
578 // The use of abs() above is a trick to ensure
581 main_placement = FL_PLACE_POSITION;
583 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
584 if (lyxrc.show_banner) {
585 fl_show_form(fd_form_title->form_title,
586 title_placement, FL_NOBORDER,
588 fl_redraw_form(fd_form_title->form_title);
589 fl_raise_form(fd_form_title->form_title);
591 // Show the title form at most 7 secs (lowered from 10 secs)
592 fl_set_timer(fd_form_title->timer_title, 7);
597 void LyXGUI::runTime()
598 /* This will usually be toolkit (GUI) specific. This is
599 * also usually the XEvent dispatcher of the GUI. */
609 kapp->processEvents();
611 if (fl_check_forms() == FL_EVENT) {
612 lyxerr << "LyX: This shouldn't happen..." << endl;
619 void LyXGUI::regBuf(Buffer * b)
621 lyxViews->view()->buffer(b);
624 LyXView * LyXGUI::getLyXView() const