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 "tex-strings.h"
25 #include "BufferView.h"
26 #include "lyxserver.h"
29 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
30 #include "lyxlookup.h"
32 #include "bufferlist.h"
33 #include "ColorHandler.h"
35 #include "frontends/GUIRunTime.h"
36 #include "frontends/xforms/xforms_helpers.h" // for XformColor
38 #include "support/filetools.h"
39 #include "support/os.h"
40 #include "support/lyxlib.h"
47 extern LyXServer * lyxserver;
48 extern bool finished; // flag, that we are quitting the program
49 extern BufferList bufferlist;
50 extern string user_lyxdir;
54 {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
70 {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
77 int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
80 LyX::emergencyCleanup();
82 // Get the reason for the crash.
84 XGetErrorText(display, xeev->error_code, etxt, 512);
85 lyxerr << etxt << " id: " << xeev->resourceid << endl;
86 // By doing an abort we get a nice backtrace. (hopefully)
88 return 0; // Solaris CC wants us to return something
94 LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
95 : _owner(owner), lyxViews(0)
104 static const int num_res = sizeof(res)/sizeof(FL_resource);
105 fl_initialize(argc, argv, "LyX", cmdopt, num_res);
106 // It appears that, in xforms >=0.89.5, fl_initialize()
107 // calls setlocale() and ruins our LC_NUMERIC setting.
109 fl_get_app_resources(res, num_res);
111 static const int geometryBitmask =
112 XParseGeometry(geometry,
115 reinterpret_cast<unsigned int *>(&width),
116 reinterpret_cast<unsigned int *>(&height));
118 Display * display = fl_get_display();
120 lyxerr << "LyX: unable to access X display, exiting" << endl;
121 os::warn("Unable to access X display, exiting");
124 fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
125 // X Error handler install goes here
126 XSetErrorHandler(LyX_XErrHandler);
128 // A width less than 590 pops up an awkward main window
129 // The minimal values of width/height (590/400) are defined in
131 if (width < 590) width = 590;
132 if (height < 400) height = 400;
134 // If width is not set by geometry, check it against monitor width
135 if (!(geometryBitmask & 4)) {
136 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
137 if (WidthOfScreen(scr) - 8 < width)
138 width = WidthOfScreen(scr) - 8;
141 // If height is not set by geometry, check it against monitor height
142 if (!(geometryBitmask & 8)) {
143 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
144 if (HeightOfScreen(scr) - 24 < height)
145 height = HeightOfScreen(scr) - 24;
148 // Recalculate xpos if it's negative
149 if (geometryBitmask & 16)
150 xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(),
153 // Recalculate ypos if it's negative
154 if (geometryBitmask & 32)
155 ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(),
156 fl_screen)) - height;
158 // Initialize the LyXColorHandler
159 lyxColorHandler.reset(new LyXColorHandler);
163 // A destructor is always necessary (asierra-970604)
166 // Lyxserver was created in this class so should be destroyed
167 // here. asierra-970604
171 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
177 void LyXGUI::setDefaults()
179 GUIRunTime::setDefaults();
183 // This is called after we have parsed lyxrc
191 if (lyxrc.popup_font_encoding.empty())
192 lyxrc.popup_font_encoding = lyxrc.font_norm;
193 // Set the font name for popups and menus
194 string boldfontname = lyxrc.popup_bold_font
195 + "-*-*-*-?-*-*-*-*-"
196 + lyxrc.popup_font_encoding;
197 // "?" means "scale that font"
198 string fontname = lyxrc.popup_normal_font
199 + "-*-*-*-?-*-*-*-*-"
200 + lyxrc.popup_font_encoding;
202 int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
203 int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
205 lyxerr << "Could not set menu font to "
206 << boldfontname << endl;
209 lyxerr << "Could not set popup font to "
212 if (bold < 0 && normal < 0) {
213 lyxerr << "Using 'helvetica' font for menus" << endl;
214 boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
215 fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
216 bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
217 normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
219 if (bold < 0 && normal < 0) {
220 lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
221 fl_set_font_name(FL_NORMAL_STYLE, "fixed");
226 fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
228 fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
230 // put here (after fl_initialize) to avoid segfault. Cannot be done
231 // in setDefaults() (Matthias 140496)
232 // Moved from ::LyXGUI to ::init to allow popup font customization
234 fl_setpup_fontstyle(FL_NORMAL_STYLE);
235 fl_setpup_fontsize(FL_NORMAL_SIZE);
236 fl_setpup_color(FL_MCOL, FL_BLACK);
237 fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
239 fl_set_oneliner_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
241 fl_set_tooltip_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
244 // all lyxrc settings has to be done here as lyxrc has not yet
245 // been read when the GUI is created (Jug)
247 // Update parameters.
250 // Initialize the views.
253 // in 0.12 the initialisation of the LyXServer must be done here
254 // 0.13 it should be moved again...
255 lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
259 void LyXGUI::create_forms()
261 lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
262 lyxViews = GUIRunTime::createMainView(width, height);
263 lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
265 // From here down should be done by somebody else. (Lgb)
267 // This is probably as good a time as any to map the xform colours,
268 // should a mapping exist.
269 string const filename = AddName(user_lyxdir, "preferences.xform");
270 XformsColor::read(filename);
272 // Show the main & title form
273 int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
274 // Did we get a valid position?
275 if (xpos >= 0 && ypos >= 0) {
276 lyxViews->setPosition(xpos, ypos);
277 main_placement = FL_PLACE_POSITION;
280 lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
284 void LyXGUI::runTime()
288 GUIRunTime::runTime();
292 void LyXGUI::regBuf(Buffer * b)
294 lyxViews->view()->buffer(b);
298 LyXView * LyXGUI::getLyXView() const