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 if (width < 590) width = 590;
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 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);
314 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
315 fl_set_pixmapbutton_data(obj, const_cast<char **>(banner));
317 fl_set_pixmapbutton_focus_outline(obj, 3);
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);
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);
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);
336 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
337 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
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,
353 fl_set_input_return(fd_form_paragraph->input_space_below,
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,
362 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
364 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
366 // the character form
367 fd_form_character = create_form_form_character();
368 fl_set_form_atclose(fd_form_character->form_character,
369 CancelCloseBoxCB, 0);
370 fl_addto_choice(fd_form_character->choice_family,
371 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
372 fl_addto_choice(fd_form_character->choice_series,
373 _(" No change %l| Medium | Bold %l| Reset "));
374 fl_addto_choice(fd_form_character->choice_shape,
375 _(" No change %l| Upright | Italic | Slanted | Small Caps "
377 fl_addto_choice(fd_form_character->choice_size,
378 _(" No change %l| Tiny | Smallest | Smaller | Small "
379 "| Normal | Large | Larger | Largest | Huge | Huger "
380 "%l| Increase | Decrease | Reset "));
381 fl_addto_choice(fd_form_character->choice_bar,
382 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
383 fl_addto_choice(fd_form_character->choice_color,
384 _(" No change %l| No color | Black | White | Red | Green "
385 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
386 fl_set_form_minsize(fd_form_character->form_character,
387 fd_form_character->form_character->w,
388 fd_form_character->form_character->h);
389 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
390 fl_addto_form(fd_form_character->form_character);
391 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
392 FL_OBJECT * ob = fd_form_character->choice_language;
393 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
394 combo_language2->shortcut("#L", 1);
396 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
399 fd_form_document = create_form_form_document();
400 fl_set_form_atclose(fd_form_document->form_document,
401 CancelCloseBoxCB, 0);
402 fl_addto_choice(fd_form_document->choice_spacing,
403 _(" Single | OneHalf | Double | Other "));
405 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
406 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
407 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
408 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
409 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
410 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
411 fl_addto_form(fd_form_document->form_document);
412 combo_language = new Combox(FL_COMBOX_DROPLIST);
413 ob = fd_form_document->choice_language;
414 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
415 combo_language->shortcut("#G", 1);
418 // "default" is not part of the languages array any more.
419 combo_language->addto("default");
420 combo_language2->addto(_("No change"));
421 combo_language2->addto(_("Reset"));
422 for(Languages::const_iterator cit = languages.begin();
423 cit != languages.end(); ++cit) {
424 combo_language->addto((*cit).second.lang().c_str());
425 combo_language2->addto((*cit).second.lang().c_str());
427 combo_language2->select_text("No change");
429 // not really necessary, but we can do it anyway.
430 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
432 for (n = 0; tex_fonts[n][0]; ++n) {
433 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
436 fl_addto_choice(fd_form_document->choice_inputenc,
437 "default|auto|latin1|latin2|latin5"
438 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
440 for (n = 0; tex_graphics[n][0]; ++n) {
441 fl_addto_choice(fd_form_document->choice_postscript_driver,
444 // not really necessary, but we can do it anyway.
445 fl_addto_choice(fd_form_document->choice_pagestyle,
446 "default|empty|plain|headings|fancy");
447 fl_addto_choice(fd_form_document->choice_default_skip,
448 _(" Smallskip | Medskip | Bigskip | Length "));
449 fl_set_input_return(fd_form_document->input_default_skip,
451 fl_set_form_minsize(fd_form_document->form_document,
452 fd_form_document->form_document->w,
453 fd_form_document->form_document->h);
454 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
457 fd_form_paper = create_form_form_paper();
458 fl_set_form_atclose(fd_form_paper->form_paper,
459 CancelCloseBoxCB, 0);
460 fl_addto_choice(fd_form_paper->choice_papersize2,
461 _(" Default | Custom | USletter | USlegal "
462 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
463 fl_addto_choice(fd_form_paper->choice_paperpackage,
465 "| A4 small Margins (only portrait) "
466 "| A4 very small Margins (only portrait) "
467 "| A4 very wide margins (only portrait) "));
468 fl_set_input_return(fd_form_paper->input_custom_width,
470 fl_set_input_return(fd_form_paper->input_custom_height,
472 fl_set_input_return(fd_form_paper->input_top_margin,
474 fl_set_input_return(fd_form_paper->input_bottom_margin,
476 fl_set_input_return(fd_form_paper->input_left_margin,
478 fl_set_input_return(fd_form_paper->input_right_margin,
480 fl_set_input_return(fd_form_paper->input_head_height,
482 fl_set_input_return(fd_form_paper->input_head_sep,
484 fl_set_input_return(fd_form_paper->input_foot_skip,
486 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
488 // the table_options form
489 fd_form_table_options = create_form_form_table_options();
490 fl_set_form_atclose(fd_form_table_options->form_table_options,
491 CancelCloseBoxCB, 0);
492 fl_set_input_return(fd_form_table_options->input_column_width,
495 // the table_extra form
496 fd_form_table_extra = create_form_form_table_extra();
497 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
498 CancelCloseBoxCB, 0);
499 fl_set_input_return(fd_form_table_extra->input_special_alignment,
501 fl_set_input_return(fd_form_table_extra->input_special_multialign,
503 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
506 fd_form_quotes = create_form_form_quotes();
507 fl_set_form_atclose(fd_form_quotes->form_quotes,
508 CancelCloseBoxCB, 0);
509 // Is it wrong of me to use « » instead of << >> ? (Lgb)
510 // Maybe if people use a font other than latin1... (JMarc)
511 fl_addto_choice(fd_form_quotes->choice_quotes_language,
512 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
515 fd_form_preamble = create_form_form_preamble();
516 fl_set_form_atclose(fd_form_preamble->form_preamble,
517 CancelCloseBoxCB, 0);
520 fd_form_table = create_form_form_table();
521 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
522 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
523 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
524 fl_set_slider_value(fd_form_table->slider_rows, 5);
525 fl_set_slider_value(fd_form_table->slider_columns, 5);
526 fl_set_slider_precision(fd_form_table->slider_rows, 0);
527 fl_set_slider_precision(fd_form_table->slider_columns, 0);
528 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
531 fd_form_sendto = create_form_form_sendto();
532 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
535 fd_form_figure = create_form_form_figure();
536 fl_set_form_atclose(fd_form_figure->form_figure,
537 CancelCloseBoxCB, 0);
538 fl_set_button(fd_form_figure->radio_postscript, 1);
541 fd_form_screen = create_form_form_screen();
542 fl_set_form_atclose(fd_form_screen->form_screen,
543 CancelCloseBoxCB, 0);
546 fd_form_toc = create_form_form_toc();
547 fl_addto_choice(fd_form_toc->toctype,
548 _(" TOC | LOF | LOT | LOA "));
549 fl_set_form_atclose(fd_form_toc->form_toc, CancelCloseBoxCB, 0);
552 fd_form_ref = create_form_form_ref();
553 fl_set_form_atclose(fd_form_ref->form_ref, CancelCloseBoxCB, 0);
554 fl_set_form_minsize(fd_form_ref->form_ref, fd_form_ref->form_ref->w,
555 fd_form_ref->form_ref->h);
557 // the latex options form
558 fd_latex_options = create_form_LaTeXOptions();
559 fl_set_form_atclose(fd_latex_options->LaTeXOptions,
560 CancelCloseBoxCB, 0);
562 // the latex log form
563 fd_latex_log = create_form_LaTeXLog();
564 fl_set_form_atclose(fd_latex_log->LaTeXLog,
565 CancelCloseBoxCB, 0);
567 // Show the main & title form
568 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
569 int title_placement = FL_PLACE_CENTER;
570 // Did we get a valid position?
571 if (xpos>= 0 && ypos>= 0) {
572 lyxViews->setPosition(xpos, ypos);
573 if (lyxrc.show_banner) {
574 // show the title form in the middle of the main form
575 fl_set_form_position(fd_form_title->form_title,
576 abs(xpos + (width/2) - (370 / 2)),
577 abs(ypos + (height/2) - (290 / 2)));
578 title_placement = FL_PLACE_GEOMETRY;
579 // The use of abs() above is a trick to ensure
582 main_placement = FL_PLACE_POSITION;
584 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
585 if (lyxrc.show_banner) {
586 fl_show_form(fd_form_title->form_title,
587 title_placement, FL_NOBORDER,
589 fl_redraw_form(fd_form_title->form_title);
590 fl_raise_form(fd_form_title->form_title);
592 // Show the title form at most 7 secs (lowered from 10 secs)
593 fl_set_timer(fd_form_title->timer_title, 7);
598 void LyXGUI::runTime()
599 /* This will usually be toolkit (GUI) specific. This is
600 * also usually the XEvent dispatcher of the GUI. */
610 kapp->processEvents();
612 if (fl_check_forms() == FL_EVENT) {
613 lyxerr << "LyX: This shouldn't happen..." << endl;
620 void LyXGUI::regBuf(Buffer * b)
622 lyxViews->view()->buffer(b);
625 LyXView * LyXGUI::getLyXView() const