3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 // FIXME: move this stuff out again
17 #include "bufferlist.h"
18 #include "BufferView.h"
19 #include "funcrequest.h"
22 #include "LyXAction.h"
25 #include "lyxserver.h"
26 #include "lyxsocket.h"
28 #include "graphics/LoaderQueue.h"
30 #include "support/lstrings.h"
31 #include "support/os.h"
34 // Dear Lord, deliver us from Evil, aka the Qt headers
35 // Qt defines a macro 'signals' that clashes with a boost namespace.
36 // All is well if the namespace is visible first.
37 #include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
38 #include <boost/bind.hpp>
39 #include <boost/shared_ptr.hpp>
42 #include "lcolorcache.h"
43 #include "qfont_loader.h"
45 #include "qt_helpers.h"
46 #include "socket_callback.h"
49 #include <Carbon/Carbon.h>
52 #include <qapplication.h>
53 #include <qpaintdevicemetrics.h>
54 #include <qtranslator.h>
55 #include <qtextcodec.h>
57 using lyx::support::ltrim;
59 using lyx::frontend::QtView;
61 namespace os = lyx::support::os;
63 using boost::shared_ptr;
65 #ifndef CXX_GLOBAL_CSTD
74 extern BufferList bufferlist;
81 QPaintDeviceMetrics pdm(&w);
82 return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY());
85 map<int, shared_ptr<socket_callback> > socket_callbacks;
89 // FIXME: wrong place !
90 LyXServer * lyxserver;
91 LyXServerSocket * lyxsocket;
94 extern void initEncodings();
97 extern bool lyxX11EventFilter(XEvent * xev);
101 extern bool macEventFilter(EventRef event);
103 handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
107 class LQApplication : public QApplication
110 LQApplication(int & argc, char ** argv);
113 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
116 bool macEventFilter(EventRef event);
121 LQApplication::LQApplication(int & argc, char ** argv)
122 : QApplication(argc, argv)
125 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
126 NewAEEventHandlerUPP(handleOpenDocuments),
132 LQApplication::~LQApplication()
137 bool LQApplication::macEventFilter(EventRef event)
139 if (GetEventClass(event) == kEventClassAppleEvent) {
140 EventRecord eventrec;
141 ConvertEventRefToEventRecord(event, &eventrec);
142 AEProcessAppleEvent(&eventrec);
155 void parse_init(int & argc, char * argv[])
157 // Force adding of font path _before_ QApplication is initialized
158 qfont_loader::initFontPath();
160 static LQApplication app(argc, argv);
162 #if QT_VERSION >= 0x030200
163 // install translation file for Qt built-in dialogs
164 // These are only installed since Qt 3.2.x
165 static QTranslator qt_trans(0);
166 if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
167 qInstallPathTranslations())) {
168 app.installTranslator(&qt_trans);
169 // even if the language calls for RtL, don't do that
170 app.setReverseLayout(false);
172 << "Successfully installed Qt translations for locale "
173 << QTextCodec::locale() << std::endl;
176 << "Could not find Qt translations for locale "
177 << QTextCodec::locale() << std::endl;
181 // These translations are meant to break Qt/Mac menu merging
182 // algorithm on some entries. It lists the menu names that
183 // should not be moved to the LyX menu
184 static QTranslator aqua_trans(0);
185 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
187 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
189 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
191 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
194 app.installTranslator(&aqua_trans);
197 using namespace lyx::graphics;
199 Image::newImage = boost::bind(&QLImage::newImage);
200 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
202 // needs to be done before reading lyxrc
203 lyxrc.dpi = getDPI();
207 LoaderQueue::setPriority(10,100);
215 void start(string const & batch, vector<string> const & files)
218 unsigned int width = 690;
219 unsigned int height = 510;
221 boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
222 LyX::ref().addLyXView(view_ptr);
224 QtView & view = *view_ptr.get();
228 // FIXME: some code below needs moving
230 lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
231 lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
232 os::slashify_path(os::getTmpDir() + "/lyxsocket"));
234 for_each(files.begin(), files.end(),
235 bind(&BufferView::loadLyXFile, view.view(), _1, true));
237 // handle the batch commands the user asked for
238 if (!batch.empty()) {
239 view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
253 qApp->processEvents();
263 // we cannot call qApp->exit(0) - that could return us
264 // into a static dialog return in the lyx code (for example,
265 // load autosave file QMessageBox. We have to just get the hell
272 FuncStatus getStatus(FuncRequest const & ev)
276 case LFUN_DIALOG_SHOW:
277 if (ev.argument == "preamble")
280 case LFUN_TOOLTIPS_TOGGLE:
291 string const hexname(LColor_color col)
293 return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
297 void update_color(LColor_color)
299 // FIXME: Bleh, can't we just clear them all at once ?
310 bool font_available(LyXFont const & font)
312 return fontloader.available(font);
316 void register_socket_callback(int fd, boost::function<void()> func)
318 socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
322 void unregister_socket_callback(int fd)
324 socket_callbacks.erase(fd);
328 string const roman_font_name()
334 font.setStyleHint(QFont::Serif);
335 font.setFamily("serif");
337 return fromqstr(QFontInfo(font).family());
341 string const sans_font_name()
347 font.setStyleHint(QFont::SansSerif);
348 font.setFamily("sans");
350 return fromqstr(QFontInfo(font).family());
354 string const typewriter_font_name()
360 font.setStyleHint(QFont::TypeWriter);
361 font.setFamily("monospace");
363 return fromqstr(QFontInfo(font).family());
366 }; // namespace lyx_gui