3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
17 // FIXME: move this stuff out again
19 #include "funcrequest.h"
22 #include "LyXAction.h"
27 #include "support/lstrings.h"
31 #include "qt_helpers.h"
32 #include "socket_callback.h"
33 #include "GuiApplication.h"
35 #include <QApplication>
37 #include <QTranslator>
40 #include <QLibraryInfo>
42 #include <boost/bind.hpp>
43 #include <boost/shared_ptr.hpp>
46 using lyx::support::ltrim;
48 using lyx::frontend::GuiImplementation;
49 using lyx::frontend::GuiView;
50 using lyx::frontend::GuiApplication;
52 using boost::shared_ptr;
54 #ifndef CXX_GLOBAL_CSTD
62 lyx::frontend::GuiApplication * guiApp;
66 map<int, shared_ptr<socket_callback> > socket_callbacks;
72 int exec(int & argc, char * argv[])
75 FIXME : Abdel 29/05/2006 (younes.a@free.fr)
76 reorganize this code. In particular make sure that this
77 advice from Qt documentation is respected:
79 Since the QApplication object does so much initialization, it
80 must be created before any other objects related to the user
81 interface are created.
83 Right now this is not the case, I suspect that a number of global variables
84 contains Qt object that are initialized before the passage through
85 parse_init(). This might also explain the message displayed by Qt
86 that caused the hanging:
88 QObject::killTimer: timers cannot be stopped from another thread
90 I hope that the problem will disappear automagically when we get rid of
91 lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
92 Clipboard and Selection access.
95 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
96 static GuiApplication app(argc, argv);
98 GuiApplication app(argc, argv);
104 return LyX::ref().exec2(argc, argv);
110 // This is the ONLY place where processEvents may be called.
111 // During screen update/ redraw, this method is disabled to
112 // prevent keyboard events being handed to the LyX core, where
113 // they could cause re-entrant calls to screen update.
114 guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
118 void exit(int status)
120 guiApp->exit(status);
124 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
126 QColor const & qcol = guiApp->colorCache().get(col);
127 if (!qcol.isValid()) {
133 rgbcol.r = qcol.red();
134 rgbcol.g = qcol.green();
135 rgbcol.b = qcol.blue();
140 string const hexname(LColor_color col)
142 return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
146 void update_color(LColor_color)
148 // FIXME: Bleh, can't we just clear them all at once ?
149 guiApp->colorCache().clear();
155 guiApp->fontLoader().update();
159 bool font_available(LyXFont const & font)
161 return guiApp->fontLoader().available(font);
165 void register_socket_callback(int fd, boost::function<void()> func)
167 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
171 void unregister_socket_callback(int fd)
173 socket_callbacks.erase(fd);
176 }; // namespace lyx_gui