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 #ifdef USE_XFORMS_IMAGE_LOADER
22 #include "xformsGImage.h"
24 #include "graphics/GraphicsImageXPM.h"
27 #include <boost/bind.hpp>
37 int const xforms_include_version = FL_INCLUDE_VERSION;
42 int GUIRunTime::initApplication(int &, char * [])
44 // Check the XForms version in the forms.h header against
45 // the one in the libforms. If they don't match quit the
46 // execution of LyX. Better with a clean fast exit than
47 // a strange segfault later.
48 // I realize that this check have to be moved when we
49 // support several toolkits, but IMO all the toolkits
50 // should try to have the same kind of check. This could
51 // be done by having a CheckHeaderAndLib function in
52 // all the toolkit implementations, this function is
53 // responsible for notifing the user.
54 // if (!CheckHeaderAndLib()) {
55 // // header vs. lib version failed
58 int xforms_lib_version = fl_library_version(0, 0);
59 if (xforms_include_version != xforms_lib_version) {
60 lyxerr << "You are either running LyX with wrong "
61 "version of a dynamic XForms library\n"
62 "or you have build LyX with conflicting header "
63 "and library (different\n"
64 "versions of XForms). Sorry but there is no point "
65 "in continuing executing LyX!" << endl;
72 void GUIRunTime::processEvents()
74 if (fl_do_forms() == FL_EVENT) {
77 lyxerr << "Received unhandled X11 event" << endl;
78 lyxerr << "Type: 0x" << hex << ev.xany.type <<
79 " Target: 0x" << hex << ev.xany.window << endl;
84 void GUIRunTime::runTime()
87 if (fl_check_forms() == FL_EVENT) {
90 lyxerr << "Received unhandled X11 event" << endl;
91 lyxerr << "Type: 0x" << hex << ev.xany.type <<
92 " Target: 0x" << hex << ev.xany.window << endl;
98 void GUIRunTime::setDefaults()
101 cntl.buttonFontSize = FL_NORMAL_SIZE;
102 cntl.browserFontSize = FL_NORMAL_SIZE;
103 cntl.labelFontSize = FL_NORMAL_SIZE;
104 cntl.choiceFontSize = FL_NORMAL_SIZE;
105 cntl.inputFontSize = FL_NORMAL_SIZE;
106 cntl.menuFontSize = FL_NORMAL_SIZE;
107 cntl.borderWidth = -1;
108 cntl.vclass = FL_DefaultVisual;
109 fl_set_defaults(FL_PDVisual
110 | FL_PDButtonFontSize
111 | FL_PDBrowserFontSize
113 | FL_PDChoiceFontSize
116 | FL_PDBorderWidth, &cntl);
120 LyXView * GUIRunTime::createMainView(int w, int h)
122 return new XFormsView(w, h);
127 // Called by the graphics cache to connect the appropriate frontend
128 // image loading routines to the LyX kernel.
129 void GUIRunTime::initialiseGraphics()
131 using namespace grfx;
133 #ifdef USE_XFORMS_IMAGE_LOADER
134 // connect the image loader based on the xforms library
135 GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
136 GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
138 // connect the image loader based on the XPM library
139 GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
140 GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
145 Display * GUIRunTime::x11Display()
147 return fl_get_display();
151 int GUIRunTime::x11Screen()
157 Colormap GUIRunTime::x11Colormap()
159 return fl_state[fl_get_vclass()].colormap;
163 int GUIRunTime::x11VisualDepth()
165 return fl_get_visual_depth();
168 float GUIRunTime::getScreenDPI()
170 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
171 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
172 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;