diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index ab27294eca..f155bfa2b3 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -93,6 +93,7 @@ unsigned int const saved_positions_num = 20; // (Lgb) boost::signals::connection dispatchcon; +boost::signals::connection viewdispatchcon; boost::signals::connection timecon; boost::signals::connection doccon; boost::signals::connection resizecon; @@ -119,6 +120,8 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this)); dispatchcon = workarea().dispatch .connect(boost::bind(&BufferView::Pimpl::dispatch, this, _1)); + viewdispatchcon = workarea().viewDispatch + .connect(boost::bind(&BufferView::Pimpl::viewDispatch, this, _1)); kpresscon = workarea().workAreaKeyPress .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2)); selectioncon = workarea().selectionRequested @@ -915,6 +918,13 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) } +bool BufferView::Pimpl::viewDispatch(FuncRequest const & ev) +{ + owner_->dispatch(ev); + return true; +} + + bool BufferView::Pimpl::dispatch(FuncRequest const & ev) { lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:" diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 9a77eba226..afd21fa690 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -102,6 +102,9 @@ struct BufferView::Pimpl : public boost::signals::trackable { void updateInset(Inset * inset, bool mark_dirty); /// bool dispatch(FuncRequest const & ev); + /// + bool viewDispatch(FuncRequest const & ev); + private: /// friend class BufferView; diff --git a/src/ChangeLog b/src/ChangeLog index ea938e6f75..84f9a5af87 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-12-04 Jean-Marc Lasgouttes + + * BufferView_pimpl.C (viewDispatch): new method, called by the qt + drag-and-drop code. + 2003-11-19 Angus Leeming * lyxtextclass.C (LyXTextClass): fix warning about variable diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index cb54cff3c4..0ebdbcddb3 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -72,6 +72,8 @@ public: boost::signal2 workAreaKeyPress; /// some mouse event boost::signal1 dispatch; + /// used by drag-and-drop + boost::signal1 viewDispatch; /// emitted when an X client has requested our selection boost::signal0 selectionRequested; /// emitted when another X client has stolen our selection diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 97491e7740..43a0bae1d3 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,16 @@ +2003-12-08 Ronald Florence + + * QWorkArea.C (checkAppleEventForMissingParams) + (handleOpenDocuments): add support for OpenDocuments apple event + + * lyx_gui.C (macEventFilter): handle apple events + +2003-12-04 Jean-Marc Lasgouttes + + * QWorkArea.C (QWorkArea): + (dragEnterEvent): + (dropEvent): add support for drag and drop of URIs + 2003-12-05 Juergen Spitzmueller * QDocument.C: use geometry on custom, A3, B3 and B4 diff --git a/src/frontends/qt2/QWorkArea.C b/src/frontends/qt2/QWorkArea.C index ef81e78f25..6d5813ebbd 100644 --- a/src/frontends/qt2/QWorkArea.C +++ b/src/frontends/qt2/QWorkArea.C @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,10 @@ #include #endif +#ifdef Q_OS_MAC +#include +#endif + #include #include @@ -44,6 +49,10 @@ using std::abs; using std::hex; +namespace { +QWorkArea const * wa_ptr = 0; +} + QWorkArea::QWorkArea(int, int, int, int) : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this) { @@ -53,6 +62,7 @@ QWorkArea::QWorkArea(int, int, int, int) (static_cast(qApp->mainWidget()))->setCentralWidget(this); setFocusProxy(content_); + setAcceptDrops(true); content_->show(); @@ -62,6 +72,9 @@ QWorkArea::QWorkArea(int, int, int, int) vl->addWidget(content_, 5); vl->addWidget(scrollbar_, 0); +#ifdef Q_OS_MAC + wa_ptr = this; +#endif show(); } @@ -84,9 +97,6 @@ void QWorkArea::setScrollbarParams(int h, int pos, int line_h) scrollbar_->setPageStep(height()); } -namespace { -QWorkArea const * wa_ptr = 0; -} #ifdef Q_WS_X11 bool lyxX11EventFilter(XEvent * xev) @@ -107,6 +117,72 @@ bool lyxX11EventFilter(XEvent * xev) } #endif +#ifdef Q_OS_MAC +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; + } +} +} + +pascal OSErr 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); + wa_ptr->viewDispatch( + FuncRequest(LFUN_FILE_OPEN, + fromqstr(s_arg))); + break; + } + } + } // for ... + } + AEDisposeDesc(&documentList); + return err; +} +#endif // Q_OS_MAC + void QWorkArea::haveSelection(bool own) const { wa_ptr = this; @@ -144,3 +220,24 @@ void QWorkArea::putClipboard(string const & str) const #endif QApplication::clipboard()->setText(toqstr(str)); } + + +void QWorkArea::dragEnterEvent(QDragEnterEvent * event) +{ + event->accept(QUriDrag::canDecode(event)); +} + + +void QWorkArea::dropEvent(QDropEvent* event) +{ + QStringList files; + + if (QUriDrag::decodeLocalFiles(event, files)) { + lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!" + << endl; + for (QStringList::Iterator i = files.begin(); + i!=files.end(); ++i) + viewDispatch(FuncRequest(LFUN_FILE_OPEN, fromqstr(*i))); +// lyxerr << "got file: " << fromqstr(*i) << endl; + } +} diff --git a/src/frontends/qt2/QWorkArea.h b/src/frontends/qt2/QWorkArea.h index d397a91bc2..3eee85ee0b 100644 --- a/src/frontends/qt2/QWorkArea.h +++ b/src/frontends/qt2/QWorkArea.h @@ -56,6 +56,11 @@ public: /// virtual void putClipboard(string const &) const; + /// + virtual void dragEnterEvent(QDragEnterEvent * event); + /// + virtual void dropEvent(QDropEvent* event); + /// get the pixmap we paint on to QPixmap * getPixmap() const { return content_->pixmap(); } diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index f6e4e6b593..6e1ed75098 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -46,6 +46,10 @@ #include "qfont_loader.h" #include "io_callback.h" +#ifdef Q_OS_MAC +#include +#endif + #include #include #include @@ -87,6 +91,12 @@ extern void initEncodings(); extern bool lyxX11EventFilter(XEvent * xev); #endif +#ifdef Q_OS_MAC +extern bool macEventFilter(EventRef event); +extern pascal OSErr +handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/, + long /*refCon*/); +#endif class LQApplication : public QApplication { @@ -96,18 +106,41 @@ public: #ifdef Q_WS_X11 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); } #endif +#ifdef Q_OS_MAC + bool macEventFilter(EventRef event); +#endif }; - LQApplication::LQApplication(int & argc, char ** argv) : QApplication(argc, argv) -{} +{ +#ifdef Q_OS_MAC + AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, + NewAEEventHandlerUPP(handleOpenDocuments), + 0, false); +#endif +} LQApplication::~LQApplication() {} +#ifdef Q_OS_MAC +bool LQApplication::macEventFilter(EventRef event) +{ + if (GetEventClass(event) == kEventClassAppleEvent) { + EventRecord eventrec; + ConvertEventRefToEventRecord(event, &eventrec); + AEProcessAppleEvent(&eventrec); + + return false; + } + return false; +} +#endif + + void lyx_gui::parse_init(int & argc, char * argv[]) { static LQApplication a(argc, argv); diff --git a/status.13x b/status.13x index 82b3a1bb2a..781cba2ccc 100644 --- a/status.13x +++ b/status.13x @@ -29,6 +29,10 @@ What's new consequence and it is therefore not possible to use LyX 1.3.4 and an earlier version with the same .lyx/ directory. +- add support for drag-n-drop opening of lyx files [Qt only] + +- add support for opening files with LyX in finder [Qt/Mac only] + - add support for \boldsymbol in math editor - update danish, german, italian, romanian and slovenian interface