2 * \file xforms/GUIRunTime.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
11 #include FORMS_H_LOCATION
14 #pragma implementation
17 #include "GUIRunTime.h"
18 #include "XFormsView.h"
21 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
22 #include "xformsGImage.h"
24 #include "graphics/GraphicsImageXPM.h"
27 #include <boost/bind.hpp>
29 // I keep these here so that it will be processed as early in
30 // the compilation process as possible.
31 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
32 #error LyX will not compile with this version of XForms.\
33 Please get version 0.89.\
34 If you want to try to compile anyway, delete this test in src/frontends/xforms/GUIRunTime.C.
46 int const xforms_include_version = FL_INCLUDE_VERSION;
51 int GUIRunTime::initApplication(int &, char * [])
53 // Check the XForms version in the forms.h header against
54 // the one in the libforms. If they don't match quit the
55 // execution of LyX. Better with a clean fast exit than
56 // a strange segfault later.
57 // I realize that this check have to be moved when we
58 // support several toolkits, but IMO all the toolkits
59 // should try to have the same kind of check. This could
60 // be done by having a CheckHeaderAndLib function in
61 // all the toolkit implementations, this function is
62 // responsible for notifing the user.
63 // if (!CheckHeaderAndLib()) {
64 // // header vs. lib version failed
67 int xforms_lib_version = fl_library_version(0, 0);
68 if (xforms_include_version != xforms_lib_version) {
69 lyxerr << "You are either running LyX with wrong "
70 "version of a dynamic XForms library\n"
71 "or you have build LyX with conflicting header "
72 "and library (different\n"
73 "versions of XForms. Sorry but there is no point "
74 "in continuing executing LyX!" << endl;
81 void GUIRunTime::processEvents()
83 if (fl_do_forms() == FL_EVENT) {
86 lyxerr << "Received unhandled X11 event" << endl;
87 lyxerr << "Type: 0x" << hex << ev.xany.type <<
88 " Target: 0x" << hex << ev.xany.window << endl;
93 void GUIRunTime::runTime()
96 if (fl_check_forms() == FL_EVENT) {
99 lyxerr << "Received unhandled X11 event" << endl;
100 lyxerr << "Type: 0x" << hex << ev.xany.type <<
101 " Target: 0x" << hex << ev.xany.window << endl;
107 void GUIRunTime::setDefaults()
110 cntl.buttonFontSize = FL_NORMAL_SIZE;
111 cntl.browserFontSize = FL_NORMAL_SIZE;
112 cntl.labelFontSize = FL_NORMAL_SIZE;
113 cntl.choiceFontSize = FL_NORMAL_SIZE;
114 cntl.inputFontSize = FL_NORMAL_SIZE;
115 cntl.menuFontSize = FL_NORMAL_SIZE;
116 cntl.borderWidth = -1;
117 cntl.vclass = FL_DefaultVisual;
118 fl_set_defaults(FL_PDVisual
119 | FL_PDButtonFontSize
120 | FL_PDBrowserFontSize
122 | FL_PDChoiceFontSize
125 | FL_PDBorderWidth, &cntl);
129 LyXView * GUIRunTime::createMainView(int w, int h)
131 return new XFormsView(w, h);
136 // Called by the graphics cache to connect the appropriate frontend
137 // image loading routines to the LyX kernel.
138 void GUIRunTime::initialiseGraphics()
140 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(boost::bind(&xformsGImage::newImage));
145 GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
147 // connect the image loader based on the XPM library
148 GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
149 GImage::loadableFormats.connect(boost::bind(&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;