]> git.lyx.org Git - features.git/blob - src/lyx_gui.C
change to use ostreams instead of string when writing files. fiddling with insettext...
[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-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12 #include <cstdlib>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include <fcntl.h>
19 #include FORMS_H_LOCATION
20 #include "lyx_gui.h"
21 #include "combox.h"
22 #include "lyx.h"
23 #include "form1.h"
24 #include "layout_forms.h"
25 #include "print_form.h"
26 #include "tex-strings.h"
27 #include "lyx_main.h"
28 #include "latexoptions.h"
29 #include "debug.h"
30 #include "version.h"
31 #include "LyXView.h"
32 #include "buffer.h"
33 #include "lyxserver.h"
34 #include "lyxrc.h"
35 #include "gettext.h"
36 #include "lyx_gui_misc.h"
37 #include "lyxlookup.h"
38 #include "bufferlist.h"
39
40 #ifdef TWO_COLOR_ICONS
41 #include "banner_bw.xbm"
42 #else
43 #include "banner.xpm"
44 #endif
45
46 FD_form_title * fd_form_title;
47 FD_form_paragraph * fd_form_paragraph;
48 FD_form_paragraph_extra * fd_form_paragraph_extra;
49 FD_form_character * fd_form_character;
50 FD_form_document * fd_form_document;
51 FD_form_paper * fd_form_paper;
52 FD_form_table_options * fd_form_table_options;
53 FD_form_table_extra * fd_form_table_extra;
54 FD_form_quotes * fd_form_quotes;
55 FD_form_preamble * fd_form_preamble;
56 FD_form_table * fd_form_table;
57 FD_form_print * fd_form_print;
58 FD_form_sendto * fd_form_sendto;
59 FD_form_figure * fd_form_figure;
60 FD_form_screen * fd_form_screen;
61 FD_form_toc * fd_form_toc;
62 FD_form_ref * fd_form_ref;
63 FD_LaTeXOptions * fd_latex_options; // from latexoptions.h
64 FD_LaTeXLog * fd_latex_log; // from latexoptions.h
65 Combox * combo_language;
66
67 extern LyXServer * lyxserver;
68 extern bool finished;   // flag, that we are quitting the program
69 extern BufferList bufferlist;
70
71 FL_CMD_OPT cmdopt[] =
72 {
73         {"-width", "*.width", XrmoptionSepArg, "690"},
74         {"-height", "*.height", XrmoptionSepArg, "510"},
75         {"-xpos", "*.xpos", XrmoptionSepArg, "-1"},
76         {"-ypos", "*.ypos", XrmoptionSepArg, "-1"},
77         {"-MathColor", "*.MathColor", XrmoptionSepArg, "blue"},
78         {"-MathFrameColor", "*.MathFrameColor", XrmoptionSepArg, "magenta"},
79         {"-FootColor", "*.FootColor", XrmoptionSepArg, "red"}, 
80         {"-NewLineColor", "*.NewLineColor", XrmoptionSepArg, "red"},
81         {"-LabelColor", "*.LabelColor", XrmoptionSepArg, "palegreen"},
82         {"-FillColor", "*.FillColor", XrmoptionSepArg, "magenta"},
83         {"-OnOffLineColor", "*.OnOffLineColor", XrmoptionSepArg, "magenta"},
84         {"-LatexColor", "*.LatexColor", XrmoptionSepArg, "red"},
85         {"-NoteColor", "*.NoteColor", XrmoptionSepArg, "yellow"},
86         {"-NoteFrameColor", "*.NoteFrameColor", XrmoptionSepArg, "black"},
87         {"-LightedColor", "*.LightedColor", XrmoptionSepArg, "gray80"},
88         {"-BackgroundColor", "*.BackgroundColor", XrmoptionSepArg, "linen"},
89         {"-SelectionColor", "*.SelectionColor", XrmoptionSepArg, "lightblue"}
90 };
91
92 static int width;
93 static int height;
94 static int xpos;
95 static int ypos;
96 bool       cursor_follows_scrollbar;
97 char       math_color[32];
98 char       math_frame_color[32];
99 char       foot_color[32];
100 char       new_line_color[32];
101 char       label_color[32];
102 char       fill_color[32];
103 char       on_off_line_color[32];
104 char       latex_color[32];
105 char       note_color[32];
106 char       note_frame_color[32];
107 char       lighted_color[32];
108 string    background_color;
109 char       b_c[32];
110 char       selection_color[32];
111
112
113 FL_resource res[] =
114 {
115         {"width", "widthClass", FL_INT, &width, "690", 0},
116         {"height", "heightClass", FL_INT, &height, "510", 0},
117         {"xpos", "xposClass", FL_INT, &xpos, "-1", 0},
118         {"ypos", "yposClass", FL_INT, &ypos, "-1", 0},
119         {"MathColor", "colorClass", FL_STRING, math_color, "blue", 31},
120         {"MathFrameColor", "colorClass", FL_STRING, math_frame_color, "magenta", 31},
121         {"FootColor", "colorClass", FL_STRING, foot_color, "red", 31},
122         {"NewLineColor", "colorClass", FL_STRING, new_line_color, "red", 31},
123         {"LabelColor", "colorClass", FL_STRING, label_color, "palegreen", 31},
124         {"FillColor", "colorClass", FL_STRING, fill_color, "magenta", 31},
125         {"OnOffLineColor", "colorClass", FL_STRING, on_off_line_color, "magenta", 31},
126         {"LatexColor", "colorClass", FL_STRING, latex_color, "red", 31},
127         {"NoteColor", "colorClass", FL_STRING, note_color, "yellow", 31},
128         {"NoteFrameColor", "colorClass", FL_STRING, note_frame_color, "black", 31},
129         {"LightedColor", "colorClass", FL_STRING, lighted_color, "gray80", 31},
130         {"BackgroundColor", "colorClass", FL_STRING, b_c, "linen", 31},
131         {"SelectionColor", "colorClass", FL_STRING, selection_color, "lightblue", 31}
132 };
133
134
135 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
136 {
137 //#warning Please see if you can trigger this!
138         // emergency save
139         if (!bufferlist.empty())
140                 bufferlist.emergencyWriteAll();
141
142         // Get the reason for the crash.
143         char etxt[513];
144         XGetErrorText(display, xeev->error_code, etxt, 512);
145         lyxerr << etxt << endl;
146         // By doing an abort we get a nice backtrace. (hopefully)
147         lyx::abort();
148         return 0; // Solaris CC wants us to return something
149 }
150
151
152 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
153         : _owner(owner)
154 {
155         gui = GUI;
156         if (!gui)
157                 return;
158
159         setDefaults();
160         
161         static const int num_res = sizeof(res)/sizeof(FL_resource);
162         fl_initialize(argc, argv, "LyX", cmdopt, num_res);
163         fl_get_app_resources(res, num_res);
164
165         Display * display = fl_get_display();
166         if (!display) {
167                 lyxerr << "LyX: unable to access X display, exiting" << endl;
168                 exit(1);
169         }
170         fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
171         // X Error handler install goes here
172         XSetErrorHandler(LyX_XErrHandler);
173         
174         background_color = b_c;
175         
176         // Make sure default screen is not larger than monitor
177         if (width == 690 && height == 510) {
178                 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
179                 if (HeightOfScreen(scr) - 24 < height)
180                         height = HeightOfScreen(scr) - 24;
181                 if (WidthOfScreen(scr) - 8 < width)
182                         width = WidthOfScreen(scr) - 8;
183         }
184
185 }
186
187
188 // A destructor is always necessary  (asierra-970604)
189 LyXGUI::~LyXGUI()
190 {
191         // Lyxserver was created in this class so should be destroyed
192         // here.  asierra-970604
193         delete lyxserver;
194         lyxserver = 0;
195
196         CloseLyXLookup();
197 }
198
199
200 void LyXGUI::setDefaults()
201 {
202         FL_IOPT cntl;
203         cntl.buttonFontSize = FL_NORMAL_SIZE;
204         cntl.browserFontSize = FL_NORMAL_SIZE;
205         cntl.labelFontSize = FL_NORMAL_SIZE;
206         cntl.choiceFontSize = FL_NORMAL_SIZE;
207         cntl.inputFontSize = FL_NORMAL_SIZE;
208         cntl.menuFontSize  = FL_NORMAL_SIZE;
209         cntl.borderWidth = -1;
210         cntl.vclass = FL_DefaultVisual;
211         fl_set_defaults(FL_PDVisual
212                         | FL_PDButtonFontSize
213                         | FL_PDBrowserFontSize
214                         | FL_PDLabelFontSize
215                         | FL_PDChoiceFontSize
216                         | FL_PDInputFontSize
217                         | FL_PDMenuFontSize
218                         | FL_PDBorderWidth, &cntl);
219 }
220
221
222 // This is called after we have parsed lyxrc
223 void LyXGUI::init()
224 {
225         if (!gui)
226                 return;
227
228         create_forms();
229         
230         // Set the font name for popups and menus
231         string menufontname = lyxrc->menu_font_name 
232                                + "-*-*-*-?-*-*-*-*-"  
233                                + lyxrc->font_norm; 
234                 // "?" means "scale that font"
235         string popupfontname = lyxrc->popup_font_name 
236                                + "-*-*-*-?-*-*-*-*-"  
237                                + lyxrc->font_norm; 
238
239         if (fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str()) < 0)
240                 lyxerr << "Could not set menu font to "
241                        << menufontname << endl;
242
243         if (fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str()) < 0)
244                 lyxerr << "Could not set popup font to "
245                        << popupfontname << endl;
246
247         // put here (after fl_initialize) to avoid segfault. Cannot be done
248         // in setDefaults() (Matthias 140496)
249         // Moved from ::LyXGUI to ::init to allow popup font customization 
250         // (petr 120997).
251         fl_setpup_fontstyle(FL_NORMAL_STYLE);
252         fl_setpup_fontsize(FL_NORMAL_SIZE);
253         fl_setpup_color(FL_MCOL, FL_BLACK);
254         fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
255
256         // all lyxrc settings has to be done here as lyxrc has not yet
257         // been read when the GUI is created (Jug)
258
259         // the print form
260         fl_set_input(fd_form_print->input_printer, 
261                      lyxrc->printer.c_str());   
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
365         // the character form
366         fd_form_character = create_form_form_character();
367         fl_set_form_atclose(fd_form_character->form_character,
368                             CancelCloseBoxCB, 0);
369         fl_addto_choice(fd_form_character->choice_family, 
370                         _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
371         fl_addto_choice(fd_form_character->choice_series, 
372                         _(" No change %l| Medium | Bold %l| Reset "));
373         fl_addto_choice(fd_form_character->choice_shape,
374                         _(" No change %l| Upright | Italic | Slanted | Small Caps "
375                         "%l| Reset "));
376         fl_addto_choice(fd_form_character->choice_size, 
377                         _(" No change %l| Tiny | Smallest | Smaller | Small "
378                         "| Normal | Large | Larger | Largest | Huge | Huger "
379                         "%l| Increase | Decrease | Reset "));
380         fl_addto_choice(fd_form_character->choice_bar, 
381                         _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
382         fl_addto_choice(fd_form_character->choice_color, 
383                         _(" No change %l| No color | Black | White | Red | Green "
384                         "| Blue | Cyan | Magenta | Yellow %l| Reset "));
385         fl_set_form_minsize(fd_form_character->form_character,
386                             fd_form_character->form_character->w,
387                             fd_form_character->form_character->h);
388
389         // the document form
390         fd_form_document = create_form_form_document();
391         fl_set_form_atclose(fd_form_document->form_document,
392                             CancelCloseBoxCB, 0);
393         fl_addto_choice(fd_form_document->choice_spacing,
394                         _(" Single | OneHalf | Double | Other "));
395
396         fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-1, 5);
397         fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
398         fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
399         fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
400         fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
401         fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
402         fl_addto_form(fd_form_document->form_document);
403         combo_language = new Combox(FL_COMBOX_DROPLIST);
404         FL_OBJECT * ob = fd_form_document->choice_language;
405         combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
406         combo_language->shortcut("#G", 1);
407         fl_end_form();
408         int n; // declared here because DEC cxx does not like multiple
409                // declarations of variables in for() loops (JMarc)
410         for (n = 0; tex_babel[n][0]; ++n) {
411             combo_language->addto(tex_babel[n]);
412         }
413
414         // not really necessary, but we can do it anyway.
415         fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
416         
417         for (n = 0; tex_fonts[n][0]; ++n) {
418             fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
419         }
420
421         fl_addto_choice(fd_form_document->choice_inputenc,
422                         "default|latin1|latin2|latin5"
423                         "|koi8-r|koi8-u|cp866|cp1251|iso88595");
424
425         for (n = 0; tex_graphics[n][0]; ++n) {
426             fl_addto_choice(fd_form_document->choice_postscript_driver,
427                                         tex_graphics[n]);
428         }
429         // not really necessary, but we can do it anyway.
430         fl_addto_choice(fd_form_document->choice_pagestyle,
431                         "default|empty|plain|headings|fancy");
432         fl_addto_choice(fd_form_document->choice_default_skip,
433                         _(" Smallskip | Medskip | Bigskip | Length "));
434         fl_set_input_return(fd_form_document->input_default_skip,
435                             FL_RETURN_ALWAYS);
436         fl_set_form_minsize(fd_form_document->form_document,
437                             fd_form_document->form_document->w,
438                             fd_form_document->form_document->h);
439
440         // the paper form
441         fd_form_paper = create_form_form_paper();
442         fl_set_form_atclose(fd_form_paper->form_paper,
443                             CancelCloseBoxCB, 0);
444         fl_addto_choice(fd_form_paper->choice_papersize2,
445                         _(" Default | Custom | USletter | USlegal "
446                         "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
447         fl_addto_choice(fd_form_paper->choice_paperpackage,
448                         _(" None "
449                         "| A4 small Margins (only portrait) "
450                         "| A4 very small Margins (only portrait) "
451                         "| A4 very wide margins (only portrait) "));
452         fl_set_input_return(fd_form_paper->input_custom_width,
453                             FL_RETURN_ALWAYS);
454         fl_set_input_return(fd_form_paper->input_custom_height,
455                             FL_RETURN_ALWAYS);
456         fl_set_input_return(fd_form_paper->input_top_margin,
457                             FL_RETURN_ALWAYS);
458         fl_set_input_return(fd_form_paper->input_bottom_margin,
459                             FL_RETURN_ALWAYS);
460         fl_set_input_return(fd_form_paper->input_left_margin,
461                             FL_RETURN_ALWAYS);
462         fl_set_input_return(fd_form_paper->input_right_margin,
463                             FL_RETURN_ALWAYS);
464         fl_set_input_return(fd_form_paper->input_head_height,
465                             FL_RETURN_ALWAYS);
466         fl_set_input_return(fd_form_paper->input_head_sep,
467                             FL_RETURN_ALWAYS);
468         fl_set_input_return(fd_form_paper->input_foot_skip,
469                             FL_RETURN_ALWAYS);
470
471         // the table_options form
472         fd_form_table_options = create_form_form_table_options();
473         fl_set_form_atclose(fd_form_table_options->form_table_options,
474                             CancelCloseBoxCB, 0);
475         fl_set_input_return(fd_form_table_options->input_column_width,
476                             FL_RETURN_ALWAYS);
477
478         // the table_extra form
479         fd_form_table_extra = create_form_form_table_extra();
480         fl_set_form_atclose(fd_form_table_extra->form_table_extra,
481                             CancelCloseBoxCB, 0);
482         fl_set_input_return(fd_form_table_extra->input_special_alignment,
483                             FL_RETURN_ALWAYS);
484         fl_set_input_return(fd_form_table_extra->input_special_multialign,
485                             FL_RETURN_ALWAYS);
486
487         // the quotes form
488         fd_form_quotes = create_form_form_quotes();
489         fl_set_form_atclose(fd_form_quotes->form_quotes,
490                             CancelCloseBoxCB, 0);
491         // Is it wrong of me to use « » instead of << >> ? (Lgb)
492         // Maybe if people use a font other than latin1... (JMarc)
493         fl_addto_choice(fd_form_quotes->choice_quotes_language,
494                         _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
495
496         // the preamble form
497         fd_form_preamble = create_form_form_preamble();
498         fl_set_form_atclose(fd_form_preamble->form_preamble,
499                             CancelCloseBoxCB, 0);
500
501         // the table form
502         fd_form_table = create_form_form_table();
503         fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
504         fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
505         fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
506         fl_set_slider_value(fd_form_table->slider_rows, 5);
507         fl_set_slider_value(fd_form_table->slider_columns, 5);
508         fl_set_slider_precision(fd_form_table->slider_rows, 0);
509         fl_set_slider_precision(fd_form_table->slider_columns, 0);
510
511         // the print form
512         fd_form_print = create_form_form_print();
513         fl_set_form_atclose(fd_form_print->form_print, CancelCloseBoxCB, 0);
514         fl_set_button(fd_form_print->radio_printer, 1);
515         fl_set_button(fd_form_print->radio_file, 0);
516         fl_set_button(fd_form_print->radio_order_normal, 1);
517         fl_set_button(fd_form_print->radio_order_reverse, 0);
518         fl_set_button(fd_form_print->radio_all_pages, 1);
519         fl_set_button(fd_form_print->radio_odd_pages, 0);
520         fl_set_button(fd_form_print->radio_even_pages, 0);
521
522         // the sendto form
523         fd_form_sendto = create_form_form_sendto();
524         fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
525
526         // the figure form
527         fd_form_figure = create_form_form_figure();
528         fl_set_form_atclose(fd_form_figure->form_figure,
529                             CancelCloseBoxCB, 0);
530         fl_set_button(fd_form_figure->radio_postscript, 1);
531
532         // the screen form
533         fd_form_screen = create_form_form_screen();
534         fl_set_form_atclose(fd_form_screen->form_screen,
535                             CancelCloseBoxCB, 0);
536
537         // the toc form
538         fd_form_toc = create_form_form_toc();
539         fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
540
541         // the ref form
542         fd_form_ref = create_form_form_ref();
543         fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
544         fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
545                             fd_form_ref->form_ref->h);
546
547         // the latex options form
548         fd_latex_options = create_form_LaTeXOptions();
549         fl_set_form_atclose(fd_latex_options->LaTeXOptions,
550                             CancelCloseBoxCB, 0);
551
552         // the latex log form
553         fd_latex_log = create_form_LaTeXLog();
554         fl_set_form_atclose(fd_latex_log->LaTeXLog,
555                             CancelCloseBoxCB, 0);
556
557         // Show the main & title form
558         int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
559         int title_placement = FL_PLACE_CENTER;
560         // Did we get a valid position?
561         if (xpos>= 0 && ypos>= 0) {
562                 lyxViews->setPosition(xpos, ypos);
563                 if (lyxrc->show_banner) {
564                         // show the title form in the middle of the main form
565                         fl_set_form_position(fd_form_title->form_title,
566                                              abs(xpos + (width/2) - (370 / 2)),
567                                              abs(ypos + (height/2) - (290 / 2)));
568                         title_placement = FL_PLACE_GEOMETRY;
569                         // The use of abs() above is a trick to ensure
570                         // valid positions
571                 }
572                         main_placement = FL_PLACE_POSITION;
573         }
574         lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
575         if (lyxrc->show_banner) {
576                 fl_show_form(fd_form_title->form_title, 
577                              title_placement, FL_NOBORDER, 
578                              _("LyX Banner"));
579                 fl_redraw_form(fd_form_title->form_title);
580                 fl_raise_form(fd_form_title->form_title);
581
582                 // Show the title form at most 7 secs (lowered from 10 secs)
583                 fl_set_timer(fd_form_title->timer_title, 7);
584         }
585 }
586
587
588 void LyXGUI::runTime()
589         /* This will usually be toolkit (GUI) specific. This is
590          * also usually the XEvent dispatcher of the GUI. */
591 {
592         if (!gui)
593                 return;
594
595         // XForms specific
596         XEvent ev;
597
598         while (!finished) {
599                 if (fl_check_forms() == FL_EVENT) {
600                         lyxerr << "LyX: This shouldn't happen..." << endl;
601                         fl_XNextEvent(&ev);
602                 }
603         }
604 }
605
606
607 void LyXGUI::regBuf(Buffer * b)
608 {
609         lyxViews->view()->buffer(b);
610 }