3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include FORMS_H_LOCATION
18 #include "gnome_helpers.h"
19 #include "GUIRunTime.h"
22 #include <gtkmm/main.h>
23 #include <libglademm/xml.h>
25 #include <boost/bind.hpp>
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"
32 #include "graphics/GraphicsImageXPM.h"
42 int const xforms_include_version = FL_INCLUDE_VERSION;
47 int GUIRunTime::initApplication(int & argc , char * argv[])
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
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;
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);
83 void GUIRunTime::processEvents()
85 while (Gtk::Main::events_pending())
86 Gtk::Main::iteration(false);
90 void GUIRunTime::runTime()
95 if (fl_check_forms() == FL_EVENT) {
97 lyxerr << "Received unhandled X11 event" << endl;
98 lyxerr << "Type: 0x" << hex << ev.xany.type <<
99 "Target: 0x" << hex << ev.xany.window << endl;
105 void GUIRunTime::setDefaults()
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
120 | FL_PDChoiceFontSize
123 | FL_PDBorderWidth, &cntl);
127 #include "XFormsView.h"
128 LyXView * GUIRunTime::createMainView(int w, int h)
130 return new XFormsView(w, h);
134 // Called by the graphics cache to connect the appropriate frontend
135 // image loading routines to the LyX kernel.
136 void GUIRunTime::initialiseGraphics()
138 using namespace grfx;
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));
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));
152 Display * GUIRunTime::x11Display()
154 return fl_get_display();
158 int GUIRunTime::x11Screen()
164 Colormap GUIRunTime::x11Colormap()
166 return fl_state[fl_get_vclass()].colormap;
170 int GUIRunTime::x11VisualDepth()
172 return fl_get_visual_depth();
175 float GUIRunTime::getScreenDPI()
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;