X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7bf854050fd5c04469d4334524433a31d4ba997a..704a4b7524e05d7bf4d208eb1b30be9989abef4c:/utils/wxPython/src/controls2.i diff --git a/utils/wxPython/src/controls2.i b/utils/wxPython/src/controls2.i index 979130677a..3b4527f54c 100644 --- a/utils/wxPython/src/controls2.i +++ b/utils/wxPython/src/controls2.i @@ -1,5 +1,3 @@ -%module controls2 -%{ ///////////////////////////////////////////////////////////////////////////// // Name: controls2.i // Purpose: More control (widget) classes for wxPython @@ -12,11 +10,12 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +%module controls2 +%{ #include "helpers.h" #include #include -#include %} //---------------------------------------------------------------------- @@ -32,6 +31,8 @@ %import events.i %import controls.i +%pragma(python) code = "import wx" + //---------------------------------------------------------------------- %{ @@ -40,6 +41,53 @@ extern wxValidator wxPyDefaultValidator; //---------------------------------------------------------------------- +enum { + wxLIST_MASK_TEXT, + wxLIST_MASK_IMAGE, + wxLIST_MASK_DATA, + wxLIST_MASK_WIDTH, + wxLIST_MASK_FORMAT, + wxLIST_MASK_STATE, + wxLIST_STATE_DONTCARE, + wxLIST_STATE_DROPHILITED, + wxLIST_STATE_FOCUSED, + wxLIST_STATE_SELECTED, + wxLIST_STATE_CUT, + wxLIST_HITTEST_ABOVE, + wxLIST_HITTEST_BELOW, + wxLIST_HITTEST_NOWHERE, + wxLIST_HITTEST_ONITEMICON, + wxLIST_HITTEST_ONITEMLABEL, + wxLIST_HITTEST_ONITEMRIGHT, + wxLIST_HITTEST_ONITEMSTATEICON, + wxLIST_HITTEST_TOLEFT, + wxLIST_HITTEST_TORIGHT, + wxLIST_HITTEST_ONITEM, + wxLIST_NEXT_ABOVE, + wxLIST_NEXT_ALL, + wxLIST_NEXT_BELOW, + wxLIST_NEXT_LEFT, + wxLIST_NEXT_RIGHT, + wxLIST_ALIGN_DEFAULT, + wxLIST_ALIGN_LEFT, + wxLIST_ALIGN_TOP, + wxLIST_ALIGN_SNAP_TO_GRID, + wxLIST_FORMAT_LEFT, + wxLIST_FORMAT_RIGHT, + wxLIST_FORMAT_CENTRE, + wxLIST_FORMAT_CENTER, + wxLIST_AUTOSIZE, + wxLIST_AUTOSIZE_USEHEADER, + wxLIST_RECT_BOUNDS, + wxLIST_RECT_ICON, + wxLIST_RECT_LABEL, + wxLIST_FIND_UP, + wxLIST_FIND_DOWN, + wxLIST_FIND_LEFT, + wxLIST_FIND_RIGHT, +}; + + class wxListItem { public: long m_mask; // Indicates what fields are valid @@ -83,14 +131,19 @@ public: const wxValidator& validator = wxPyDefaultValidator, char* name = "listCtrl"); + %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" + bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); bool DeleteItem(long item); bool DeleteAllItems(); bool DeleteColumn(int col); bool DeleteAllColumns(void); void ClearAll(void); +#ifdef __WXMSW__ wxTextCtrl* EditLabel(long item); bool EndEditLabel(bool cancel); + wxTextCtrl* GetEditControl(); +#endif bool EnsureVisible(long item); long FindItem(long start, const wxString& str, bool partial = FALSE); %name(FindItemData)long FindItem(long start, long data); @@ -99,13 +152,13 @@ public: bool GetColumn(int col, wxListItem& item); int GetColumnWidth(int col); int GetCountPerPage(); - wxTextCtrl* GetEditControl(); wxImageList* GetImageList(int which); long GetItemData(long item); %addmethods { - %new wxListItem* GetItem() { + %new wxListItem* GetItem(long itemId) { wxListItem* info = new wxListItem; + info->m_itemId = itemId; self->GetItem(*info); return info; } @@ -129,10 +182,13 @@ public: int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE); int GetSelectedItemCount(); +#ifdef __WXMSW__ wxColour GetTextColour(); + void SetTextColour(const wxColour& col); +#endif long GetTopItem(); long HitTest(const wxPoint& point, int& OUTPUT); - %name(InsertColumnWithInfo)long InsertColumn(long col, wxListItem& info); + %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info); long InsertColumn(long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT, int width = -1); @@ -148,16 +204,17 @@ public: bool SetColumn(int col, wxListItem& item); bool SetColumnWidth(int col, int width); void SetImageList(wxImageList* imageList, int which); + bool SetItem(wxListItem& info); - %name(SetItemString)long SetItem(long index, int col, const wxString& label, + %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1); + bool SetItemData(long item, long data); bool SetItemImage(long item, int image, int selImage); bool SetItemPosition(long item, const wxPoint& pos); bool SetItemState(long item, long state, long stateMask); void SetItemText(long item, const wxString& text); void SetSingleStyle(long style, bool add = TRUE); - void SetTextColour(const wxColour& col); void SetWindowStyleFlag(long style); // TODO: bool SortItems(wxListCtrlCompare fn, long data); }; @@ -167,163 +224,232 @@ public: //---------------------------------------------------------------------- -enum { - wxTREE_MASK_HANDLE, - wxTREE_MASK_STATE, - wxTREE_MASK_TEXT, - wxTREE_MASK_IMAGE, - wxTREE_MASK_SELECTED_IMAGE, - wxTREE_MASK_CHILDREN, - wxTREE_MASK_DATA, - - wxTREE_STATE_BOLD, - wxTREE_STATE_DROPHILITED, - wxTREE_STATE_EXPANDED, - wxTREE_STATE_EXPANDEDONCE, - wxTREE_STATE_FOCUSED, - wxTREE_STATE_SELECTED, - wxTREE_STATE_CUT, - - wxTREE_HITTEST_ABOVE, - wxTREE_HITTEST_BELOW, - wxTREE_HITTEST_NOWHERE, - wxTREE_HITTEST_ONITEMBUTTON, - wxTREE_HITTEST_ONITEMICON, - wxTREE_HITTEST_ONITEMINDENT, - wxTREE_HITTEST_ONITEMLABEL, - wxTREE_HITTEST_ONITEMRIGHT, - wxTREE_HITTEST_ONITEMSTATEICON, - wxTREE_HITTEST_TOLEFT, - wxTREE_HITTEST_TORIGHT, - wxTREE_HITTEST_ONITEM, -}; - +class wxTreeItemId { +public: + wxTreeItemId(); + ~wxTreeItemId(); + bool IsOk(); -enum { - wxTREE_NEXT_CARET, - wxTREE_NEXT_CHILD, - wxTREE_NEXT_DROPHILITE, - wxTREE_NEXT_FIRSTVISIBLE, - wxTREE_NEXT_NEXT, - wxTREE_NEXT_NEXTVISIBLE, - wxTREE_NEXT_PARENT, - wxTREE_NEXT_PREVIOUS, - wxTREE_NEXT_PREVIOUSVISIBLE, - wxTREE_NEXT_ROOT }; -enum { - wxTREE_EXPAND_EXPAND, - wxTREE_EXPAND_COLLAPSE, - wxTREE_EXPAND_COLLAPSE_RESET, - wxTREE_EXPAND_TOGGLE -}; -enum { - wxTREE_INSERT_LAST, - wxTREE_INSERT_FIRST, - wxTREE_INSERT_SORT, -}; +%{ +class wxPyTreeItemData : public wxTreeItemData { +public: + wxPyTreeItemData(PyObject* obj = NULL) { + if (obj == NULL) + obj = Py_None; + Py_INCREF(obj); + m_obj = obj; + } + + ~wxPyTreeItemData() { +#ifdef WXP_WITH_THREAD + PyEval_RestoreThread(wxPyEventThreadState); +#endif + Py_DECREF(m_obj); +#ifdef WXP_WITH_THREAD + PyEval_SaveThread(); +#endif + } + PyObject* GetData() { + Py_INCREF(m_obj); + return m_obj; + } + void SetData(PyObject* obj) { + Py_DECREF(m_obj); + m_obj = obj; + Py_INCREF(obj); + } + PyObject* m_obj; +}; +%} -class wxTreeItem { +%name(wxTreeItemData) class wxPyTreeItemData { public: - long m_mask; - long m_itemId; - long m_state; - long m_stateMask; - wxString m_text; - int m_image; - int m_selectedImage; - int m_children; - long m_data; - - wxTreeItem(); - ~wxTreeItem(); + wxPyTreeItemData(PyObject* obj = NULL); + + PyObject* GetData(); + void SetData(PyObject* obj); + + const wxTreeItemId& GetId(); + void SetId(const wxTreeItemId& id); }; -class wxTreeEvent : public wxCommandEvent { +class wxTreeEvent : public wxCommandEvent { public: - int m_code; - wxTreeItem m_item; - long m_oldItem; - wxPoint m_pointDrag; + wxTreeItemId GetItem(); + wxTreeItemId GetOldItem(); + wxPoint GetPoint(); + int GetCode(); + void Veto(); }; +// These are for the GetFirstChild/GetNextChild methods below +%typemap(python, in) long& INOUT = long* INOUT; +%typemap(python, argout) long& INOUT = long* INOUT; class wxTreeCtrl : public wxControl { public: wxTreeCtrl(wxWindow *parent, wxWindowID id = -1, - const wxPoint& pos = wxPyDefaultPosition, - const wxSize& size = wxPyDefaultSize, - long style = wxTR_HAS_BUTTONS, - const wxValidator& validator = wxPyDefaultValidator, - char* name = "wxTreeCtrl"); + const wxPoint& pos = wxPyDefaultPosition, + const wxSize& size = wxPyDefaultSize, + long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT, + const wxValidator& validator = wxPyDefaultValidator, + char* name = "wxTreeCtrl"); - bool DeleteAllItems(); - bool DeleteItem(long item); - wxTextCtrl* EditLabel(long item); - bool EnsureVisible(long item); - bool ExpandItem(long item, int action); - long GetChild(long item); - int GetCount(); - wxTextCtrl* GetEditControl(); - long GetFirstVisibleItem(); - wxImageList* GetImageList(int which = wxIMAGE_LIST_NORMAL); - int GetIndent(); - long GetItemData(long item); + %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" + + size_t GetCount(); + unsigned int GetIndent(); + void SetIndent(unsigned int indent); + wxImageList *GetImageList(); + wxImageList *GetStateImageList(); + void SetImageList(wxImageList *imageList); + void SetStateImageList(wxImageList *imageList); + + wxString GetItemText(const wxTreeItemId& item); + int GetItemImage(const wxTreeItemId& item); + int GetItemSelectedImage(const wxTreeItemId& item); + + void SetItemText(const wxTreeItemId& item, const wxString& text); + void SetItemImage(const wxTreeItemId& item, int image); + void SetItemSelectedImage(const wxTreeItemId& item, int image); + void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); %addmethods { - %new wxTreeItem* GetItem() { - wxTreeItem* info = new wxTreeItem; - self->GetItem(*info); - return info; - } - %new wxRect* GetItemRect(long item, int textOnly = FALSE) { - wxRect* rect = new wxRect; - self->GetItemRect(item, *rect, textOnly); - return rect; + // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData + // if needed. + wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(); + self->SetItemData(item, data); + } + return data; } + + void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { + self->SetItemData(item, data); + } + + // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by + // automatically creating data classes. + PyObject* GetPyData(const wxTreeItemId& item) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(); + self->SetItemData(item, data); + } + return data->GetData(); + } + + void SetPyData(const wxTreeItemId& item, PyObject* obj) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(obj); + self->SetItemData(item, data); + } else + data->SetData(obj); + } } - int GetItemState(long item, long stateMask); - wxString GetItemText(long item); - long GetNextItem(long item, int code); - long GetNextVisibleItem(long item); - long GetParent(long item); - long GetRootItem(); - long GetSelection(); - long HitTest(const wxPoint& point, int& OUTPUT); // *** check this - long InsertItem(long parent, wxTreeItem& info, - long insertAfter = wxTREE_INSERT_LAST); - %name(InsertItemString) - long InsertItem(long parent, const wxString& label, - int image = -1, int selImage = -1, - long insertAfter = wxTREE_INSERT_LAST); - bool ItemHasChildren(long item); - bool ScrollTo(long item); - bool SelectItem(long item); - void SetIndent(int indent); - void SetImageList(wxImageList* imageList, int which = wxIMAGE_LIST_NORMAL); - bool SetItem(wxTreeItem& info); - bool SetItemImage(long item, int image, int selImage); - bool SetItemState(long item, long state, long stateMask); - void SetItemText(long item, const wxString& text); - bool SetItemData(long item, long data); - bool SortChildren(long item); + + bool IsVisible(const wxTreeItemId& item); + bool ItemHasChildren(const wxTreeItemId& item); + bool IsExpanded(const wxTreeItemId& item); + bool IsSelected(const wxTreeItemId& item); + + wxTreeItemId GetRootItem(); + wxTreeItemId GetSelection(); + wxTreeItemId GetParent(const wxTreeItemId& item); + + size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); + + wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); + wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); + wxTreeItemId GetNextSibling(const wxTreeItemId& item); + wxTreeItemId GetPrevSibling(const wxTreeItemId& item); + wxTreeItemId GetFirstVisibleItem(); + wxTreeItemId GetNextVisible(const wxTreeItemId& item); + wxTreeItemId GetPrevVisible(const wxTreeItemId& item); + + + wxTreeItemId AddRoot(const wxString& text, + int image = -1, int selectedImage = -1, + wxPyTreeItemData *data = NULL); + wxTreeItemId PrependItem(const wxTreeItemId& parent, + const wxString& text, + int image = -1, int selectedImage = -1, + wxPyTreeItemData *data = NULL); + wxTreeItemId InsertItem(const wxTreeItemId& parent, + const wxTreeItemId& idPrevious, + const wxString& text, + int image = -1, int selectedImage = -1, + wxPyTreeItemData *data = NULL); + wxTreeItemId AppendItem(const wxTreeItemId& parent, + const wxString& text, + int image = -1, int selectedImage = -1, + wxPyTreeItemData *data = NULL); + + void Delete(const wxTreeItemId& item); + void DeleteChildren(const wxTreeItemId& item); + void DeleteAllItems(); + + void Expand(const wxTreeItemId& item); + void Collapse(const wxTreeItemId& item); + void CollapseAndReset(const wxTreeItemId& item); + void Toggle(const wxTreeItemId& item); + + void Unselect(); + void SelectItem(const wxTreeItemId& item); + void EnsureVisible(const wxTreeItemId& item); + void ScrollTo(const wxTreeItemId& item); + + wxTextCtrl* EditLabel(const wxTreeItemId& item); + // **** figure out how to do this + // wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); + wxTextCtrl* GetEditControl(); + void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE); + +// void SortChildren(const wxTreeItemId& item); + // **** And this too + // wxTreeItemCmpFunc *cmpFunction = NULL); + + void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); + bool IsBold(const wxTreeItemId& item) const; + wxTreeItemId HitTest(const wxPoint& point); + +%pragma(python) addtoclass = " + # Redefine a couple methods that SWIG gets a bit confused on... + def GetFirstChild(self,arg0,arg1): + val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1) + val1 = wxTreeItemIdPtr(val1) + val1.thisown = 1 + return (val1,val2) + def GetNextChild(self,arg0,arg1): + val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1) + val1 = wxTreeItemIdPtr(val1) + val1.thisown = 1 + return (val1,val2) +" }; + //---------------------------------------------------------------------- +#ifdef SKIPTHIS +#ifdef __WXMSW__ class wxTabEvent : public wxCommandEvent { public: }; @@ -338,6 +464,8 @@ public: long style = 0, char* name = "tabCtrl"); + %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" + bool DeleteAllItems(); bool DeleteItem(int item); wxImageList* GetImageList(); @@ -369,13 +497,9 @@ public: }; +#endif +#endif + //---------------------------------------------------------------------- -///////////////////////////////////////////////////////////////////////////// -// -// $Log$ -// Revision 1.1 1998/08/09 08:25:49 RD -// Initial version -// -//