]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/GUIRunTime.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / GUIRunTime.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000-2001 The LyX Team.
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #include FORMS_H_LOCATION
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "GUIRunTime.h"
19 #include "XFormsView.h"
20 #include "debug.h"
21
22 // I keep these here so that it will be processed as early in
23 // the compilation process as possible.
24 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
25 #error LyX will not compile with this version of XForms.\
26        Please get version 0.89.\
27        If you want to try to compile anyway, delete this test in src/frontends/xforms/GUIRunTime.C.
28 #endif
29
30 using std::endl;
31
32 extern bool finished;
33
34 namespace {
35
36 int const xforms_include_version = FL_INCLUDE_VERSION;
37
38 } // namespace anon
39
40
41 int GUIRunTime::initApplication(int &, char **)
42 {
43         // Check the XForms version in the forms.h header against
44         // the one in the libforms. If they don't match quit the
45         // execution of LyX. Better with a clean fast exit than
46         // a strange segfault later.
47         // I realize that this check have to be moved when we
48         // support several toolkits, but IMO all the toolkits
49         // should try to have the same kind of check. This could
50         // be done by having a CheckHeaderAndLib function in
51         // all the toolkit implementations, this function is
52         // responsible for notifing the user.
53         // if (!CheckHeaderAndLib()) {
54         //         // header vs. lib version failed
55         //         return 1;
56         // }
57         int xforms_lib_version = fl_library_version(0, 0);
58         if (xforms_include_version != xforms_lib_version) {
59                 lyxerr << "You are either running LyX with wrong "
60                         "version of a dynamic XForms library\n"
61                         "or you have build LyX with conflicting header "
62                         "and library (different\n"
63                         "versions of XForms. Sorry but there is no point "
64                         "in continuing executing LyX!" << endl;
65                 return 1;
66         }
67         return 0;
68 }
69
70
71 void GUIRunTime::processEvents() 
72 {
73         if (fl_do_forms() == FL_EVENT) {
74                 XEvent ev;
75                 fl_XNextEvent(&ev);
76                 lyxerr << "Received unhandled X11 event" << endl;
77                 lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
78                         "Target: 0x" << std::hex << ev.xany.window << endl;
79         }
80 }
81
82
83 void GUIRunTime::runTime()
84 {
85         while (!finished) {
86                 if (fl_check_forms() == FL_EVENT) {
87                         XEvent ev;
88                         fl_XNextEvent(&ev);
89                         lyxerr << "Received unhandled X11 event" << endl;
90                         lyxerr << "Type: 0x" << std::hex << ev.xany.type <<
91                                 "Target: 0x" << std::hex << ev.xany.window << endl;
92                 }
93         }
94 }
95
96
97 void GUIRunTime::setDefaults()
98 {
99         FL_IOPT cntl;
100         cntl.buttonFontSize = FL_NORMAL_SIZE;
101         cntl.browserFontSize = FL_NORMAL_SIZE;
102         cntl.labelFontSize = FL_NORMAL_SIZE;
103         cntl.choiceFontSize = FL_NORMAL_SIZE;
104         cntl.inputFontSize = FL_NORMAL_SIZE;
105         cntl.menuFontSize  = FL_NORMAL_SIZE;
106         cntl.borderWidth = -1;
107         cntl.vclass = FL_DefaultVisual;
108         fl_set_defaults(FL_PDVisual
109                         | FL_PDButtonFontSize
110                         | FL_PDBrowserFontSize
111                         | FL_PDLabelFontSize
112                         | FL_PDChoiceFontSize
113                         | FL_PDInputFontSize
114                         | FL_PDMenuFontSize
115                         | FL_PDBorderWidth, &cntl);
116 }
117
118
119 LyXView * GUIRunTime::createMainView(int w, int h)
120 {
121         return new XFormsView(w, h);
122 }
123
124
125 Display * GUIRunTime::x11Display()
126 {
127         return fl_get_display();
128 }
129
130
131 int GUIRunTime::x11Screen()
132 {
133         return fl_screen;
134 }
135
136
137 Colormap GUIRunTime::x11Colormap()
138 {
139         return fl_state[fl_get_vclass()].colormap;
140 }
141
142
143 int GUIRunTime::x11VisualDepth()
144 {
145         return fl_get_visual_depth();
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 }