2 * \file qt2/GUIRunTime.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
12 #pragma implementation
15 #include <qapplication.h>
18 #include "QtLyXView.h"
19 #include "XFormsView.h"
20 #include "GUIRunTime.h"
23 #include FORMS_H_LOCATION
25 // For now we use the xforms image loader if we can.
26 // In the future, this will be replaced by a Qt equivalent.
27 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
28 #include "xforms/xformsGImage.h"
30 #include "graphics/GraphicsImageXPM.h"
35 // For now we need this here as long as we use xforms components!
37 // I keep these here so that it will be processed as early in
38 // the compilation process as possible.
39 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
40 #error LyX will not compile with this version of XForms.\
41 Please get version 0.89.\
42 If you want to try to compile anyway, delete this test in src/frontends/qt2/GUIRunTime.C.
47 int GUIRunTime::initApplication(int & argc, char * argv[])
49 int const xforms_include_version = FL_INCLUDE_VERSION;
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 int xforms_lib_version = fl_library_version(0, 0);
56 if (xforms_include_version != xforms_lib_version) {
57 lyxerr << "You are either running LyX with wrong "
58 "version of a dynamic XForms library\n"
59 "or you have build LyX with conflicting header "
60 "and library (different\n"
61 "versions of XForms. Sorry but there is no point "
62 "in continuing executing LyX!" << endl;
66 // I belive this is done in the wrong place, imo this should
67 // be done in lyx_gui.C similar to how/where xforms does it (Lgb)
68 static QApplication a(argc, argv);
73 void GUIRunTime::processEvents()
75 qApp->processEvents();
79 void GUIRunTime::runTime()
81 // We still use xforms event handler as the main one...
85 if (fl_check_forms() == FL_EVENT) {
87 lyxerr << "Received unhandled X11 event" << endl;
88 lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
89 "Target: 0x" << std::hex << ev.xany.window << endl;
95 LyXView * GUIRunTime::createMainView(int w, int h)
97 return new XFormsView(w, h);
101 // Called by the graphics cache to connect the appropriate frontend
102 // image loading routines to the LyX kernel.
103 void GUIRunTime::initialiseGraphics()
105 using namespace grfx;
108 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
109 // connect the image loader based on the xforms library
110 GImage::newImage.connect(slot(&xformsGImage::newImage));
111 GImage::loadableFormats.connect(slot(&xformsGImage::loadableFormats));
113 // connect the image loader based on the XPM library
114 GImage::newImage.connect(slot(&GImageXPM::newImage));
115 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
120 Display * GUIRunTime::x11Display()
122 //return p.device()->x11Display();
123 return fl_get_display();
127 int GUIRunTime::x11Screen()
129 //return p.device()->x11Screen();
134 Colormap GUIRunTime::x11Colormap()
136 //return p.device()->x11Colormap();
137 return fl_state[fl_get_vclass()].colormap;
141 int GUIRunTime::x11VisualDepth()
143 //return p.device()->x11Depth();
144 return fl_get_visual_depth();
148 float GUIRunTime::getScreenDPI()
150 Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
151 return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
152 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
156 void GUIRunTime::setDefaults()
159 cntl.buttonFontSize = FL_NORMAL_SIZE;
160 cntl.browserFontSize = FL_NORMAL_SIZE;
161 cntl.labelFontSize = FL_NORMAL_SIZE;
162 cntl.choiceFontSize = FL_NORMAL_SIZE;
163 cntl.inputFontSize = FL_NORMAL_SIZE;
164 cntl.menuFontSize = FL_NORMAL_SIZE;
165 cntl.borderWidth = -1;
166 cntl.vclass = FL_DefaultVisual;
167 fl_set_defaults(FL_PDVisual
168 | FL_PDButtonFontSize
169 | FL_PDBrowserFontSize
171 | FL_PDChoiceFontSize
174 | FL_PDBorderWidth, &cntl);