]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/GUIRunTime.C
7b9aeab955152647ef5bca4df3b0318f327ebd5f
[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 // 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"
29 #else
30 #include "graphics/GraphicsImageXPM.h"
31 #endif
32
33 using std::endl;
34
35 // For now we need this here as long as we use xforms components!
36
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.
43 #endif
44
45 extern bool finished;
46
47 int GUIRunTime::initApplication(int & argc, char * argv[])
48 {
49         int const xforms_include_version = FL_INCLUDE_VERSION;
50  
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;
63                 return 1;
64         }
65
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);
69         return 0;
70 }
71
72  
73 void GUIRunTime::processEvents() 
74 {
75         qApp->processEvents();
76 }
77
78
79 void GUIRunTime::runTime()
80 {
81         // We still use xforms event handler as the main one...
82         XEvent ev;
83         while (!finished) {
84                 processEvents();
85                 if (fl_check_forms() == FL_EVENT) {
86                         fl_XNextEvent(&ev);
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;
90                 }
91         }
92 }
93
94
95 LyXView * GUIRunTime::createMainView(int w, int h)
96 {
97         return new XFormsView(w, h);
98 }
99
100  
101 // Called by the graphics cache to connect the appropriate frontend
102 // image loading routines to the LyX kernel.
103 void GUIRunTime::initialiseGraphics()
104 {
105         using namespace grfx;
106         using SigC::slot;
107     
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));
112 #else
113         // connect the image loader based on the XPM library
114         GImage::newImage.connect(slot(&GImageXPM::newImage));
115         GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
116 #endif
117 }
118
119
120 Display * GUIRunTime::x11Display()
121 {
122         //return p.device()->x11Display();
123         return fl_get_display();
124 }
125
126
127 int GUIRunTime::x11Screen()
128 {
129         //return p.device()->x11Screen(); 
130         return fl_screen;
131 }
132
133
134 Colormap GUIRunTime::x11Colormap()
135 {
136         //return p.device()->x11Colormap(); 
137         return fl_state[fl_get_vclass()].colormap;
138 }
139
140  
141 int GUIRunTime::x11VisualDepth() 
142 {
143         //return p.device()->x11Depth();
144         return fl_get_visual_depth();
145 }
146
147  
148 float GUIRunTime::getScreenDPI()
149 {
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;
153 }
154
155  
156 void GUIRunTime::setDefaults() 
157 {
158         FL_IOPT cntl;
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
170                         | FL_PDLabelFontSize
171                         | FL_PDChoiceFontSize
172                         | FL_PDInputFontSize
173                         | FL_PDMenuFontSize
174                         | FL_PDBorderWidth, &cntl);
175 }