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