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