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"
32 #include "qt_helpers.h"
33 #include "socket_callback.h"
34 #include "GuiApplication.h"
36 #include <QApplication>
38 #include <QTranslator>
41 #include <QLibraryInfo>
43 #include <boost/bind.hpp>
44 #include <boost/shared_ptr.hpp>
47 using lyx::support::ltrim;
49 using lyx::frontend::GuiImplementation;
50 using lyx::frontend::GuiView;
51 using lyx::frontend::GuiApplication;
53 using boost::shared_ptr;
55 #ifndef CXX_GLOBAL_CSTD
63 lyx::frontend::GuiApplication * guiApp;
64 lyx::frontend::Application * theApp;
69 map<int, shared_ptr<socket_callback> > socket_callbacks;
77 int exec(int & argc, char * argv[])
80 FIXME : Abdel 29/05/2006 (younes.a@free.fr)
81 reorganize this code. In particular make sure that this
82 advice from Qt documentation is respected:
84 Since the QApplication object does so much initialization, it
85 must be created before any other objects related to the user
86 interface are created.
88 Right now this is not the case, I suspect that a number of global variables
89 contains Qt object that are initialized before the passage through
90 parse_init(). This might also explain the message displayed by Qt
91 that caused the hanging:
93 QObject::killTimer: timers cannot be stopped from another thread
95 I hope that the problem will disappear automagically when we get rid of
96 lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
97 Clipboard and Selection access.
100 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
101 static GuiApplication app(argc, argv);
103 GuiApplication app(argc, argv);
109 return LyX::ref().exec2(argc, argv);
117 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
120 return &guiApp->createView(width, height, posx, posy, maximize);
124 int start(LyXView * view, string const & batch)
126 return theApp->start(batch);
132 // This is the ONLY place where processEvents may be called.
133 // During screen update/ redraw, this method is disabled to
134 // prevent keyboard events being handed to the LyX core, where
135 // they could cause re-entrant calls to screen update.
136 guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
140 void exit(int status)
142 guiApp->exit(status);
146 FuncStatus getStatus(FuncRequest const & ev)
150 case LFUN_TOOLTIPS_TOGGLE:
161 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
163 QColor const & qcol = guiApp->colorCache().get(col);
164 if (!qcol.isValid()) {
170 rgbcol.r = qcol.red();
171 rgbcol.g = qcol.green();
172 rgbcol.b = qcol.blue();
177 string const hexname(LColor_color col)
179 return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
183 void update_color(LColor_color)
185 // FIXME: Bleh, can't we just clear them all at once ?
186 guiApp->colorCache().clear();
192 guiApp->fontLoader().update();
196 bool font_available(LyXFont const & font)
198 return guiApp->fontLoader().available(font);
202 void register_socket_callback(int fd, boost::function<void()> func)
204 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
208 void unregister_socket_callback(int fd)
210 socket_callbacks.erase(fd);
214 string const roman_font_name()
220 font.setStyleHint(QFont::Serif);
221 font.setFamily("serif");
223 return fromqstr(QFontInfo(font).family());
227 string const sans_font_name()
233 font.setStyleHint(QFont::SansSerif);
234 font.setFamily("sans");
236 return fromqstr(QFontInfo(font).family());
240 string const typewriter_font_name()
246 font.setStyleHint(QFont::TypeWriter);
247 font.setFamily("monospace");
249 return fromqstr(QFontInfo(font).family());
252 }; // namespace lyx_gui