X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd9f7fea29e3f8bb61861f52984b7943512346ac..b0d45269cc5046402752449098731b8ee189d78d:/wxPython/src/_treectrl.i diff --git a/wxPython/src/_treectrl.i b/wxPython/src/_treectrl.i index 52112b1a91..841df1aa77 100644 --- a/wxPython/src/_treectrl.i +++ b/wxPython/src/_treectrl.i @@ -18,10 +18,9 @@ %{ #include #include "wx/wxPython/pytree.h" - - const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl"); - DECLARE_DEF_STRING(_TreeCtrlNameStr); %} + +MAKE_CONST_WXSTRING2(TreeCtrlNameStr, _T("wxTreeCtrl")); //--------------------------------------------------------------------------- %newgroup @@ -83,7 +82,6 @@ enum { //--------------------------------------------------------------------------- %newgroup -typedef void *wxTreeItemIdValue; // wxTreeItemId identifies an element of the tree. In this implementation, it's // just a trivial wrapper around Win32 HTREEITEM or a pointer to some private @@ -98,18 +96,11 @@ public: bool IsOk() const; %extend { - bool operator==(const wxTreeItemId* other) { - if (!other) return False; - return *self == *other; - } - - bool operator!=(const wxTreeItemId* other) { - if (!other) return True; - return *self != *other; - } + bool __eq__(const wxTreeItemId* other) { return other ? (*self == *other) : false; } + bool __ne__(const wxTreeItemId* other) { return other ? (*self != *other) : true; } } - wxTreeItemIdValue m_pItem; + void* m_pItem; %pythoncode { @@ -126,16 +117,19 @@ public: // Python code should rarely be neccessary. Just use the GetItemPyData and // SetItemPyData tree methods instead of the GetItemData and SetItemData // methods. -%name(TreeItemData) class wxPyTreeItemData { +%rename(TreeItemData) wxPyTreeItemData; +class wxPyTreeItemData { public: wxPyTreeItemData(PyObject* obj = NULL); - + ~wxPyTreeItemData(); + PyObject* GetData(); void SetData(PyObject* obj); const wxTreeItemId& GetId(); void SetId(const wxTreeItemId& id); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; @@ -152,7 +146,8 @@ public: wxTreeItemAttr(const wxColour& colText = wxNullColour, const wxColour& colBack = wxNullColour, const wxFont& font = wxNullFont); - + ~wxTreeItemAttr(); + // setters void SetTextColour(const wxColour& colText); void SetBackgroundColour(const wxColour& colBack); @@ -167,6 +162,7 @@ public: wxColour GetBackgroundColour(); wxFont GetFont(); + %pythonAppend Destroy "args[0].thisown = 0" %extend { void Destroy() { delete self; } } }; @@ -196,11 +192,10 @@ public: %constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK; %constant wxEventType wxEVT_COMMAND_TREE_END_DRAG; %constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK; - - +%constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP; +%constant wxEventType wxEVT_COMMAND_TREE_ITEM_MENU; %pythoncode { - EVT_TREE_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG , 1) EVT_TREE_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG , 1) EVT_TREE_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1) @@ -220,7 +215,8 @@ EVT_TREE_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLIC EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1) EVT_TREE_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG , 1) EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1) - +EVT_TREE_ITEM_GETTOOLTIP = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, 1) +EVT_TREE_ITEM_MENU = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MENU, 1) } @@ -261,6 +257,9 @@ public: bool IsEditCancelled() const; void SetEditCanceled(bool editCancelled); + // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events) + void SetToolTip(const wxString& toolTip); + wxString GetToolTip(); }; //--------------------------------------------------------------------------- @@ -268,7 +267,7 @@ public: %{ // C++ version of Python aware wxTreeCtrl class wxPyTreeCtrl : public wxTreeCtrl { - DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl); + DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl) public: wxPyTreeCtrl() : wxTreeCtrl() {} wxPyTreeCtrl(wxWindow *parent, wxWindowID id, @@ -293,15 +292,15 @@ public: const wxTreeItemId& item2) { int rval = 0; bool found; - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) { - PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), False); - PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), False); + PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), false); + PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), false); rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2)); Py_DECREF(o1); Py_DECREF(o2); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); if (! found) rval = wxTreeCtrl::OnCompareItems(item1, item2); return rval; @@ -316,25 +315,32 @@ IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl); -%name(TreeCtrl)class wxPyTreeCtrl : public wxControl { +MustHaveApp(wxPyTreeCtrl); + +%rename(TreeCtrl) wxPyTreeCtrl; +class wxPyTreeCtrl : public wxControl { public: - %addtofunc wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)" - %addtofunc wxPyTreeCtrl() "" + %pythonAppend wxPyTreeCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeCtrl)" + %pythonAppend wxPyTreeCtrl() "" + %typemap(out) wxPyTreeCtrl*; // turn off this typemap wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_DEFAULT_STYLE, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxPy_TreeCtrlNameStr); - %name(PreTreeCtrl)wxPyTreeCtrl(); + const wxString& name = wxPyTreeCtrlNameStr); + %RenameCtor(PreTreeCtrl, wxPyTreeCtrl()); + + // Turn it back on again + %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); } bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_DEFAULT_STYLE, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxPy_TreeCtrlNameStr); + const wxString& name = wxPyTreeCtrlNameStr); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -370,10 +376,10 @@ public: void SetImageList(wxImageList *imageList); void SetStateImageList(wxImageList *imageList); - %addtofunc AssignImageList "args[1].thisown = 0"; - %addtofunc AssignStateImageList "args[1].thisown = 0"; + %disownarg( wxImageList *imageList ); void AssignImageList(wxImageList *imageList); void AssignStateImageList(wxImageList *imageList); + %cleardisown( wxImageList *imageList ); // retrieve items label @@ -428,10 +434,12 @@ public: %extend { // associate a wxPyTreeItemData with the tree item + %disownarg( wxPyTreeItemData* data ); void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { data->SetId(item); // set the id self->SetItemData(item, data); } + %cleardisown( wxPyTreeItemData* data ); // associate a Python object with the tree item void SetItemPyData(const wxTreeItemId& item, PyObject* obj) { @@ -451,15 +459,13 @@ public: // allow the user to expand the items which don't have any children now // - but instead add them only when needed, thus minimizing memory // usage and loading time. - void SetItemHasChildren(const wxTreeItemId& item, bool has = True); + void SetItemHasChildren(const wxTreeItemId& item, bool has = true); // the item will be shown in bold - void SetItemBold(const wxTreeItemId& item, bool bold = True); + void SetItemBold(const wxTreeItemId& item, bool bold = true); -#ifdef __WXMSW__ // the item will be shown with a drop highlight - void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = True); -#endif + void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true); // set the items text colour void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); @@ -490,7 +496,7 @@ public: // if 'recursively' is False, only immediate children count, otherwise // the returned number is the number of all items in this branch size_t GetChildrenCount(const wxTreeItemId& item, - bool recursively = True) /*const*/; + bool recursively = true) /*const*/; @@ -508,17 +514,18 @@ public: // NB: this operation is expensive and can take a long time for a // control with a lot of items (~ O(number of items)). PyObject* GetSelections() { - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* rval = PyList_New(0); wxArrayTreeItemIds array; size_t num, x; num = self->GetSelections(array); for (x=0; x < num; x++) { wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); - PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True); + PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), true); PyList_Append(rval, item); + Py_DECREF(item); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); return rval; } } @@ -528,18 +535,20 @@ public: wxTreeItemId GetItemParent(const wxTreeItemId& item) const; + // NOTE: These are a copy of the same methods in gizmos.i, be sure to + // update both at the same time. (Or find a good way to refactor!) %extend { // Get the first child of this item. Returns a wxTreeItemId and an // opaque "cookie" value that should be passed to GetNextChild in // order to continue the search. PyObject* GetFirstChild(const wxTreeItemId& item) { - wxTreeItemIdValue cookie = 0; - wxTreeItemId ritem = self->GetFirstChild(item, cookie); - wxPyBeginBlockThreads(); + void* cookie = 0; + wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie)); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); - PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True)); - PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True)); - wxPyEndBlockThreads(); + PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); + PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); + wxPyEndBlockThreads(blocked); return tup; } @@ -548,13 +557,13 @@ public: // value returned from GetFirstChild or the previous GetNextChild. // Returns a wxTreeItemId and an opaque "cookie" value that should be // passed to GetNextChild in order to continue the search. - PyObject* GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) { - wxTreeItemId ritem = self->GetNextChild(item, cookie); - wxPyBeginBlockThreads(); + PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) { + wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie)); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); - PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), True)); - PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(cookie, wxT("wxTreeItemIdValue"), True)); - wxPyEndBlockThreads(); + PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true)); + PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void"))); + wxPyEndBlockThreads(blocked); return tup; } } @@ -579,6 +588,7 @@ public: wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; + %disownarg( wxPyTreeItemData* data ); // add the root node to the tree wxTreeItemId AddRoot(const wxString& text, @@ -599,12 +609,12 @@ public: wxPyTreeItemData *data = NULL); // insert a new item before the one with the given index - %name(InsertItemBefore) - wxTreeItemId InsertItem(const wxTreeItemId& parent, + %Rename(InsertItemBefore, + wxTreeItemId, InsertItem(const wxTreeItemId& parent, size_t index, const wxString& text, int image = -1, int selectedImage = -1, - wxPyTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL)); // insert a new item in as the last child of the parent wxTreeItemId AppendItem(const wxTreeItemId& parent, @@ -613,7 +623,8 @@ public: wxPyTreeItemData *data = NULL); - + %cleardisown( wxPyTreeItemData* data ); + // delete this item and associated data if any void Delete(const wxTreeItemId& item); @@ -642,12 +653,19 @@ public: // remove the selection from currently selected item (if any) void Unselect(); + // remove the selection from the given one (multiselect mode only) + void UnselectItem(const wxTreeItemId& item); + // unselect all items (only makes sense for multiple selection control) void UnselectAll(); // select this item - void SelectItem(const wxTreeItemId& item); + void SelectItem(const wxTreeItemId& item, bool select = true); + + // toggle the item selection + void ToggleItemSelection(const wxTreeItemId& item); + // make sure this item is visible (expanding the parent item and/or // scrolling to this item if necessary) void EnsureVisible(const wxTreeItemId& item); @@ -669,7 +687,7 @@ public: #ifdef __WXMSW__ // end editing and accept or discard the changes to item label - void EndEditLabel(const wxTreeItemId& item, bool discardChanges = False); + void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false); #endif @@ -682,23 +700,24 @@ public: - // determine to which item (if any) belongs the given point (the - // coordinates specified are relative to the client area of tree ctrl) - // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx - // constants. - // - wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT); + DocDeclAStr( + wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT), + "HitTest(Point point) -> (item, where)", + "Determine which item (if any) belongs the given point. The coordinates +specified are relative to the client area of tree ctrl and the where return +value is set to a bitmask of wxTREE_HITTEST_xxx constants. +", ""); %extend { // get the bounding rectangle of the item (or of its label only) - PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = False) { + PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = false) { wxRect rect; if (self->GetBoundingRect(item, rect, textOnly)) { - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxRect* r = new wxRect(rect); - PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), True); - wxPyEndBlockThreads(); + PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), true); + wxPyEndBlockThreads(blocked); return val; } else @@ -706,7 +725,14 @@ public: } } +#ifdef __WXMSW__ + // set/get the item state.image (state == -1 means cycle to the next one) + void SetState(const wxTreeItemId& node, int state); + int GetState(const wxTreeItemId& node); +#endif + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); };