>>>>> "Bennett" == Bennett Helm <[EMAIL PROTECTED]> writes:

Bennett> Drag-and-drop to the LyX window works, but it does not work
Bennett> to the Dock icon.

This is because the code to do so has been disabled. Moreover, Qt4 has
native support for this kind of stuff, and I propose to use something
like the attached patch (which does a nice cleanup).

Abdel, the important part of the patch is commented out. How can I
dispatch from GuiApplication?

        case QEvent::FileOpen: {
                // Open a file; this happens only on Mac OS X for now
                QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
//              bv->workAreaDispatch(
//                      FuncRequest(LFUN_FILE_OPEN,
//                                  fromqstr(foe->file())));
                return true;

JMarc

Index: src/frontends/qt4/GuiApplication.C
===================================================================
--- src/frontends/qt4/GuiApplication.C	(revision 16090)
+++ src/frontends/qt4/GuiApplication.C	(working copy)
@@ -37,6 +37,7 @@
 #include <QApplication>
 #include <QClipboard>
 #include <QEventLoop>
+#include <QFileOpenEvent>
 #include <QLocale>
 #include <QLibraryInfo>
 #include <QTextCodec>
@@ -102,12 +103,6 @@ GuiApplication::GuiApplication(int & arg
 	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,23 @@ string const GuiApplication::typewriterF
 }
 
 
+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<QFileOpenEvent *>(e);
+// 		bv->workAreaDispatch(
+// 			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.
@@ -303,84 +315,6 @@ bool GuiApplication::x11EventFilter(XEve
 // 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
 
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h	(revision 16090)
+++ src/frontends/qt4/GuiApplication.h	(working copy)
@@ -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;

Reply via email to