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_LaTeXLog * fd_latex_log; // from log_form.h
68 Combox * combo_language;
69 Combox * combo_language2;
71 extern LyXServer * lyxserver;
72 extern bool finished; // flag, that we are quitting the program
73 extern BufferList bufferlist;
77 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
80 static int width = 690;
81 static int height = 510;
84 static char geometry[40];
85 bool cursor_follows_scrollbar;
90 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
94 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
96 //#warning Please see if you can trigger this!
98 if (!bufferlist.empty())
99 bufferlist.emergencyWriteAll();
101 // Get the reason for the crash.
103 XGetErrorText(display, xeev->error_code, etxt, 512);
104 lyxerr << etxt << endl;
105 // By doing an abort we get a nice backtrace. (hopefully)
107 return 0; // Solaris CC wants us to return something
111 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
112 : _owner(owner), lyxViews(0)
120 static const int num_res = sizeof(res)/sizeof(FL_resource);
121 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
122 fl_get_app_resources(res, num_res);
124 static const int geometryBitmask = XParseGeometry( geometry,
127 (unsigned int *) &width,
128 (unsigned int *) &height
131 Display * display = fl_get_display();
133 lyxerr << "LyX: unable to access X display, exiting" << endl;
136 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
137 // X Error handler install goes here
138 XSetErrorHandler(LyX_XErrHandler);
140 // A width less than 590 pops up an awkward main window
141 // The minimal values of width/height (590/400) are defined in
143 if (width < 590) width = 590;
144 if (height < 400) height = 400;
146 // If width is not set by geometry, check it against monitor width
147 if ( !(geometryBitmask & 4) ) {
148 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
149 if (WidthOfScreen(scr) - 8 < width)
150 width = WidthOfScreen(scr) - 8;
153 // If height is not set by geometry, check it against monitor height
154 if ( !(geometryBitmask & 8) ) {
155 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
156 if (HeightOfScreen(scr) - 24 < height)
157 height = HeightOfScreen(scr) - 24;
160 // Recalculate xpos if it's negative
161 if (geometryBitmask & 16)
162 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
164 // Recalculate ypos if it's negative
165 if (geometryBitmask & 32)
166 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
168 // Initialize the LyXColorHandler
169 lyxColorHandler = new LyXColorHandler;
173 // A destructor is always necessary (asierra-970604)
176 // Lyxserver was created in this class so should be destroyed
177 // here. asierra-970604
187 void LyXGUI::setDefaults()
190 cntl.buttonFontSize = FL_NORMAL_SIZE;
191 cntl.browserFontSize = FL_NORMAL_SIZE;
192 cntl.labelFontSize = FL_NORMAL_SIZE;
193 cntl.choiceFontSize = FL_NORMAL_SIZE;
194 cntl.inputFontSize = FL_NORMAL_SIZE;
195 cntl.menuFontSize = FL_NORMAL_SIZE;
196 cntl.borderWidth = -1;
197 cntl.vclass = FL_DefaultVisual;
198 fl_set_defaults(FL_PDVisual
199 | FL_PDButtonFontSize
200 | FL_PDBrowserFontSize
202 | FL_PDChoiceFontSize
205 | FL_PDBorderWidth, &cntl);
209 // This is called after we have parsed lyxrc
217 if (lyxrc.font_norm_menu.empty())
218 lyxrc.font_norm_menu = lyxrc.font_norm;
219 // Set the font name for popups and menus
220 string menufontname = lyxrc.menu_font_name
221 + "-*-*-*-?-*-*-*-*-"
222 + lyxrc.font_norm_menu;
223 // "?" means "scale that font"
224 string popupfontname = lyxrc.popup_font_name
225 + "-*-*-*-?-*-*-*-*-"
226 + lyxrc.font_norm_menu;
228 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
229 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
231 lyxerr << "Could not set menu font to "
232 << menufontname << endl;
235 lyxerr << "Could not set popup font to "
236 << popupfontname << endl;
238 if (bold < 0 && normal < 0) {
239 lyxerr << "Using 'helvetica' font for menus" << endl;
240 bold = fl_set_font_name(FL_BOLD_STYLE,
241 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
242 normal = fl_set_font_name(FL_NORMAL_STYLE,
243 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
244 if (bold < 0 && normal < 0) {
245 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
246 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
250 // put here (after fl_initialize) to avoid segfault. Cannot be done
251 // in setDefaults() (Matthias 140496)
252 // Moved from ::LyXGUI to ::init to allow popup font customization
254 fl_setpup_fontstyle(FL_NORMAL_STYLE);
255 fl_setpup_fontsize(FL_NORMAL_SIZE);
256 fl_setpup_color(FL_MCOL, FL_BLACK);
257 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
259 // all lyxrc settings has to be done here as lyxrc has not yet
260 // been read when the GUI is created (Jug)
263 if (!lyxrc.custom_export_command.empty())
264 fl_set_input(fd_form_sendto->input_cmd,
265 lyxrc.custom_export_command.c_str());
266 if (lyxrc.custom_export_format == "lyx")
267 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
268 else if (lyxrc.custom_export_format == "tex")
269 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
270 else if (lyxrc.custom_export_format == "dvi")
271 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
272 else if (lyxrc.custom_export_format == "ps")
273 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
274 else if (lyxrc.custom_export_format == "ascii")
275 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
277 // Update parameters.
280 // Initialize the views.
283 // in 0.12 the initialisation of the LyXServer must be done here
284 // 0.13 it should be moved again...
285 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
289 void LyXGUI::create_forms()
291 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
292 lyxViews = new LyXView(width, height);
293 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
295 // From here down should be done by somebody else. (Lgb)
302 string banner_file = LibFileSearch("images", "banner", "xpm");
303 if (lyxrc.show_banner && !banner_file.empty()) {
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 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
309 fl_set_pixmapbutton_file(obj, banner_file.c_str());
311 fl_set_pixmapbutton_focus_outline(obj, 3);
312 fl_set_button_shortcut(obj, "^M ^[", 1);
313 fl_set_object_boxtype(obj, FL_NO_BOX);
314 fl_set_object_callback(obj, TimerCB, 0);
316 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
317 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
318 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
319 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
320 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
321 fl_set_object_lcol(obj, FL_FREE_COL3);
322 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
323 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
327 // the paragraph form
328 fd_form_paragraph = create_form_form_paragraph();
329 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
330 CancelCloseBoxCB, 0);
331 fl_addto_choice(fd_form_paragraph->choice_space_above,
332 _(" None | Defskip | Smallskip "
333 "| Medskip | Bigskip | VFill | Length "));
334 fl_addto_choice(fd_form_paragraph->choice_space_below,
335 _(" None | Defskip | Smallskip "
336 "| Medskip | Bigskip | VFill | Length "));
337 fl_set_input_return(fd_form_paragraph->input_space_above,
339 fl_set_input_return(fd_form_paragraph->input_space_below,
342 // the paragraph extra form
343 fd_form_paragraph_extra = create_form_form_paragraph_extra();
344 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
345 CancelCloseBoxCB, 0);
346 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
348 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
350 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
352 // the character form
353 fd_form_character = create_form_form_character();
354 fl_set_form_atclose(fd_form_character->form_character,
355 CancelCloseBoxCB, 0);
356 fl_addto_choice(fd_form_character->choice_family,
357 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
358 fl_addto_choice(fd_form_character->choice_series,
359 _(" No change %l| Medium | Bold %l| Reset "));
360 fl_addto_choice(fd_form_character->choice_shape,
361 _(" No change %l| Upright | Italic | Slanted | Small Caps "
363 fl_addto_choice(fd_form_character->choice_size,
364 _(" No change %l| Tiny | Smallest | Smaller | Small "
365 "| Normal | Large | Larger | Largest | Huge | Huger "
366 "%l| Increase | Decrease | Reset "));
367 fl_addto_choice(fd_form_character->choice_bar,
368 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
369 fl_addto_choice(fd_form_character->choice_color,
370 _(" No change %l| No color | Black | White | Red | Green "
371 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
372 fl_set_form_minsize(fd_form_character->form_character,
373 fd_form_character->form_character->w,
374 fd_form_character->form_character->h);
375 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
376 fl_addto_form(fd_form_character->form_character);
377 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
378 FL_OBJECT * ob = fd_form_character->choice_language;
379 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
380 combo_language2->shortcut("#L", 1);
382 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
385 fd_form_document = create_form_form_document();
386 fl_set_form_atclose(fd_form_document->form_document,
387 CancelCloseBoxCB, 0);
388 fl_addto_choice(fd_form_document->choice_spacing,
389 _(" Single | OneHalf | Double | Other "));
391 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
392 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
393 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
394 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
395 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
396 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
397 fl_addto_form(fd_form_document->form_document);
398 combo_language = new Combox(FL_COMBOX_DROPLIST);
399 ob = fd_form_document->choice_language;
400 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
401 combo_language->shortcut("#G", 1);
404 // "default" is not part of the languages array any more.
405 combo_language->addto("default");
406 combo_language2->addto(_("No change"));
407 combo_language2->addto(_("Reset"));
408 for(Languages::const_iterator cit = languages.begin();
409 cit != languages.end(); ++cit) {
410 combo_language->addto((*cit).second.lang().c_str());
411 combo_language2->addto((*cit).second.lang().c_str());
413 combo_language2->select_text("No change");
415 // not really necessary, but we can do it anyway.
416 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
418 for (n = 0; tex_fonts[n][0]; ++n) {
419 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
422 fl_addto_choice(fd_form_document->choice_inputenc,
423 "default|auto|latin1|latin2|latin5"
424 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
426 for (n = 0; tex_graphics[n][0]; ++n) {
427 fl_addto_choice(fd_form_document->choice_postscript_driver,
430 // not really necessary, but we can do it anyway.
431 fl_addto_choice(fd_form_document->choice_pagestyle,
432 "default|empty|plain|headings|fancy");
433 fl_addto_choice(fd_form_document->choice_default_skip,
434 _(" Smallskip | Medskip | Bigskip | Length "));
435 fl_set_input_return(fd_form_document->input_default_skip,
437 fl_set_form_minsize(fd_form_document->form_document,
438 fd_form_document->form_document->w,
439 fd_form_document->form_document->h);
440 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
443 fd_form_paper = create_form_form_paper();
444 fl_set_form_atclose(fd_form_paper->form_paper,
445 CancelCloseBoxCB, 0);
446 fl_addto_choice(fd_form_paper->choice_papersize2,
447 _(" Default | Custom | USletter | USlegal "
448 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
449 fl_addto_choice(fd_form_paper->choice_paperpackage,
451 "| A4 small Margins (only portrait) "
452 "| A4 very small Margins (only portrait) "
453 "| A4 very wide margins (only portrait) "));
454 fl_set_input_return(fd_form_paper->input_custom_width,
456 fl_set_input_return(fd_form_paper->input_custom_height,
458 fl_set_input_return(fd_form_paper->input_top_margin,
460 fl_set_input_return(fd_form_paper->input_bottom_margin,
462 fl_set_input_return(fd_form_paper->input_left_margin,
464 fl_set_input_return(fd_form_paper->input_right_margin,
466 fl_set_input_return(fd_form_paper->input_head_height,
468 fl_set_input_return(fd_form_paper->input_head_sep,
470 fl_set_input_return(fd_form_paper->input_foot_skip,
472 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
474 // the table_options form
475 fd_form_table_options = create_form_form_table_options();
476 fl_set_form_atclose(fd_form_table_options->form_table_options,
477 CancelCloseBoxCB, 0);
478 fl_set_input_return(fd_form_table_options->input_column_width,
481 // the table_extra form
482 fd_form_table_extra = create_form_form_table_extra();
483 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
484 CancelCloseBoxCB, 0);
485 fl_set_input_return(fd_form_table_extra->input_special_alignment,
487 fl_set_input_return(fd_form_table_extra->input_special_multialign,
489 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
492 fd_form_quotes = create_form_form_quotes();
493 fl_set_form_atclose(fd_form_quotes->form_quotes,
494 CancelCloseBoxCB, 0);
495 // Is it wrong of me to use « » instead of << >> ? (Lgb)
496 // Maybe if people use a font other than latin1... (JMarc)
497 fl_addto_choice(fd_form_quotes->choice_quotes_language,
498 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
501 fd_form_preamble = create_form_form_preamble();
502 fl_set_form_atclose(fd_form_preamble->form_preamble,
503 CancelCloseBoxCB, 0);
507 fd_form_table = create_form_form_table();
508 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
509 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
510 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
511 fl_set_slider_value(fd_form_table->slider_rows, 5);
512 fl_set_slider_value(fd_form_table->slider_columns, 5);
513 fl_set_slider_precision(fd_form_table->slider_rows, 0);
514 fl_set_slider_precision(fd_form_table->slider_columns, 0);
515 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
519 fd_form_sendto = create_form_form_sendto();
520 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
523 fd_form_figure = create_form_form_figure();
524 fl_set_form_atclose(fd_form_figure->form_figure,
525 CancelCloseBoxCB, 0);
526 fl_set_button(fd_form_figure->radio_postscript, 1);
529 fd_form_screen = create_form_form_screen();
530 fl_set_form_atclose(fd_form_screen->form_screen,
531 CancelCloseBoxCB, 0);
533 // the latex log form
534 fd_latex_log = create_form_LaTeXLog();
535 fl_set_form_atclose(fd_latex_log->LaTeXLog,
536 CancelCloseBoxCB, 0);
538 // Show the main & title form
539 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
540 int title_placement = FL_PLACE_CENTER;
541 // Did we get a valid position?
542 if (xpos>= 0 && ypos>= 0) {
543 lyxViews->setPosition(xpos, ypos);
544 if (lyxrc.show_banner) {
545 // show the title form in the middle of the main form
546 fl_set_form_position(fd_form_title->form_title,
547 abs(xpos + (width/2) - (370 / 2)),
548 abs(ypos + (height/2) - (290 / 2)));
549 title_placement = FL_PLACE_GEOMETRY;
550 // The use of abs() above is a trick to ensure
553 main_placement = FL_PLACE_POSITION;
555 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
556 if (lyxrc.show_banner) {
557 fl_show_form(fd_form_title->form_title,
558 title_placement, FL_NOBORDER,
560 fl_redraw_form(fd_form_title->form_title);
561 fl_raise_form(fd_form_title->form_title);
563 // Show the title form at most 7 secs (lowered from 10 secs)
564 fl_set_timer(fd_form_title->timer_title, 7);
569 void LyXGUI::runTime()
570 /* This will usually be toolkit (GUI) specific. This is
571 * also usually the XEvent dispatcher of the GUI. */
581 kapp->processEvents();
584 Gnome::Main::instance()->iteration(FALSE);
587 if (fl_check_forms() == FL_EVENT) {
588 lyxerr << "LyX: This shouldn't happen..." << endl;
595 void LyXGUI::regBuf(Buffer * b)
597 lyxViews->view()->buffer(b);
600 LyXView * LyXGUI::getLyXView() const