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)
82 if (!bufferlist.empty())
83 bufferlist.emergencyWriteAll();
85 // Get the reason for the crash.
87 XGetErrorText(display, xeev->error_code, etxt, 512);
88 lyxerr << etxt << endl;
89 // By doing an abort we get a nice backtrace. (hopefully)
91 return 0; // Solaris CC wants us to return something
95 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
96 : _owner(owner), lyxViews(0)
105 static const int num_res = sizeof(res)/sizeof(FL_resource);
106 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
107 fl_get_app_resources(res, num_res);
109 static const int geometryBitmask =
110 XParseGeometry( geometry,
113 reinterpret_cast<unsigned int *>(&width),
114 reinterpret_cast<unsigned int *>(&height));
116 Display * display = fl_get_display();
118 lyxerr << "LyX: unable to access X display, exiting" << endl;
121 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
122 // X Error handler install goes here
123 XSetErrorHandler(LyX_XErrHandler);
125 // A width less than 590 pops up an awkward main window
126 // The minimal values of width/height (590/400) are defined in
128 if (width < 590) width = 590;
129 if (height < 400) height = 400;
131 // If width is not set by geometry, check it against monitor width
132 if ( !(geometryBitmask & 4) ) {
133 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
134 if (WidthOfScreen(scr) - 8 < width)
135 width = WidthOfScreen(scr) - 8;
138 // If height is not set by geometry, check it against monitor height
139 if ( !(geometryBitmask & 8) ) {
140 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
141 if (HeightOfScreen(scr) - 24 < height)
142 height = HeightOfScreen(scr) - 24;
145 // Recalculate xpos if it's negative
146 if (geometryBitmask & 16)
147 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
149 // Recalculate ypos if it's negative
150 if (geometryBitmask & 32)
151 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height;
153 // Initialize the LyXColorHandler
154 lyxColorHandler = new LyXColorHandler;
158 // A destructor is always necessary (asierra-970604)
161 // Lyxserver was created in this class so should be destroyed
162 // here. asierra-970604
171 void LyXGUI::setDefaults()
173 GUIRunTime::setDefaults();
177 // This is called after we have parsed lyxrc
185 if (lyxrc.font_norm_menu.empty())
186 lyxrc.font_norm_menu = lyxrc.font_norm;
187 // Set the font name for popups and menus
188 string menufontname = lyxrc.menu_font_name
189 + "-*-*-*-?-*-*-*-*-"
190 + lyxrc.font_norm_menu;
191 // "?" means "scale that font"
192 string popupfontname = lyxrc.popup_font_name
193 + "-*-*-*-?-*-*-*-*-"
194 + lyxrc.font_norm_menu;
196 int bold = fl_set_font_name(FL_BOLD_STYLE, menufontname.c_str());
197 int normal = fl_set_font_name(FL_NORMAL_STYLE, popupfontname.c_str());
199 lyxerr << "Could not set menu font to "
200 << menufontname << endl;
203 lyxerr << "Could not set popup font to "
204 << popupfontname << endl;
206 if (bold < 0 && normal < 0) {
207 lyxerr << "Using 'helvetica' font for menus" << endl;
208 bold = fl_set_font_name(FL_BOLD_STYLE,
209 "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1");
210 normal = fl_set_font_name(FL_NORMAL_STYLE,
211 "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1");
212 if (bold < 0 && normal < 0) {
213 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
214 normal = fl_set_font_name(FL_NORMAL_STYLE, "fixed");
218 // put here (after fl_initialize) to avoid segfault. Cannot be done
219 // in setDefaults() (Matthias 140496)
220 // Moved from ::LyXGUI to ::init to allow popup font customization
222 fl_setpup_fontstyle(FL_NORMAL_STYLE);
223 fl_setpup_fontsize(FL_NORMAL_SIZE);
224 fl_setpup_color(FL_MCOL, FL_BLACK);
225 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
227 // all lyxrc settings has to be done here as lyxrc has not yet
228 // been read when the GUI is created (Jug)
231 if (!lyxrc.custom_export_command.empty())
232 fl_set_input(fd_form_sendto->input_cmd,
233 lyxrc.custom_export_command.c_str());
234 if (lyxrc.custom_export_format == "lyx")
235 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
236 else if (lyxrc.custom_export_format == "tex")
237 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
238 else if (lyxrc.custom_export_format == "dvi")
239 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
240 else if (lyxrc.custom_export_format == "ps")
241 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
242 else if (lyxrc.custom_export_format == "ascii")
243 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
245 // Update parameters.
248 // Initialize the views.
251 // in 0.12 the initialisation of the LyXServer must be done here
252 // 0.13 it should be moved again...
253 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
257 void LyXGUI::create_forms()
259 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
260 lyxViews = new LyXView(width, height);
261 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
263 // From here down should be done by somebody else. (Lgb)
270 string banner_file = LibFileSearch("images", "banner", "xpm");
271 if (lyxrc.show_banner && !banner_file.empty()) {
272 fd_form_title = create_form_form_title();
273 fl_set_form_dblbuffer(fd_form_title->form_title, 1); // use dbl buffer
274 fl_set_form_atclose(fd_form_title->form_title, CancelCloseBoxCB, 0);
275 fl_addto_form(fd_form_title->form_title);
276 FL_OBJECT *obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, "");
277 fl_set_pixmapbutton_file(obj, banner_file.c_str());
279 fl_set_pixmapbutton_focus_outline(obj, 3);
280 fl_set_button_shortcut(obj, "^M ^[", 1);
281 fl_set_object_boxtype(obj, FL_NO_BOX);
282 fl_set_object_callback(obj, TimerCB, 0);
284 obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION);
285 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
286 fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c);
287 fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b);
288 fl_set_object_color(obj, FL_FREE_COL2, FL_FREE_COL2);
289 fl_set_object_lcol(obj, FL_FREE_COL3);
290 fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
291 fl_set_object_lstyle(obj, FL_BOLD_STYLE);
295 // the character form
296 fd_form_character = create_form_form_character();
297 fl_set_form_atclose(fd_form_character->form_character,
298 CancelCloseBoxCB, 0);
299 fl_addto_choice(fd_form_character->choice_family,
300 _(" No change %l| Roman | Sans Serif | Typewriter %l| Reset "));
301 fl_addto_choice(fd_form_character->choice_series,
302 _(" No change %l| Medium | Bold %l| Reset "));
303 fl_addto_choice(fd_form_character->choice_shape,
304 _(" No change %l| Upright | Italic | Slanted | Small Caps "
306 fl_addto_choice(fd_form_character->choice_size,
307 _(" No change %l| Tiny | Smallest | Smaller | Small "
308 "| Normal | Large | Larger | Largest | Huge | Huger "
309 "%l| Increase | Decrease | Reset "));
310 fl_addto_choice(fd_form_character->choice_bar,
311 _(" No change %l| Emph | Underbar | Noun | LaTeX mode %l| Reset "));
312 fl_addto_choice(fd_form_character->choice_color,
313 _(" No change %l| No color | Black | White | Red | Green "
314 "| Blue | Cyan | Magenta | Yellow %l| Reset "));
315 fl_set_form_minsize(fd_form_character->form_character,
316 fd_form_character->form_character->w,
317 fd_form_character->form_character->h);
318 lyxerr[Debug::INIT] << "Initializing form_character::combox..." << endl;
319 fl_addto_form(fd_form_character->form_character);
320 combo_language2 = new Combox(FL_COMBOX_DROPLIST);
321 FL_OBJECT * ob = fd_form_character->choice_language;
322 combo_language2->add(ob->x, ob->y, ob->w, ob->h, 250);
323 combo_language2->shortcut("#L", 1);
325 lyxerr[Debug::INIT] << "Initializing form_character...done" << endl;
327 // build up the combox entries
328 combo_language2->addto(_("No change"));
329 combo_language2->addto(_("Reset"));
330 for(Languages::const_iterator cit = languages.begin();
331 cit != languages.end(); ++cit) {
332 #ifdef DO_USE_DEFAULT_LANGUAGE
333 if ((*cit).second.lang() != "default")
335 combo_language2->addto((*cit).second.lang());
337 combo_language2->select_text(_("No change"));
340 fd_form_preamble = create_form_form_preamble();
341 fl_set_form_atclose(fd_form_preamble->form_preamble,
342 CancelCloseBoxCB, 0);
345 fd_form_sendto = create_form_form_sendto();
346 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
349 fd_form_figure = create_form_form_figure();
350 fl_set_form_atclose(fd_form_figure->form_figure,
351 CancelCloseBoxCB, 0);
352 fl_set_button(fd_form_figure->radio_postscript, 1);
354 // the latex log form
355 fd_latex_log = create_form_LaTeXLog();
356 fl_set_form_atclose(fd_latex_log->LaTeXLog,
357 CancelCloseBoxCB, 0);
359 // Show the main & title form
360 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
361 int title_placement = FL_PLACE_CENTER;
362 // Did we get a valid position?
363 if (xpos >= 0 && ypos >= 0) {
364 lyxViews->setPosition(xpos, ypos);
365 if (lyxrc.show_banner) {
366 // show the title form in the middle of the main form
367 fl_set_form_position(fd_form_title->form_title,
368 abs(xpos + (width/2) - (370 / 2)),
369 abs(ypos + (height/2) - (290 / 2)));
370 title_placement = FL_PLACE_GEOMETRY;
371 // The use of abs() above is a trick to ensure
374 main_placement = FL_PLACE_POSITION;
376 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
377 if (lyxrc.show_banner) {
378 fl_show_form(fd_form_title->form_title,
379 title_placement, FL_NOBORDER,
381 fl_redraw_form(fd_form_title->form_title);
382 fl_raise_form(fd_form_title->form_title);
384 // Show the title form at most 7 secs (lowered from 10 secs)
385 fl_set_timer(fd_form_title->timer_title, 7);
390 void LyXGUI::runTime()
394 guiruntime.runTime();
398 void LyXGUI::regBuf(Buffer * b)
400 lyxViews->view()->buffer(b);
404 LyXView * LyXGUI::getLyXView() const