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
23 # include <gnome--/main.h>
28 #include FORMS_H_LOCATION
29 #include "support/filetools.h"
33 #include "layout_forms.h"
34 #include "print_form.h"
35 #include "tex-strings.h"
42 #include "lyxserver.h"
45 #include "lyx_gui_misc.h"
46 #include "lyxlookup.h"
47 #include "bufferlist.h"
49 #include "ColorHandler.h"
53 FD_form_title * fd_form_title;
54 FD_form_paragraph * fd_form_paragraph;
55 FD_form_paragraph_extra * fd_form_paragraph_extra;
56 FD_form_character * fd_form_character;
57 FD_form_document * fd_form_document;
58 FD_form_paper * fd_form_paper;
59 FD_form_table_options * fd_form_table_options;
60 FD_form_table_extra * fd_form_table_extra;
61 FD_form_quotes * fd_form_quotes;
62 FD_form_preamble * fd_form_preamble;
63 FD_form_table * fd_form_table;
64 FD_form_sendto * fd_form_sendto;
65 FD_form_figure * fd_form_figure;
66 FD_LaTeXLog * fd_latex_log; // from log_form.h
67 Combox * combo_language;
68 Combox * combo_language2;
70 extern LyXServer * lyxserver;
71 extern bool finished; // flag, that we are quitting the program
72 extern BufferList bufferlist;
76 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
79 static int width = 690;
80 static int height = 510;
83 static char geometry[40];
84 bool cursor_follows_scrollbar;
89 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
93 extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
95 //#warning Please see if you can trigger this!
97 if (!bufferlist.empty())
98 bufferlist.emergencyWriteAll();
100 // Get the reason for the crash.
102 XGetErrorText(display, xeev->error_code, etxt, 512);
103 lyxerr << etxt << endl;
104 // By doing an abort we get a nice backtrace. (hopefully)
106 return 0; // Solaris CC wants us to return something
110 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
111 : _owner(owner), lyxViews(0)
119 static const int num_res = sizeof(res)/sizeof(FL_resource);
120 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
121 fl_get_app_resources(res, num_res);
123 static const int geometryBitmask = XParseGeometry( geometry,
126 (unsigned int *) &width,
127 (unsigned int *) &height
130 Display * display = fl_get_display();
132 lyxerr << "LyX: unable to access X display, exiting" << endl;
135 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
136 // X Error handler install goes here
137 XSetErrorHandler(LyX_XErrHandler);
139 // A width less than 590 pops up an awkward main window
140 // The minimal values of width/height (590/400) are defined in
142 if (width < 590) width = 590;
143 if (height < 400) height = 400;
145 // If width is not set by geometry, check it against monitor width
146 if ( !(geometryBitmask & 4) ) {
147 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
148 if (WidthOfScreen(scr) - 8 < width)
149 width = WidthOfScreen(scr) - 8;
152 // If height is not set by geometry, check it against monitor height
153 if ( !(geometryBitmask & 8) ) {
154 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
155 if (HeightOfScreen(scr) - 24 < height)
156 height = HeightOfScreen(scr) - 24;
159 // Recalculate xpos if it's negative
160 if (geometryBitmask & 16)
161 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
163 // Recalculate ypos if it's negative
164 if (geometryBitmask & 32)
165 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
167 // Initialize the LyXColorHandler
168 lyxColorHandler = new LyXColorHandler;
172 // A destructor is always necessary (asierra-970604)
175 // Lyxserver was created in this class so should be destroyed
176 // here. asierra-970604
186 void LyXGUI::setDefaults()
189 cntl.buttonFontSize = FL_NORMAL_SIZE;
190 cntl.browserFontSize = FL_NORMAL_SIZE;
191 cntl.labelFontSize = FL_NORMAL_SIZE;
192 cntl.choiceFontSize = FL_NORMAL_SIZE;
193 cntl.inputFontSize = FL_NORMAL_SIZE;
194 cntl.menuFontSize = FL_NORMAL_SIZE;
195 cntl.borderWidth = -1;
196 cntl.vclass = FL_DefaultVisual;
197 fl_set_defaults(FL_PDVisual
198 | FL_PDButtonFontSize
199 | FL_PDBrowserFontSize
201 | FL_PDChoiceFontSize
204 | FL_PDBorderWidth, &cntl);
208 // This is called after we have parsed lyxrc
216 if (lyxrc.font_norm_menu.empty())
217 lyxrc.font_norm_menu = lyxrc.font_norm;
218 // Set the font name for popups and menus
219 string menufontname = lyxrc.menu_font_name
220 + "-*-*-*-?-*-*-*-*-"
221 + lyxrc.font_norm_menu;
222 // "?" means "scale that font"
223 string popupfontname = lyxrc.popup_font_name
224 + "-*-*-*-?-*-*-*-*-"
225 + lyxrc.font_norm_menu;
227 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
228 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
230 lyxerr << "Could not set menu font to "
231 << menufontname << endl;
234 lyxerr << "Could not set popup font to "
235 << popupfontname << endl;
237 if (bold < 0 && normal < 0) {
238 lyxerr << "Using 'helvetica' font for menus" << endl;
239 bold = fl_set_font_name(FL_BOLD_STYLE,
240 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
241 normal = fl_set_font_name(FL_NORMAL_STYLE,
242 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
243 if (bold < 0 && normal < 0) {
244 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
245 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
249 // put here (after fl_initialize) to avoid segfault. Cannot be done
250 // in setDefaults() (Matthias 140496)
251 // Moved from ::LyXGUI to ::init to allow popup font customization
253 fl_setpup_fontstyle(FL_NORMAL_STYLE);
254 fl_setpup_fontsize(FL_NORMAL_SIZE);
255 fl_setpup_color(FL_MCOL, FL_BLACK);
256 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
258 // all lyxrc settings has to be done here as lyxrc has not yet
259 // been read when the GUI is created (Jug)
262 if (!lyxrc.custom_export_command.empty())
263 fl_set_input(fd_form_sendto->input_cmd,
264 lyxrc.custom_export_command.c_str());
265 if (lyxrc.custom_export_format == "lyx")
266 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
267 else if (lyxrc.custom_export_format == "tex")
268 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
269 else if (lyxrc.custom_export_format == "dvi")
270 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
271 else if (lyxrc.custom_export_format == "ps")
272 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
273 else if (lyxrc.custom_export_format == "ascii")
274 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
276 // Update parameters.
279 // Initialize the views.
282 // in 0.12 the initialisation of the LyXServer must be done here
283 // 0.13 it should be moved again...
284 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
288 void LyXGUI::create_forms()
290 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
291 lyxViews = new LyXView(width, height);
292 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
294 // From here down should be done by somebody else. (Lgb)
301 string banner_file = LibFileSearch("images", "banner", "xpm");
302 if (lyxrc.show_banner && !banner_file.empty()) {
303 fd_form_title = create_form_form_title();
304 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
305 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
306 fl_addto_form(fd_form_title->form_title);
307 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
308 fl_set_pixmapbutton_file(obj, banner_file.c_str());
310 fl_set_pixmapbutton_focus_outline(obj, 3);
311 fl_set_button_shortcut(obj, "^M ^[", 1);
312 fl_set_object_boxtype(obj, FL_NO_BOX);
313 fl_set_object_callback(obj, TimerCB, 0);
315 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
316 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
317 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
318 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
319 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
320 fl_set_object_lcol(obj, FL_FREE_COL3);
321 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
322 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
326 // the paragraph form
327 fd_form_paragraph = create_form_form_paragraph();
328 fl_set_form_atclose(fd_form_paragraph->form_paragraph,
329 CancelCloseBoxCB, 0);
330 fl_addto_choice(fd_form_paragraph->choice_space_above,
331 _(" None | Defskip | Smallskip "
332 "| Medskip | Bigskip | VFill | Length "));
333 fl_addto_choice(fd_form_paragraph->choice_space_below,
334 _(" None | Defskip | Smallskip "
335 "| Medskip | Bigskip | VFill | Length "));
336 fl_set_input_return(fd_form_paragraph->input_space_above,
338 fl_set_input_return(fd_form_paragraph->input_space_below,
341 // the paragraph extra form
342 fd_form_paragraph_extra = create_form_form_paragraph_extra();
343 fl_set_form_atclose(fd_form_paragraph_extra->form_paragraph_extra,
344 CancelCloseBoxCB, 0);
345 fl_set_input_return(fd_form_paragraph_extra->input_pextra_width,
347 fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
349 lyxerr[Debug::INIT] << "Initializing form_paragraph...done" << endl;
351 // the character form
352 fd_form_character = create_form_form_character();
353 fl_set_form_atclose(fd_form_character->form_character,
354 CancelCloseBoxCB, 0);
355 fl_addto_choice(fd_form_character->choice_family,
356 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
357 fl_addto_choice(fd_form_character->choice_series,
358 _(" No change %l| Medium | Bold %l| Reset "));
359 fl_addto_choice(fd_form_character->choice_shape,
360 _(" No change %l| Upright | Italic | Slanted | Small Caps "
362 fl_addto_choice(fd_form_character->choice_size,
363 _(" No change %l| Tiny | Smallest | Smaller | Small "
364 "| Normal | Large | Larger | Largest | Huge | Huger "
365 "%l| Increase | Decrease | Reset "));
366 fl_addto_choice(fd_form_character->choice_bar,
367 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
368 fl_addto_choice(fd_form_character->choice_color,
369 _(" No change %l| No color | Black | White | Red | Green "
370 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
371 fl_set_form_minsize(fd_form_character->form_character,
372 fd_form_character->form_character->w,
373 fd_form_character->form_character->h);
374 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
375 fl_addto_form(fd_form_character->form_character);
376 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
377 FL_OBJECT * ob = fd_form_character->choice_language;
378 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
379 combo_language2->shortcut("#L", 1);
381 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
384 fd_form_document = create_form_form_document();
385 fl_set_form_atclose(fd_form_document->form_document,
386 CancelCloseBoxCB, 0);
387 fl_addto_choice(fd_form_document->choice_spacing,
388 _(" Single | OneHalf | Double | Other "));
390 fl_set_counter_bounds(fd_form_document->slider_secnumdepth,-2, 5);
391 fl_set_counter_bounds(fd_form_document->slider_tocdepth,-1, 5);
392 fl_set_counter_step(fd_form_document->slider_secnumdepth, 1, 1);
393 fl_set_counter_step(fd_form_document->slider_tocdepth, 1, 1);
394 fl_set_counter_precision(fd_form_document->slider_secnumdepth, 0);
395 fl_set_counter_precision(fd_form_document->slider_tocdepth, 0);
396 fl_addto_form(fd_form_document->form_document);
397 combo_language = new Combox(FL_COMBOX_DROPLIST);
398 ob = fd_form_document->choice_language;
399 combo_language->add(ob->x, ob->y, ob->w, ob->h, 250);
400 combo_language->shortcut("#G", 1);
403 // "default" is not part of the languages array any more.
404 combo_language->addto("default");
405 combo_language2->addto(_("No change"));
406 combo_language2->addto(_("Reset"));
407 for(Languages::const_iterator cit = languages.begin();
408 cit != languages.end(); ++cit) {
409 combo_language->addto((*cit).second.lang().c_str());
410 combo_language2->addto((*cit).second.lang().c_str());
412 combo_language2->select_text("No change");
414 // not really necessary, but we can do it anyway.
415 fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12");
417 for (n = 0; tex_fonts[n][0]; ++n) {
418 fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]);
421 fl_addto_choice(fd_form_document->choice_inputenc,
422 "default|auto|latin1|latin2|latin5"
423 "|koi8-r|koi8-u|cp866|cp1251|iso88595");
425 for (n = 0; tex_graphics[n][0]; ++n) {
426 fl_addto_choice(fd_form_document->choice_postscript_driver,
429 // not really necessary, but we can do it anyway.
430 fl_addto_choice(fd_form_document->choice_pagestyle,
431 "default|empty|plain|headings|fancy");
432 fl_addto_choice(fd_form_document->choice_default_skip,
433 _(" Smallskip | Medskip | Bigskip | Length "));
434 fl_set_input_return(fd_form_document->input_default_skip,
436 fl_set_form_minsize(fd_form_document->form_document,
437 fd_form_document->form_document->w,
438 fd_form_document->form_document->h);
439 lyxerr[Debug::INIT] << "Initializing form_document...done" << endl;
442 fd_form_paper = create_form_form_paper();
443 fl_set_form_atclose(fd_form_paper->form_paper,
444 CancelCloseBoxCB, 0);
445 fl_addto_choice(fd_form_paper->choice_papersize2,
446 _(" Default | Custom | USletter | USlegal "
447 "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
448 fl_addto_choice(fd_form_paper->choice_paperpackage,
450 "| A4 small Margins (only portrait) "
451 "| A4 very small Margins (only portrait) "
452 "| A4 very wide margins (only portrait) "));
453 fl_set_input_return(fd_form_paper->input_custom_width,
455 fl_set_input_return(fd_form_paper->input_custom_height,
457 fl_set_input_return(fd_form_paper->input_top_margin,
459 fl_set_input_return(fd_form_paper->input_bottom_margin,
461 fl_set_input_return(fd_form_paper->input_left_margin,
463 fl_set_input_return(fd_form_paper->input_right_margin,
465 fl_set_input_return(fd_form_paper->input_head_height,
467 fl_set_input_return(fd_form_paper->input_head_sep,
469 fl_set_input_return(fd_form_paper->input_foot_skip,
471 lyxerr[Debug::INIT] << "Initializing form_paper...done" << endl;
473 // the table_options form
474 fd_form_table_options = create_form_form_table_options();
475 fl_set_form_atclose(fd_form_table_options->form_table_options,
476 CancelCloseBoxCB, 0);
477 fl_set_input_return(fd_form_table_options->input_column_width,
480 // the table_extra form
481 fd_form_table_extra = create_form_form_table_extra();
482 fl_set_form_atclose(fd_form_table_extra->form_table_extra,
483 CancelCloseBoxCB, 0);
484 fl_set_input_return(fd_form_table_extra->input_special_alignment,
486 fl_set_input_return(fd_form_table_extra->input_special_multialign,
488 lyxerr[Debug::INIT] << "Initializing form_table_extra...done" << endl;
491 fd_form_quotes = create_form_form_quotes();
492 fl_set_form_atclose(fd_form_quotes->form_quotes,
493 CancelCloseBoxCB, 0);
494 // Is it wrong of me to use « » instead of << >> ? (Lgb)
495 // Maybe if people use a font other than latin1... (JMarc)
496 fl_addto_choice(fd_form_quotes->choice_quotes_language,
497 _(" ``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()
564 /* This will usually be toolkit (GUI) specific. This is
565 * also usually the XEvent dispatcher of the GUI. */
575 kapp->processEvents();
578 Gnome::Main::instance()->iteration(FALSE);
581 if (fl_check_forms() == FL_EVENT) {
582 lyxerr << "LyX: This shouldn't happen..." << endl;
589 void LyXGUI::regBuf(Buffer * b)
591 lyxViews->view()->buffer(b);
594 LyXView * LyXGUI::getLyXView() const