]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_vscroll.i
REWRITE wxStringBase::append and wxString::Replace.
[wxWidgets.git] / wxPython / src / _vscroll.i
CommitLineData
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%{
36class wxPyVScrolledWindow : public wxVScrolledWindow
37{
38 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow);
39public:
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
98
99 PYPRIVATE;
100};
101
102IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
103
104IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
105IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
106IMP_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
ab1f7d2a
RD
128MustHaveApp(wxPyVScrolledWindow);
129
1b8c7ba6
RD
130%rename(VScrolledWindow) wxPyVScrolledWindow;
131class wxPyVScrolledWindow : public wxPanel
3628e088
RD
132{
133public:
2b9048c5
RD
134 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
135 %pythonAppend wxPyVScrolledWindow() ""
d14a1e28 136
3628e088
RD
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
1b8c7ba6 145 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
3628e088
RD
146
147 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
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 //
dd9f7fea 165 // return True if we scrolled the window, False if nothing was done
3628e088
RD
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
1b8c7ba6 180 %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const);
3628e088
RD
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 GetFirstVisibleLine() const;
193
194 // get the last currently visible line
195 size_t GetLastVisibleLine() const;
196
197 // is this line currently visible?
198 bool IsVisible(size_t line) const;
199
200};
201
202//---------------------------------------------------------------------------
203// wxVListBox
204
205%{
206#include <wx/vlbox.h>
3628e088
RD
207%}
208
b2dc1044
RD
209MAKE_CONST_WXSTRING(VListBoxNameStr);
210
3628e088
RD
211
212// First, the C++ version
213%{
214class wxPyVListBox : public wxVListBox
215{
216 DECLARE_ABSTRACT_CLASS(wxPyVListBox);
217public:
218 wxPyVListBox() : wxVListBox() {}
219
220 wxPyVListBox(wxWindow *parent,
221 wxWindowID id = wxID_ANY,
222 const wxPoint& pos = wxDefaultPosition,
223 const wxSize& size = wxDefaultSize,
224 long style = 0,
225 const wxString& name = wxPyVListBoxNameStr)
226 : wxVListBox(parent, id, pos, size, style, name)
227 {}
228
229 // Overridable virtuals
230
231 // the derived class must implement this function to actually draw the item
232 // with the given index on the provided DC
233 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
234 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
235
236
237 // the derived class must implement this method to return the height of the
238 // specified item
239 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
240 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
241
242
243 // this method may be used to draw separators between the lines; note that
244 // the rectangle may be modified, typically to deflate it a bit before
245 // passing to OnDrawItem()
246 //
247 // the base class version doesn't do anything
248 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
249 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator);
250
251
252 // this method is used to draw the items background and, maybe, a border
253 // around it
254 //
255 // the base class version implements a reasonable default behaviour which
256 // consists in drawing the selected item with the standard background
257 // colour and drawing a border around the item if it is either selected or
258 // current
259 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
260 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
261
262
263 PYPRIVATE;
264};
265
266IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
267
268IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
269IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
270IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator);
271IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
272
273%}
274
275
276
277// Now define this class for SWIG
278
279/*
280 This class has two main differences from a regular listbox: it can have an
281 arbitrarily huge number of items because it doesn't store them itself but
282 uses OnDrawItem() callback to draw them and its items can have variable
283 height as determined by OnMeasureItem().
284
285 It emits the same events as wxListBox and the same event macros may be used
286 with it.
287 */
ab1f7d2a
RD
288MustHaveApp(wxPyVListBox);
289
1b8c7ba6
RD
290%rename(VListBox) wxPyVListBox;
291class wxPyVListBox : public wxPyVScrolledWindow
3628e088
RD
292{
293public:
2b9048c5
RD
294 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
295 %pythonAppend wxPyVListBox() ""
d14a1e28 296
3628e088
RD
297
298 wxPyVListBox(wxWindow *parent,
299 wxWindowID id = wxID_ANY,
300 const wxPoint& pos = wxDefaultPosition,
301 const wxSize& size = wxDefaultSize,
302 long style = 0,
303 const wxString& name = wxPyVListBoxNameStr);
304
1b8c7ba6 305 %RenameCtor(PreVListBox, wxPyVListBox());
3628e088
RD
306
307 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
308
309 bool Create(wxWindow *parent,
310 wxWindowID id = wxID_ANY,
311 const wxPoint& pos = wxDefaultPosition,
312 const wxSize& size = wxDefaultSize,
313 long style = 0,
314 const wxString& name = wxPyVListBoxNameStr);
315
316 // get the number of items in the control
317 size_t GetItemCount() const;
318
319 // does this control use multiple selection?
320 bool HasMultipleSelection() const;
321
322 // get the currently selected item or wxNOT_FOUND if there is no selection
323 //
324 // this method is only valid for the single selection listboxes
325 int GetSelection() const;
326
327 // is this item the current one?
328 bool IsCurrent(size_t item) const;
329
330 // is this item selected?
331 bool IsSelected(size_t item) const;
332
333 // get the number of the selected items (maybe 0)
334 //
335 // this method is valid for both single and multi selection listboxes
336 size_t GetSelectedCount() const;
337
3d8a2fd7
RD
338 %extend {
339 // get the first selected item, returns wxNOT_FOUND if none
340 //
341 // cookie is an opaque parameter which should be passed to
342 // GetNextSelected() later
343 //
344 // this method is only valid for the multi selection listboxes
345 //int GetFirstSelected(unsigned long& cookie) const;
346 PyObject* GetFirstSelected() {
347 unsigned long cookie = 0;
348 int selected = self->GetFirstSelected(cookie);
6e6b3557 349 wxPyBlock_t blocked = wxPyBeginBlockThreads();
3d8a2fd7
RD
350 PyObject* tup = PyTuple_New(2);
351 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
352 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
353 wxPyEndBlockThreads(blocked);
354 return tup;
355 }
356
357 // get next selection item, return wxNOT_FOUND if no more
358 //
359 // cookie must be the same parameter that was passed to GetFirstSelected()
360 // before
361 //
362 // this method is only valid for the multi selection listboxes
363 // int GetNextSelected(unsigned long& cookie) const;
364 PyObject* GetNextSelected(unsigned long cookie) {
365 int selected = self->GetNextSelected(cookie);
6e6b3557 366 wxPyBlock_t blocked = wxPyBeginBlockThreads();
3d8a2fd7
RD
367 PyObject* tup = PyTuple_New(2);
368 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
369 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
370 wxPyEndBlockThreads(blocked);
371 return tup;
372 }
373 }
3628e088 374
3d8a2fd7 375
3628e088
RD
376 // get the margins around each item
377 wxPoint GetMargins() const;
378
379 // get the background colour of selected cells
380 const wxColour& GetSelectionBackground() const;
381
382
383 // set the number of items to be shown in the control
384 //
385 // this is just a synonym for wxVScrolledWindow::SetLineCount()
386 void SetItemCount(size_t count);
387
388 // delete all items from the control
389 void Clear();
390
391 // set the selection to the specified item, if it is wxNOT_FOUND the
392 // selection is unset
393 //
394 // this function is only valid for the single selection listboxes
395 void SetSelection(int selection);
396
397 // selects or deselects the specified item which must be valid (i.e. not
398 // equal to wxNOT_FOUND)
399 //
dd9f7fea 400 // return True if the items selection status has changed or False
3628e088
RD
401 // otherwise
402 //
403 // this function is only valid for the multiple selection listboxes
a72f4631 404 bool Select(size_t item, bool select = true);
3628e088
RD
405
406 // selects the items in the specified range whose end points may be given
407 // in any order
408 //
dd9f7fea 409 // return True if any items selection status has changed, False otherwise
3628e088
RD
410 //
411 // this function is only valid for the single selection listboxes
412 bool SelectRange(size_t from, size_t to);
413
414 // toggle the selection of the specified item (must be valid)
415 //
416 // this function is only valid for the multiple selection listboxes
417 void Toggle(size_t item);
418
419 // select all items in the listbox
420 //
421 // the return code indicates if any items were affected by this operation
dd9f7fea 422 // (True) or if nothing has changed (False)
3628e088
RD
423 bool SelectAll();
424
425 // unselect all items in the listbox
426 //
427 // the return code has the same meaning as for SelectAll()
428 bool DeselectAll();
429
430 // set the margins: horizontal margin is the distance between the window
431 // border and the item contents while vertical margin is half of the
432 // distance between items
433 //
434 // by default both margins are 0
435 void SetMargins(const wxPoint& pt);
1b8c7ba6 436 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
3628e088
RD
437
438 // change the background colour of the selected cells
439 void SetSelectionBackground(const wxColour& col);
440
441};
442
443
444//---------------------------------------------------------------------------
445// wxHtmlListBox
446
447%{
448#include <wx/htmllbox.h>
449%}
450
451// First, the C++ version
452%{
453class wxPyHtmlListBox : public wxHtmlListBox
454{
455 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox);
456public:
457 wxPyHtmlListBox() : wxHtmlListBox() {}
458
459 wxPyHtmlListBox(wxWindow *parent,
460 wxWindowID id = wxID_ANY,
461 const wxPoint& pos = wxDefaultPosition,
462 const wxSize& size = wxDefaultSize,
463 long style = 0,
464 const wxString& name = wxPyVListBoxNameStr)
465 : wxHtmlListBox(parent, id, pos, size, style, name)
466 {}
467
468 // Overridable virtuals
469
470 // this method must be implemented in the derived class and should return
471 // the body (i.e. without <html>) of the HTML for the given item
472 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
473
474 // this function may be overridden to decorate HTML returned by OnGetItem()
475 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
476
477// TODO:
478// // this method allows to customize the selection appearance: it may be used
479// // to specify the colour of the text which normally has the given colour
480// // colFg when it is inside the selection
481// //
482// // by default, the original colour is not used at all and all text has the
483// // same (default for this system) colour inside selection
484// virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
485
486// // this is the same as GetSelectedTextColour() but allows to customize the
487// // background colour -- this is even more rarely used as you can change it
488// // globally using SetSelectionBackground()
489// virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
490
491
492 PYPRIVATE;
493};
494
495
496IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
497
498IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
499IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
500
501%}
502
503
504
505// Now define this class for SWIG
506
507
508// wxHtmlListBox is a listbox whose items are wxHtmlCells
ab1f7d2a 509MustHaveApp(wxPyHtmlListBox);
1b8c7ba6
RD
510%rename(HtmlListBox) wxPyHtmlListBox;
511class wxPyHtmlListBox : public wxPyVListBox
3628e088
RD
512{
513public:
2b9048c5
RD
514 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
515 %pythonAppend wxPyHtmlListBox() ""
d14a1e28 516
3628e088
RD
517
518 // normal constructor which calls Create() internally
519 wxPyHtmlListBox(wxWindow *parent,
520 wxWindowID id = wxID_ANY,
521 const wxPoint& pos = wxDefaultPosition,
522 const wxSize& size = wxDefaultSize,
523 long style = 0,
524 const wxString& name = wxPyVListBoxNameStr);
525
1b8c7ba6 526 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
3628e088
RD
527
528 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
529
530 bool Create(wxWindow *parent,
531 wxWindowID id = wxID_ANY,
532 const wxPoint& pos = wxDefaultPosition,
533 const wxSize& size = wxDefaultSize,
534 long style = 0,
535 const wxString& name = wxPyVListBoxNameStr);
536
537
538 void RefreshAll();
539 void SetItemCount(size_t count);
540
450d55a0
RD
541 // retrieve the file system used by the wxHtmlWinParser: if you use
542 // relative paths in your HTML, you should use its ChangePathTo() method
543 wxFileSystem& GetFileSystem();
3628e088
RD
544};
545
546
d14a1e28 547
3628e088 548//---------------------------------------------------------------------------
4416b508 549
771eb7a2
RD
550%init %{
551 // Map renamed classes back to their common name for OOR
d14a1e28
RD
552 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
553 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
771eb7a2
RD
554 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
555%}
556
d14a1e28 557//---------------------------------------------------------------------------