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"
39 #include "lyxlookup.h"
41 #include "bufferlist.h"
43 #include "ColorHandler.h"
44 #include "frontends/GUIRunTime.h"
48 FD_form_title * fd_form_title;
49 FD_form_character * fd_form_character;
50 FD_form_preamble * fd_form_preamble;
51 FD_form_sendto * fd_form_sendto;
52 FD_form_figure * fd_form_figure;
53 FD_LaTeXLog * fd_latex_log; // from log_form.h
54 Combox * combo_language;
55 Combox * combo_language2;
57 extern LyXServer * lyxserver;
58 extern bool finished; // flag, that we are quitting the program
59 extern BufferList bufferlist;
60 extern GUIRunTime guiruntime;
64 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
67 static int width = 690;
68 static int height = 510;
71 static char geometry[40];
76 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
81 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
84 if (!bufferlist.empty())
85 bufferlist.emergencyWriteAll();
87 // Get the reason for the crash.
89 XGetErrorText(display, xeev->error_code, etxt, 512);
90 lyxerr << etxt << endl;
91 // By doing an abort we get a nice backtrace. (hopefully)
93 return 0; // Solaris CC wants us to return something
97 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
98 : _owner(owner), lyxViews(0)
107 static const int num_res = sizeof(res)/sizeof(FL_resource);
108 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
109 fl_get_app_resources(res, num_res);
111 static const int geometryBitmask =
112 XParseGeometry( geometry,
115 reinterpret_cast<unsigned int *>(&width),
116 reinterpret_cast<unsigned int *>(&height));
118 Display * display = fl_get_display();
120 lyxerr << "LyX: unable to access X display, exiting" << endl;
123 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
124 // X Error handler install goes here
125 XSetErrorHandler(LyX_XErrHandler);
127 // A width less than 590 pops up an awkward main window
128 // The minimal values of width/height (590/400) are defined in
130 if (width < 590) width = 590;
131 if (height < 400) height = 400;
133 // If width is not set by geometry, check it against monitor width
134 if ( !(geometryBitmask & 4) ) {
135 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
136 if (WidthOfScreen(scr) - 8 < width)
137 width = WidthOfScreen(scr) - 8;
140 // If height is not set by geometry, check it against monitor height
141 if ( !(geometryBitmask & 8) ) {
142 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
143 if (HeightOfScreen(scr) - 24 < height)
144 height = HeightOfScreen(scr) - 24;
147 // Recalculate xpos if it's negative
148 if (geometryBitmask & 16)
149 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
151 // Recalculate ypos if it's negative
152 if (geometryBitmask & 32)
153 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height;
155 // Initialize the LyXColorHandler
156 lyxColorHandler = new LyXColorHandler;
160 // A destructor is always necessary (asierra-970604)
163 // Lyxserver was created in this class so should be destroyed
164 // here. asierra-970604
174 void LyXGUI::setDefaults()
176 GUIRunTime::setDefaults();
180 // This is called after we have parsed lyxrc
188 if (lyxrc.font_norm_menu.empty())
189 lyxrc.font_norm_menu = lyxrc.font_norm;
190 // Set the font name for popups and menus
191 string boldfontname = lyxrc.menu_font_name
192 + "-*-*-*-?-*-*-*-*-"
193 + lyxrc.font_norm_menu;
194 // "?" means "scale that font"
195 string fontname = lyxrc.popup_font_name
196 + "-*-*-*-?-*-*-*-*-"
197 + lyxrc.font_norm_menu;
199 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
200 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
202 lyxerr << "Could not set menu font to "
203 << boldfontname << endl;
206 lyxerr << "Could not set popup font to "
209 if (bold < 0 && normal < 0) {
210 lyxerr << "Using 'helvetica' font for menus" << endl;
211 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
212 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
213 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
214 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
216 if (bold < 0 && normal < 0) {
217 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
218 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
223 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
225 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
227 // put here (after fl_initialize) to avoid segfault. Cannot be done
228 // in setDefaults() (Matthias 140496)
229 // Moved from ::LyXGUI to ::init to allow popup font customization
231 fl_setpup_fontstyle(FL_NORMAL_STYLE);
232 fl_setpup_fontsize(FL_NORMAL_SIZE);
233 fl_setpup_color(FL_MCOL, FL_BLACK);
234 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
236 // all lyxrc settings has to be done here as lyxrc has not yet
237 // been read when the GUI is created (Jug)
240 if (!lyxrc.custom_export_command.empty())
241 fl_set_input(fd_form_sendto->input_cmd,
242 lyxrc.custom_export_command.c_str());
243 if (lyxrc.custom_export_format == "lyx")
244 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
245 else if (lyxrc.custom_export_format == "tex")
246 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
247 else if (lyxrc.custom_export_format == "dvi")
248 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
249 else if (lyxrc.custom_export_format == "ps")
250 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
251 else if (lyxrc.custom_export_format == "ascii")
252 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
254 // Update parameters.
257 // Initialize the views.
260 // in 0.12 the initialisation of the LyXServer must be done here
261 // 0.13 it should be moved again...
262 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
266 void LyXGUI::create_forms()
268 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
269 lyxViews = new LyXView(width, height);
270 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
272 // From here down should be done by somebody else. (Lgb)
279 string banner_file = LibFileSearch("images", "banner", "xpm");
280 if (lyxrc.show_banner && !banner_file.empty()) {
281 fd_form_title = create_form_form_title();
282 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
283 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
284 fl_addto_form(fd_form_title->form_title);
285 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
286 fl_set_pixmapbutton_file(obj, banner_file.c_str());
288 fl_set_pixmapbutton_focus_outline(obj, 3);
289 fl_set_button_shortcut(obj, "^M ^[", 1);
290 fl_set_object_boxtype(obj, FL_NO_BOX);
291 fl_set_object_callback(obj, TimerCB, 0);
293 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
294 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
295 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
296 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
297 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
298 fl_set_object_lcol(obj, FL_FREE_COL3);
299 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
300 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
304 // the character form
305 fd_form_character = create_form_form_character();
306 fl_set_form_atclose(fd_form_character->form_character,
307 CancelCloseBoxCB, 0);
308 fl_addto_choice(fd_form_character->choice_family,
309 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
310 fl_addto_choice(fd_form_character->choice_series,
311 _(" No change %l| Medium | Bold %l| Reset "));
312 fl_addto_choice(fd_form_character->choice_shape,
313 _(" No change %l| Upright | Italic | Slanted | Small Caps "
315 fl_addto_choice(fd_form_character->choice_size,
316 _(" No change %l| Tiny | Smallest | Smaller | Small "
317 "| Normal | Large | Larger | Largest | Huge | Huger "
318 "%l| Increase | Decrease | Reset "));
319 fl_addto_choice(fd_form_character->choice_bar,
320 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
321 fl_addto_choice(fd_form_character->choice_color,
322 _(" No change %l| No color | Black | White | Red | Green "
323 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
324 // Appears to need initialising to avoid seg fault when dialog is
325 // launched. Over-written by combo_language2, below
326 fl_addto_choice(fd_form_character->choice_language,
327 _(" English %l| German | French "));
328 fl_set_form_minsize(fd_form_character->form_character,
329 fd_form_character->form_character->w,
330 fd_form_character->form_character->h);
331 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
332 fl_addto_form(fd_form_character->form_character);
333 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
334 FL_OBJECT * ob = fd_form_character->choice_language;
335 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
336 combo_language2->shortcut("#L", 1);
338 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
340 // build up the combox entries
341 combo_language2->addline(_("No change"));
342 combo_language2->addline(_("Reset"));
343 for(Languages::const_iterator cit = languages.begin();
344 cit != languages.end(); ++cit) {
345 #ifdef DO_USE_DEFAULT_LANGUAGE
346 if ((*cit).second.lang() != "default")
348 combo_language2->addto((*cit).second.lang());
352 fd_form_preamble = create_form_form_preamble();
353 fl_set_form_atclose(fd_form_preamble->form_preamble,
354 CancelCloseBoxCB, 0);
357 fd_form_sendto = create_form_form_sendto();
358 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
361 fd_form_figure = create_form_form_figure();
362 fl_set_form_atclose(fd_form_figure->form_figure,
363 CancelCloseBoxCB, 0);
364 fl_set_button(fd_form_figure->radio_postscript, 1);
366 // the latex log form
367 fd_latex_log = create_form_LaTeXLog();
368 fl_set_form_atclose(fd_latex_log->LaTeXLog,
369 CancelCloseBoxCB, 0);
371 // Show the main & title form
372 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
373 int title_placement = FL_PLACE_CENTER;
374 // Did we get a valid position?
375 if (xpos >= 0 && ypos >= 0) {
376 lyxViews->setPosition(xpos, ypos);
377 if (lyxrc.show_banner) {
378 // show the title form in the middle of the main form
379 fl_set_form_position(fd_form_title->form_title,
380 abs(xpos + (width/2) - (370 / 2)),
381 abs(ypos + (height/2) - (290 / 2)));
382 title_placement = FL_PLACE_GEOMETRY;
383 // The use of abs() above is a trick to ensure
386 main_placement = FL_PLACE_POSITION;
388 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
389 if (lyxrc.show_banner) {
390 fl_show_form(fd_form_title->form_title,
391 title_placement, FL_NOBORDER,
393 fl_redraw_form(fd_form_title->form_title);
394 fl_raise_form(fd_form_title->form_title);
396 // Show the title form at most 7 secs (lowered from 10 secs)
397 fl_set_timer(fd_form_title->timer_title, 7);
402 void LyXGUI::runTime()
406 guiruntime.runTime();
410 void LyXGUI::regBuf(Buffer * b)
412 lyxViews->view()->buffer(b);
416 LyXView * LyXGUI::getLyXView() const