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"
19 #include "BufferView.h"
21 #include "funcrequest.h"
24 #include "LyXAction.h"
29 #include "support/lstrings.h"
33 #include "FontLoader.h"
35 #include "qt_helpers.h"
36 #include "socket_callback.h"
37 #include "GuiApplication.h"
39 #include <QApplication>
41 #include <QTranslator>
44 #include <QLibraryInfo>
46 #include <boost/bind.hpp>
47 #include <boost/shared_ptr.hpp>
50 using lyx::support::ltrim;
52 using lyx::frontend::GuiImplementation;
53 using lyx::frontend::GuiView;
54 using lyx::frontend::GuiApplication;
56 using boost::shared_ptr;
58 #ifndef CXX_GLOBAL_CSTD
66 lyx::frontend::GuiApplication * guiApp;
67 lyx::frontend::Application * theApp;
72 map<int, shared_ptr<socket_callback> > socket_callbacks;
80 int exec(int & argc, char * argv[])
83 FIXME : Abdel 29/05/2006 (younes.a@free.fr)
84 reorganize this code. In particular make sure that this
85 advice from Qt documentation is respected:
87 Since the QApplication object does so much initialization, it
88 must be created before any other objects related to the user
89 interface are created.
91 Right now this is not the case, I suspect that a number of global variables
92 contains Qt object that are initialized before the passage through
93 parse_init(). This might also explain the message displayed by Qt
94 that caused the hanging:
96 QObject::killTimer: timers cannot be stopped from another thread
98 I hope that the problem will disappear automagically when we get rid of
99 lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
100 Clipboard and Selection access.
103 // Force adding of font path _before_ QApplication is initialized
104 FontLoader::initFontPath();
106 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
107 static GuiApplication app(argc, argv);
109 GuiApplication app(argc, argv);
115 return LyX::ref().exec2(argc, argv);
123 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
126 return &guiApp->createView(width, height, posx, posy, maximize);
130 int start(LyXView * view, string const & batch)
132 return theApp->start(batch);
138 // This is the ONLY place where processEvents may be called.
139 // During screen update/ redraw, this method is disabled to
140 // prevent keyboard events being handed to the LyX core, where
141 // they could cause re-entrant calls to screen update.
142 guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
146 void exit(int status)
148 guiApp->exit(status);
152 FuncStatus getStatus(FuncRequest const & ev)
156 case LFUN_TOOLTIPS_TOGGLE:
167 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
169 QColor const & qcol = guiApp->colorCache().get(col);
170 if (!qcol.isValid()) {
176 rgbcol.r = qcol.red();
177 rgbcol.g = qcol.green();
178 rgbcol.b = qcol.blue();
183 string const hexname(LColor_color col)
185 return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
189 void update_color(LColor_color)
191 // FIXME: Bleh, can't we just clear them all at once ?
192 guiApp->colorCache().clear();
198 guiApp->fontLoader().update();
202 bool font_available(LyXFont const & font)
204 return guiApp->fontLoader().available(font);
208 void register_socket_callback(int fd, boost::function<void()> func)
210 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
214 void unregister_socket_callback(int fd)
216 socket_callbacks.erase(fd);
220 string const roman_font_name()
226 font.setStyleHint(QFont::Serif);
227 font.setFamily("serif");
229 return fromqstr(QFontInfo(font).family());
233 string const sans_font_name()
239 font.setStyleHint(QFont::SansSerif);
240 font.setFamily("sans");
242 return fromqstr(QFontInfo(font).family());
246 string const typewriter_font_name()
252 font.setStyleHint(QFont::TypeWriter);
253 font.setFamily("monospace");
255 return fromqstr(QFontInfo(font).family());
258 }; // namespace lyx_gui