]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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> | |
d14a1e28 RD |
20 | %} |
21 | ||
b2dc1044 RD |
22 | MAKE_CONST_WXSTRING(ListBoxNameStr); |
23 | ||
24 | ||
d14a1e28 RD |
25 | //--------------------------------------------------------------------------- |
26 | %newgroup | |
27 | ||
ab1f7d2a RD |
28 | MustHaveApp(wxListBox); |
29 | ||
d14a1e28 RD |
30 | class wxListBox : public wxControlWithItems |
31 | { | |
32 | public: | |
2b9048c5 RD |
33 | %pythonAppend wxListBox "self._setOORInfo(self)" |
34 | %pythonAppend wxListBox() "" | |
d14a1e28 | 35 | |
1dc0f664 DS |
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); | |
1b8c7ba6 | 54 | %RenameCtor(PreListBox, wxListBox()); |
d14a1e28 | 55 | |
1dc0f664 DS |
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); | |
d14a1e28 RD |
74 | |
75 | // all generic methods are in wxControlWithItems... | |
76 | ||
1dc0f664 DS |
77 | %extend |
78 | { | |
79 | void Insert(const wxString& item, int pos, PyObject* clientData = NULL) | |
80 | { | |
81 | if (clientData) | |
82 | { | |
d14a1e28 RD |
83 | wxPyClientData* data = new wxPyClientData(clientData); |
84 | self->Insert(item, pos, data); | |
1dc0f664 DS |
85 | } |
86 | else | |
d14a1e28 RD |
87 | self->Insert(item, pos); |
88 | } | |
89 | } | |
90 | ||
3f5ec806 | 91 | void InsertItems(const wxArrayString& items, unsigned int pos); |
d14a1e28 RD |
92 | void Set(const wxArrayString& items/*, void **clientData = NULL */); |
93 | ||
94 | // multiple selection logic | |
95 | virtual bool IsSelected(int n) const; | |
a72f4631 | 96 | virtual void SetSelection(int n, bool select = true); |
d14a1e28 | 97 | virtual void Select(int n); |
1dc0f664 | 98 | |
d14a1e28 RD |
99 | void Deselect(int n); |
100 | void DeselectAll(int itemToLeaveSelected = -1); | |
101 | ||
a72f4631 | 102 | virtual bool SetStringSelection(const wxString& s, bool select = true); |
d14a1e28 RD |
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; | |
ffb4a474 RD |
107 | %extend { |
108 | PyObject* GetSelections() { | |
109 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
214c4fbe RD |
110 | wxArrayInt lst; |
111 | self->GetSelections(lst); | |
112 | PyObject *tup = PyTuple_New(lst.GetCount()); | |
1dc0f664 DS |
113 | for (size_t i=0; i<lst.GetCount(); i++) |
114 | { | |
214c4fbe RD |
115 | PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i])); |
116 | } | |
ffb4a474 | 117 | wxPyEndBlockThreads(blocked); |
214c4fbe RD |
118 | return tup; |
119 | } | |
d14a1e28 RD |
120 | } |
121 | ||
122 | // set the specified item at the first visible item or scroll to max | |
123 | // range. | |
124 | void SetFirstItem(int n); | |
1b8c7ba6 | 125 | %Rename(SetFirstItemStr, void, SetFirstItem(const wxString& s)); |
d14a1e28 | 126 | |
1dc0f664 DS |
127 | // ensures that the given item is visible scrolling the listbox |
128 | // if necessary | |
d14a1e28 RD |
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 | ||
dd9f7fea | 135 | // return True if this listbox is sorted |
d14a1e28 | 136 | bool IsSorted() const; |
8492b560 | 137 | |
d344366c RD |
138 | // return the index of the item at this position or wxNOT_FOUND |
139 | int HitTest(const wxPoint& pt) const; | |
8492b560 | 140 | |
1dc0f664 DS |
141 | %extend |
142 | { | |
143 | void SetItemForegroundColour(int item, const wxColour& c) | |
144 | { | |
8492b560 RD |
145 | %#ifdef __WXMSW__ |
146 | if (self->GetWindowStyle() & wxLB_OWNERDRAW) | |
147 | self->GetItem(item)->SetTextColour(c); | |
148 | %#endif | |
149 | } | |
1dc0f664 DS |
150 | void SetItemBackgroundColour(int item, const wxColour& c) |
151 | { | |
8492b560 RD |
152 | %#ifdef __WXMSW__ |
153 | if (self->GetWindowStyle() & wxLB_OWNERDRAW) | |
154 | self->GetItem(item)->SetBackgroundColour(c); | |
155 | %#endif | |
156 | } | |
1dc0f664 DS |
157 | void SetItemFont(int item, const wxFont& f) |
158 | { | |
8492b560 RD |
159 | %#ifdef __WXMSW__ |
160 | if (self->GetWindowStyle() & wxLB_OWNERDRAW) | |
161 | self->GetItem(item)->SetFont(f); | |
162 | %#endif | |
163 | } | |
164 | } | |
1dc0f664 | 165 | |
174051f6 RD |
166 | static wxVisualAttributes |
167 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
76b8fa1d RD |
168 | |
169 | %property(Selections, GetSelections, doc="See `GetSelections`"); | |
d14a1e28 RD |
170 | }; |
171 | ||
172 | ||
173 | //--------------------------------------------------------------------------- | |
174 | %newgroup | |
175 | ||
176 | ||
ab1f7d2a RD |
177 | MustHaveApp(wxCheckListBox); |
178 | ||
d14a1e28 RD |
179 | // wxCheckListBox: a listbox whose items may be checked |
180 | class wxCheckListBox : public wxListBox | |
181 | { | |
182 | public: | |
2b9048c5 RD |
183 | %pythonAppend wxCheckListBox "self._setOORInfo(self)" |
184 | %pythonAppend wxCheckListBox() "" | |
d14a1e28 | 185 | |
1dc0f664 DS |
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); | |
1b8c7ba6 | 194 | %RenameCtor(PreCheckListBox, wxCheckListBox()); |
d14a1e28 | 195 | |
1dc0f664 DS |
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); | |
d14a1e28 | 204 | |
3f5ec806 RD |
205 | bool IsChecked(unsigned int index); |
206 | void Check(unsigned int index, int check = true); | |
d14a1e28 | 207 | |
8dfc6457 | 208 | #if defined(__WXMSW__) || defined(__WXGTK__) |
d14a1e28 | 209 | int GetItemHeight(); |
77aee871 RD |
210 | #else |
211 | %pythoncode { | |
212 | def GetItemHeight(self): | |
213 | raise NotImplementedError | |
214 | } | |
d14a1e28 | 215 | #endif |
0eae5d09 RD |
216 | |
217 | %property(ItemHeight, GetItemHeight, doc="See `GetItemHeight`"); | |
d14a1e28 RD |
218 | }; |
219 | ||
220 | //--------------------------------------------------------------------------- |