mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 14:29:21 +00:00
* 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
This commit is contained in:
parent
6e7c76fe4f
commit
e1771f375b
@ -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 & 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<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.
|
||||
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user