2 * \file qt3/GuiApplication.C
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.
15 #include "frontends/LyXView.h"
16 #include "frontends/WorkArea.h"
18 #include "GuiApplication.h"
20 #include "qt_helpers.h"
23 #include "graphics/LoaderQueue.h"
25 #include "support/lstrings.h"
26 #include "support/os.h"
27 #include "support/package.h"
29 #include "BufferView.h"
34 #include <qapplication.h>
35 #include <qclipboard.h>
36 #include <qeventloop.h>
38 #include <qpaintdevicemetrics.h>
39 #include <qtextcodec.h>
40 #include <qtranslator.h>
46 #include <boost/bind.hpp>
48 using lyx::support::subst;
54 extern void initEncodings();
56 ///////////////////////////////////////////////////////////////
57 // You can find other X11 and MACX specific stuff
58 // at the end of this file...
59 ///////////////////////////////////////////////////////////////
66 QPaintDeviceMetrics pdm(&w);
67 return int(0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()));
76 GuiApplication::GuiApplication(int & argc, char ** argv)
77 : QApplication(argc, argv), Application(argc, argv)
80 // doubleClickInterval() is 400 ms on X11 witch is just too long.
81 // On Windows and Mac OS X, the operating system's value is used.
82 // On Microsoft Windows, calling this function sets the double
83 // click interval for all applications. So we don't!
84 QApplication::setDoubleClickInterval(300);
88 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
89 NewAEEventHandlerUPP(handleOpenDocuments),
93 #if QT_VERSION >= 0x030200
94 // install translation file for Qt built-in dialogs
95 // These are only installed since Qt 3.2.x
96 QTranslator qt_trans(0);
97 if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
98 qInstallPathTranslations())) {
99 qApp->installTranslator(&qt_trans);
100 // even if the language calls for RtL, don't do that
101 qApp->setReverseLayout(false);
103 << "Successfully installed Qt translations for locale "
104 << QTextCodec::locale() << std::endl;
107 << "Could not find Qt translations for locale "
108 << QTextCodec::locale() << std::endl;
112 // These translations are meant to break Qt/Mac menu merging
113 // algorithm on some entries. It lists the menu names that
114 // should not be moved to the LyX menu
115 QTranslator aqua_trans(0);
116 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
118 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
120 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
122 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
125 qApp->installTranslator(&aqua_trans);
128 using namespace lyx::graphics;
130 Image::newImage = boost::bind(&QLImage::newImage);
131 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
133 // needs to be done before reading lyxrc
134 lyxrc.dpi = getDPI();
136 LoaderQueue::setPriority(10,100);
140 Clipboard& GuiApplication::clipboard()
146 Selection& GuiApplication::selection()
152 int const GuiApplication::exec()
154 return QApplication::exec();
158 void GuiApplication::exit(int status)
160 QApplication::exit(status);
164 string const GuiApplication::romanFontName()
167 font.setStyleHint(QFont::Serif);
168 font.setFamily("serif");
170 return fromqstr(QFontInfo(font).family());
174 string const GuiApplication::sansFontName()
177 font.setStyleHint(QFont::SansSerif);
178 font.setFamily("sans");
180 return fromqstr(QFontInfo(font).family());
184 string const GuiApplication::typewriterFontName()
187 font.setStyleHint(QFont::TypeWriter);
188 font.setFamily("monospace");
190 return fromqstr(QFontInfo(font).family());
194 ////////////////////////////////////////////////////////////////////////
195 // X11 specific stuff goes here...
197 bool GuiApplication::x11EventFilter(XEvent * xev)
200 case SelectionRequest:
201 lyxerr[Debug::GUI] << "X requested selection." << endl;
203 lyx::docstring const sel = buffer_view_->requestSelection();
209 lyxerr[Debug::GUI] << "Lost selection." << endl;
211 buffer_view_->clearSelection();
219 ////////////////////////////////////////////////////////////////////////
220 // Mac OSX specific stuff goes here...
225 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
227 DescType returnedType;
229 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
230 typeWildCard, &returnedType, nil, 0,
233 case errAEDescNotFound:
236 return errAEEventNotHandled;
244 OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
245 AppleEvent* /*reply*/, long /*refCon*/)
248 AEDescList documentList;
249 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
254 err = checkAppleEventForMissingParams(*inEvent);
257 err = AECountItems(&documentList, &documentCount);
258 for (long documentIndex = 1;
259 err == noErr && documentIndex <= documentCount;
261 DescType returnedType;
266 err = AESizeOfNthItem(&documentList, documentIndex,
267 &returnedType, &actualSize);
269 err = AEGetNthPtr(&documentList, documentIndex,
271 &returnedType, (Ptr)&ref,
272 sizeof(FSRef), &actualSize);
274 FSRefMakePath(&ref, (UInt8*)qstr_buf,
276 s_arg=QString::fromUtf8(qstr_buf);
277 // buffer_view_->workAreaDispatch(
278 // FuncRequest(LFUN_FILE_OPEN,
279 // fromqstr(s_arg)));
285 AEDisposeDesc(&documentList);
290 bool GuiApplication::macEventFilter(EventRef event)
292 if (GetEventClass(event) == kEventClassAppleEvent) {
293 EventRecord eventrec;
294 ConvertEventRefToEventRecord(event, &eventrec);
295 AEProcessAppleEvent(&eventrec);
304 } // namespace frontend