basic dnd support for qt; OpenDocuments support for qt/mac

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@8218 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2003-12-09 14:15:22 +00:00
parent 54e25d6844
commit 787b7fc67d
9 changed files with 177 additions and 5 deletions

View File

@ -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:"

View File

@ -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;

View File

@ -1,3 +1,8 @@
2003-12-04 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* BufferView_pimpl.C (viewDispatch): new method, called by the qt
drag-and-drop code.
2003-11-19 Angus Leeming <leeming@lyx.org>
* lyxtextclass.C (LyXTextClass): fix warning about variable

View File

@ -72,6 +72,8 @@ public:
boost::signal2<void, LyXKeySymPtr, key_modifier::state> workAreaKeyPress;
/// some mouse event
boost::signal1<void, FuncRequest> dispatch;
/// used by drag-and-drop
boost::signal1<bool, FuncRequest> viewDispatch;
/// emitted when an X client has requested our selection
boost::signal0<void> selectionRequested;
/// emitted when another X client has stolen our selection

View File

@ -1,3 +1,16 @@
2003-12-08 Ronald Florence <ron@18james.com>
* QWorkArea.C (checkAppleEventForMissingParams)
(handleOpenDocuments): add support for OpenDocuments apple event
* lyx_gui.C (macEventFilter): handle apple events
2003-12-04 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* QWorkArea.C (QWorkArea):
(dragEnterEvent):
(dropEvent): add support for drag and drop of URIs
2003-12-05 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* QDocument.C: use geometry on custom, A3, B3 and B4

View File

@ -27,6 +27,7 @@
#include <qapplication.h>
#include <qevent.h>
#include <qdragobject.h>
#include <qpainter.h>
#include <qmainwindow.h>
#include <qlayout.h>
@ -36,6 +37,10 @@
#include <X11/Xlib.h>
#endif
#ifdef Q_OS_MAC
#include <Carbon/Carbon.h>
#endif
#include <cmath>
#include <cctype>
@ -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<QMainWindow*>(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;
}
}

View File

@ -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(); }

View File

@ -46,6 +46,10 @@
#include "qfont_loader.h"
#include "io_callback.h"
#ifdef Q_OS_MAC
#include <Carbon/Carbon.h>
#endif
#include <qapplication.h>
#include <qwidget.h>
#include <qpaintdevicemetrics.h>
@ -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);

View File

@ -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