1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 *======================================================*/
12 #include FORMS_H_LOCATION
15 #pragma implementation
18 #include "GUIRunTime.h"
19 #include "XFormsView.h"
22 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
23 #include "xformsGImage.h"
25 #include "graphics/GraphicsImageXPM.h"
28 // I keep these here so that it will be processed as early in
29 // the compilation process as possible.
30 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
31 #error LyX will not compile with this version of XForms.\
32 Please get version 0.89.\
33 If you want to try to compile anyway, delete this test in src/frontends/xforms/GUIRunTime.C.
45 int const xforms_include_version = FL_INCLUDE_VERSION;
50 int GUIRunTime::initApplication(int &, char **)
52 // Check the XForms version in the forms.h header against
53 // the one in the libforms. If they don't match quit the
54 // execution of LyX. Better with a clean fast exit than
55 // a strange segfault later.
56 // I realize that this check have to be moved when we
57 // support several toolkits, but IMO all the toolkits
58 // should try to have the same kind of check. This could
59 // be done by having a CheckHeaderAndLib function in
60 // all the toolkit implementations, this function is
61 // responsible for notifing the user.
62 // if (!CheckHeaderAndLib()) {
63 // // header vs. lib version failed
66 int xforms_lib_version = fl_library_version(0, 0);
67 if (xforms_include_version != xforms_lib_version) {
68 lyxerr << "You are either running LyX with wrong "
69 "version of a dynamic XForms library\n"
70 "or you have build LyX with conflicting header "
71 "and library (different\n"
72 "versions of XForms. Sorry but there is no point "
73 "in continuing executing LyX!" << endl;
80 void GUIRunTime::processEvents()
82 if (fl_do_forms() == FL_EVENT) {
85 lyxerr << "Received unhandled X11 event" << endl;
86 lyxerr << "Type: 0x" << hex << ev.xany.type <<
87 "Target: 0x" << hex << ev.xany.window << endl;
92 void GUIRunTime::runTime()
95 if (fl_check_forms() == FL_EVENT) {
98 lyxerr << "Received unhandled X11 event" << endl;
99 lyxerr << "Type: 0x" << hex << ev.xany.type <<
100 "Target: 0x" << hex << ev.xany.window << endl;
106 void GUIRunTime::setDefaults()
109 cntl.buttonFontSize = FL_NORMAL_SIZE;
110 cntl.browserFontSize = FL_NORMAL_SIZE;
111 cntl.labelFontSize = FL_NORMAL_SIZE;
112 cntl.choiceFontSize = FL_NORMAL_SIZE;
113 cntl.inputFontSize = FL_NORMAL_SIZE;
114 cntl.menuFontSize = FL_NORMAL_SIZE;
115 cntl.borderWidth = -1;
116 cntl.vclass = FL_DefaultVisual;
117 fl_set_defaults(FL_PDVisual
118 | FL_PDButtonFontSize
119 | FL_PDBrowserFontSize
121 | FL_PDChoiceFontSize
124 | FL_PDBorderWidth, &cntl);
128 LyXView * GUIRunTime::createMainView(int w, int h)
130 return new XFormsView(w, h);
135 // Called by the graphics cache to connect the appropriate frontend
136 // image loading routines to the LyX kernel.
137 void GUIRunTime::initialiseGraphics()
139 using namespace grfx;
142 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
143 // connect the image loader based on the xforms library
144 GImage::newImage.connect(slot(&xformsGImage::newImage));
145 GImage::loadableFormats.connect(slot(&xformsGImage::loadableFormats));
147 // connect the image loader based on the XPM library
148 GImage::newImage.connect(slot(&GImageXPM::newImage));
149 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
154 Display * GUIRunTime::x11Display()
156 return fl_get_display();
160 int GUIRunTime::x11Screen()
166 Colormap GUIRunTime::x11Colormap()
168 return fl_state[fl_get_vclass()].colormap;
172 int GUIRunTime::x11VisualDepth()
174 return fl_get_visual_depth();
177 float GUIRunTime::getScreenDPI()
179 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
180 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
181 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;