]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GUIRunTime.C
Move Dialogs::redrawGUI to frontends/Dialogs.C from all those guis.
[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
18 #include "GUIRunTime.h"
19 #include "debug.h"
20
21 #include <gnome--/main.h>
22 #include <glade/glade.h>
23
24 #include "graphics/GraphicsImageXPM.h"
25
26 using std::endl;
27
28 // I keep these here so that it will be processed as early in
29 // the compilation process as possible.
30 #if !defined(FL_REVISION) || FL_REVISION < 88 || FL_VERSION != 0
31 #error LyX will not compile with this version of XForms.\
32        Please get version 0.89.\
33        If you want to try to compile anyway, delete this test in src/frontends/gnome/GUIRunTime.C.
34 #endif
35
36 extern bool finished;
37
38 namespace {
39
40 int const xforms_include_version = FL_INCLUDE_VERSION;
41
42 } // namespace anon
43
44
45 int GUIRunTime::initApplication(int &, char * argv[])
46 {
47         // Check the XForms version in the forms.h header against
48         // the one in the libforms. If they don't match quit the
49         // execution of LyX. Better with a clean fast exit than
50         // a strange segfault later.
51         // I realize that this check have to be moved when we
52         // support several toolkits, but IMO all the toolkits
53         // should try to have the same kind of check. This could
54         // be done by having a CheckHeaderAndLib function in
55         // all the toolkit implementations, this function is
56         // responsible for notifing the user.
57         // if (!CheckHeaderAndLib()) {
58         //         // header vs. lib version failed
59         //         return 1;
60         // }
61         int xforms_lib_version = fl_library_version(0, 0);
62         if (xforms_include_version != xforms_lib_version) {
63                 cerr << "You are either running LyX with wrong "
64                         "version of a dynamic XForms library\n"
65                         "or you have build LyX with conflicting header "
66                         "and library (different\n"
67                         "versions of XForms. Sorry but there is no point "
68                         "in continuing executing LyX!" << endl;
69                 return 1;
70         }
71
72         // I belive that this should be done at a later stage, in
73         // lyx_gui, the same place as xforms does the same. (Lgb)
74         string app_id(PACKAGE);
75         string app_version(VERSION);
76         static Gnome::Main  a(app_id, app_version, 1, argv);
77         glade_gnome_init(); // Initialize the glade library.
78
79         return 0;
80 }
81
82 void GUIRunTime::processEvents() 
83 {
84         while (Gnome::Main::instance()->events_pending())
85                 Gnome::Main::instance()->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 bu the graphics cache to connect the approriate frontend
134 // image loading routines to the LyX kernel.
135 void GUIRunTime::initialiseGraphics()
136 {
137         using namespace grfx;
138         using SigC::slot;
139     
140         // connect the image loader based on the XPM library
141         GImage::newImage.connect(slot(&GImageXPM::newImage));
142         GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
143 }
144
145
146 Display * GUIRunTime::x11Display()
147 {
148         return fl_get_display();
149 }
150
151
152 int GUIRunTime::x11Screen()
153 {
154         return fl_screen;
155 }
156
157
158 Colormap GUIRunTime::x11Colormap()
159 {
160         return fl_state[fl_get_vclass()].colormap;
161 }
162
163
164 int GUIRunTime::x11VisualDepth()
165 {
166         return fl_get_visual_depth();
167 }
168
169 float GUIRunTime::getScreenDPI()
170 {
171         Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
172         return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
173                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
174 }