2 * \file qt4/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 "GuiApplication.h"
17 #include "qt_helpers.h"
20 #include "graphics/LoaderQueue.h"
22 #include "support/lstrings.h"
23 #include "support/os.h"
24 #include "support/package.h"
26 #include "BufferView.h"
31 #include <QApplication>
35 #include <QLibraryInfo>
37 #include <QTranslator>
44 #include <boost/bind.hpp>
46 using lyx::support::subst;
52 extern void initEncodings();
54 ///////////////////////////////////////////////////////////////
55 // You can find other X11 and MACX specific stuff
56 // at the end of this file...
57 ///////////////////////////////////////////////////////////////
64 return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
73 GuiApplication::GuiApplication(int & argc, char ** argv)
74 : QApplication(argc, argv), Application(argc, argv)
77 // doubleClickInterval() is 400 ms on X11 witch is just too long.
78 // On Windows and Mac OS X, the operating system's value is used.
79 // On Microsoft Windows, calling this function sets the double
80 // click interval for all applications. So we don't!
81 QApplication::setDoubleClickInterval(300);
85 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
86 NewAEEventHandlerUPP(handleOpenDocuments),
90 // install translation file for Qt built-in dialogs
91 // These are only installed since Qt 3.2.x
93 QString language_name = QString("qt_") + QLocale::system().name();
94 language_name.truncate(5);
95 if (qt_trans.load(language_name,
96 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
98 qApp->installTranslator(&qt_trans);
99 // even if the language calls for RtL, don't do that
100 qApp->setLayoutDirection(Qt::LeftToRight);
102 << "Successfully installed Qt translations for locale "
103 << fromqstr(language_name) << std::endl;
106 << "Could not find Qt translations for locale "
107 << fromqstr(language_name) << std::endl;
110 // These translations are meant to break Qt/Mac menu merging
111 // algorithm on some entries. It lists the menu names that
112 // should not be moved to the LyX menu
113 QTranslator aqua_trans(0);
114 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
116 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
118 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
120 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
123 qApp->installTranslator(&aqua_trans);
126 using namespace lyx::graphics;
128 Image::newImage = boost::bind(&QLImage::newImage);
129 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
131 // needs to be done before reading lyxrc
132 lyxrc.dpi = getDPI();
134 LoaderQueue::setPriority(10,100);
138 Clipboard& GuiApplication::clipboard()
144 Selection& GuiApplication::selection()
150 int const GuiApplication::exec()
152 return QApplication::exec();
156 void GuiApplication::exit(int status)
158 QApplication::exit(status);
164 ////////////////////////////////////////////////////////////////////////
165 // X11 specific stuff goes here...
167 bool GuiApplication::x11EventFilter(XEvent * xev)
170 case SelectionRequest:
171 lyxerr[Debug::GUI] << "X requested selection." << endl;
173 lyx::docstring const sel = buffer_view_->requestSelection();
179 lyxerr[Debug::GUI] << "Lost selection." << endl;
181 buffer_view_->clearSelection();
189 ////////////////////////////////////////////////////////////////////////
190 // Mac OSX specific stuff goes here...
195 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
197 DescType returnedType;
199 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
200 typeWildCard, &returnedType, nil, 0,
203 case errAEDescNotFound:
206 return errAEEventNotHandled;
214 OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
215 AppleEvent* /*reply*/, long /*refCon*/)
218 AEDescList documentList;
219 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
224 err = checkAppleEventForMissingParams(*inEvent);
227 err = AECountItems(&documentList, &documentCount);
228 for (long documentIndex = 1;
229 err == noErr && documentIndex <= documentCount;
231 DescType returnedType;
236 err = AESizeOfNthItem(&documentList, documentIndex,
237 &returnedType, &actualSize);
239 err = AEGetNthPtr(&documentList, documentIndex,
241 &returnedType, (Ptr)&ref,
242 sizeof(FSRef), &actualSize);
244 FSRefMakePath(&ref, (UInt8*)qstr_buf,
246 s_arg=QString::fromUtf8(qstr_buf);
247 // buffer_view_->workAreaDispatch(
248 // FuncRequest(LFUN_FILE_OPEN,
249 // fromqstr(s_arg)));
255 AEDisposeDesc(&documentList);
260 bool GuiApplication::macEventFilter(EventRef event)
262 if (GetEventClass(event) == kEventClassAppleEvent) {
263 EventRecord eventrec;
264 ConvertEventRefToEventRecord(event, &eventrec);
265 AEProcessAppleEvent(&eventrec);
274 } // namespace frontend