]> git.lyx.org Git - lyx.git/blob - src/lyx_gui.C
Angus insetindex patch + protect patch from Dekel
[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 #ifdef KDEGUI
19 #    include <kapp.h>
20 #endif
21
22 #ifdef GTKGUI
23 #    include <gnome--/main.h>
24 #endif
25
26 #include <fcntl.h>
27 #include "lyx_gui.h"
28 #include FORMS_H_LOCATION
29 #include "support/filetools.h"
30 #include "combox.h"
31 #include "lyx.h"
32 #include "form1.h"
33 #include "layout_forms.h"
34 #include "print_form.h"
35 #include "tex-strings.h"
36 #include "lyx_main.h"
37 #include "log_form.h"
38 #include "debug.h"
39 #include "version.h"
40 #include "LyXView.h"
41 #include "buffer.h"
42 #include "lyxserver.h"
43 #include "lyxrc.h"
44 #include "gettext.h"
45 #include "lyx_gui_misc.h"
46 #include "lyxlookup.h"
47 #include "bufferlist.h"
48 #include "language.h"
49 #include "ColorHandler.h"
50
51 using std::endl;
52
53 FD_form_title * fd_form_title;
54 FD_form_paragraph * fd_form_paragraph;
55 FD_form_paragraph_extra * fd_form_paragraph_extra;
56 FD_form_character * fd_form_character;
57 FD_form_document * fd_form_document;
58 FD_form_paper * fd_form_paper;
59 FD_form_table_options * fd_form_table_options;
60 FD_form_table_extra * fd_form_table_extra;
61 FD_form_quotes * fd_form_quotes;
62 FD_form_preamble * fd_form_preamble;
63 FD_form_table * fd_form_table;
64 FD_form_sendto * fd_form_sendto;
65 FD_form_figure * fd_form_figure;
66 FD_form_screen * fd_form_screen;
67 FD_form_ref * fd_form_ref;
68 FD_LaTeXLog * fd_latex_log; // from log_form.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         {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
79 };
80
81 static int width  = 690;
82 static int height = 510;
83 static int xpos   = -1;
84 static int ypos   = -1;
85 static char geometry[40];
86 bool       cursor_follows_scrollbar;
87
88
89 FL_resource res[] =
90 {
91         {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
92 };
93
94
95 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
96 {
97 //#warning Please see if you can trigger this!
98         // emergency save
99         if (!bufferlist.empty())
100                 bufferlist.emergencyWriteAll();
101
102         // Get the reason for the crash.
103         char etxt[513];
104         XGetErrorText(display, xeev->error_code, etxt, 512);
105         lyxerr << etxt << endl;
106         // By doing an abort we get a nice backtrace. (hopefully)
107         lyx::abort();
108         return 0; // Solaris CC wants us to return something
109 }
110
111
112 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
113   : _owner(owner), lyxViews(0)
114 {
115         gui = GUI;
116         if (!gui)
117                 return;
118
119         setDefaults();
120         
121         static const int num_res = sizeof(res)/sizeof(FL_resource);
122         fl_initialize(argc, argv, "LyX", cmdopt, num_res);
123         fl_get_app_resources(res, num_res);
124
125         static const int geometryBitmask = XParseGeometry( geometry,
126                                                            &xpos,
127                                                            &ypos,
128                                                            (unsigned int *) &width,
129                                                            (unsigned int *) &height
130                                                          );
131
132         Display * display = fl_get_display();
133         if (!display) {
134                 lyxerr << "LyX: unable to access X display, exiting" << endl;
135                 exit(1);
136         }
137         fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
138         // X Error handler install goes here
139         XSetErrorHandler(LyX_XErrHandler);
140
141         // A width less than 590 pops up an awkward main window
142         // The minimal values of width/height (590/400) are defined in
143         // src/lyx.C  
144         if (width < 590) width = 590;
145         if (height < 400) height = 400;
146         
147         // If width is not set by geometry, check it against monitor width
148         if ( !(geometryBitmask & 4) ) {
149                 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
150                 if (WidthOfScreen(scr) - 8 < width)
151                         width = WidthOfScreen(scr) - 8;
152         }
153
154         // If height is not set by geometry, check it against monitor height
155         if ( !(geometryBitmask & 8) ) {
156                 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
157                 if (HeightOfScreen(scr) - 24 < height)
158                         height = HeightOfScreen(scr) - 24;
159         }
160
161         // Recalculate xpos if it's negative
162         if (geometryBitmask & 16)
163                 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
164
165         // Recalculate ypos if it's negative
166         if (geometryBitmask & 32)
167                 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
168
169         // Initialize the LyXColorHandler
170         lyxColorHandler = new LyXColorHandler;
171 }
172
173
174 // A destructor is always necessary  (asierra-970604)
175 LyXGUI::~LyXGUI()
176 {
177         // Lyxserver was created in this class so should be destroyed
178         // here.  asierra-970604
179         delete lyxserver;
180         lyxserver = 0;
181         delete lyxViews;
182         lyxViews = 0;
183
184         CloseLyXLookup();
185 }
186
187
188 void LyXGUI::setDefaults()
189 {
190         FL_IOPT cntl;
191         cntl.buttonFontSize = FL_NORMAL_SIZE;
192         cntl.browserFontSize = FL_NORMAL_SIZE;
193         cntl.labelFontSize = FL_NORMAL_SIZE;
194         cntl.choiceFontSize = FL_NORMAL_SIZE;
195         cntl.inputFontSize = FL_NORMAL_SIZE;
196         cntl.menuFontSize  = FL_NORMAL_SIZE;
197         cntl.borderWidth = -1;
198         cntl.vclass = FL_DefaultVisual;
199         fl_set_defaults(FL_PDVisual
200                         | FL_PDButtonFontSize
201                         | FL_PDBrowserFontSize
202                         | FL_PDLabelFontSize
203                         | FL_PDChoiceFontSize
204                         | FL_PDInputFontSize
205                         | FL_PDMenuFontSize
206                         | FL_PDBorderWidth, &cntl);
207 }
208
209
210 // This is called after we have parsed lyxrc
211 void LyXGUI::init()
212 {
213         if (!gui)
214                 return;
215
216         create_forms();
217
218         if (lyxrc.font_norm_menu.empty())
219                 lyxrc.font_norm_menu = lyxrc.font_norm;
220         // Set the font name for popups and menus
221         string menufontname = lyxrc.menu_font_name 
222                                + "-*-*-*-?-*-*-*-*-"  
223                                + lyxrc.font_norm_menu;
224                 // "?" means "scale that font"
225         string popupfontname = lyxrc.popup_font_name 
226                                + "-*-*-*-?-*-*-*-*-"  
227                                + lyxrc.font_norm_menu;
228
229         int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
230         int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
231         if (bold < 0)
232                 lyxerr << "Could not set menu font to "
233                        << menufontname << endl;
234
235         if (normal < 0)
236                 lyxerr << "Could not set popup font to "
237                        << popupfontname << endl;
238
239         if (bold < 0 && normal < 0) {
240                 lyxerr << "Using 'helvetica' font for menus" << endl;
241                 bold = fl_set_font_name(FL_BOLD_STYLE,
242                                         "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
243                 normal = fl_set_font_name(FL_NORMAL_STYLE,
244                                           "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
245                 if (bold < 0 && normal < 0) {
246                         lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
247                         normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
248                 }
249         }
250
251         // put here (after fl_initialize) to avoid segfault. Cannot be done
252         // in setDefaults() (Matthias 140496)
253         // Moved from ::LyXGUI to ::init to allow popup font customization 
254         // (petr 120997).
255         fl_setpup_fontstyle(FL_NORMAL_STYLE);
256         fl_setpup_fontsize(FL_NORMAL_SIZE);
257         fl_setpup_color(FL_MCOL, FL_BLACK);
258         fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
259
260         // all lyxrc settings has to be done here as lyxrc has not yet
261         // been read when the GUI is created (Jug)
262
263         // the sendto form
264         if (!lyxrc.custom_export_command.empty())
265                 fl_set_input(fd_form_sendto->input_cmd,
266                              lyxrc.custom_export_command.c_str());
267         if (lyxrc.custom_export_format == "lyx")
268                 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
269         else if (lyxrc.custom_export_format == "tex")
270                 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
271         else if (lyxrc.custom_export_format == "dvi")
272                 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
273         else if (lyxrc.custom_export_format == "ps")
274                 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
275         else if (lyxrc.custom_export_format == "ascii")
276                 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
277
278         // Update parameters.
279         lyxViews->redraw();
280
281         // Initialize the views.
282         lyxViews->init();
283
284         // in 0.12 the initialisation of the LyXServer must be done here
285         // 0.13 it should be moved again...
286         lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
287 }
288
289
290 void LyXGUI::create_forms()
291 {
292         lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
293         lyxViews = new LyXView(width, height);
294         lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
295
296         // From here down should be done by somebody else. (Lgb)
297
298         //
299         // Create forms
300         //
301
302         // the title form
303         string banner_file = LibFileSearch("images", "banner", "xpm");
304         if (lyxrc.show_banner && !banner_file.empty()) {
305                 fd_form_title = create_form_form_title();
306                 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
307                 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
308                 fl_addto_form(fd_form_title->form_title);
309                 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
310                 fl_set_pixmapbutton_file(obj, banner_file.c_str());
311                 
312                 fl_set_pixmapbutton_focus_outline(obj, 3);
313                 fl_set_button_shortcut(obj, "^M ^[", 1);
314                 fl_set_object_boxtype(obj, FL_NO_BOX);
315                 fl_set_object_callback(obj, TimerCB, 0);
316                 
317                 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
318                 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
319                 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
320                 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
321                 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
322                 fl_set_object_lcol(obj, FL_FREE_COL3);
323                 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
324                 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
325                 fl_end_form();
326         }
327         
328         // the paragraph form
329         fd_form_paragraph = create_form_form_paragraph();
330         fl_set_form_atclose(fd_form_paragraph->form_paragraph,
331                             CancelCloseBoxCB, 0);
332         fl_addto_choice(fd_form_paragraph->choice_space_above,
333                         _(" None | Defskip | Smallskip "
334                         "| Medskip | Bigskip | VFill | Length "));
335         fl_addto_choice(fd_form_paragraph->choice_space_below,
336                         _(" None | Defskip | Smallskip "
337                         "| Medskip | Bigskip | VFill | Length ")); 
338         fl_set_input_return(fd_form_paragraph->input_space_above,
339                             FL_RETURN_ALWAYS);
340         fl_set_input_return(fd_form_paragraph->input_space_below,
341                             FL_RETURN_ALWAYS);
342
343         // the paragraph extra form
344         fd_form_paragraph_extra = create_form_form_paragraph_extra();
345         fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
346                             CancelCloseBoxCB, 0);
347         fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
348                             FL_RETURN_ALWAYS);
349         fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
350                             FL_RETURN_ALWAYS);
351         lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
352
353         // the character form
354         fd_form_character = create_form_form_character();
355         fl_set_form_atclose(fd_form_character->form_character,
356                             CancelCloseBoxCB, 0);
357         fl_addto_choice(fd_form_character->choice_family, 
358                         _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
359         fl_addto_choice(fd_form_character->choice_series, 
360                         _(" No change %l| Medium | Bold %l| Reset "));
361         fl_addto_choice(fd_form_character->choice_shape,
362                         _(" No change %l| Upright | Italic | Slanted | Small Caps "
363                         "%l| Reset "));
364         fl_addto_choice(fd_form_character->choice_size, 
365                         _(" No change %l| Tiny | Smallest | Smaller | Small "
366                         "| Normal | Large | Larger | Largest | Huge | Huger "
367                         "%l| Increase | Decrease | Reset "));
368         fl_addto_choice(fd_form_character->choice_bar, 
369                         _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
370         fl_addto_choice(fd_form_character->choice_color, 
371                         _(" No change %l| No color | Black | White | Red | Green "
372                         "| Blue | Cyan | Magenta | Yellow %l| Reset "));
373         fl_set_form_minsize(fd_form_character->form_character,
374                             fd_form_character->form_character->w,
375                             fd_form_character->form_character->h);
376         lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
377         fl_addto_form(fd_form_character->form_character);
378         combo_language2 = new Combox(FL_COMBOX_DROPLIST);
379         FL_OBJECT * ob = fd_form_character->choice_language;
380         combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
381         combo_language2->shortcut("#L", 1);
382         fl_end_form();
383         lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
384
385         // the document form
386         fd_form_document = create_form_form_document();
387         fl_set_form_atclose(fd_form_document->form_document,
388                             CancelCloseBoxCB, 0);
389         fl_addto_choice(fd_form_document->choice_spacing,
390                         _(" Single | OneHalf | Double | Other "));
391
392         fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
393         fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
394         fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
395         fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
396         fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
397         fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
398         fl_addto_form(fd_form_document->form_document);
399         combo_language = new Combox(FL_COMBOX_DROPLIST);
400         ob = fd_form_document->choice_language;
401         combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
402         combo_language->shortcut("#G", 1);
403         fl_end_form();
404
405         // "default" is not part of the languages array any more.
406         combo_language->addto("default");
407         combo_language2->addto(_("No change"));
408         combo_language2->addto(_("Reset"));
409         for(Languages::const_iterator cit = languages.begin();
410             cit != languages.end(); ++cit) {
411                 combo_language->addto((*cit).second.lang().c_str());
412                 combo_language2->addto((*cit).second.lang().c_str());
413         }
414         combo_language2->select_text("No change");
415
416         // not really necessary, but we can do it anyway.
417         fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
418         int n;
419         for (n = 0; tex_fonts[n][0]; ++n) {
420             fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
421         }
422
423         fl_addto_choice(fd_form_document->choice_inputenc,
424                         "default|auto|latin1|latin2|latin5"
425                         "|koi8-r|koi8-u|cp866|cp1251|iso88595");
426
427         for (n = 0; tex_graphics[n][0]; ++n) {
428             fl_addto_choice(fd_form_document->choice_postscript_driver,
429                                         tex_graphics[n]);
430         }
431         // not really necessary, but we can do it anyway.
432         fl_addto_choice(fd_form_document->choice_pagestyle,
433                         "default|empty|plain|headings|fancy");
434         fl_addto_choice(fd_form_document->choice_default_skip,
435                         _(" Smallskip | Medskip | Bigskip | Length "));
436         fl_set_input_return(fd_form_document->input_default_skip,
437                             FL_RETURN_ALWAYS);
438         fl_set_form_minsize(fd_form_document->form_document,
439                             fd_form_document->form_document->w,
440                             fd_form_document->form_document->h);
441         lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
442
443         // the paper form
444         fd_form_paper = create_form_form_paper();
445         fl_set_form_atclose(fd_form_paper->form_paper,
446                             CancelCloseBoxCB, 0);
447         fl_addto_choice(fd_form_paper->choice_papersize2,
448                         _(" Default | Custom | USletter | USlegal "
449                         "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
450         fl_addto_choice(fd_form_paper->choice_paperpackage,
451                         _(" None "
452                         "| A4 small Margins (only portrait) "
453                         "| A4 very small Margins (only portrait) "
454                         "| A4 very wide margins (only portrait) "));
455         fl_set_input_return(fd_form_paper->input_custom_width,
456                             FL_RETURN_ALWAYS);
457         fl_set_input_return(fd_form_paper->input_custom_height,
458                             FL_RETURN_ALWAYS);
459         fl_set_input_return(fd_form_paper->input_top_margin,
460                             FL_RETURN_ALWAYS);
461         fl_set_input_return(fd_form_paper->input_bottom_margin,
462                             FL_RETURN_ALWAYS);
463         fl_set_input_return(fd_form_paper->input_left_margin,
464                             FL_RETURN_ALWAYS);
465         fl_set_input_return(fd_form_paper->input_right_margin,
466                             FL_RETURN_ALWAYS);
467         fl_set_input_return(fd_form_paper->input_head_height,
468                             FL_RETURN_ALWAYS);
469         fl_set_input_return(fd_form_paper->input_head_sep,
470                             FL_RETURN_ALWAYS);
471         fl_set_input_return(fd_form_paper->input_foot_skip,
472                             FL_RETURN_ALWAYS);
473         lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
474
475         // the table_options form
476         fd_form_table_options = create_form_form_table_options();
477         fl_set_form_atclose(fd_form_table_options->form_table_options,
478                             CancelCloseBoxCB, 0);
479         fl_set_input_return(fd_form_table_options->input_column_width,
480                             FL_RETURN_ALWAYS);
481
482         // the table_extra form
483         fd_form_table_extra = create_form_form_table_extra();
484         fl_set_form_atclose(fd_form_table_extra->form_table_extra,
485                             CancelCloseBoxCB, 0);
486         fl_set_input_return(fd_form_table_extra->input_special_alignment,
487                             FL_RETURN_ALWAYS);
488         fl_set_input_return(fd_form_table_extra->input_special_multialign,
489                             FL_RETURN_ALWAYS);
490         lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
491
492         // the quotes form
493         fd_form_quotes = create_form_form_quotes();
494         fl_set_form_atclose(fd_form_quotes->form_quotes,
495                             CancelCloseBoxCB, 0);
496         // Is it wrong of me to use « » instead of << >> ? (Lgb)
497         // Maybe if people use a font other than latin1... (JMarc)
498         fl_addto_choice(fd_form_quotes->choice_quotes_language,
499                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
500
501         // the preamble form
502         fd_form_preamble = create_form_form_preamble();
503         fl_set_form_atclose(fd_form_preamble->form_preamble,
504                             CancelCloseBoxCB, 0);
505
506 #ifndef NEW_TABULAR
507         // the table form
508         fd_form_table = create_form_form_table();
509         fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
510         fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
511         fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
512         fl_set_slider_value(fd_form_table->slider_rows, 5);
513         fl_set_slider_value(fd_form_table->slider_columns, 5);
514         fl_set_slider_precision(fd_form_table->slider_rows, 0);
515         fl_set_slider_precision(fd_form_table->slider_columns, 0);
516         lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
517 #endif
518
519         // the sendto form
520         fd_form_sendto = create_form_form_sendto();
521         fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
522
523         // the figure form
524         fd_form_figure = create_form_form_figure();
525         fl_set_form_atclose(fd_form_figure->form_figure,
526                             CancelCloseBoxCB, 0);
527         fl_set_button(fd_form_figure->radio_postscript, 1);
528
529         // the screen form
530         fd_form_screen = create_form_form_screen();
531         fl_set_form_atclose(fd_form_screen->form_screen,
532                             CancelCloseBoxCB, 0);
533
534         // the ref form
535         fd_form_ref = create_form_form_ref();
536         fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
537         fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
538                             fd_form_ref->form_ref->h);
539
540         // the latex log form
541         fd_latex_log = create_form_LaTeXLog();
542         fl_set_form_atclose(fd_latex_log->LaTeXLog,
543                             CancelCloseBoxCB, 0);
544
545         // Show the main & title form
546         int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
547         int title_placement = FL_PLACE_CENTER;
548         // Did we get a valid position?
549         if (xpos>= 0 && ypos>= 0) {
550                 lyxViews->setPosition(xpos, ypos);
551                 if (lyxrc.show_banner) {
552                         // show the title form in the middle of the main form
553                         fl_set_form_position(fd_form_title->form_title,
554                                              abs(xpos + (width/2) - (370 / 2)),
555                                              abs(ypos + (height/2) - (290 / 2)));
556                         title_placement = FL_PLACE_GEOMETRY;
557                         // The use of abs() above is a trick to ensure
558                         // valid positions
559                 }
560                         main_placement = FL_PLACE_POSITION;
561         }
562         lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
563         if (lyxrc.show_banner) {
564                 fl_show_form(fd_form_title->form_title, 
565                              title_placement, FL_NOBORDER, 
566                              _("LyX Banner"));
567                 fl_redraw_form(fd_form_title->form_title);
568                 fl_raise_form(fd_form_title->form_title);
569
570                 // Show the title form at most 7 secs (lowered from 10 secs)
571                 fl_set_timer(fd_form_title->timer_title, 7);
572         }
573 }
574
575
576 void LyXGUI::runTime()
577         /* This will usually be toolkit (GUI) specific. This is
578          * also usually the XEvent dispatcher of the GUI. */
579 {
580         if (!gui)
581                 return;
582
583         // XForms specific
584         XEvent ev;
585
586         while (!finished) {
587 #ifdef KDEGUI
588                 kapp->processEvents();
589 #endif
590 #ifdef GTKGUI
591                 Gnome::Main::instance()->iteration(FALSE);
592 #endif
593                 
594                 if (fl_check_forms() == FL_EVENT) {
595                         lyxerr << "LyX: This shouldn't happen..." << endl;
596                         fl_XNextEvent(&ev);
597                 }
598         }
599 }
600
601
602 void LyXGUI::regBuf(Buffer * b)
603 {
604         lyxViews->view()->buffer(b);
605 }
606
607 LyXView * LyXGUI::getLyXView() const
608 {
609         return lyxViews;
610 }