]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_listbox.i
No animate contrib anymore
[wxWidgets.git] / wxPython / src / _listbox.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _listbox.i
3 // Purpose: SWIG interface defs for wxListBox and wxCheckListBox
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 10-June-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include <wx/checklst.h>
20 %}
21
22 MAKE_CONST_WXSTRING(ListBoxNameStr);
23
24
25 //---------------------------------------------------------------------------
26 %newgroup
27
28 MustHaveApp(wxListBox);
29
30 class wxListBox : public wxControlWithItems
31 {
32 public:
33 %pythonAppend wxListBox "self._setOORInfo(self)"
34 %pythonAppend wxListBox() ""
35
36 wxListBox(wxWindow* parent,
37 wxWindowID id = -1,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 const wxArrayString& choices = wxPyEmptyStringArray,
41 long style = 0,
42 const wxValidator& validator = wxDefaultValidator,
43 const wxString& name = wxPyListBoxNameStr);
44
45 // wxListBox(wxWindow* parent,
46 // wxWindowID id = -1,
47 // const wxPoint& pos = wxDefaultPosition,
48 // const wxSize& size = wxDefaultSize,
49 // int n = 0,
50 // const wxString choices[] = NULL,
51 // long style = 0,
52 // const wxValidator& validator = wxDefaultValidator,
53 // const wxString& name = wxPyListBoxNameStr);
54 %RenameCtor(PreListBox, wxListBox());
55
56 bool Create(wxWindow* parent,
57 wxWindowID id = -1,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 const wxArrayString& choices = wxPyEmptyStringArray,
61 long style = 0,
62 const wxValidator& validator = wxDefaultValidator,
63 const wxString& name = wxPyListBoxNameStr);
64
65 // bool Create(wxWindow *parent,
66 // wxWindowID id = -1,
67 // const wxPoint& pos = wxDefaultPosition,
68 // const wxSize& size = wxDefaultSize,
69 // int n = 0,
70 // const wxString choices[] = NULL,
71 // long style = 0,
72 // const wxValidator& validator = wxDefaultValidator,
73 // const wxString& name = wxPyListBoxNameStr);
74
75 // all generic methods are in wxControlWithItems...
76
77 %extend
78 {
79 void Insert(const wxString& item, int pos, PyObject* clientData = NULL)
80 {
81 if (clientData)
82 {
83 wxPyClientData* data = new wxPyClientData(clientData);
84 self->Insert(item, pos, data);
85 }
86 else
87 self->Insert(item, pos);
88 }
89 }
90
91 void InsertItems(const wxArrayString& items, unsigned int pos);
92 void Set(const wxArrayString& items/*, void **clientData = NULL */);
93
94 // multiple selection logic
95 virtual bool IsSelected(int n) const;
96 virtual void SetSelection(int n, bool select = true);
97 virtual void Select(int n);
98
99 void Deselect(int n);
100 void DeselectAll(int itemToLeaveSelected = -1);
101
102 virtual bool SetStringSelection(const wxString& s, bool select = true);
103
104 // works for single as well as multiple selection listboxes (unlike
105 // GetSelection which only works for listboxes with single selection)
106 //virtual int GetSelections(wxArrayInt& aSelections) const;
107 %extend {
108 PyObject* GetSelections() {
109 wxPyBlock_t blocked = wxPyBeginBlockThreads();
110 wxArrayInt lst;
111 self->GetSelections(lst);
112 PyObject *tup = PyTuple_New(lst.GetCount());
113 for (size_t i=0; i<lst.GetCount(); i++)
114 {
115 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
116 }
117 wxPyEndBlockThreads(blocked);
118 return tup;
119 }
120 }
121
122 // set the specified item at the first visible item or scroll to max
123 // range.
124 void SetFirstItem(int n);
125 %Rename(SetFirstItemStr, void, SetFirstItem(const wxString& s));
126
127 // ensures that the given item is visible scrolling the listbox
128 // if necessary
129 virtual void EnsureVisible(int n);
130
131 // a combination of Append() and EnsureVisible(): appends the item to the
132 // listbox and ensures that it is visible i.e. not scrolled out of view
133 void AppendAndEnsureVisible(const wxString& s);
134
135 // return True if this listbox is sorted
136 bool IsSorted() const;
137
138 // return the index of the item at this position or wxNOT_FOUND
139 int HitTest(const wxPoint& pt) const;
140
141 %extend
142 {
143 void SetItemForegroundColour(int item, const wxColour& c)
144 {
145 %#ifdef __WXMSW__
146 if (self->GetWindowStyle() & wxLB_OWNERDRAW)
147 self->GetItem(item)->SetTextColour(c);
148 %#endif
149 }
150 void SetItemBackgroundColour(int item, const wxColour& c)
151 {
152 %#ifdef __WXMSW__
153 if (self->GetWindowStyle() & wxLB_OWNERDRAW)
154 self->GetItem(item)->SetBackgroundColour(c);
155 %#endif
156 }
157 void SetItemFont(int item, const wxFont& f)
158 {
159 %#ifdef __WXMSW__
160 if (self->GetWindowStyle() & wxLB_OWNERDRAW)
161 self->GetItem(item)->SetFont(f);
162 %#endif
163 }
164 }
165
166 static wxVisualAttributes
167 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
168
169 %property(Selections, GetSelections, doc="See `GetSelections`");
170 };
171
172
173 //---------------------------------------------------------------------------
174 %newgroup
175
176
177 MustHaveApp(wxCheckListBox);
178
179 // wxCheckListBox: a listbox whose items may be checked
180 class wxCheckListBox : public wxListBox
181 {
182 public:
183 %pythonAppend wxCheckListBox "self._setOORInfo(self)"
184 %pythonAppend wxCheckListBox() ""
185
186 wxCheckListBox(wxWindow *parent,
187 wxWindowID id = -1,
188 const wxPoint& pos = wxDefaultPosition,
189 const wxSize& size = wxDefaultSize,
190 const wxArrayString& choices = wxPyEmptyStringArray,
191 long style = 0,
192 const wxValidator& validator = wxDefaultValidator,
193 const wxString& name = wxPyListBoxNameStr);
194 %RenameCtor(PreCheckListBox, wxCheckListBox());
195
196 bool Create(wxWindow *parent,
197 wxWindowID id = -1,
198 const wxPoint& pos = wxDefaultPosition,
199 const wxSize& size = wxDefaultSize,
200 const wxArrayString& choices = wxPyEmptyStringArray,
201 long style = 0,
202 const wxValidator& validator = wxDefaultValidator,
203 const wxString& name = wxPyListBoxNameStr);
204
205 bool IsChecked(unsigned int index);
206 void Check(unsigned int index, int check = true);
207
208 #if defined(__WXMSW__) || defined(__WXGTK__)
209 int GetItemHeight();
210 #else
211 %pythoncode {
212 def GetItemHeight(self):
213 raise NotImplementedError
214 }
215 #endif
216
217 %property(ItemHeight, GetItemHeight, doc="See `GetItemHeight`");
218 };
219
220 //---------------------------------------------------------------------------