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_character * fd_form_character;
48 FD_form_preamble * fd_form_preamble;
49 FD_form_sendto * fd_form_sendto;
50 FD_form_figure * fd_form_figure;
51 FD_LaTeXLog * fd_latex_log; // from log_form.h
52 Combox * combo_language;
53 Combox * combo_language2;
55 extern LyXServer * lyxserver;
56 extern bool finished; // flag, that we are quitting the program
57 extern BufferList bufferlist;
58 extern GUIRunTime guiruntime;
62 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
65 static int width = 690;
66 static int height = 510;
69 static char geometry[40];
74 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
79 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
81 //#warning Please see if you can trigger this!
83 if (!bufferlist.empty())
84 bufferlist.emergencyWriteAll();
86 // Get the reason for the crash.
88 XGetErrorText(display, xeev->error_code, etxt, 512);
89 lyxerr << etxt << endl;
90 // By doing an abort we get a nice backtrace. (hopefully)
92 return 0; // Solaris CC wants us to return something
96 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
97 : _owner(owner), lyxViews(0)
106 static const int num_res = sizeof(res)/sizeof(FL_resource);
107 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
108 fl_get_app_resources(res, num_res);
110 static const int geometryBitmask =
111 XParseGeometry( geometry,
114 reinterpret_cast<unsigned int *>(&width),
115 reinterpret_cast<unsigned int *>(&height));
117 Display * display = fl_get_display();
119 lyxerr << "LyX: unable to access X display, exiting" << endl;
122 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
123 // X Error handler install goes here
124 XSetErrorHandler(LyX_XErrHandler);
126 // A width less than 590 pops up an awkward main window
127 // The minimal values of width/height (590/400) are defined in
129 if (width < 590) width = 590;
130 if (height < 400) height = 400;
132 // If width is not set by geometry, check it against monitor width
133 if ( !(geometryBitmask & 4) ) {
134 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
135 if (WidthOfScreen(scr) - 8 < width)
136 width = WidthOfScreen(scr) - 8;
139 // If height is not set by geometry, check it against monitor height
140 if ( !(geometryBitmask & 8) ) {
141 Screen * scr = DefaultScreenOfDisplay(fl_get_display());
142 if (HeightOfScreen(scr) - 24 < height)
143 height = HeightOfScreen(scr) - 24;
146 // Recalculate xpos if it's negative
147 if (geometryBitmask & 16)
148 xpos += WidthOfScreen(DefaultScreenOfDisplay(fl_get_display())) - width;
150 // Recalculate ypos if it's negative
151 if (geometryBitmask & 32)
152 ypos += HeightOfScreen(DefaultScreenOfDisplay(fl_get_display())) - height;
154 // Initialize the LyXColorHandler
155 lyxColorHandler = new LyXColorHandler;
159 // A destructor is always necessary (asierra-970604)
162 // Lyxserver was created in this class so should be destroyed
163 // here. asierra-970604
172 void LyXGUI::setDefaults()
174 GUIRunTime::setDefaults();
178 // This is called after we have parsed lyxrc
186 if (lyxrc.font_norm_menu.empty())
187 lyxrc.font_norm_menu = lyxrc.font_norm;
188 // Set the font name for popups and menus
189 string menufontname = lyxrc.menu_font_name
190 + "-*-*-*-?-*-*-*-*-"
191 + lyxrc.font_norm_menu;
192 // "?" means "scale that font"
193 string popupfontname = lyxrc.popup_font_name
194 + "-*-*-*-?-*-*-*-*-"
195 + lyxrc.font_norm_menu;
197 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
198 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
200 lyxerr << "Could not set menu font to "
201 << menufontname << endl;
204 lyxerr << "Could not set popup font to "
205 << popupfontname << endl;
207 if (bold < 0 && normal < 0) {
208 lyxerr << "Using 'helvetica' font for menus" << endl;
209 bold = fl_set_font_name(FL_BOLD_STYLE,
210 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
211 normal = fl_set_font_name(FL_NORMAL_STYLE,
212 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
213 if (bold < 0 && normal < 0) {
214 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
215 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
219 // put here (after fl_initialize) to avoid segfault. Cannot be done
220 // in setDefaults() (Matthias 140496)
221 // Moved from ::LyXGUI to ::init to allow popup font customization
223 fl_setpup_fontstyle(FL_NORMAL_STYLE);
224 fl_setpup_fontsize(FL_NORMAL_SIZE);
225 fl_setpup_color(FL_MCOL, FL_BLACK);
226 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
228 // all lyxrc settings has to be done here as lyxrc has not yet
229 // been read when the GUI is created (Jug)
232 if (!lyxrc.custom_export_command.empty())
233 fl_set_input(fd_form_sendto->input_cmd,
234 lyxrc.custom_export_command.c_str());
235 if (lyxrc.custom_export_format == "lyx")
236 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
237 else if (lyxrc.custom_export_format == "tex")
238 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
239 else if (lyxrc.custom_export_format == "dvi")
240 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
241 else if (lyxrc.custom_export_format == "ps")
242 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
243 else if (lyxrc.custom_export_format == "ascii")
244 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
246 // Update parameters.
249 // Initialize the views.
252 // in 0.12 the initialisation of the LyXServer must be done here
253 // 0.13 it should be moved again...
254 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
258 void LyXGUI::create_forms()
260 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
261 lyxViews = new LyXView(width, height);
262 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
264 // From here down should be done by somebody else. (Lgb)
271 string banner_file = LibFileSearch("images", "banner", "xpm");
272 if (lyxrc.show_banner && !banner_file.empty()) {
273 fd_form_title = create_form_form_title();
274 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
275 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
276 fl_addto_form(fd_form_title->form_title);
277 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
278 fl_set_pixmapbutton_file(obj, banner_file.c_str());
280 fl_set_pixmapbutton_focus_outline(obj, 3);
281 fl_set_button_shortcut(obj, "^M ^[", 1);
282 fl_set_object_boxtype(obj, FL_NO_BOX);
283 fl_set_object_callback(obj, TimerCB, 0);
285 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
286 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
287 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
288 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
289 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
290 fl_set_object_lcol(obj, FL_FREE_COL3);
291 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
292 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
296 // the character form
297 fd_form_character = create_form_form_character();
298 fl_set_form_atclose(fd_form_character->form_character,
299 CancelCloseBoxCB, 0);
300 fl_addto_choice(fd_form_character->choice_family,
301 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
302 fl_addto_choice(fd_form_character->choice_series,
303 _(" No change %l| Medium | Bold %l| Reset "));
304 fl_addto_choice(fd_form_character->choice_shape,
305 _(" No change %l| Upright | Italic | Slanted | Small Caps "
307 fl_addto_choice(fd_form_character->choice_size,
308 _(" No change %l| Tiny | Smallest | Smaller | Small "
309 "| Normal | Large | Larger | Largest | Huge | Huger "
310 "%l| Increase | Decrease | Reset "));
311 fl_addto_choice(fd_form_character->choice_bar,
312 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
313 fl_addto_choice(fd_form_character->choice_color,
314 _(" No change %l| No color | Black | White | Red | Green "
315 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
316 fl_set_form_minsize(fd_form_character->form_character,
317 fd_form_character->form_character->w,
318 fd_form_character->form_character->h);
319 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
320 fl_addto_form(fd_form_character->form_character);
321 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
322 FL_OBJECT * ob = fd_form_character->choice_language;
323 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
324 combo_language2->shortcut("#L", 1);
326 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
328 // build up the combox entries
329 combo_language2->addto(_("No change"));
330 combo_language2->addto(_("Reset"));
331 for(Languages::const_iterator cit = languages.begin();
332 cit != languages.end(); ++cit) {
333 #ifdef DO_USE_DEFAULT_LANGUAGE
334 if ((*cit).second.lang() != "default")
336 combo_language2->addto((*cit).second.lang().c_str());
338 combo_language2->select_text(_("No change"));
341 fd_form_preamble = create_form_form_preamble();
342 fl_set_form_atclose(fd_form_preamble->form_preamble,
343 CancelCloseBoxCB, 0);
346 fd_form_sendto = create_form_form_sendto();
347 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
350 fd_form_figure = create_form_form_figure();
351 fl_set_form_atclose(fd_form_figure->form_figure,
352 CancelCloseBoxCB, 0);
353 fl_set_button(fd_form_figure->radio_postscript, 1);
355 // the latex log form
356 fd_latex_log = create_form_LaTeXLog();
357 fl_set_form_atclose(fd_latex_log->LaTeXLog,
358 CancelCloseBoxCB, 0);
360 // Show the main & title form
361 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
362 int title_placement = FL_PLACE_CENTER;
363 // Did we get a valid position?
364 if (xpos >= 0 && ypos >= 0) {
365 lyxViews->setPosition(xpos, ypos);
366 if (lyxrc.show_banner) {
367 // show the title form in the middle of the main form
368 fl_set_form_position(fd_form_title->form_title,
369 abs(xpos + (width/2) - (370 / 2)),
370 abs(ypos + (height/2) - (290 / 2)));
371 title_placement = FL_PLACE_GEOMETRY;
372 // The use of abs() above is a trick to ensure
375 main_placement = FL_PLACE_POSITION;
377 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
378 if (lyxrc.show_banner) {
379 fl_show_form(fd_form_title->form_title,
380 title_placement, FL_NOBORDER,
382 fl_redraw_form(fd_form_title->form_title);
383 fl_raise_form(fd_form_title->form_title);
385 // Show the title form at most 7 secs (lowered from 10 secs)
386 fl_set_timer(fd_form_title->timer_title, 7);
391 void LyXGUI::runTime()
395 guiruntime.runTime();
399 void LyXGUI::regBuf(Buffer * b)
401 lyxViews->view()->buffer(b);
405 LyXView * LyXGUI::getLyXView() const