1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 *======================================================*/
13 #pragma implementation
16 #include FORMS_H_LOCATION
18 #include "GUIRunTime.h"
21 #include <gnome--/main.h>
22 #include <glade/glade.h>
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"
29 #include "graphics/GraphicsImageXPM.h"
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.
46 int const xforms_include_version = FL_INCLUDE_VERSION;
51 int GUIRunTime::initApplication(int &, char * argv[])
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
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;
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.
88 void GUIRunTime::processEvents()
90 while (Gnome::Main::instance()->events_pending())
91 Gnome::Main::instance()->iteration(FALSE);
95 void GUIRunTime::runTime()
100 if (fl_check_forms() == FL_EVENT) {
102 lyxerr << "Received unhandled X11 event" << endl;
103 lyxerr << "Type: 0x" << hex << ev.xany.type <<
104 "Target: 0x" << hex << ev.xany.window << endl;
110 void GUIRunTime::setDefaults()
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
125 | FL_PDChoiceFontSize
128 | FL_PDBorderWidth, &cntl);
132 #include "XFormsView.h"
133 LyXView * GUIRunTime::createMainView(int w, int h)
135 return new XFormsView(w, h);
139 // Called by the graphics cache to connect the appropriate frontend
140 // image loading routines to the LyX kernel.
141 void GUIRunTime::initialiseGraphics()
143 using namespace grfx;
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));
151 // connect the image loader based on the XPM library
152 GImage::newImage.connect(slot(&GImageXPM::newImage));
153 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
158 Display * GUIRunTime::x11Display()
160 return fl_get_display();
164 int GUIRunTime::x11Screen()
170 Colormap GUIRunTime::x11Colormap()
172 return fl_state[fl_get_vclass()].colormap;
176 int GUIRunTime::x11VisualDepth()
178 return fl_get_visual_depth();
181 float GUIRunTime::getScreenDPI()
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;