]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/GUIRunTime.C
Add an image loader using the xforms library routines and compile it if
[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 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
23 #include "xformsGImage.h"
24 #else
25 #include "graphics/GraphicsImageXPM.h"
26 #endif
27
28 // I keep these here so that it will be processed as early in
29 // the compilation process as possible.
30 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
31 #error LyX will not compile with this version of XForms.\
32        Please get version 0.89.\
33        If you want to try to compile anyway, delete this test in src/frontends/xforms/GUIRunTime.C.
34 #endif
35
36
37 using std::endl;
38 using std::hex;
39
40
41 extern bool finished;
42
43 namespace {
44
45 int const xforms_include_version = FL_INCLUDE_VERSION;
46
47 } // namespace anon
48
49
50 int GUIRunTime::initApplication(int &, char **)
51 {
52         // Check the XForms version in the forms.h header against
53         // the one in the libforms. If they don't match quit the
54         // execution of LyX. Better with a clean fast exit than
55         // a strange segfault later.
56         // I realize that this check have to be moved when we
57         // support several toolkits, but IMO all the toolkits
58         // should try to have the same kind of check. This could
59         // be done by having a CheckHeaderAndLib function in
60         // all the toolkit implementations, this function is
61         // responsible for notifing the user.
62         // if (!CheckHeaderAndLib()) {
63         //         // header vs. lib version failed
64         //         return 1;
65         // }
66         int xforms_lib_version = fl_library_version(0, 0);
67         if (xforms_include_version != xforms_lib_version) {
68                 lyxerr << "You are either running LyX with wrong "
69                         "version of a dynamic XForms library\n"
70                         "or you have build LyX with conflicting header "
71                         "and library (different\n"
72                         "versions of XForms. Sorry but there is no point "
73                         "in continuing executing LyX!" << endl;
74                 return 1;
75         }
76         return 0;
77 }
78
79
80 void GUIRunTime::processEvents() 
81 {
82         if (fl_do_forms() == FL_EVENT) {
83                 XEvent ev;
84                 fl_XNextEvent(&ev);
85                 lyxerr << "Received unhandled X11 event" << endl;
86                 lyxerr << "Type: 0x" << hex << ev.xany.type <<
87                         "Target: 0x" << hex << ev.xany.window << endl;
88         }
89 }
90
91
92 void GUIRunTime::runTime()
93 {
94         while (!finished) {
95                 if (fl_check_forms() == FL_EVENT) {
96                         XEvent ev;
97                         fl_XNextEvent(&ev);
98                         lyxerr << "Received unhandled X11 event" << endl;
99                         lyxerr << "Type: 0x" << hex << ev.xany.type <<
100                                 "Target: 0x" << hex << ev.xany.window << endl;
101                 }
102         }
103 }
104
105
106 void GUIRunTime::setDefaults()
107 {
108         FL_IOPT cntl;
109         cntl.buttonFontSize = FL_NORMAL_SIZE;
110         cntl.browserFontSize = FL_NORMAL_SIZE;
111         cntl.labelFontSize = FL_NORMAL_SIZE;
112         cntl.choiceFontSize = FL_NORMAL_SIZE;
113         cntl.inputFontSize = FL_NORMAL_SIZE;
114         cntl.menuFontSize  = FL_NORMAL_SIZE;
115         cntl.borderWidth = -1;
116         cntl.vclass = FL_DefaultVisual;
117         fl_set_defaults(FL_PDVisual
118                         | FL_PDButtonFontSize
119                         | FL_PDBrowserFontSize
120                         | FL_PDLabelFontSize
121                         | FL_PDChoiceFontSize
122                         | FL_PDInputFontSize
123                         | FL_PDMenuFontSize
124                         | FL_PDBorderWidth, &cntl);
125 }
126
127
128 LyXView * GUIRunTime::createMainView(int w, int h)
129 {
130         return new XFormsView(w, h);
131 }
132
133
134
135 // Called by the graphics cache to connect the appropriate frontend
136 // image loading routines to the LyX kernel.
137 void GUIRunTime::initialiseGraphics()
138 {
139         using namespace grfx;
140         using SigC::slot;
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(slot(&xformsGImage::newImage));
145         GImage::loadableFormats.connect(slot(&xformsGImage::loadableFormats));
146 #else
147         // connect the image loader based on the XPM library
148         GImage::newImage.connect(slot(&GImageXPM::newImage));
149         GImage::loadableFormats.connect(slot(&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 }