#include <QApplication>
#include <QClipboard>
#include <QEventLoop>
+#include <QFileOpenEvent>
#include <QLocale>
#include <QLibraryInfo>
#include <QTextCodec>
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();
}
+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);
+ 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.
#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
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();
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;