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
18 #include "bufferlist.h"
20 #include "funcrequest.h"
23 #include "LyXAction.h"
28 #include "support/lstrings.h"
32 #include "FontLoader.h"
34 #include "qt_helpers.h"
35 #include "socket_callback.h"
36 #include "GuiApplication.h"
38 #include <QApplication>
40 #include <QTranslator>
43 #include <QLibraryInfo>
45 #include <boost/bind.hpp>
46 #include <boost/shared_ptr.hpp>
49 using lyx::support::ltrim;
51 using lyx::frontend::GuiImplementation;
52 using lyx::frontend::GuiView;
53 using lyx::frontend::GuiApplication;
55 using boost::shared_ptr;
57 #ifndef CXX_GLOBAL_CSTD
65 lyx::frontend::GuiApplication * guiApp;
66 lyx::frontend::Application * theApp;
71 map<int, shared_ptr<socket_callback> > socket_callbacks;
79 int exec(int & argc, char * argv[])
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:
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.
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:
95 QObject::killTimer: timers cannot be stopped from another thread
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.
102 // Force adding of font path _before_ QApplication is initialized
103 FontLoader::initFontPath();
105 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
106 static GuiApplication app(argc, argv);
108 GuiApplication app(argc, argv);
114 return LyX::ref().exec2(argc, argv);
122 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
125 return &guiApp->createView(width, height, posx, posy, maximize);
129 int start(LyXView * view, string const & batch)
131 return theApp->start(batch);
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);
145 void exit(int status)
147 guiApp->exit(status);
151 FuncStatus getStatus(FuncRequest const & ev)
155 case LFUN_TOOLTIPS_TOGGLE:
166 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
168 QColor const & qcol = guiApp->colorCache().get(col);
169 if (!qcol.isValid()) {
175 rgbcol.r = qcol.red();
176 rgbcol.g = qcol.green();
177 rgbcol.b = qcol.blue();
182 string const hexname(LColor_color col)
184 return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
188 void update_color(LColor_color)
190 // FIXME: Bleh, can't we just clear them all at once ?
191 guiApp->colorCache().clear();
197 guiApp->fontLoader().update();
201 bool font_available(LyXFont const & font)
203 return guiApp->fontLoader().available(font);
207 void register_socket_callback(int fd, boost::function<void()> func)
209 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
213 void unregister_socket_callback(int fd)
215 socket_callbacks.erase(fd);
219 string const roman_font_name()
225 font.setStyleHint(QFont::Serif);
226 font.setFamily("serif");
228 return fromqstr(QFontInfo(font).family());
232 string const sans_font_name()
238 font.setStyleHint(QFont::SansSerif);
239 font.setFamily("sans");
241 return fromqstr(QFontInfo(font).family());
245 string const typewriter_font_name()
251 font.setStyleHint(QFont::TypeWriter);
252 font.setFamily("monospace");
254 return fromqstr(QFontInfo(font).family());
257 }; // namespace lyx_gui