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;
66 extern GUIRunTime guiruntime;
70 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
73 static int width = 690;
74 static int height = 510;
77 static char geometry[40];
78 bool cursor_follows_scrollbar;
83 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
88 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
90 //#warning Please see if you can trigger this!
92 if (!bufferlist.empty())
93 bufferlist.emergencyWriteAll();
95 // Get the reason for the crash.
97 XGetErrorText(display, xeev->error_code, etxt, 512);
98 lyxerr << etxt << endl;
99 // By doing an abort we get a nice backtrace. (hopefully)
101 return 0; // Solaris CC wants us to return something
105 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
106 : _owner(owner), lyxViews(0)
114 static const int num_res = sizeof(res)/sizeof(FL_resource);
115 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
116 fl_get_app_resources(res, num_res);
118 static const int geometryBitmask =
119 XParseGeometry( geometry,
122 reinterpret_cast<unsigned int *>(&width),
123 reinterpret_cast<unsigned int *>(&height));
125 Display * display = fl_get_display();
127 lyxerr << "LyX: unable to access X display, exiting" << endl;
130 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
131 // X Error handler install goes here
132 XSetErrorHandler(LyX_XErrHandler);
134 // A width less than 590 pops up an awkward main window
135 // The minimal values of width/height (590/400) are defined in
137 if (width < 590) width = 590;
138 if (height < 400) height = 400;
140 // If width is not set by geometry, check it against monitor width
141 if ( !(geometryBitmask & 4) ) {
142 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
143 if (WidthOfScreen(scr) - 8 < width)
144 width = WidthOfScreen(scr) - 8;
147 // If height is not set by geometry, check it against monitor height
148 if ( !(geometryBitmask & 8) ) {
149 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
150 if (HeightOfScreen(scr) - 24 < height)
151 height = HeightOfScreen(scr) - 24;
154 // Recalculate xpos if it's negative
155 if (geometryBitmask & 16)
156 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
158 // Recalculate ypos if it's negative
159 if (geometryBitmask & 32)
160 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
162 // Initialize the LyXColorHandler
163 lyxColorHandler = new LyXColorHandler;
167 // A destructor is always necessary (asierra-970604)
170 // Lyxserver was created in this class so should be destroyed
171 // here. asierra-970604
181 void LyXGUI::setDefaults()
184 cntl.buttonFontSize = FL_NORMAL_SIZE;
185 cntl.browserFontSize = FL_NORMAL_SIZE;
186 cntl.labelFontSize = FL_NORMAL_SIZE;
187 cntl.choiceFontSize = FL_NORMAL_SIZE;
188 cntl.inputFontSize = FL_NORMAL_SIZE;
189 cntl.menuFontSize = FL_NORMAL_SIZE;
190 cntl.borderWidth = -1;
191 cntl.vclass = FL_DefaultVisual;
192 fl_set_defaults(FL_PDVisual
193 | FL_PDButtonFontSize
194 | FL_PDBrowserFontSize
196 | FL_PDChoiceFontSize
199 | FL_PDBorderWidth, &cntl);
203 // This is called after we have parsed lyxrc
211 if (lyxrc.font_norm_menu.empty())
212 lyxrc.font_norm_menu = lyxrc.font_norm;
213 // Set the font name for popups and menus
214 string menufontname = lyxrc.menu_font_name
215 + "-*-*-*-?-*-*-*-*-"
216 + lyxrc.font_norm_menu;
217 // "?" means "scale that font"
218 string popupfontname = lyxrc.popup_font_name
219 + "-*-*-*-?-*-*-*-*-"
220 + lyxrc.font_norm_menu;
222 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
223 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
225 lyxerr << "Could not set menu font to "
226 << menufontname << endl;
229 lyxerr << "Could not set popup font to "
230 << popupfontname << endl;
232 if (bold < 0 && normal < 0) {
233 lyxerr << "Using 'helvetica' font for menus" << endl;
234 bold = fl_set_font_name(FL_BOLD_STYLE,
235 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
236 normal = fl_set_font_name(FL_NORMAL_STYLE,
237 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
238 if (bold < 0 && normal < 0) {
239 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
240 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
244 // put here (after fl_initialize) to avoid segfault. Cannot be done
245 // in setDefaults() (Matthias 140496)
246 // Moved from ::LyXGUI to ::init to allow popup font customization
248 fl_setpup_fontstyle(FL_NORMAL_STYLE);
249 fl_setpup_fontsize(FL_NORMAL_SIZE);
250 fl_setpup_color(FL_MCOL, FL_BLACK);
251 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
253 // all lyxrc settings has to be done here as lyxrc has not yet
254 // been read when the GUI is created (Jug)
257 if (!lyxrc.custom_export_command.empty())
258 fl_set_input(fd_form_sendto->input_cmd,
259 lyxrc.custom_export_command.c_str());
260 if (lyxrc.custom_export_format == "lyx")
261 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
262 else if (lyxrc.custom_export_format == "tex")
263 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
264 else if (lyxrc.custom_export_format == "dvi")
265 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
266 else if (lyxrc.custom_export_format == "ps")
267 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
268 else if (lyxrc.custom_export_format == "ascii")
269 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
271 // Update parameters.
274 // Initialize the views.
277 // in 0.12 the initialisation of the LyXServer must be done here
278 // 0.13 it should be moved again...
279 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
283 void LyXGUI::create_forms()
285 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
286 lyxViews = new LyXView(width, height);
287 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
289 // From here down should be done by somebody else. (Lgb)
296 string banner_file = LibFileSearch("images", "banner", "xpm");
297 if (lyxrc.show_banner && !banner_file.empty()) {
298 fd_form_title = create_form_form_title();
299 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
300 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
301 fl_addto_form(fd_form_title->form_title);
302 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
303 fl_set_pixmapbutton_file(obj, banner_file.c_str());
305 fl_set_pixmapbutton_focus_outline(obj, 3);
306 fl_set_button_shortcut(obj, "^M ^[", 1);
307 fl_set_object_boxtype(obj, FL_NO_BOX);
308 fl_set_object_callback(obj, TimerCB, 0);
310 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
311 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
312 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
313 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
314 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
315 fl_set_object_lcol(obj, FL_FREE_COL3);
316 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
317 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
321 // the paragraph form
322 fd_form_paragraph = create_form_form_paragraph();
323 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
324 CancelCloseBoxCB, 0);
325 fl_addto_choice(fd_form_paragraph->choice_space_above,
326 _(" None | Defskip | Smallskip "
327 "| Medskip | Bigskip | VFill | Length "));
328 fl_addto_choice(fd_form_paragraph->choice_space_below,
329 _(" None | Defskip | Smallskip "
330 "| Medskip | Bigskip | VFill | Length "));
331 fl_set_input_return(fd_form_paragraph->input_space_above,
333 fl_set_input_return(fd_form_paragraph->input_space_below,
336 // the paragraph extra form
337 fd_form_paragraph_extra = create_form_form_paragraph_extra();
338 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
339 CancelCloseBoxCB, 0);
340 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
342 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
344 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
346 // the character form
347 fd_form_character = create_form_form_character();
348 fl_set_form_atclose(fd_form_character->form_character,
349 CancelCloseBoxCB, 0);
350 fl_addto_choice(fd_form_character->choice_family,
351 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
352 fl_addto_choice(fd_form_character->choice_series,
353 _(" No change %l| Medium | Bold %l| Reset "));
354 fl_addto_choice(fd_form_character->choice_shape,
355 _(" No change %l| Upright | Italic | Slanted | Small Caps "
357 fl_addto_choice(fd_form_character->choice_size,
358 _(" No change %l| Tiny | Smallest | Smaller | Small "
359 "| Normal | Large | Larger | Largest | Huge | Huger "
360 "%l| Increase | Decrease | Reset "));
361 fl_addto_choice(fd_form_character->choice_bar,
362 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
363 fl_addto_choice(fd_form_character->choice_color,
364 _(" No change %l| No color | Black | White | Red | Green "
365 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
366 fl_set_form_minsize(fd_form_character->form_character,
367 fd_form_character->form_character->w,
368 fd_form_character->form_character->h);
369 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
370 fl_addto_form(fd_form_character->form_character);
371 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
372 FL_OBJECT * ob = fd_form_character->choice_language;
373 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
374 combo_language2->shortcut("#L", 1);
376 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
378 // build up the combox entries
379 combo_language2->addto(_("No change"));
380 combo_language2->addto(_("Reset"));
381 for(Languages::const_iterator cit = languages.begin();
382 cit != languages.end(); ++cit) {
383 if ((*cit).second.lang() != "default")
384 combo_language2->addto((*cit).second.lang().c_str());
386 combo_language2->select_text(_("No change"));
388 #ifdef USE_OLD_DOCUMENT_LAYOUT
390 fd_form_document = create_form_form_document();
391 fl_set_form_atclose(fd_form_document->form_document,
392 CancelCloseBoxCB, 0);
393 fl_addto_choice(fd_form_document->choice_spacing,
394 _(" Single | OneHalf | Double | Other "));
396 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
397 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
398 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
399 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
400 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
401 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
402 fl_addto_form(fd_form_document->form_document);
403 combo_language = new Combox(FL_COMBOX_DROPLIST);
404 ob = fd_form_document->choice_language;
405 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
406 combo_language->shortcut("#G", 1);
409 // "default" is not part of the languages array any more.
410 combo_language->addto("default");
411 for(Languages::const_iterator cit = languages.begin();
412 cit != languages.end(); ++cit) {
413 combo_language->addto((*cit).second.lang().c_str());
416 // not really necessary, but we can do it anyway.
417 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
419 for (n = 0; tex_fonts[n][0]; ++n) {
420 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
423 fl_addto_choice(fd_form_document->choice_inputenc,
424 "default|auto|latin1|latin2|latin5"
425 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
427 for (n = 0; tex_graphics[n][0]; ++n) {
428 fl_addto_choice(fd_form_document->choice_postscript_driver,
431 // not really necessary, but we can do it anyway.
432 fl_addto_choice(fd_form_document->choice_pagestyle,
433 "default|empty|plain|headings|fancy");
434 fl_addto_choice(fd_form_document->choice_default_skip,
435 _(" Smallskip | Medskip | Bigskip | Length "));
436 fl_set_input_return(fd_form_document->input_default_skip,
438 fl_set_form_minsize(fd_form_document->form_document,
439 fd_form_document->form_document->w,
440 fd_form_document->form_document->h);
441 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
444 fd_form_paper = create_form_form_paper();
445 fl_set_form_atclose(fd_form_paper->form_paper,
446 CancelCloseBoxCB, 0);
447 fl_addto_choice(fd_form_paper->choice_papersize2,
448 _(" Default | Custom | USletter | USlegal "
449 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
450 fl_addto_choice(fd_form_paper->choice_paperpackage,
452 "| A4 small Margins (only portrait) "
453 "| A4 very small Margins (only portrait) "
454 "| A4 very wide margins (only portrait) "));
455 fl_set_input_return(fd_form_paper->input_custom_width,
457 fl_set_input_return(fd_form_paper->input_custom_height,
459 fl_set_input_return(fd_form_paper->input_top_margin,
461 fl_set_input_return(fd_form_paper->input_bottom_margin,
463 fl_set_input_return(fd_form_paper->input_left_margin,
465 fl_set_input_return(fd_form_paper->input_right_margin,
467 fl_set_input_return(fd_form_paper->input_head_height,
469 fl_set_input_return(fd_form_paper->input_head_sep,
471 fl_set_input_return(fd_form_paper->input_foot_skip,
473 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
477 // the table_options form
478 fd_form_table_options = create_form_form_table_options();
479 fl_set_form_atclose(fd_form_table_options->form_table_options,
480 CancelCloseBoxCB, 0);
481 fl_set_input_return(fd_form_table_options->input_column_width,
484 // the table_extra form
485 fd_form_table_extra = create_form_form_table_extra();
486 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
487 CancelCloseBoxCB, 0);
488 fl_set_input_return(fd_form_table_extra->input_special_alignment,
490 fl_set_input_return(fd_form_table_extra->input_special_multialign,
492 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
495 #ifdef USE_OLD_DOCUMENT_LAYOUT
497 fd_form_quotes = create_form_form_quotes();
498 fl_set_form_atclose(fd_form_quotes->form_quotes,
499 CancelCloseBoxCB, 0);
500 // Is it wrong of me to use « » instead of << >> ? (Lgb)
501 // Maybe if people use a font other than latin1... (JMarc)
502 fl_addto_choice(fd_form_quotes->choice_quotes_language,
503 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
507 fd_form_preamble = create_form_form_preamble();
508 fl_set_form_atclose(fd_form_preamble->form_preamble,
509 CancelCloseBoxCB, 0);
513 fd_form_table = create_form_form_table();
514 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
515 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
516 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
517 fl_set_slider_value(fd_form_table->slider_rows, 5);
518 fl_set_slider_value(fd_form_table->slider_columns, 5);
519 fl_set_slider_precision(fd_form_table->slider_rows, 0);
520 fl_set_slider_precision(fd_form_table->slider_columns, 0);
521 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
525 fd_form_sendto = create_form_form_sendto();
526 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
529 fd_form_figure = create_form_form_figure();
530 fl_set_form_atclose(fd_form_figure->form_figure,
531 CancelCloseBoxCB, 0);
532 fl_set_button(fd_form_figure->radio_postscript, 1);
534 // the latex log form
535 fd_latex_log = create_form_LaTeXLog();
536 fl_set_form_atclose(fd_latex_log->LaTeXLog,
537 CancelCloseBoxCB, 0);
539 // Show the main & title form
540 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
541 int title_placement = FL_PLACE_CENTER;
542 // Did we get a valid position?
543 if (xpos >= 0 && ypos >= 0) {
544 lyxViews->setPosition(xpos, ypos);
545 if (lyxrc.show_banner) {
546 // show the title form in the middle of the main form
547 fl_set_form_position(fd_form_title->form_title,
548 abs(xpos + (width/2) - (370 / 2)),
549 abs(ypos + (height/2) - (290 / 2)));
550 title_placement = FL_PLACE_GEOMETRY;
551 // The use of abs() above is a trick to ensure
554 main_placement = FL_PLACE_POSITION;
556 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
557 if (lyxrc.show_banner) {
558 fl_show_form(fd_form_title->form_title,
559 title_placement, FL_NOBORDER,
561 fl_redraw_form(fd_form_title->form_title);
562 fl_raise_form(fd_form_title->form_title);
564 // Show the title form at most 7 secs (lowered from 10 secs)
565 fl_set_timer(fd_form_title->timer_title, 7);
570 void LyXGUI::runTime()
574 guiruntime.runTime();
578 void LyXGUI::regBuf(Buffer * b)
580 lyxViews->view()->buffer(b);
584 LyXView * LyXGUI::getLyXView() const