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