]> git.lyx.org Git - features.git/blob - src/frontends/xforms/GUIRunTime.C
66a0212e4b7c814295b1fd906f16e7356d270172
[features.git] / src / frontends / xforms / GUIRunTime.C
1 /**
2  * \file xforms/GUIRunTime.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author unknown
7  */
8
9 #include <config.h>
10
11 #include FORMS_H_LOCATION
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "GUIRunTime.h"
18 #include "XFormsView.h"
19 #include "debug.h"
20
21 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
22 #include "xformsGImage.h"
23 #else
24 #include "graphics/GraphicsImageXPM.h"
25 #endif
26
27 #include <boost/bind.hpp>
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/xforms/GUIRunTime.C.
35 #endif
36
37
38 using std::endl;
39 using std::hex;
40
41
42 extern bool finished;
43
44 namespace {
45
46 int const xforms_include_version = FL_INCLUDE_VERSION;
47
48 } // namespace anon
49
50
51 int GUIRunTime::initApplication(int &, char * [])
52 {
53         // Check the XForms version in the forms.h header against
54         // the one in the libforms. If they don't match quit the
55         // execution of LyX. Better with a clean fast exit than
56         // a strange segfault later.
57         // I realize that this check have to be moved when we
58         // support several toolkits, but IMO all the toolkits
59         // should try to have the same kind of check. This could
60         // be done by having a CheckHeaderAndLib function in
61         // all the toolkit implementations, this function is
62         // responsible for notifing the user.
63         // if (!CheckHeaderAndLib()) {
64         //         // header vs. lib version failed
65         //         return 1;
66         // }
67         int xforms_lib_version = fl_library_version(0, 0);
68         if (xforms_include_version != xforms_lib_version) {
69                 lyxerr << "You are either running LyX with wrong "
70                         "version of a dynamic XForms library\n"
71                         "or you have build LyX with conflicting header "
72                         "and library (different\n"
73                         "versions of XForms. Sorry but there is no point "
74                         "in continuing executing LyX!" << endl;
75                 return 1;
76         }
77         return 0;
78 }
79
80
81 void GUIRunTime::processEvents()
82 {
83         if (fl_do_forms() == FL_EVENT) {
84                 XEvent ev;
85                 fl_XNextEvent(&ev);
86                 lyxerr << "Received unhandled X11 event" << endl;
87                 lyxerr << "Type: 0x" << hex << ev.xany.type <<
88                         " Target: 0x" << hex << ev.xany.window << endl;
89         }
90 }
91
92
93 void GUIRunTime::runTime()
94 {
95         while (!finished) {
96                 if (fl_check_forms() == FL_EVENT) {
97                         XEvent ev;
98                         fl_XNextEvent(&ev);
99                         lyxerr << "Received unhandled X11 event" << endl;
100                         lyxerr << "Type: 0x" << hex << ev.xany.type <<
101                                 " Target: 0x" << hex << ev.xany.window << endl;
102                 }
103         }
104 }
105
106
107 void GUIRunTime::setDefaults()
108 {
109         FL_IOPT cntl;
110         cntl.buttonFontSize = FL_NORMAL_SIZE;
111         cntl.browserFontSize = FL_NORMAL_SIZE;
112         cntl.labelFontSize = FL_NORMAL_SIZE;
113         cntl.choiceFontSize = FL_NORMAL_SIZE;
114         cntl.inputFontSize = FL_NORMAL_SIZE;
115         cntl.menuFontSize  = FL_NORMAL_SIZE;
116         cntl.borderWidth = -1;
117         cntl.vclass = FL_DefaultVisual;
118         fl_set_defaults(FL_PDVisual
119                         | FL_PDButtonFontSize
120                         | FL_PDBrowserFontSize
121                         | FL_PDLabelFontSize
122                         | FL_PDChoiceFontSize
123                         | FL_PDInputFontSize
124                         | FL_PDMenuFontSize
125                         | FL_PDBorderWidth, &cntl);
126 }
127
128
129 LyXView * GUIRunTime::createMainView(int w, int h)
130 {
131         return new XFormsView(w, h);
132 }
133
134
135
136 // Called by the graphics cache to connect the appropriate frontend
137 // image loading routines to the LyX kernel.
138 void GUIRunTime::initialiseGraphics()
139 {
140         using namespace grfx;
141
142 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
143         // connect the image loader based on the xforms library
144         GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
145         GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
146 #else
147         // connect the image loader based on the XPM library
148         GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
149         GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
150 #endif
151 }
152
153
154 Display * GUIRunTime::x11Display()
155 {
156         return fl_get_display();
157 }
158
159
160 int GUIRunTime::x11Screen()
161 {
162         return fl_screen;
163 }
164
165
166 Colormap GUIRunTime::x11Colormap()
167 {
168         return fl_state[fl_get_vclass()].colormap;
169 }
170
171
172 int GUIRunTime::x11VisualDepth()
173 {
174         return fl_get_visual_depth();
175 }
176
177 float GUIRunTime::getScreenDPI()
178 {
179         Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
180         return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
181                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
182 }