]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/lyx_gui.C
delete unneeded BufferView.h declaration.
[lyx.git] / src / frontends / qt4 / lyx_gui.C
1 /**
2  * \file qt4/lyx_gui.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "lyx_gui.h"
16
17 // FIXME: move this stuff out again
18 #include "bufferlist.h"
19 #include "Color.h"
20 #include "funcrequest.h"
21 #include "LColor.h"
22 #include "lyx_main.h"
23 #include "LyXAction.h"
24 #include "lyxfunc.h"
25 #include "lyxrc.h"
26
27
28 #include "support/lstrings.h"
29
30
31 #include "GuiView.h"
32 #include "FontLoader.h"
33 #include "QLImage.h"
34 #include "qt_helpers.h"
35 #include "socket_callback.h"
36 #include "GuiApplication.h"
37
38 #include <QApplication>
39 #include <QEventLoop>
40 #include <QTranslator>
41 #include <QTextCodec>
42 #include <QLocale>
43 #include <QLibraryInfo>
44
45 #include <boost/bind.hpp>
46 #include <boost/shared_ptr.hpp>
47
48
49 using lyx::support::ltrim;
50
51 using lyx::frontend::GuiImplementation;
52 using lyx::frontend::GuiView;
53 using lyx::frontend::GuiApplication;
54
55 using boost::shared_ptr;
56
57 #ifndef CXX_GLOBAL_CSTD
58 using std::exit;
59 #endif
60
61 using std::map;
62 using std::vector;
63 using std::string;
64
65 lyx::frontend::GuiApplication * guiApp;
66 lyx::frontend::Application * theApp;
67
68
69 namespace {
70
71 map<int, shared_ptr<socket_callback> > socket_callbacks;
72
73 } // namespace anon
74
75 namespace lyx_gui {
76
77 bool use_gui = true;
78
79 int exec(int & argc, char * argv[])
80 {
81         /*
82         FIXME : Abdel 29/05/2006 (younes.a@free.fr)
83         reorganize this code. In particular make sure that this
84         advice from Qt documentation is respected:
85
86                 Since the QApplication object does so much initialization, it
87                 must be created before any other objects related to the user
88                 interface are created.
89
90         Right now this is not the case, I suspect that a number of global variables
91         contains Qt object that are initialized before the passage through
92         parse_init(). This might also explain the message displayed by Qt
93         that caused the hanging:
94
95         QObject::killTimer: timers cannot be stopped from another thread
96
97         I hope that the problem will disappear automagically when we get rid of
98         lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
99         Clipboard and Selection access.
100         */
101
102         // Force adding of font path _before_ QApplication is initialized
103         FontLoader::initFontPath();
104
105 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
106         static GuiApplication app(argc, argv);
107 #else
108         GuiApplication app(argc, argv);
109 #endif
110
111         guiApp = &app;
112         theApp = guiApp;
113
114         return LyX::ref().exec2(argc, argv);
115 }
116
117
118 void parse_lyxrc()
119 {}
120
121
122 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
123           bool maximize)
124 {
125         return &guiApp->createView(width, height, posx, posy, maximize);
126 }
127
128
129 int start(LyXView * view, string const & batch)
130 {
131         return theApp->start(batch);
132 }
133
134
135 void sync_events()
136 {
137         // This is the ONLY place where processEvents may be called.
138         // During screen update/ redraw, this method is disabled to
139         // prevent keyboard events being handed to the LyX core, where
140         // they could cause re-entrant calls to screen update.
141         guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
142 }
143
144
145 void exit(int status)
146 {
147         guiApp->exit(status);
148 }
149
150
151 FuncStatus getStatus(FuncRequest const & ev)
152 {
153         FuncStatus flag;
154         switch (ev.action) {
155         case LFUN_TOOLTIPS_TOGGLE:
156                 flag.unknown(true);
157                 break;
158         default:
159                 break;
160         }
161
162         return flag;
163 }
164
165
166 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
167 {
168         QColor const & qcol = guiApp->colorCache().get(col);
169         if (!qcol.isValid()) {
170                 rgbcol.r = 0;
171                 rgbcol.g = 0;
172                 rgbcol.b = 0;
173                 return false;
174         }
175         rgbcol.r = qcol.red();
176         rgbcol.g = qcol.green();
177         rgbcol.b = qcol.blue();
178         return true;
179 }
180
181
182 string const hexname(LColor_color col)
183 {
184         return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
185 }
186
187
188 void update_color(LColor_color)
189 {
190         // FIXME: Bleh, can't we just clear them all at once ?
191         guiApp->colorCache().clear();
192 }
193
194
195 void update_fonts()
196 {
197         guiApp->fontLoader().update();
198 }
199
200
201 bool font_available(LyXFont const & font)
202 {
203         return guiApp->fontLoader().available(font);
204 }
205
206
207 void register_socket_callback(int fd, boost::function<void()> func)
208 {
209         socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
210 }
211
212
213 void unregister_socket_callback(int fd)
214 {
215         socket_callbacks.erase(fd);
216 }
217
218
219 string const roman_font_name()
220 {
221         if (!use_gui)
222                 return "serif";
223
224         QFont font;
225         font.setStyleHint(QFont::Serif);
226         font.setFamily("serif");
227
228         return fromqstr(QFontInfo(font).family());
229 }
230
231
232 string const sans_font_name()
233 {
234         if (!use_gui)
235                 return "sans";
236
237         QFont font;
238         font.setStyleHint(QFont::SansSerif);
239         font.setFamily("sans");
240
241         return fromqstr(QFontInfo(font).family());
242 }
243
244
245 string const typewriter_font_name()
246 {
247         if (!use_gui)
248                 return "monospace";
249
250         QFont font;
251         font.setStyleHint(QFont::TypeWriter);
252         font.setFamily("monospace");
253
254         return fromqstr(QFontInfo(font).family());
255 }
256
257 }; // namespace lyx_gui