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 //----------------------------------------------------------------------
87 class wxControlWithItems : public wxControl {
90 // void Clear(); ambiguous, redefine below...
94 %pragma(python) addtoclass = "Number = GetCount"
95 wxString GetString(int n);
96 void SetString(int n, const wxString& s);
97 int FindString(const wxString& s);
102 wxString GetStringSelection() const;
104 // void Append(const wxString& item);
105 // void Append(const wxString& item, char* clientData);
106 // char* GetClientData(const int n);
107 // void SetClientData(const int n, char* data);
109 void Append(const wxString& item, PyObject* clientData=NULL) {
111 wxPyClientData* data = new wxPyClientData(clientData);
112 self->Append(item, data);
117 PyObject* GetClientData(int n) {
118 wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n);
120 Py_INCREF(data->m_obj);
128 void SetClientData(int n, PyObject* clientData) {
129 wxPyClientData* data = new wxPyClientData(clientData);
130 self->SetClientObject(n, data);
135 //----------------------------------------------------------------------
137 class wxButton : public wxControl {
139 wxButton(wxWindow* parent, wxWindowID id, const wxString& label,
140 const wxPoint& pos = wxDefaultPosition,
141 const wxSize& size = wxDefaultSize,
143 const wxValidator& validator = wxDefaultValidator,
144 char* name = "button");
145 %name(wxPreButton)wxButton();
147 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
148 const wxPoint& pos = wxDefaultPosition,
149 const wxSize& size = wxDefaultSize,
151 const wxValidator& validator = wxDefaultValidator,
152 char* name = "button");
156 void SetBackgroundColour(const wxColour& colour);
157 void SetForegroundColour(const wxColour& colour);
159 void SetImageLabel(const wxBitmap& bitmap);
160 void SetImageMargins(wxCoord x, wxCoord y);
162 static wxSize GetDefaultSize();
165 //----------------------------------------------------------------------
167 class wxBitmapButton : public wxButton {
169 wxBitmapButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
170 const wxPoint& pos = wxDefaultPosition,
171 const wxSize& size = wxDefaultSize,
172 long style = wxBU_AUTODRAW,
173 const wxValidator& validator = wxDefaultValidator,
174 char* name = "button");
175 %name(wxPreBitmapButton)wxBitmapButton();
177 bool Create(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
180 long style = wxBU_AUTODRAW,
181 const wxValidator& validator = wxDefaultValidator,
182 char* name = "button");
185 wxBitmap& GetBitmapLabel();
186 wxBitmap& GetBitmapDisabled();
187 wxBitmap& GetBitmapFocus();
188 wxBitmap& GetBitmapSelected();
189 void SetBitmapDisabled(const wxBitmap& bitmap);
190 void SetBitmapFocus(const wxBitmap& bitmap);
191 void SetBitmapSelected(const wxBitmap& bitmap);
192 void SetBitmapLabel(const wxBitmap& bitmap);
194 void SetMargins(int x, int y) { m_marginX = x; m_marginY = y; }
195 int GetMarginX() const { return m_marginX; }
196 int GetMarginY() const { return m_marginY; }
199 //----------------------------------------------------------------------
201 class wxCheckBox : public wxControl {
203 wxCheckBox(wxWindow* parent, wxWindowID id, const wxString& label,
204 const wxPoint& pos = wxDefaultPosition,
205 const wxSize& size = wxDefaultSize,
207 const wxValidator& val = wxDefaultValidator,
208 char* name = "checkBox");
209 %name(wxPreCheckBox)wxCheckBox();
211 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
212 const wxPoint& pos = wxDefaultPosition,
213 const wxSize& size = wxDefaultSize,
215 const wxValidator& val = wxDefaultValidator,
216 char* name = "checkBox");
220 void SetValue(const bool state);
223 //----------------------------------------------------------------------
225 class wxChoice : public wxControlWithItems {
227 wxChoice(wxWindow *parent, wxWindowID id,
228 const wxPoint& pos = wxDefaultPosition,
229 const wxSize& size = wxDefaultSize,
230 int LCOUNT=0, wxString* choices=NULL,
232 const wxValidator& validator = wxDefaultValidator,
233 char* name = "choice");
234 %name(wxPreChoice)wxChoice();
236 bool Create(wxWindow *parent, wxWindowID id,
237 const wxPoint& pos = wxDefaultPosition,
238 const wxSize& size = wxDefaultSize,
239 int LCOUNT=0, wxString* choices=NULL,
241 const wxValidator& validator = wxDefaultValidator,
242 char* name = "choice");
247 void SetColumns(const int n = 1);
248 void SetSelection(const int n);
249 void SetStringSelection(const wxString& string);
250 void SetString(int n, const wxString& s);
252 %pragma(python) addtoclass = "
253 Select = SetSelection
257 //----------------------------------------------------------------------
259 class wxComboBox : public wxChoice {
261 wxComboBox(wxWindow* parent, wxWindowID id, char* value = "",
262 const wxPoint& pos = wxDefaultPosition,
263 const wxSize& size = wxDefaultSize,
264 int LCOUNT=0, wxString* choices=NULL,
266 const wxValidator& validator = wxDefaultValidator,
267 char* name = "comboBox");
268 %name(wxPreComboBox)wxComboBox();
270 bool Create(wxWindow* parent, wxWindowID id, char* value = "",
271 const wxPoint& pos = wxDefaultPosition,
272 const wxSize& size = wxDefaultSize,
273 int LCOUNT=0, wxString* choices=NULL,
275 const wxValidator& validator = wxDefaultValidator,
276 char* name = "comboBox");
281 long GetInsertionPoint();
282 long GetLastPosition();
285 void Replace(long from, long to, const wxString& text);
286 void Remove(long from, long to);
287 void SetInsertionPoint(long pos);
288 void SetInsertionPointEnd();
289 void SetSelection(int n);
290 %name(SetMark)void SetSelection(long from, long to);
291 void SetValue(const wxString& text);
292 void SetEditable(bool editable);
295 //----------------------------------------------------------------------
297 class wxGauge : public wxControl {
299 wxGauge(wxWindow* parent, wxWindowID id, int range,
300 const wxPoint& pos = wxDefaultPosition,
301 const wxSize& size = wxDefaultSize,
302 long style = wxGA_HORIZONTAL,
303 const wxValidator& validator = wxDefaultValidator,
304 char* name = "gauge");
305 %name(wxPreGauge)wxGauge();
307 bool Create(wxWindow* parent, wxWindowID id, int range,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
310 long style = wxGA_HORIZONTAL,
311 const wxValidator& validator = wxDefaultValidator,
312 char* name = "gauge");
317 int GetShadowWidth();
319 void SetBezelFace(int width);
320 void SetRange(int range);
321 void SetShadowWidth(int width);
322 void SetValue(int pos);
325 //----------------------------------------------------------------------
327 class wxStaticBox : public wxControl {
329 wxStaticBox(wxWindow* parent, wxWindowID id, const wxString& label,
330 const wxPoint& pos = wxDefaultPosition,
331 const wxSize& size = wxDefaultSize,
333 char* name = "staticBox");
334 %name(wxPreStaticBox)wxStaticBox();
336 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
337 const wxPoint& pos = wxDefaultPosition,
338 const wxSize& size = wxDefaultSize,
340 char* name = "staticBox");
344 //----------------------------------------------------------------------
347 class wxStaticLine : public wxControl {
349 wxStaticLine( wxWindow *parent, wxWindowID id,
350 const wxPoint &pos = wxDefaultPosition,
351 const wxSize &size = wxDefaultSize,
352 long style = wxLI_HORIZONTAL,
353 const char* name = "staticLine" );
354 %name(wxPreStaticLine)wxStaticLine();
356 bool Create( wxWindow *parent, wxWindowID id,
357 const wxPoint &pos = wxDefaultPosition,
358 const wxSize &size = wxDefaultSize,
359 long style = wxLI_HORIZONTAL,
360 const char* name = "staticLine" );
364 //----------------------------------------------------------------------
366 class wxStaticText : public wxControl {
368 wxStaticText(wxWindow* parent, wxWindowID id, const wxString& label,
369 const wxPoint& pos = wxDefaultPosition,
370 const wxSize& size = wxDefaultSize,
372 char* name = "staticText");
373 %name(wxPreStaticText)wxStaticText();
375 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
376 const wxPoint& pos = wxDefaultPosition,
377 const wxSize& size = wxDefaultSize,
379 char* name = "staticText");
383 void SetLabel(const wxString& label);
386 //----------------------------------------------------------------------
388 class wxListBox : public wxControlWithItems {
390 wxListBox(wxWindow* parent, wxWindowID id,
391 const wxPoint& pos = wxDefaultPosition,
392 const wxSize& size = wxDefaultSize,
393 int LCOUNT, wxString* choices = NULL,
395 const wxValidator& validator = wxDefaultValidator,
396 char* name = "listBox");
397 %name(wxPreListBox)wxListBox();
399 bool Create(wxWindow* parent, wxWindowID id,
400 const wxPoint& pos = wxDefaultPosition,
401 const wxSize& size = wxDefaultSize,
402 int LCOUNT, wxString* choices = NULL,
404 const wxValidator& validator = wxDefaultValidator,
405 char* name = "listBox");
408 void Deselect(int n);
410 // int GetSelections(int **selections);
412 PyObject* GetSelections() {
414 self->GetSelections(lst);
415 PyObject *tup = PyTuple_New(lst.GetCount());
416 for(size_t i=0; i<lst.GetCount(); i++) {
417 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
424 void InsertItems(int LCOUNT, wxString* choices, int pos);
426 bool IsSelected(const int n);
427 bool Selected(const int n);
428 void Set(int LCOUNT, wxString* choices);
429 void SetFirstItem(int n);
430 %name(SetFirstItemStr)void SetFirstItem(const wxString& string);
431 void SetSelection(int n, bool select = TRUE);
432 void SetString(int n, const wxString& string);
433 void SetStringSelection(const wxString& string, bool select = TRUE);
437 //----------------------------------------------------------------------
439 class wxCheckListBox : public wxListBox {
441 wxCheckListBox(wxWindow *parent, wxWindowID id,
442 const wxPoint& pos = wxDefaultPosition,
443 const wxSize& size = wxDefaultSize,
445 wxString* choices = NULL,
447 const wxValidator& validator = wxDefaultValidator,
448 char* name = "listBox");
449 %name(wxPreCheckListBox)wxCheckListBox();
451 bool Create(wxWindow *parent, wxWindowID id,
452 const wxPoint& pos = wxDefaultPosition,
453 const wxSize& size = wxDefaultSize,
455 wxString* choices = NULL,
457 const wxValidator& validator = wxDefaultValidator,
458 char* name = "listBox");
461 bool IsChecked(int uiIndex);
462 void Check(int uiIndex, int bCheck = TRUE);
463 void InsertItems(int LCOUNT, wxString* choices, int pos);
468 //----------------------------------------------------------------------
475 wxTextAttr(const wxColour& colText = wxNullColour,
476 const wxColour& colBack = wxNullColour,
477 const wxFont& font = wxNullFont);
481 void SetTextColour(const wxColour& colText);
482 void SetBackgroundColour(const wxColour& colBack);
483 void SetFont(const wxFont& font);
486 bool HasTextColour() const;
487 bool HasBackgroundColour() const;
488 bool HasFont() const;
490 const wxColour& GetTextColour() const;
491 const wxColour& GetBackgroundColour() const;
492 const wxFont& GetFont() const;
497 class wxTextCtrl : public wxControl {
499 wxTextCtrl(wxWindow* parent, wxWindowID id, char* value = "",
500 const wxPoint& pos = wxDefaultPosition,
501 const wxSize& size = wxDefaultSize,
503 const wxValidator& validator = wxDefaultValidator,
504 char* name = "text");
505 %name(wxPreTextCtrl)wxTextCtrl();
507 bool Create(wxWindow* parent, wxWindowID id, char* value = "",
508 const wxPoint& pos = wxDefaultPosition,
509 const wxSize& size = wxDefaultSize,
511 const wxValidator& validator = wxDefaultValidator,
512 char* name = "text");
519 long GetInsertionPoint();
520 long GetLastPosition();
521 int GetLineLength(long lineNo);
522 wxString GetLineText(long lineNo);
523 int GetNumberOfLines();
526 bool LoadFile(const wxString& filename);
528 void PositionToXY(long pos, long *OUTPUT, long *OUTPUT);
529 void Remove(long from, long to);
530 void Replace(long from, long to, const wxString& value);
531 bool SaveFile(const wxString& filename);
532 void SetEditable(bool editable);
533 void SetInsertionPoint(long pos);
534 void SetInsertionPointEnd();
535 void SetSelection(long from, long to);
536 void SetValue(const wxString& value);
537 void ShowPosition(long pos);
538 void WriteText(const wxString& text);
539 void AppendText(const wxString& text);
540 long XYToPosition(long x, long y);
547 void GetSelection(long* OUTPUT, long* OUTPUT);
552 bool SetStyle(long start, long end, const wxTextAttr& style);
553 bool SetDefaultStyle(const wxTextAttr& style);
554 const wxTextAttr& GetDefaultStyle() const;
556 void SetMaxLength(unsigned long len);
559 void write(const wxString& text) {
560 self->AppendText(text);
565 //----------------------------------------------------------------------
567 class wxScrollBar : public wxControl {
569 wxScrollBar(wxWindow* parent, wxWindowID id = -1,
570 const wxPoint& pos = wxDefaultPosition,
571 const wxSize& size = wxDefaultSize,
572 long style = wxSB_HORIZONTAL,
573 const wxValidator& validator = wxDefaultValidator,
574 char* name = "scrollBar");
575 %name(wxPreScrollBar)wxScrollBar();
577 bool Create(wxWindow* parent, wxWindowID id = -1,
578 const wxPoint& pos = wxDefaultPosition,
579 const wxSize& size = wxDefaultSize,
580 long style = wxSB_HORIZONTAL,
581 const wxValidator& validator = wxDefaultValidator,
582 char* name = "scrollBar");
587 int GetThumbPosition();
589 %name(GetThumbLength) int GetThumbSize(); // to match the docs
590 void SetThumbPosition(int viewStart);
591 void SetScrollbar(int position, int thumbSize,
592 int range, int pageSize,
593 bool refresh = TRUE);
596 //----------------------------------------------------------------------
598 class wxSpinButton : public wxControl {
600 wxSpinButton(wxWindow* parent, wxWindowID id = -1,
601 const wxPoint& pos = wxDefaultPosition,
602 const wxSize& size = wxDefaultSize,
603 long style = wxSP_HORIZONTAL,
604 char* name = "spinButton");
605 %name(wxPreSpinButton)wxSpinButton();
607 bool Create(wxWindow* parent, wxWindowID id = -1,
608 const wxPoint& pos = wxDefaultPosition,
609 const wxSize& size = wxDefaultSize,
610 long style = wxSP_HORIZONTAL,
611 char* name = "spinButton");
616 void SetRange(int min, int max);
617 void SetValue(int value);
620 //----------------------------------------------------------------------
622 class wxStaticBitmap : public wxControl {
624 wxStaticBitmap(wxWindow* parent, wxWindowID id,
625 const wxBitmap& bitmap,
626 const wxPoint& pos = wxDefaultPosition,
627 const wxSize& size = wxDefaultSize,
629 char* name = "staticBitmap");
630 %name(wxPreStaticBitmap)wxStaticBitmap();
632 bool Create(wxWindow* parent, wxWindowID id,
633 const wxBitmap& bitmap,
634 const wxPoint& pos = wxDefaultPosition,
635 const wxSize& size = wxDefaultSize,
637 char* name = "staticBitmap");
640 const wxBitmap& GetBitmap();
641 void SetBitmap(const wxBitmap& bitmap);
642 void SetIcon(const wxIcon& icon);
645 //----------------------------------------------------------------------
647 class wxRadioBox : public wxControl {
649 wxRadioBox(wxWindow* parent, wxWindowID id,
650 const wxString& label,
651 const wxPoint& point = wxDefaultPosition,
652 const wxSize& size = wxDefaultSize,
653 int LCOUNT = 0, wxString* choices = NULL,
654 int majorDimension = 0,
655 long style = wxRA_HORIZONTAL,
656 const wxValidator& validator = wxDefaultValidator,
657 char* name = "radioBox");
658 %name(wxPreRadioBox)wxRadioBox();
660 bool Create(wxWindow* parent, wxWindowID id,
661 const wxString& label,
662 const wxPoint& point = wxDefaultPosition,
663 const wxSize& size = wxDefaultSize,
664 int LCOUNT = 0, wxString* choices = NULL,
665 int majorDimension = 0,
666 long style = wxRA_HORIZONTAL,
667 const wxValidator& validator = wxDefaultValidator,
668 char* name = "radioBox");
671 void Enable(bool enable);
672 %name(EnableItem)void Enable(int n, bool enable);
673 int FindString(const wxString& string);
675 wxString GetString(int n);
678 void SetString(int n, const wxString& label);
679 %pragma(python) addtoclass = "
680 GetItemLabel = GetString
681 SetItemLabel = SetString
683 int GetColumnCount();
686 %name(GetItemLabel)wxString GetLabel( int item );
687 %name(SetItemLabel)void SetLabel( int item, const wxString& label );
691 wxString GetStringSelection();
693 %pragma(python) addtoclass = "Number = GetCount"
695 void SetSelection(int n);
696 void SetStringSelection(const wxString& string);
697 void Show(bool show);
698 %name(ShowItem)void Show(int item, bool show);
701 //----------------------------------------------------------------------
703 class wxRadioButton : public wxControl {
705 wxRadioButton(wxWindow* parent, wxWindowID id,
706 const wxString& label,
707 const wxPoint& pos = wxDefaultPosition,
708 const wxSize& size = wxDefaultSize,
710 const wxValidator& validator = wxDefaultValidator,
711 char* name = "radioButton");
712 %name(wxPreRadioButton)wxRadioButton();
714 bool Create(wxWindow* parent, wxWindowID id,
715 const wxString& label,
716 const wxPoint& pos = wxDefaultPosition,
717 const wxSize& size = wxDefaultSize,
719 const wxValidator& validator = wxDefaultValidator,
720 char* name = "radioButton");
724 void SetValue(bool value);
727 //----------------------------------------------------------------------
729 class wxSlider : public wxControl {
731 wxSlider(wxWindow* parent, wxWindowID id,
732 int value, int minValue, int maxValue,
733 const wxPoint& point = wxDefaultPosition,
734 const wxSize& size = wxDefaultSize,
735 long style = wxSL_HORIZONTAL,
736 const wxValidator& validator = wxDefaultValidator,
737 char* name = "slider");
738 %name(wxPreSlider)wxSlider();
740 bool Create(wxWindow* parent, wxWindowID id,
741 int value, int minValue, int maxValue,
742 const wxPoint& point = wxDefaultPosition,
743 const wxSize& size = wxDefaultSize,
744 long style = wxSL_HORIZONTAL,
745 const wxValidator& validator = wxDefaultValidator,
746 char* name = "slider");
757 int GetThumbLength();
760 void SetRange(int minValue, int maxValue);
761 void SetTickFreq(int n, int pos);
762 void SetLineSize(int lineSize);
763 void SetPageSize(int pageSize);
764 void SetSelection(int startPos, int endPos);
765 void SetThumbLength(int len);
766 void SetTick(int tickPos);
767 void SetValue(int value);
771 //----------------------------------------------------------------------
773 class wxSpinCtrl : public wxSpinButton {
775 wxSpinCtrl(wxWindow *parent,
777 const char* value = "",
778 const wxPoint& pos = wxDefaultPosition,
779 const wxSize& size = wxDefaultSize,
780 long style = wxSP_ARROW_KEYS,
781 int min = 0, int max = 100, int initial = 0,
782 const char* name = "wxSpinCtrl");
783 %name(wxPreSpinCtrl)wxSpinCtrl();
785 bool Create(wxWindow *parent,
787 const char* value = "",
788 const wxPoint& pos = wxDefaultPosition,
789 const wxSize& size = wxDefaultSize,
790 long style = wxSP_ARROW_KEYS,
791 int min = 0, int max = 100, int initial = 0,
792 const char* name = "wxSpinCtrl");
798 void SetRange(int min, int max);
799 void SetValue(int value);
804 //----------------------------------------------------------------------
806 enum { wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, };
808 class wxToggleButton : public wxControl {
810 wxToggleButton(wxWindow *parent,
812 const wxString& label,
813 const wxPoint& pos = wxDefaultPosition,
814 const wxSize& size = wxDefaultSize,
816 const wxValidator& validator = wxDefaultValidator,
817 const char* name = "toggle");
818 %name(wxPreToggleButton)wxToggleButton();
820 bool Create(wxWindow *parent,
822 const wxString& label,
823 const wxPoint& pos = wxDefaultPosition,
824 const wxSize& size = wxDefaultSize,
826 const wxValidator& validator = wxDefaultValidator,
827 const char* name = "toggle");
829 void SetValue(bool value);
830 bool GetValue() const ;
831 void SetLabel(const wxString& label);
835 //----------------------------------------------------------------------
836 //----------------------------------------------------------------------
837 //----------------------------------------------------------------------