]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _vscroll.i | |
3 | // Purpose: SWIG interface defs for wxVScrolledWindow, wxVListBox, and | |
4 | // wxHtmlListBox | |
5 | // | |
6 | // Author: Robin Dunn | |
7 | // | |
8 | // Created: 14-Aug-2003 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) 2003 by Total Control Software | |
11 | // Licence: wxWindows license | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | // Not a %module | |
15 | ||
16 | ||
17 | //--------------------------------------------------------------------------- | |
18 | ||
19 | %{ | |
20 | #include <wx/tipwin.h> | |
21 | %} | |
22 | ||
23 | //--------------------------------------------------------------------------- | |
24 | %newgroup; | |
25 | ||
26 | ||
27 | // wxVScrolledWindow | |
28 | ||
29 | %{ | |
30 | #include <wx/vscroll.h> | |
31 | %} | |
32 | ||
33 | ||
34 | // First, the C++ version | |
35 | %{ | |
36 | class wxPyVScrolledWindow : public wxVScrolledWindow | |
37 | { | |
38 | DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow) | |
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 | |
90 | size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false) | |
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 | ||
98 | ||
99 | PYPRIVATE; | |
100 | }; | |
101 | ||
102 | IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow); | |
103 | ||
104 | IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight); | |
105 | IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint); | |
106 | IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight); | |
107 | %} | |
108 | ||
109 | ||
110 | ||
111 | // Now define this class for SWIG | |
112 | ||
113 | /* | |
114 | In the name of this class, "V" may stand for "variable" because it can be | |
115 | used for scrolling lines of variable heights; "virtual" because it is not | |
116 | necessary to know the heights of all lines in advance -- only those which | |
117 | are shown on the screen need to be measured; or, even, "vertical" because | |
118 | this class only supports scrolling in one direction currently (this could | |
119 | and probably will change in the future however). | |
120 | ||
121 | In any case, this is a generalization of the wxScrolledWindow class which | |
122 | can be only used when all lines have the same height. It lacks some other | |
123 | wxScrolledWindow features however, notably it currently lacks support for | |
124 | horizontal scrolling; it can't scroll another window nor only a rectangle | |
125 | of the window and not its entire client area. | |
126 | */ | |
127 | ||
128 | MustHaveApp(wxPyVScrolledWindow); | |
129 | ||
130 | %rename(VScrolledWindow) wxPyVScrolledWindow; | |
131 | class wxPyVScrolledWindow : public wxPanel | |
132 | { | |
133 | public: | |
134 | %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)" | |
135 | %pythonAppend wxPyVScrolledWindow() "" | |
136 | ||
137 | ||
138 | wxPyVScrolledWindow(wxWindow *parent, | |
139 | wxWindowID id = wxID_ANY, | |
140 | const wxPoint& pos = wxDefaultPosition, | |
141 | const wxSize& size = wxDefaultSize, | |
142 | long style = 0, | |
143 | const wxString& name = wxPyPanelNameStr); | |
144 | ||
145 | %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow()); | |
146 | ||
147 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
148 | ||
149 | bool Create(wxWindow *parent, | |
150 | wxWindowID id = wxID_ANY, | |
151 | const wxPoint& pos = wxDefaultPosition, | |
152 | const wxSize& size = wxDefaultSize, | |
153 | long style = 0, | |
154 | const wxString& name = wxPyPanelNameStr); | |
155 | ||
156 | ||
157 | // set the number of lines the window contains: the derived class must | |
158 | // provide the heights for all lines with indices up to the one given here | |
159 | // in its OnGetLineHeight() | |
160 | void SetLineCount(size_t count); | |
161 | ||
162 | // scroll to the specified line: it will become the first visible line in | |
163 | // the window | |
164 | // | |
165 | // return True if we scrolled the window, False if nothing was done | |
166 | bool ScrollToLine(size_t line); | |
167 | ||
168 | // scroll by the specified number of lines/pages | |
169 | virtual bool ScrollLines(int lines); | |
170 | virtual bool ScrollPages(int pages); | |
171 | ||
172 | // redraw the specified line | |
173 | void RefreshLine(size_t line); | |
174 | ||
175 | // redraw all lines in the specified range (inclusive) | |
176 | void RefreshLines(size_t from, size_t to); | |
177 | ||
178 | // return the item at the specified (in physical coordinates) position or | |
179 | // wxNOT_FOUND if none, i.e. if it is below the last item | |
180 | %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const); | |
181 | int HitTest(const wxPoint& pt) const; | |
182 | ||
183 | // recalculate all our parameters and redisplay all lines | |
184 | virtual void RefreshAll(); | |
185 | ||
186 | ||
187 | // get the number of lines this window contains (previously set by | |
188 | // SetLineCount()) | |
189 | size_t GetLineCount() const; | |
190 | ||
191 | // get the first currently visible line | |
192 | size_t GetVisibleBegin() const; | |
193 | ||
194 | // get the last currently visible line | |
195 | size_t GetVisibleEnd() const; | |
196 | ||
197 | // is this line currently visible? | |
198 | bool IsVisible(size_t line) const; | |
199 | ||
200 | // this is the same as GetVisibleBegin(), exists to match | |
201 | // GetLastVisibleLine() and for backwards compatibility only | |
202 | size_t GetFirstVisibleLine() const; | |
203 | ||
204 | // get the last currently visible line | |
205 | // | |
206 | // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive | |
207 | // number) if the control is empty, use GetVisibleEnd() instead, this one | |
208 | // is kept for backwards compatibility | |
209 | size_t GetLastVisibleLine() const; | |
210 | ||
211 | // find the index of the line we need to show at the top of the window such | |
212 | // that the last (fully or partially) visible line is the given one | |
213 | size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false); | |
214 | ||
215 | // get the total height of the lines between lineMin (inclusive) and | |
216 | // lineMax (exclusive) | |
217 | wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const; | |
218 | }; | |
219 | ||
220 | ||
221 | ||
222 | // //---------------------------------------------------------------------------- | |
223 | // %newgroup; | |
224 | ||
225 | // // wxHVScrolledWindow | |
226 | ||
227 | // // First, the C++ version | |
228 | // %{ | |
229 | // class wxPyHVScrolledWindow : public wxHVScrolledWindow | |
230 | // { | |
231 | // DECLARE_ABSTRACT_CLASS(wxPyHVScrolledWindow) | |
232 | // public: | |
233 | // wxPyHVScrolledWindow() : wxHVScrolledWindow() {} | |
234 | // wxPyHVScrolledWindow(wxWindow *parent, | |
235 | // wxWindowID id = wxID_ANY, | |
236 | // const wxPoint& pos = wxDefaultPosition, | |
237 | // const wxSize& size = wxDefaultSize, | |
238 | // long style = 0, | |
239 | // const wxString& name = wxPyPanelNameStr) | |
240 | // : wxHVScrolledWindow(parent, id, pos, size, style, name) {} | |
241 | ||
242 | // // Overridable virtuals | |
243 | ||
244 | // // these functions must be overridden in the derived class and they should | |
245 | // // return the width or height of the given line in pixels | |
246 | // DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight); | |
247 | // DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth); | |
248 | ||
249 | // // the following functions don't need to be overridden but it may be useful | |
250 | // // to do if calculating the lines widths or heights is a relatively | |
251 | // // expensive operation as it gives the user code a possibility to calculate | |
252 | // // several of them at once | |
253 | // // | |
254 | // // OnGetRowsHeightHint() and OnGetColumnsWidthHint() are normally called | |
255 | // // just before OnGetRowHeight() and OnGetColumnWidth(), respectively, but | |
256 | // // you shouldn't rely on the latter methods being called for all lines in | |
257 | // // the interval specified here. It is also possible that OnGetRowHeight() | |
258 | // // or OnGetColumnWidth() will be called for the lines outside of this | |
259 | // // interval, so this is really just a hint, not a promise. | |
260 | // // | |
261 | // // finally note that min is inclusive, while max is exclusive, as usual | |
262 | // DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint); | |
263 | // DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint); | |
264 | ||
265 | // // when the number of lines changes, we try to estimate the total width or | |
266 | // // height of all lines which is a rather expensive operation in terms of | |
267 | // // lines access, so if the user code may estimate the average height | |
268 | // // better/faster than we do, it should override this function to implement | |
269 | // // its own logic | |
270 | // // | |
271 | // // this function should return the best guess for the total height it may | |
272 | // // make | |
273 | // DEC_PYCALLBACK_COORD_const(EstimateTotalHeight); | |
274 | // DEC_PYCALLBACK_COORD_const(EstimateTotalWidth); | |
275 | ||
276 | ||
277 | // // Also expose some other interesting protected methods | |
278 | ||
279 | // // find the index of the horizontal line we need to show at the top of the | |
280 | // // window such that the last (fully or partially) visible line is the given | |
281 | // // one | |
282 | // size_t FindFirstFromRight(size_t columnLast, bool fullyVisible = false) | |
283 | // { return wxHVScrolledWindow::FindFirstFromRight(columnLast, fullyVisible); } | |
284 | ||
285 | // // find the index of the vertical line we need to show at the top of the | |
286 | // // window such that the last (fully or partially) visible line is the given | |
287 | // // one | |
288 | // size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false) | |
289 | // { return wxHVScrolledWindow::FindFirstFromBottom(lineLast, fullyVisible); } | |
290 | ||
291 | ||
292 | // // get the total width or height of the lines between lineMin (inclusive) | |
293 | // // and lineMax (exclusive) | |
294 | // wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const | |
295 | // { return wxHVScrolledWindow::GetRowsHeight(lineMin, lineMax); } | |
296 | // wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const | |
297 | // { return wxHVScrolledWindow::GetColumnsWidth(columnMin, columnMax); } | |
298 | ||
299 | // PYPRIVATE; | |
300 | // }; | |
301 | ||
302 | ||
303 | // IMPLEMENT_ABSTRACT_CLASS(wxPyHVScrolledWindow, wxHVScrolledWindow); | |
304 | ||
305 | // IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowHeight); | |
306 | // IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnWidth); | |
307 | // IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowsHeightHint); | |
308 | // IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnsWidthHint); | |
309 | // IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalHeight); | |
310 | // IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalWidth); | |
311 | // %} | |
312 | ||
313 | ||
314 | ||
315 | ||
316 | // // Now define this class for SWIG | |
317 | ||
318 | // /* | |
319 | // This class is strongly influenced by wxVScrolledWindow. In fact, much of | |
320 | // code is line for line the same except it EXPLICITLY states which axis is | |
321 | // being worked on. Like wxVScrolledWindow, this class is here to provide | |
322 | // an easy way to implement variable line sizes. The difference is that | |
323 | // wxVScrolledWindow only works with vertical scrolling. This class extends | |
324 | // the behavior of wxVScrolledWindow to the horizontal axis in addition to the | |
325 | // vertical axis. | |
326 | ||
327 | // The scrolling is also "virtual" in the sense that line widths and heights | |
328 | // only need to be known for lines that are currently visible. | |
329 | ||
330 | // Like wxVScrolledWindow, this is a generalization of the wxScrolledWindow | |
331 | // class which can be only used when all horizontal lines have the same width | |
332 | // and all of the vertical lines have the same height. Like wxVScrolledWinow | |
333 | // it lacks some of wxScrolledWindow features such as scrolling another window | |
334 | // or only scrolling a rectangle of the window and not its entire client area. | |
335 | ||
336 | // If only vertical scrolling is needed, wxVScrolledWindow is recommended | |
337 | // because it is simpler to use (and you get to type less). | |
338 | ||
339 | // There is no wxHScrolledWindow but horizontal only scrolling is implemented | |
340 | // easily enough with this class. If someone feels the need for such a class, | |
341 | // implementing it is trivial. | |
342 | // */ | |
343 | // MustHaveApp(wxPyHVScrolledWindow); | |
344 | ||
345 | // %rename(HVScrolledWindow) wxPyHVScrolledWindow; | |
346 | // class wxPyHVScrolledWindow : public wxPanel | |
347 | // { | |
348 | // public: | |
349 | // %pythonAppend wxPyHVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)" | |
350 | // %pythonAppend wxPyHVScrolledWindow() "" | |
351 | ||
352 | // // normal ctor, no need to call Create() after this one | |
353 | // // | |
354 | // // note that wxVSCROLL and wxHSCROLL are always automatically added to our | |
355 | // // style, there is no need to specify them explicitly | |
356 | // wxPyHVScrolledWindow(wxWindow *parent, | |
357 | // wxWindowID id = wxID_ANY, | |
358 | // const wxPoint& pos = wxDefaultPosition, | |
359 | // const wxSize& size = wxDefaultSize, | |
360 | // long style = 0, | |
361 | // const wxString& name = wxPyPanelNameStr); | |
362 | ||
363 | // %RenameCtor(PreHVScrolledWindow, wxPyHVScrolledWindow()); | |
364 | // void _setCallbackInfo(PyObject* self, PyObject* _class); | |
365 | ||
366 | ||
367 | // bool Create(wxWindow *parent, | |
368 | // wxWindowID id = wxID_ANY, | |
369 | // const wxPoint& pos = wxDefaultPosition, | |
370 | // const wxSize& size = wxDefaultSize, | |
371 | // long style = 0, | |
372 | // const wxString& name = wxPyPanelNameStr); | |
373 | ||
374 | ||
375 | // // operations | |
376 | // // ---------- | |
377 | ||
378 | // // set the number of lines the window contains for each axis: the derived | |
379 | // // class must provide the widths and heights for all lines with indices up | |
380 | // // to each of the one given here in its OnGetColumnWidth() and | |
381 | // // OnGetRowHeight() | |
382 | // void SetRowColumnCounts(size_t rowCount, size_t columnCount); | |
383 | ||
384 | // // with physical scrolling on, the device origin is changed properly when | |
385 | // // a wxPaintDC is prepared, children are actually moved and layed out | |
386 | // // properly, and the contents of the window (pixels) are actually moved | |
387 | // void EnablePhysicalScrolling(bool scrolling = true); | |
388 | ||
389 | // // scroll to the specified line: it will become the first visible line in | |
390 | // // the window | |
391 | // // | |
392 | // // return true if we scrolled the window, false if nothing was done | |
393 | // bool ScrollToRow(size_t row); | |
394 | // bool ScrollToColumn(size_t column); | |
395 | // bool ScrollToRowColumn(size_t row, size_t column); | |
396 | ||
397 | // // scroll by the specified number of lines/pages | |
398 | // virtual bool ScrollRows(int rows); | |
399 | // virtual bool ScrollColumns(int columns); | |
400 | // virtual bool ScrollRowsColumns(int rows, int columns); | |
401 | // virtual bool ScrollRowPages(int pages); | |
402 | // virtual bool ScrollColumnPages(int pages); | |
403 | // virtual bool ScrollPages(int rowPages, int columnPages); | |
404 | ||
405 | // // redraw the specified line | |
406 | // virtual void RefreshRow(size_t line); | |
407 | // virtual void RefreshColumn(size_t line); | |
408 | // virtual void RefreshRowColumn(size_t row, size_t column); | |
409 | ||
410 | // // redraw all lines in the specified range (inclusive) | |
411 | // virtual void RefreshRows(size_t from, size_t to); | |
412 | // virtual void RefreshColumns(size_t from, size_t to); | |
413 | // virtual void RefreshRowsColumns(size_t fromRow, size_t toRow, | |
414 | // size_t fromColumn, size_t toColumn); | |
415 | ||
416 | // // return the horizontal and vertical line within a wxPoint at the | |
417 | // // specified (in physical coordinates) position or. | |
418 | ||
419 | // // wxNOT_FOUND in either or both axes if no line is present at the | |
420 | // // requested coordinates, i.e. if it is past the last lines | |
421 | // %Rename(HitTestXY, wxPoint, HitTest(wxCoord x, wxCoord y) const); | |
422 | // wxPoint HitTest(const wxPoint& pt) const; | |
423 | ||
424 | // // recalculate all our parameters and redisplay all lines | |
425 | // virtual void RefreshAll(); | |
426 | ||
427 | ||
428 | // // accessors | |
429 | // // --------- | |
430 | ||
431 | // // get the number of lines this window contains (previously set by | |
432 | // // SetLineCount()) | |
433 | // size_t GetRowCount() const; | |
434 | // size_t GetColumnCount() const; | |
435 | // wxSize GetRowColumnCounts() const; | |
436 | ||
437 | // // get the first currently visible line/lines | |
438 | // size_t GetVisibleRowsBegin() const; | |
439 | // size_t GetVisibleColumnsBegin() const; | |
440 | // wxPoint GetVisibleBegin() const; | |
441 | ||
442 | // // get the last currently visible line/lines | |
443 | // size_t GetVisibleRowsEnd() const; | |
444 | // size_t GetVisibleColumnsEnd() const; | |
445 | // wxPoint GetVisibleEnd() const; | |
446 | ||
447 | // // is this line currently visible? | |
448 | // bool IsRowVisible(size_t row) const; | |
449 | // bool IsColumnVisible(size_t column) const; | |
450 | // bool IsVisible(size_t row, size_t column) const; | |
451 | ||
452 | ||
453 | // // find the index of the horizontal line we need to show at the top of the | |
454 | // // window such that the last (fully or partially) visible line is the given | |
455 | // // one | |
456 | // size_t FindFirstFromRight(size_t columnLast, bool fullyVisible = false); | |
457 | ||
458 | // // find the index of the vertical line we need to show at the top of the | |
459 | // // window such that the last (fully or partially) visible line is the given | |
460 | // // one | |
461 | // size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false); | |
462 | ||
463 | ||
464 | // // get the total width or height of the lines between lineMin (inclusive) | |
465 | // // and lineMax (exclusive) | |
466 | // wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const; | |
467 | // wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const; | |
468 | ||
469 | // }; | |
470 | ||
471 | ||
472 | ||
473 | //--------------------------------------------------------------------------- | |
474 | // wxVListBox | |
475 | ||
476 | %{ | |
477 | #include <wx/vlbox.h> | |
478 | %} | |
479 | ||
480 | MAKE_CONST_WXSTRING(VListBoxNameStr); | |
481 | ||
482 | ||
483 | // First, the C++ version | |
484 | %{ | |
485 | class wxPyVListBox : public wxVListBox | |
486 | { | |
487 | DECLARE_ABSTRACT_CLASS(wxPyVListBox) | |
488 | public: | |
489 | wxPyVListBox() : wxVListBox() {} | |
490 | ||
491 | wxPyVListBox(wxWindow *parent, | |
492 | wxWindowID id = wxID_ANY, | |
493 | const wxPoint& pos = wxDefaultPosition, | |
494 | const wxSize& size = wxDefaultSize, | |
495 | long style = 0, | |
496 | const wxString& name = wxPyVListBoxNameStr) | |
497 | : wxVListBox(parent, id, pos, size, style, name) | |
498 | {} | |
499 | ||
500 | // Overridable virtuals | |
501 | ||
502 | // the derived class must implement this function to actually draw the item | |
503 | // with the given index on the provided DC | |
504 | // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0; | |
505 | DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem); | |
506 | ||
507 | ||
508 | // the derived class must implement this method to return the height of the | |
509 | // specified item | |
510 | // virtual wxCoord OnMeasureItem(size_t n) const = 0; | |
511 | DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem); | |
512 | ||
513 | ||
514 | // this method may be used to draw separators between the lines; note that | |
515 | // the rectangle may be modified, typically to deflate it a bit before | |
516 | // passing to OnDrawItem() | |
517 | // | |
518 | // the base class version doesn't do anything | |
519 | // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; | |
520 | DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator); | |
521 | ||
522 | ||
523 | // this method is used to draw the items background and, maybe, a border | |
524 | // around it | |
525 | // | |
526 | // the base class version implements a reasonable default behaviour which | |
527 | // consists in drawing the selected item with the standard background | |
528 | // colour and drawing a border around the item if it is either selected or | |
529 | // current | |
530 | // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const; | |
531 | DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground); | |
532 | ||
533 | ||
534 | PYPRIVATE; | |
535 | }; | |
536 | ||
537 | IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox); | |
538 | ||
539 | IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem); | |
540 | IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem); | |
541 | IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator); | |
542 | IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground); | |
543 | ||
544 | %} | |
545 | ||
546 | ||
547 | ||
548 | // Now define this class for SWIG | |
549 | ||
550 | /* | |
551 | This class has two main differences from a regular listbox: it can have an | |
552 | arbitrarily huge number of items because it doesn't store them itself but | |
553 | uses OnDrawItem() callback to draw them and its items can have variable | |
554 | height as determined by OnMeasureItem(). | |
555 | ||
556 | It emits the same events as wxListBox and the same event macros may be used | |
557 | with it. | |
558 | */ | |
559 | MustHaveApp(wxPyVListBox); | |
560 | ||
561 | %rename(VListBox) wxPyVListBox; | |
562 | class wxPyVListBox : public wxPyVScrolledWindow | |
563 | { | |
564 | public: | |
565 | %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)" | |
566 | %pythonAppend wxPyVListBox() "" | |
567 | ||
568 | ||
569 | wxPyVListBox(wxWindow *parent, | |
570 | wxWindowID id = wxID_ANY, | |
571 | const wxPoint& pos = wxDefaultPosition, | |
572 | const wxSize& size = wxDefaultSize, | |
573 | long style = 0, | |
574 | const wxString& name = wxPyVListBoxNameStr); | |
575 | ||
576 | %RenameCtor(PreVListBox, wxPyVListBox()); | |
577 | ||
578 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
579 | ||
580 | bool Create(wxWindow *parent, | |
581 | wxWindowID id = wxID_ANY, | |
582 | const wxPoint& pos = wxDefaultPosition, | |
583 | const wxSize& size = wxDefaultSize, | |
584 | long style = 0, | |
585 | const wxString& name = wxPyVListBoxNameStr); | |
586 | ||
587 | // get the number of items in the control | |
588 | size_t GetItemCount() const; | |
589 | ||
590 | // does this control use multiple selection? | |
591 | bool HasMultipleSelection() const; | |
592 | ||
593 | // get the currently selected item or wxNOT_FOUND if there is no selection | |
594 | // | |
595 | // this method is only valid for the single selection listboxes | |
596 | int GetSelection() const; | |
597 | ||
598 | // is this item the current one? | |
599 | bool IsCurrent(size_t item) const; | |
600 | ||
601 | // is this item selected? | |
602 | bool IsSelected(size_t item) const; | |
603 | ||
604 | // get the number of the selected items (maybe 0) | |
605 | // | |
606 | // this method is valid for both single and multi selection listboxes | |
607 | size_t GetSelectedCount() const; | |
608 | ||
609 | %extend { | |
610 | // get the first selected item, returns wxNOT_FOUND if none | |
611 | // | |
612 | // cookie is an opaque parameter which should be passed to | |
613 | // GetNextSelected() later | |
614 | // | |
615 | // this method is only valid for the multi selection listboxes | |
616 | //int GetFirstSelected(unsigned long& cookie) const; | |
617 | PyObject* GetFirstSelected() { | |
618 | unsigned long cookie = 0; | |
619 | int selected = self->GetFirstSelected(cookie); | |
620 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
621 | PyObject* tup = PyTuple_New(2); | |
622 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); | |
623 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); | |
624 | wxPyEndBlockThreads(blocked); | |
625 | return tup; | |
626 | } | |
627 | ||
628 | // get next selection item, return wxNOT_FOUND if no more | |
629 | // | |
630 | // cookie must be the same parameter that was passed to GetFirstSelected() | |
631 | // before | |
632 | // | |
633 | // this method is only valid for the multi selection listboxes | |
634 | // int GetNextSelected(unsigned long& cookie) const; | |
635 | PyObject* GetNextSelected(unsigned long cookie) { | |
636 | int selected = self->GetNextSelected(cookie); | |
637 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
638 | PyObject* tup = PyTuple_New(2); | |
639 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); | |
640 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); | |
641 | wxPyEndBlockThreads(blocked); | |
642 | return tup; | |
643 | } | |
644 | } | |
645 | ||
646 | ||
647 | // get the margins around each item | |
648 | wxPoint GetMargins() const; | |
649 | ||
650 | // get the background colour of selected cells | |
651 | const wxColour& GetSelectionBackground() const; | |
652 | ||
653 | ||
654 | // set the number of items to be shown in the control | |
655 | // | |
656 | // this is just a synonym for wxVScrolledWindow::SetLineCount() | |
657 | void SetItemCount(size_t count); | |
658 | ||
659 | // delete all items from the control | |
660 | void Clear(); | |
661 | ||
662 | // set the selection to the specified item, if it is wxNOT_FOUND the | |
663 | // selection is unset | |
664 | // | |
665 | // this function is only valid for the single selection listboxes | |
666 | void SetSelection(int selection); | |
667 | ||
668 | // selects or deselects the specified item which must be valid (i.e. not | |
669 | // equal to wxNOT_FOUND) | |
670 | // | |
671 | // return True if the items selection status has changed or False | |
672 | // otherwise | |
673 | // | |
674 | // this function is only valid for the multiple selection listboxes | |
675 | bool Select(size_t item, bool select = true); | |
676 | ||
677 | // selects the items in the specified range whose end points may be given | |
678 | // in any order | |
679 | // | |
680 | // return True if any items selection status has changed, False otherwise | |
681 | // | |
682 | // this function is only valid for the single selection listboxes | |
683 | bool SelectRange(size_t from, size_t to); | |
684 | ||
685 | // toggle the selection of the specified item (must be valid) | |
686 | // | |
687 | // this function is only valid for the multiple selection listboxes | |
688 | void Toggle(size_t item); | |
689 | ||
690 | // select all items in the listbox | |
691 | // | |
692 | // the return code indicates if any items were affected by this operation | |
693 | // (True) or if nothing has changed (False) | |
694 | bool SelectAll(); | |
695 | ||
696 | // unselect all items in the listbox | |
697 | // | |
698 | // the return code has the same meaning as for SelectAll() | |
699 | bool DeselectAll(); | |
700 | ||
701 | // set the margins: horizontal margin is the distance between the window | |
702 | // border and the item contents while vertical margin is half of the | |
703 | // distance between items | |
704 | // | |
705 | // by default both margins are 0 | |
706 | void SetMargins(const wxPoint& pt); | |
707 | %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y)); | |
708 | ||
709 | // change the background colour of the selected cells | |
710 | void SetSelectionBackground(const wxColour& col); | |
711 | ||
712 | }; | |
713 | ||
714 | ||
715 | //--------------------------------------------------------------------------- | |
716 | // wxHtmlListBox | |
717 | ||
718 | %{ | |
719 | #include <wx/htmllbox.h> | |
720 | %} | |
721 | ||
722 | // First, the C++ version | |
723 | %{ | |
724 | class wxPyHtmlListBox : public wxHtmlListBox | |
725 | { | |
726 | DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox) | |
727 | public: | |
728 | wxPyHtmlListBox() : wxHtmlListBox() {} | |
729 | ||
730 | wxPyHtmlListBox(wxWindow *parent, | |
731 | wxWindowID id = wxID_ANY, | |
732 | const wxPoint& pos = wxDefaultPosition, | |
733 | const wxSize& size = wxDefaultSize, | |
734 | long style = 0, | |
735 | const wxString& name = wxPyVListBoxNameStr) | |
736 | : wxHtmlListBox(parent, id, pos, size, style, name) | |
737 | {} | |
738 | ||
739 | // Overridable virtuals | |
740 | ||
741 | // this method must be implemented in the derived class and should return | |
742 | // the body (i.e. without <html>) of the HTML for the given item | |
743 | DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem); | |
744 | ||
745 | // this function may be overridden to decorate HTML returned by OnGetItem() | |
746 | DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup); | |
747 | ||
748 | // TODO: | |
749 | // // this method allows to customize the selection appearance: it may be used | |
750 | // // to specify the colour of the text which normally has the given colour | |
751 | // // colFg when it is inside the selection | |
752 | // // | |
753 | // // by default, the original colour is not used at all and all text has the | |
754 | // // same (default for this system) colour inside selection | |
755 | // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const; | |
756 | ||
757 | // // this is the same as GetSelectedTextColour() but allows to customize the | |
758 | // // background colour -- this is even more rarely used as you can change it | |
759 | // // globally using SetSelectionBackground() | |
760 | // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const; | |
761 | ||
762 | ||
763 | PYPRIVATE; | |
764 | }; | |
765 | ||
766 | ||
767 | IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox) | |
768 | ||
769 | IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem); | |
770 | IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup); | |
771 | ||
772 | %} | |
773 | ||
774 | ||
775 | ||
776 | // Now define this class for SWIG | |
777 | ||
778 | ||
779 | // wxHtmlListBox is a listbox whose items are wxHtmlCells | |
780 | MustHaveApp(wxPyHtmlListBox); | |
781 | %rename(HtmlListBox) wxPyHtmlListBox; | |
782 | class wxPyHtmlListBox : public wxPyVListBox | |
783 | { | |
784 | public: | |
785 | %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)" | |
786 | %pythonAppend wxPyHtmlListBox() "" | |
787 | ||
788 | ||
789 | // normal constructor which calls Create() internally | |
790 | wxPyHtmlListBox(wxWindow *parent, | |
791 | wxWindowID id = wxID_ANY, | |
792 | const wxPoint& pos = wxDefaultPosition, | |
793 | const wxSize& size = wxDefaultSize, | |
794 | long style = 0, | |
795 | const wxString& name = wxPyVListBoxNameStr); | |
796 | ||
797 | %RenameCtor(PreHtmlListBox, wxPyHtmlListBox()); | |
798 | ||
799 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
800 | ||
801 | bool Create(wxWindow *parent, | |
802 | wxWindowID id = wxID_ANY, | |
803 | const wxPoint& pos = wxDefaultPosition, | |
804 | const wxSize& size = wxDefaultSize, | |
805 | long style = 0, | |
806 | const wxString& name = wxPyVListBoxNameStr); | |
807 | ||
808 | ||
809 | void RefreshAll(); | |
810 | void SetItemCount(size_t count); | |
811 | ||
812 | // retrieve the file system used by the wxHtmlWinParser: if you use | |
813 | // relative paths in your HTML, you should use its ChangePathTo() method | |
814 | wxFileSystem& GetFileSystem(); | |
815 | }; | |
816 | ||
817 | ||
818 | ||
819 | //--------------------------------------------------------------------------- | |
820 | ||
821 | %init %{ | |
822 | // Map renamed classes back to their common name for OOR | |
823 | wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox"); | |
824 | wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox"); | |
825 | wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow"); | |
826 | %} | |
827 | ||
828 | //--------------------------------------------------------------------------- |