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 "FontLoader.h"
33 #include "qt_helpers.h"
34 #include "socket_callback.h"
35 #include "GuiApplication.h"
37 #include <QApplication>
39 #include <QTranslator>
42 #include <QLibraryInfo>
44 #include <boost/bind.hpp>
45 #include <boost/shared_ptr.hpp>
48 using lyx::support::ltrim;
50 using lyx::frontend::GuiImplementation;
51 using lyx::frontend::GuiView;
52 using lyx::frontend::GuiApplication;
54 using boost::shared_ptr;
56 #ifndef CXX_GLOBAL_CSTD
64 lyx::frontend::GuiApplication * guiApp;
65 lyx::frontend::Application * theApp;
70 map<int, shared_ptr<socket_callback> > socket_callbacks;
78 int exec(int & argc, char * argv[])
81 FIXME : Abdel 29/05/2006 (younes.a@free.fr)
82 reorganize this code. In particular make sure that this
83 advice from Qt documentation is respected:
85 Since the QApplication object does so much initialization, it
86 must be created before any other objects related to the user
87 interface are created.
89 Right now this is not the case, I suspect that a number of global variables
90 contains Qt object that are initialized before the passage through
91 parse_init(). This might also explain the message displayed by Qt
92 that caused the hanging:
94 QObject::killTimer: timers cannot be stopped from another thread
96 I hope that the problem will disappear automagically when we get rid of
97 lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
98 Clipboard and Selection access.
101 // Force adding of font path _before_ QApplication is initialized
102 FontLoader::initFontPath();
104 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
105 static GuiApplication app(argc, argv);
107 GuiApplication app(argc, argv);
113 return LyX::ref().exec2(argc, argv);
121 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
124 return &guiApp->createView(width, height, posx, posy, maximize);
128 int start(LyXView * view, string const & batch)
130 return theApp->start(batch);
136 // This is the ONLY place where processEvents may be called.
137 // During screen update/ redraw, this method is disabled to
138 // prevent keyboard events being handed to the LyX core, where
139 // they could cause re-entrant calls to screen update.
140 guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
144 void exit(int status)
146 guiApp->exit(status);
150 FuncStatus getStatus(FuncRequest const & ev)
154 case LFUN_TOOLTIPS_TOGGLE:
165 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
167 QColor const & qcol = guiApp->colorCache().get(col);
168 if (!qcol.isValid()) {
174 rgbcol.r = qcol.red();
175 rgbcol.g = qcol.green();
176 rgbcol.b = qcol.blue();
181 string const hexname(LColor_color col)
183 return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
187 void update_color(LColor_color)
189 // FIXME: Bleh, can't we just clear them all at once ?
190 guiApp->colorCache().clear();
196 guiApp->fontLoader().update();
200 bool font_available(LyXFont const & font)
202 return guiApp->fontLoader().available(font);
206 void register_socket_callback(int fd, boost::function<void()> func)
208 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
212 void unregister_socket_callback(int fd)
214 socket_callbacks.erase(fd);
218 string const roman_font_name()
224 font.setStyleHint(QFont::Serif);
225 font.setFamily("serif");
227 return fromqstr(QFontInfo(font).family());
231 string const sans_font_name()
237 font.setStyleHint(QFont::SansSerif);
238 font.setFamily("sans");
240 return fromqstr(QFontInfo(font).family());
244 string const typewriter_font_name()
250 font.setStyleHint(QFont::TypeWriter);
251 font.setFamily("monospace");
253 return fromqstr(QFontInfo(font).family());
256 }; // namespace lyx_gui