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"
27 #include "lyxserver.h"
28 #include "lyxsocket.h"
31 #include "support/lstrings.h"
35 #include "ColorCache.h"
36 #include "FontLoader.h"
38 #include "qt_helpers.h"
39 #include "socket_callback.h"
40 #include "GuiApplication.h"
42 #include <QApplication>
44 #include <QTranslator>
47 #include <QLibraryInfo>
49 #include <boost/bind.hpp>
50 #include <boost/shared_ptr.hpp>
53 using lyx::support::ltrim;
55 using lyx::frontend::GuiImplementation;
56 using lyx::frontend::GuiView;
57 using lyx::frontend::GuiApplication;
59 using boost::shared_ptr;
61 #ifndef CXX_GLOBAL_CSTD
69 lyx::frontend::GuiApplication * guiApp;
70 lyx::frontend::Application * theApp;
75 map<int, shared_ptr<socket_callback> > socket_callbacks;
83 int exec(int & argc, char * argv[])
86 FIXME : Abdel 29/05/2006 (younes.a@free.fr)
87 reorganize this code. In particular make sure that this
88 advice from Qt documentation is respected:
90 Since the QApplication object does so much initialization, it
91 must be created before any other objects related to the user
92 interface are created.
94 Right now this is not the case, I suspect that a number of global variables
95 contains Qt object that are initialized before the passage through
96 parse_init(). This might also explain the message displayed by Qt
97 that caused the hanging:
99 QObject::killTimer: timers cannot be stopped from another thread
101 I hope that the problem will disappear automagically when we get rid of
102 lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
103 Clipboard and Selection access.
106 // Force adding of font path _before_ QApplication is initialized
107 FontLoader::initFontPath();
109 #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
110 static GuiApplication app(argc, argv);
112 GuiApplication app(argc, argv);
118 return LyX::ref().exec2(argc, argv);
126 LyXView * create_view(unsigned int width, unsigned int height, int posx, int posy,
129 return &guiApp->createView(width, height, posx, posy, maximize);
133 int start(LyXView * view, string const & batch)
135 return theApp->start(batch);
141 // This is the ONLY place where processEvents may be called.
142 // During screen update/ redraw, this method is disabled to
143 // prevent keyboard events being handed to the LyX core, where
144 // they could cause re-entrant calls to screen update.
145 guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
149 void exit(int status)
151 guiApp->exit(status);
155 FuncStatus getStatus(FuncRequest const & ev)
159 case LFUN_TOOLTIPS_TOGGLE:
170 bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
172 QColor const & qcol = lcolorcache.get(col);
173 if (!qcol.isValid()) {
179 rgbcol.r = qcol.red();
180 rgbcol.g = qcol.green();
181 rgbcol.b = qcol.blue();
186 string const hexname(LColor_color col)
188 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
192 void update_color(LColor_color)
194 // FIXME: Bleh, can't we just clear them all at once ?
201 guiApp->fontLoader().update();
205 bool font_available(LyXFont const & font)
207 return guiApp->fontLoader().available(font);
211 void register_socket_callback(int fd, boost::function<void()> func)
213 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
217 void unregister_socket_callback(int fd)
219 socket_callbacks.erase(fd);
223 string const roman_font_name()
229 font.setStyleHint(QFont::Serif);
230 font.setFamily("serif");
232 return fromqstr(QFontInfo(font).family());
236 string const sans_font_name()
242 font.setStyleHint(QFont::SansSerif);
243 font.setFamily("sans");
245 return fromqstr(QFontInfo(font).family());
249 string const typewriter_font_name()
255 font.setStyleHint(QFont::TypeWriter);
256 font.setFamily("monospace");
258 return fromqstr(QFontInfo(font).family());
261 }; // namespace lyx_gui