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 // I keep these here so that it will be processed as early in
28 // the compilation process as possible.
29 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
30 #error LyX will not compile with this version of XForms.\
31 Please get version 0.89.\
32 If you want to try to compile anyway, delete this test in src/frontends/xforms/GUIRunTime.C.
44 int const xforms_include_version = FL_INCLUDE_VERSION;
49 int GUIRunTime::initApplication(int &, char * [])
51 // Check the XForms version in the forms.h header against
52 // the one in the libforms. If they don't match quit the
53 // execution of LyX. Better with a clean fast exit than
54 // a strange segfault later.
55 // I realize that this check have to be moved when we
56 // support several toolkits, but IMO all the toolkits
57 // should try to have the same kind of check. This could
58 // be done by having a CheckHeaderAndLib function in
59 // all the toolkit implementations, this function is
60 // responsible for notifing the user.
61 // if (!CheckHeaderAndLib()) {
62 // // header vs. lib version failed
65 int xforms_lib_version = fl_library_version(0, 0);
66 if (xforms_include_version != xforms_lib_version) {
67 lyxerr << "You are either running LyX with wrong "
68 "version of a dynamic XForms library\n"
69 "or you have build LyX with conflicting header "
70 "and library (different\n"
71 "versions of XForms. Sorry but there is no point "
72 "in continuing executing LyX!" << endl;
79 void GUIRunTime::processEvents()
81 if (fl_do_forms() == FL_EVENT) {
84 lyxerr << "Received unhandled X11 event" << endl;
85 lyxerr << "Type: 0x" << hex << ev.xany.type <<
86 " Target: 0x" << hex << ev.xany.window << endl;
91 void GUIRunTime::runTime()
94 if (fl_check_forms() == FL_EVENT) {
97 lyxerr << "Received unhandled X11 event" << endl;
98 lyxerr << "Type: 0x" << hex << ev.xany.type <<
99 " Target: 0x" << hex << ev.xany.window << endl;
105 void GUIRunTime::setDefaults()
108 cntl.buttonFontSize = FL_NORMAL_SIZE;
109 cntl.browserFontSize = FL_NORMAL_SIZE;
110 cntl.labelFontSize = FL_NORMAL_SIZE;
111 cntl.choiceFontSize = FL_NORMAL_SIZE;
112 cntl.inputFontSize = FL_NORMAL_SIZE;
113 cntl.menuFontSize = FL_NORMAL_SIZE;
114 cntl.borderWidth = -1;
115 cntl.vclass = FL_DefaultVisual;
116 fl_set_defaults(FL_PDVisual
117 | FL_PDButtonFontSize
118 | FL_PDBrowserFontSize
120 | FL_PDChoiceFontSize
123 | FL_PDBorderWidth, &cntl);
127 LyXView * GUIRunTime::createMainView(int w, int h)
129 return new XFormsView(w, h);
134 // Called by the graphics cache to connect the appropriate frontend
135 // image loading routines to the LyX kernel.
136 void GUIRunTime::initialiseGraphics()
138 using namespace grfx;
141 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
142 // connect the image loader based on the xforms library
143 GImage::newImage.connect(slot(&xformsGImage::newImage));
144 GImage::loadableFormats.connect(slot(&xformsGImage::loadableFormats));
146 // connect the image loader based on the XPM library
147 GImage::newImage.connect(slot(&GImageXPM::newImage));
148 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
153 Display * GUIRunTime::x11Display()
155 return fl_get_display();
159 int GUIRunTime::x11Screen()
165 Colormap GUIRunTime::x11Colormap()
167 return fl_state[fl_get_vclass()].colormap;
171 int GUIRunTime::x11VisualDepth()
173 return fl_get_visual_depth();
176 float GUIRunTime::getScreenDPI()
178 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
179 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
180 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;