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_ref * fd_form_ref;
68 FD_LaTeXLog * fd_latex_log; // from log_form.h
69 Combox * combo_language;
70 Combox * combo_language2;
72 extern LyXServer * lyxserver;
73 extern bool finished; // flag, that we are quitting the program
74 extern BufferList bufferlist;
78 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
81 static int width = 690;
82 static int height = 510;
85 static char geometry[40];
86 bool cursor_follows_scrollbar;
91 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
95 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
97 //#warning Please see if you can trigger this!
99 if (!bufferlist.empty())
100 bufferlist.emergencyWriteAll();
102 // Get the reason for the crash.
104 XGetErrorText(display, xeev->error_code, etxt, 512);
105 lyxerr << etxt << endl;
106 // By doing an abort we get a nice backtrace. (hopefully)
108 return 0; // Solaris CC wants us to return something
112 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
113 : _owner(owner), lyxViews(0)
121 static const int num_res = sizeof(res)/sizeof(FL_resource);
122 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
123 fl_get_app_resources(res, num_res);
125 static const int geometryBitmask = XParseGeometry( geometry,
128 (unsigned int *) &width,
129 (unsigned int *) &height
132 Display * display = fl_get_display();
134 lyxerr << "LyX: unable to access X display, exiting" << endl;
137 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
138 // X Error handler install goes here
139 XSetErrorHandler(LyX_XErrHandler);
141 // A width less than 590 pops up an awkward main window
142 // The minimal values of width/height (590/400) are defined in
144 if (width < 590) width = 590;
145 if (height < 400) height = 400;
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;
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;
161 // Recalculate xpos if it's negative
162 if (geometryBitmask & 16)
163 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
165 // Recalculate ypos if it's negative
166 if (geometryBitmask & 32)
167 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
169 // Initialize the LyXColorHandler
170 lyxColorHandler = new LyXColorHandler;
174 // A destructor is always necessary (asierra-970604)
177 // Lyxserver was created in this class so should be destroyed
178 // here. asierra-970604
188 void LyXGUI::setDefaults()
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
203 | FL_PDChoiceFontSize
206 | FL_PDBorderWidth, &cntl);
210 // This is called after we have parsed lyxrc
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;
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());
232 lyxerr << "Could not set menu font to "
233 << menufontname << endl;
236 lyxerr << "Could not set popup font to "
237 << popupfontname << endl;
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");
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
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);
260 // all lyxrc settings has to be done here as lyxrc has not yet
261 // been read when the GUI is created (Jug)
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);
278 // Update parameters.
281 // Initialize the views.
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);
290 void LyXGUI::create_forms()
292 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
293 lyxViews = new LyXView(width, height);
294 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
296 // From here down should be done by somebody else. (Lgb)
303 string banner_file = LibFileSearch("images", "banner", "xpm");
304 if (lyxrc.show_banner && !banner_file.empty()) {
305 fd_form_title = create_form_form_title();
306 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
307 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
308 fl_addto_form(fd_form_title->form_title);
309 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
310 fl_set_pixmapbutton_file(obj, banner_file.c_str());
312 fl_set_pixmapbutton_focus_outline(obj, 3);
313 fl_set_button_shortcut(obj, "^M ^[", 1);
314 fl_set_object_boxtype(obj, FL_NO_BOX);
315 fl_set_object_callback(obj, TimerCB, 0);
317 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
318 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
319 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
320 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
321 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
322 fl_set_object_lcol(obj, FL_FREE_COL3);
323 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
324 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
328 // the paragraph form
329 fd_form_paragraph = create_form_form_paragraph();
330 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
331 CancelCloseBoxCB, 0);
332 fl_addto_choice(fd_form_paragraph->choice_space_above,
333 _(" None | Defskip | Smallskip "
334 "| Medskip | Bigskip | VFill | Length "));
335 fl_addto_choice(fd_form_paragraph->choice_space_below,
336 _(" None | Defskip | Smallskip "
337 "| Medskip | Bigskip | VFill | Length "));
338 fl_set_input_return(fd_form_paragraph->input_space_above,
340 fl_set_input_return(fd_form_paragraph->input_space_below,
343 // the paragraph extra form
344 fd_form_paragraph_extra = create_form_form_paragraph_extra();
345 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
346 CancelCloseBoxCB, 0);
347 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
349 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
351 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
353 // the character form
354 fd_form_character = create_form_form_character();
355 fl_set_form_atclose(fd_form_character->form_character,
356 CancelCloseBoxCB, 0);
357 fl_addto_choice(fd_form_character->choice_family,
358 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
359 fl_addto_choice(fd_form_character->choice_series,
360 _(" No change %l| Medium | Bold %l| Reset "));
361 fl_addto_choice(fd_form_character->choice_shape,
362 _(" No change %l| Upright | Italic | Slanted | Small Caps "
364 fl_addto_choice(fd_form_character->choice_size,
365 _(" No change %l| Tiny | Smallest | Smaller | Small "
366 "| Normal | Large | Larger | Largest | Huge | Huger "
367 "%l| Increase | Decrease | Reset "));
368 fl_addto_choice(fd_form_character->choice_bar,
369 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
370 fl_addto_choice(fd_form_character->choice_color,
371 _(" No change %l| No color | Black | White | Red | Green "
372 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
373 fl_set_form_minsize(fd_form_character->form_character,
374 fd_form_character->form_character->w,
375 fd_form_character->form_character->h);
376 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
377 fl_addto_form(fd_form_character->form_character);
378 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
379 FL_OBJECT * ob = fd_form_character->choice_language;
380 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
381 combo_language2->shortcut("#L", 1);
383 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
386 fd_form_document = create_form_form_document();
387 fl_set_form_atclose(fd_form_document->form_document,
388 CancelCloseBoxCB, 0);
389 fl_addto_choice(fd_form_document->choice_spacing,
390 _(" Single | OneHalf | Double | Other "));
392 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
393 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
394 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
395 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
396 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
397 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
398 fl_addto_form(fd_form_document->form_document);
399 combo_language = new Combox(FL_COMBOX_DROPLIST);
400 ob = fd_form_document->choice_language;
401 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
402 combo_language->shortcut("#G", 1);
405 // "default" is not part of the languages array any more.
406 combo_language->addto("default");
407 combo_language2->addto(_("No change"));
408 combo_language2->addto(_("Reset"));
409 for(Languages::const_iterator cit = languages.begin();
410 cit != languages.end(); ++cit) {
411 combo_language->addto((*cit).second.lang().c_str());
412 combo_language2->addto((*cit).second.lang().c_str());
414 combo_language2->select_text("No change");
416 // not really necessary, but we can do it anyway.
417 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
419 for (n = 0; tex_fonts[n][0]; ++n) {
420 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
423 fl_addto_choice(fd_form_document->choice_inputenc,
424 "default|auto|latin1|latin2|latin5"
425 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
427 for (n = 0; tex_graphics[n][0]; ++n) {
428 fl_addto_choice(fd_form_document->choice_postscript_driver,
431 // not really necessary, but we can do it anyway.
432 fl_addto_choice(fd_form_document->choice_pagestyle,
433 "default|empty|plain|headings|fancy");
434 fl_addto_choice(fd_form_document->choice_default_skip,
435 _(" Smallskip | Medskip | Bigskip | Length "));
436 fl_set_input_return(fd_form_document->input_default_skip,
438 fl_set_form_minsize(fd_form_document->form_document,
439 fd_form_document->form_document->w,
440 fd_form_document->form_document->h);
441 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
444 fd_form_paper = create_form_form_paper();
445 fl_set_form_atclose(fd_form_paper->form_paper,
446 CancelCloseBoxCB, 0);
447 fl_addto_choice(fd_form_paper->choice_papersize2,
448 _(" Default | Custom | USletter | USlegal "
449 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
450 fl_addto_choice(fd_form_paper->choice_paperpackage,
452 "| A4 small Margins (only portrait) "
453 "| A4 very small Margins (only portrait) "
454 "| A4 very wide margins (only portrait) "));
455 fl_set_input_return(fd_form_paper->input_custom_width,
457 fl_set_input_return(fd_form_paper->input_custom_height,
459 fl_set_input_return(fd_form_paper->input_top_margin,
461 fl_set_input_return(fd_form_paper->input_bottom_margin,
463 fl_set_input_return(fd_form_paper->input_left_margin,
465 fl_set_input_return(fd_form_paper->input_right_margin,
467 fl_set_input_return(fd_form_paper->input_head_height,
469 fl_set_input_return(fd_form_paper->input_head_sep,
471 fl_set_input_return(fd_form_paper->input_foot_skip,
473 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
475 // the table_options form
476 fd_form_table_options = create_form_form_table_options();
477 fl_set_form_atclose(fd_form_table_options->form_table_options,
478 CancelCloseBoxCB, 0);
479 fl_set_input_return(fd_form_table_options->input_column_width,
482 // the table_extra form
483 fd_form_table_extra = create_form_form_table_extra();
484 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
485 CancelCloseBoxCB, 0);
486 fl_set_input_return(fd_form_table_extra->input_special_alignment,
488 fl_set_input_return(fd_form_table_extra->input_special_multialign,
490 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
493 fd_form_quotes = create_form_form_quotes();
494 fl_set_form_atclose(fd_form_quotes->form_quotes,
495 CancelCloseBoxCB, 0);
496 // Is it wrong of me to use « » instead of << >> ? (Lgb)
497 // Maybe if people use a font other than latin1... (JMarc)
498 fl_addto_choice(fd_form_quotes->choice_quotes_language,
499 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
502 fd_form_preamble = create_form_form_preamble();
503 fl_set_form_atclose(fd_form_preamble->form_preamble,
504 CancelCloseBoxCB, 0);
508 fd_form_table = create_form_form_table();
509 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
510 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
511 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
512 fl_set_slider_value(fd_form_table->slider_rows, 5);
513 fl_set_slider_value(fd_form_table->slider_columns, 5);
514 fl_set_slider_precision(fd_form_table->slider_rows, 0);
515 fl_set_slider_precision(fd_form_table->slider_columns, 0);
516 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
520 fd_form_sendto = create_form_form_sendto();
521 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
524 fd_form_figure = create_form_form_figure();
525 fl_set_form_atclose(fd_form_figure->form_figure,
526 CancelCloseBoxCB, 0);
527 fl_set_button(fd_form_figure->radio_postscript, 1);
530 fd_form_screen = create_form_form_screen();
531 fl_set_form_atclose(fd_form_screen->form_screen,
532 CancelCloseBoxCB, 0);
535 fd_form_ref = create_form_form_ref();
536 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
537 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
538 fd_form_ref->form_ref->h);
540 // the latex log form
541 fd_latex_log = create_form_LaTeXLog();
542 fl_set_form_atclose(fd_latex_log->LaTeXLog,
543 CancelCloseBoxCB, 0);
545 // Show the main & title form
546 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
547 int title_placement = FL_PLACE_CENTER;
548 // Did we get a valid position?
549 if (xpos>= 0 && ypos>= 0) {
550 lyxViews->setPosition(xpos, ypos);
551 if (lyxrc.show_banner) {
552 // show the title form in the middle of the main form
553 fl_set_form_position(fd_form_title->form_title,
554 abs(xpos + (width/2) - (370 / 2)),
555 abs(ypos + (height/2) - (290 / 2)));
556 title_placement = FL_PLACE_GEOMETRY;
557 // The use of abs() above is a trick to ensure
560 main_placement = FL_PLACE_POSITION;
562 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
563 if (lyxrc.show_banner) {
564 fl_show_form(fd_form_title->form_title,
565 title_placement, FL_NOBORDER,
567 fl_redraw_form(fd_form_title->form_title);
568 fl_raise_form(fd_form_title->form_title);
570 // Show the title form at most 7 secs (lowered from 10 secs)
571 fl_set_timer(fd_form_title->timer_title, 7);
576 void LyXGUI::runTime()
577 /* This will usually be toolkit (GUI) specific. This is
578 * also usually the XEvent dispatcher of the GUI. */
588 kapp->processEvents();
591 Gnome::Main::instance()->iteration(FALSE);
594 if (fl_check_forms() == FL_EVENT) {
595 lyxerr << "LyX: This shouldn't happen..." << endl;
602 void LyXGUI::regBuf(Buffer * b)
604 lyxViews->view()->buffer(b);
607 LyXView * LyXGUI::getLyXView() const