From: Jean-Marc Lasgouttes Date: Wed, 29 Nov 2006 09:06:37 +0000 (+0000) Subject: * qt4/GuiApplication.C: remove ad-hoc Mac OSX Carbon code to handle X-Git-Tag: 1.6.10~11717 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e1771f375b11905550415b98232ed8b6be4dfa5c;p=features.git * qt4/GuiApplication.C: remove ad-hoc Mac OSX Carbon code to handle kAEOpenDocuments ApleEvent. (event): new method to do the same thing using qt4 built-in support. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16099 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C index fb5a1b0432..ffd1624cc9 100644 --- a/src/frontends/qt4/GuiApplication.C +++ b/src/frontends/qt4/GuiApplication.C @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -102,12 +103,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv) QApplication::setDoubleClickInterval(300); #endif -#ifdef Q_WS_MACX - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - NewAEEventHandlerUPP(handleOpenDocuments), - 0, false); -#endif - // install translation file for Qt built-in dialogs QTranslator qt_trans; QString language_name = QString("qt_") + QLocale::system().name(); @@ -220,6 +215,22 @@ string const GuiApplication::typewriterFontName() } +bool GuiApplication::event(QEvent * e) +{ + switch(e->type()) { + case QEvent::FileOpen: { + // Open a file; this happens only on Mac OS X for now + QFileOpenEvent * foe = static_cast(e); + lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, + fromqstr(foe->file()))); + return true; + } + default: + return false; + } +} + + void GuiApplication::syncEvents() { // This is the ONLY place where processEvents may be called. @@ -299,91 +310,6 @@ bool GuiApplication::x11EventFilter(XEvent * xev) #endif -//////////////////////////////////////////////////////////////////////// -// Mac OSX specific stuff goes here... - -#ifdef Q_WS_MACX -namespace{ - -OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent) - { - DescType returnedType; - Size actualSize; - OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, - typeWildCard, &returnedType, nil, 0, - &actualSize); - switch (err) { - case errAEDescNotFound: - return noErr; - case noErr: - return errAEEventNotHandled; - default: - return err; - } - } - -} // namespace - -OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent, - AppleEvent* /*reply*/, long /*refCon*/) -{ - QString s_arg; - AEDescList documentList; - OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList, - &documentList); - if (err != noErr) - return err; - - err = checkAppleEventForMissingParams(*inEvent); - if (err == noErr) { - long documentCount; - err = AECountItems(&documentList, &documentCount); - for (long documentIndex = 1; - err == noErr && documentIndex <= documentCount; - documentIndex++) { - DescType returnedType; - Size actualSize; - AEKeyword keyword; - FSRef ref; - char qstr_buf[1024]; - err = AESizeOfNthItem(&documentList, documentIndex, - &returnedType, &actualSize); - if (err == noErr) { - err = AEGetNthPtr(&documentList, documentIndex, - typeFSRef, &keyword, - &returnedType, (Ptr)&ref, - sizeof(FSRef), &actualSize); - if (err == noErr) { - FSRefMakePath(&ref, (UInt8*)qstr_buf, - 1024); - s_arg=QString::fromUtf8(qstr_buf); -// bv->workAreaDispatch( -// FuncRequest(LFUN_FILE_OPEN, -// fromqstr(s_arg))); - break; - } - } - } // for ... - } - AEDisposeDesc(&documentList); - - return err; -} - -bool GuiApplication::macEventFilter(EventRef event) -{ - if (GetEventClass(event) == kEventClassAppleEvent) { - EventRecord eventrec; - ConvertEventRefToEventRecord(event, &eventrec); - AEProcessAppleEvent(&eventrec); - - return false; - } - return false; -} - -#endif // Q_WS_MACX - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 656d873003..1f609467c7 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -65,6 +65,7 @@ public: virtual int const exec(); virtual Gui & gui() { return gui_; } virtual void exit(int status); + virtual bool event(QEvent * e); void syncEvents(); virtual std::string const romanFontName(); virtual std::string const sansFontName(); @@ -106,14 +107,6 @@ public: bool x11EventFilter (XEvent * ev); #endif -#ifdef Q_WS_MACX -public: - bool macEventFilter(EventRef event); -private: -// static OSStatus handleOpenDocuments( - static pascal OSErr handleOpenDocuments( - const AppleEvent* inEvent, AppleEvent*, long); -#endif }; // GuiApplication extern GuiApplication * guiApp;