X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd9f7fea29e3f8bb61861f52984b7943512346ac..38b2e0de1806b8c5e723cdd04d20ce2b911ed5c4:/wxPython/src/_dnd.i?ds=inline diff --git a/wxPython/src/_dnd.i b/wxPython/src/_dnd.i index 4c99368754..01a908c031 100644 --- a/wxPython/src/_dnd.i +++ b/wxPython/src/_dnd.i @@ -14,12 +14,8 @@ //--------------------------------------------------------------------------- +#ifndef __WXX11__ -%{ -#include -%} - -//--------------------------------------------------------------------------- %newgroup // flags for wxDropSource::DoDragDrop() @@ -55,64 +51,59 @@ bool wxIsDragResultOk(wxDragResult res); %{ -class wxPyDropSource : public wxDropSource { -public: -#ifndef __WXGTK__ - wxPyDropSource(wxWindow *win = NULL, - const wxCursor © = wxNullCursor, - const wxCursor &move = wxNullCursor, - const wxCursor &none = wxNullCursor) - : wxDropSource(win, copy, move, none) {} -#else - wxPyDropSource(wxWindow *win = NULL, - const wxIcon& copy = wxNullIcon, - const wxIcon& move = wxNullIcon, - const wxIcon& none = wxNullIcon) - : wxDropSource(win, copy, move, none) {} -#endif - ~wxPyDropSource() { } - - DEC_PYCALLBACK_BOOL_DR(GiveFeedback); - PYPRIVATE; -}; - IMP_PYCALLBACK_BOOL_DR(wxPyDropSource, wxDropSource, GiveFeedback); - %} -%name(DropSource) class wxPyDropSource { +%rename(DropSource) wxPyDropSource; +class wxPyDropSource { public: + %pythonAppend wxPyDropSource "self._setCallbackInfo(self, DropSource, 0)" #ifndef __WXGTK__ - wxPyDropSource(wxWindow *win = NULL, + wxPyDropSource(wxWindow *win, const wxCursor © = wxNullCursor, const wxCursor &move = wxNullCursor, const wxCursor &none = wxNullCursor); #else - wxPyDropSource(wxWindow *win = NULL, + wxPyDropSource(wxWindow *win, const wxIcon& copy = wxNullIcon, const wxIcon& move = wxNullIcon, const wxIcon& none = wxNullIcon); #endif void _setCallbackInfo(PyObject* self, PyObject* _class, int incref); - %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxDropSource, 0)" ~wxPyDropSource(); // set the data which is transfered by drag and drop void SetData(wxDataObject& data); - + wxDataObject *GetDataObject(); - + // set the icon corresponding to given drag result void SetCursor(wxDragResult res, const wxCursor& cursor); wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); - bool base_GiveFeedback(wxDragResult effect); + bool GiveFeedback(wxDragResult effect); + %MAKE_BASE_FUNC(DropSource, GiveFeedback); }; +%pythoncode { +def DROP_ICON(filename): + """ + Returns either a `wx.Cursor` or `wx.Icon` created from the image file + ``filename``. This function is useful with the `wx.DropSource` class + which, depending on platform accepts either a icon or a cursor. + """ + img = wx.Image(filename) + if wx.Platform == '__WXGTK__': + return wx.IconFromBitmap(wx.BitmapFromImage(img)) + else: + return wx.CursorFromImage(img) +} + + //--------------------------------------------------------------------------- // wxDropTarget should be associated with a window if it wants to be able to @@ -133,50 +124,22 @@ public: %{ -class wxPyDropTarget : public wxDropTarget { -public: - wxPyDropTarget(wxDataObject *dataObject = NULL) - : wxDropTarget(dataObject) {} - - // called when mouse leaves the window: might be used to remove the - // feedback which was given in OnEnter() - DEC_PYCALLBACK__(OnLeave); - - // called when the mouse enters the window (only once until OnLeave()) - DEC_PYCALLBACK_DR_2WXCDR(OnEnter); - - // called when the mouse moves in the window - shouldn't take long to - // execute or otherwise mouse movement would be too slow - DEC_PYCALLBACK_DR_2WXCDR(OnDragOver); - - // called after OnDrop() returns True: you will usually just call - // GetData() from here and, probably, also refresh something to update the - // new data and, finally, return the code indicating how did the operation - // complete (returning default value in case of success and wxDragError on - // failure is usually ok) - DEC_PYCALLBACK_DR_2WXCDR_pure(OnData); - - // this function is called when data is dropped at position (x, y) - if it - // returns True, OnData() will be called immediately afterwards which will - // allow to retrieve the data dropped. - DEC_PYCALLBACK_BOOL_INTINT(OnDrop); - - PYPRIVATE; -}; - IMP_PYCALLBACK__(wxPyDropTarget, wxDropTarget, OnLeave); IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnEnter); IMP_PYCALLBACK_DR_2WXCDR(wxPyDropTarget, wxDropTarget, OnDragOver); IMP_PYCALLBACK_DR_2WXCDR_pure(wxPyDropTarget, wxDropTarget, OnData); IMP_PYCALLBACK_BOOL_INTINT(wxPyDropTarget, wxDropTarget, OnDrop); - %} -%name(DropTarget) class wxPyDropTarget // : public wxDropTarget +%rename(DropTarget) wxPyDropTarget; +class wxPyDropTarget // : public wxDropTarget { public: - %addtofunc wxPyDropTarget "if args: args[1].thisown = 0; self._setCallbackInfo(self, DropTarget)" + %pythonAppend wxPyDropTarget + "self._setCallbackInfo(self, DropTarget)" + + %disownarg( wxDataObject *dataObject ); wxPyDropTarget(wxDataObject *dataObject = NULL); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -185,18 +148,34 @@ public: // get/set the associated wxDataObject wxDataObject *GetDataObject(); - %addtofunc SetDataObject "args[1].thisown = 0" void SetDataObject(wxDataObject *dataObject); - wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); - wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); - void base_OnLeave(); - bool base_OnDrop(wxCoord x, wxCoord y); + %cleardisown( wxDataObject *dataObject ); + + wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); + wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); + void OnLeave(); + bool OnDrop(wxCoord x, wxCoord y); + + %MAKE_BASE_FUNC(DropTarget, OnEnter); + %MAKE_BASE_FUNC(DropTarget, OnDragOver); + %MAKE_BASE_FUNC(DropTarget, OnLeave); + %MAKE_BASE_FUNC(DropTarget, OnDrop); + // may be called *only* from inside OnData() and will fill m_dataObject // with the data from the drop source if it returns True bool GetData(); + // sets the default action for drag and drop: + // use wxDragMove or wxDragCopy to set deafult action to move or copy + // and use wxDragNone (default) to set default action specified by + // initialization of draging (see wxDropSourceBase::DoDragDrop()) + void SetDefaultAction(wxDragResult action); + + // returns default action for drag and drop or + // wxDragNone if this not specified + wxDragResult GetDefaultAction(); }; @@ -233,19 +212,27 @@ IMP_PYCALLBACK_BOOL_INTINT(wxPyTextDropTarget, wxTextDropTarget, OnDrop); %} -%name(TextDropTarget) class wxPyTextDropTarget : public wxPyDropTarget { +%rename(TextDropTarget) wxPyTextDropTarget; +class wxPyTextDropTarget : public wxPyDropTarget { public: - %addtofunc wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" + %pythonAppend wxPyTextDropTarget "self._setCallbackInfo(self, TextDropTarget)" wxPyTextDropTarget(); void _setCallbackInfo(PyObject* self, PyObject* _class); - //bool OnDropText(wxCoord x, wxCoord y, const wxString& text) = 0; - wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); - wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); - void base_OnLeave(); - bool base_OnDrop(wxCoord x, wxCoord y); - wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); + bool OnDropText(wxCoord x, wxCoord y, const wxString& text); + wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); + wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); + void OnLeave(); + bool OnDrop(wxCoord x, wxCoord y); + wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); + + %MAKE_BASE_FUNC(TextDropTarget, OnDropText); + %MAKE_BASE_FUNC(TextDropTarget, OnEnter); + %MAKE_BASE_FUNC(TextDropTarget, OnDragOver); + %MAKE_BASE_FUNC(TextDropTarget, OnLeave); + %MAKE_BASE_FUNC(TextDropTarget, OnDrop); + %MAKE_BASE_FUNC(TextDropTarget, OnData); }; //--------------------------------------------------------------------------- @@ -271,14 +258,14 @@ public: bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) { - bool rval = False; - wxPyBeginBlockThreads(); + bool rval = false; + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "OnDropFiles")) { PyObject* list = wxArrayString2PyList_helper(filenames); rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",x,y,list)); Py_DECREF(list); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); return rval; } @@ -293,20 +280,28 @@ IMP_PYCALLBACK_BOOL_INTINT(wxPyFileDropTarget, wxFileDropTarget, OnDrop); %} -%name(FileDropTarget) class wxPyFileDropTarget : public wxPyDropTarget +%rename(FileDropTarget) wxPyFileDropTarget; +class wxPyFileDropTarget : public wxPyDropTarget { public: - %addtofunc wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" + %pythonAppend wxPyFileDropTarget "self._setCallbackInfo(self, FileDropTarget)" wxPyFileDropTarget(); void _setCallbackInfo(PyObject* self, PyObject* _class); -// bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) = 0; - wxDragResult base_OnEnter(wxCoord x, wxCoord y, wxDragResult def); - wxDragResult base_OnDragOver(wxCoord x, wxCoord y, wxDragResult def); - void base_OnLeave(); - bool base_OnDrop(wxCoord x, wxCoord y); - wxDragResult base_OnData(wxCoord x, wxCoord y, wxDragResult def); + bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); + wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); + wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); + void OnLeave(); + bool OnDrop(wxCoord x, wxCoord y); + wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); + + %MAKE_BASE_FUNC(FileDropTarget, OnDropFiles); + %MAKE_BASE_FUNC(FileDropTarget, OnEnter); + %MAKE_BASE_FUNC(FileDropTarget, OnDragOver); + %MAKE_BASE_FUNC(FileDropTarget, OnLeave); + %MAKE_BASE_FUNC(FileDropTarget, OnDrop); + %MAKE_BASE_FUNC(FileDropTarget, OnData); }; @@ -318,3 +313,5 @@ public: wxPyPtrTypeMap_Add("wxFileDropTarget", "wxPyFileDropTarget"); %} //--------------------------------------------------------------------------- + +#endif