]> git.lyx.org Git - lyx.git/blob - src/lyx_gui.C
encoding + etc 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 #include <fcntl.h>
23 #include "lyx_gui.h"
24 #include FORMS_H_LOCATION
25 #include "support/filetools.h"
26 #include "combox.h"
27 #include "lyx.h"
28 #include "form1.h"
29 #include "layout_forms.h"
30 #include "print_form.h"
31 #include "tex-strings.h"
32 #include "lyx_main.h"
33 #include "log_form.h"
34 #include "debug.h"
35 #include "version.h"
36 #include "LyXView.h"
37 #include "buffer.h"
38 #include "lyxserver.h"
39 #include "lyxrc.h"
40 #include "gettext.h"
41 #include "lyx_gui_misc.h"
42 #include "lyxlookup.h"
43 #include "bufferlist.h"
44 #include "language.h"
45 #include "ColorHandler.h"
46
47 using std::endl;
48
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;
68
69 extern LyXServer * lyxserver;
70 extern bool finished;   // flag, that we are quitting the program
71 extern BufferList bufferlist;
72
73 FL_CMD_OPT cmdopt[] =
74 {
75         {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
76 };
77
78 static int width  = 690;
79 static int height = 510;
80 static int xpos   = -1;
81 static int ypos   = -1;
82 static char geometry[40];
83 bool       cursor_follows_scrollbar;
84
85
86 FL_resource res[] =
87 {
88         {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
89 };
90
91
92 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
93 {
94 //#warning Please see if you can trigger this!
95         // emergency save
96         if (!bufferlist.empty())
97                 bufferlist.emergencyWriteAll();
98
99         // Get the reason for the crash.
100         char etxt[513];
101         XGetErrorText(display, xeev->error_code, etxt, 512);
102         lyxerr << etxt << endl;
103         // By doing an abort we get a nice backtrace. (hopefully)
104         lyx::abort();
105         return 0; // Solaris CC wants us to return something
106 }
107
108
109 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
110   : _owner(owner), lyxViews(0)
111 {
112         gui = GUI;
113         if (!gui)
114                 return;
115
116         setDefaults();
117         
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);
121
122         static const int geometryBitmask = XParseGeometry( geometry,
123                                                            &xpos,
124                                                            &ypos,
125                                                            (unsigned int *) &width,
126                                                            (unsigned int *) &height
127                                                          );
128
129         Display * display = fl_get_display();
130         if (!display) {
131                 lyxerr << "LyX: unable to access X display, exiting" << endl;
132                 exit(1);
133         }
134         fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
135         // X Error handler install goes here
136         XSetErrorHandler(LyX_XErrHandler);
137
138         // A width less than 590 pops up an awkward main window
139         // The minimal values of width/height (590/400) are defined in
140         // src/lyx.C  
141         if (width < 590) width = 590;
142         if (height < 400) height = 400;
143         
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;
149         }
150
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;
156         }
157
158         // Recalculate xpos if it's negative
159         if (geometryBitmask & 16)
160                 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
161
162         // Recalculate ypos if it's negative
163         if (geometryBitmask & 32)
164                 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
165
166         // Initialize the LyXColorHandler
167         lyxColorHandler = new LyXColorHandler;
168 }
169
170
171 // A destructor is always necessary  (asierra-970604)
172 LyXGUI::~LyXGUI()
173 {
174         // Lyxserver was created in this class so should be destroyed
175         // here.  asierra-970604
176         delete lyxserver;
177         lyxserver = 0;
178         delete lyxViews;
179         lyxViews = 0;
180
181         CloseLyXLookup();
182 }
183
184
185 void LyXGUI::setDefaults()
186 {
187         FL_IOPT cntl;
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
199                         | FL_PDLabelFontSize
200                         | FL_PDChoiceFontSize
201                         | FL_PDInputFontSize
202                         | FL_PDMenuFontSize
203                         | FL_PDBorderWidth, &cntl);
204 }
205
206
207 // This is called after we have parsed lyxrc
208 void LyXGUI::init()
209 {
210         if (!gui)
211                 return;
212
213         create_forms();
214
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;
225
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());
228         if (bold < 0)
229                 lyxerr << "Could not set menu font to "
230                        << menufontname << endl;
231
232         if (normal < 0)
233                 lyxerr << "Could not set popup font to "
234                        << popupfontname << endl;
235
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");
245                 }
246         }
247
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 
251         // (petr 120997).
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);
256
257         // all lyxrc settings has to be done here as lyxrc has not yet
258         // been read when the GUI is created (Jug)
259
260         // the sendto form
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);
274
275         // Update parameters.
276         lyxViews->redraw();
277
278         // Initialize the views.
279         lyxViews->init();
280
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);
284 }
285
286
287 void LyXGUI::create_forms()
288 {
289         lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
290         lyxViews = new LyXView(width, height);
291         lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
292
293         // From here down should be done by somebody else. (Lgb)
294
295         //
296         // Create forms
297         //
298
299         // the title form
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());
308                 
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);
313                 
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);
322                 fl_end_form();
323         }
324         
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,
336                             FL_RETURN_ALWAYS);
337         fl_set_input_return(fd_form_paragraph->input_space_below,
338                             FL_RETURN_ALWAYS);
339
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,
345                             FL_RETURN_ALWAYS);
346         fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
347                             FL_RETURN_ALWAYS);
348         lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
349
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 "
360                         "%l| Reset "));
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);
379         fl_end_form();
380         lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
381
382         // the document form
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 "));
388
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);
400         fl_end_form();
401
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());
410         }
411         combo_language2->select_text("No change");
412
413         // not really necessary, but we can do it anyway.
414         fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
415         int n;
416         for (n = 0; tex_fonts[n][0]; ++n) {
417             fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
418         }
419
420         fl_addto_choice(fd_form_document->choice_inputenc,
421                         "default|auto|latin1|latin2|latin5"
422                         "|koi8-r|koi8-u|cp866|cp1251|iso88595");
423
424         for (n = 0; tex_graphics[n][0]; ++n) {
425             fl_addto_choice(fd_form_document->choice_postscript_driver,
426                                         tex_graphics[n]);
427         }
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,
434                             FL_RETURN_ALWAYS);
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;
439
440         // the paper form
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,
448                         _(" None "
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,
453                             FL_RETURN_ALWAYS);
454         fl_set_input_return(fd_form_paper->input_custom_height,
455                             FL_RETURN_ALWAYS);
456         fl_set_input_return(fd_form_paper->input_top_margin,
457                             FL_RETURN_ALWAYS);
458         fl_set_input_return(fd_form_paper->input_bottom_margin,
459                             FL_RETURN_ALWAYS);
460         fl_set_input_return(fd_form_paper->input_left_margin,
461                             FL_RETURN_ALWAYS);
462         fl_set_input_return(fd_form_paper->input_right_margin,
463                             FL_RETURN_ALWAYS);
464         fl_set_input_return(fd_form_paper->input_head_height,
465                             FL_RETURN_ALWAYS);
466         fl_set_input_return(fd_form_paper->input_head_sep,
467                             FL_RETURN_ALWAYS);
468         fl_set_input_return(fd_form_paper->input_foot_skip,
469                             FL_RETURN_ALWAYS);
470         lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
471
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,
477                             FL_RETURN_ALWAYS);
478
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,
484                             FL_RETURN_ALWAYS);
485         fl_set_input_return(fd_form_table_extra->input_special_multialign,
486                             FL_RETURN_ALWAYS);
487         lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
488
489         // the quotes form
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« "));
497
498         // the preamble form
499         fd_form_preamble = create_form_form_preamble();
500         fl_set_form_atclose(fd_form_preamble->form_preamble,
501                             CancelCloseBoxCB, 0);
502
503 #ifndef NEW_TABULAR
504         // the table form
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;
514 #endif
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 log form
544         fd_latex_log = create_form_LaTeXLog();
545         fl_set_form_atclose(fd_latex_log->LaTeXLog,
546                             CancelCloseBoxCB, 0);
547
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
561                         // valid positions
562                 }
563                         main_placement = FL_PLACE_POSITION;
564         }
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, 
569                              _("LyX Banner"));
570                 fl_redraw_form(fd_form_title->form_title);
571                 fl_raise_form(fd_form_title->form_title);
572
573                 // Show the title form at most 7 secs (lowered from 10 secs)
574                 fl_set_timer(fd_form_title->timer_title, 7);
575         }
576 }
577
578
579 void LyXGUI::runTime()
580         /* This will usually be toolkit (GUI) specific. This is
581          * also usually the XEvent dispatcher of the GUI. */
582 {
583         if (!gui)
584                 return;
585
586         // XForms specific
587         XEvent ev;
588
589         while (!finished) {
590 #ifdef KDEGUI
591                 kapp->processEvents();
592 #endif
593                 if (fl_check_forms() == FL_EVENT) {
594                         lyxerr << "LyX: This shouldn't happen..." << endl;
595                         fl_XNextEvent(&ev);
596                 }
597         }
598 }
599
600
601 void LyXGUI::regBuf(Buffer * b)
602 {
603         lyxViews->view()->buffer(b);
604 }
605
606 LyXView * LyXGUI::getLyXView() const
607 {
608         return lyxViews;
609 }