X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/630d84f26f30e2cac046baa864f93596e51368b2..227c63bac98c6f40f17f1ee188f22e7ac11f563d:/utils/wxPython/src/controls2.i diff --git a/utils/wxPython/src/controls2.i b/utils/wxPython/src/controls2.i index 7a21fbe916..6d5697b931 100644 --- a/utils/wxPython/src/controls2.i +++ b/utils/wxPython/src/controls2.i @@ -14,11 +14,11 @@ %{ #include "helpers.h" +#ifdef __WXMSW__ +#include +#endif #include #include -#if 0 -#include -#endif %} //---------------------------------------------------------------------- @@ -34,7 +34,7 @@ %import events.i %import controls.i -%pragma(python) code = "import wxp" +%pragma(python) code = "import wx" //---------------------------------------------------------------------- @@ -44,6 +44,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 @@ -80,32 +127,27 @@ public: class wxListCtrl : public wxControl { public: -#ifdef __WXMSW__ wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxPyDefaultPosition, const wxSize& size = wxPyDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxPyDefaultValidator, char* name = "listCtrl"); -#else - wxListCtrl(wxWindow* parent, wxWindowID id, - const wxPoint& pos = wxPyDefaultPosition, - const wxSize& size = wxPyDefaultSize, - long style = wxLC_ICON, - char* name = "listctrl"); -#endif - %pragma(python) addtomethod = "__init__:wxp._StdWindowCallbacks(self)" + %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); bool DeleteItem(long item); bool DeleteAllItems(); bool DeleteColumn(int col); -#ifdef __WXMSW__ bool DeleteAllColumns(void); void ClearAll(void); +#ifdef __WXMSW__ wxTextCtrl* EditLabel(long item); bool EndEditLabel(bool cancel); + wxTextCtrl* GetEditControl(); +#else + void EditLabel(long item); #endif bool EnsureVisible(long item); long FindItem(long start, const wxString& str, bool partial = FALSE); @@ -115,15 +157,15 @@ public: bool GetColumn(int col, wxListItem& item); int GetColumnWidth(int col); int GetCountPerPage(); -#ifdef __WXMSW__ - wxTextCtrl* GetEditControl(); -#endif wxImageList* GetImageList(int which); long GetItemData(long item); %addmethods { - %new wxListItem* GetItem() { + %new wxListItem* GetItem(long itemId, int col=0) { wxListItem* info = new wxListItem; + info->m_itemId = itemId; + info->m_col = col; + info->m_mask = 0xFFFF; self->GetItem(*info); return info; } @@ -149,10 +191,11 @@ public: 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); @@ -168,18 +211,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); -#ifdef __WXMSW__ - void SetTextColour(const wxColour& col); -#endif void SetWindowStyleFlag(long style); // TODO: bool SortItems(wxListCtrlCompare fn, long data); }; @@ -188,42 +230,79 @@ public: //---------------------------------------------------------------------- +enum wxTreeItemIcon +{ + wxTreeItemIcon_Normal, // not selected, not expanded + wxTreeItemIcon_Selected, // selected, not expanded + wxTreeItemIcon_Expanded, // not selected, expanded + wxTreeItemIcon_SelectedExpanded, // selected, expanded + wxTreeItemIcon_Max +}; + -#ifdef __WXMSW__ class wxTreeItemId { public: wxTreeItemId(); ~wxTreeItemId(); - bool IsOk() const { return m_itemId != 0; } + bool IsOk(); - %addmethods { - long GetId() { return (long)(*self); } +}; + + + +%{ +class wxPyTreeItemData : public wxTreeItemData { +public: + wxPyTreeItemData(PyObject* obj = NULL) { + if (obj == NULL) + obj = Py_None; + Py_INCREF(obj); + m_obj = obj; } + + ~wxPyTreeItemData() { + bool doSave = wxPyRestoreThread(); + Py_DECREF(m_obj); + wxPySaveThread(doSave); + } + + 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; }; +%} -// **** This isn't very useful yet. This needs to be specialized to enable -// derived Python classes... -class wxTreeItemData { +%name(wxTreeItemData) class wxPyTreeItemData { public: - wxTreeItemData(); - ~wxTreeItemData(); + wxPyTreeItemData(PyObject* obj = NULL); + + PyObject* GetData(); + void SetData(PyObject* obj); const wxTreeItemId& GetId(); - void SetId(const wxTreeItemId& id); + void SetId(const wxTreeItemId& id); }; - -class wxTreeEvent : public wxCommandEvent { +class wxTreeEvent : public wxNotifyEvent { public: wxTreeItemId GetItem(); wxTreeItemId GetOldItem(); wxPoint GetPoint(); int GetCode(); - void Veto(); + const wxString& GetLabel(); }; @@ -241,25 +320,67 @@ public: const wxValidator& validator = wxPyDefaultValidator, char* name = "wxTreeCtrl"); - %pragma(python) addtomethod = "__init__:wxp._StdWindowCallbacks(self)" + %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 SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/); void SetStateImageList(wxImageList *imageList); + unsigned int GetSpacing(); + void SetSpacing(unsigned int spacing); + wxString GetItemText(const wxTreeItemId& item); - int GetItemImage(const wxTreeItemId& item); + int GetItemImage(const wxTreeItemId& item, + wxTreeItemIcon which = wxTreeItemIcon_Normal); int GetItemSelectedImage(const wxTreeItemId& item); - wxTreeItemData *GetItemData(const wxTreeItemId& item); void SetItemText(const wxTreeItemId& item, const wxString& text); - void SetItemImage(const wxTreeItemId& item, int image); + void SetItemImage(const wxTreeItemId& item, int image, + wxTreeItemIcon which = wxTreeItemIcon_Normal); void SetItemSelectedImage(const wxTreeItemId& item, int image); - void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); + void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); + + %addmethods { + // [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); + } + } + bool IsVisible(const wxTreeItemId& item); bool ItemHasChildren(const wxTreeItemId& item); @@ -268,7 +389,26 @@ public: wxTreeItemId GetRootItem(); wxTreeItemId GetSelection(); - wxTreeItemId GetParent(const wxTreeItemId& item); + %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item); + //size_t GetSelections(wxArrayTreeItemIds& selection); + %addmethods { + PyObject* GetSelections() { + PyObject* rval = PyList_New(0); + wxArrayTreeItemIds array; + size_t num, x; + num = self->GetSelections(array); + for (x=0; x < num; x++) { + PyObject* item = wxPyConstructObject((void*)&array.Item(x), + "wxTreeItemId"); + PyList_Append(rval, item); + } + return rval; + } + } + + + + size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT); wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT); @@ -277,26 +417,29 @@ public: wxTreeItemId GetFirstVisibleItem(); wxTreeItemId GetNextVisible(const wxTreeItemId& item); wxTreeItemId GetPrevVisible(const wxTreeItemId& item); + wxTreeItemId GetLastChild(const wxTreeItemId& item); + wxTreeItemId AddRoot(const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId PrependItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId InsertItem(const wxTreeItemId& parent, const wxTreeItemId& idPrevious, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); void Delete(const wxTreeItemId& item); + void DeleteChildren(const wxTreeItemId& item); void DeleteAllItems(); void Expand(const wxTreeItemId& item); @@ -305,24 +448,61 @@ public: void Toggle(const wxTreeItemId& item); void Unselect(); + void UnselectAll(); void SelectItem(const wxTreeItemId& item); void EnsureVisible(const wxTreeItemId& item); void ScrollTo(const wxTreeItemId& item); - +#ifdef __WXMSW__ 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 EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE); +#else + void EditLabel(const wxTreeItemId& item); +#endif void SortChildren(const wxTreeItemId& item); - // **** And this too - // wxTreeItemCmpFunc *cmpFunction = NULL); -}; + void SetItemBold(const wxTreeItemId& item, int bold = TRUE); + bool IsBold(const wxTreeItemId& item) const; + wxTreeItemId HitTest(const wxPoint& point); + + void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); + void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); + void SetItemFont(const wxTreeItemId& item, const wxFont& font); +#ifdef __WXMSW__ + void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE); + + //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE) + %addmethods { + PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) { + wxRect rect; + if (self->GetBoundingRect(item, rect, textOnly)) + return wxPyConstructObject((void*)&rect, "wxRect"); + else { + Py_INCREF(Py_None); + return Py_None; + } + } + } #endif +%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 @@ -341,7 +521,7 @@ public: long style = 0, char* name = "tabCtrl"); - %pragma(python) addtomethod = "__init__:wxp._StdWindowCallbacks(self)" + %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)" bool DeleteAllItems(); bool DeleteItem(int item); @@ -380,37 +560,3 @@ public: //---------------------------------------------------------------------- -///////////////////////////////////////////////////////////////////////////// -// -// $Log$ -// Revision 1.7 1998/11/11 03:12:25 RD -// Additions for wxTreeCtrl -// -// Revision 1.6 1998/10/20 06:43:55 RD -// New wxTreeCtrl wrappers (untested) -// some changes in helpers -// etc. -// -// Revision 1.5 1998/10/07 07:34:33 RD -// Version 0.4.1 for wxGTK -// -// Revision 1.4 1998/10/02 06:40:36 RD -// -// Version 0.4 of wxPython for MSW. -// -// Revision 1.3 1998/08/18 19:48:15 RD -// more wxGTK compatibility things. -// -// It builds now but there are serious runtime problems... -// -// Revision 1.2 1998/08/15 07:36:30 RD -// - Moved the header in the .i files out of the code that gets put into -// the .cpp files. It caused CVS conflicts because of the RCS ID being -// different each time. -// -// - A few minor fixes. -// -// Revision 1.1 1998/08/09 08:25:49 RD -// Initial version -// -//