]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/GUIRunTime.C
We don't currently use fork anywhere (or if we do it's by mistake!), so
[lyx.git] / src / frontends / qt2 / GUIRunTime.C
1 /**
2  * \file GUIRunTime.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <qapplication.h>
16 #include <qpainter.h>
17  
18 #include "QtLyXView.h" 
19 #include "XFormsView.h"
20 #include "GUIRunTime.h"
21 #include "debug.h"
22
23 #include FORMS_H_LOCATION
24
25 using std::endl;
26
27 // For now we need this here as long as we use xforms components!
28
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/qt2/GUIRunTime.C.
35 #endif
36
37 extern bool finished;
38
39 int GUIRunTime::initApplication(int & argc, char * argv[])
40 {
41         int const xforms_include_version = FL_INCLUDE_VERSION;
42  
43         // Check the XForms version in the forms.h header against
44         // the one in the libforms. If they don't match quit the
45         // execution of LyX. Better with a clean fast exit than
46         // a strange segfault later.
47         int xforms_lib_version = fl_library_version(0, 0);
48         if (xforms_include_version != xforms_lib_version) {
49                 lyxerr << "You are either running LyX with wrong "
50                         "version of a dynamic XForms library\n"
51                         "or you have build LyX with conflicting header "
52                         "and library (different\n"
53                         "versions of XForms. Sorry but there is no point "
54                         "in continuing executing LyX!" << endl;
55                 return 1;
56         }
57
58         // I belive this is done in the wrong place, imo this should
59         // be done in lyx_gui.C similar to how/where xforms does it (Lgb)
60         static QApplication a(argc, argv);
61         return 0;
62 }
63
64  
65 void GUIRunTime::processEvents() 
66 {
67         qApp->processEvents();
68 }
69
70
71 void GUIRunTime::runTime()
72 {
73         // We still use xforms event handler as the main one...
74         XEvent ev;
75         while (!finished) {
76                 processEvents();
77                 if (fl_check_forms() == FL_EVENT) {
78                         fl_XNextEvent(&ev);
79                         lyxerr << "Received unhandled X11 event" << endl;
80                         lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
81                                 "Target: 0x" << std::hex << ev.xany.window << endl;
82                 }
83         }
84 }
85
86
87 LyXView * GUIRunTime::createMainView(int w, int h)
88 {
89         return new XFormsView(w, h);
90 }
91
92  
93 Display * GUIRunTime::x11Display()
94 {
95         //return p.device()->x11Display();
96         return fl_get_display();
97 }
98
99
100 int GUIRunTime::x11Screen()
101 {
102         //return p.device()->x11Screen(); 
103         return fl_screen;
104 }
105
106
107 Colormap GUIRunTime::x11Colormap()
108 {
109         //return p.device()->x11Colormap(); 
110         return fl_state[fl_get_vclass()].colormap;
111 }
112
113  
114 int GUIRunTime::x11VisualDepth() 
115 {
116         //return p.device()->x11Depth();
117         return fl_get_visual_depth();
118 }
119
120  
121 float GUIRunTime::getScreenDPI()
122 {
123         Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
124         return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
125                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
126 }
127
128  
129 void GUIRunTime::setDefaults() 
130 {
131         FL_IOPT cntl;
132         cntl.buttonFontSize = FL_NORMAL_SIZE;
133         cntl.browserFontSize = FL_NORMAL_SIZE;
134         cntl.labelFontSize = FL_NORMAL_SIZE;
135         cntl.choiceFontSize = FL_NORMAL_SIZE;
136         cntl.inputFontSize = FL_NORMAL_SIZE;
137         cntl.menuFontSize  = FL_NORMAL_SIZE;
138         cntl.borderWidth = -1;
139         cntl.vclass = FL_DefaultVisual;
140         fl_set_defaults(FL_PDVisual
141                         | FL_PDButtonFontSize
142                         | FL_PDBrowserFontSize
143                         | FL_PDLabelFontSize
144                         | FL_PDChoiceFontSize
145                         | FL_PDInputFontSize
146                         | FL_PDMenuFontSize
147                         | FL_PDBorderWidth, &cntl);
148 }