1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
18 #include FORMS_H_LOCATION
19 #include "figure_form.h"
20 #include "print_form.h"
21 #include "tex-strings.h"
27 #include "BufferView.h"
28 #include "lyxserver.h"
31 #include "lyx_gui_misc.h"
32 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
33 #include "lyxlookup.h"
35 #include "bufferlist.h"
36 #include "ColorHandler.h"
38 #include "frontends/GUIRunTime.h"
39 #include "frontends/xforms/xforms_helpers.h" // for XformColor
41 #include "support/filetools.h"
42 #include "support/os.h"
43 #include "support/lyxlib.h"
50 FD_form_sendto * fd_form_sendto;
51 FD_form_figure * fd_form_figure;
53 extern LyXServer * lyxserver;
54 extern bool finished; // flag, that we are quitting the program
55 extern BufferList bufferlist;
56 extern string user_lyxdir;
60 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
76 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
83 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
86 LyX::emergencyCleanup();
88 // Get the reason for the crash.
90 XGetErrorText(display, xeev->error_code, etxt, 512);
91 lyxerr << etxt << endl;
92 // By doing an abort we get a nice backtrace. (hopefully)
94 return 0; // Solaris CC wants us to return something
100 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
101 : _owner(owner), lyxViews(0)
110 static const int num_res = sizeof(res)/sizeof(FL_resource);
111 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
112 // It appears that, in xforms >=0.89.5, fl_initialize()
113 // calls setlocale() and ruins our LC_NUMERIC setting.
115 fl_get_app_resources(res, num_res);
117 static const int geometryBitmask =
118 XParseGeometry( geometry,
121 reinterpret_cast<unsigned int *>(&width),
122 reinterpret_cast<unsigned int *>(&height));
124 Display * display = fl_get_display();
126 lyxerr << "LyX: unable to access X display, exiting" << endl;
127 os::warn("Unable to access X display, exiting");
130 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
131 // X Error handler install goes here
132 XSetErrorHandler(LyX_XErrHandler);
134 // A width less than 590 pops up an awkward main window
135 // The minimal values of width/height (590/400) are defined in
137 if (width < 590) width = 590;
138 if (height < 400) height = 400;
140 // If width is not set by geometry, check it against monitor width
141 if (!(geometryBitmask & 4)) {
142 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
143 if (WidthOfScreen(scr) - 8 < width)
144 width = WidthOfScreen(scr) - 8;
147 // If height is not set by geometry, check it against monitor height
148 if (!(geometryBitmask & 8)) {
149 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
150 if (HeightOfScreen(scr) - 24 < height)
151 height = HeightOfScreen(scr) - 24;
154 // Recalculate xpos if it's negative
155 if (geometryBitmask & 16)
156 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(),
159 // Recalculate ypos if it's negative
160 if (geometryBitmask & 32)
161 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(),
162 fl_screen)) - height;
164 // Initialize the LyXColorHandler
165 lyxColorHandler.reset(new LyXColorHandler);
169 // A destructor is always necessary (asierra-970604)
172 // Lyxserver was created in this class so should be destroyed
173 // here. asierra-970604
177 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
183 void LyXGUI::setDefaults()
185 GUIRunTime::setDefaults();
189 // This is called after we have parsed lyxrc
197 if (lyxrc.font_norm_menu.empty())
198 lyxrc.font_norm_menu = lyxrc.font_norm;
199 // Set the font name for popups and menus
200 string boldfontname = lyxrc.menu_font_name
201 + "-*-*-*-?-*-*-*-*-"
202 + lyxrc.font_norm_menu;
203 // "?" means "scale that font"
204 string fontname = lyxrc.popup_font_name
205 + "-*-*-*-?-*-*-*-*-"
206 + lyxrc.font_norm_menu;
208 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
209 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
211 lyxerr << "Could not set menu font to "
212 << boldfontname << endl;
215 lyxerr << "Could not set popup font to "
218 if (bold < 0 && normal < 0) {
219 lyxerr << "Using 'helvetica' font for menus" << endl;
220 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
221 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
222 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
223 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
225 if (bold < 0 && normal < 0) {
226 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
227 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
232 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
234 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
236 // put here (after fl_initialize) to avoid segfault. Cannot be done
237 // in setDefaults() (Matthias 140496)
238 // Moved from ::LyXGUI to ::init to allow popup font customization
240 fl_setpup_fontstyle(FL_BOLD_STYLE);
241 fl_setpup_fontsize(FL_NORMAL_SIZE);
242 fl_setpup_color(FL_MCOL, FL_BLACK);
243 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
245 // all lyxrc settings has to be done here as lyxrc has not yet
246 // been read when the GUI is created (Jug)
249 if (!lyxrc.custom_export_command.empty())
250 fl_set_input(fd_form_sendto->input_cmd,
251 lyxrc.custom_export_command.c_str());
252 if (lyxrc.custom_export_format == "lyx")
253 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
254 else if (lyxrc.custom_export_format == "tex")
255 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
256 else if (lyxrc.custom_export_format == "dvi")
257 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
258 else if (lyxrc.custom_export_format == "ps")
259 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
260 else if (lyxrc.custom_export_format == "ascii")
261 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
263 // Update parameters.
266 // Initialize the views.
269 // in 0.12 the initialisation of the LyXServer must be done here
270 // 0.13 it should be moved again...
271 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
275 void LyXGUI::create_forms()
277 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
278 lyxViews = GUIRunTime::createMainView(width, height);
279 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
281 // From here down should be done by somebody else. (Lgb)
288 fd_form_sendto = create_form_form_sendto();
289 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
292 fd_form_figure = create_form_form_figure();
293 fl_set_form_atclose(fd_form_figure->form_figure,
294 CancelCloseBoxCB, 0);
295 fl_set_button(fd_form_figure->radio_postscript, 1);
297 // This is probably as good a time as any to map the xform colours,
298 // should a mapping exist.
299 string const filename = AddName(user_lyxdir, "preferences.xform");
300 XformsColor::read( filename );
302 // Show the main & title form
303 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
304 // Did we get a valid position?
305 if (xpos >= 0 && ypos >= 0) {
306 lyxViews->setPosition(xpos, ypos);
307 main_placement = FL_PLACE_POSITION;
310 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
314 void LyXGUI::runTime()
318 GUIRunTime::runTime();
322 void LyXGUI::regBuf(Buffer * b)
324 lyxViews->view()->buffer(b);
328 LyXView * LyXGUI::getLyXView() const