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 class WXDLLEXPORT wxDropSourceBase
{ {
public: 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() { } virtual ~wxDropSourceBase() { }
// set the data which is transfered by drag and drop // set the data which is transfered by drag and drop
@@ -55,21 +61,42 @@ public:
wxDataObject *GetDataObject() wxDataObject *GetDataObject()
{ return m_data; } { 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 // start drag action, see enum wxDragResult for return value description
// //
// if bAllowMove is TRUE, data can be moved, if not - only copied // if bAllowMove is TRUE, data can be moved, if not - only copied
virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0; virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0;
// override to give feedback depending on the current operation result // override to give feedback depending on the current operation result
// "effect" // "effect" and return TRUE if you did something, FALSE to let the library
virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), // give the default feedback
bool WXUNUSED(bScrolling) ) virtual bool GiveFeedback(wxDragResult WXUNUSED(effect)) { return FALSE; }
{
return TRUE;
}
protected: 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; 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 // NB: the "wxWindow *win" parameter is unused and is here only for wxGTK
// compatibility, as well as both icon parameters // compatibility, as well as both icon parameters
wxDropSource(wxWindow *win = NULL, wxDropSource(wxWindow *win = NULL,
const wxIcon &go = wxNullIcon, const wxCursor &cursorCopy = wxNullCursor,
const wxIcon &stop = wxNullIcon ); const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor);
wxDropSource(wxDataObject& data, wxDropSource(wxDataObject& data,
wxWindow *win = NULL, wxWindow *win = NULL,
const wxIcon &go = wxNullIcon, const wxCursor &cursorCopy = wxNullCursor,
const wxIcon &stop = wxNullIcon ); const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor);
virtual ~wxDropSource(); virtual ~wxDropSource();
@@ -57,7 +59,7 @@ public:
// overridable: you may give some custom UI feedback during d&d operation // 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 // 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. // too slow). Just return false if you want default feedback.
virtual bool GiveFeedback(wxDragResult effect, bool bScrolling); virtual bool GiveFeedback(wxDragResult effect);
protected: protected:
void Init(); void Init();

View File

@@ -871,7 +871,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{ {
// start drag operation // start drag operation
wxTextDataObject textData(m_strText); 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; const char *pc;
@@ -1253,7 +1256,7 @@ void DnDShapeFrame::OnDrag(wxMouseEvent& event)
// start drag operation // start drag operation
DnDShapeDataObject shapeData(m_shape); DnDShapeDataObject shapeData(m_shape);
wxDropSource source(shapeData, this, wxICON(mondrian)); wxDropSource source(shapeData, this);
const char *pc = NULL; const char *pc = NULL;
switch ( source.DoDragDrop(TRUE) ) switch ( source.DoDragDrop(TRUE) )

View File

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