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 "BufferView.h"
22 // FIXME: this is needed for now because LyXFunc is still constructed
24 #include "frontends/Application_pimpl.h"
26 #include "graphics/LoaderQueue.h"
28 #include "support/lstrings.h"
29 #include "support/os.h"
30 #include "support/package.h"
36 #include <QApplication>
40 #include <QLibraryInfo>
42 #include <QTranslator>
49 #include <boost/bind.hpp>
51 using lyx::support::subst;
57 extern void initEncodings();
59 ///////////////////////////////////////////////////////////////
60 // You can find other X11 and MACX specific stuff
61 // at the end of this file...
62 ///////////////////////////////////////////////////////////////
69 return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
78 GuiApplication::GuiApplication(int & argc, char ** argv)
79 : QApplication(argc, argv), Application(argc, argv)
82 // doubleClickInterval() is 400 ms on X11 witch is just too long.
83 // On Windows and Mac OS X, the operating system's value is used.
84 // On Microsoft Windows, calling this function sets the double
85 // click interval for all applications. So we don't!
86 QApplication::setDoubleClickInterval(300);
90 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
91 NewAEEventHandlerUPP(handleOpenDocuments),
95 // install translation file for Qt built-in dialogs
96 // These are only installed since Qt 3.2.x
98 QString language_name = QString("qt_") + QLocale::system().name();
99 language_name.truncate(5);
100 if (qt_trans.load(language_name,
101 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
103 qApp->installTranslator(&qt_trans);
104 // even if the language calls for RtL, don't do that
105 qApp->setLayoutDirection(Qt::LeftToRight);
107 << "Successfully installed Qt translations for locale "
108 << fromqstr(language_name) << std::endl;
111 << "Could not find Qt translations for locale "
112 << fromqstr(language_name) << std::endl;
115 // These translations are meant to break Qt/Mac menu merging
116 // algorithm on some entries. It lists the menu names that
117 // should not be moved to the LyX menu
118 QTranslator aqua_trans(0);
119 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
121 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
123 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
125 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
128 qApp->installTranslator(&aqua_trans);
131 using namespace lyx::graphics;
133 Image::newImage = boost::bind(&QLImage::newImage);
134 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
136 // needs to be done before reading lyxrc
137 lyxrc.dpi = getDPI();
139 LoaderQueue::setPriority(10,100);
143 Clipboard& GuiApplication::clipboard()
149 Selection& GuiApplication::selection()
155 int const GuiApplication::exec()
157 return QApplication::exec();
161 void GuiApplication::exit(int status)
163 QApplication::exit(status);
169 ////////////////////////////////////////////////////////////////////////
170 // X11 specific stuff goes here...
172 bool GuiApplication::x11EventFilter(XEvent * xev)
175 case SelectionRequest:
176 lyxerr[Debug::GUI] << "X requested selection." << endl;
178 lyx::docstring const sel = buffer_view_->requestSelection();
184 lyxerr[Debug::GUI] << "Lost selection." << endl;
186 buffer_view_->clearSelection();
194 ////////////////////////////////////////////////////////////////////////
195 // Mac OSX specific stuff goes here...
200 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
202 DescType returnedType;
204 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
205 typeWildCard, &returnedType, nil, 0,
208 case errAEDescNotFound:
211 return errAEEventNotHandled;
219 OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
220 AppleEvent* /*reply*/, long /*refCon*/)
223 AEDescList documentList;
224 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
229 err = checkAppleEventForMissingParams(*inEvent);
232 err = AECountItems(&documentList, &documentCount);
233 for (long documentIndex = 1;
234 err == noErr && documentIndex <= documentCount;
236 DescType returnedType;
241 err = AESizeOfNthItem(&documentList, documentIndex,
242 &returnedType, &actualSize);
244 err = AEGetNthPtr(&documentList, documentIndex,
246 &returnedType, (Ptr)&ref,
247 sizeof(FSRef), &actualSize);
249 FSRefMakePath(&ref, (UInt8*)qstr_buf,
251 s_arg=QString::fromUtf8(qstr_buf);
252 // buffer_view_->workAreaDispatch(
253 // FuncRequest(LFUN_FILE_OPEN,
254 // fromqstr(s_arg)));
260 AEDisposeDesc(&documentList);
265 bool GuiApplication::macEventFilter(EventRef event)
267 if (GetEventClass(event) == kEventClassAppleEvent) {
268 EventRecord eventrec;
269 ConvertEventRefToEventRecord(event, &eventrec);
270 AEProcessAppleEvent(&eventrec);
279 } // namespace frontend