Clean up wxDropTarget (first stage) by moving Qt specific stuff (e.g. QMimeData) into an Impl.
This commit is contained in:
@@ -16,6 +16,7 @@ class WXDLLIMPEXP_CORE wxDropTarget : public wxDropTargetBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDropTarget(wxDataObject *dataObject = NULL);
|
wxDropTarget(wxDataObject *dataObject = NULL);
|
||||||
|
virtual ~wxDropTarget();
|
||||||
|
|
||||||
virtual bool OnDrop(wxCoord x, wxCoord y) wxOVERRIDE;
|
virtual bool OnDrop(wxCoord x, wxCoord y) wxOVERRIDE;
|
||||||
virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) wxOVERRIDE;
|
virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def) wxOVERRIDE;
|
||||||
@@ -29,10 +30,8 @@ public:
|
|||||||
void OnQtDrop(QEvent* event);
|
void OnQtDrop(QEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PendingMimeDataSetter;
|
class Impl;
|
||||||
friend class PendingMimeDataSetter;
|
Impl* m_pImpl;
|
||||||
|
|
||||||
const QMimeData* m_pendingMimeData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDropSource: public wxDropSourceBase
|
class WXDLLIMPEXP_CORE wxDropSource: public wxDropSourceBase
|
||||||
|
@@ -82,40 +82,54 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class wxDropTarget::PendingMimeDataSetter
|
|
||||||
|
class wxDropTarget::Impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PendingMimeDataSetter(wxDropTarget* dropTarget, const QMimeData* mimeData)
|
const QMimeData* m_pendingMimeData;
|
||||||
: m_dropTarget(dropTarget)
|
|
||||||
{
|
|
||||||
m_dropTarget->m_pendingMimeData = mimeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PendingMimeDataSetter()
|
|
||||||
{
|
|
||||||
m_dropTarget->m_pendingMimeData = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
wxDropTarget* m_dropTarget;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class PendingMimeDataSetter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PendingMimeDataSetter(const QMimeData*& targetMimeData, const QMimeData* mimeData)
|
||||||
|
: m_targetMimeData(targetMimeData)
|
||||||
|
{
|
||||||
|
m_targetMimeData = mimeData;
|
||||||
|
}
|
||||||
|
|
||||||
|
~PendingMimeDataSetter()
|
||||||
|
{
|
||||||
|
m_targetMimeData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QMimeData*& m_targetMimeData;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
wxDropTarget::wxDropTarget(wxDataObject *dataObject)
|
wxDropTarget::wxDropTarget(wxDataObject *dataObject)
|
||||||
: wxDropTargetBase(dataObject),
|
: wxDropTargetBase(dataObject),
|
||||||
m_pendingMimeData(NULL)
|
m_pImpl(new Impl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDropTarget::~wxDropTarget()
|
||||||
|
{
|
||||||
|
delete m_pImpl;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxDropTarget::OnDrop(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
|
bool wxDropTarget::OnDrop(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
|
||||||
{
|
{
|
||||||
return !GetMatchingPair().GetMimeType().empty();
|
return !GetMatchingPair().GetMimeType().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragResult wxDropTarget::OnData(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult default_drag_result)
|
wxDragResult wxDropTarget::OnData(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def)
|
||||||
{
|
{
|
||||||
GetData();
|
GetData();
|
||||||
return default_drag_result;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDropTarget::GetData()
|
bool wxDropTarget::GetData()
|
||||||
@@ -126,17 +140,17 @@ bool wxDropTarget::GetData()
|
|||||||
if ( mimeType.empty() )
|
if ( mimeType.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QByteArray data = m_pendingMimeData->data(wxQtConvertString(mimeType));
|
const QByteArray data = m_pImpl->m_pendingMimeData->data(wxQtConvertString(mimeType));
|
||||||
|
|
||||||
return m_dataObject->SetData(droppedFormat, data.size(), data.data());
|
return m_dataObject->SetData(droppedFormat, data.size(), data.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat wxDropTarget::GetMatchingPair()
|
wxDataFormat wxDropTarget::GetMatchingPair()
|
||||||
{
|
{
|
||||||
if ( m_pendingMimeData == NULL || m_dataObject == NULL )
|
if ( m_pImpl->m_pendingMimeData == NULL || m_dataObject == NULL )
|
||||||
return wxFormatInvalid;
|
return wxFormatInvalid;
|
||||||
|
|
||||||
const QStringList formats = m_pendingMimeData->formats();
|
const QStringList formats = m_pImpl->m_pendingMimeData->formats();
|
||||||
for ( int i = 0; i < formats.count(); ++i )
|
for ( int i = 0; i < formats.count(); ++i )
|
||||||
{
|
{
|
||||||
const wxDataFormat format(wxQtConvertString(formats[i]));
|
const wxDataFormat format(wxQtConvertString(formats[i]));
|
||||||
@@ -156,7 +170,7 @@ void wxDropTarget::OnQtEnter(QEvent* event)
|
|||||||
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
|
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
|
||||||
const QPoint where = e->pos();
|
const QPoint where = e->pos();
|
||||||
|
|
||||||
PendingMimeDataSetter setter(this, e->mimeData());
|
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||||
|
|
||||||
wxDragResult result = OnEnter(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
wxDragResult result = OnEnter(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||||
|
|
||||||
@@ -176,7 +190,7 @@ void wxDropTarget::OnQtMove(QEvent* event)
|
|||||||
QDragMoveEvent *e = static_cast<QDragMoveEvent*>(event);
|
QDragMoveEvent *e = static_cast<QDragMoveEvent*>(event);
|
||||||
const QPoint where = e->pos();
|
const QPoint where = e->pos();
|
||||||
|
|
||||||
PendingMimeDataSetter setter(this, e->mimeData());
|
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||||
|
|
||||||
wxDragResult result = OnDragOver(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
wxDragResult result = OnDragOver(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||||
|
|
||||||
@@ -190,7 +204,7 @@ void wxDropTarget::OnQtDrop(QEvent* event)
|
|||||||
const QDropEvent *e = static_cast<QDropEvent*>(event);
|
const QDropEvent *e = static_cast<QDropEvent*>(event);
|
||||||
const QPoint where = e->pos();
|
const QPoint where = e->pos();
|
||||||
|
|
||||||
PendingMimeDataSetter setter(this, e->mimeData());
|
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||||
|
|
||||||
if ( OnDrop(where.x(), where.y()) )
|
if ( OnDrop(where.x(), where.y()) )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user