]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GUIRunTime.C
ws changes
[lyx.git] / src / frontends / gnome / GUIRunTime.C
1 /**
2  * \file GUIRunTime.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include FORMS_H_LOCATION
18 #include "gnome_helpers.h"
19 #include "GUIRunTime.h"
20 #include "debug.h"
21
22 #include <gtkmm/main.h>
23 #include <libglademm/xml.h>
24
25 #include <boost/bind.hpp>
26
27 // For now we use the xforms image loader if we can.
28 // In the future, this will be replaced by a gnome equivalent.
29 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
30 #include "xforms/xformsGImage.h"
31 #else
32 #include "graphics/GraphicsImageXPM.h"
33 #endif
34
35 using std::endl;
36
37
38 extern bool finished;
39
40 namespace {
41
42 int const xforms_include_version = FL_INCLUDE_VERSION;
43
44 } // namespace anon
45
46
47 int GUIRunTime::initApplication(int & argc , char * argv[])
48 {
49         // Check the XForms version in the forms.h header against
50         // the one in the libforms. If they don't match quit the
51         // execution of LyX. Better with a clean fast exit than
52         // a strange segfault later.
53         // I realize that this check have to be moved when we
54         // support several toolkits, but IMO all the toolkits
55         // should try to have the same kind of check. This could
56         // be done by having a CheckHeaderAndLib function in
57         // all the toolkit implementations, this function is
58         // responsible for notifing the user.
59         // if (!CheckHeaderAndLib()) {
60         //         // header vs. lib version failed
61         //         return 1;
62         // }
63         int xforms_lib_version = fl_library_version(0, 0);
64         if (xforms_include_version != xforms_lib_version) {
65                 cerr << "You are either running LyX with wrong "
66                         "version of a dynamic XForms library\n"
67                         "or you have build LyX with conflicting header "
68                         "and library (different\n"
69                         "versions of XForms. Sorry but there is no point "
70                         "in continuing executing LyX!" << endl;
71                 return 1;
72         }
73
74         // I belive that this should be done at a later stage, in
75         // lyx_gui, the same place as xforms does the same. (Lgb)
76         string app_id(PACKAGE);
77         string app_version(VERSION);
78         new Gtk::Main (argc, argv);
79
80         return 0;
81 }
82
83 void GUIRunTime::processEvents()
84 {
85         while (Gtk::Main::events_pending())
86                 Gtk::Main::iteration(false);
87 }
88
89
90 void GUIRunTime::runTime()
91 {
92         XEvent ev;
93         while (!finished) {
94                 processEvents();
95                 if (fl_check_forms() == FL_EVENT) {
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 #include "XFormsView.h"
128 LyXView * GUIRunTime::createMainView(int w, int h)
129 {
130         return new XFormsView(w, h);
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
140 #if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP)
141         // connect the image loader based on the xforms library
142         GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
143         GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
144 #else
145         // connect the image loader based on the XPM library
146         GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
147         GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
148 #endif
149 }
150
151
152 Display * GUIRunTime::x11Display()
153 {
154         return fl_get_display();
155 }
156
157
158 int GUIRunTime::x11Screen()
159 {
160         return fl_screen;
161 }
162
163
164 Colormap GUIRunTime::x11Colormap()
165 {
166         return fl_state[fl_get_vclass()].colormap;
167 }
168
169
170 int GUIRunTime::x11VisualDepth()
171 {
172         return fl_get_visual_depth();
173 }
174
175 float GUIRunTime::getScreenDPI()
176 {
177         Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
178         return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
179                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
180 }