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"
24 #include "print_form.h"
25 #include "tex-strings.h"
31 #include "lyxserver.h"
34 #include "lyx_gui_misc.h"
35 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
36 #include "lyxlookup.h"
38 #include "bufferlist.h"
39 #include "ColorHandler.h"
40 #include "frontends/Dialogs.h"
41 #include "frontends/GUIRunTime.h"
42 #include "frontends/xforms/xforms_helpers.h" // for XformColor
46 FD_form_sendto * fd_form_sendto;
47 FD_form_figure * fd_form_figure;
49 extern LyXServer * lyxserver;
50 extern bool finished; // flag, that we are quitting the program
51 extern BufferList bufferlist;
52 extern GUIRunTime guiruntime;
53 extern string user_lyxdir;
57 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
60 static int width = 690;
61 static int height = 510;
64 static char geometry[40];
69 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
74 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
77 if (!bufferlist.empty())
78 bufferlist.emergencyWriteAll();
80 // Get the reason for the crash.
82 XGetErrorText(display, xeev->error_code, etxt, 512);
83 lyxerr << etxt << endl;
84 // By doing an abort we get a nice backtrace. (hopefully)
86 return 0; // Solaris CC wants us to return something
90 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
91 : _owner(owner), lyxViews(0)
100 static const int num_res = sizeof(res)/sizeof(FL_resource);
101 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
102 // It appears that, in xforms >=0.89.5, fl_initialize()
103 // calls setlocale() and ruins our LC_NUMERIC setting.
105 fl_get_app_resources(res, num_res);
107 static const int geometryBitmask =
108 XParseGeometry( geometry,
111 reinterpret_cast<unsigned int *>(&width),
112 reinterpret_cast<unsigned int *>(&height));
114 Display * display = fl_get_display();
116 lyxerr << "LyX: unable to access X display, exiting" << endl;
119 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
120 // X Error handler install goes here
121 XSetErrorHandler(LyX_XErrHandler);
123 // A width less than 590 pops up an awkward main window
124 // The minimal values of width/height (590/400) are defined in
126 if (width < 590) width = 590;
127 if (height < 400) height = 400;
129 // If width is not set by geometry, check it against monitor width
130 if (!(geometryBitmask & 4)) {
131 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
132 if (WidthOfScreen(scr) - 8 < width)
133 width = WidthOfScreen(scr) - 8;
136 // If height is not set by geometry, check it against monitor height
137 if (!(geometryBitmask & 8)) {
138 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
139 if (HeightOfScreen(scr) - 24 < height)
140 height = HeightOfScreen(scr) - 24;
143 // Recalculate xpos if it's negative
144 if (geometryBitmask & 16)
145 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
147 // Recalculate ypos if it's negative
148 if (geometryBitmask & 32)
149 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height;
151 // Initialize the LyXColorHandler
152 lyxColorHandler.reset(new LyXColorHandler);
156 // A destructor is always necessary (asierra-970604)
159 // Lyxserver was created in this class so should be destroyed
160 // here. asierra-970604
164 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
170 void LyXGUI::setDefaults()
172 GUIRunTime::setDefaults();
176 // This is called after we have parsed lyxrc
184 if (lyxrc.font_norm_menu.empty())
185 lyxrc.font_norm_menu = lyxrc.font_norm;
186 // Set the font name for popups and menus
187 string boldfontname = lyxrc.menu_font_name
188 + "-*-*-*-?-*-*-*-*-"
189 + lyxrc.font_norm_menu;
190 // "?" means "scale that font"
191 string fontname = lyxrc.popup_font_name
192 + "-*-*-*-?-*-*-*-*-"
193 + lyxrc.font_norm_menu;
195 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
196 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
198 lyxerr << "Could not set menu font to "
199 << boldfontname << endl;
202 lyxerr << "Could not set popup font to "
205 if (bold < 0 && normal < 0) {
206 lyxerr << "Using 'helvetica' font for menus" << endl;
207 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
208 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
209 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
210 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
212 if (bold < 0 && normal < 0) {
213 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
214 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
219 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
221 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
223 // put here (after fl_initialize) to avoid segfault. Cannot be done
224 // in setDefaults() (Matthias 140496)
225 // Moved from ::LyXGUI to ::init to allow popup font customization
227 fl_setpup_fontstyle(FL_NORMAL_STYLE);
228 fl_setpup_fontsize(FL_NORMAL_SIZE);
229 fl_setpup_color(FL_MCOL, FL_BLACK);
230 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
232 // all lyxrc settings has to be done here as lyxrc has not yet
233 // been read when the GUI is created (Jug)
236 if (!lyxrc.custom_export_command.empty())
237 fl_set_input(fd_form_sendto->input_cmd,
238 lyxrc.custom_export_command.c_str());
239 if (lyxrc.custom_export_format == "lyx")
240 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
241 else if (lyxrc.custom_export_format == "tex")
242 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
243 else if (lyxrc.custom_export_format == "dvi")
244 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
245 else if (lyxrc.custom_export_format == "ps")
246 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
247 else if (lyxrc.custom_export_format == "ascii")
248 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
250 // Update parameters.
253 // Initialize the views.
256 // in 0.12 the initialisation of the LyXServer must be done here
257 // 0.13 it should be moved again...
258 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
262 void LyXGUI::create_forms()
264 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
265 lyxViews = new LyXView(width, height);
266 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
268 // From here down should be done by somebody else. (Lgb)
275 fd_form_sendto = create_form_form_sendto();
276 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
279 fd_form_figure = create_form_form_figure();
280 fl_set_form_atclose(fd_form_figure->form_figure,
281 CancelCloseBoxCB, 0);
282 fl_set_button(fd_form_figure->radio_postscript, 1);
284 // This is probably as good a time as any to map the xform colours,
285 // should a mapping exist.
287 string filename = AddName(user_lyxdir, "preferences.xform");
288 XformsColor::read( filename );
291 // Show the main & title form
292 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
293 // Did we get a valid position?
294 if (xpos >= 0 && ypos >= 0) {
295 lyxViews->setPosition(xpos, ypos);
296 main_placement = FL_PLACE_POSITION;
299 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
301 if (lyxrc.show_banner)
302 lyxViews->getDialogs()->showSplash();
306 void LyXGUI::runTime()
310 guiruntime.runTime();
314 void LyXGUI::regBuf(Buffer * b)
316 lyxViews->view()->buffer(b);
320 LyXView * LyXGUI::getLyXView() const