Implement initial try of wxDropTarget.

The drop target needs to use an event filter to capture drag-and-drop events from the window.
This commit is contained in:
Jay Nabonne
2019-01-29 16:13:41 +00:00
parent 0dc1654ab6
commit 323cbdabdb
5 changed files with 211 additions and 19 deletions

View File

@@ -31,12 +31,12 @@
#endif // WX_PRECOMP
#include "wx/window.h"
#include "wx/dnd.h"
#include "wx/tooltip.h"
#include "wx/qt/private/utils.h"
#include "wx/qt/private/converter.h"
#include "wx/qt/private/winevent.h"
#define VERT_SCROLLBAR_POSITION 0, 1
#define HORZ_SCROLLBAR_POSITION 1, 0
@@ -193,9 +193,6 @@ static const char WINDOW_POINTER_PROPERTY_NAME[] = "wxWindowPointer";
return const_cast< wxWindowQt * >( ( variant.value< const wxWindow * >() ));
}
static wxWindowQt *s_capturedWindow = NULL;
/* static */ wxWindowQt *wxWindowBase::DoFindFocus()
@@ -225,6 +222,8 @@ void wxWindowQt::Init()
#endif
m_qtWindow = NULL;
m_qtContainer = NULL;
m_dropTarget = NULL;
}
wxWindowQt::wxWindowQt()
@@ -688,9 +687,9 @@ void wxWindowQt::ScrollWindow( int dx, int dy, const wxRect *rect )
#if wxUSE_DRAG_AND_DROP
void wxWindowQt::SetDropTarget( wxDropTarget * WXUNUSED( dropTarget ) )
void wxWindowQt::SetDropTarget( wxDropTarget *dropTarget )
{
wxMISSING_IMPLEMENTATION( __FUNCTION__ );
dnd_event_adapter.SetDropTarget(dropTarget, m_qtWindow);
}
#endif
@@ -1543,3 +1542,60 @@ QPainter *wxWindowQt::QtGetPainter()
{
return m_qtPainter;
}
//##############################################################################
// DnDEventAdapter
//##############################################################################
wxWindow::DnDEventAdapter::DnDEventAdapter() : m_dropTarget(NULL)
{
}
bool wxWindow::DnDEventAdapter::eventFilter(QObject* watched, QEvent* event)
{
if ( m_dropTarget != NULL )
{
switch ( event->type() )
{
case QEvent::Drop:
m_dropTarget->OnQtDrop(event);
return true;
case QEvent::DragEnter:
m_dropTarget->OnQtEnter(event);
return true;
case QEvent::DragMove:
m_dropTarget->OnQtMove(event);
return true;
case QEvent::DragLeave:
m_dropTarget->OnQtLeave(event);
return true;
default:
break;
}
}
return QObject::eventFilter(watched, event);
}
void wxWindow::DnDEventAdapter::SetDropTarget(wxDropTarget* dropTarget, QWidget* window)
{
if ( m_dropTarget == dropTarget )
return;
m_dropTarget = dropTarget;
if ( m_dropTarget == NULL )
{
window->removeEventFilter(this);
window->setAcceptDrops(false);
}
else
{
window->installEventFilter(this);
window->setAcceptDrops(true);
}
}