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);
162 string const GuiApplication::romanFontName()
165 font.setStyleHint(QFont::Serif);
166 font.setFamily("serif");
168 return fromqstr(QFontInfo(font).family());
172 string const GuiApplication::sansFontName()
175 font.setStyleHint(QFont::SansSerif);
176 font.setFamily("sans");
178 return fromqstr(QFontInfo(font).family());
182 string const GuiApplication::typewriterFontName()
185 font.setStyleHint(QFont::TypeWriter);
186 font.setFamily("monospace");
188 return fromqstr(QFontInfo(font).family());
192 ////////////////////////////////////////////////////////////////////////
193 // X11 specific stuff goes here...
195 bool GuiApplication::x11EventFilter(XEvent * xev)
198 case SelectionRequest:
199 lyxerr[Debug::GUI] << "X requested selection." << endl;
201 lyx::docstring const sel = buffer_view_->requestSelection();
207 lyxerr[Debug::GUI] << "Lost selection." << endl;
209 buffer_view_->clearSelection();
217 ////////////////////////////////////////////////////////////////////////
218 // Mac OSX specific stuff goes here...
223 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
225 DescType returnedType;
227 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
228 typeWildCard, &returnedType, nil, 0,
231 case errAEDescNotFound:
234 return errAEEventNotHandled;
242 OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
243 AppleEvent* /*reply*/, long /*refCon*/)
246 AEDescList documentList;
247 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
252 err = checkAppleEventForMissingParams(*inEvent);
255 err = AECountItems(&documentList, &documentCount);
256 for (long documentIndex = 1;
257 err == noErr && documentIndex <= documentCount;
259 DescType returnedType;
264 err = AESizeOfNthItem(&documentList, documentIndex,
265 &returnedType, &actualSize);
267 err = AEGetNthPtr(&documentList, documentIndex,
269 &returnedType, (Ptr)&ref,
270 sizeof(FSRef), &actualSize);
272 FSRefMakePath(&ref, (UInt8*)qstr_buf,
274 s_arg=QString::fromUtf8(qstr_buf);
275 // buffer_view_->workAreaDispatch(
276 // FuncRequest(LFUN_FILE_OPEN,
277 // fromqstr(s_arg)));
283 AEDisposeDesc(&documentList);
288 bool GuiApplication::macEventFilter(EventRef event)
290 if (GetEventClass(event) == kEventClassAppleEvent) {
291 EventRecord eventrec;
292 ConvertEventRefToEventRecord(event, &eventrec);
293 AEProcessAppleEvent(&eventrec);
302 } // namespace frontend