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
25 #include "support/filetools.h"
29 #include "layout_forms.h"
30 #include "print_form.h"
31 #include "tex-strings.h"
38 #include "lyxserver.h"
41 #include "lyx_gui_misc.h"
42 #include "lyxlookup.h"
43 #include "bufferlist.h"
45 #include "ColorHandler.h"
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_sendto * fd_form_sendto;
61 FD_form_figure * fd_form_figure;
62 FD_form_screen * fd_form_screen;
63 FD_form_toc * fd_form_toc;
64 FD_form_ref * fd_form_ref;
65 FD_LaTeXLog * fd_latex_log; // from log_form.h
66 Combox * combo_language;
67 Combox * combo_language2;
69 extern LyXServer * lyxserver;
70 extern bool finished; // flag, that we are quitting the program
71 extern BufferList bufferlist;
75 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
78 static int width = 690;
79 static int height = 510;
82 static char geometry[40];
83 bool cursor_follows_scrollbar;
88 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
92 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
94 //#warning Please see if you can trigger this!
96 if (!bufferlist.empty())
97 bufferlist.emergencyWriteAll();
99 // Get the reason for the crash.
101 XGetErrorText(display, xeev->error_code, etxt, 512);
102 lyxerr << etxt << endl;
103 // By doing an abort we get a nice backtrace. (hopefully)
105 return 0; // Solaris CC wants us to return something
109 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
110 : _owner(owner), lyxViews(0)
118 static const int num_res = sizeof(res)/sizeof(FL_resource);
119 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
120 fl_get_app_resources(res, num_res);
122 static const int geometryBitmask = XParseGeometry( geometry,
125 (unsigned int *) &width,
126 (unsigned int *) &height
129 Display * display = fl_get_display();
131 lyxerr << "LyX: unable to access X display, exiting" << endl;
134 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
135 // X Error handler install goes here
136 XSetErrorHandler(LyX_XErrHandler);
138 // A width less than 590 pops up an awkward main window
139 // The minimal values of width/height (590/400) are defined in
141 if (width < 590) width = 590;
142 if (height < 400) height = 400;
144 // If width is not set by geometry, check it against monitor width
145 if ( !(geometryBitmask & 4) ) {
146 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
147 if (WidthOfScreen(scr) - 8 < width)
148 width = WidthOfScreen(scr) - 8;
151 // If height is not set by geometry, check it against monitor height
152 if ( !(geometryBitmask & 8) ) {
153 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
154 if (HeightOfScreen(scr) - 24 < height)
155 height = HeightOfScreen(scr) - 24;
158 // Recalculate xpos if it's negative
159 if (geometryBitmask & 16)
160 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
162 // Recalculate ypos if it's negative
163 if (geometryBitmask & 32)
164 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
166 // Initialize the LyXColorHandler
167 lyxColorHandler = new LyXColorHandler;
171 // A destructor is always necessary (asierra-970604)
174 // Lyxserver was created in this class so should be destroyed
175 // here. asierra-970604
185 void LyXGUI::setDefaults()
188 cntl.buttonFontSize = FL_NORMAL_SIZE;
189 cntl.browserFontSize = FL_NORMAL_SIZE;
190 cntl.labelFontSize = FL_NORMAL_SIZE;
191 cntl.choiceFontSize = FL_NORMAL_SIZE;
192 cntl.inputFontSize = FL_NORMAL_SIZE;
193 cntl.menuFontSize = FL_NORMAL_SIZE;
194 cntl.borderWidth = -1;
195 cntl.vclass = FL_DefaultVisual;
196 fl_set_defaults(FL_PDVisual
197 | FL_PDButtonFontSize
198 | FL_PDBrowserFontSize
200 | FL_PDChoiceFontSize
203 | FL_PDBorderWidth, &cntl);
207 // This is called after we have parsed lyxrc
215 if (lyxrc.font_norm_menu.empty())
216 lyxrc.font_norm_menu = lyxrc.font_norm;
217 // Set the font name for popups and menus
218 string menufontname = lyxrc.menu_font_name
219 + "-*-*-*-?-*-*-*-*-"
220 + lyxrc.font_norm_menu;
221 // "?" means "scale that font"
222 string popupfontname = lyxrc.popup_font_name
223 + "-*-*-*-?-*-*-*-*-"
224 + lyxrc.font_norm_menu;
226 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
227 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
229 lyxerr << "Could not set menu font to "
230 << menufontname << endl;
233 lyxerr << "Could not set popup font to "
234 << popupfontname << endl;
236 if (bold < 0 && normal < 0) {
237 lyxerr << "Using 'helvetica' font for menus" << endl;
238 bold = fl_set_font_name(FL_BOLD_STYLE,
239 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
240 normal = fl_set_font_name(FL_NORMAL_STYLE,
241 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
242 if (bold < 0 && normal < 0) {
243 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
244 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
248 // put here (after fl_initialize) to avoid segfault. Cannot be done
249 // in setDefaults() (Matthias 140496)
250 // Moved from ::LyXGUI to ::init to allow popup font customization
252 fl_setpup_fontstyle(FL_NORMAL_STYLE);
253 fl_setpup_fontsize(FL_NORMAL_SIZE);
254 fl_setpup_color(FL_MCOL, FL_BLACK);
255 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
257 // all lyxrc settings has to be done here as lyxrc has not yet
258 // been read when the GUI is created (Jug)
261 if (!lyxrc.custom_export_command.empty())
262 fl_set_input(fd_form_sendto->input_cmd,
263 lyxrc.custom_export_command.c_str());
264 if (lyxrc.custom_export_format == "lyx")
265 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
266 else if (lyxrc.custom_export_format == "tex")
267 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
268 else if (lyxrc.custom_export_format == "dvi")
269 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
270 else if (lyxrc.custom_export_format == "ps")
271 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
272 else if (lyxrc.custom_export_format == "ascii")
273 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
275 // Update parameters.
278 // Initialize the views.
281 // in 0.12 the initialisation of the LyXServer must be done here
282 // 0.13 it should be moved again...
283 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
287 void LyXGUI::create_forms()
289 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
290 lyxViews = new LyXView(width, height);
291 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
293 // From here down should be done by somebody else. (Lgb)
300 string banner_file = LibFileSearch("images", "banner", "xpm");
301 if (lyxrc.show_banner && !banner_file.empty()) {
302 fd_form_title = create_form_form_title();
303 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
304 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
305 fl_addto_form(fd_form_title->form_title);
306 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
307 fl_set_pixmapbutton_file(obj, banner_file.c_str());
309 fl_set_pixmapbutton_focus_outline(obj, 3);
310 fl_set_button_shortcut(obj, "^M ^[", 1);
311 fl_set_object_boxtype(obj, FL_NO_BOX);
312 fl_set_object_callback(obj, TimerCB, 0);
314 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
315 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
316 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
317 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
318 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
319 fl_set_object_lcol(obj, FL_FREE_COL3);
320 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
321 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
325 // the paragraph form
326 fd_form_paragraph = create_form_form_paragraph();
327 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
328 CancelCloseBoxCB, 0);
329 fl_addto_choice(fd_form_paragraph->choice_space_above,
330 _(" None | Defskip | Smallskip "
331 "| Medskip | Bigskip | VFill | Length "));
332 fl_addto_choice(fd_form_paragraph->choice_space_below,
333 _(" None | Defskip | Smallskip "
334 "| Medskip | Bigskip | VFill | Length "));
335 fl_set_input_return(fd_form_paragraph->input_space_above,
337 fl_set_input_return(fd_form_paragraph->input_space_below,
340 // the paragraph extra form
341 fd_form_paragraph_extra = create_form_form_paragraph_extra();
342 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
343 CancelCloseBoxCB, 0);
344 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
346 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
348 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
350 // the character form
351 fd_form_character = create_form_form_character();
352 fl_set_form_atclose(fd_form_character->form_character,
353 CancelCloseBoxCB, 0);
354 fl_addto_choice(fd_form_character->choice_family,
355 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
356 fl_addto_choice(fd_form_character->choice_series,
357 _(" No change %l| Medium | Bold %l| Reset "));
358 fl_addto_choice(fd_form_character->choice_shape,
359 _(" No change %l| Upright | Italic | Slanted | Small Caps "
361 fl_addto_choice(fd_form_character->choice_size,
362 _(" No change %l| Tiny | Smallest | Smaller | Small "
363 "| Normal | Large | Larger | Largest | Huge | Huger "
364 "%l| Increase | Decrease | Reset "));
365 fl_addto_choice(fd_form_character->choice_bar,
366 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
367 fl_addto_choice(fd_form_character->choice_color,
368 _(" No change %l| No color | Black | White | Red | Green "
369 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
370 fl_set_form_minsize(fd_form_character->form_character,
371 fd_form_character->form_character->w,
372 fd_form_character->form_character->h);
373 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
374 fl_addto_form(fd_form_character->form_character);
375 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
376 FL_OBJECT * ob = fd_form_character->choice_language;
377 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
378 combo_language2->shortcut("#L", 1);
380 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
383 fd_form_document = create_form_form_document();
384 fl_set_form_atclose(fd_form_document->form_document,
385 CancelCloseBoxCB, 0);
386 fl_addto_choice(fd_form_document->choice_spacing,
387 _(" Single | OneHalf | Double | Other "));
389 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
390 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
391 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
392 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
393 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
394 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
395 fl_addto_form(fd_form_document->form_document);
396 combo_language = new Combox(FL_COMBOX_DROPLIST);
397 ob = fd_form_document->choice_language;
398 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
399 combo_language->shortcut("#G", 1);
402 // "default" is not part of the languages array any more.
403 combo_language->addto("default");
404 combo_language2->addto(_("No change"));
405 combo_language2->addto(_("Reset"));
406 for(Languages::const_iterator cit = languages.begin();
407 cit != languages.end(); ++cit) {
408 combo_language->addto((*cit).second.lang().c_str());
409 combo_language2->addto((*cit).second.lang().c_str());
411 combo_language2->select_text("No change");
413 // not really necessary, but we can do it anyway.
414 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
416 for (n = 0; tex_fonts[n][0]; ++n) {
417 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
420 fl_addto_choice(fd_form_document->choice_inputenc,
421 "default|auto|latin1|latin2|latin5"
422 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
424 for (n = 0; tex_graphics[n][0]; ++n) {
425 fl_addto_choice(fd_form_document->choice_postscript_driver,
428 // not really necessary, but we can do it anyway.
429 fl_addto_choice(fd_form_document->choice_pagestyle,
430 "default|empty|plain|headings|fancy");
431 fl_addto_choice(fd_form_document->choice_default_skip,
432 _(" Smallskip | Medskip | Bigskip | Length "));
433 fl_set_input_return(fd_form_document->input_default_skip,
435 fl_set_form_minsize(fd_form_document->form_document,
436 fd_form_document->form_document->w,
437 fd_form_document->form_document->h);
438 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
441 fd_form_paper = create_form_form_paper();
442 fl_set_form_atclose(fd_form_paper->form_paper,
443 CancelCloseBoxCB, 0);
444 fl_addto_choice(fd_form_paper->choice_papersize2,
445 _(" Default | Custom | USletter | USlegal "
446 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
447 fl_addto_choice(fd_form_paper->choice_paperpackage,
449 "| A4 small Margins (only portrait) "
450 "| A4 very small Margins (only portrait) "
451 "| A4 very wide margins (only portrait) "));
452 fl_set_input_return(fd_form_paper->input_custom_width,
454 fl_set_input_return(fd_form_paper->input_custom_height,
456 fl_set_input_return(fd_form_paper->input_top_margin,
458 fl_set_input_return(fd_form_paper->input_bottom_margin,
460 fl_set_input_return(fd_form_paper->input_left_margin,
462 fl_set_input_return(fd_form_paper->input_right_margin,
464 fl_set_input_return(fd_form_paper->input_head_height,
466 fl_set_input_return(fd_form_paper->input_head_sep,
468 fl_set_input_return(fd_form_paper->input_foot_skip,
470 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
472 // the table_options form
473 fd_form_table_options = create_form_form_table_options();
474 fl_set_form_atclose(fd_form_table_options->form_table_options,
475 CancelCloseBoxCB, 0);
476 fl_set_input_return(fd_form_table_options->input_column_width,
479 // the table_extra form
480 fd_form_table_extra = create_form_form_table_extra();
481 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
482 CancelCloseBoxCB, 0);
483 fl_set_input_return(fd_form_table_extra->input_special_alignment,
485 fl_set_input_return(fd_form_table_extra->input_special_multialign,
487 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
490 fd_form_quotes = create_form_form_quotes();
491 fl_set_form_atclose(fd_form_quotes->form_quotes,
492 CancelCloseBoxCB, 0);
493 // Is it wrong of me to use « » instead of << >> ? (Lgb)
494 // Maybe if people use a font other than latin1... (JMarc)
495 fl_addto_choice(fd_form_quotes->choice_quotes_language,
496 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
499 fd_form_preamble = create_form_form_preamble();
500 fl_set_form_atclose(fd_form_preamble->form_preamble,
501 CancelCloseBoxCB, 0);
505 fd_form_table = create_form_form_table();
506 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
507 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
508 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
509 fl_set_slider_value(fd_form_table->slider_rows, 5);
510 fl_set_slider_value(fd_form_table->slider_columns, 5);
511 fl_set_slider_precision(fd_form_table->slider_rows, 0);
512 fl_set_slider_precision(fd_form_table->slider_columns, 0);
513 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
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 log form
544 fd_latex_log = create_form_LaTeXLog();
545 fl_set_form_atclose(fd_latex_log->LaTeXLog,
546 CancelCloseBoxCB, 0);
548 // Show the main & title form
549 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
550 int title_placement = FL_PLACE_CENTER;
551 // Did we get a valid position?
552 if (xpos>= 0 && ypos>= 0) {
553 lyxViews->setPosition(xpos, ypos);
554 if (lyxrc.show_banner) {
555 // show the title form in the middle of the main form
556 fl_set_form_position(fd_form_title->form_title,
557 abs(xpos + (width/2) - (370 / 2)),
558 abs(ypos + (height/2) - (290 / 2)));
559 title_placement = FL_PLACE_GEOMETRY;
560 // The use of abs() above is a trick to ensure
563 main_placement = FL_PLACE_POSITION;
565 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
566 if (lyxrc.show_banner) {
567 fl_show_form(fd_form_title->form_title,
568 title_placement, FL_NOBORDER,
570 fl_redraw_form(fd_form_title->form_title);
571 fl_raise_form(fd_form_title->form_title);
573 // Show the title form at most 7 secs (lowered from 10 secs)
574 fl_set_timer(fd_form_title->timer_title, 7);
579 void LyXGUI::runTime()
580 /* This will usually be toolkit (GUI) specific. This is
581 * also usually the XEvent dispatcher of the GUI. */
591 kapp->processEvents();
593 if (fl_check_forms() == FL_EVENT) {
594 lyxerr << "LyX: This shouldn't happen..." << endl;
601 void LyXGUI::regBuf(Buffer * b)
603 lyxViews->view()->buffer(b);
606 LyXView * LyXGUI::getLyXView() const