]> git.lyx.org Git - features.git/blob - src/frontends/qt2/GUIRunTime.C
Move Dialogs::redrawGUI to frontends/Dialogs.C from all those guis.
[features.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 #include "graphics/GraphicsImageXPM.h"
23
24 #include FORMS_H_LOCATION
25
26 using std::endl;
27
28 // For now we need this here as long as we use xforms components!
29
30 // I keep these here so that it will be processed as early in
31 // the compilation process as possible.
32 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
33 #error LyX will not compile with this version of XForms.\
34        Please get version 0.89.\
35        If you want to try to compile anyway, delete this test in src/frontends/qt2/GUIRunTime.C.
36 #endif
37
38 extern bool finished;
39
40 int GUIRunTime::initApplication(int & argc, char * argv[])
41 {
42         int const xforms_include_version = FL_INCLUDE_VERSION;
43  
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         int xforms_lib_version = fl_library_version(0, 0);
49         if (xforms_include_version != xforms_lib_version) {
50                 lyxerr << "You are either running LyX with wrong "
51                         "version of a dynamic XForms library\n"
52                         "or you have build LyX with conflicting header "
53                         "and library (different\n"
54                         "versions of XForms. Sorry but there is no point "
55                         "in continuing executing LyX!" << endl;
56                 return 1;
57         }
58
59         // I belive this is done in the wrong place, imo this should
60         // be done in lyx_gui.C similar to how/where xforms does it (Lgb)
61         static QApplication a(argc, argv);
62         return 0;
63 }
64
65  
66 void GUIRunTime::processEvents() 
67 {
68         qApp->processEvents();
69 }
70
71
72 void GUIRunTime::runTime()
73 {
74         // We still use xforms event handler as the main one...
75         XEvent ev;
76         while (!finished) {
77                 processEvents();
78                 if (fl_check_forms() == FL_EVENT) {
79                         fl_XNextEvent(&ev);
80                         lyxerr << "Received unhandled X11 event" << endl;
81                         lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
82                                 "Target: 0x" << std::hex << ev.xany.window << endl;
83                 }
84         }
85 }
86
87
88 LyXView * GUIRunTime::createMainView(int w, int h)
89 {
90         return new XFormsView(w, h);
91 }
92
93  
94 // Called bu the graphics cache to connect the approriate frontend
95 // image loading routines to the LyX kernel.
96 void GUIRunTime::initialiseGraphics()
97 {
98         using namespace grfx;
99         using SigC::slot;
100     
101         // connect the image loader based on the XPM library
102         GImage::newImage.connect(slot(&GImageXPM::newImage));
103         GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
104 }
105
106
107 Display * GUIRunTime::x11Display()
108 {
109         //return p.device()->x11Display();
110         return fl_get_display();
111 }
112
113
114 int GUIRunTime::x11Screen()
115 {
116         //return p.device()->x11Screen(); 
117         return fl_screen;
118 }
119
120
121 Colormap GUIRunTime::x11Colormap()
122 {
123         //return p.device()->x11Colormap(); 
124         return fl_state[fl_get_vclass()].colormap;
125 }
126
127  
128 int GUIRunTime::x11VisualDepth() 
129 {
130         //return p.device()->x11Depth();
131         return fl_get_visual_depth();
132 }
133
134  
135 float GUIRunTime::getScreenDPI()
136 {
137         Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
138         return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
139                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
140 }
141
142  
143 void GUIRunTime::setDefaults() 
144 {
145         FL_IOPT cntl;
146         cntl.buttonFontSize = FL_NORMAL_SIZE;
147         cntl.browserFontSize = FL_NORMAL_SIZE;
148         cntl.labelFontSize = FL_NORMAL_SIZE;
149         cntl.choiceFontSize = FL_NORMAL_SIZE;
150         cntl.inputFontSize = FL_NORMAL_SIZE;
151         cntl.menuFontSize  = FL_NORMAL_SIZE;
152         cntl.borderWidth = -1;
153         cntl.vclass = FL_DefaultVisual;
154         fl_set_defaults(FL_PDVisual
155                         | FL_PDButtonFontSize
156                         | FL_PDBrowserFontSize
157                         | FL_PDLabelFontSize
158                         | FL_PDChoiceFontSize
159                         | FL_PDInputFontSize
160                         | FL_PDMenuFontSize
161                         | FL_PDBorderWidth, &cntl);
162 }