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 "print_form.h"
26 #include "tex-strings.h"
32 #include "lyxserver.h"
35 #include "lyx_gui_misc.h"
36 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
37 #include "lyxlookup.h"
39 #include "bufferlist.h"
40 #include "ColorHandler.h"
41 #include "frontends/Dialogs.h"
42 #include "frontends/GUIRunTime.h"
43 #include "frontends/xforms/xforms_helpers.h" // for XformColor
47 FD_form_sendto * fd_form_sendto;
48 FD_form_figure * fd_form_figure;
50 extern LyXServer * lyxserver;
51 extern bool finished; // flag, that we are quitting the program
52 extern BufferList bufferlist;
53 extern GUIRunTime guiruntime;
54 extern string user_lyxdir;
58 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
61 static int width = 690;
62 static int height = 510;
65 static char geometry[40];
70 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
75 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
78 if (!bufferlist.empty())
79 bufferlist.emergencyWriteAll();
81 // Get the reason for the crash.
83 XGetErrorText(display, xeev->error_code, etxt, 512);
84 lyxerr << etxt << endl;
85 // By doing an abort we get a nice backtrace. (hopefully)
87 return 0; // Solaris CC wants us to return something
91 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
92 : _owner(owner), lyxViews(0)
101 static const int num_res = sizeof(res)/sizeof(FL_resource);
102 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
103 // It appears that, in xforms >=0.89.5, fl_initialize()
104 // calls setlocale() and ruins our LC_NUMERIC setting.
106 fl_get_app_resources(res, num_res);
108 static const int geometryBitmask =
109 XParseGeometry( geometry,
112 reinterpret_cast<unsigned int *>(&width),
113 reinterpret_cast<unsigned int *>(&height));
115 Display * display = fl_get_display();
117 lyxerr << "LyX: unable to access X display, exiting" << endl;
120 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
121 // X Error handler install goes here
122 XSetErrorHandler(LyX_XErrHandler);
124 // A width less than 590 pops up an awkward main window
125 // The minimal values of width/height (590/400) are defined in
127 if (width < 590) width = 590;
128 if (height < 400) height = 400;
130 // If width is not set by geometry, check it against monitor width
131 if (!(geometryBitmask & 4)) {
132 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
133 if (WidthOfScreen(scr) - 8 < width)
134 width = WidthOfScreen(scr) - 8;
137 // If height is not set by geometry, check it against monitor height
138 if (!(geometryBitmask & 8)) {
139 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
140 if (HeightOfScreen(scr) - 24 < height)
141 height = HeightOfScreen(scr) - 24;
144 // Recalculate xpos if it's negative
145 if (geometryBitmask & 16)
146 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
148 // Recalculate ypos if it's negative
149 if (geometryBitmask & 32)
150 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - height;
152 // Initialize the LyXColorHandler
153 lyxColorHandler.reset(new LyXColorHandler);
157 // A destructor is always necessary (asierra-970604)
160 // Lyxserver was created in this class so should be destroyed
161 // here. asierra-970604
165 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
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 boldfontname = lyxrc.menu_font_name
189 + "-*-*-*-?-*-*-*-*-"
190 + lyxrc.font_norm_menu;
191 // "?" means "scale that font"
192 string fontname = lyxrc.popup_font_name
193 + "-*-*-*-?-*-*-*-*-"
194 + lyxrc.font_norm_menu;
196 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
197 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
199 lyxerr << "Could not set menu font to "
200 << boldfontname << endl;
203 lyxerr << "Could not set popup font to "
206 if (bold < 0 && normal < 0) {
207 lyxerr << "Using 'helvetica' font for menus" << endl;
208 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
209 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
210 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
211 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
213 if (bold < 0 && normal < 0) {
214 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
215 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
220 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
222 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
224 // put here (after fl_initialize) to avoid segfault. Cannot be done
225 // in setDefaults() (Matthias 140496)
226 // Moved from ::LyXGUI to ::init to allow popup font customization
228 fl_setpup_fontstyle(FL_NORMAL_STYLE);
229 fl_setpup_fontsize(FL_NORMAL_SIZE);
230 fl_setpup_color(FL_MCOL, FL_BLACK);
231 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
233 // all lyxrc settings has to be done here as lyxrc has not yet
234 // been read when the GUI is created (Jug)
237 if (!lyxrc.custom_export_command.empty())
238 fl_set_input(fd_form_sendto->input_cmd,
239 lyxrc.custom_export_command.c_str());
240 if (lyxrc.custom_export_format == "lyx")
241 fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
242 else if (lyxrc.custom_export_format == "tex")
243 fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
244 else if (lyxrc.custom_export_format == "dvi")
245 fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
246 else if (lyxrc.custom_export_format == "ps")
247 fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
248 else if (lyxrc.custom_export_format == "ascii")
249 fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
251 // Update parameters.
254 // Initialize the views.
257 // in 0.12 the initialisation of the LyXServer must be done here
258 // 0.13 it should be moved again...
259 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
263 void LyXGUI::create_forms()
265 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
266 lyxViews = new LyXView(width, height);
267 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
269 // From here down should be done by somebody else. (Lgb)
276 fd_form_sendto = create_form_form_sendto();
277 fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
280 fd_form_figure = create_form_form_figure();
281 fl_set_form_atclose(fd_form_figure->form_figure,
282 CancelCloseBoxCB, 0);
283 fl_set_button(fd_form_figure->radio_postscript, 1);
285 // This is probably as good a time as any to map the xform colours,
286 // should a mapping exist.
288 string filename = AddName(user_lyxdir, "preferences.xform");
289 XformsColor::read( filename );
292 // Show the main & title form
293 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
294 // Did we get a valid position?
295 if (xpos >= 0 && ypos >= 0) {
296 lyxViews->setPosition(xpos, ypos);
297 main_placement = FL_PLACE_POSITION;
300 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
302 if (lyxrc.show_banner)
303 lyxViews->getDialogs()->showSplash();
307 void LyXGUI::runTime()
311 guiruntime.runTime();
315 void LyXGUI::regBuf(Buffer * b)
317 lyxViews->view()->buffer(b);
321 LyXView * LyXGUI::getLyXView() const