wxDropSource now has 3 custom cursors for copy/move/nothing

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-24 19:34:11 +00:00
parent f96ac56ad3
commit 2d93e1335c
4 changed files with 76 additions and 31 deletions

View File

@@ -45,7 +45,13 @@ inline WXDLLEXPORT bool wxIsDragResultOk(wxDragResult res)
class WXDLLEXPORT wxDropSourceBase
{
public:
wxDropSourceBase() { m_data = (wxDataObject *)NULL; }
wxDropSourceBase(const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor)
: m_cursorCopy(cursorCopy),
m_cursorMove(cursorMove),
m_cursorStop(cursorStop)
{ m_data = (wxDataObject *)NULL; }
virtual ~wxDropSourceBase() { }
// set the data which is transfered by drag and drop
@@ -55,21 +61,42 @@ public:
wxDataObject *GetDataObject()
{ return m_data; }
// set the icon corresponding to given drag result
void SetCursor(wxDragResult res, const wxCursor& cursor)
{
if ( res == wxDragCopy )
m_cursorCopy = cursor;
else if ( res == wxDragMove )
m_cursorMove = cursor;
else
m_cursorStop = cursor;
}
// start drag action, see enum wxDragResult for return value description
//
// if bAllowMove is TRUE, data can be moved, if not - only copied
virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0;
// override to give feedback depending on the current operation result
// "effect"
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect),
bool WXUNUSED(bScrolling) )
{
return TRUE;
}
// "effect" and return TRUE if you did something, FALSE to let the library
// give the default feedback
virtual bool GiveFeedback(wxDragResult WXUNUSED(effect)) { return FALSE; }
protected:
const wxCursor& GetCursor(wxDragResult res) const
{
if ( res == wxDragCopy )
return m_cursorCopy;
else if ( res == wxDragMove )
return m_cursorMove;
else
return m_cursorStop;
}
wxDataObject *m_data;
// the cursors to use for feedback
wxCursor m_cursorCopy, m_cursorMove, m_cursorStop;
};
// ----------------------------------------------------------------------------

View File

@@ -41,12 +41,14 @@ public:
// NB: the "wxWindow *win" parameter is unused and is here only for wxGTK
// compatibility, as well as both icon parameters
wxDropSource(wxWindow *win = NULL,
const wxIcon &go = wxNullIcon,
const wxIcon &stop = wxNullIcon );
const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor);
wxDropSource(wxDataObject& data,
wxWindow *win = NULL,
const wxIcon &go = wxNullIcon,
const wxIcon &stop = wxNullIcon );
wxWindow *win = NULL,
const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor);
virtual ~wxDropSource();
@@ -57,7 +59,7 @@ public:
// overridable: you may give some custom UI feedback during d&d operation
// in this function (it's called on each mouse move, so it shouldn't be
// too slow). Just return false if you want default feedback.
virtual bool GiveFeedback(wxDragResult effect, bool bScrolling);
virtual bool GiveFeedback(wxDragResult effect);
protected:
void Init();

View File

@@ -871,7 +871,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
// start drag operation
wxTextDataObject textData(m_strText);
wxDropSource source(textData, this, wxICON(mondrian));
wxDropSource source(textData, this,
wxCURSOR_PENCIL, // for copy
wxCURSOR_SPRAYCAN, // for move
wxCURSOR_QUESTION_ARROW); // for nothing
const char *pc;
@@ -1253,7 +1256,7 @@ void DnDShapeFrame::OnDrag(wxMouseEvent& event)
// start drag operation
DnDShapeDataObject shapeData(m_shape);
wxDropSource source(shapeData, this, wxICON(mondrian));
wxDropSource source(shapeData, this);
const char *pc = NULL;
switch ( source.DoDragDrop(TRUE) )

View File

@@ -140,8 +140,7 @@ STDMETHODIMP wxIDropSource::GiveFeedback(DWORD dwEffect)
else
effect = wxDragNone;
if ( m_pDropSource->GiveFeedback(effect,
(dwEffect & DROPEFFECT_SCROLL) != 0 ) )
if ( m_pDropSource->GiveFeedback(effect) )
return S_OK;
return DRAGDROP_S_USEDEFAULTCURSORS;
@@ -156,29 +155,33 @@ STDMETHODIMP wxIDropSource::GiveFeedback(DWORD dwEffect)
// common part of all ctors
void wxDropSource::Init()
{
m_pIDropSource = new wxIDropSource(this);
m_pIDropSource->AddRef();
m_pIDropSource = new wxIDropSource(this);
m_pIDropSource->AddRef();
}
wxDropSource::wxDropSource(wxWindow* WXUNUSED(win),
const wxIcon & WXUNUSED(go),
const wxIcon & WXUNUSED(stop))
const wxCursor &cursorCopy,
const wxCursor &cursorMove,
const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
Init();
Init();
}
wxDropSource::wxDropSource(wxDataObject& data,
wxWindow* WXUNUSED(win),
const wxIcon & WXUNUSED(go),
const wxIcon & WXUNUSED(stop))
const wxCursor &cursorCopy,
const wxCursor &cursorMove,
const wxCursor &cursorStop)
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
{
Init();
SetData(data);
Init();
SetData(data);
}
wxDropSource::~wxDropSource()
{
m_pIDropSource->Release();
m_pIDropSource->Release();
}
// Name : DoDragDrop
@@ -223,7 +226,8 @@ wxDragResult wxDropSource::DoDragDrop(bool bAllowMove)
wxLogError(wxT("Drag & drop operation failed."));
}
else {
wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."), hr);
wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."),
hr);
}
return wxDragError;
@@ -234,11 +238,20 @@ wxDragResult wxDropSource::DoDragDrop(bool bAllowMove)
// Purpose : visually inform the user about d&d operation state
// Returns : bool: true if we do all ourselves or false for default feedback
// Params : [in] DragResult effect - what would happen if we dropped now
// [in] bool bScrolling - true if target is scrolling
// Notes : here we just leave this stuff for default implementation
bool wxDropSource::GiveFeedback(wxDragResult effect, bool bScrolling)
bool wxDropSource::GiveFeedback(wxDragResult effect)
{
return FALSE;
const wxCursor& cursor = GetCursor(effect);
if ( cursor.Ok() )
{
::SetCursor((HCURSOR)cursor.GetHCURSOR());
return TRUE;
}
else
{
return FALSE;
}
}
#endif //USE_DRAG_AND_DROP