2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 *======================================================*/
14 #pragma implementation
17 #include FORMS_H_LOCATION
19 #include "GUIRunTime.h"
22 #include <gnome--/main.h>
23 #include <glade/glade.h>
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"
30 #include "graphics/GraphicsImageXPM.h"
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.
47 int const xforms_include_version = FL_INCLUDE_VERSION;
52 int GUIRunTime::initApplication(int &, char * argv[])
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
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;
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.
89 void GUIRunTime::processEvents()
91 while (Gnome::Main::instance()->events_pending())
92 Gnome::Main::instance()->iteration(FALSE);
96 void GUIRunTime::runTime()
101 if (fl_check_forms() == FL_EVENT) {
103 lyxerr << "Received unhandled X11 event" << endl;
104 lyxerr << "Type: 0x" << hex << ev.xany.type <<
105 "Target: 0x" << hex << ev.xany.window << endl;
111 void GUIRunTime::setDefaults()
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
126 | FL_PDChoiceFontSize
129 | FL_PDBorderWidth, &cntl);
133 #include "XFormsView.h"
134 LyXView * GUIRunTime::createMainView(int w, int h)
136 return new XFormsView(w, h);
140 // Called by the graphics cache to connect the appropriate frontend
141 // image loading routines to the LyX kernel.
142 void GUIRunTime::initialiseGraphics()
144 using namespace grfx;
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));
152 // connect the image loader based on the XPM library
153 GImage::newImage.connect(slot(&GImageXPM::newImage));
154 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
159 Display * GUIRunTime::x11Display()
161 return fl_get_display();
165 int GUIRunTime::x11Screen()
171 Colormap GUIRunTime::x11Colormap()
173 return fl_state[fl_get_vclass()].colormap;
177 int GUIRunTime::x11VisualDepth()
179 return fl_get_visual_depth();
182 float GUIRunTime::getScreenDPI()
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;