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
20 #include FORMS_H_LOCATION
21 #include "support/filetools.h"
25 #include "layout_forms.h"
26 #include "print_form.h"
27 #include "tex-strings.h"
34 #include "lyxserver.h"
37 #include "lyx_gui_misc.h"
38 #include "lyxlookup.h"
39 #include "bufferlist.h"
41 #include "ColorHandler.h"
42 #include "frontends/GUIRunTime.h"
46 FD_form_title * fd_form_title;
47 FD_form_paragraph * fd_form_paragraph;
48 FD_form_paragraph_extra * fd_form_paragraph_extra;
49 FD_form_character * fd_form_character;
50 FD_form_document * fd_form_document;
51 FD_form_paper * fd_form_paper;
52 FD_form_table_options * fd_form_table_options;
53 FD_form_table_extra * fd_form_table_extra;
54 FD_form_quotes * fd_form_quotes;
55 FD_form_preamble * fd_form_preamble;
56 FD_form_table * fd_form_table;
57 FD_form_sendto * fd_form_sendto;
58 FD_form_figure * fd_form_figure;
59 FD_LaTeXLog * fd_latex_log; // from log_form.h
60 Combox * combo_language;
61 Combox * combo_language2;
63 extern LyXServer * lyxserver;
64 extern bool finished; // flag, that we are quitting the program
65 extern BufferList bufferlist;
69 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
72 static int width = 690;
73 static int height = 510;
76 static char geometry[40];
77 bool cursor_follows_scrollbar;
82 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
86 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
88 //#warning Please see if you can trigger this!
90 if (!bufferlist.empty())
91 bufferlist.emergencyWriteAll();
93 // Get the reason for the crash.
95 XGetErrorText(display, xeev->error_code, etxt, 512);
96 lyxerr << etxt << endl;
97 // By doing an abort we get a nice backtrace. (hopefully)
99 return 0; // Solaris CC wants us to return something
103 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
104 : _owner(owner), lyxViews(0)
112 static const int num_res = sizeof(res)/sizeof(FL_resource);
113 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
114 fl_get_app_resources(res, num_res);
116 static const int geometryBitmask = XParseGeometry( geometry,
119 (unsigned int *) &width,
120 (unsigned int *) &height
123 Display * display = fl_get_display();
125 lyxerr << "LyX: unable to access X display, exiting" << endl;
128 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
129 // X Error handler install goes here
130 XSetErrorHandler(LyX_XErrHandler);
132 // A width less than 590 pops up an awkward main window
133 // The minimal values of width/height (590/400) are defined in
135 if (width < 590) width = 590;
136 if (height < 400) height = 400;
138 // If width is not set by geometry, check it against monitor width
139 if ( !(geometryBitmask & 4) ) {
140 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
141 if (WidthOfScreen(scr) - 8 < width)
142 width = WidthOfScreen(scr) - 8;
145 // If height is not set by geometry, check it against monitor height
146 if ( !(geometryBitmask & 8) ) {
147 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
148 if (HeightOfScreen(scr) - 24 < height)
149 height = HeightOfScreen(scr) - 24;
152 // Recalculate xpos if it's negative
153 if (geometryBitmask & 16)
154 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
156 // Recalculate ypos if it's negative
157 if (geometryBitmask & 32)
158 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
160 // Initialize the LyXColorHandler
161 lyxColorHandler = new LyXColorHandler;
165 // A destructor is always necessary (asierra-970604)
168 // Lyxserver was created in this class so should be destroyed
169 // here. asierra-970604
179 void LyXGUI::setDefaults()
182 cntl.buttonFontSize = FL_NORMAL_SIZE;
183 cntl.browserFontSize = FL_NORMAL_SIZE;
184 cntl.labelFontSize = FL_NORMAL_SIZE;
185 cntl.choiceFontSize = FL_NORMAL_SIZE;
186 cntl.inputFontSize = FL_NORMAL_SIZE;
187 cntl.menuFontSize = FL_NORMAL_SIZE;
188 cntl.borderWidth = -1;
189 cntl.vclass = FL_DefaultVisual;
190 fl_set_defaults(FL_PDVisual
191 | FL_PDButtonFontSize
192 | FL_PDBrowserFontSize
194 | FL_PDChoiceFontSize
197 | FL_PDBorderWidth, &cntl);
201 // This is called after we have parsed lyxrc
209 if (lyxrc.font_norm_menu.empty())
210 lyxrc.font_norm_menu = lyxrc.font_norm;
211 // Set the font name for popups and menus
212 string menufontname = lyxrc.menu_font_name
213 + "-*-*-*-?-*-*-*-*-"
214 + lyxrc.font_norm_menu;
215 // "?" means "scale that font"
216 string popupfontname = lyxrc.popup_font_name
217 + "-*-*-*-?-*-*-*-*-"
218 + lyxrc.font_norm_menu;
220 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
221 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
223 lyxerr << "Could not set menu font to "
224 << menufontname << endl;
227 lyxerr << "Could not set popup font to "
228 << popupfontname << endl;
230 if (bold < 0 && normal < 0) {
231 lyxerr << "Using 'helvetica' font for menus" << endl;
232 bold = fl_set_font_name(FL_BOLD_STYLE,
233 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
234 normal = fl_set_font_name(FL_NORMAL_STYLE,
235 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
236 if (bold < 0 && normal < 0) {
237 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
238 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
242 // put here (after fl_initialize) to avoid segfault. Cannot be done
243 // in setDefaults() (Matthias 140496)
244 // Moved from ::LyXGUI to ::init to allow popup font customization
246 fl_setpup_fontstyle(FL_NORMAL_STYLE);
247 fl_setpup_fontsize(FL_NORMAL_SIZE);
248 fl_setpup_color(FL_MCOL, FL_BLACK);
249 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
251 // all lyxrc settings has to be done here as lyxrc has not yet
252 // been read when the GUI is created (Jug)
255 if (!lyxrc.custom_export_command.empty())
256 fl_set_input(fd_form_sendto->input_cmd,
257 lyxrc.custom_export_command.c_str());
258 if (lyxrc.custom_export_format == "lyx")
259 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
260 else if (lyxrc.custom_export_format == "tex")
261 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
262 else if (lyxrc.custom_export_format == "dvi")
263 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
264 else if (lyxrc.custom_export_format == "ps")
265 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
266 else if (lyxrc.custom_export_format == "ascii")
267 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
269 // Update parameters.
272 // Initialize the views.
275 // in 0.12 the initialisation of the LyXServer must be done here
276 // 0.13 it should be moved again...
277 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
281 void LyXGUI::create_forms()
283 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
284 lyxViews = new LyXView(width, height);
285 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
287 // From here down should be done by somebody else. (Lgb)
294 string banner_file = LibFileSearch("images", "banner", "xpm");
295 if (lyxrc.show_banner && !banner_file.empty()) {
296 fd_form_title = create_form_form_title();
297 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
298 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
299 fl_addto_form(fd_form_title->form_title);
300 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
301 fl_set_pixmapbutton_file(obj, banner_file.c_str());
303 fl_set_pixmapbutton_focus_outline(obj, 3);
304 fl_set_button_shortcut(obj, "^M ^[", 1);
305 fl_set_object_boxtype(obj, FL_NO_BOX);
306 fl_set_object_callback(obj, TimerCB, 0);
308 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
309 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
310 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
311 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
312 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
313 fl_set_object_lcol(obj, FL_FREE_COL3);
314 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
315 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
319 // the paragraph form
320 fd_form_paragraph = create_form_form_paragraph();
321 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
322 CancelCloseBoxCB, 0);
323 fl_addto_choice(fd_form_paragraph->choice_space_above,
324 _(" None | Defskip | Smallskip "
325 "| Medskip | Bigskip | VFill | Length "));
326 fl_addto_choice(fd_form_paragraph->choice_space_below,
327 _(" None | Defskip | Smallskip "
328 "| Medskip | Bigskip | VFill | Length "));
329 fl_set_input_return(fd_form_paragraph->input_space_above,
331 fl_set_input_return(fd_form_paragraph->input_space_below,
334 // the paragraph extra form
335 fd_form_paragraph_extra = create_form_form_paragraph_extra();
336 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
337 CancelCloseBoxCB, 0);
338 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
340 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
342 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
344 // the character form
345 fd_form_character = create_form_form_character();
346 fl_set_form_atclose(fd_form_character->form_character,
347 CancelCloseBoxCB, 0);
348 fl_addto_choice(fd_form_character->choice_family,
349 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
350 fl_addto_choice(fd_form_character->choice_series,
351 _(" No change %l| Medium | Bold %l| Reset "));
352 fl_addto_choice(fd_form_character->choice_shape,
353 _(" No change %l| Upright | Italic | Slanted | Small Caps "
355 fl_addto_choice(fd_form_character->choice_size,
356 _(" No change %l| Tiny | Smallest | Smaller | Small "
357 "| Normal | Large | Larger | Largest | Huge | Huger "
358 "%l| Increase | Decrease | Reset "));
359 fl_addto_choice(fd_form_character->choice_bar,
360 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
361 fl_addto_choice(fd_form_character->choice_color,
362 _(" No change %l| No color | Black | White | Red | Green "
363 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
364 fl_set_form_minsize(fd_form_character->form_character,
365 fd_form_character->form_character->w,
366 fd_form_character->form_character->h);
367 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
368 fl_addto_form(fd_form_character->form_character);
369 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
370 FL_OBJECT * ob = fd_form_character->choice_language;
371 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
372 combo_language2->shortcut("#L", 1);
374 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
377 fd_form_document = create_form_form_document();
378 fl_set_form_atclose(fd_form_document->form_document,
379 CancelCloseBoxCB, 0);
380 fl_addto_choice(fd_form_document->choice_spacing,
381 _(" Single | OneHalf | Double | Other "));
383 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
384 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
385 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
386 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
387 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
388 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
389 fl_addto_form(fd_form_document->form_document);
390 combo_language = new Combox(FL_COMBOX_DROPLIST);
391 ob = fd_form_document->choice_language;
392 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
393 combo_language->shortcut("#G", 1);
396 // "default" is not part of the languages array any more.
397 combo_language->addto("default");
398 combo_language2->addto(_("No change"));
399 combo_language2->addto(_("Reset"));
400 for(Languages::const_iterator cit = languages.begin();
401 cit != languages.end(); ++cit) {
402 combo_language->addto((*cit).second.lang().c_str());
403 combo_language2->addto((*cit).second.lang().c_str());
405 combo_language2->select_text("No change");
407 // not really necessary, but we can do it anyway.
408 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
410 for (n = 0; tex_fonts[n][0]; ++n) {
411 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
414 fl_addto_choice(fd_form_document->choice_inputenc,
415 "default|auto|latin1|latin2|latin5"
416 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
418 for (n = 0; tex_graphics[n][0]; ++n) {
419 fl_addto_choice(fd_form_document->choice_postscript_driver,
422 // not really necessary, but we can do it anyway.
423 fl_addto_choice(fd_form_document->choice_pagestyle,
424 "default|empty|plain|headings|fancy");
425 fl_addto_choice(fd_form_document->choice_default_skip,
426 _(" Smallskip | Medskip | Bigskip | Length "));
427 fl_set_input_return(fd_form_document->input_default_skip,
429 fl_set_form_minsize(fd_form_document->form_document,
430 fd_form_document->form_document->w,
431 fd_form_document->form_document->h);
432 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
435 fd_form_paper = create_form_form_paper();
436 fl_set_form_atclose(fd_form_paper->form_paper,
437 CancelCloseBoxCB, 0);
438 fl_addto_choice(fd_form_paper->choice_papersize2,
439 _(" Default | Custom | USletter | USlegal "
440 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
441 fl_addto_choice(fd_form_paper->choice_paperpackage,
443 "| A4 small Margins (only portrait) "
444 "| A4 very small Margins (only portrait) "
445 "| A4 very wide margins (only portrait) "));
446 fl_set_input_return(fd_form_paper->input_custom_width,
448 fl_set_input_return(fd_form_paper->input_custom_height,
450 fl_set_input_return(fd_form_paper->input_top_margin,
452 fl_set_input_return(fd_form_paper->input_bottom_margin,
454 fl_set_input_return(fd_form_paper->input_left_margin,
456 fl_set_input_return(fd_form_paper->input_right_margin,
458 fl_set_input_return(fd_form_paper->input_head_height,
460 fl_set_input_return(fd_form_paper->input_head_sep,
462 fl_set_input_return(fd_form_paper->input_foot_skip,
464 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
466 // the table_options form
467 fd_form_table_options = create_form_form_table_options();
468 fl_set_form_atclose(fd_form_table_options->form_table_options,
469 CancelCloseBoxCB, 0);
470 fl_set_input_return(fd_form_table_options->input_column_width,
473 // the table_extra form
474 fd_form_table_extra = create_form_form_table_extra();
475 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
476 CancelCloseBoxCB, 0);
477 fl_set_input_return(fd_form_table_extra->input_special_alignment,
479 fl_set_input_return(fd_form_table_extra->input_special_multialign,
481 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
484 fd_form_quotes = create_form_form_quotes();
485 fl_set_form_atclose(fd_form_quotes->form_quotes,
486 CancelCloseBoxCB, 0);
487 // Is it wrong of me to use « » instead of << >> ? (Lgb)
488 // Maybe if people use a font other than latin1... (JMarc)
489 fl_addto_choice(fd_form_quotes->choice_quotes_language,
490 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
493 fd_form_preamble = create_form_form_preamble();
494 fl_set_form_atclose(fd_form_preamble->form_preamble,
495 CancelCloseBoxCB, 0);
499 fd_form_table = create_form_form_table();
500 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
501 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
502 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
503 fl_set_slider_value(fd_form_table->slider_rows, 5);
504 fl_set_slider_value(fd_form_table->slider_columns, 5);
505 fl_set_slider_precision(fd_form_table->slider_rows, 0);
506 fl_set_slider_precision(fd_form_table->slider_columns, 0);
507 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
511 fd_form_sendto = create_form_form_sendto();
512 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
515 fd_form_figure = create_form_form_figure();
516 fl_set_form_atclose(fd_form_figure->form_figure,
517 CancelCloseBoxCB, 0);
518 fl_set_button(fd_form_figure->radio_postscript, 1);
520 // the latex log form
521 fd_latex_log = create_form_LaTeXLog();
522 fl_set_form_atclose(fd_latex_log->LaTeXLog,
523 CancelCloseBoxCB, 0);
525 // Show the main & title form
526 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
527 int title_placement = FL_PLACE_CENTER;
528 // Did we get a valid position?
529 if (xpos>= 0 && ypos>= 0) {
530 lyxViews->setPosition(xpos, ypos);
531 if (lyxrc.show_banner) {
532 // show the title form in the middle of the main form
533 fl_set_form_position(fd_form_title->form_title,
534 abs(xpos + (width/2) - (370 / 2)),
535 abs(ypos + (height/2) - (290 / 2)));
536 title_placement = FL_PLACE_GEOMETRY;
537 // The use of abs() above is a trick to ensure
540 main_placement = FL_PLACE_POSITION;
542 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
543 if (lyxrc.show_banner) {
544 fl_show_form(fd_form_title->form_title,
545 title_placement, FL_NOBORDER,
547 fl_redraw_form(fd_form_title->form_title);
548 fl_raise_form(fd_form_title->form_title);
550 // Show the title form at most 7 secs (lowered from 10 secs)
551 fl_set_timer(fd_form_title->timer_title, 7);
556 void LyXGUI::runTime()
557 /* This will usually be toolkit (GUI) specific. This is
558 * also usually the XEvent dispatcher of the GUI. */
570 // for now we have to leave this here then if the GUII is
571 // completed this obviously has to be removed! (Jug)
572 if (fl_check_forms() == FL_EVENT) {
573 lyxerr << "LyX: This shouldn't happen..." << endl;
580 void LyXGUI::regBuf(Buffer * b)
582 lyxViews->view()->buffer(b);
585 LyXView * LyXGUI::getLyXView() const