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}
87 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
89 //#warning Please see if you can trigger this!
91 if (!bufferlist.empty())
92 bufferlist.emergencyWriteAll();
94 // Get the reason for the crash.
96 XGetErrorText(display, xeev->error_code, etxt, 512);
97 lyxerr << etxt << endl;
98 // By doing an abort we get a nice backtrace. (hopefully)
100 return 0; // Solaris CC wants us to return something
104 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
105 : _owner(owner), lyxViews(0)
113 static const int num_res = sizeof(res)/sizeof(FL_resource);
114 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
115 fl_get_app_resources(res, num_res);
117 static const int geometryBitmask =
118 XParseGeometry( geometry,
121 reinterpret_cast<unsigned int *>(&width),
122 reinterpret_cast<unsigned int *>(&height));
124 Display * display = fl_get_display();
126 lyxerr << "LyX: unable to access X display, exiting" << endl;
129 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
130 // X Error handler install goes here
131 XSetErrorHandler(LyX_XErrHandler);
133 // A width less than 590 pops up an awkward main window
134 // The minimal values of width/height (590/400) are defined in
136 if (width < 590) width = 590;
137 if (height < 400) height = 400;
139 // If width is not set by geometry, check it against monitor width
140 if ( !(geometryBitmask & 4) ) {
141 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
142 if (WidthOfScreen(scr) - 8 < width)
143 width = WidthOfScreen(scr) - 8;
146 // If height is not set by geometry, check it against monitor height
147 if ( !(geometryBitmask & 8) ) {
148 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
149 if (HeightOfScreen(scr) - 24 < height)
150 height = HeightOfScreen(scr) - 24;
153 // Recalculate xpos if it's negative
154 if (geometryBitmask & 16)
155 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
157 // Recalculate ypos if it's negative
158 if (geometryBitmask & 32)
159 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
161 // Initialize the LyXColorHandler
162 lyxColorHandler = new LyXColorHandler;
166 // A destructor is always necessary (asierra-970604)
169 // Lyxserver was created in this class so should be destroyed
170 // here. asierra-970604
180 void LyXGUI::setDefaults()
183 cntl.buttonFontSize = FL_NORMAL_SIZE;
184 cntl.browserFontSize = FL_NORMAL_SIZE;
185 cntl.labelFontSize = FL_NORMAL_SIZE;
186 cntl.choiceFontSize = FL_NORMAL_SIZE;
187 cntl.inputFontSize = FL_NORMAL_SIZE;
188 cntl.menuFontSize = FL_NORMAL_SIZE;
189 cntl.borderWidth = -1;
190 cntl.vclass = FL_DefaultVisual;
191 fl_set_defaults(FL_PDVisual
192 | FL_PDButtonFontSize
193 | FL_PDBrowserFontSize
195 | FL_PDChoiceFontSize
198 | FL_PDBorderWidth, &cntl);
202 // This is called after we have parsed lyxrc
210 if (lyxrc.font_norm_menu.empty())
211 lyxrc.font_norm_menu = lyxrc.font_norm;
212 // Set the font name for popups and menus
213 string menufontname = lyxrc.menu_font_name
214 + "-*-*-*-?-*-*-*-*-"
215 + lyxrc.font_norm_menu;
216 // "?" means "scale that font"
217 string popupfontname = lyxrc.popup_font_name
218 + "-*-*-*-?-*-*-*-*-"
219 + lyxrc.font_norm_menu;
221 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
222 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
224 lyxerr << "Could not set menu font to "
225 << menufontname << endl;
228 lyxerr << "Could not set popup font to "
229 << popupfontname << endl;
231 if (bold < 0 && normal < 0) {
232 lyxerr << "Using 'helvetica' font for menus" << endl;
233 bold = fl_set_font_name(FL_BOLD_STYLE,
234 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
235 normal = fl_set_font_name(FL_NORMAL_STYLE,
236 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
237 if (bold < 0 && normal < 0) {
238 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
239 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
243 // put here (after fl_initialize) to avoid segfault. Cannot be done
244 // in setDefaults() (Matthias 140496)
245 // Moved from ::LyXGUI to ::init to allow popup font customization
247 fl_setpup_fontstyle(FL_NORMAL_STYLE);
248 fl_setpup_fontsize(FL_NORMAL_SIZE);
249 fl_setpup_color(FL_MCOL, FL_BLACK);
250 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
252 // all lyxrc settings has to be done here as lyxrc has not yet
253 // been read when the GUI is created (Jug)
256 if (!lyxrc.custom_export_command.empty())
257 fl_set_input(fd_form_sendto->input_cmd,
258 lyxrc.custom_export_command.c_str());
259 if (lyxrc.custom_export_format == "lyx")
260 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
261 else if (lyxrc.custom_export_format == "tex")
262 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
263 else if (lyxrc.custom_export_format == "dvi")
264 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
265 else if (lyxrc.custom_export_format == "ps")
266 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
267 else if (lyxrc.custom_export_format == "ascii")
268 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
270 // Update parameters.
273 // Initialize the views.
276 // in 0.12 the initialisation of the LyXServer must be done here
277 // 0.13 it should be moved again...
278 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
282 void LyXGUI::create_forms()
284 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
285 lyxViews = new LyXView(width, height);
286 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
288 // From here down should be done by somebody else. (Lgb)
295 string banner_file = LibFileSearch("images", "banner", "xpm");
296 if (lyxrc.show_banner && !banner_file.empty()) {
297 fd_form_title = create_form_form_title();
298 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
299 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
300 fl_addto_form(fd_form_title->form_title);
301 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
302 fl_set_pixmapbutton_file(obj, banner_file.c_str());
304 fl_set_pixmapbutton_focus_outline(obj, 3);
305 fl_set_button_shortcut(obj, "^M ^[", 1);
306 fl_set_object_boxtype(obj, FL_NO_BOX);
307 fl_set_object_callback(obj, TimerCB, 0);
309 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
310 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
311 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
312 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
313 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
314 fl_set_object_lcol(obj, FL_FREE_COL3);
315 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
316 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
320 // the paragraph form
321 fd_form_paragraph = create_form_form_paragraph();
322 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
323 CancelCloseBoxCB, 0);
324 fl_addto_choice(fd_form_paragraph->choice_space_above,
325 _(" None | Defskip | Smallskip "
326 "| Medskip | Bigskip | VFill | Length "));
327 fl_addto_choice(fd_form_paragraph->choice_space_below,
328 _(" None | Defskip | Smallskip "
329 "| Medskip | Bigskip | VFill | Length "));
330 fl_set_input_return(fd_form_paragraph->input_space_above,
332 fl_set_input_return(fd_form_paragraph->input_space_below,
335 // the paragraph extra form
336 fd_form_paragraph_extra = create_form_form_paragraph_extra();
337 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
338 CancelCloseBoxCB, 0);
339 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
341 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
343 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
345 // the character form
346 fd_form_character = create_form_form_character();
347 fl_set_form_atclose(fd_form_character->form_character,
348 CancelCloseBoxCB, 0);
349 fl_addto_choice(fd_form_character->choice_family,
350 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
351 fl_addto_choice(fd_form_character->choice_series,
352 _(" No change %l| Medium | Bold %l| Reset "));
353 fl_addto_choice(fd_form_character->choice_shape,
354 _(" No change %l| Upright | Italic | Slanted | Small Caps "
356 fl_addto_choice(fd_form_character->choice_size,
357 _(" No change %l| Tiny | Smallest | Smaller | Small "
358 "| Normal | Large | Larger | Largest | Huge | Huger "
359 "%l| Increase | Decrease | Reset "));
360 fl_addto_choice(fd_form_character->choice_bar,
361 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
362 fl_addto_choice(fd_form_character->choice_color,
363 _(" No change %l| No color | Black | White | Red | Green "
364 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
365 fl_set_form_minsize(fd_form_character->form_character,
366 fd_form_character->form_character->w,
367 fd_form_character->form_character->h);
368 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
369 fl_addto_form(fd_form_character->form_character);
370 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
371 FL_OBJECT * ob = fd_form_character->choice_language;
372 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
373 combo_language2->shortcut("#L", 1);
375 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
377 #ifdef USE_OLD_DOCUMENT_LAYOUT
379 fd_form_document = create_form_form_document();
380 fl_set_form_atclose(fd_form_document->form_document,
381 CancelCloseBoxCB, 0);
382 fl_addto_choice(fd_form_document->choice_spacing,
383 _(" Single | OneHalf | Double | Other "));
385 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
386 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
387 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
388 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
389 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
390 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
391 fl_addto_form(fd_form_document->form_document);
392 combo_language = new Combox(FL_COMBOX_DROPLIST);
393 ob = fd_form_document->choice_language;
394 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
395 combo_language->shortcut("#G", 1);
398 // "default" is not part of the languages array any more.
399 combo_language->addto("default");
400 combo_language2->addto(_("No change"));
401 combo_language2->addto(_("Reset"));
402 for(Languages::const_iterator cit = languages.begin();
403 cit != languages.end(); ++cit) {
404 combo_language->addto((*cit).second.lang().c_str());
405 combo_language2->addto((*cit).second.lang().c_str());
407 combo_language2->select_text(_("No change"));
409 // not really necessary, but we can do it anyway.
410 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
412 for (n = 0; tex_fonts[n][0]; ++n) {
413 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
416 fl_addto_choice(fd_form_document->choice_inputenc,
417 "default|auto|latin1|latin2|latin5"
418 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
420 for (n = 0; tex_graphics[n][0]; ++n) {
421 fl_addto_choice(fd_form_document->choice_postscript_driver,
424 // not really necessary, but we can do it anyway.
425 fl_addto_choice(fd_form_document->choice_pagestyle,
426 "default|empty|plain|headings|fancy");
427 fl_addto_choice(fd_form_document->choice_default_skip,
428 _(" Smallskip | Medskip | Bigskip | Length "));
429 fl_set_input_return(fd_form_document->input_default_skip,
431 fl_set_form_minsize(fd_form_document->form_document,
432 fd_form_document->form_document->w,
433 fd_form_document->form_document->h);
434 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
437 fd_form_paper = create_form_form_paper();
438 fl_set_form_atclose(fd_form_paper->form_paper,
439 CancelCloseBoxCB, 0);
440 fl_addto_choice(fd_form_paper->choice_papersize2,
441 _(" Default | Custom | USletter | USlegal "
442 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
443 fl_addto_choice(fd_form_paper->choice_paperpackage,
445 "| A4 small Margins (only portrait) "
446 "| A4 very small Margins (only portrait) "
447 "| A4 very wide margins (only portrait) "));
448 fl_set_input_return(fd_form_paper->input_custom_width,
450 fl_set_input_return(fd_form_paper->input_custom_height,
452 fl_set_input_return(fd_form_paper->input_top_margin,
454 fl_set_input_return(fd_form_paper->input_bottom_margin,
456 fl_set_input_return(fd_form_paper->input_left_margin,
458 fl_set_input_return(fd_form_paper->input_right_margin,
460 fl_set_input_return(fd_form_paper->input_head_height,
462 fl_set_input_return(fd_form_paper->input_head_sep,
464 fl_set_input_return(fd_form_paper->input_foot_skip,
466 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
470 // the table_options form
471 fd_form_table_options = create_form_form_table_options();
472 fl_set_form_atclose(fd_form_table_options->form_table_options,
473 CancelCloseBoxCB, 0);
474 fl_set_input_return(fd_form_table_options->input_column_width,
477 // the table_extra form
478 fd_form_table_extra = create_form_form_table_extra();
479 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
480 CancelCloseBoxCB, 0);
481 fl_set_input_return(fd_form_table_extra->input_special_alignment,
483 fl_set_input_return(fd_form_table_extra->input_special_multialign,
485 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
488 #ifdef USE_OLD_DOCUMENT_LAYOUT
490 fd_form_quotes = create_form_form_quotes();
491 fl_set_form_atclose(fd_form_quotes->form_quotes,
492 CancelCloseBoxCB, 0);
493 // Is it wrong of me to use « » instead of << >> ? (Lgb)
494 // Maybe if people use a font other than latin1... (JMarc)
495 fl_addto_choice(fd_form_quotes->choice_quotes_language,
496 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
500 fd_form_preamble = create_form_form_preamble();
501 fl_set_form_atclose(fd_form_preamble->form_preamble,
502 CancelCloseBoxCB, 0);
506 fd_form_table = create_form_form_table();
507 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
508 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
509 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
510 fl_set_slider_value(fd_form_table->slider_rows, 5);
511 fl_set_slider_value(fd_form_table->slider_columns, 5);
512 fl_set_slider_precision(fd_form_table->slider_rows, 0);
513 fl_set_slider_precision(fd_form_table->slider_columns, 0);
514 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
518 fd_form_sendto = create_form_form_sendto();
519 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
522 fd_form_figure = create_form_form_figure();
523 fl_set_form_atclose(fd_form_figure->form_figure,
524 CancelCloseBoxCB, 0);
525 fl_set_button(fd_form_figure->radio_postscript, 1);
527 // the latex log form
528 fd_latex_log = create_form_LaTeXLog();
529 fl_set_form_atclose(fd_latex_log->LaTeXLog,
530 CancelCloseBoxCB, 0);
532 // Show the main & title form
533 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
534 int title_placement = FL_PLACE_CENTER;
535 // Did we get a valid position?
536 if (xpos >= 0 && ypos >= 0) {
537 lyxViews->setPosition(xpos, ypos);
538 if (lyxrc.show_banner) {
539 // show the title form in the middle of the main form
540 fl_set_form_position(fd_form_title->form_title,
541 abs(xpos + (width/2) - (370 / 2)),
542 abs(ypos + (height/2) - (290 / 2)));
543 title_placement = FL_PLACE_GEOMETRY;
544 // The use of abs() above is a trick to ensure
547 main_placement = FL_PLACE_POSITION;
549 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
550 if (lyxrc.show_banner) {
551 fl_show_form(fd_form_title->form_title,
552 title_placement, FL_NOBORDER,
554 fl_redraw_form(fd_form_title->form_title);
555 fl_raise_form(fd_form_title->form_title);
557 // Show the title form at most 7 secs (lowered from 10 secs)
558 fl_set_timer(fd_form_title->timer_title, 7);
563 void LyXGUI::runTime()
567 GUIRunTime::runTime();
571 void LyXGUI::regBuf(Buffer * b)
573 lyxViews->view()->buffer(b);
577 LyXView * LyXGUI::getLyXView() const