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