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