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