]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_vscroll.i
added wxDialog::GetParentForModalDialog() and use it to try to always create modal...
[wxWidgets.git] / wxPython / src / _vscroll.i
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 #include <wx/vscroll.h>
22 %}
23
24 %newgroup;
25 //---------------------------------------------------------------------------
26 // Base classes. I don't expect that these will ever be used directly from
27 // Python, (especially being derived from) so I own't worry about making their
28 // virutals overridable. They're just defined here for their public methods.
29
30
31
32 // Provides all base common scroll calculations needed for either orientation,
33 // automatic scrollbar functionality, saved scroll positions, functionality
34 // for changing the target window to be scrolled, as well as defining all
35 // required virtual functions that need to be implemented for any orientation
36 // specific work.
37
38 class wxVarScrollHelperBase
39 {
40 public:
41
42 // wxVarScrollHelperBase(wxWindow *winToScroll); *** ABC, can't instantiate
43 // virtual ~wxVarScrollHelperBase();
44
45
46 // with physical scrolling on, the device origin is changed properly when
47 // a wxPaintDC is prepared, children are actually moved and laid out
48 // properly, and the contents of the window (pixels) are actually moved
49 void EnablePhysicalScrolling(bool scrolling = true);
50
51 // wxNOT_FOUND if none, i.e. if it is below the last item
52 virtual int HitTest(wxCoord coord) const;
53
54 // recalculate all our parameters and redisplay all units
55 virtual void RefreshAll();
56
57
58 // get the first currently visible unit
59 size_t GetVisibleBegin() const;
60
61 // get the last currently visible unit
62 size_t GetVisibleEnd() const;
63
64 // is this unit currently visible?
65 bool IsVisible(size_t unit) const;
66
67 // translate between scrolled and unscrolled coordinates
68 int CalcScrolledPosition(int coord) const;
69 int CalcUnscrolledPosition(int coord) const;
70
71 // update the thumb size shown by the scrollbar
72 virtual void UpdateScrollbar();
73 void RemoveScrollbar();
74
75 // Normally the wxScrolledWindow will scroll itself, but in some rare
76 // occasions you might want it to scroll [part of] another window (e.g. a
77 // child of it in order to scroll only a portion the area between the
78 // scrollbars (spreadsheet: only cell area will move).
79 virtual void SetTargetWindow(wxWindow *target);
80 virtual wxWindow *GetTargetWindow() const;
81
82
83 // these functions must be overidden in the derived class to return
84 // orientation specific data (e.g. the width for vertically scrolling
85 // derivatives in the case of GetOrientationTargetSize())
86 virtual int GetOrientationTargetSize() const; // = 0;
87 virtual int GetNonOrientationTargetSize() const; // = 0;
88 virtual wxOrientation GetOrientation() const; // = 0;
89 };
90
91
92
93
94
95 // Provides public API functions targeted for vertical-specific scrolling,
96 // wrapping the functionality of wxVarScrollHelperBase.
97
98 class wxVarVScrollHelper : public wxVarScrollHelperBase
99 {
100 public:
101
102 // wxVarVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
103
104 void SetRowCount(size_t rowCount);
105 bool ScrollToRow(size_t row);
106
107 virtual bool ScrollRows(int rows);
108 virtual bool ScrollRowPages(int pages);
109
110 virtual void RefreshRow(size_t row);
111 virtual void RefreshRows(size_t from, size_t to);
112
113 virtual int HitTest(wxCoord y) const;
114
115
116 size_t GetRowCount() const;
117 size_t GetVisibleRowsBegin() const;
118 size_t GetVisibleRowsEnd() const;
119 bool IsRowVisible(size_t row) const;
120
121 virtual int GetOrientationTargetSize() const;
122 virtual int GetNonOrientationTargetSize() const;
123 virtual wxOrientation GetOrientation() const;
124 };
125
126
127
128
129
130 // Provides public API functions targeted for horizontal-specific scrolling,
131 // wrapping the functionality of wxVarScrollHelperBase.
132
133 class wxVarHScrollHelper : public wxVarScrollHelperBase
134 {
135 public:
136
137 // wxVarHScrollHelper(wxWindow *winToScroll) *** ABC, can't instantiate
138
139 void SetColumnCount(size_t columnCount);
140
141 bool ScrollToColumn(size_t column);
142 virtual bool ScrollColumns(int columns);
143 virtual bool ScrollColumnPages(int pages);
144
145 virtual void RefreshColumn(size_t column);
146 virtual void RefreshColumns(size_t from, size_t to);
147 virtual int HitTest(wxCoord x) const;
148
149
150 size_t GetColumnCount() const;
151 size_t GetVisibleColumnsBegin() const;
152 size_t GetVisibleColumnsEnd() const;
153 bool IsColumnVisible(size_t column) const;
154
155
156 virtual int GetOrientationTargetSize() const;
157 virtual int GetNonOrientationTargetSize() const;
158 virtual wxOrientation GetOrientation() const;
159
160 };
161
162
163
164
165
166
167 // Provides public API functions targeted at functions with similar names in
168 // both wxVScrollHelper and wxHScrollHelper so class scope doesn't need to be
169 // specified (since we are using multiple inheritance). It also provides
170 // functions to make changing values for both orientations at the same time
171 // easier.
172
173 class wxVarHVScrollHelper : public wxVarVScrollHelper,
174 public wxVarHScrollHelper
175 {
176 public:
177
178 // wxVarHVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
179
180
181 // set the number of units the window contains for each axis: the derived
182 // class must provide the widths and heights for all units with indices up
183 // to each of the one given here in its OnGetColumnWidth() and
184 // OnGetRowHeight()
185 void SetRowColumnCount(size_t rowCount, size_t columnCount);
186
187
188 // with physical scrolling on, the device origin is changed properly when
189 // a wxPaintDC is prepared, children are actually moved and laid out
190 // properly, and the contents of the window (pixels) are actually moved
191 void EnablePhysicalScrolling(bool vscrolling = true, bool hscrolling = true);
192
193
194 // scroll to the specified row/column: it will become the first visible
195 // cell in the window
196 //
197 // return true if we scrolled the window, false if nothing was done
198 // bool ScrollToRowColumn(size_t row, size_t column);
199 bool ScrollToRowColumn(const wxPosition &pos);
200
201 // redraw the specified cell
202 // virtual void RefreshRowColumn(size_t row, size_t column);
203 virtual void RefreshRowColumn(const wxPosition &pos);
204
205 // redraw the specified regions (inclusive). If the target window for
206 // both orientations is the same the rectangle of cells is refreshed; if
207 // the target windows differ the entire client size opposite the
208 // orientation direction is refreshed between the specified limits
209 // virtual void RefreshRowsColumns(size_t fromRow, size_t toRow,
210 // size_t fromColumn, size_t toColumn);
211 virtual void RefreshRowsColumns(const wxPosition& from,
212 const wxPosition& to);
213
214 // Override wxPanel::HitTest to use our version
215 // virtual wxPosition HitTest(wxCoord x, wxCoord y) const;
216 virtual wxPosition HitTest(const wxPoint &pos) const;
217
218 // replacement implementation of wxWindow::Layout virtual method. To
219 // properly forward calls to wxWindow::Layout use
220 // WX_FORWARD_TO_SCROLL_HELPER() derived class. We use this version to
221 // call both base classes' ScrollLayout()
222 bool ScrollLayout();
223
224 // get the number of units this window contains (previously set by
225 // Set[Column/Row/RowColumn/Unit]Count())
226 wxSize GetRowColumnCount() const;
227
228 // get the first currently visible units
229 wxPosition GetVisibleBegin() const;
230 wxPosition GetVisibleEnd() const;
231
232 // is this cell currently visible?
233 // bool IsVisible(size_t row, size_t column) const;
234 bool IsVisible(const wxPosition &pos) const;
235 };
236
237
238
239
240 //---------------------------------------------------------------------------
241 // wxVScrolledWindow
242
243
244
245 // First, the C++ version that can redirect to overridden Python methods
246 %{
247 class wxPyVScrolledWindow : public wxVScrolledWindow
248 {
249 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow)
250 public:
251 wxPyVScrolledWindow() : wxVScrolledWindow() {}
252
253 wxPyVScrolledWindow(wxWindow *parent,
254 wxWindowID id = wxID_ANY,
255 const wxPoint& pos = wxDefaultPosition,
256 const wxSize& size = wxDefaultSize,
257 long style = 0,
258 const wxString& name = wxPyPanelNameStr)
259 : wxVScrolledWindow(parent, id, pos, size, style, name)
260 {}
261
262 // Overridable virtuals
263
264 // this function must be overridden in the derived class and it should
265 // return the height of the given line in pixels
266 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
267 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight); // old name
268
269 // this function doesn't have to be overridden but it may be useful to do
270 // it if calculating the lines heights is a relatively expensive operation
271 // as it gives the user code a possibility to calculate several of them at
272 // once
273 //
274 // OnGetLinesHint() is normally called just before OnGetRowHeight() but you
275 // shouldn't rely on the latter being called for all lines in the interval
276 // specified here. It is also possible that OnGetRowHeight() will be
277 // called for the lines outside of this interval, so this is really just a
278 // hint, not a promise.
279 //
280 // finally note that lineMin is inclusive, while lineMax is exclusive, as
281 // usual
282 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
283 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint); // old name
284
285 // when the number of lines changes, we try to estimate the total height
286 // of all lines which is a rather expensive operation in terms of lines
287 // access, so if the user code may estimate the average height
288 // better/faster than we do, it should override this function to implement
289 // its own logic
290 //
291 // this function should return the best guess for the total height it may
292 // make
293 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
294
295
296 // Also expose some other interesting protected methods
297
298
299 // get the total height of the lines between lineMin (inclusive) and
300 // lineMax (exclusive)
301 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
302 { return wxVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
303
304
305 PYPRIVATE;
306 };
307
308 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
309
310 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowHeight);
311 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
312 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowsHeightHint);
313 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
314
315 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
316 %}
317
318
319
320
321
322 // Now define this class for SWIG
323
324 /*
325 In the name of this class, "V" may stand for "variable" because it can be
326 used for scrolling lines of variable heights; "virtual" because it is not
327 necessary to know the heights of all lines in advance -- only those which
328 are shown on the screen need to be measured; or, even, "vertical" because
329 this class only supports scrolling in one direction currently (this could
330 and probably will change in the future however).
331
332 In any case, this is a generalization of the wxScrolledWindow class which
333 can be only used when all lines have the same height. It lacks some other
334 wxScrolledWindow features however, notably it currently lacks support for
335 horizontal scrolling; it can't scroll another window nor only a rectangle
336 of the window and not its entire client area.
337 */
338
339 MustHaveApp(wxPyVScrolledWindow);
340
341 %rename(VScrolledWindow) wxPyVScrolledWindow;
342
343 class wxPyVScrolledWindow : public wxPanel,
344 public wxVarVScrollHelper
345 {
346 public:
347 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow)
348 %pythonAppend wxPyVScrolledWindow() ""
349
350
351 wxPyVScrolledWindow(wxWindow *parent,
352 wxWindowID id = wxID_ANY,
353 const wxPoint& pos = wxDefaultPosition,
354 const wxSize& size = wxDefaultSize,
355 long style = 0,
356 const wxString& name = wxPyPanelNameStr);
357
358 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
359
360 void _setCallbackInfo(PyObject* self, PyObject* _class);
361
362 bool Create(wxWindow *parent,
363 wxWindowID id = wxID_ANY,
364 const wxPoint& pos = wxDefaultPosition,
365 const wxSize& size = wxDefaultSize,
366 long style = 0,
367 const wxString& name = wxPyPanelNameStr);
368
369
370 // get the total height of the lines between lineMin (inclusive) and
371 // lineMax (exclusive)
372 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
373 %pythoncode { GetLinesHeight = wx._deprecated(GetRowsHeight,
374 "Use GetRowsHeight instead.") }
375
376 virtual wxCoord EstimateTotalHeight() const;
377
378 int HitTest(const wxPoint& pt) const;
379
380
381 // Deprecated wrappers for methods whose name changed when adding the H
382 // classes. I just put them here instead of wrapping the
383 // wxVarVScrollLegacyAdaptor class.
384 %pythoncode {
385 def GetFirstVisibleLine(self):
386 return self.GetVisibleRowsBegin()
387 GetFirstVisibleLine = wx._deprecated(GetFirstVisibleLine, "Use GetVisibleRowsBegin instead" )
388
389 def GetLastVisibleLine(self):
390 return self.GetVisibleRowsEnd() - 1
391 GetLastVisibleLine = wx._deprecated(GetLastVisibleLine, "Use GetVisibleRowsEnd instead")
392
393 def GetLineCount(self):
394 return self.GetRowCount()
395 GetLineCount = wx._deprecated(GetLineCount, "Use GetRowCount instead")
396
397 def SetLineCount(self, count):
398 self.SetRowCount(count)
399 SetLineCount = wx._deprecated(SetLineCount, "Use SetRowCount instead")
400
401 def RefreshLine(self, line):
402 self.RefreshRow(line)
403 RefreshLine = wx._deprecated(RefreshLine, "Use RefreshRow instead")
404
405 def RefreshLines(self, frm, to):
406 self.RefreshRows(frm, to)
407 RefreshLines = wx._deprecated(RefreshLines, "Use RefreshRows instead")
408
409 def ScrollToLine(self, line):
410 return self.ScrollToRow(line)
411 ScrollToLine = wx._deprecated(ScrollToLine, "Use RefreshRow instead")
412
413 def ScrollLines(self, lines):
414 return self.ScrollRows(lines)
415 ScrollLines = wx._deprecated(ScrollLines, "Use ScrollRows instead")
416
417 def ScrollPages(self, pages):
418 return self.ScrollRowPages(pages)
419 ScrollPages = wx._deprecated(ScrollPages, "Use ScrollRowPages instead")
420 }
421
422 };
423
424
425
426 //---------------------------------------------------------------------------
427 // wxHScrolledWindow
428
429
430 // First, the C++ version that can redirect to overridden Python methods
431 %{
432 class wxPyHScrolledWindow : public wxHScrolledWindow
433 {
434 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
435 public:
436 wxPyHScrolledWindow() : wxHScrolledWindow() {}
437
438 wxPyHScrolledWindow(wxWindow *parent,
439 wxWindowID id = wxID_ANY,
440 const wxPoint& pos = wxDefaultPosition,
441 const wxSize& size = wxDefaultSize,
442 long style = 0,
443 const wxString& name = wxPyPanelNameStr)
444 : wxHScrolledWindow(parent, id, pos, size, style, name)
445 {}
446
447 // Overridable virtuals
448 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
449 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
450 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
451
452 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
453 { return wxHScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
454
455 PYPRIVATE;
456 };
457
458 IMPLEMENT_ABSTRACT_CLASS(wxPyHScrolledWindow, wxHScrolledWindow);
459
460 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnWidth);
461 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnsWidthHint);
462 IMP_PYCALLBACK_COORD_const (wxPyHScrolledWindow, wxHScrolledWindow, EstimateTotalWidth);
463
464 %}
465
466
467
468 // Now define this class for SWIG
469
470 // In the name of this class, "H" stands for "horizontal" because it can be
471 // used for scrolling columns of variable widths. It is not necessary to know
472 // the widths of all columns in advance -- only those which are shown on the
473 // screen need to be measured.
474
475 // This is a generalization of the wxScrolledWindow class which can be only
476 // used when all columns have the same width. It lacks some other
477 // wxScrolledWindow features however, notably it can't scroll only a rectangle
478 // of the window and not its entire client area.
479
480 MustHaveApp(wxPyHScrolledWindow);
481
482 %rename(HScrolledWindow) wxPyHScrolledWindow;
483
484 class wxPyHScrolledWindow : public wxPanel,
485 public wxVarHScrollHelper
486 {
487 public:
488 %pythonAppend wxPyHScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HScrolledWindow)
489 %pythonAppend wxPyHScrolledWindow() ""
490
491
492 wxPyHScrolledWindow(wxWindow *parent,
493 wxWindowID id = wxID_ANY,
494 const wxPoint& pos = wxDefaultPosition,
495 const wxSize& size = wxDefaultSize,
496 long style = 0,
497 const wxString& name = wxPyPanelNameStr);
498
499 %RenameCtor(PreHScrolledWindow, wxPyHScrolledWindow());
500
501 void _setCallbackInfo(PyObject* self, PyObject* _class);
502
503 bool Create(wxWindow *parent,
504 wxWindowID id = wxID_ANY,
505 const wxPoint& pos = wxDefaultPosition,
506 const wxSize& size = wxDefaultSize,
507 long style = 0,
508 const wxString& name = wxPyPanelNameStr);
509
510
511 int HitTest(const wxPoint& pt) const;
512 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
513 wxCoord EstimateTotalWidth() const;
514 };
515
516
517
518 //---------------------------------------------------------------------------
519 // wxHVScrolledWindow
520
521
522
523 // First, the C++ version that can redirect to overridden Python methods
524 %{
525 class wxPyHVScrolledWindow : public wxHVScrolledWindow
526 {
527 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
528 public:
529 wxPyHVScrolledWindow() : wxHVScrolledWindow() {}
530
531 wxPyHVScrolledWindow(wxWindow *parent,
532 wxWindowID id = wxID_ANY,
533 const wxPoint& pos = wxDefaultPosition,
534 const wxSize& size = wxDefaultSize,
535 long style = 0,
536 const wxString& name = wxPyPanelNameStr)
537 : wxHVScrolledWindow(parent, id, pos, size, style, name)
538 {}
539
540 // Overridable virtuals
541 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
542 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
543 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
544
545 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
546 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
547 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
548
549 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
550 { return wxHVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
551
552 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
553 { return wxHVScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
554
555 PYPRIVATE;
556 };
557
558 IMPLEMENT_ABSTRACT_CLASS(wxPyHVScrolledWindow, wxHVScrolledWindow);
559
560 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowHeight);
561 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowsHeightHint);
562 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalHeight);
563
564 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnWidth);
565 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnsWidthHint);
566 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalWidth);
567
568 %}
569
570
571
572
573 // Now define this class for SWIG
574
575 // This window inherits all functionality of both vertical and horizontal
576 // scrolled windows automatically handling everything needed to scroll both
577 // axis simultaneously.
578
579 MustHaveApp(wxPyHVScrolledWindow);
580
581 %rename(HVScrolledWindow) wxPyHVScrolledWindow;
582
583 class wxPyHVScrolledWindow : public wxPanel,
584 public wxVarHVScrollHelper
585 {
586 public:
587 %pythonAppend wxPyHVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HVScrolledWindow)
588 %pythonAppend wxPyHVScrolledWindow() ""
589
590
591 wxPyHVScrolledWindow(wxWindow *parent,
592 wxWindowID id = wxID_ANY,
593 const wxPoint& pos = wxDefaultPosition,
594 const wxSize& size = wxDefaultSize,
595 long style = 0,
596 const wxString& name = wxPyPanelNameStr);
597
598 %RenameCtor(PreHVScrolledWindow, wxPyHVScrolledWindow());
599
600 void _setCallbackInfo(PyObject* self, PyObject* _class);
601
602 bool Create(wxWindow *parent,
603 wxWindowID id = wxID_ANY,
604 const wxPoint& pos = wxDefaultPosition,
605 const wxSize& size = wxDefaultSize,
606 long style = 0,
607 const wxString& name = wxPyPanelNameStr);
608
609
610 wxPosition HitTest(const wxPoint& pt) const;
611
612 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
613 wxCoord EstimateTotalHeight() const;
614
615 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
616 wxCoord EstimateTotalWidth() const;
617 };
618
619
620
621 //---------------------------------------------------------------------------
622 //---------------------------------------------------------------------------
623 // wxVListBox
624
625 %{
626 #include <wx/vlbox.h>
627 %}
628
629 MAKE_CONST_WXSTRING(VListBoxNameStr);
630
631
632 // First, the C++ version
633 %{
634 class wxPyVListBox : public wxVListBox
635 {
636 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
637 public:
638 wxPyVListBox() : wxVListBox() {}
639
640 wxPyVListBox(wxWindow *parent,
641 wxWindowID id = wxID_ANY,
642 const wxPoint& pos = wxDefaultPosition,
643 const wxSize& size = wxDefaultSize,
644 long style = 0,
645 const wxString& name = wxPyVListBoxNameStr)
646 : wxVListBox(parent, id, pos, size, style, name)
647 {}
648
649 // Overridable virtuals
650
651 // the derived class must implement this function to actually draw the item
652 // with the given index on the provided DC
653 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
654 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
655
656
657 // the derived class must implement this method to return the height of the
658 // specified item
659 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
660 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
661
662
663 // this method may be used to draw separators between the lines; note that
664 // the rectangle may be modified, typically to deflate it a bit before
665 // passing to OnDrawItem()
666 //
667 // the base class version doesn't do anything
668 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
669 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
670
671
672 // this method is used to draw the items background and, maybe, a border
673 // around it
674 //
675 // the base class version implements a reasonable default behaviour which
676 // consists in drawing the selected item with the standard background
677 // colour and drawing a border around the item if it is either selected or
678 // current
679 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
680 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
681
682
683 PYPRIVATE;
684 };
685
686 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
687
688 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
689 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
690 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
691 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
692
693 %}
694
695
696
697 // Now define this class for SWIG
698
699 /*
700 This class has two main differences from a regular listbox: it can have an
701 arbitrarily huge number of items because it doesn't store them itself but
702 uses OnDrawItem() callback to draw them and its items can have variable
703 height as determined by OnMeasureItem().
704
705 It emits the same events as wxListBox and the same event macros may be used
706 with it.
707 */
708 MustHaveApp(wxPyVListBox);
709
710 %rename(VListBox) wxPyVListBox;
711 class wxPyVListBox : public wxPyVScrolledWindow
712 {
713 public:
714 %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox)
715 %pythonAppend wxPyVListBox() ""
716
717
718 wxPyVListBox(wxWindow *parent,
719 wxWindowID id = wxID_ANY,
720 const wxPoint& pos = wxDefaultPosition,
721 const wxSize& size = wxDefaultSize,
722 long style = 0,
723 const wxString& name = wxPyVListBoxNameStr);
724
725 %RenameCtor(PreVListBox, wxPyVListBox());
726
727 void _setCallbackInfo(PyObject* self, PyObject* _class);
728
729 bool Create(wxWindow *parent,
730 wxWindowID id = wxID_ANY,
731 const wxPoint& pos = wxDefaultPosition,
732 const wxSize& size = wxDefaultSize,
733 long style = 0,
734 const wxString& name = wxPyVListBoxNameStr);
735
736 // get the number of items in the control
737 size_t GetItemCount() const;
738
739 // does this control use multiple selection?
740 bool HasMultipleSelection() const;
741
742 // get the currently selected item or wxNOT_FOUND if there is no selection
743 //
744 // this method is only valid for the single selection listboxes
745 int GetSelection() const;
746
747 // is this item the current one?
748 bool IsCurrent(size_t item) const;
749
750 // is this item selected?
751 bool IsSelected(size_t item) const;
752
753 // get the number of the selected items (maybe 0)
754 //
755 // this method is valid for both single and multi selection listboxes
756 size_t GetSelectedCount() const;
757
758 %extend {
759 // get the first selected item, returns wxNOT_FOUND if none
760 //
761 // cookie is an opaque parameter which should be passed to
762 // GetNextSelected() later
763 //
764 // this method is only valid for the multi selection listboxes
765 //int GetFirstSelected(unsigned long& cookie) const;
766 PyObject* GetFirstSelected() {
767 unsigned long cookie = 0;
768 int selected = self->GetFirstSelected(cookie);
769 wxPyBlock_t blocked = wxPyBeginBlockThreads();
770 PyObject* tup = PyTuple_New(2);
771 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
772 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
773 wxPyEndBlockThreads(blocked);
774 return tup;
775 }
776
777 // get next selection item, return wxNOT_FOUND if no more
778 //
779 // cookie must be the same parameter that was passed to GetFirstSelected()
780 // before
781 //
782 // this method is only valid for the multi selection listboxes
783 // int GetNextSelected(unsigned long& cookie) const;
784 PyObject* GetNextSelected(unsigned long cookie) {
785 int selected = self->GetNextSelected(cookie);
786 wxPyBlock_t blocked = wxPyBeginBlockThreads();
787 PyObject* tup = PyTuple_New(2);
788 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
789 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
790 wxPyEndBlockThreads(blocked);
791 return tup;
792 }
793 }
794
795
796 // get the margins around each item
797 wxPoint GetMargins() const;
798
799 // get the background colour of selected cells
800 const wxColour& GetSelectionBackground() const;
801
802
803 // set the number of items to be shown in the control
804 //
805 // this is just a synonym for wxVScrolledWindow::SetLineCount()
806 void SetItemCount(size_t count);
807
808 // delete all items from the control
809 void Clear();
810
811 // set the selection to the specified item, if it is wxNOT_FOUND the
812 // selection is unset
813 //
814 // this function is only valid for the single selection listboxes
815 void SetSelection(int selection);
816
817 // selects or deselects the specified item which must be valid (i.e. not
818 // equal to wxNOT_FOUND)
819 //
820 // return True if the items selection status has changed or False
821 // otherwise
822 //
823 // this function is only valid for the multiple selection listboxes
824 bool Select(size_t item, bool select = true);
825
826 // selects the items in the specified range whose end points may be given
827 // in any order
828 //
829 // return True if any items selection status has changed, False otherwise
830 //
831 // this function is only valid for the single selection listboxes
832 bool SelectRange(size_t from, size_t to);
833
834 // toggle the selection of the specified item (must be valid)
835 //
836 // this function is only valid for the multiple selection listboxes
837 void Toggle(size_t item);
838
839 // select all items in the listbox
840 //
841 // the return code indicates if any items were affected by this operation
842 // (True) or if nothing has changed (False)
843 bool SelectAll();
844
845 // unselect all items in the listbox
846 //
847 // the return code has the same meaning as for SelectAll()
848 bool DeselectAll();
849
850 // set the margins: horizontal margin is the distance between the window
851 // border and the item contents while vertical margin is half of the
852 // distance between items
853 //
854 // by default both margins are 0
855 void SetMargins(const wxPoint& pt);
856 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
857
858 // change the background colour of the selected cells
859 void SetSelectionBackground(const wxColour& col);
860
861 // refreshes only the selected items
862 void RefreshSelected();
863
864 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
865 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
866
867 %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`");
868 %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`");
869 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
870 %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`");
871 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
872 %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`");
873 };
874
875
876 //---------------------------------------------------------------------------
877 // wxHtmlListBox
878
879 %{
880 #include <wx/htmllbox.h>
881 %}
882
883 // First, the C++ version
884 %{
885 class wxPyHtmlListBox : public wxHtmlListBox
886 {
887 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
888 public:
889 wxPyHtmlListBox() : wxHtmlListBox() {}
890
891 wxPyHtmlListBox(wxWindow *parent,
892 wxWindowID id = wxID_ANY,
893 const wxPoint& pos = wxDefaultPosition,
894 const wxSize& size = wxDefaultSize,
895 long style = 0,
896 const wxString& name = wxPyVListBoxNameStr)
897 : wxHtmlListBox(parent, id, pos, size, style, name)
898 {}
899
900 // Overridable virtuals
901
902 // this method must be implemented in the derived class and should return
903 // the body (i.e. without <html>) of the HTML for the given item
904 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
905
906 // this function may be overridden to decorate HTML returned by OnGetItem()
907 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
908
909 // These are from wxVListBox
910 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
911 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
912
913 // TODO:
914 // // this method allows to customize the selection appearance: it may be used
915 // // to specify the colour of the text which normally has the given colour
916 // // colFg when it is inside the selection
917 // //
918 // // by default, the original colour is not used at all and all text has the
919 // // same (default for this system) colour inside selection
920 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
921
922 // // this is the same as GetSelectedTextColour() but allows to customize the
923 // // background colour -- this is even more rarely used as you can change it
924 // // globally using SetSelectionBackground()
925 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
926
927
928 // This method may be overriden to handle clicking on a link in
929 // the listbox. By default, clicking links is ignored.
930 virtual void OnLinkClicked(size_t n,
931 const wxHtmlLinkInfo& link);
932
933 PYPRIVATE;
934 };
935
936
937 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
938
939 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
940 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
941 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
942 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
943
944
945 void wxPyHtmlListBox::OnLinkClicked(size_t n,
946 const wxHtmlLinkInfo& link) {
947 bool found;
948 wxPyBlock_t blocked = wxPyBeginBlockThreads();
949 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
950 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
951 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
952 Py_DECREF(obj);
953 }
954 wxPyEndBlockThreads(blocked);
955 if (! found)
956 wxPyHtmlListBox::OnLinkClicked(n, link);
957 }
958
959 %}
960
961
962
963 // Now define this class for SWIG
964
965
966 // wxHtmlListBox is a listbox whose items are wxHtmlCells
967 MustHaveApp(wxPyHtmlListBox);
968 %rename(HtmlListBox) wxPyHtmlListBox;
969 class wxPyHtmlListBox : public wxPyVListBox
970 {
971 public:
972 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox)
973 %pythonAppend wxPyHtmlListBox() ""
974
975
976 // normal constructor which calls Create() internally
977 wxPyHtmlListBox(wxWindow *parent,
978 wxWindowID id = wxID_ANY,
979 const wxPoint& pos = wxDefaultPosition,
980 const wxSize& size = wxDefaultSize,
981 long style = 0,
982 const wxString& name = wxPyVListBoxNameStr);
983
984 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
985
986 void _setCallbackInfo(PyObject* self, PyObject* _class);
987
988 bool Create(wxWindow *parent,
989 wxWindowID id = wxID_ANY,
990 const wxPoint& pos = wxDefaultPosition,
991 const wxSize& size = wxDefaultSize,
992 long style = 0,
993 const wxString& name = wxPyVListBoxNameStr);
994
995
996 void RefreshAll();
997 void SetItemCount(size_t count);
998
999 // retrieve the file system used by the wxHtmlWinParser: if you use
1000 // relative paths in your HTML, you should use its ChangePathTo() method
1001 wxFileSystem& GetFileSystem();
1002
1003 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
1004
1005 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
1006 };
1007
1008
1009
1010 //---------------------------------------------------------------------------
1011
1012 %{
1013 const wxArrayString wxPyEmptyStringArray;
1014 %}
1015 MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr);
1016
1017
1018 enum {
1019 wxHLB_DEFAULT_STYLE,
1020 wxHLB_MULTIPLE
1021 };
1022
1023 MustHaveApp(wxSimpleHtmlListBox);
1024
1025 class wxSimpleHtmlListBox : public wxPyHtmlListBox,
1026 public wxItemContainer
1027 {
1028 public:
1029 %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)";
1030 %pythonAppend wxSimpleHtmlListBox() "";
1031
1032 wxSimpleHtmlListBox(wxWindow *parent,
1033 wxWindowID id = -1,
1034 const wxPoint& pos = wxDefaultPosition,
1035 const wxSize& size = wxDefaultSize,
1036 const wxArrayString& choices = wxPyEmptyStringArray,
1037 long style = wxHLB_DEFAULT_STYLE,
1038 const wxValidator& validator = wxDefaultValidator,
1039 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1040 %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox());
1041
1042 bool Create(wxWindow *parent,
1043 wxWindowID id = -1,
1044 const wxPoint& pos = wxDefaultPosition,
1045 const wxSize& size= wxDefaultSize,
1046 const wxArrayString& choices = wxPyEmptyStringArray,
1047 long style = wxHLB_DEFAULT_STYLE,
1048 const wxValidator& validator = wxDefaultValidator,
1049 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1050 };
1051
1052 //---------------------------------------------------------------------------
1053
1054 %init %{
1055 // Map renamed classes back to their common name for OOR
1056 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
1057 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
1058 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
1059 %}
1060
1061 //---------------------------------------------------------------------------