1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
23 # include <gnome--/main.h>
28 #include FORMS_H_LOCATION
29 #include "support/filetools.h"
33 #include "layout_forms.h"
34 #include "print_form.h"
35 #include "tex-strings.h"
42 #include "lyxserver.h"
45 #include "lyx_gui_misc.h"
46 #include "lyxlookup.h"
47 #include "bufferlist.h"
49 #include "ColorHandler.h"
53 FD_form_title * fd_form_title;
54 FD_form_paragraph * fd_form_paragraph;
55 FD_form_paragraph_extra * fd_form_paragraph_extra;
56 FD_form_character * fd_form_character;
57 FD_form_document * fd_form_document;
58 FD_form_paper * fd_form_paper;
59 FD_form_table_options * fd_form_table_options;
60 FD_form_table_extra * fd_form_table_extra;
61 FD_form_quotes * fd_form_quotes;
62 FD_form_preamble * fd_form_preamble;
63 FD_form_table * fd_form_table;
64 FD_form_sendto * fd_form_sendto;
65 FD_form_figure * fd_form_figure;
66 FD_form_screen * fd_form_screen;
67 FD_form_toc * fd_form_toc;
68 FD_form_ref * fd_form_ref;
69 FD_LaTeXLog * fd_latex_log; // from log_form.h
70 Combox * combo_language;
71 Combox * combo_language2;
73 extern LyXServer * lyxserver;
74 extern bool finished; // flag, that we are quitting the program
75 extern BufferList bufferlist;
79 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
82 static int width = 690;
83 static int height = 510;
86 static char geometry[40];
87 bool cursor_follows_scrollbar;
92 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
96 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
98 //#warning Please see if you can trigger this!
100 if (!bufferlist.empty())
101 bufferlist.emergencyWriteAll();
103 // Get the reason for the crash.
105 XGetErrorText(display, xeev->error_code, etxt, 512);
106 lyxerr << etxt << endl;
107 // By doing an abort we get a nice backtrace. (hopefully)
109 return 0; // Solaris CC wants us to return something
113 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
114 : _owner(owner), lyxViews(0)
122 static const int num_res = sizeof(res)/sizeof(FL_resource);
123 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
124 fl_get_app_resources(res, num_res);
126 static const int geometryBitmask = XParseGeometry( geometry,
129 (unsigned int *) &width,
130 (unsigned int *) &height
133 Display * display = fl_get_display();
135 lyxerr << "LyX: unable to access X display, exiting" << endl;
138 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
139 // X Error handler install goes here
140 XSetErrorHandler(LyX_XErrHandler);
142 // A width less than 590 pops up an awkward main window
143 // The minimal values of width/height (590/400) are defined in
145 if (width < 590) width = 590;
146 if (height < 400) height = 400;
148 // If width is not set by geometry, check it against monitor width
149 if ( !(geometryBitmask & 4) ) {
150 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
151 if (WidthOfScreen(scr) - 8 < width)
152 width = WidthOfScreen(scr) - 8;
155 // If height is not set by geometry, check it against monitor height
156 if ( !(geometryBitmask & 8) ) {
157 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
158 if (HeightOfScreen(scr) - 24 < height)
159 height = HeightOfScreen(scr) - 24;
162 // Recalculate xpos if it's negative
163 if (geometryBitmask & 16)
164 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
166 // Recalculate ypos if it's negative
167 if (geometryBitmask & 32)
168 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
170 // Initialize the LyXColorHandler
171 lyxColorHandler = new LyXColorHandler;
175 // A destructor is always necessary (asierra-970604)
178 // Lyxserver was created in this class so should be destroyed
179 // here. asierra-970604
189 void LyXGUI::setDefaults()
192 cntl.buttonFontSize = FL_NORMAL_SIZE;
193 cntl.browserFontSize = FL_NORMAL_SIZE;
194 cntl.labelFontSize = FL_NORMAL_SIZE;
195 cntl.choiceFontSize = FL_NORMAL_SIZE;
196 cntl.inputFontSize = FL_NORMAL_SIZE;
197 cntl.menuFontSize = FL_NORMAL_SIZE;
198 cntl.borderWidth = -1;
199 cntl.vclass = FL_DefaultVisual;
200 fl_set_defaults(FL_PDVisual
201 | FL_PDButtonFontSize
202 | FL_PDBrowserFontSize
204 | FL_PDChoiceFontSize
207 | FL_PDBorderWidth, &cntl);
211 // This is called after we have parsed lyxrc
219 if (lyxrc.font_norm_menu.empty())
220 lyxrc.font_norm_menu = lyxrc.font_norm;
221 // Set the font name for popups and menus
222 string menufontname = lyxrc.menu_font_name
223 + "-*-*-*-?-*-*-*-*-"
224 + lyxrc.font_norm_menu;
225 // "?" means "scale that font"
226 string popupfontname = lyxrc.popup_font_name
227 + "-*-*-*-?-*-*-*-*-"
228 + lyxrc.font_norm_menu;
230 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
231 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
233 lyxerr << "Could not set menu font to "
234 << menufontname << endl;
237 lyxerr << "Could not set popup font to "
238 << popupfontname << endl;
240 if (bold < 0 && normal < 0) {
241 lyxerr << "Using 'helvetica' font for menus" << endl;
242 bold = fl_set_font_name(FL_BOLD_STYLE,
243 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
244 normal = fl_set_font_name(FL_NORMAL_STYLE,
245 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
246 if (bold < 0 && normal < 0) {
247 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
248 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
252 // put here (after fl_initialize) to avoid segfault. Cannot be done
253 // in setDefaults() (Matthias 140496)
254 // Moved from ::LyXGUI to ::init to allow popup font customization
256 fl_setpup_fontstyle(FL_NORMAL_STYLE);
257 fl_setpup_fontsize(FL_NORMAL_SIZE);
258 fl_setpup_color(FL_MCOL, FL_BLACK);
259 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
261 // all lyxrc settings has to be done here as lyxrc has not yet
262 // been read when the GUI is created (Jug)
265 if (!lyxrc.custom_export_command.empty())
266 fl_set_input(fd_form_sendto->input_cmd,
267 lyxrc.custom_export_command.c_str());
268 if (lyxrc.custom_export_format == "lyx")
269 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
270 else if (lyxrc.custom_export_format == "tex")
271 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
272 else if (lyxrc.custom_export_format == "dvi")
273 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
274 else if (lyxrc.custom_export_format == "ps")
275 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
276 else if (lyxrc.custom_export_format == "ascii")
277 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
279 // Update parameters.
282 // Initialize the views.
285 // in 0.12 the initialisation of the LyXServer must be done here
286 // 0.13 it should be moved again...
287 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
291 void LyXGUI::create_forms()
293 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
294 lyxViews = new LyXView(width, height);
295 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
297 // From here down should be done by somebody else. (Lgb)
304 string banner_file = LibFileSearch("images", "banner", "xpm");
305 if (lyxrc.show_banner && !banner_file.empty()) {
306 fd_form_title = create_form_form_title();
307 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
308 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
309 fl_addto_form(fd_form_title->form_title);
310 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
311 fl_set_pixmapbutton_file(obj, banner_file.c_str());
313 fl_set_pixmapbutton_focus_outline(obj, 3);
314 fl_set_button_shortcut(obj, "^M ^[", 1);
315 fl_set_object_boxtype(obj, FL_NO_BOX);
316 fl_set_object_callback(obj, TimerCB, 0);
318 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
319 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
320 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
321 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
322 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
323 fl_set_object_lcol(obj, FL_FREE_COL3);
324 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
325 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
329 // the paragraph form
330 fd_form_paragraph = create_form_form_paragraph();
331 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
332 CancelCloseBoxCB, 0);
333 fl_addto_choice(fd_form_paragraph->choice_space_above,
334 _(" None | Defskip | Smallskip "
335 "| Medskip | Bigskip | VFill | Length "));
336 fl_addto_choice(fd_form_paragraph->choice_space_below,
337 _(" None | Defskip | Smallskip "
338 "| Medskip | Bigskip | VFill | Length "));
339 fl_set_input_return(fd_form_paragraph->input_space_above,
341 fl_set_input_return(fd_form_paragraph->input_space_below,
344 // the paragraph extra form
345 fd_form_paragraph_extra = create_form_form_paragraph_extra();
346 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
347 CancelCloseBoxCB, 0);
348 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
350 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
352 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
354 // the character form
355 fd_form_character = create_form_form_character();
356 fl_set_form_atclose(fd_form_character->form_character,
357 CancelCloseBoxCB, 0);
358 fl_addto_choice(fd_form_character->choice_family,
359 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
360 fl_addto_choice(fd_form_character->choice_series,
361 _(" No change %l| Medium | Bold %l| Reset "));
362 fl_addto_choice(fd_form_character->choice_shape,
363 _(" No change %l| Upright | Italic | Slanted | Small Caps "
365 fl_addto_choice(fd_form_character->choice_size,
366 _(" No change %l| Tiny | Smallest | Smaller | Small "
367 "| Normal | Large | Larger | Largest | Huge | Huger "
368 "%l| Increase | Decrease | Reset "));
369 fl_addto_choice(fd_form_character->choice_bar,
370 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
371 fl_addto_choice(fd_form_character->choice_color,
372 _(" No change %l| No color | Black | White | Red | Green "
373 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
374 fl_set_form_minsize(fd_form_character->form_character,
375 fd_form_character->form_character->w,
376 fd_form_character->form_character->h);
377 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
378 fl_addto_form(fd_form_character->form_character);
379 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
380 FL_OBJECT * ob = fd_form_character->choice_language;
381 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
382 combo_language2->shortcut("#L", 1);
384 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
387 fd_form_document = create_form_form_document();
388 fl_set_form_atclose(fd_form_document->form_document,
389 CancelCloseBoxCB, 0);
390 fl_addto_choice(fd_form_document->choice_spacing,
391 _(" Single | OneHalf | Double | Other "));
393 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
394 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
395 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
396 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
397 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
398 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
399 fl_addto_form(fd_form_document->form_document);
400 combo_language = new Combox(FL_COMBOX_DROPLIST);
401 ob = fd_form_document->choice_language;
402 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
403 combo_language->shortcut("#G", 1);
406 // "default" is not part of the languages array any more.
407 combo_language->addto("default");
408 combo_language2->addto(_("No change"));
409 combo_language2->addto(_("Reset"));
410 for(Languages::const_iterator cit = languages.begin();
411 cit != languages.end(); ++cit) {
412 combo_language->addto((*cit).second.lang().c_str());
413 combo_language2->addto((*cit).second.lang().c_str());
415 combo_language2->select_text("No change");
417 // not really necessary, but we can do it anyway.
418 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
420 for (n = 0; tex_fonts[n][0]; ++n) {
421 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
424 fl_addto_choice(fd_form_document->choice_inputenc,
425 "default|auto|latin1|latin2|latin5"
426 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
428 for (n = 0; tex_graphics[n][0]; ++n) {
429 fl_addto_choice(fd_form_document->choice_postscript_driver,
432 // not really necessary, but we can do it anyway.
433 fl_addto_choice(fd_form_document->choice_pagestyle,
434 "default|empty|plain|headings|fancy");
435 fl_addto_choice(fd_form_document->choice_default_skip,
436 _(" Smallskip | Medskip | Bigskip | Length "));
437 fl_set_input_return(fd_form_document->input_default_skip,
439 fl_set_form_minsize(fd_form_document->form_document,
440 fd_form_document->form_document->w,
441 fd_form_document->form_document->h);
442 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
445 fd_form_paper = create_form_form_paper();
446 fl_set_form_atclose(fd_form_paper->form_paper,
447 CancelCloseBoxCB, 0);
448 fl_addto_choice(fd_form_paper->choice_papersize2,
449 _(" Default | Custom | USletter | USlegal "
450 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
451 fl_addto_choice(fd_form_paper->choice_paperpackage,
453 "| A4 small Margins (only portrait) "
454 "| A4 very small Margins (only portrait) "
455 "| A4 very wide margins (only portrait) "));
456 fl_set_input_return(fd_form_paper->input_custom_width,
458 fl_set_input_return(fd_form_paper->input_custom_height,
460 fl_set_input_return(fd_form_paper->input_top_margin,
462 fl_set_input_return(fd_form_paper->input_bottom_margin,
464 fl_set_input_return(fd_form_paper->input_left_margin,
466 fl_set_input_return(fd_form_paper->input_right_margin,
468 fl_set_input_return(fd_form_paper->input_head_height,
470 fl_set_input_return(fd_form_paper->input_head_sep,
472 fl_set_input_return(fd_form_paper->input_foot_skip,
474 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
476 // the table_options form
477 fd_form_table_options = create_form_form_table_options();
478 fl_set_form_atclose(fd_form_table_options->form_table_options,
479 CancelCloseBoxCB, 0);
480 fl_set_input_return(fd_form_table_options->input_column_width,
483 // the table_extra form
484 fd_form_table_extra = create_form_form_table_extra();
485 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
486 CancelCloseBoxCB, 0);
487 fl_set_input_return(fd_form_table_extra->input_special_alignment,
489 fl_set_input_return(fd_form_table_extra->input_special_multialign,
491 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
494 fd_form_quotes = create_form_form_quotes();
495 fl_set_form_atclose(fd_form_quotes->form_quotes,
496 CancelCloseBoxCB, 0);
497 // Is it wrong of me to use « » instead of << >> ? (Lgb)
498 // Maybe if people use a font other than latin1... (JMarc)
499 fl_addto_choice(fd_form_quotes->choice_quotes_language,
500 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
503 fd_form_preamble = create_form_form_preamble();
504 fl_set_form_atclose(fd_form_preamble->form_preamble,
505 CancelCloseBoxCB, 0);
509 fd_form_table = create_form_form_table();
510 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
511 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
512 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
513 fl_set_slider_value(fd_form_table->slider_rows, 5);
514 fl_set_slider_value(fd_form_table->slider_columns, 5);
515 fl_set_slider_precision(fd_form_table->slider_rows, 0);
516 fl_set_slider_precision(fd_form_table->slider_columns, 0);
517 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
521 fd_form_sendto = create_form_form_sendto();
522 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
525 fd_form_figure = create_form_form_figure();
526 fl_set_form_atclose(fd_form_figure->form_figure,
527 CancelCloseBoxCB, 0);
528 fl_set_button(fd_form_figure->radio_postscript, 1);
531 fd_form_screen = create_form_form_screen();
532 fl_set_form_atclose(fd_form_screen->form_screen,
533 CancelCloseBoxCB, 0);
536 fd_form_toc = create_form_form_toc();
537 fl_addto_choice(fd_form_toc->toctype,
538 _(" TOC | LOF | LOT | LOA "));
539 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
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);
547 // the latex log form
548 fd_latex_log = create_form_LaTeXLog();
549 fl_set_form_atclose(fd_latex_log->LaTeXLog,
550 CancelCloseBoxCB, 0);
552 // Show the main & title form
553 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
554 int title_placement = FL_PLACE_CENTER;
555 // Did we get a valid position?
556 if (xpos>= 0 && ypos>= 0) {
557 lyxViews->setPosition(xpos, ypos);
558 if (lyxrc.show_banner) {
559 // show the title form in the middle of the main form
560 fl_set_form_position(fd_form_title->form_title,
561 abs(xpos + (width/2) - (370 / 2)),
562 abs(ypos + (height/2) - (290 / 2)));
563 title_placement = FL_PLACE_GEOMETRY;
564 // The use of abs() above is a trick to ensure
567 main_placement = FL_PLACE_POSITION;
569 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
570 if (lyxrc.show_banner) {
571 fl_show_form(fd_form_title->form_title,
572 title_placement, FL_NOBORDER,
574 fl_redraw_form(fd_form_title->form_title);
575 fl_raise_form(fd_form_title->form_title);
577 // Show the title form at most 7 secs (lowered from 10 secs)
578 fl_set_timer(fd_form_title->timer_title, 7);
583 void LyXGUI::runTime()
584 /* This will usually be toolkit (GUI) specific. This is
585 * also usually the XEvent dispatcher of the GUI. */
595 kapp->processEvents();
598 Gnome::Main::instance()->iteration(FALSE);
601 if (fl_check_forms() == FL_EVENT) {
602 lyxerr << "LyX: This shouldn't happen..." << endl;
609 void LyXGUI::regBuf(Buffer * b)
611 lyxViews->view()->buffer(b);
614 LyXView * LyXGUI::getLyXView() const