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