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)
115 static const int num_res = sizeof(res)/sizeof(FL_resource);
116 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
117 fl_get_app_resources(res, num_res);
119 static const int geometryBitmask =
120 XParseGeometry( geometry,
123 reinterpret_cast<unsigned int *>(&width),
124 reinterpret_cast<unsigned int *>(&height));
126 Display * display = fl_get_display();
128 lyxerr << "LyX: unable to access X display, exiting" << endl;
131 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
132 // X Error handler install goes here
133 XSetErrorHandler(LyX_XErrHandler);
135 // A width less than 590 pops up an awkward main window
136 // The minimal values of width/height (590/400) are defined in
138 if (width < 590) width = 590;
139 if (height < 400) height = 400;
141 // If width is not set by geometry, check it against monitor width
142 if ( !(geometryBitmask & 4) ) {
143 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
144 if (WidthOfScreen(scr) - 8 < width)
145 width = WidthOfScreen(scr) - 8;
148 // If height is not set by geometry, check it against monitor height
149 if ( !(geometryBitmask & 8) ) {
150 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
151 if (HeightOfScreen(scr) - 24 < height)
152 height = HeightOfScreen(scr) - 24;
155 // Recalculate xpos if it's negative
156 if (geometryBitmask & 16)
157 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
159 // Recalculate ypos if it's negative
160 if (geometryBitmask & 32)
161 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
163 // Initialize the LyXColorHandler
164 lyxColorHandler = new LyXColorHandler;
168 // A destructor is always necessary (asierra-970604)
171 // Lyxserver was created in this class so should be destroyed
172 // here. asierra-970604
181 void LyXGUI::setDefaults()
183 GUIRunTime::setDefaults();
187 // This is called after we have parsed lyxrc
195 if (lyxrc.font_norm_menu.empty())
196 lyxrc.font_norm_menu = lyxrc.font_norm;
197 // Set the font name for popups and menus
198 string menufontname = lyxrc.menu_font_name
199 + "-*-*-*-?-*-*-*-*-"
200 + lyxrc.font_norm_menu;
201 // "?" means "scale that font"
202 string popupfontname = lyxrc.popup_font_name
203 + "-*-*-*-?-*-*-*-*-"
204 + lyxrc.font_norm_menu;
206 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
207 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
209 lyxerr << "Could not set menu font to "
210 << menufontname << endl;
213 lyxerr << "Could not set popup font to "
214 << popupfontname << endl;
216 if (bold < 0 && normal < 0) {
217 lyxerr << "Using 'helvetica' font for menus" << endl;
218 bold = fl_set_font_name(FL_BOLD_STYLE,
219 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
220 normal = fl_set_font_name(FL_NORMAL_STYLE,
221 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
222 if (bold < 0 && normal < 0) {
223 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
224 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
228 // put here (after fl_initialize) to avoid segfault. Cannot be done
229 // in setDefaults() (Matthias 140496)
230 // Moved from ::LyXGUI to ::init to allow popup font customization
232 fl_setpup_fontstyle(FL_NORMAL_STYLE);
233 fl_setpup_fontsize(FL_NORMAL_SIZE);
234 fl_setpup_color(FL_MCOL, FL_BLACK);
235 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
237 // all lyxrc settings has to be done here as lyxrc has not yet
238 // been read when the GUI is created (Jug)
241 if (!lyxrc.custom_export_command.empty())
242 fl_set_input(fd_form_sendto->input_cmd,
243 lyxrc.custom_export_command.c_str());
244 if (lyxrc.custom_export_format == "lyx")
245 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
246 else if (lyxrc.custom_export_format == "tex")
247 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
248 else if (lyxrc.custom_export_format == "dvi")
249 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
250 else if (lyxrc.custom_export_format == "ps")
251 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
252 else if (lyxrc.custom_export_format == "ascii")
253 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
255 // Update parameters.
258 // Initialize the views.
261 // in 0.12 the initialisation of the LyXServer must be done here
262 // 0.13 it should be moved again...
263 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
267 void LyXGUI::create_forms()
269 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
270 lyxViews = new LyXView(width, height);
271 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
273 // From here down should be done by somebody else. (Lgb)
280 string banner_file = LibFileSearch("images", "banner", "xpm");
281 if (lyxrc.show_banner && !banner_file.empty()) {
282 fd_form_title = create_form_form_title();
283 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
284 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
285 fl_addto_form(fd_form_title->form_title);
286 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
287 fl_set_pixmapbutton_file(obj, banner_file.c_str());
289 fl_set_pixmapbutton_focus_outline(obj, 3);
290 fl_set_button_shortcut(obj, "^M ^[", 1);
291 fl_set_object_boxtype(obj, FL_NO_BOX);
292 fl_set_object_callback(obj, TimerCB, 0);
294 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
295 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
296 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
297 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
298 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
299 fl_set_object_lcol(obj, FL_FREE_COL3);
300 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
301 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
305 // the paragraph form
306 fd_form_paragraph = create_form_form_paragraph();
307 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
308 CancelCloseBoxCB, 0);
309 fl_addto_choice(fd_form_paragraph->choice_space_above,
310 _(" None | Defskip | Smallskip "
311 "| Medskip | Bigskip | VFill | Length "));
312 fl_addto_choice(fd_form_paragraph->choice_space_below,
313 _(" None | Defskip | Smallskip "
314 "| Medskip | Bigskip | VFill | Length "));
315 fl_set_input_return(fd_form_paragraph->input_space_above,
317 fl_set_input_return(fd_form_paragraph->input_space_below,
320 // the paragraph extra form
321 fd_form_paragraph_extra = create_form_form_paragraph_extra();
322 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
323 CancelCloseBoxCB, 0);
324 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
326 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
328 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
330 // the character form
331 fd_form_character = create_form_form_character();
332 fl_set_form_atclose(fd_form_character->form_character,
333 CancelCloseBoxCB, 0);
334 fl_addto_choice(fd_form_character->choice_family,
335 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
336 fl_addto_choice(fd_form_character->choice_series,
337 _(" No change %l| Medium | Bold %l| Reset "));
338 fl_addto_choice(fd_form_character->choice_shape,
339 _(" No change %l| Upright | Italic | Slanted | Small Caps "
341 fl_addto_choice(fd_form_character->choice_size,
342 _(" No change %l| Tiny | Smallest | Smaller | Small "
343 "| Normal | Large | Larger | Largest | Huge | Huger "
344 "%l| Increase | Decrease | Reset "));
345 fl_addto_choice(fd_form_character->choice_bar,
346 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
347 fl_addto_choice(fd_form_character->choice_color,
348 _(" No change %l| No color | Black | White | Red | Green "
349 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
350 fl_set_form_minsize(fd_form_character->form_character,
351 fd_form_character->form_character->w,
352 fd_form_character->form_character->h);
353 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
354 fl_addto_form(fd_form_character->form_character);
355 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
356 FL_OBJECT * ob = fd_form_character->choice_language;
357 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
358 combo_language2->shortcut("#L", 1);
360 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
362 // build up the combox entries
363 combo_language2->addto(_("No change"));
364 combo_language2->addto(_("Reset"));
365 for(Languages::const_iterator cit = languages.begin();
366 cit != languages.end(); ++cit) {
367 if ((*cit).second.lang() != "default")
368 combo_language2->addto((*cit).second.lang().c_str());
370 combo_language2->select_text(_("No change"));
372 #ifdef USE_OLD_DOCUMENT_LAYOUT
374 fd_form_document = create_form_form_document();
375 fl_set_form_atclose(fd_form_document->form_document,
376 CancelCloseBoxCB, 0);
377 fl_addto_choice(fd_form_document->choice_spacing,
378 _(" Single | OneHalf | Double | Other "));
380 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
381 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
382 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
383 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
384 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
385 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
386 fl_addto_form(fd_form_document->form_document);
387 combo_language = new Combox(FL_COMBOX_DROPLIST);
388 ob = fd_form_document->choice_language;
389 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
390 combo_language->shortcut("#G", 1);
393 // "default" is not part of the languages array any more.
394 combo_language->addto("default");
395 for(Languages::const_iterator cit = languages.begin();
396 cit != languages.end(); ++cit) {
397 combo_language->addto((*cit).second.lang().c_str());
400 // not really necessary, but we can do it anyway.
401 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
403 for (n = 0; tex_fonts[n][0]; ++n) {
404 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
407 fl_addto_choice(fd_form_document->choice_inputenc,
408 "default|auto|latin1|latin2|latin5"
409 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
411 for (n = 0; tex_graphics[n][0]; ++n) {
412 fl_addto_choice(fd_form_document->choice_postscript_driver,
415 // not really necessary, but we can do it anyway.
416 fl_addto_choice(fd_form_document->choice_pagestyle,
417 "default|empty|plain|headings|fancy");
418 fl_addto_choice(fd_form_document->choice_default_skip,
419 _(" Smallskip | Medskip | Bigskip | Length "));
420 fl_set_input_return(fd_form_document->input_default_skip,
422 fl_set_form_minsize(fd_form_document->form_document,
423 fd_form_document->form_document->w,
424 fd_form_document->form_document->h);
425 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
428 fd_form_paper = create_form_form_paper();
429 fl_set_form_atclose(fd_form_paper->form_paper,
430 CancelCloseBoxCB, 0);
431 fl_addto_choice(fd_form_paper->choice_papersize2,
432 _(" Default | Custom | USletter | USlegal "
433 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
434 fl_addto_choice(fd_form_paper->choice_paperpackage,
436 "| A4 small Margins (only portrait) "
437 "| A4 very small Margins (only portrait) "
438 "| A4 very wide margins (only portrait) "));
439 fl_set_input_return(fd_form_paper->input_custom_width,
441 fl_set_input_return(fd_form_paper->input_custom_height,
443 fl_set_input_return(fd_form_paper->input_top_margin,
445 fl_set_input_return(fd_form_paper->input_bottom_margin,
447 fl_set_input_return(fd_form_paper->input_left_margin,
449 fl_set_input_return(fd_form_paper->input_right_margin,
451 fl_set_input_return(fd_form_paper->input_head_height,
453 fl_set_input_return(fd_form_paper->input_head_sep,
455 fl_set_input_return(fd_form_paper->input_foot_skip,
457 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
461 // the table_options form
462 fd_form_table_options = create_form_form_table_options();
463 fl_set_form_atclose(fd_form_table_options->form_table_options,
464 CancelCloseBoxCB, 0);
465 fl_set_input_return(fd_form_table_options->input_column_width,
468 // the table_extra form
469 fd_form_table_extra = create_form_form_table_extra();
470 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
471 CancelCloseBoxCB, 0);
472 fl_set_input_return(fd_form_table_extra->input_special_alignment,
474 fl_set_input_return(fd_form_table_extra->input_special_multialign,
476 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
479 #ifdef USE_OLD_DOCUMENT_LAYOUT
481 fd_form_quotes = create_form_form_quotes();
482 fl_set_form_atclose(fd_form_quotes->form_quotes,
483 CancelCloseBoxCB, 0);
484 // Is it wrong of me to use « » instead of << >> ? (Lgb)
485 // Maybe if people use a font other than latin1... (JMarc)
486 fl_addto_choice(fd_form_quotes->choice_quotes_language,
487 _(" ``text'' | ''text'' | ,,text`` | ,,text'' | «text» | »text« "));
491 fd_form_preamble = create_form_form_preamble();
492 fl_set_form_atclose(fd_form_preamble->form_preamble,
493 CancelCloseBoxCB, 0);
497 fd_form_table = create_form_form_table();
498 fl_set_form_atclose(fd_form_table->form_table, CancelCloseBoxCB, 0);
499 fl_set_slider_bounds(fd_form_table->slider_rows, 1, 50);
500 fl_set_slider_bounds(fd_form_table->slider_columns, 1, 50);
501 fl_set_slider_value(fd_form_table->slider_rows, 5);
502 fl_set_slider_value(fd_form_table->slider_columns, 5);
503 fl_set_slider_precision(fd_form_table->slider_rows, 0);
504 fl_set_slider_precision(fd_form_table->slider_columns, 0);
505 lyxerr[Debug::INIT] << "Initializing form_table...done" << endl;
509 fd_form_sendto = create_form_form_sendto();
510 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
513 fd_form_figure = create_form_form_figure();
514 fl_set_form_atclose(fd_form_figure->form_figure,
515 CancelCloseBoxCB, 0);
516 fl_set_button(fd_form_figure->radio_postscript, 1);
518 // the latex log form
519 fd_latex_log = create_form_LaTeXLog();
520 fl_set_form_atclose(fd_latex_log->LaTeXLog,
521 CancelCloseBoxCB, 0);
523 // Show the main & title form
524 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
525 int title_placement = FL_PLACE_CENTER;
526 // Did we get a valid position?
527 if (xpos >= 0 && ypos >= 0) {
528 lyxViews->setPosition(xpos, ypos);
529 if (lyxrc.show_banner) {
530 // show the title form in the middle of the main form
531 fl_set_form_position(fd_form_title->form_title,
532 abs(xpos + (width/2) - (370 / 2)),
533 abs(ypos + (height/2) - (290 / 2)));
534 title_placement = FL_PLACE_GEOMETRY;
535 // The use of abs() above is a trick to ensure
538 main_placement = FL_PLACE_POSITION;
540 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
541 if (lyxrc.show_banner) {
542 fl_show_form(fd_form_title->form_title,
543 title_placement, FL_NOBORDER,
545 fl_redraw_form(fd_form_title->form_title);
546 fl_raise_form(fd_form_title->form_title);
548 // Show the title form at most 7 secs (lowered from 10 secs)
549 fl_set_timer(fd_form_title->timer_title, 7);
554 void LyXGUI::runTime()
558 guiruntime.runTime();
562 void LyXGUI::regBuf(Buffer * b)
564 lyxViews->view()->buffer(b);
568 LyXView * LyXGUI::getLyXView() const