]> git.lyx.org Git - lyx.git/blob - src/lyx_gui.C
ebb32b9f67de6f6b45a20cb61503f82c1f9be401
[lyx.git] / src / lyx_gui.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12 #include <cstdlib>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include <fcntl.h>
19 #include FORMS_H_LOCATION
20 #include "lyx_gui.h"
21 #include "combox.h"
22 #include "lyx.h"
23 #include "form1.h"
24 #include "layout_forms.h"
25 #include "print_form.h"
26 #include "tex-strings.h"
27 #include "lyx_main.h"
28 #include "latexoptions.h"
29 #include "debug.h"
30 #include "version.h"
31 #include "LyXView.h"
32 #include "buffer.h"
33 #include "lyxserver.h"
34 #include "lyxrc.h"
35 #include "gettext.h"
36 #include "lyx_gui_misc.h"
37 #include "lyxlookup.h"
38 #include "bufferlist.h"
39 #include "language.h"
40 #include "ColorHandler.h"
41
42 #ifdef TWO_COLOR_ICONS
43 #include "banner_bw.xbm"
44 #else
45 #include "banner.xpm"
46 #endif
47
48 using std::endl;
49
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;
71
72 extern LyXServer * lyxserver;
73 extern bool finished;   // flag, that we are quitting the program
74 extern BufferList bufferlist;
75
76 FL_CMD_OPT cmdopt[] =
77 {
78         {"-width", "*.width", XrmoptionSepArg, "690"},
79         {"-height", "*.height", XrmoptionSepArg, "510"},
80         {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
81         {"-ypos", "*.ypos", XrmoptionSepArg, "-1"}
82 };
83
84 static int width;
85 static int height;
86 static int xpos;
87 static int ypos;
88 bool       cursor_follows_scrollbar;
89
90
91 FL_resource res[] =
92 {
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}
97 };
98
99
100 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
101 {
102 //#warning Please see if you can trigger this!
103         // emergency save
104         if (!bufferlist.empty())
105                 bufferlist.emergencyWriteAll();
106
107         // Get the reason for the crash.
108         char etxt[513];
109         XGetErrorText(display, xeev->error_code, etxt, 512);
110         lyxerr << etxt << endl;
111         // By doing an abort we get a nice backtrace. (hopefully)
112         lyx::abort();
113         return 0; // Solaris CC wants us to return something
114 }
115
116
117 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
118   : _owner(owner), lyxViews(0)
119 {
120         gui = GUI;
121         if (!gui)
122                 return;
123
124         setDefaults();
125         
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);
129
130         Display * display = fl_get_display();
131         if (!display) {
132                 lyxerr << "LyX: unable to access X display, exiting" << endl;
133                 exit(1);
134         }
135         fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
136         // X Error handler install goes here
137         XSetErrorHandler(LyX_XErrHandler);
138         
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;
146         }
147
148         // Initialize the LyXColorHandler
149         lyxColorHandler = new LyXColorHandler;
150 }
151
152
153 // A destructor is always necessary  (asierra-970604)
154 LyXGUI::~LyXGUI()
155 {
156         // Lyxserver was created in this class so should be destroyed
157         // here.  asierra-970604
158         delete lyxserver;
159         lyxserver = 0;
160         delete lyxViews;
161         lyxViews = 0;
162
163         CloseLyXLookup();
164 }
165
166
167 void LyXGUI::setDefaults()
168 {
169         FL_IOPT cntl;
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
181                         | FL_PDLabelFontSize
182                         | FL_PDChoiceFontSize
183                         | FL_PDInputFontSize
184                         | FL_PDMenuFontSize
185                         | FL_PDBorderWidth, &cntl);
186 }
187
188
189 // This is called after we have parsed lyxrc
190 void LyXGUI::init()
191 {
192         if (!gui)
193                 return;
194
195         create_forms();
196
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;
207
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());
210         if (bold < 0)
211                 lyxerr << "Could not set menu font to "
212                        << menufontname << endl;
213
214         if (normal < 0)
215                 lyxerr << "Could not set popup font to "
216                        << popupfontname << endl;
217
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");
227                 }
228         }
229
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 
233         // (petr 120997).
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);
238
239         // all lyxrc settings has to be done here as lyxrc has not yet
240         // been read when the GUI is created (Jug)
241
242         // the print form
243         fl_set_input(fd_form_print->input_printer, 
244                      lyxrc.printer.c_str());    
245         
246         // the sendto form
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);
260
261         // Update parameters.
262         lyxViews->redraw();
263
264         // Initialize the views.
265         lyxViews->init();
266
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);
270 }
271
272
273 void LyXGUI::create_forms()
274 {
275         lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
276         lyxViews = new LyXView(width, height);
277         lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
278
279         // From here down should be done by somebody else. (Lgb)
280
281         //
282         // Create forms
283         //
284
285         // the title form
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);
296 #else
297                 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
298                 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
299                 
300                 fl_set_pixmapbutton_focus_outline(obj, 3);
301 #endif
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);
305                 
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);
311 #else
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);
318 #endif
319                 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
320                 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
321                 fl_end_form();
322         }
323         
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,
335                             FL_RETURN_ALWAYS);
336         fl_set_input_return(fd_form_paragraph->input_space_below,
337                             FL_RETURN_ALWAYS);
338
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,
344                             FL_RETURN_ALWAYS);
345         fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
346                             FL_RETURN_ALWAYS);
347
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 "
358                         "%l| Reset "));
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);
376         fl_end_form();
377
378         // the document form
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 "));
384
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);
396         fl_end_form();
397
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());
405         }
406         combo_language2->select_text("No change");
407
408         // not really necessary, but we can do it anyway.
409         fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
410         int n;
411         for (n = 0; tex_fonts[n][0]; ++n) {
412             fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
413         }
414
415         fl_addto_choice(fd_form_document->choice_inputenc,
416                         "default|latin1|latin2|latin5"
417                         "|koi8-r|koi8-u|cp866|cp1251|iso88595");
418
419         for (n = 0; tex_graphics[n][0]; ++n) {
420             fl_addto_choice(fd_form_document->choice_postscript_driver,
421                                         tex_graphics[n]);
422         }
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,
429                             FL_RETURN_ALWAYS);
430         fl_set_form_minsize(fd_form_document->form_document,
431                             fd_form_document->form_document->w,
432                             fd_form_document->form_document->h);
433
434         // the paper form
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,
442                         _(" None "
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,
447                             FL_RETURN_ALWAYS);
448         fl_set_input_return(fd_form_paper->input_custom_height,
449                             FL_RETURN_ALWAYS);
450         fl_set_input_return(fd_form_paper->input_top_margin,
451                             FL_RETURN_ALWAYS);
452         fl_set_input_return(fd_form_paper->input_bottom_margin,
453                             FL_RETURN_ALWAYS);
454         fl_set_input_return(fd_form_paper->input_left_margin,
455                             FL_RETURN_ALWAYS);
456         fl_set_input_return(fd_form_paper->input_right_margin,
457                             FL_RETURN_ALWAYS);
458         fl_set_input_return(fd_form_paper->input_head_height,
459                             FL_RETURN_ALWAYS);
460         fl_set_input_return(fd_form_paper->input_head_sep,
461                             FL_RETURN_ALWAYS);
462         fl_set_input_return(fd_form_paper->input_foot_skip,
463                             FL_RETURN_ALWAYS);
464
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,
470                             FL_RETURN_ALWAYS);
471
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,
477                             FL_RETURN_ALWAYS);
478         fl_set_input_return(fd_form_table_extra->input_special_multialign,
479                             FL_RETURN_ALWAYS);
480
481         // the quotes form
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« "));
489
490         // the preamble form
491         fd_form_preamble = create_form_form_preamble();
492         fl_set_form_atclose(fd_form_preamble->form_preamble,
493                             CancelCloseBoxCB, 0);
494
495         // the table form
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);
504
505         // the print form
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);
515
516         // the sendto form
517         fd_form_sendto = create_form_form_sendto();
518         fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
519
520         // the figure form
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);
525
526         // the screen form
527         fd_form_screen = create_form_form_screen();
528         fl_set_form_atclose(fd_form_screen->form_screen,
529                             CancelCloseBoxCB, 0);
530
531         // the toc form
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);
536
537         // the ref form
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);
542
543         // the latex options form
544         fd_latex_options = create_form_LaTeXOptions();
545         fl_set_form_atclose(fd_latex_options->LaTeXOptions,
546                             CancelCloseBoxCB, 0);
547
548         // the latex log form
549         fd_latex_log = create_form_LaTeXLog();
550         fl_set_form_atclose(fd_latex_log->LaTeXLog,
551                             CancelCloseBoxCB, 0);
552
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
566                         // valid positions
567                 }
568                         main_placement = FL_PLACE_POSITION;
569         }
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, 
574                              _("LyX Banner"));
575                 fl_redraw_form(fd_form_title->form_title);
576                 fl_raise_form(fd_form_title->form_title);
577
578                 // Show the title form at most 7 secs (lowered from 10 secs)
579                 fl_set_timer(fd_form_title->timer_title, 7);
580         }
581 }
582
583
584 void LyXGUI::runTime()
585         /* This will usually be toolkit (GUI) specific. This is
586          * also usually the XEvent dispatcher of the GUI. */
587 {
588         if (!gui)
589                 return;
590
591         // XForms specific
592         XEvent ev;
593
594         while (!finished) {
595                 if (fl_check_forms() == FL_EVENT) {
596                         lyxerr << "LyX: This shouldn't happen..." << endl;
597                         fl_XNextEvent(&ev);
598                 }
599         }
600 }
601
602
603 void LyXGUI::regBuf(Buffer * b)
604 {
605         lyxViews->view()->buffer(b);
606 }
607
608 LyXView * LyXGUI::getLyXView() const
609 {
610         return lyxViews;
611 }