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 * ====================================================== */
16 #pragma implementation
21 #include FORMS_H_LOCATION
22 #include "support/filetools.h"
26 #include "print_form.h"
27 #include "tex-strings.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"
42 #include "ColorHandler.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/GUIRunTime.h"
45 #include "frontends/xforms/xform_helpers.h" // for XformColor
49 FD_form_sendto * fd_form_sendto;
50 FD_form_figure * fd_form_figure;
52 extern LyXServer * lyxserver;
53 extern bool finished; // flag, that we are quitting the program
54 extern BufferList bufferlist;
55 extern GUIRunTime guiruntime;
56 extern string user_lyxdir;
60 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
63 static int width = 690;
64 static int height = 510;
67 static char geometry[40];
72 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
77 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
80 if (!bufferlist.empty())
81 bufferlist.emergencyWriteAll();
83 // Get the reason for the crash.
85 XGetErrorText(display, xeev->error_code, etxt, 512);
86 lyxerr << etxt << endl;
87 // By doing an abort we get a nice backtrace. (hopefully)
89 return 0; // Solaris CC wants us to return something
93 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
94 : _owner(owner), lyxViews(0)
103 static const int num_res = sizeof(res)/sizeof(FL_resource);
104 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
105 // It appears that, in xforms >=0.89.5, fl_initialize()
106 // calls setlocale() and ruins our LC_NUMERIC setting.
107 setlocale(LC_NUMERIC, "C");
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 = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(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 = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(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(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
150 // Recalculate ypos if it's negative
151 if (geometryBitmask & 32)
152 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(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
167 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
173 void LyXGUI::setDefaults()
175 GUIRunTime::setDefaults();
179 // This is called after we have parsed lyxrc
187 if (lyxrc.font_norm_menu.empty())
188 lyxrc.font_norm_menu = lyxrc.font_norm;
189 // Set the font name for popups and menus
190 string boldfontname = lyxrc.menu_font_name
191 + "-*-*-*-?-*-*-*-*-"
192 + lyxrc.font_norm_menu;
193 // "?" means "scale that font"
194 string fontname = lyxrc.popup_font_name
195 + "-*-*-*-?-*-*-*-*-"
196 + lyxrc.font_norm_menu;
198 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
199 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
201 lyxerr << "Could not set menu font to "
202 << boldfontname << endl;
205 lyxerr << "Could not set popup font to "
208 if (bold < 0 && normal < 0) {
209 lyxerr << "Using 'helvetica' font for menus" << endl;
210 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
211 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
212 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
213 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
215 if (bold < 0 && normal < 0) {
216 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
217 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
222 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
224 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
226 // put here (after fl_initialize) to avoid segfault. Cannot be done
227 // in setDefaults() (Matthias 140496)
228 // Moved from ::LyXGUI to ::init to allow popup font customization
230 fl_setpup_fontstyle(FL_NORMAL_STYLE);
231 fl_setpup_fontsize(FL_NORMAL_SIZE);
232 fl_setpup_color(FL_MCOL, FL_BLACK);
233 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
235 // all lyxrc settings has to be done here as lyxrc has not yet
236 // been read when the GUI is created (Jug)
239 if (!lyxrc.custom_export_command.empty())
240 fl_set_input(fd_form_sendto->input_cmd,
241 lyxrc.custom_export_command.c_str());
242 if (lyxrc.custom_export_format == "lyx")
243 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
244 else if (lyxrc.custom_export_format == "tex")
245 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
246 else if (lyxrc.custom_export_format == "dvi")
247 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
248 else if (lyxrc.custom_export_format == "ps")
249 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
250 else if (lyxrc.custom_export_format == "ascii")
251 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
253 // Update parameters.
256 // Initialize the views.
259 // in 0.12 the initialisation of the LyXServer must be done here
260 // 0.13 it should be moved again...
261 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
265 void LyXGUI::create_forms()
267 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
268 lyxViews = new LyXView(width, height);
269 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
271 // From here down should be done by somebody else. (Lgb)
278 fd_form_sendto = create_form_form_sendto();
279 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
282 fd_form_figure = create_form_form_figure();
283 fl_set_form_atclose(fd_form_figure->form_figure,
284 CancelCloseBoxCB, 0);
285 fl_set_button(fd_form_figure->radio_postscript, 1);
287 // This is probably as good a time as any to map the xform colours,
288 // should a mapping exist.
290 string filename = AddName(user_lyxdir, "preferences.xform");
291 XformColor::read( filename );
294 // Show the main & title form
295 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
296 // Did we get a valid position?
297 if (xpos >= 0 && ypos >= 0) {
298 lyxViews->setPosition(xpos, ypos);
299 main_placement = FL_PLACE_POSITION;
302 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
304 if (lyxrc.show_banner)
305 lyxViews->getDialogs()->showSplash();
309 void LyXGUI::runTime()
313 guiruntime.runTime();
317 void LyXGUI::regBuf(Buffer * b)
319 lyxViews->view()->buffer(b);
323 LyXView * LyXGUI::getLyXView() const