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
24 #include FORMS_H_LOCATION
28 #include "layout_forms.h"
29 #include "print_form.h"
30 #include "tex-strings.h"
32 #include "latexoptions.h"
37 #include "lyxserver.h"
40 #include "lyx_gui_misc.h"
41 #include "lyxlookup.h"
42 #include "bufferlist.h"
44 #include "ColorHandler.h"
46 #ifdef TWO_COLOR_ICONS
47 #include "banner_bw.xbm"
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;
75 extern LyXServer * lyxserver;
76 extern bool finished; // flag, that we are quitting the program
77 extern BufferList bufferlist;
81 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
84 static int width = 690;
85 static int height = 510;
88 static char geometry[40];
89 bool cursor_follows_scrollbar;
94 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
98 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
100 //#warning Please see if you can trigger this!
102 if (!bufferlist.empty())
103 bufferlist.emergencyWriteAll();
105 // Get the reason for the crash.
107 XGetErrorText(display, xeev->error_code, etxt, 512);
108 lyxerr << etxt << endl;
109 // By doing an abort we get a nice backtrace. (hopefully)
111 return 0; // Solaris CC wants us to return something
115 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
116 : _owner(owner), lyxViews(0)
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);
128 static const int geometryBitmask = XParseGeometry( geometry,
131 (unsigned int *) &width,
132 (unsigned int *) &height
135 Display * display = fl_get_display();
137 lyxerr << "LyX: unable to access X display, exiting" << endl;
140 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
141 // X Error handler install goes here
142 XSetErrorHandler(LyX_XErrHandler);
144 // A width less than 590 pops up an awkward main window
145 // The minimal values of width/height (590/400) are defined in
147 if (width < 590) width = 590;
148 if (height < 400) height = 400;
150 // If width is not set by geometry, check it against monitor width
151 if ( !(geometryBitmask & 4) ) {
152 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
153 if (WidthOfScreen(scr) - 8 < width)
154 width = WidthOfScreen(scr) - 8;
157 // If height is not set by geometry, check it against monitor height
158 if ( !(geometryBitmask & 8) ) {
159 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
160 if (HeightOfScreen(scr) - 24 < height)
161 height = HeightOfScreen(scr) - 24;
164 // Recalculate xpos if it's negative
165 if (geometryBitmask & 16)
166 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
168 // Recalculate ypos if it's negative
169 if (geometryBitmask & 32)
170 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
172 // Initialize the LyXColorHandler
173 lyxColorHandler = new LyXColorHandler;
177 // A destructor is always necessary (asierra-970604)
180 // Lyxserver was created in this class so should be destroyed
181 // here. asierra-970604
191 void LyXGUI::setDefaults()
194 cntl.buttonFontSize = FL_NORMAL_SIZE;
195 cntl.browserFontSize = FL_NORMAL_SIZE;
196 cntl.labelFontSize = FL_NORMAL_SIZE;
197 cntl.choiceFontSize = FL_NORMAL_SIZE;
198 cntl.inputFontSize = FL_NORMAL_SIZE;
199 cntl.menuFontSize = FL_NORMAL_SIZE;
200 cntl.borderWidth = -1;
201 cntl.vclass = FL_DefaultVisual;
202 fl_set_defaults(FL_PDVisual
203 | FL_PDButtonFontSize
204 | FL_PDBrowserFontSize
206 | FL_PDChoiceFontSize
209 | FL_PDBorderWidth, &cntl);
213 // This is called after we have parsed lyxrc
221 if (lyxrc.font_norm_menu.empty())
222 lyxrc.font_norm_menu = lyxrc.font_norm;
223 // Set the font name for popups and menus
224 string menufontname = lyxrc.menu_font_name
225 + "-*-*-*-?-*-*-*-*-"
226 + lyxrc.font_norm_menu;
227 // "?" means "scale that font"
228 string popupfontname = lyxrc.popup_font_name
229 + "-*-*-*-?-*-*-*-*-"
230 + lyxrc.font_norm_menu;
232 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
233 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
235 lyxerr << "Could not set menu font to "
236 << menufontname << endl;
239 lyxerr << "Could not set popup font to "
240 << popupfontname << endl;
242 if (bold < 0 && normal < 0) {
243 lyxerr << "Using 'helvetica' font for menus" << endl;
244 bold = fl_set_font_name(FL_BOLD_STYLE,
245 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
246 normal = fl_set_font_name(FL_NORMAL_STYLE,
247 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
248 if (bold < 0 && normal < 0) {
249 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
250 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
254 // put here (after fl_initialize) to avoid segfault. Cannot be done
255 // in setDefaults() (Matthias 140496)
256 // Moved from ::LyXGUI to ::init to allow popup font customization
258 fl_setpup_fontstyle(FL_NORMAL_STYLE);
259 fl_setpup_fontsize(FL_NORMAL_SIZE);
260 fl_setpup_color(FL_MCOL, FL_BLACK);
261 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
263 // all lyxrc settings has to be done here as lyxrc has not yet
264 // been read when the GUI is created (Jug)
267 if (!lyxrc.custom_export_command.empty())
268 fl_set_input(fd_form_sendto->input_cmd,
269 lyxrc.custom_export_command.c_str());
270 if (lyxrc.custom_export_format == "lyx")
271 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
272 else if (lyxrc.custom_export_format == "tex")
273 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
274 else if (lyxrc.custom_export_format == "dvi")
275 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
276 else if (lyxrc.custom_export_format == "ps")
277 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
278 else if (lyxrc.custom_export_format == "ascii")
279 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
281 // Update parameters.
284 // Initialize the views.
287 // in 0.12 the initialisation of the LyXServer must be done here
288 // 0.13 it should be moved again...
289 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
293 void LyXGUI::create_forms()
295 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
296 lyxViews = new LyXView(width, height);
297 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
299 // From here down should be done by somebody else. (Lgb)
306 if (lyxrc.show_banner) {
307 fd_form_title = create_form_form_title();
308 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
309 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
310 fl_addto_form(fd_form_title->form_title);
311 #ifdef TWO_COLOR_ICONS
312 FL_OBJECT *obj = fl_add_bitmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
313 fl_set_bitmapbutton_data(obj, banner_bw_width,
314 banner_bw_height, banner_bw_bits);
315 fl_set_object_color(obj, FL_WHITE, FL_BLACK);
317 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
318 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
320 fl_set_pixmapbutton_focus_outline(obj, 3);
322 fl_set_button_shortcut(obj, "^M ^[", 1);
323 fl_set_object_boxtype(obj, FL_NO_BOX);
324 fl_set_object_callback(obj, TimerCB, 0);
326 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
327 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
328 #ifdef TWO_COLOR_ICONS
329 fl_set_object_color(obj, FL_WHITE, FL_WHITE);
330 fl_set_object_lcol(obj, FL_BLACK);
332 // fl_set_object_color(obj, FL_WHITE, FL_WHITE);
333 // fl_set_object_lcol(obj, FL_BLACK);
334 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
335 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
336 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
337 fl_set_object_lcol(obj, FL_FREE_COL3);
339 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
340 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
344 // the paragraph form
345 fd_form_paragraph = create_form_form_paragraph();
346 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
347 CancelCloseBoxCB, 0);
348 fl_addto_choice(fd_form_paragraph->choice_space_above,
349 _(" None | Defskip | Smallskip "
350 "| Medskip | Bigskip | VFill | Length "));
351 fl_addto_choice(fd_form_paragraph->choice_space_below,
352 _(" None | Defskip | Smallskip "
353 "| Medskip | Bigskip | VFill | Length "));
354 fl_set_input_return(fd_form_paragraph->input_space_above,
356 fl_set_input_return(fd_form_paragraph->input_space_below,
359 // the paragraph extra form
360 fd_form_paragraph_extra = create_form_form_paragraph_extra();
361 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
362 CancelCloseBoxCB, 0);
363 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
365 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
367 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
369 // the character form
370 fd_form_character = create_form_form_character();
371 fl_set_form_atclose(fd_form_character->form_character,
372 CancelCloseBoxCB, 0);
373 fl_addto_choice(fd_form_character->choice_family,
374 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
375 fl_addto_choice(fd_form_character->choice_series,
376 _(" No change %l| Medium | Bold %l| Reset "));
377 fl_addto_choice(fd_form_character->choice_shape,
378 _(" No change %l| Upright | Italic | Slanted | Small Caps "
380 fl_addto_choice(fd_form_character->choice_size,
381 _(" No change %l| Tiny | Smallest | Smaller | Small "
382 "| Normal | Large | Larger | Largest | Huge | Huger "
383 "%l| Increase | Decrease | Reset "));
384 fl_addto_choice(fd_form_character->choice_bar,
385 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
386 fl_addto_choice(fd_form_character->choice_color,
387 _(" No change %l| No color | Black | White | Red | Green "
388 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
389 fl_set_form_minsize(fd_form_character->form_character,
390 fd_form_character->form_character->w,
391 fd_form_character->form_character->h);
392 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
393 fl_addto_form(fd_form_character->form_character);
394 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
395 FL_OBJECT * ob = fd_form_character->choice_language;
396 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
397 combo_language2->shortcut("#L", 1);
399 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
402 fd_form_document = create_form_form_document();
403 fl_set_form_atclose(fd_form_document->form_document,
404 CancelCloseBoxCB, 0);
405 fl_addto_choice(fd_form_document->choice_spacing,
406 _(" Single | OneHalf | Double | Other "));
408 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
409 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
410 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
411 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
412 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
413 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
414 fl_addto_form(fd_form_document->form_document);
415 combo_language = new Combox(FL_COMBOX_DROPLIST);
416 ob = fd_form_document->choice_language;
417 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
418 combo_language->shortcut("#G", 1);
421 // "default" is not part of the languages array any more.
422 combo_language->addto("default");
423 combo_language2->addto(_("No change"));
424 combo_language2->addto(_("Reset"));
425 for(Languages::const_iterator cit = languages.begin();
426 cit != languages.end(); ++cit) {
427 combo_language->addto((*cit).second.lang().c_str());
428 combo_language2->addto((*cit).second.lang().c_str());
430 combo_language2->select_text("No change");
432 // not really necessary, but we can do it anyway.
433 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
435 for (n = 0; tex_fonts[n][0]; ++n) {
436 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
439 fl_addto_choice(fd_form_document->choice_inputenc,
440 "default|auto|latin1|latin2|latin5"
441 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
443 for (n = 0; tex_graphics[n][0]; ++n) {
444 fl_addto_choice(fd_form_document->choice_postscript_driver,
447 // not really necessary, but we can do it anyway.
448 fl_addto_choice(fd_form_document->choice_pagestyle,
449 "default|empty|plain|headings|fancy");
450 fl_addto_choice(fd_form_document->choice_default_skip,
451 _(" Smallskip | Medskip | Bigskip | Length "));
452 fl_set_input_return(fd_form_document->input_default_skip,
454 fl_set_form_minsize(fd_form_document->form_document,
455 fd_form_document->form_document->w,
456 fd_form_document->form_document->h);
457 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
460 fd_form_paper = create_form_form_paper();
461 fl_set_form_atclose(fd_form_paper->form_paper,
462 CancelCloseBoxCB, 0);
463 fl_addto_choice(fd_form_paper->choice_papersize2,
464 _(" Default | Custom | USletter | USlegal "
465 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
466 fl_addto_choice(fd_form_paper->choice_paperpackage,
468 "| A4 small Margins (only portrait) "
469 "| A4 very small Margins (only portrait) "
470 "| A4 very wide margins (only portrait) "));
471 fl_set_input_return(fd_form_paper->input_custom_width,
473 fl_set_input_return(fd_form_paper->input_custom_height,
475 fl_set_input_return(fd_form_paper->input_top_margin,
477 fl_set_input_return(fd_form_paper->input_bottom_margin,
479 fl_set_input_return(fd_form_paper->input_left_margin,
481 fl_set_input_return(fd_form_paper->input_right_margin,
483 fl_set_input_return(fd_form_paper->input_head_height,
485 fl_set_input_return(fd_form_paper->input_head_sep,
487 fl_set_input_return(fd_form_paper->input_foot_skip,
489 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
491 // the table_options form
492 fd_form_table_options = create_form_form_table_options();
493 fl_set_form_atclose(fd_form_table_options->form_table_options,
494 CancelCloseBoxCB, 0);
495 fl_set_input_return(fd_form_table_options->input_column_width,
498 // the table_extra form
499 fd_form_table_extra = create_form_form_table_extra();
500 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
501 CancelCloseBoxCB, 0);
502 fl_set_input_return(fd_form_table_extra->input_special_alignment,
504 fl_set_input_return(fd_form_table_extra->input_special_multialign,
506 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
509 fd_form_quotes = create_form_form_quotes();
510 fl_set_form_atclose(fd_form_quotes->form_quotes,
511 CancelCloseBoxCB, 0);
512 // Is it wrong of me to use « » instead of << >> ? (Lgb)
513 // Maybe if people use a font other than latin1... (JMarc)
514 fl_addto_choice(fd_form_quotes->choice_quotes_language,
515 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
518 fd_form_preamble = create_form_form_preamble();
519 fl_set_form_atclose(fd_form_preamble->form_preamble,
520 CancelCloseBoxCB, 0);
524 fd_form_table = create_form_form_table();
525 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
526 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
527 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
528 fl_set_slider_value(fd_form_table->slider_rows, 5);
529 fl_set_slider_value(fd_form_table->slider_columns, 5);
530 fl_set_slider_precision(fd_form_table->slider_rows, 0);
531 fl_set_slider_precision(fd_form_table->slider_columns, 0);
532 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
536 fd_form_sendto = create_form_form_sendto();
537 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
540 fd_form_figure = create_form_form_figure();
541 fl_set_form_atclose(fd_form_figure->form_figure,
542 CancelCloseBoxCB, 0);
543 fl_set_button(fd_form_figure->radio_postscript, 1);
546 fd_form_screen = create_form_form_screen();
547 fl_set_form_atclose(fd_form_screen->form_screen,
548 CancelCloseBoxCB, 0);
551 fd_form_toc = create_form_form_toc();
552 fl_addto_choice(fd_form_toc->toctype,
553 _(" TOC | LOF | LOT | LOA "));
554 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
557 fd_form_ref = create_form_form_ref();
558 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
559 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
560 fd_form_ref->form_ref->h);
562 // the latex options form
563 fd_latex_options = create_form_LaTeXOptions();
564 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
565 CancelCloseBoxCB, 0);
567 // the latex log form
568 fd_latex_log = create_form_LaTeXLog();
569 fl_set_form_atclose(fd_latex_log->LaTeXLog,
570 CancelCloseBoxCB, 0);
572 // Show the main & title form
573 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
574 int title_placement = FL_PLACE_CENTER;
575 // Did we get a valid position?
576 if (xpos>= 0 && ypos>= 0) {
577 lyxViews->setPosition(xpos, ypos);
578 if (lyxrc.show_banner) {
579 // show the title form in the middle of the main form
580 fl_set_form_position(fd_form_title->form_title,
581 abs(xpos + (width/2) - (370 / 2)),
582 abs(ypos + (height/2) - (290 / 2)));
583 title_placement = FL_PLACE_GEOMETRY;
584 // The use of abs() above is a trick to ensure
587 main_placement = FL_PLACE_POSITION;
589 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
590 if (lyxrc.show_banner) {
591 fl_show_form(fd_form_title->form_title,
592 title_placement, FL_NOBORDER,
594 fl_redraw_form(fd_form_title->form_title);
595 fl_raise_form(fd_form_title->form_title);
597 // Show the title form at most 7 secs (lowered from 10 secs)
598 fl_set_timer(fd_form_title->timer_title, 7);
603 void LyXGUI::runTime()
604 /* This will usually be toolkit (GUI) specific. This is
605 * also usually the XEvent dispatcher of the GUI. */
615 kapp->processEvents();
617 if (fl_check_forms() == FL_EVENT) {
618 lyxerr << "LyX: This shouldn't happen..." << endl;
625 void LyXGUI::regBuf(Buffer * b)
627 lyxViews->view()->buffer(b);
630 LyXView * LyXGUI::getLyXView() const