]>
Commit | Line | Data |
---|---|---|
08127323 | 1 | ///////////////////////////////////////////////////////////////////////////// |
d14a1e28 RD |
2 | // Name: _vscroll.i |
3 | // Purpose: SWIG interface defs for wxVScrolledWindow, wxVListBox, and | |
4 | // wxHtmlListBox | |
08127323 RD |
5 | // |
6 | // Author: Robin Dunn | |
7 | // | |
d14a1e28 | 8 | // Created: 14-Aug-2003 |
08127323 | 9 | // RCS-ID: $Id$ |
d14a1e28 | 10 | // Copyright: (c) 2003 by Total Control Software |
08127323 RD |
11 | // Licence: wxWindows license |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
d14a1e28 | 14 | // Not a %module |
08127323 RD |
15 | |
16 | ||
17 | //--------------------------------------------------------------------------- | |
0122b7e3 RD |
18 | |
19 | %{ | |
d14a1e28 | 20 | #include <wx/tipwin.h> |
0122b7e3 RD |
21 | %} |
22 | ||
1fded56b | 23 | //--------------------------------------------------------------------------- |
d14a1e28 | 24 | %newgroup; |
1fded56b | 25 | |
4416b508 | 26 | |
3628e088 RD |
27 | // wxVScrolledWindow |
28 | ||
29 | %{ | |
30 | #include <wx/vscroll.h> | |
3628e088 RD |
31 | %} |
32 | ||
33 | ||
34 | // First, the C++ version | |
35 | %{ | |
36 | class wxPyVScrolledWindow : public wxVScrolledWindow | |
37 | { | |
4617be08 | 38 | DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow) |
3628e088 RD |
39 | public: |
40 | wxPyVScrolledWindow() : wxVScrolledWindow() {} | |
41 | ||
42 | wxPyVScrolledWindow(wxWindow *parent, | |
43 | wxWindowID id = wxID_ANY, | |
44 | const wxPoint& pos = wxDefaultPosition, | |
45 | const wxSize& size = wxDefaultSize, | |
46 | long style = 0, | |
47 | const wxString& name = wxPyPanelNameStr) | |
48 | : wxVScrolledWindow(parent, id, pos, size, style, name) | |
49 | {} | |
50 | ||
51 | // Overridable virtuals | |
52 | ||
53 | // this function must be overridden in the derived class and it should | |
54 | // return the height of the given line in pixels | |
55 | DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight); | |
56 | ||
57 | ||
58 | // this function doesn't have to be overridden but it may be useful to do | |
59 | // it if calculating the lines heights is a relatively expensive operation | |
60 | // as it gives the user code a possibility to calculate several of them at | |
61 | // once | |
62 | // | |
63 | // OnGetLinesHint() is normally called just before OnGetLineHeight() but you | |
64 | // shouldn't rely on the latter being called for all lines in the interval | |
65 | // specified here. It is also possible that OnGetLineHeight() will be | |
66 | // called for the lines outside of this interval, so this is really just a | |
67 | // hint, not a promise. | |
68 | // | |
69 | // finally note that lineMin is inclusive, while lineMax is exclusive, as | |
70 | // usual | |
71 | DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint); | |
72 | ||
73 | ||
74 | // when the number of lines changes, we try to estimate the total height | |
75 | // of all lines which is a rather expensive operation in terms of lines | |
76 | // access, so if the user code may estimate the average height | |
77 | // better/faster than we do, it should override this function to implement | |
78 | // its own logic | |
79 | // | |
80 | // this function should return the best guess for the total height it may | |
81 | // make | |
82 | DEC_PYCALLBACK_COORD_const(EstimateTotalHeight); | |
83 | ||
84 | ||
85 | // Also expose some other interesting protected methods | |
86 | ||
87 | ||
88 | // find the index of the line we need to show at the top of the window such | |
89 | // that the last (fully or partially) visible line is the given one | |
a72f4631 | 90 | size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false) |
3628e088 RD |
91 | { return wxVScrolledWindow::FindFirstFromBottom(lineLast, fullyVisible); } |
92 | ||
93 | // get the total height of the lines between lineMin (inclusive) and | |
94 | // lineMax (exclusive) | |
95 | wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const | |
96 | { return wxVScrolledWindow::GetLinesHeight(lineMin, lineMax); } | |
97 | ||
ef802f32 RD |
98 | // update the thumb size shown by the scrollbar |
99 | void UpdateScrollbar() { wxVScrolledWindow::UpdateScrollbar(); } | |
100 | ||
101 | // remove the scrollbar completely because we don't need it | |
102 | void RemoveScrollbar() { wxVScrolledWindow::RemoveScrollbar(); } | |
3628e088 RD |
103 | |
104 | PYPRIVATE; | |
105 | }; | |
106 | ||
107 | IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow); | |
108 | ||
109 | IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight); | |
110 | IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint); | |
111 | IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight); | |
112 | %} | |
113 | ||
114 | ||
115 | ||
116 | // Now define this class for SWIG | |
117 | ||
118 | /* | |
119 | In the name of this class, "V" may stand for "variable" because it can be | |
120 | used for scrolling lines of variable heights; "virtual" because it is not | |
121 | necessary to know the heights of all lines in advance -- only those which | |
122 | are shown on the screen need to be measured; or, even, "vertical" because | |
123 | this class only supports scrolling in one direction currently (this could | |
124 | and probably will change in the future however). | |
125 | ||
126 | In any case, this is a generalization of the wxScrolledWindow class which | |
127 | can be only used when all lines have the same height. It lacks some other | |
128 | wxScrolledWindow features however, notably it currently lacks support for | |
129 | horizontal scrolling; it can't scroll another window nor only a rectangle | |
130 | of the window and not its entire client area. | |
131 | */ | |
132 | ||
ab1f7d2a RD |
133 | MustHaveApp(wxPyVScrolledWindow); |
134 | ||
1b8c7ba6 RD |
135 | %rename(VScrolledWindow) wxPyVScrolledWindow; |
136 | class wxPyVScrolledWindow : public wxPanel | |
3628e088 RD |
137 | { |
138 | public: | |
c25f90f6 | 139 | %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow) |
2b9048c5 | 140 | %pythonAppend wxPyVScrolledWindow() "" |
d14a1e28 | 141 | |
3628e088 RD |
142 | |
143 | wxPyVScrolledWindow(wxWindow *parent, | |
144 | wxWindowID id = wxID_ANY, | |
145 | const wxPoint& pos = wxDefaultPosition, | |
146 | const wxSize& size = wxDefaultSize, | |
147 | long style = 0, | |
148 | const wxString& name = wxPyPanelNameStr); | |
149 | ||
1b8c7ba6 | 150 | %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow()); |
3628e088 RD |
151 | |
152 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
3628e088 RD |
153 | |
154 | bool Create(wxWindow *parent, | |
155 | wxWindowID id = wxID_ANY, | |
156 | const wxPoint& pos = wxDefaultPosition, | |
157 | const wxSize& size = wxDefaultSize, | |
158 | long style = 0, | |
159 | const wxString& name = wxPyPanelNameStr); | |
160 | ||
161 | ||
162 | // set the number of lines the window contains: the derived class must | |
163 | // provide the heights for all lines with indices up to the one given here | |
164 | // in its OnGetLineHeight() | |
165 | void SetLineCount(size_t count); | |
166 | ||
167 | // scroll to the specified line: it will become the first visible line in | |
168 | // the window | |
169 | // | |
dd9f7fea | 170 | // return True if we scrolled the window, False if nothing was done |
3628e088 RD |
171 | bool ScrollToLine(size_t line); |
172 | ||
173 | // scroll by the specified number of lines/pages | |
174 | virtual bool ScrollLines(int lines); | |
175 | virtual bool ScrollPages(int pages); | |
176 | ||
177 | // redraw the specified line | |
178 | void RefreshLine(size_t line); | |
179 | ||
180 | // redraw all lines in the specified range (inclusive) | |
181 | void RefreshLines(size_t from, size_t to); | |
182 | ||
183 | // return the item at the specified (in physical coordinates) position or | |
184 | // wxNOT_FOUND if none, i.e. if it is below the last item | |
1b8c7ba6 | 185 | %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const); |
3628e088 RD |
186 | int HitTest(const wxPoint& pt) const; |
187 | ||
188 | // recalculate all our parameters and redisplay all lines | |
189 | virtual void RefreshAll(); | |
190 | ||
191 | ||
192 | // get the number of lines this window contains (previously set by | |
193 | // SetLineCount()) | |
194 | size_t GetLineCount() const; | |
195 | ||
196 | // get the first currently visible line | |
33661156 | 197 | size_t GetVisibleBegin() const; |
3628e088 RD |
198 | |
199 | // get the last currently visible line | |
33661156 | 200 | size_t GetVisibleEnd() const; |
3628e088 RD |
201 | |
202 | // is this line currently visible? | |
203 | bool IsVisible(size_t line) const; | |
204 | ||
88609ec9 RD |
205 | // this is the same as GetVisibleBegin(), exists to match |
206 | // GetLastVisibleLine() and for backwards compatibility only | |
207 | size_t GetFirstVisibleLine() const; | |
208 | ||
209 | // get the last currently visible line | |
210 | // | |
211 | // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive | |
212 | // number) if the control is empty, use GetVisibleEnd() instead, this one | |
213 | // is kept for backwards compatibility | |
214 | size_t GetLastVisibleLine() const; | |
215 | ||
4424b2a1 RD |
216 | // find the index of the line we need to show at the top of the window such |
217 | // that the last (fully or partially) visible line is the given one | |
218 | size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false); | |
219 | ||
220 | // get the total height of the lines between lineMin (inclusive) and | |
221 | // lineMax (exclusive) | |
222 | wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const; | |
dba7934c RD |
223 | |
224 | %property(FirstVisibleLine, GetFirstVisibleLine, doc="See `GetFirstVisibleLine`"); | |
225 | %property(LastVisibleLine, GetLastVisibleLine, doc="See `GetLastVisibleLine`"); | |
226 | %property(LineCount, GetLineCount, SetLineCount, doc="See `GetLineCount` and `SetLineCount`"); | |
227 | %property(VisibleBegin, GetVisibleBegin, doc="See `GetVisibleBegin`"); | |
228 | %property(VisibleEnd, GetVisibleEnd, doc="See `GetVisibleEnd`"); | |
3628e088 RD |
229 | }; |
230 | ||
4424b2a1 RD |
231 | |
232 | ||
3628e088 RD |
233 | //--------------------------------------------------------------------------- |
234 | // wxVListBox | |
235 | ||
236 | %{ | |
237 | #include <wx/vlbox.h> | |
3628e088 RD |
238 | %} |
239 | ||
b2dc1044 RD |
240 | MAKE_CONST_WXSTRING(VListBoxNameStr); |
241 | ||
3628e088 RD |
242 | |
243 | // First, the C++ version | |
244 | %{ | |
245 | class wxPyVListBox : public wxVListBox | |
246 | { | |
4617be08 | 247 | DECLARE_ABSTRACT_CLASS(wxPyVListBox) |
3628e088 RD |
248 | public: |
249 | wxPyVListBox() : wxVListBox() {} | |
250 | ||
251 | wxPyVListBox(wxWindow *parent, | |
252 | wxWindowID id = wxID_ANY, | |
253 | const wxPoint& pos = wxDefaultPosition, | |
254 | const wxSize& size = wxDefaultSize, | |
255 | long style = 0, | |
256 | const wxString& name = wxPyVListBoxNameStr) | |
257 | : wxVListBox(parent, id, pos, size, style, name) | |
258 | {} | |
259 | ||
260 | // Overridable virtuals | |
261 | ||
262 | // the derived class must implement this function to actually draw the item | |
263 | // with the given index on the provided DC | |
264 | // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0; | |
265 | DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem); | |
266 | ||
267 | ||
268 | // the derived class must implement this method to return the height of the | |
269 | // specified item | |
270 | // virtual wxCoord OnMeasureItem(size_t n) const = 0; | |
271 | DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem); | |
272 | ||
273 | ||
274 | // this method may be used to draw separators between the lines; note that | |
275 | // the rectangle may be modified, typically to deflate it a bit before | |
276 | // passing to OnDrawItem() | |
277 | // | |
278 | // the base class version doesn't do anything | |
279 | // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; | |
8072477d | 280 | DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator); |
3628e088 RD |
281 | |
282 | ||
283 | // this method is used to draw the items background and, maybe, a border | |
284 | // around it | |
285 | // | |
286 | // the base class version implements a reasonable default behaviour which | |
287 | // consists in drawing the selected item with the standard background | |
288 | // colour and drawing a border around the item if it is either selected or | |
289 | // current | |
290 | // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const; | |
291 | DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground); | |
292 | ||
293 | ||
294 | PYPRIVATE; | |
295 | }; | |
296 | ||
297 | IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox); | |
298 | ||
299 | IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem); | |
300 | IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem); | |
8072477d | 301 | IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator); |
3628e088 RD |
302 | IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground); |
303 | ||
304 | %} | |
305 | ||
306 | ||
307 | ||
308 | // Now define this class for SWIG | |
309 | ||
310 | /* | |
311 | This class has two main differences from a regular listbox: it can have an | |
312 | arbitrarily huge number of items because it doesn't store them itself but | |
313 | uses OnDrawItem() callback to draw them and its items can have variable | |
314 | height as determined by OnMeasureItem(). | |
315 | ||
316 | It emits the same events as wxListBox and the same event macros may be used | |
317 | with it. | |
318 | */ | |
ab1f7d2a RD |
319 | MustHaveApp(wxPyVListBox); |
320 | ||
1b8c7ba6 RD |
321 | %rename(VListBox) wxPyVListBox; |
322 | class wxPyVListBox : public wxPyVScrolledWindow | |
3628e088 RD |
323 | { |
324 | public: | |
c25f90f6 | 325 | %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox) |
2b9048c5 | 326 | %pythonAppend wxPyVListBox() "" |
d14a1e28 | 327 | |
3628e088 RD |
328 | |
329 | wxPyVListBox(wxWindow *parent, | |
330 | wxWindowID id = wxID_ANY, | |
331 | const wxPoint& pos = wxDefaultPosition, | |
332 | const wxSize& size = wxDefaultSize, | |
333 | long style = 0, | |
334 | const wxString& name = wxPyVListBoxNameStr); | |
335 | ||
1b8c7ba6 | 336 | %RenameCtor(PreVListBox, wxPyVListBox()); |
3628e088 RD |
337 | |
338 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
3628e088 RD |
339 | |
340 | bool Create(wxWindow *parent, | |
341 | wxWindowID id = wxID_ANY, | |
342 | const wxPoint& pos = wxDefaultPosition, | |
343 | const wxSize& size = wxDefaultSize, | |
344 | long style = 0, | |
345 | const wxString& name = wxPyVListBoxNameStr); | |
346 | ||
347 | // get the number of items in the control | |
348 | size_t GetItemCount() const; | |
349 | ||
350 | // does this control use multiple selection? | |
351 | bool HasMultipleSelection() const; | |
352 | ||
353 | // get the currently selected item or wxNOT_FOUND if there is no selection | |
354 | // | |
355 | // this method is only valid for the single selection listboxes | |
356 | int GetSelection() const; | |
357 | ||
358 | // is this item the current one? | |
359 | bool IsCurrent(size_t item) const; | |
360 | ||
361 | // is this item selected? | |
362 | bool IsSelected(size_t item) const; | |
363 | ||
364 | // get the number of the selected items (maybe 0) | |
365 | // | |
366 | // this method is valid for both single and multi selection listboxes | |
367 | size_t GetSelectedCount() const; | |
368 | ||
3d8a2fd7 RD |
369 | %extend { |
370 | // get the first selected item, returns wxNOT_FOUND if none | |
371 | // | |
372 | // cookie is an opaque parameter which should be passed to | |
373 | // GetNextSelected() later | |
374 | // | |
375 | // this method is only valid for the multi selection listboxes | |
376 | //int GetFirstSelected(unsigned long& cookie) const; | |
377 | PyObject* GetFirstSelected() { | |
378 | unsigned long cookie = 0; | |
379 | int selected = self->GetFirstSelected(cookie); | |
6e6b3557 | 380 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3d8a2fd7 RD |
381 | PyObject* tup = PyTuple_New(2); |
382 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); | |
383 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); | |
384 | wxPyEndBlockThreads(blocked); | |
385 | return tup; | |
386 | } | |
387 | ||
388 | // get next selection item, return wxNOT_FOUND if no more | |
389 | // | |
390 | // cookie must be the same parameter that was passed to GetFirstSelected() | |
391 | // before | |
392 | // | |
393 | // this method is only valid for the multi selection listboxes | |
394 | // int GetNextSelected(unsigned long& cookie) const; | |
395 | PyObject* GetNextSelected(unsigned long cookie) { | |
396 | int selected = self->GetNextSelected(cookie); | |
6e6b3557 | 397 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
3d8a2fd7 RD |
398 | PyObject* tup = PyTuple_New(2); |
399 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); | |
400 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); | |
401 | wxPyEndBlockThreads(blocked); | |
402 | return tup; | |
403 | } | |
404 | } | |
3628e088 | 405 | |
3d8a2fd7 | 406 | |
3628e088 RD |
407 | // get the margins around each item |
408 | wxPoint GetMargins() const; | |
409 | ||
410 | // get the background colour of selected cells | |
411 | const wxColour& GetSelectionBackground() const; | |
412 | ||
413 | ||
414 | // set the number of items to be shown in the control | |
415 | // | |
416 | // this is just a synonym for wxVScrolledWindow::SetLineCount() | |
417 | void SetItemCount(size_t count); | |
418 | ||
419 | // delete all items from the control | |
420 | void Clear(); | |
421 | ||
422 | // set the selection to the specified item, if it is wxNOT_FOUND the | |
423 | // selection is unset | |
424 | // | |
425 | // this function is only valid for the single selection listboxes | |
426 | void SetSelection(int selection); | |
427 | ||
428 | // selects or deselects the specified item which must be valid (i.e. not | |
429 | // equal to wxNOT_FOUND) | |
430 | // | |
dd9f7fea | 431 | // return True if the items selection status has changed or False |
3628e088 RD |
432 | // otherwise |
433 | // | |
434 | // this function is only valid for the multiple selection listboxes | |
a72f4631 | 435 | bool Select(size_t item, bool select = true); |
3628e088 RD |
436 | |
437 | // selects the items in the specified range whose end points may be given | |
438 | // in any order | |
439 | // | |
dd9f7fea | 440 | // return True if any items selection status has changed, False otherwise |
3628e088 RD |
441 | // |
442 | // this function is only valid for the single selection listboxes | |
443 | bool SelectRange(size_t from, size_t to); | |
444 | ||
445 | // toggle the selection of the specified item (must be valid) | |
446 | // | |
447 | // this function is only valid for the multiple selection listboxes | |
448 | void Toggle(size_t item); | |
449 | ||
450 | // select all items in the listbox | |
451 | // | |
452 | // the return code indicates if any items were affected by this operation | |
dd9f7fea | 453 | // (True) or if nothing has changed (False) |
3628e088 RD |
454 | bool SelectAll(); |
455 | ||
456 | // unselect all items in the listbox | |
457 | // | |
458 | // the return code has the same meaning as for SelectAll() | |
459 | bool DeselectAll(); | |
460 | ||
461 | // set the margins: horizontal margin is the distance between the window | |
462 | // border and the item contents while vertical margin is half of the | |
463 | // distance between items | |
464 | // | |
465 | // by default both margins are 0 | |
466 | void SetMargins(const wxPoint& pt); | |
1b8c7ba6 | 467 | %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y)); |
3628e088 RD |
468 | |
469 | // change the background colour of the selected cells | |
470 | void SetSelectionBackground(const wxColour& col); | |
471 | ||
cbfc9df6 RD |
472 | // refreshes only the selected items |
473 | void RefreshSelected(); | |
474 | ||
8072477d RD |
475 | virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; |
476 | virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const; | |
dba7934c RD |
477 | |
478 | %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`"); | |
479 | %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`"); | |
480 | %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`"); | |
481 | %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`"); | |
482 | %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`"); | |
483 | %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`"); | |
3628e088 RD |
484 | }; |
485 | ||
486 | ||
487 | //--------------------------------------------------------------------------- | |
488 | // wxHtmlListBox | |
489 | ||
490 | %{ | |
491 | #include <wx/htmllbox.h> | |
492 | %} | |
493 | ||
494 | // First, the C++ version | |
495 | %{ | |
496 | class wxPyHtmlListBox : public wxHtmlListBox | |
497 | { | |
4617be08 | 498 | DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox) |
3628e088 RD |
499 | public: |
500 | wxPyHtmlListBox() : wxHtmlListBox() {} | |
501 | ||
502 | wxPyHtmlListBox(wxWindow *parent, | |
503 | wxWindowID id = wxID_ANY, | |
504 | const wxPoint& pos = wxDefaultPosition, | |
505 | const wxSize& size = wxDefaultSize, | |
506 | long style = 0, | |
507 | const wxString& name = wxPyVListBoxNameStr) | |
508 | : wxHtmlListBox(parent, id, pos, size, style, name) | |
509 | {} | |
510 | ||
511 | // Overridable virtuals | |
512 | ||
513 | // this method must be implemented in the derived class and should return | |
514 | // the body (i.e. without <html>) of the HTML for the given item | |
515 | DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem); | |
516 | ||
517 | // this function may be overridden to decorate HTML returned by OnGetItem() | |
518 | DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup); | |
519 | ||
8072477d RD |
520 | // These are from wxVListBox |
521 | DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator); | |
522 | DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground); | |
523 | ||
3628e088 RD |
524 | // TODO: |
525 | // // this method allows to customize the selection appearance: it may be used | |
526 | // // to specify the colour of the text which normally has the given colour | |
527 | // // colFg when it is inside the selection | |
528 | // // | |
529 | // // by default, the original colour is not used at all and all text has the | |
530 | // // same (default for this system) colour inside selection | |
531 | // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const; | |
532 | ||
533 | // // this is the same as GetSelectedTextColour() but allows to customize the | |
534 | // // background colour -- this is even more rarely used as you can change it | |
535 | // // globally using SetSelectionBackground() | |
536 | // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const; | |
537 | ||
2890ca15 RD |
538 | |
539 | // This method may be overriden to handle clicking on a link in | |
540 | // the listbox. By default, clicking links is ignored. | |
541 | virtual void OnLinkClicked(size_t n, | |
542 | const wxHtmlLinkInfo& link); | |
3628e088 RD |
543 | |
544 | PYPRIVATE; | |
545 | }; | |
546 | ||
547 | ||
548 | IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox) | |
549 | ||
550 | IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem); | |
551 | IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup); | |
8072477d RD |
552 | IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator); |
553 | IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground); | |
3628e088 | 554 | |
2890ca15 RD |
555 | |
556 | void wxPyHtmlListBox::OnLinkClicked(size_t n, | |
557 | const wxHtmlLinkInfo& link) { | |
558 | bool found; | |
559 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
560 | if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) { | |
561 | PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0); | |
562 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj)); | |
563 | Py_DECREF(obj); | |
564 | } | |
565 | wxPyEndBlockThreads(blocked); | |
566 | if (! found) | |
567 | wxPyHtmlListBox::OnLinkClicked(n, link); | |
568 | } | |
569 | ||
3628e088 RD |
570 | %} |
571 | ||
572 | ||
573 | ||
574 | // Now define this class for SWIG | |
575 | ||
576 | ||
577 | // wxHtmlListBox is a listbox whose items are wxHtmlCells | |
ab1f7d2a | 578 | MustHaveApp(wxPyHtmlListBox); |
1b8c7ba6 RD |
579 | %rename(HtmlListBox) wxPyHtmlListBox; |
580 | class wxPyHtmlListBox : public wxPyVListBox | |
3628e088 RD |
581 | { |
582 | public: | |
c25f90f6 | 583 | %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox) |
2b9048c5 | 584 | %pythonAppend wxPyHtmlListBox() "" |
d14a1e28 | 585 | |
3628e088 RD |
586 | |
587 | // normal constructor which calls Create() internally | |
588 | wxPyHtmlListBox(wxWindow *parent, | |
589 | wxWindowID id = wxID_ANY, | |
590 | const wxPoint& pos = wxDefaultPosition, | |
591 | const wxSize& size = wxDefaultSize, | |
592 | long style = 0, | |
593 | const wxString& name = wxPyVListBoxNameStr); | |
594 | ||
1b8c7ba6 | 595 | %RenameCtor(PreHtmlListBox, wxPyHtmlListBox()); |
3628e088 RD |
596 | |
597 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
3628e088 RD |
598 | |
599 | bool Create(wxWindow *parent, | |
600 | wxWindowID id = wxID_ANY, | |
601 | const wxPoint& pos = wxDefaultPosition, | |
602 | const wxSize& size = wxDefaultSize, | |
603 | long style = 0, | |
604 | const wxString& name = wxPyVListBoxNameStr); | |
605 | ||
606 | ||
607 | void RefreshAll(); | |
608 | void SetItemCount(size_t count); | |
609 | ||
450d55a0 RD |
610 | // retrieve the file system used by the wxHtmlWinParser: if you use |
611 | // relative paths in your HTML, you should use its ChangePathTo() method | |
612 | wxFileSystem& GetFileSystem(); | |
2890ca15 RD |
613 | |
614 | void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link); | |
76b8fa1d RD |
615 | |
616 | %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`"); | |
3628e088 RD |
617 | }; |
618 | ||
619 | ||
d14a1e28 | 620 | |
f3e5dcaa RD |
621 | //--------------------------------------------------------------------------- |
622 | ||
623 | %{ | |
624 | const wxArrayString wxPyEmptyStringArray; | |
625 | %} | |
626 | MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr); | |
627 | ||
628 | ||
629 | enum { | |
630 | wxHLB_DEFAULT_STYLE, | |
631 | wxHLB_MULTIPLE | |
632 | }; | |
633 | ||
634 | MustHaveApp(wxSimpleHtmlListBox); | |
635 | ||
636 | class wxSimpleHtmlListBox : public wxPyHtmlListBox, | |
637 | public wxItemContainer | |
638 | { | |
639 | public: | |
640 | %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)"; | |
641 | %pythonAppend wxSimpleHtmlListBox() ""; | |
642 | ||
643 | wxSimpleHtmlListBox(wxWindow *parent, | |
644 | wxWindowID id = -1, | |
645 | const wxPoint& pos = wxDefaultPosition, | |
646 | const wxSize& size = wxDefaultSize, | |
647 | const wxArrayString& choices = wxPyEmptyStringArray, | |
648 | long style = wxHLB_DEFAULT_STYLE, | |
649 | const wxValidator& validator = wxDefaultValidator, | |
650 | const wxString& name = wxPySimpleHtmlListBoxNameStr); | |
651 | %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox()); | |
652 | ||
653 | bool Create(wxWindow *parent, | |
654 | wxWindowID id = -1, | |
655 | const wxPoint& pos = wxDefaultPosition, | |
656 | const wxSize& size= wxDefaultSize, | |
657 | const wxArrayString& choices = wxPyEmptyStringArray, | |
658 | long style = wxHLB_DEFAULT_STYLE, | |
659 | const wxValidator& validator = wxDefaultValidator, | |
660 | const wxString& name = wxPySimpleHtmlListBoxNameStr); | |
661 | }; | |
662 | ||
3628e088 | 663 | //--------------------------------------------------------------------------- |
4416b508 | 664 | |
771eb7a2 RD |
665 | %init %{ |
666 | // Map renamed classes back to their common name for OOR | |
d14a1e28 RD |
667 | wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox"); |
668 | wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox"); | |
771eb7a2 RD |
669 | wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow"); |
670 | %} | |
671 | ||
d14a1e28 | 672 | //--------------------------------------------------------------------------- |