]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls.i
e2d6e99dbe3eae5110012d40089ae2db311712a5
[wxWidgets.git] / wxPython / src / controls.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: controls.i
3 // Purpose: Control (widget) classes for wxPython
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 6/10/98
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module controls
14
15 %{
16 #include "helpers.h"
17 #include <wx/slider.h>
18 #include <wx/spinbutt.h>
19 #include <wx/spinctrl.h>
20 #include <wx/dynarray.h>
21 #include <wx/statline.h>
22 #include <wx/tglbtn.h>
23
24 #ifdef __WXMSW__
25 #if wxUSE_OWNER_DRAWN
26 #include <wx/checklst.h>
27 #endif
28 #endif
29
30 #ifdef __WXGTK__
31 #include <wx/checklst.h>
32 #endif
33 %}
34
35 //----------------------------------------------------------------------
36
37 %include typemaps.i
38 %include my_typemaps.i
39
40 // Import some definitions of other classes, etc.
41 %import _defs.i
42 %import misc.i
43 %import windows.i
44 %import gdi.i
45 %import events.i
46
47 %pragma(python) code = "import wx"
48
49 //----------------------------------------------------------------------
50
51 %readonly
52 // See also wxPy_ReinitStockObjects in helpers.cpp
53 wxValidator wxDefaultValidator;
54 %readwrite
55
56 //----------------------------------------------------------------------
57
58 %{
59 //#define DECLARE_DEF_STRING(name) static wxString* wxPy##name
60
61 // Put some wx default wxChar* values into wxStrings.
62 DECLARE_DEF_STRING(ControlNameStr);
63 DECLARE_DEF_STRING(ButtonNameStr);
64 DECLARE_DEF_STRING(CheckBoxNameStr);
65 DECLARE_DEF_STRING(ChoiceNameStr);
66 DECLARE_DEF_STRING(ComboBoxNameStr);
67 DECLARE_DEF_STRING(GaugeNameStr);
68 DECLARE_DEF_STRING(StaticBoxNameStr);
69 DECLARE_DEF_STRING(StaticTextNameStr);
70 DECLARE_DEF_STRING(ListBoxNameStr);
71 DECLARE_DEF_STRING(TextCtrlNameStr);
72 DECLARE_DEF_STRING(ScrollBarNameStr);
73 DECLARE_DEF_STRING(SPIN_BUTTON_NAME);
74 DECLARE_DEF_STRING(StaticBitmapNameStr);
75 DECLARE_DEF_STRING(RadioBoxNameStr);
76 DECLARE_DEF_STRING(RadioButtonNameStr);
77 DECLARE_DEF_STRING(SliderNameStr);
78
79 wxChar* wxSpinCtrlNameStr = _T("wxSpinCtrl");
80 DECLARE_DEF_STRING(SpinCtrlNameStr);
81
82 static const wxString wxPyEmptyString(wxT(""));
83 %}
84
85 //----------------------------------------------------------------------
86
87 // This is the base class for a control or 'widget'.
88 //
89 // A control is generally a small window which processes user input and/or
90 // displays one or more item of data.
91 class wxControl : public wxWindow {
92 public:
93
94 //
95 wxControl(wxWindow *parent,
96 wxWindowID id,
97 const wxPoint& pos=wxDefaultPosition,
98 const wxSize& size=wxDefaultSize,
99 long style=0,
100 const wxValidator& validator=wxDefaultValidator,
101 const wxString& name=wxPyControlNameStr);
102
103 //
104 %name(wxPreControl)wxControl();
105
106 //
107 bool Create(wxWindow *parent,
108 wxWindowID id,
109 const wxPoint& pos=wxDefaultPosition,
110 const wxSize& size=wxDefaultSize,
111 long style=0,
112 const wxValidator& validator=wxDefaultValidator,
113 const wxString& name=wxPyControlNameStr);
114
115 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
116 %pragma(python) addtomethod = "wxPreControl:val._setOORInfo(val)"
117
118 // Simulates the effect of the user issuing a command to the item. See
119 // wxCommandEvent.
120 void Command(wxCommandEvent& event);
121
122 // Return a control's text.
123 wxString GetLabel();
124
125 // Sets the item's text.
126 void SetLabel(const wxString& label);
127 };
128
129
130 //----------------------------------------------------------------------
131
132
133 class wxControlWithItems : public wxControl {
134 public:
135
136 // void Clear(); ambiguous, redefine below...
137
138 // Deletes an item from the control
139 void Delete(int n);
140
141 // Returns the number of items in the control.
142 int GetCount();
143 %pragma(python) addtoclass = "Number = GetCount"
144
145 // Returns the string at the given position.
146 wxString GetString(int n);
147
148 // Sets the string value of an item.
149 void SetString(int n, const wxString& s);
150
151 // Finds an item matching the given string. Returns the zero-based
152 // position of the item, or -1 if the string was not found.
153 int FindString(const wxString& s);
154
155 // Select the item at postion n.
156 void Select(int n);
157
158 // Gets the position of the selected item.
159 int GetSelection();
160
161 // Gets the current selection as a string.
162 wxString GetStringSelection() const;
163
164 // void Append(const wxString& item);
165 // void Append(const wxString& item, char* clientData);
166 // char* GetClientData(const int n);
167 // void SetClientData(const int n, char* data);
168
169
170 %addmethods {
171 // Adds the item to the control, associating the given data with the
172 // item if not None.
173 void Append(const wxString& item, PyObject* clientData=NULL) {
174 if (clientData) {
175 wxPyClientData* data = new wxPyClientData(clientData);
176 self->Append(item, data);
177 } else
178 self->Append(item);
179 }
180
181 // Returns the client data associated with the given item, (if any.)
182 PyObject* GetClientData(int n) {
183 wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n);
184 if (data) {
185 Py_INCREF(data->m_obj);
186 return data->m_obj;
187 } else {
188 Py_INCREF(Py_None);
189 return Py_None;
190 }
191 }
192
193 // Associate the given client data with the item at position n.
194 void SetClientData(int n, PyObject* clientData) {
195 wxPyClientData* data = new wxPyClientData(clientData);
196 self->SetClientObject(n, data);
197 }
198 }
199
200 // append several items at once to the control
201 %name(AppendItems)void Append(const wxArrayString& strings);
202
203 };
204
205 //----------------------------------------------------------------------
206
207 // A button is a control that contains a text string, and is one of the most
208 // common elements of a GUI. It may be placed on a dialog box or panel, or
209 // indeed almost any other window.
210 //
211 // Styles
212 // wxBU_LEFT: Left-justifies the label. WIN32 only.
213 // wxBU_TOP: Aligns the label to the top of the button. WIN32 only.
214 // wxBU_RIGHT: Right-justifies the bitmap label. WIN32 only.
215 // wxBU_BOTTOM: Aligns the label to the bottom of the button. WIN32 only.
216 // wxBU_EXACTFIT: Creates the button as small as possible instead of making
217 // it of the standard size (which is the default behaviour.)
218 //
219 // Events
220 // EVT_BUTTON(win,id,func):
221 // Sent when the button is clicked.
222 //
223 class wxButton : public wxControl {
224 public:
225 // Constructor, creating and showing a button.
226 //
227 // parent: Parent window. Must not be None.
228 // id: Button identifier. A value of -1 indicates a default value.
229 // label: The text to be displayed on the button.
230 // pos: The button position on it's parent.
231 // size: Button size. If the default size (-1, -1) is specified then the
232 // button is sized appropriately for the text.
233 // style: Window style. See wxButton.
234 // validator: Window validator.
235 // name: Window name.
236 wxButton(wxWindow* parent, wxWindowID id, const wxString& label,
237 const wxPoint& pos = wxDefaultPosition,
238 const wxSize& size = wxDefaultSize,
239 long style = 0,
240 const wxValidator& validator = wxDefaultValidator,
241 const wxString& name = wxPyButtonNameStr);
242
243 // Default constructor
244 %name(wxPreButton)wxButton();
245
246 // Button creation function for two-step creation.
247 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
248 const wxPoint& pos = wxDefaultPosition,
249 const wxSize& size = wxDefaultSize,
250 long style = 0,
251 const wxValidator& validator = wxDefaultValidator,
252 const wxString& name = wxPyButtonNameStr);
253
254 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
255 %pragma(python) addtomethod = "wxPreButton:val._setOORInfo(val)"
256
257 // This sets the button to be the default item for the panel or dialog box.
258 //
259 // Under Windows, only dialog box buttons respond to this function. As
260 // normal under Windows and Motif, pressing return causes the default
261 // button to be depressed when the return key is pressed. See also
262 // wxWindow.SetFocus which sets the keyboard focus for windows and text
263 // panel items, and wxPanel.SetDefaultItem.
264 void SetDefault();
265
266 //
267 void SetBackgroundColour(const wxColour& colour);
268 //
269 void SetForegroundColour(const wxColour& colour);
270
271 #ifdef __WXMSW__
272 // show the image in the button in addition to the label
273 void SetImageLabel(const wxBitmap& bitmap);
274
275 // set the margins around the image
276 void SetImageMargins(wxCoord x, wxCoord y);
277 #endif
278
279 // returns the default button size for this platform
280 static wxSize GetDefaultSize();
281 };
282
283 //----------------------------------------------------------------------
284
285 class wxBitmapButton : public wxButton {
286 public:
287 wxBitmapButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
288 const wxPoint& pos = wxDefaultPosition,
289 const wxSize& size = wxDefaultSize,
290 long style = wxBU_AUTODRAW,
291 const wxValidator& validator = wxDefaultValidator,
292 const wxString& name = wxPyButtonNameStr);
293 %name(wxPreBitmapButton)wxBitmapButton();
294
295 bool Create(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
296 const wxPoint& pos = wxDefaultPosition,
297 const wxSize& size = wxDefaultSize,
298 long style = wxBU_AUTODRAW,
299 const wxValidator& validator = wxDefaultValidator,
300 const wxString& name = wxPyButtonNameStr);
301
302 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
303 %pragma(python) addtomethod = "wxPreBitmapButton:val._setOORInfo(val)"
304
305 wxBitmap GetBitmapLabel();
306 wxBitmap GetBitmapDisabled();
307 wxBitmap GetBitmapFocus();
308 wxBitmap GetBitmapSelected();
309 void SetBitmapDisabled(const wxBitmap& bitmap);
310 void SetBitmapFocus(const wxBitmap& bitmap);
311 void SetBitmapSelected(const wxBitmap& bitmap);
312 void SetBitmapLabel(const wxBitmap& bitmap);
313
314 void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
315 int GetMarginX() const { return m_marginX; }
316 int GetMarginY() const { return m_marginY; }
317 };
318
319 //----------------------------------------------------------------------
320
321 class wxCheckBox : public wxControl {
322 public:
323 wxCheckBox(wxWindow* parent, wxWindowID id, const wxString& label,
324 const wxPoint& pos = wxDefaultPosition,
325 const wxSize& size = wxDefaultSize,
326 long style = 0,
327 const wxValidator& validator = wxDefaultValidator,
328 const wxString& name = wxPyCheckBoxNameStr);
329 %name(wxPreCheckBox)wxCheckBox();
330
331 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
332 const wxPoint& pos = wxDefaultPosition,
333 const wxSize& size = wxDefaultSize,
334 long style = 0,
335 const wxValidator& validator = wxDefaultValidator,
336 const wxString& name = wxPyCheckBoxNameStr);
337
338 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
339 %pragma(python) addtomethod = "wxPreCheckBox:val._setOORInfo(val)"
340
341 bool GetValue();
342 bool IsChecked();
343 void SetValue(const bool state);
344 };
345
346 //----------------------------------------------------------------------
347
348 class wxChoice : public wxControlWithItems {
349 public:
350 wxChoice(wxWindow *parent, wxWindowID id,
351 const wxPoint& pos = wxDefaultPosition,
352 const wxSize& size = wxDefaultSize,
353 int LCOUNT=0, wxString* choices=NULL,
354 long style = 0,
355 const wxValidator& validator = wxDefaultValidator,
356 const wxString& name = wxPyChoiceNameStr);
357 %name(wxPreChoice)wxChoice();
358
359 bool Create(wxWindow *parent, wxWindowID id,
360 const wxPoint& pos = wxDefaultPosition,
361 const wxSize& size = wxDefaultSize,
362 int LCOUNT=0, wxString* choices=NULL,
363 long style = 0,
364 const wxValidator& validator = wxDefaultValidator,
365 const wxString& name = wxPyChoiceNameStr);
366
367 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
368 %pragma(python) addtomethod = "wxPreChoice:val._setOORInfo(val)"
369
370 void Clear();
371
372 int GetColumns();
373 void SetColumns(const int n = 1);
374 void SetSelection(const int n);
375 void SetStringSelection(const wxString& string);
376 void SetString(int n, const wxString& s);
377
378 %pragma(python) addtoclass = "
379 Select = SetSelection
380 "
381 };
382
383 //----------------------------------------------------------------------
384
385 // wxGTK's wxComboBox doesn't derive from wxChoice like wxMSW, or even
386 // wxControlWithItems, so we have to duplicate the methods here... <blech!>
387 // wxMac's inheritace is weird too so we'll fake it with this one too.
388
389 #ifndef __WXMSW__
390 class wxComboBox : public wxControl
391 {
392 public:
393 wxComboBox(wxWindow* parent, wxWindowID id,
394 const wxString& value = wxPyEmptyString,
395 const wxPoint& pos = wxDefaultPosition,
396 const wxSize& size = wxDefaultSize,
397 int LCOUNT=0, wxString* choices=NULL,
398 long style = 0,
399 const wxValidator& validator = wxDefaultValidator,
400 const wxString& name = wxPyComboBoxNameStr);
401 %name(wxPreComboBox)wxComboBox();
402
403 bool Create(wxWindow* parent, wxWindowID id,
404 const wxString& value = wxPyEmptyString,
405 const wxPoint& pos = wxDefaultPosition,
406 const wxSize& size = wxDefaultSize,
407 int LCOUNT=0, wxString* choices=NULL,
408 long style = 0,
409 const wxValidator& validator = wxDefaultValidator,
410 const wxString& name = wxPyComboBoxNameStr);
411
412 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
413 %pragma(python) addtomethod = "wxPreComboBox:val._setOORInfo(val)"
414
415 void Copy();
416 void Cut();
417 long GetInsertionPoint();
418 long GetLastPosition();
419 wxString GetValue();
420 void Paste();
421 void Replace(long from, long to, const wxString& text);
422 void Remove(long from, long to);
423 void SetInsertionPoint(long pos);
424 void SetInsertionPointEnd();
425 void SetSelection(int n);
426 %name(SetMark)void SetSelection(long from, long to);
427 void SetValue(const wxString& text);
428 void SetEditable(bool editable);
429
430
431 void Clear();
432 void Delete(int n);
433
434 int GetCount();
435 %pragma(python) addtoclass = "Number = GetCount"
436 wxString GetString(int n);
437 int FindString(const wxString& s);
438
439 //void SetString(int n, const wxString& s); *** No equivalent for wxGTK!!!
440
441 // void Select(int n);
442 %pragma(python) addtoclass = "Select = SetSelection"
443
444 int GetSelection();
445 wxString GetStringSelection() const;
446
447 // void Append(const wxString& item);
448 // void Append(const wxString& item, char* clientData);
449 // char* GetClientData(const int n);
450 // void SetClientData(const int n, char* data);
451 %addmethods {
452 void Append(const wxString& item, PyObject* clientData=NULL) {
453 if (clientData) {
454 wxPyClientData* data = new wxPyClientData(clientData);
455 self->Append(item, data);
456 } else
457 self->Append(item);
458 }
459
460 PyObject* GetClientData(int n) {
461 #ifdef __WXMAC__
462 wxPyClientData* data = (wxPyClientData*)self->wxItemContainer::GetClientObject(n);
463 #else
464 wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n);
465 #endif
466 if (data) {
467 Py_INCREF(data->m_obj);
468 return data->m_obj;
469 } else {
470 Py_INCREF(Py_None);
471 return Py_None;
472 }
473 }
474
475 void SetClientData(int n, PyObject* clientData) {
476 wxPyClientData* data = new wxPyClientData(clientData);
477 #ifdef __WXMAC__
478 self->wxItemContainer::SetClientObject(n, data);
479 #else
480 self->SetClientObject(n, data);
481 #endif
482 }
483 }
484
485 };
486
487
488
489 #else
490 // MSW's version derives from wxChoice
491
492 class wxComboBox : public wxChoice {
493 public:
494 wxComboBox(wxWindow* parent, wxWindowID id,
495 const wxString& value = wxPyEmptyString,
496 const wxPoint& pos = wxDefaultPosition,
497 const wxSize& size = wxDefaultSize,
498 int LCOUNT=0, wxString* choices=NULL,
499 long style = 0,
500 const wxValidator& validator = wxDefaultValidator,
501 const wxString& name = wxPyComboBoxNameStr);
502 %name(wxPreComboBox)wxComboBox();
503
504 bool Create(wxWindow* parent, wxWindowID id,
505 const wxString& value = wxPyEmptyString,
506 const wxPoint& pos = wxDefaultPosition,
507 const wxSize& size = wxDefaultSize,
508 int LCOUNT=0, wxString* choices=NULL,
509 long style = 0,
510 const wxValidator& validator = wxDefaultValidator,
511 const wxString& name = wxPyComboBoxNameStr);
512
513 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
514 %pragma(python) addtomethod = "wxPreComboBox:val._setOORInfo(val)"
515
516 void Copy();
517 void Cut();
518 long GetInsertionPoint();
519 long GetLastPosition();
520 wxString GetValue();
521 void Paste();
522 void Replace(long from, long to, const wxString& text);
523 void Remove(long from, long to);
524 void SetInsertionPoint(long pos);
525 void SetInsertionPointEnd();
526 void SetSelection(int n);
527 %name(SetMark)void SetSelection(long from, long to);
528 void SetValue(const wxString& text);
529 void SetEditable(bool editable);
530 };
531 #endif
532
533
534 //----------------------------------------------------------------------
535
536 class wxGauge : public wxControl {
537 public:
538 wxGauge(wxWindow* parent, wxWindowID id, int range,
539 const wxPoint& pos = wxDefaultPosition,
540 const wxSize& size = wxDefaultSize,
541 long style = wxGA_HORIZONTAL,
542 const wxValidator& validator = wxDefaultValidator,
543 const wxString& name = wxPyGaugeNameStr);
544 %name(wxPreGauge)wxGauge();
545
546 bool Create(wxWindow* parent, wxWindowID id, int range,
547 const wxPoint& pos = wxDefaultPosition,
548 const wxSize& size = wxDefaultSize,
549 long style = wxGA_HORIZONTAL,
550 const wxValidator& validator = wxDefaultValidator,
551 const wxString& name = wxPyGaugeNameStr);
552
553 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
554 %pragma(python) addtomethod = "wxPreGauge:val._setOORInfo(val)"
555
556 int GetBezelFace();
557 int GetRange();
558 int GetShadowWidth();
559 int GetValue();
560 bool IsVertical() const;
561 void SetBezelFace(int width);
562 void SetRange(int range);
563 void SetShadowWidth(int width);
564 void SetValue(int pos);
565 };
566
567 //----------------------------------------------------------------------
568
569 class wxStaticBox : public wxControl {
570 public:
571 wxStaticBox(wxWindow* parent, wxWindowID id, const wxString& label,
572 const wxPoint& pos = wxDefaultPosition,
573 const wxSize& size = wxDefaultSize,
574 long style = 0,
575 const wxString& name = wxPyStaticBoxNameStr);
576 %name(wxPreStaticBox)wxStaticBox();
577
578 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
579 const wxPoint& pos = wxDefaultPosition,
580 const wxSize& size = wxDefaultSize,
581 long style = 0,
582 const wxString& name = wxPyStaticBoxNameStr);
583
584 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
585 %pragma(python) addtomethod = "wxPreStaticBox:val._setOORInfo(val)"
586 };
587
588
589 //----------------------------------------------------------------------
590
591
592 class wxStaticLine : public wxControl {
593 public:
594 wxStaticLine( wxWindow *parent, wxWindowID id,
595 const wxPoint &pos = wxDefaultPosition,
596 const wxSize &size = wxDefaultSize,
597 long style = wxLI_HORIZONTAL,
598 const wxString& name = wxPyStaticTextNameStr);
599 %name(wxPreStaticLine)wxStaticLine();
600
601 bool Create( wxWindow *parent, wxWindowID id,
602 const wxPoint &pos = wxDefaultPosition,
603 const wxSize &size = wxDefaultSize,
604 long style = wxLI_HORIZONTAL,
605 const wxString& name = wxPyStaticTextNameStr);
606
607 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
608 %pragma(python) addtomethod = "wxPreStaticLine:val._setOORInfo(val)"
609 };
610
611
612 //----------------------------------------------------------------------
613
614 class wxStaticText : public wxControl {
615 public:
616 wxStaticText(wxWindow* parent, wxWindowID id, const wxString& label,
617 const wxPoint& pos = wxDefaultPosition,
618 const wxSize& size = wxDefaultSize,
619 long style = 0,
620 const wxString& name = wxPyStaticTextNameStr);
621 %name(wxPreStaticText)wxStaticText();
622
623 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
624 const wxPoint& pos = wxDefaultPosition,
625 const wxSize& size = wxDefaultSize,
626 long style = 0,
627 const wxString& name = wxPyStaticTextNameStr);
628
629 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
630 %pragma(python) addtomethod = "wxPreStaticText:val._setOORInfo(val)"
631
632 wxString GetLabel();
633 void SetLabel(const wxString& label);
634 };
635
636 //----------------------------------------------------------------------
637
638 class wxListBox : public wxControlWithItems {
639 public:
640 wxListBox(wxWindow* parent, wxWindowID id,
641 const wxPoint& pos = wxDefaultPosition,
642 const wxSize& size = wxDefaultSize,
643 int LCOUNT, wxString* choices = NULL,
644 long style = 0,
645 const wxValidator& validator = wxDefaultValidator,
646 const wxString& name = wxPyListBoxNameStr);
647 %name(wxPreListBox)wxListBox();
648
649 bool Create(wxWindow* parent, wxWindowID id,
650 const wxPoint& pos = wxDefaultPosition,
651 const wxSize& size = wxDefaultSize,
652 int LCOUNT, wxString* choices = NULL,
653 long style = 0,
654 const wxValidator& validator = wxDefaultValidator,
655 const wxString& name = wxPyListBoxNameStr);
656
657 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
658 %pragma(python) addtomethod = "wxPreListBox:val._setOORInfo(val)"
659
660 void Clear();
661 void Deselect(int n);
662
663 // int GetSelections(int **selections);
664 %addmethods {
665 PyObject* GetSelections() {
666 wxArrayInt lst;
667 self->GetSelections(lst);
668 PyObject *tup = PyTuple_New(lst.GetCount());
669 for(size_t i=0; i<lst.GetCount(); i++) {
670 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
671 }
672 return tup;
673 }
674 }
675
676
677 void InsertItems(int LCOUNT, wxString* choices, int pos);
678
679 bool IsSelected(const int n);
680 bool Selected(const int n);
681 void Set(int LCOUNT, wxString* choices);
682 void SetFirstItem(int n);
683 %name(SetFirstItemStr)void SetFirstItem(const wxString& string);
684 void SetSelection(int n, bool select = TRUE);
685 void SetString(int n, const wxString& string);
686 void SetStringSelection(const wxString& string, bool select = TRUE);
687 };
688
689
690 //----------------------------------------------------------------------
691
692 class wxCheckListBox : public wxListBox {
693 public:
694 wxCheckListBox(wxWindow *parent, wxWindowID id,
695 const wxPoint& pos = wxDefaultPosition,
696 const wxSize& size = wxDefaultSize,
697 int LCOUNT = 0,
698 wxString* choices = NULL,
699 long style = 0,
700 const wxValidator& validator = wxDefaultValidator,
701 const wxString& name = wxPyListBoxNameStr);
702 %name(wxPreCheckListBox)wxCheckListBox();
703
704 bool Create(wxWindow *parent, wxWindowID id,
705 const wxPoint& pos = wxDefaultPosition,
706 const wxSize& size = wxDefaultSize,
707 int LCOUNT = 0,
708 wxString* choices = NULL,
709 long style = 0,
710 const wxValidator& validator = wxDefaultValidator,
711 const wxString& name = wxPyListBoxNameStr);
712
713 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
714 %pragma(python) addtomethod = "wxPreCheckListBox:val._setOORInfo(val)"
715
716 bool IsChecked(int uiIndex);
717 void Check(int uiIndex, int bCheck = TRUE);
718 void InsertItems(int LCOUNT, wxString* choices, int pos);
719
720 #ifndef __WXMAC__
721 int GetItemHeight();
722 #endif
723
724 // return the index of the item at this position or wxNOT_FOUND
725 int HitTest(const wxPoint& pt) const;
726 %name(HitTestXY)int HitTest(wxCoord x, wxCoord y) const;
727
728 };
729
730 //----------------------------------------------------------------------
731
732 enum {
733 // Styles
734 wxTE_NO_VSCROLL,
735 wxTE_AUTO_SCROLL,
736 wxTE_READONLY,
737 wxTE_MULTILINE,
738 wxTE_PROCESS_TAB,
739 wxTE_LEFT,
740 wxTE_CENTER,
741 wxTE_RIGHT,
742 wxTE_CENTRE,
743 wxTE_RICH,
744 wxTE_PROCESS_ENTER,
745 wxTE_PASSWORD,
746 wxTE_AUTO_URL,
747 wxTE_NOHIDESEL,
748 wxTE_DONTWRAP,
749 wxTE_LINEWRAP,
750 wxTE_WORDWRAP,
751 wxTE_RICH2,
752
753 // Flags to indicate which attributes are being applied
754 wxTEXT_ATTR_TEXT_COLOUR,
755 wxTEXT_ATTR_BACKGROUND_COLOUR,
756 wxTEXT_ATTR_FONT_FACE,
757 wxTEXT_ATTR_FONT_SIZE,
758 wxTEXT_ATTR_FONT_WEIGHT,
759 wxTEXT_ATTR_FONT_ITALIC,
760 wxTEXT_ATTR_FONT_UNDERLINE,
761 wxTEXT_ATTR_FONT,
762 wxTEXT_ATTR_ALIGNMENT,
763 wxTEXT_ATTR_LEFT_INDENT,
764 wxTEXT_ATTR_RIGHT_INDENT,
765 wxTEXT_ATTR_TABS,
766
767 };
768
769
770 enum wxTextAttrAlignment
771 {
772 wxTEXT_ALIGNMENT_DEFAULT,
773 wxTEXT_ALIGNMENT_LEFT,
774 wxTEXT_ALIGNMENT_CENTRE,
775 wxTEXT_ALIGNMENT_CENTER,
776 wxTEXT_ALIGNMENT_RIGHT,
777 wxTEXT_ALIGNMENT_JUSTIFIED
778 };
779
780
781
782
783 class wxTextAttr
784 {
785 public:
786 // ctors
787 wxTextAttr(const wxColour& colText = wxNullColour,
788 const wxColour& colBack = wxNullColour,
789 const wxFont& font = wxNullFont,
790 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
791 ~wxTextAttr();
792
793 void Init();
794
795 // setters
796 void SetTextColour(const wxColour& colText);
797 void SetBackgroundColour(const wxColour& colBack);
798 void SetFont(const wxFont& font);
799 void SetAlignment(wxTextAttrAlignment alignment);
800 void SetTabs(const wxArrayInt& tabs);
801 void SetLeftIndent(int indent);
802 void SetRightIndent(int indent);
803 void SetFlags(long flags);
804
805 // accessors
806 bool HasTextColour() const;
807 bool HasBackgroundColour() const;
808 bool HasFont() const;
809 bool HasAlignment() const;
810 bool HasTabs() const;
811 bool HasLeftIndent() const;
812 bool HasRightIndent() const;
813 bool HasFlag(long flag) const;
814
815 wxColour GetTextColour() const;
816 wxColour GetBackgroundColour() const;
817 wxFont GetFont() const;
818 wxTextAttrAlignment GetAlignment();
819 const wxArrayInt& GetTabs() const;
820 long GetLeftIndent() const;
821 long GetRightIndent() const;
822 long GetFlags() const;
823
824
825 // returns false if we have any attributes set, true otherwise
826 bool IsDefault();
827
828 // return the attribute having the valid font and colours: it uses the
829 // attributes set in attr and falls back first to attrDefault and then to
830 // the text control font/colours for those attributes which are not set
831 static wxTextAttr Combine(const wxTextAttr& attr,
832 const wxTextAttr& attrDef,
833 const wxTextCtrl *text);
834 };
835
836
837
838 class wxTextCtrl : public wxControl {
839 public:
840 wxTextCtrl(wxWindow* parent, wxWindowID id,
841 const wxString& value = wxPyEmptyString,
842 const wxPoint& pos = wxDefaultPosition,
843 const wxSize& size = wxDefaultSize,
844 long style = 0,
845 const wxValidator& validator = wxDefaultValidator,
846 const wxString& name = wxPyTextCtrlNameStr);
847 %name(wxPreTextCtrl)wxTextCtrl();
848
849 bool Create(wxWindow* parent, wxWindowID id,
850 const wxString& value = wxPyEmptyString,
851 const wxPoint& pos = wxDefaultPosition,
852 const wxSize& size = wxDefaultSize,
853 long style = 0,
854 const wxValidator& validator = wxDefaultValidator,
855 const wxString& name = wxPyTextCtrlNameStr);
856
857 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
858 %pragma(python) addtomethod = "wxPreTextCtrl:val._setOORInfo(val)"
859
860
861 wxString GetValue() const;
862 void SetValue(const wxString& value);
863
864 wxString GetRange(long from, long to);
865
866 int GetLineLength(long lineNo) const;
867 wxString GetLineText(long lineNo) const;
868 int GetNumberOfLines() const;
869
870 bool IsModified() const;
871 bool IsEditable() const;
872
873 // If the return values from and to are the same, there is no selection.
874 void GetSelection(long* OUTPUT, long* OUTPUT) const;
875 wxString GetStringSelection();
876
877 void Clear();
878 void Replace(long from, long to, const wxString& value);
879 void Remove(long from, long to);
880
881 // load/save the controls contents from/to the file
882 bool LoadFile(const wxString& file);
883 bool SaveFile(const wxString& file = wxPyEmptyString);
884
885 // sets the dirty flag
886 virtual void MarkDirty() = 0;
887
888 // clears the dirty flag
889 void DiscardEdits();
890
891 // set the max number of characters which may be entered in a single line
892 // text control
893 void SetMaxLength(unsigned long len);
894
895 // writing text inserts it at the current position, appending always
896 // inserts it at the end
897 void WriteText(const wxString& text);
898 void AppendText(const wxString& text);
899
900 // insert the character which would have resulted from this key event,
901 // return TRUE if anything has been inserted
902 bool EmulateKeyPress(const wxKeyEvent& event);
903
904 // text control under some platforms supports the text styles: these
905 // methods allow to apply the given text style to the given selection or to
906 // set/get the style which will be used for all appended text
907 bool SetStyle(long start, long end, const wxTextAttr& style);
908 bool SetDefaultStyle(const wxTextAttr& style);
909 const wxTextAttr& GetDefaultStyle() const;
910 bool GetStyle(long position, wxTextAttr& style);
911
912 // translate between the position (which is just an index in the text ctrl
913 // considering all its contents as a single strings) and (x, y) coordinates
914 // which represent column and line.
915 long XYToPosition(long x, long y) const;
916 void PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const;
917
918 //bool PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const;
919 // TODO: check return value, raise exception.
920
921 void ShowPosition(long pos);
922
923 // Clipboard operations
924 void Copy();
925 void Cut();
926 void Paste();
927
928 bool CanCopy() const;
929 bool CanCut() const;
930 bool CanPaste() const;
931
932 // Undo/redo
933 void Undo();
934 void Redo();
935
936 bool CanUndo() const;
937 bool CanRedo() const;
938
939 // Insertion point
940 void SetInsertionPoint(long pos);
941 void SetInsertionPointEnd();
942 long GetInsertionPoint() const;
943 long GetLastPosition() const;
944
945 void SetSelection(long from, long to);
946 void SelectAll();
947 void SetEditable(bool editable);
948
949 bool IsSingleLine();
950 bool IsMultiLine();
951
952
953 %addmethods {
954 void write(const wxString& text) {
955 self->AppendText(text);
956 }
957 }
958
959 // TODO: replace this when the method is really added to wxTextCtrl
960 %addmethods {
961 wxString GetString(long from, long to) {
962 return self->GetValue().Mid(from, to - from);
963 }
964 }
965 };
966
967 //----------------------------------------------------------------------
968
969 class wxScrollBar : public wxControl {
970 public:
971 wxScrollBar(wxWindow* parent, wxWindowID id = -1,
972 const wxPoint& pos = wxDefaultPosition,
973 const wxSize& size = wxDefaultSize,
974 long style = wxSB_HORIZONTAL,
975 const wxValidator& validator = wxDefaultValidator,
976 const wxString& name = wxPyScrollBarNameStr);
977 %name(wxPreScrollBar)wxScrollBar();
978
979 bool Create(wxWindow* parent, wxWindowID id = -1,
980 const wxPoint& pos = wxDefaultPosition,
981 const wxSize& size = wxDefaultSize,
982 long style = wxSB_HORIZONTAL,
983 const wxValidator& validator = wxDefaultValidator,
984 const wxString& name = wxPyScrollBarNameStr);
985
986 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
987 %pragma(python) addtomethod = "wxPreScrollBar:val._setOORInfo(val)"
988
989 int GetRange();
990 int GetPageSize();
991 int GetThumbPosition();
992 int GetThumbSize();
993 %name(GetThumbLength) int GetThumbSize(); // to match the docs
994
995 bool IsVertical();
996
997 void SetThumbPosition(int viewStart);
998 void SetScrollbar(int position, int thumbSize,
999 int range, int pageSize,
1000 bool refresh = TRUE);
1001 };
1002
1003 //----------------------------------------------------------------------
1004
1005 class wxSpinButton : public wxControl {
1006 public:
1007 wxSpinButton(wxWindow* parent, wxWindowID id = -1,
1008 const wxPoint& pos = wxDefaultPosition,
1009 const wxSize& size = wxDefaultSize,
1010 long style = wxSP_HORIZONTAL,
1011 const wxString& name = wxPySPIN_BUTTON_NAME);
1012 %name(wxPreSpinButton)wxSpinButton();
1013
1014 bool Create(wxWindow* parent, wxWindowID id = -1,
1015 const wxPoint& pos = wxDefaultPosition,
1016 const wxSize& size = wxDefaultSize,
1017 long style = wxSP_HORIZONTAL,
1018 const wxString& name = wxPySPIN_BUTTON_NAME);
1019
1020 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1021 %pragma(python) addtomethod = "wxPreSpinButton:val._setOORInfo(val)"
1022
1023 int GetMax();
1024 int GetMin();
1025 int GetValue();
1026 void SetRange(int min, int max);
1027 void SetValue(int value);
1028 };
1029
1030 //----------------------------------------------------------------------
1031
1032 class wxStaticBitmap : public wxControl {
1033 public:
1034 wxStaticBitmap(wxWindow* parent, wxWindowID id,
1035 const wxBitmap& bitmap,
1036 const wxPoint& pos = wxDefaultPosition,
1037 const wxSize& size = wxDefaultSize,
1038 long style = 0,
1039 const wxString& name = wxPyStaticBitmapNameStr);
1040 %name(wxPreStaticBitmap)wxStaticBitmap();
1041
1042 bool Create(wxWindow* parent, wxWindowID id,
1043 const wxBitmap& bitmap,
1044 const wxPoint& pos = wxDefaultPosition,
1045 const wxSize& size = wxDefaultSize,
1046 long style = 0,
1047 const wxString& name = wxPyStaticBitmapNameStr);
1048
1049 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1050 %pragma(python) addtomethod = "wxPreStaticBitmap:val._setOORInfo(val)"
1051
1052 wxBitmap GetBitmap();
1053 void SetBitmap(const wxBitmap& bitmap);
1054 void SetIcon(const wxIcon& icon);
1055 };
1056
1057 //----------------------------------------------------------------------
1058
1059 class wxRadioBox : public wxControl {
1060 public:
1061 wxRadioBox(wxWindow* parent, wxWindowID id,
1062 const wxString& label,
1063 const wxPoint& point = wxDefaultPosition,
1064 const wxSize& size = wxDefaultSize,
1065 int LCOUNT = 0, wxString* choices = NULL,
1066 int majorDimension = 0,
1067 long style = wxRA_HORIZONTAL,
1068 const wxValidator& validator = wxDefaultValidator,
1069 const wxString& name = wxPyRadioBoxNameStr);
1070 %name(wxPreRadioBox)wxRadioBox();
1071
1072 bool Create(wxWindow* parent, wxWindowID id,
1073 const wxString& label,
1074 const wxPoint& point = wxDefaultPosition,
1075 const wxSize& size = wxDefaultSize,
1076 int LCOUNT = 0, wxString* choices = NULL,
1077 int majorDimension = 0,
1078 long style = wxRA_HORIZONTAL,
1079 const wxValidator& validator = wxDefaultValidator,
1080 const wxString& name = wxPyRadioBoxNameStr);
1081
1082 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1083 %pragma(python) addtomethod = "wxPreRadioBox:val._setOORInfo(val)"
1084
1085 void Enable(bool enable);
1086 %name(EnableItem)void Enable(int n, bool enable);
1087 int FindString(const wxString& string);
1088
1089 wxString GetString(int n);
1090 void SetString(int n, const wxString& label);
1091 %pragma(python) addtoclass = "
1092 GetItemLabel = GetString
1093 SetItemLabel = SetString
1094 "
1095 #ifndef __WXGTK__
1096 int GetColumnCount();
1097 int GetRowCount();
1098 int GetNextItem(int item, wxDirection dir, long style);
1099 #endif
1100
1101 int GetSelection();
1102 wxString GetStringSelection();
1103 int GetCount();
1104 %pragma(python) addtoclass = "Number = GetCount"
1105
1106 void SetSelection(int n);
1107 void SetStringSelection(const wxString& string);
1108 void Show(bool show);
1109 %name(ShowItem)void Show(int item, bool show);
1110 };
1111
1112 //----------------------------------------------------------------------
1113
1114 class wxRadioButton : public wxControl {
1115 public:
1116 wxRadioButton(wxWindow* parent, wxWindowID id,
1117 const wxString& label,
1118 const wxPoint& pos = wxDefaultPosition,
1119 const wxSize& size = wxDefaultSize,
1120 long style = 0,
1121 const wxValidator& validator = wxDefaultValidator,
1122 const wxString& name = wxPyRadioButtonNameStr);
1123 %name(wxPreRadioButton)wxRadioButton();
1124
1125 bool Create(wxWindow* parent, wxWindowID id,
1126 const wxString& label,
1127 const wxPoint& pos = wxDefaultPosition,
1128 const wxSize& size = wxDefaultSize,
1129 long style = 0,
1130 const wxValidator& validator = wxDefaultValidator,
1131 const wxString& name = wxPyRadioButtonNameStr);
1132
1133 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1134 %pragma(python) addtomethod = "wxPreRadioButton:val._setOORInfo(val)"
1135
1136 bool GetValue();
1137 void SetValue(bool value);
1138 };
1139
1140 //----------------------------------------------------------------------
1141
1142 class wxSlider : public wxControl {
1143 public:
1144 wxSlider(wxWindow* parent, wxWindowID id,
1145 int value, int minValue, int maxValue,
1146 const wxPoint& point = wxDefaultPosition,
1147 const wxSize& size = wxDefaultSize,
1148 long style = wxSL_HORIZONTAL,
1149 const wxValidator& validator = wxDefaultValidator,
1150 const wxString& name = wxPySliderNameStr);
1151 %name(wxPreSlider)wxSlider();
1152
1153 bool Create(wxWindow* parent, wxWindowID id,
1154 int value, int minValue, int maxValue,
1155 const wxPoint& point = wxDefaultPosition,
1156 const wxSize& size = wxDefaultSize,
1157 long style = wxSL_HORIZONTAL,
1158 const wxValidator& validator = wxDefaultValidator,
1159 const wxString& name = wxPySliderNameStr);
1160
1161 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1162 %pragma(python) addtomethod = "wxPreSlider:val._setOORInfo(val)"
1163
1164 void ClearSel();
1165 void ClearTicks();
1166 int GetLineSize();
1167 int GetMax();
1168 int GetMin();
1169 int GetPageSize();
1170 int GetSelEnd();
1171 int GetSelStart();
1172 int GetThumbLength();
1173 int GetTickFreq();
1174 int GetValue();
1175 void SetRange(int minValue, int maxValue);
1176 void SetTickFreq(int n, int pos);
1177 void SetLineSize(int lineSize);
1178 void SetPageSize(int pageSize);
1179 void SetSelection(int startPos, int endPos);
1180 void SetThumbLength(int len);
1181 void SetTick(int tickPos);
1182 void SetValue(int value);
1183 };
1184
1185
1186 //----------------------------------------------------------------------
1187
1188 class wxSpinCtrl : public wxSpinButton {
1189 public:
1190 wxSpinCtrl(wxWindow *parent,
1191 wxWindowID id = -1,
1192 const wxString& value = wxPyEmptyString,
1193 const wxPoint& pos = wxDefaultPosition,
1194 const wxSize& size = wxDefaultSize,
1195 long style = wxSP_ARROW_KEYS,
1196 int min = 0, int max = 100, int initial = 0,
1197 const wxString& name = wxPySpinCtrlNameStr);
1198 %name(wxPreSpinCtrl)wxSpinCtrl();
1199
1200 bool Create(wxWindow *parent,
1201 wxWindowID id = -1,
1202 const wxString& value = wxPyEmptyString,
1203 const wxPoint& pos = wxDefaultPosition,
1204 const wxSize& size = wxDefaultSize,
1205 long style = wxSP_ARROW_KEYS,
1206 int min = 0, int max = 100, int initial = 0,
1207 const wxString& name = wxPySpinCtrlNameStr);
1208
1209 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1210 %pragma(python) addtomethod = "wxPreSpinCtrl:val._setOORInfo(val)"
1211
1212 int GetMax();
1213 int GetMin();
1214 int GetValue();
1215 void SetRange(int min, int max);
1216 void SetValue(int value);
1217 #ifdef __WXGTK__
1218 %addmethods {
1219 void SetSelection(long from, long to) {
1220 }
1221 }
1222 #else
1223 void SetSelection(long from, long to);
1224 #endif
1225 };
1226
1227
1228 //----------------------------------------------------------------------
1229
1230 #ifndef __WXMAC__
1231 enum { wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, };
1232
1233 class wxToggleButton : public wxControl {
1234 public:
1235 wxToggleButton(wxWindow *parent,
1236 wxWindowID id,
1237 const wxString& label,
1238 const wxPoint& pos = wxDefaultPosition,
1239 const wxSize& size = wxDefaultSize,
1240 long style = 0,
1241 const wxValidator& validator = wxDefaultValidator,
1242 const wxString& name = wxPyCheckBoxNameStr);
1243 %name(wxPreToggleButton)wxToggleButton();
1244
1245 bool Create(wxWindow *parent,
1246 wxWindowID id,
1247 const wxString& label,
1248 const wxPoint& pos = wxDefaultPosition,
1249 const wxSize& size = wxDefaultSize,
1250 long style = 0,
1251 const wxValidator& validator = wxDefaultValidator,
1252 const wxString& name = wxPyCheckBoxNameStr);
1253
1254 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1255 %pragma(python) addtomethod = "wxPreToggleButton:val._setOORInfo(val)"
1256
1257 void SetValue(bool value);
1258 bool GetValue() const ;
1259 void SetLabel(const wxString& label);
1260
1261 };
1262
1263 #endif
1264
1265 //----------------------------------------------------------------------
1266 //----------------------------------------------------------------------
1267 //----------------------------------------------------------------------
1268
1269
1270