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