1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Control (widget) classes for wxPython
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
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>
26 #include <wx/checklst.h>
31 #include <wx/checklst.h>
36 //----------------------------------------------------------------------
39 %include my_typemaps.i
41 // Import some definitions of other classes, etc.
48 %pragma(python) code = "import wx"
50 //----------------------------------------------------------------------
53 wxValidator wxDefaultValidator;
56 //----------------------------------------------------------------------
58 class wxControl : public wxWindow {
60 wxControl(wxWindow *parent,
62 const wxPoint& pos=wxDefaultPosition,
63 const wxSize& size=wxDefaultSize,
65 const wxValidator& validator=wxDefaultValidator,
66 const char* name="control");
67 %name(wxPreControl)wxControl();
69 bool Create(wxWindow *parent,
71 const wxPoint& pos=wxDefaultPosition,
72 const wxSize& size=wxDefaultSize,
74 const wxValidator& validator=wxDefaultValidator,
75 const char* name="control");
78 void Command(wxCommandEvent& event);
80 void SetLabel(const wxString& label);
84 //----------------------------------------------------------------------
86 class wxButton : public wxControl {
88 wxButton(wxWindow* parent, wxWindowID id, const wxString& label,
89 const wxPoint& pos = wxDefaultPosition,
90 const wxSize& size = wxDefaultSize,
92 const wxValidator& validator = wxDefaultValidator,
93 char* name = "button");
94 %name(wxPreButton)wxButton();
96 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
97 const wxPoint& pos = wxDefaultPosition,
98 const wxSize& size = wxDefaultSize,
100 const wxValidator& validator = wxDefaultValidator,
101 char* name = "button");
105 void SetBackgroundColour(const wxColour& colour);
106 void SetForegroundColour(const wxColour& colour);
108 void SetImageLabel(const wxBitmap& bitmap);
109 void SetImageMargins(wxCoord x, wxCoord y);
111 static wxSize GetDefaultSize();
114 //----------------------------------------------------------------------
116 class wxBitmapButton : public wxButton {
118 wxBitmapButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
119 const wxPoint& pos = wxDefaultPosition,
120 const wxSize& size = wxDefaultSize,
121 long style = wxBU_AUTODRAW,
122 const wxValidator& validator = wxDefaultValidator,
123 char* name = "button");
124 %name(wxPreBitmapButton)wxBitmapButton();
126 bool Create(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
127 const wxPoint& pos = wxDefaultPosition,
128 const wxSize& size = wxDefaultSize,
129 long style = wxBU_AUTODRAW,
130 const wxValidator& validator = wxDefaultValidator,
131 char* name = "button");
134 wxBitmap& GetBitmapLabel();
135 wxBitmap& GetBitmapDisabled();
136 wxBitmap& GetBitmapFocus();
137 wxBitmap& GetBitmapSelected();
138 void SetBitmapDisabled(const wxBitmap& bitmap);
139 void SetBitmapFocus(const wxBitmap& bitmap);
140 void SetBitmapSelected(const wxBitmap& bitmap);
141 void SetBitmapLabel(const wxBitmap& bitmap);
143 void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
144 int GetMarginX() const { return m_marginX; }
145 int GetMarginY() const { return m_marginY; }
148 //----------------------------------------------------------------------
150 class wxCheckBox : public wxControl {
152 wxCheckBox(wxWindow* parent, wxWindowID id, const wxString& label,
153 const wxPoint& pos = wxDefaultPosition,
154 const wxSize& size = wxDefaultSize,
156 const wxValidator& val = wxDefaultValidator,
157 char* name = "checkBox");
158 %name(wxPreCheckBox)wxCheckBox();
160 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
161 const wxPoint& pos = wxDefaultPosition,
162 const wxSize& size = wxDefaultSize,
164 const wxValidator& val = wxDefaultValidator,
165 char* name = "checkBox");
169 void SetValue(const bool state);
172 //----------------------------------------------------------------------
174 class wxChoice : public wxControl {
176 wxChoice(wxWindow *parent, wxWindowID id,
177 const wxPoint& pos = wxDefaultPosition,
178 const wxSize& size = wxDefaultSize,
179 int LCOUNT=0, wxString* choices=NULL,
181 const wxValidator& validator = wxDefaultValidator,
182 char* name = "choice");
183 %name(wxPreChoice)wxChoice();
185 bool Create(wxWindow *parent, wxWindowID id,
186 const wxPoint& pos = wxDefaultPosition,
187 const wxSize& size = wxDefaultSize,
188 int LCOUNT=0, wxString* choices=NULL,
190 const wxValidator& validator = wxDefaultValidator,
191 char* name = "choice");
194 void Append(const wxString& item);
197 int FindString(const wxString& string);
200 wxString GetString(const int n);
201 wxString GetStringSelection();
203 void SetColumns(const int n = 1);
204 void SetSelection(const int n);
205 void SetStringSelection(const wxString& string);
206 void SetString(int n, const wxString& s);
208 %pragma(python) addtoclass = "
210 Select = SetSelection
215 //----------------------------------------------------------------------
217 class wxComboBox : public wxChoice {
219 wxComboBox(wxWindow* parent, wxWindowID id, char* value = "",
220 const wxPoint& pos = wxDefaultPosition,
221 const wxSize& size = wxDefaultSize,
222 int LCOUNT=0, wxString* choices=NULL,
224 const wxValidator& validator = wxDefaultValidator,
225 char* name = "comboBox");
226 %name(wxPreComboBox)wxComboBox();
228 bool Create(wxWindow* parent, wxWindowID id, char* value = "",
229 const wxPoint& pos = wxDefaultPosition,
230 const wxSize& size = wxDefaultSize,
231 int LCOUNT=0, wxString* choices=NULL,
233 const wxValidator& validator = wxDefaultValidator,
234 char* name = "comboBox");
237 void Append(const wxString& item);
238 // TODO: void Append(const wxString& item, char* clientData);
243 // NotMember??: void Deselect(int n);
244 int FindString(const wxString& string);
245 // TODO: char* GetClientData(const int n);
246 long GetInsertionPoint();
247 long GetLastPosition();
249 wxString GetString(int n);
250 wxString GetStringSelection();
253 void Replace(long from, long to, const wxString& text);
254 void Remove(long from, long to);
255 // TODO: void SetClientData(const int n, char* data);
256 void SetInsertionPoint(long pos);
257 void SetInsertionPointEnd();
258 void SetSelection(int n);
259 %name(SetMark)void SetSelection(long from, long to);
260 void SetValue(const wxString& text);
261 void SetEditable(bool editable);
264 //----------------------------------------------------------------------
266 class wxGauge : public wxControl {
268 wxGauge(wxWindow* parent, wxWindowID id, int range,
269 const wxPoint& pos = wxDefaultPosition,
270 const wxSize& size = wxDefaultSize,
271 long style = wxGA_HORIZONTAL,
272 const wxValidator& validator = wxDefaultValidator,
273 char* name = "gauge");
274 %name(wxPreGauge)wxGauge();
276 bool Create(wxWindow* parent, wxWindowID id, int range,
277 const wxPoint& pos = wxDefaultPosition,
278 const wxSize& size = wxDefaultSize,
279 long style = wxGA_HORIZONTAL,
280 const wxValidator& validator = wxDefaultValidator,
281 char* name = "gauge");
286 int GetShadowWidth();
288 void SetBezelFace(int width);
289 void SetRange(int range);
290 void SetShadowWidth(int width);
291 void SetValue(int pos);
294 //----------------------------------------------------------------------
296 class wxStaticBox : public wxControl {
298 wxStaticBox(wxWindow* parent, wxWindowID id, const wxString& label,
299 const wxPoint& pos = wxDefaultPosition,
300 const wxSize& size = wxDefaultSize,
302 char* name = "staticBox");
303 %name(wxPreStaticBox)wxStaticBox();
305 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
306 const wxPoint& pos = wxDefaultPosition,
307 const wxSize& size = wxDefaultSize,
309 char* name = "staticBox");
313 //----------------------------------------------------------------------
316 class wxStaticLine : public wxControl {
318 wxStaticLine( wxWindow *parent, wxWindowID id,
319 const wxPoint &pos = wxDefaultPosition,
320 const wxSize &size = wxDefaultSize,
321 long style = wxLI_HORIZONTAL,
322 const char* name = "staticLine" );
323 %name(wxPreStaticLine)wxStaticLine();
325 bool Create( wxWindow *parent, wxWindowID id,
326 const wxPoint &pos = wxDefaultPosition,
327 const wxSize &size = wxDefaultSize,
328 long style = wxLI_HORIZONTAL,
329 const char* name = "staticLine" );
333 //----------------------------------------------------------------------
335 class wxStaticText : public wxControl {
337 wxStaticText(wxWindow* parent, wxWindowID id, const wxString& label,
338 const wxPoint& pos = wxDefaultPosition,
339 const wxSize& size = wxDefaultSize,
341 char* name = "staticText");
342 %name(wxPreStaticText)wxStaticText();
344 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
345 const wxPoint& pos = wxDefaultPosition,
346 const wxSize& size = wxDefaultSize,
348 char* name = "staticText");
352 void SetLabel(const wxString& label);
355 //----------------------------------------------------------------------
357 class wxListBox : public wxControl {
359 wxListBox(wxWindow* parent, wxWindowID id,
360 const wxPoint& pos = wxDefaultPosition,
361 const wxSize& size = wxDefaultSize,
362 int LCOUNT, wxString* choices = NULL,
364 const wxValidator& validator = wxDefaultValidator,
365 char* name = "listBox");
366 %name(wxPreListBox)wxListBox();
368 bool Create(wxWindow* parent, wxWindowID id,
369 const wxPoint& pos = wxDefaultPosition,
370 const wxSize& size = wxDefaultSize,
371 int LCOUNT, wxString* choices = NULL,
373 const wxValidator& validator = wxDefaultValidator,
374 char* name = "listBox");
377 void Append(const wxString& item);
378 // TODO: void Append(const wxString& item, char* clientData);
381 void Deselect(int n);
382 int FindString(const wxString& string);
383 // TODO: char* GetClientData(const int n);
386 // int GetSelections(int **selections);
388 PyObject* GetSelections() {
390 self->GetSelections(lst);
391 PyObject *tup = PyTuple_New(lst.GetCount());
392 for(size_t i=0; i<lst.GetCount(); i++) {
393 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
399 void InsertItems(int LCOUNT, wxString* choices, int pos);
401 wxString GetString(int n);
402 wxString GetStringSelection();
404 %pragma(python) addtoclass = "Number = GetCount"
405 bool IsSelected(const int n);
406 bool Selected(const int n);
407 void Set(int LCOUNT, wxString* choices);
408 // TODO: void SetClientData(const int n, char* data);
409 void SetFirstItem(int n);
410 %name(SetFirstItemStr)void SetFirstItem(const wxString& string);
411 void SetSelection(int n, bool select = TRUE);
412 void SetString(int n, const wxString& string);
413 void SetStringSelection(const wxString& string, bool select = TRUE);
417 //----------------------------------------------------------------------
419 class wxCheckListBox : public wxListBox {
421 wxCheckListBox(wxWindow *parent, wxWindowID id,
422 const wxPoint& pos = wxDefaultPosition,
423 const wxSize& size = wxDefaultSize,
425 wxString* choices = NULL,
427 const wxValidator& validator = wxDefaultValidator,
428 char* name = "listBox");
429 %name(wxPreCheckListBox)wxCheckListBox();
431 bool Create(wxWindow *parent, wxWindowID id,
432 const wxPoint& pos = wxDefaultPosition,
433 const wxSize& size = wxDefaultSize,
435 wxString* choices = NULL,
437 const wxValidator& validator = wxDefaultValidator,
438 char* name = "listBox");
441 bool IsChecked(int uiIndex);
442 void Check(int uiIndex, int bCheck = TRUE);
443 void InsertItems(int LCOUNT, wxString* choices, int pos);
448 //----------------------------------------------------------------------
455 wxTextAttr(const wxColour& colText = wxNullColour,
456 const wxColour& colBack = wxNullColour,
457 const wxFont& font = wxNullFont);
461 void SetTextColour(const wxColour& colText);
462 void SetBackgroundColour(const wxColour& colBack);
463 void SetFont(const wxFont& font);
466 bool HasTextColour() const;
467 bool HasBackgroundColour() const;
468 bool HasFont() const;
470 const wxColour& GetTextColour() const;
471 const wxColour& GetBackgroundColour() const;
472 const wxFont& GetFont() const;
477 class wxTextCtrl : public wxControl {
479 wxTextCtrl(wxWindow* parent, wxWindowID id, char* value = "",
480 const wxPoint& pos = wxDefaultPosition,
481 const wxSize& size = wxDefaultSize,
483 const wxValidator& validator = wxDefaultValidator,
484 char* name = "text");
485 %name(wxPreTextCtrl)wxTextCtrl();
487 bool Create(wxWindow* parent, wxWindowID id, char* value = "",
488 const wxPoint& pos = wxDefaultPosition,
489 const wxSize& size = wxDefaultSize,
491 const wxValidator& validator = wxDefaultValidator,
492 char* name = "text");
499 long GetInsertionPoint();
500 long GetLastPosition();
501 int GetLineLength(long lineNo);
502 wxString GetLineText(long lineNo);
503 int GetNumberOfLines();
506 bool LoadFile(const wxString& filename);
508 void PositionToXY(long pos, long *OUTPUT, long *OUTPUT);
509 void Remove(long from, long to);
510 void Replace(long from, long to, const wxString& value);
511 bool SaveFile(const wxString& filename);
512 void SetEditable(bool editable);
513 void SetInsertionPoint(long pos);
514 void SetInsertionPointEnd();
515 void SetSelection(long from, long to);
516 void SetValue(const wxString& value);
517 void ShowPosition(long pos);
518 void WriteText(const wxString& text);
519 void AppendText(const wxString& text);
520 long XYToPosition(long x, long y);
527 void GetSelection(long* OUTPUT, long* OUTPUT);
532 bool SetStyle(long start, long end, const wxTextAttr& style);
533 bool SetDefaultStyle(const wxTextAttr& style);
534 const wxTextAttr& GetDefaultStyle() const;
536 void SetMaxLength(unsigned long len);
539 void write(const wxString& text) {
540 self->AppendText(text);
545 //----------------------------------------------------------------------
547 class wxScrollBar : public wxControl {
549 wxScrollBar(wxWindow* parent, wxWindowID id = -1,
550 const wxPoint& pos = wxDefaultPosition,
551 const wxSize& size = wxDefaultSize,
552 long style = wxSB_HORIZONTAL,
553 const wxValidator& validator = wxDefaultValidator,
554 char* name = "scrollBar");
555 %name(wxPreScrollBar)wxScrollBar();
557 bool Create(wxWindow* parent, wxWindowID id = -1,
558 const wxPoint& pos = wxDefaultPosition,
559 const wxSize& size = wxDefaultSize,
560 long style = wxSB_HORIZONTAL,
561 const wxValidator& validator = wxDefaultValidator,
562 char* name = "scrollBar");
567 int GetThumbPosition();
569 %name(GetThumbLength) int GetThumbSize(); // to match the docs
570 void SetThumbPosition(int viewStart);
571 void SetScrollbar(int position, int thumbSize,
572 int range, int pageSize,
573 bool refresh = TRUE);
576 //----------------------------------------------------------------------
578 class wxSpinButton : public wxControl {
580 wxSpinButton(wxWindow* parent, wxWindowID id = -1,
581 const wxPoint& pos = wxDefaultPosition,
582 const wxSize& size = wxDefaultSize,
583 long style = wxSP_HORIZONTAL,
584 char* name = "spinButton");
585 %name(wxPreSpinButton)wxSpinButton();
587 bool Create(wxWindow* parent, wxWindowID id = -1,
588 const wxPoint& pos = wxDefaultPosition,
589 const wxSize& size = wxDefaultSize,
590 long style = wxSP_HORIZONTAL,
591 char* name = "spinButton");
596 void SetRange(int min, int max);
597 void SetValue(int value);
600 //----------------------------------------------------------------------
602 class wxStaticBitmap : public wxControl {
604 wxStaticBitmap(wxWindow* parent, wxWindowID id,
605 const wxBitmap& bitmap,
606 const wxPoint& pos = wxDefaultPosition,
607 const wxSize& size = wxDefaultSize,
609 char* name = "staticBitmap");
610 %name(wxPreStaticBitmap)wxStaticBitmap();
612 bool Create(wxWindow* parent, wxWindowID id,
613 const wxBitmap& bitmap,
614 const wxPoint& pos = wxDefaultPosition,
615 const wxSize& size = wxDefaultSize,
617 char* name = "staticBitmap");
620 const wxBitmap& GetBitmap();
621 void SetBitmap(const wxBitmap& bitmap);
622 void SetIcon(const wxIcon& icon);
625 //----------------------------------------------------------------------
627 class wxRadioBox : public wxControl {
629 wxRadioBox(wxWindow* parent, wxWindowID id,
630 const wxString& label,
631 const wxPoint& point = wxDefaultPosition,
632 const wxSize& size = wxDefaultSize,
633 int LCOUNT = 0, wxString* choices = NULL,
634 int majorDimension = 0,
635 long style = wxRA_HORIZONTAL,
636 const wxValidator& validator = wxDefaultValidator,
637 char* name = "radioBox");
638 %name(wxPreRadioBox)wxRadioBox();
640 bool Create(wxWindow* parent, wxWindowID id,
641 const wxString& label,
642 const wxPoint& point = wxDefaultPosition,
643 const wxSize& size = wxDefaultSize,
644 int LCOUNT = 0, wxString* choices = NULL,
645 int majorDimension = 0,
646 long style = wxRA_HORIZONTAL,
647 const wxValidator& validator = wxDefaultValidator,
648 char* name = "radioBox");
651 void Enable(bool enable);
652 %name(EnableItem)void Enable(int n, bool enable);
653 int FindString(const wxString& string);
655 wxString GetString(int n);
658 void SetString(int n, const wxString& label);
659 %pragma(python) addtoclass = "
660 GetItemLabel = GetString
661 SetItemLabel = SetString
663 int GetColumnCount();
666 %name(GetItemLabel)wxString GetLabel( int item );
667 %name(SetItemLabel)void SetLabel( int item, const wxString& label );
671 wxString GetStringSelection();
673 %pragma(python) addtoclass = "Number = GetCount"
675 void SetSelection(int n);
676 void SetStringSelection(const wxString& string);
677 void Show(bool show);
678 %name(ShowItem)void Show(int item, bool show);
681 //----------------------------------------------------------------------
683 class wxRadioButton : public wxControl {
685 wxRadioButton(wxWindow* parent, wxWindowID id,
686 const wxString& label,
687 const wxPoint& pos = wxDefaultPosition,
688 const wxSize& size = wxDefaultSize,
690 const wxValidator& validator = wxDefaultValidator,
691 char* name = "radioButton");
692 %name(wxPreRadioButton)wxRadioButton();
694 bool Create(wxWindow* parent, wxWindowID id,
695 const wxString& label,
696 const wxPoint& pos = wxDefaultPosition,
697 const wxSize& size = wxDefaultSize,
699 const wxValidator& validator = wxDefaultValidator,
700 char* name = "radioButton");
704 void SetValue(bool value);
707 //----------------------------------------------------------------------
709 class wxSlider : public wxControl {
711 wxSlider(wxWindow* parent, wxWindowID id,
712 int value, int minValue, int maxValue,
713 const wxPoint& point = wxDefaultPosition,
714 const wxSize& size = wxDefaultSize,
715 long style = wxSL_HORIZONTAL,
716 const wxValidator& validator = wxDefaultValidator,
717 char* name = "slider");
718 %name(wxPreSlider)wxSlider();
720 bool Create(wxWindow* parent, wxWindowID id,
721 int value, int minValue, int maxValue,
722 const wxPoint& point = wxDefaultPosition,
723 const wxSize& size = wxDefaultSize,
724 long style = wxSL_HORIZONTAL,
725 const wxValidator& validator = wxDefaultValidator,
726 char* name = "slider");
737 int GetThumbLength();
740 void SetRange(int minValue, int maxValue);
741 void SetTickFreq(int n, int pos);
742 void SetLineSize(int lineSize);
743 void SetPageSize(int pageSize);
744 void SetSelection(int startPos, int endPos);
745 void SetThumbLength(int len);
746 void SetTick(int tickPos);
747 void SetValue(int value);
751 //----------------------------------------------------------------------
753 class wxSpinCtrl : public wxSpinButton {
755 wxSpinCtrl(wxWindow *parent,
757 const char* value = "",
758 const wxPoint& pos = wxDefaultPosition,
759 const wxSize& size = wxDefaultSize,
760 long style = wxSP_ARROW_KEYS,
761 int min = 0, int max = 100, int initial = 0,
762 const char* name = "wxSpinCtrl");
763 %name(wxPreSpinCtrl)wxSpinCtrl();
765 bool Create(wxWindow *parent,
767 const char* value = "",
768 const wxPoint& pos = wxDefaultPosition,
769 const wxSize& size = wxDefaultSize,
770 long style = wxSP_ARROW_KEYS,
771 int min = 0, int max = 100, int initial = 0,
772 const char* name = "wxSpinCtrl");
778 void SetRange(int min, int max);
779 void SetValue(int value);
784 //----------------------------------------------------------------------
786 enum { wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, };
788 class wxToggleButton : public wxControl {
790 wxToggleButton(wxWindow *parent,
792 const wxString& label,
793 const wxPoint& pos = wxDefaultPosition,
794 const wxSize& size = wxDefaultSize,
796 const wxValidator& validator = wxDefaultValidator,
797 const char* name = "toggle");
798 %name(wxPreToggleButton)wxToggleButton();
800 bool Create(wxWindow *parent,
802 const wxString& label,
803 const wxPoint& pos = wxDefaultPosition,
804 const wxSize& size = wxDefaultSize,
806 const wxValidator& validator = wxDefaultValidator,
807 const char* name = "toggle");
809 void SetValue(bool value);
810 bool GetValue() const ;
811 void SetLabel(const wxString& label);
815 //----------------------------------------------------------------------
816 //----------------------------------------------------------------------
817 //----------------------------------------------------------------------