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