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