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 * ====================================================== */
16 #pragma implementation
20 #include FORMS_H_LOCATION
21 #include "support/filetools.h"
22 #include "support/os.h"
23 #include "support/lyxlib.h"
24 #include "figure_form.h"
25 #include "print_form.h"
26 #include "tex-strings.h"
32 #include "BufferView.h"
33 #include "lyxserver.h"
36 #include "lyx_gui_misc.h"
37 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
38 #include "lyxlookup.h"
40 #include "bufferlist.h"
41 #include "ColorHandler.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/GUIRunTime.h"
44 #include "frontends/xforms/xforms_helpers.h" // for XformColor
48 FD_form_sendto * fd_form_sendto;
49 FD_form_figure * fd_form_figure;
51 extern LyXServer * lyxserver;
52 extern bool finished; // flag, that we are quitting the program
53 extern BufferList bufferlist;
54 extern string user_lyxdir;
58 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
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 // It appears that, in xforms >=0.89.5, fl_initialize()
108 // calls setlocale() and ruins our LC_NUMERIC setting.
110 fl_get_app_resources(res, num_res);
112 static const int geometryBitmask =
113 XParseGeometry( geometry,
116 reinterpret_cast<unsigned int *>(&width),
117 reinterpret_cast<unsigned int *>(&height));
119 Display * display = fl_get_display();
121 lyxerr << "LyX: unable to access X display, exiting" << endl;
122 os::warn("Unable to access X display, exiting");
125 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
126 // X Error handler install goes here
127 XSetErrorHandler(LyX_XErrHandler);
129 // A width less than 590 pops up an awkward main window
130 // The minimal values of width/height (590/400) are defined in
132 if (width < 590) width = 590;
133 if (height < 400) height = 400;
135 // If width is not set by geometry, check it against monitor width
136 if (!(geometryBitmask & 4)) {
137 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
138 if (WidthOfScreen(scr) - 8 < width)
139 width = WidthOfScreen(scr) - 8;
142 // If height is not set by geometry, check it against monitor height
143 if (!(geometryBitmask & 8)) {
144 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
145 if (HeightOfScreen(scr) - 24 < height)
146 height = HeightOfScreen(scr) - 24;
149 // Recalculate xpos if it's negative
150 if (geometryBitmask & 16)
151 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
153 // Recalculate ypos if it's negative
154 if (geometryBitmask & 32)
155 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height;
157 // Initialize the LyXColorHandler
158 lyxColorHandler.reset(new LyXColorHandler);
162 // A destructor is always necessary (asierra-970604)
165 // Lyxserver was created in this class so should be destroyed
166 // here. asierra-970604
170 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
176 void LyXGUI::setDefaults()
178 GUIRunTime::setDefaults();
182 // This is called after we have parsed lyxrc
190 if (lyxrc.font_norm_menu.empty())
191 lyxrc.font_norm_menu = lyxrc.font_norm;
192 // Set the font name for popups and menus
193 string boldfontname = lyxrc.menu_font_name
194 + "-*-*-*-?-*-*-*-*-"
195 + lyxrc.font_norm_menu;
196 // "?" means "scale that font"
197 string fontname = lyxrc.popup_font_name
198 + "-*-*-*-?-*-*-*-*-"
199 + lyxrc.font_norm_menu;
201 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
202 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
204 lyxerr << "Could not set menu font to "
205 << boldfontname << endl;
208 lyxerr << "Could not set popup font to "
211 if (bold < 0 && normal < 0) {
212 lyxerr << "Using 'helvetica' font for menus" << endl;
213 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
214 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
215 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
216 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
218 if (bold < 0 && normal < 0) {
219 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
220 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
225 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
227 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
229 // put here (after fl_initialize) to avoid segfault. Cannot be done
230 // in setDefaults() (Matthias 140496)
231 // Moved from ::LyXGUI to ::init to allow popup font customization
233 fl_setpup_fontstyle(FL_NORMAL_STYLE);
234 fl_setpup_fontsize(FL_NORMAL_SIZE);
235 fl_setpup_color(FL_MCOL, FL_BLACK);
236 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
238 // all lyxrc settings has to be done here as lyxrc has not yet
239 // been read when the GUI is created (Jug)
242 if (!lyxrc.custom_export_command.empty())
243 fl_set_input(fd_form_sendto->input_cmd,
244 lyxrc.custom_export_command.c_str());
245 if (lyxrc.custom_export_format == "lyx")
246 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
247 else if (lyxrc.custom_export_format == "tex")
248 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
249 else if (lyxrc.custom_export_format == "dvi")
250 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
251 else if (lyxrc.custom_export_format == "ps")
252 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
253 else if (lyxrc.custom_export_format == "ascii")
254 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
256 // Update parameters.
259 // Initialize the views.
262 // in 0.12 the initialisation of the LyXServer must be done here
263 // 0.13 it should be moved again...
264 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
268 void LyXGUI::create_forms()
270 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
271 lyxViews = GUIRunTime::createMainView(width, height);
272 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
274 // From here down should be done by somebody else. (Lgb)
281 fd_form_sendto = create_form_form_sendto();
282 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
285 fd_form_figure = create_form_form_figure();
286 fl_set_form_atclose(fd_form_figure->form_figure,
287 CancelCloseBoxCB, 0);
288 fl_set_button(fd_form_figure->radio_postscript, 1);
290 // This is probably as good a time as any to map the xform colours,
291 // should a mapping exist.
293 string filename = AddName(user_lyxdir, "preferences.xform");
294 XformsColor::read( filename );
297 // Show the main & title form
298 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
299 // Did we get a valid position?
300 if (xpos >= 0 && ypos >= 0) {
301 lyxViews->setPosition(xpos, ypos);
302 main_placement = FL_PLACE_POSITION;
305 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
307 if (lyxrc.show_banner)
308 lyxViews->getDialogs()->showSplash();
312 void LyXGUI::runTime()
316 GUIRunTime::runTime();
320 void LyXGUI::regBuf(Buffer * b)
322 lyxViews->view()->buffer(b);
326 LyXView * LyXGUI::getLyXView() const