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/dynarray.h>
20 #include <wx/statline.h>
24 #include <wx/checklst.h>
29 #include <wx/checklst.h>
34 //----------------------------------------------------------------------
37 %include my_typemaps.i
39 // Import some definitions of other classes, etc.
46 %pragma(python) code = "import wx"
48 //----------------------------------------------------------------------
51 wxValidator wxPyDefaultValidator; // Non-const default because of SWIG
54 //----------------------------------------------------------------------
56 class wxControl : public wxWindow {
59 void Command(wxCommandEvent& event);
62 void SetLabel(const wxString& label);
65 //----------------------------------------------------------------------
67 class wxButton : public wxControl {
69 wxButton(wxWindow* parent, wxWindowID id, const wxString& label,
70 const wxPoint& pos = wxPyDefaultPosition,
71 const wxSize& size = wxPyDefaultSize,
73 const wxValidator& validator = wxPyDefaultValidator,
74 char* name = "button");
76 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
81 //----------------------------------------------------------------------
83 class wxBitmapButton : public wxButton {
85 wxBitmapButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap,
86 const wxPoint& pos = wxPyDefaultPosition,
87 const wxSize& size = wxPyDefaultSize,
88 long style = wxBU_AUTODRAW,
89 const wxValidator& validator = wxPyDefaultValidator,
90 char* name = "button");
92 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
94 wxBitmap& GetBitmapLabel();
95 wxBitmap& GetBitmapDisabled();
96 wxBitmap& GetBitmapFocus();
97 wxBitmap& GetBitmapSelected();
98 void SetBitmapDisabled(const wxBitmap& bitmap);
99 void SetBitmapFocus(const wxBitmap& bitmap);
100 void SetBitmapSelected(const wxBitmap& bitmap);
101 void SetBitmapLabel(const wxBitmap& bitmap);
105 //----------------------------------------------------------------------
107 class wxCheckBox : public wxControl {
109 wxCheckBox(wxWindow* parent, wxWindowID id, const wxString& label,
110 const wxPoint& pos = wxPyDefaultPosition,
111 const wxSize& size = wxPyDefaultSize,
113 const wxValidator& val = wxPyDefaultValidator,
114 char* name = "checkBox");
116 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
119 void SetValue(const bool state);
122 //----------------------------------------------------------------------
124 class wxChoice : public wxControl {
126 wxChoice(wxWindow *parent, wxWindowID id,
127 const wxPoint& pos = wxPyDefaultPosition,
128 const wxSize& size = wxPyDefaultSize,
129 int LCOUNT=0, wxString* LIST=NULL,
131 const wxValidator& validator = wxPyDefaultValidator,
132 char* name = "choice");
134 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
136 void Append(const wxString& item);
138 int FindString(const wxString& string);
141 wxString GetString(const int n);
142 wxString GetStringSelection();
144 void SetColumns(const int n = 1);
145 void SetSelection(const int n);
146 void SetStringSelection(const wxString& string);
149 //----------------------------------------------------------------------
151 class wxComboBox : public wxChoice {
153 wxComboBox(wxWindow* parent, wxWindowID id, char* value = "",
154 const wxPoint& pos = wxPyDefaultPosition,
155 const wxSize& size = wxPyDefaultSize,
156 int LCOUNT=0, wxString* LIST=NULL,
158 const wxValidator& validator = wxPyDefaultValidator,
159 char* name = "comboBox");
161 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
163 void Append(const wxString& item);
164 // TODO: void Append(const wxString& item, char* clientData);
169 // NotMember??: void Deselect(int n);
170 int FindString(const wxString& string);
171 // TODO: char* GetClientData(const int n);
172 long GetInsertionPoint();
173 long GetLastPosition();
175 wxString GetString(int n);
176 wxString GetStringSelection();
180 void Replace(long from, long to, const wxString& text);
181 void Remove(long from, long to);
182 // TODO: void SetClientData(const int n, char* data);
183 void SetInsertionPoint(long pos);
184 void SetInsertionPointEnd();
185 //void SetSelection(int n, int select = TRUE); **** Just use the one in wxChoice
186 %name(SetMark)void SetSelection(long from, long to);
187 void SetValue(const wxString& text);
190 //----------------------------------------------------------------------
192 class wxGauge : public wxControl {
194 wxGauge(wxWindow* parent, wxWindowID id, int range,
195 const wxPoint& pos = wxPyDefaultPosition,
196 const wxSize& size = wxPyDefaultSize,
197 long style = wxGA_HORIZONTAL,
198 const wxValidator& validator = wxPyDefaultValidator,
199 char* name = "gauge");
201 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
205 int GetShadowWidth();
207 void SetBezelFace(int width);
208 void SetRange(int range);
209 void SetShadowWidth(int width);
210 void SetValue(int pos);
213 //----------------------------------------------------------------------
215 class wxStaticBox : public wxControl {
217 wxStaticBox(wxWindow* parent, wxWindowID id, const wxString& label,
218 const wxPoint& pos = wxPyDefaultPosition,
219 const wxSize& size = wxPyDefaultSize,
221 char* name = "staticBox");
225 //----------------------------------------------------------------------
228 class wxStaticLine : public wxControl {
230 wxStaticLine( wxWindow *parent, wxWindowID id,
231 const wxPoint &pos = wxPyDefaultPosition,
232 const wxSize &size = wxPyDefaultSize,
233 long style = wxLI_HORIZONTAL,
234 const char* name = "staticLine" );
238 //----------------------------------------------------------------------
240 class wxStaticText : public wxControl {
242 wxStaticText(wxWindow* parent, wxWindowID id, const wxString& label,
243 const wxPoint& pos = wxPyDefaultPosition,
244 const wxSize& size = wxPyDefaultSize,
246 char* name = "staticText");
248 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
251 void SetLabel(const wxString& label);
254 //----------------------------------------------------------------------
256 class wxListBox : public wxControl {
258 wxListBox(wxWindow* parent, wxWindowID id,
259 const wxPoint& pos = wxPyDefaultPosition,
260 const wxSize& size = wxPyDefaultSize,
261 int LCOUNT, wxString* LIST = NULL,
263 const wxValidator& validator = wxPyDefaultValidator,
264 char* name = "listBox");
266 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
268 void Append(const wxString& item);
269 // TODO: void Append(const wxString& item, char* clientData);
272 void Deselect(int n);
273 int FindString(const wxString& string);
274 // TODO: char* GetClientData(const int n);
277 // int GetSelections(int **selections);
279 PyObject* GetSelections() {
281 self->GetSelections(lst);
282 PyObject *tup = PyTuple_New(lst.GetCount());
283 for(int i=0; i<lst.GetCount(); i++) {
284 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
290 wxString GetString(int n);
291 wxString GetStringSelection();
293 bool Selected(const int n);
294 void Set(int LCOUNT, wxString* LIST);
295 // TODO: void SetClientData(const int n, char* data);
296 void SetFirstItem(int n);
297 %name(SetFirstItemStr)void SetFirstItem(const wxString& string);
298 void SetSelection(int n, bool select = TRUE);
299 void SetString(int n, const wxString& string);
300 void SetStringSelection(const wxString& string, bool select = TRUE);
304 //----------------------------------------------------------------------
306 class wxCheckListBox : public wxListBox {
308 wxCheckListBox(wxWindow *parent, wxWindowID id,
309 const wxPoint& pos = wxPyDefaultPosition,
310 const wxSize& size = wxPyDefaultSize,
312 wxString* LIST = NULL,
314 const wxValidator& validator = wxPyDefaultValidator,
315 char* name = "listBox");
317 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
319 bool IsChecked(int uiIndex);
320 void Check(int uiIndex, bool bCheck = TRUE);
325 //----------------------------------------------------------------------
327 class wxTextCtrl : public wxControl {
329 wxTextCtrl(wxWindow* parent, wxWindowID id, char* value = "",
330 const wxPoint& pos = wxPyDefaultPosition,
331 const wxSize& size = wxPyDefaultSize,
333 const wxValidator& validator = wxPyDefaultValidator,
334 char* name = "text");
336 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
342 long GetInsertionPoint();
343 long GetLastPosition();
344 int GetLineLength(long lineNo);
345 wxString GetLineText(long lineNo);
346 int GetNumberOfLines();
349 bool LoadFile(const wxString& filename);
351 void PositionToXY(long pos, long *OUTPUT, long *OUTPUT);
352 void Remove(long from, long to);
353 void Replace(long from, long to, const wxString& value);
354 bool SaveFile(const wxString& filename);
355 void SetEditable(bool editable);
356 void SetInsertionPoint(long pos);
357 void SetInsertionPointEnd();
358 void SetSelection(long from, long to);
359 void SetValue(const wxString& value);
360 void ShowPosition(long pos);
361 void WriteText(const wxString& text);
362 void AppendText(const wxString& text);
363 long XYToPosition(long x, long y);
370 void GetSelection(long* OUTPUT, long* OUTPUT);
374 //----------------------------------------------------------------------
376 class wxScrollBar : public wxControl {
378 wxScrollBar(wxWindow* parent, wxWindowID id = -1,
379 const wxPoint& pos = wxPyDefaultPosition,
380 const wxSize& size = wxPyDefaultSize,
381 long style = wxSB_HORIZONTAL,
382 const wxValidator& validator = wxPyDefaultValidator,
383 char* name = "scrollBar");
385 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
389 int GetThumbPosition();
391 void SetThumbPosition(int viewStart);
392 void SetScrollbar(int position, int thumbSize,
393 int range, int pageSize,
394 bool refresh = TRUE);
397 //----------------------------------------------------------------------
399 class wxSpinButton : public wxControl {
401 wxSpinButton(wxWindow* parent, wxWindowID id = -1,
402 const wxPoint& pos = wxPyDefaultPosition,
403 const wxSize& size = wxPyDefaultSize,
404 long style = wxSP_HORIZONTAL,
405 char* name = "spinButton");
410 void SetRange(int min, int max);
411 void SetValue(int value);
414 //----------------------------------------------------------------------
416 class wxStaticBitmap : public wxControl {
418 wxStaticBitmap(wxWindow* parent, wxWindowID id,
419 const wxBitmap& bitmap,
420 const wxPoint& pos = wxPyDefaultPosition,
421 const wxSize& size = wxPyDefaultSize,
423 char* name = "staticBitmap");
425 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
427 const wxBitmap& GetBitmap();
428 void SetBitmap(const wxBitmap& bitmap);
429 void SetIcon(const wxIcon& icon);
432 //----------------------------------------------------------------------
434 class wxRadioBox : public wxControl {
436 wxRadioBox(wxWindow* parent, wxWindowID id,
437 const wxString& label,
438 const wxPoint& point = wxPyDefaultPosition,
439 const wxSize& size = wxPyDefaultSize,
440 int LCOUNT = 0, wxString* LIST = NULL,
441 int majorDimension = 0,
442 long style = wxRA_HORIZONTAL,
443 const wxValidator& validator = wxPyDefaultValidator,
444 char* name = "radioBox");
446 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
448 void Enable(bool enable);
449 %name(EnableItem)void Enable(int n, bool enable);
450 int FindString(const wxString& string);
452 //*** wxString GetLabel();
453 //*** void SetLabel(const wxString& label);
455 %name(GetItemLabel)wxString GetLabel(int n);
457 wxString GetString(int n);
458 wxString GetStringSelection();
460 %name(SetItemLabel)void SetLabel(int n, const wxString& label);
461 void SetSelection(int n);
462 void SetStringSelection(const wxString& string);
463 void Show(bool show);
464 %name(ShowItem)void Show(int item, bool show);
467 //----------------------------------------------------------------------
469 class wxRadioButton : public wxControl {
471 wxRadioButton(wxWindow* parent, wxWindowID id,
472 const wxString& label,
473 const wxPoint& pos = wxPyDefaultPosition,
474 const wxSize& size = wxPyDefaultSize,
476 const wxValidator& validator = wxPyDefaultValidator,
477 char* name = "radioButton");
479 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
482 void SetValue(bool value);
485 //----------------------------------------------------------------------
487 class wxSlider : public wxControl {
489 wxSlider(wxWindow* parent, wxWindowID id,
490 int value, int minValue, int maxValue,
491 const wxPoint& point = wxPyDefaultPosition,
492 const wxSize& size = wxPyDefaultSize,
493 long style = wxSL_HORIZONTAL,
494 const wxValidator& validator = wxPyDefaultValidator,
495 char* name = "slider");
497 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
507 int GetThumbLength();
510 void SetRange(int minValue, int maxValue);
511 void SetTickFreq(int n, int pos);
512 void SetLineSize(int lineSize);
513 void SetPageSize(int pageSize);
514 void SetSelection(int startPos, int endPos);
515 void SetThumbLength(int len);
516 void SetTick(int tickPos);
517 void SetValue(int value);
521 //----------------------------------------------------------------------
524 /////////////////////////////////////////////////////////////////////////////
527 // Revision 1.16 1999/07/31 07:54:35 RD
530 // Added the missing wxWindow.GetUpdateRegion() method.
532 // Made a new change in SWIG (update your patches everybody) that
533 // provides a fix for global shadow objects that get an exception in
534 // their __del__ when their extension module has already been deleted.
535 // It was only a 1 line change in .../SWIG/Modules/pycpp.cxx at about
536 // line 496 if you want to do it by hand.
538 // It is now possible to run through MainLoop more than once in any one
539 // process. The cleanup that used to happen as MainLoop completed (and
540 // prevented it from running again) has been delayed until the wxc module
541 // is being unloaded by Python.
543 // wxWindow.PopupMenu() now takes a wxPoint instead of x,y. Added
544 // wxWindow.PopupMenuXY to be consistent with some other methods.
546 // Added wxGrid.SetEditInPlace and wxGrid.GetEditInPlace.
548 // You can now provide your own app.MainLoop method. See
549 // wxPython/demo/demoMainLoop.py for an example and some explaination.
551 // Got the in-place-edit for the wxTreeCtrl fixed and added some demo
552 // code to show how to use it.
554 // Put the wxIcon constructor back in for GTK as it now has one that
557 // Added wxGrid.GetCells
559 // Added wxSystemSettings static methods as functions with names like
560 // wxSystemSettings_GetSystemColour.
562 // Removed wxPyMenu since using menu callbacks have been depreciated in
563 // wxWindows. Use wxMenu and events instead.
565 // Added alternate wxBitmap constructor (for MSW only) as
566 // wxBitmapFromData(data, type, width, height, depth = 1)
568 // Added a helper function named wxPyTypeCast that can convert shadow
569 // objects of one type into shadow objects of another type. (Like doing
570 // a down-cast.) See the implementation in wx.py for some docs.
572 // Revision 1.15 1999/06/22 17:45:18 RD
574 // wxPython 2.1b1: Very minor changes needed for wxGTK
576 // Revision 1.14 1999/06/22 07:03:02 RD
578 // wxPython 2.1b1 for wxMSW (wxGTK coming soon)
579 // Lots of changes, see the README.txt for details...
581 // Revision 1.13 1999/04/30 21:13:43 RD
583 // wxPython 2.0b9, first phase (win32)
584 // Added gobs of stuff, see wxPython/README.txt for details
586 // Revision 1.12 1999/04/30 03:29:18 RD
588 // wxPython 2.0b9, first phase (win32)
589 // Added gobs of stuff, see wxPython/README.txt for details
591 // Revision 1.11.4.1 1999/03/27 23:29:14 RD
594 // Python thread support
595 // various minor additions
596 // various minor fixes
598 // Revision 1.11 1999/02/25 07:08:30 RD
600 // wxPython version 2.0b5
602 // Revision 1.10 1998/12/17 17:52:19 RD
605 // Minor fixes and SWIG code generation for RR's changes. MSW and GTK
606 // versions are much closer now!
608 // Revision 1.9 1998/12/17 14:07:29 RR
610 // Removed minor differences between wxMSW and wxGTK
612 // Revision 1.8 1998/12/15 20:41:15 RD
613 // Changed the import semantics from "from wxPython import *" to "from
614 // wxPython.wx import *" This is for people who are worried about
615 // namespace pollution, they can use "from wxPython import wx" and then
616 // prefix all the wxPython identifiers with "wx."
618 // Added wxTaskbarIcon for wxMSW.
620 // Made the events work for wxGrid.
624 // Added wxMiniFrame for wxGTK, (untested.)
626 // Changed many of the args and return values that were pointers to gdi
627 // objects to references to reflect changes in the wxWindows API.
629 // Other assorted fixes and additions.
631 // Revision 1.7 1998/11/16 00:00:53 RD
632 // Generic treectrl for wxPython/GTK compiles...
634 // Revision 1.6 1998/11/15 23:03:43 RD
635 // Removing some ifdef's for wxGTK
637 // Revision 1.5 1998/10/07 07:34:32 RD
638 // Version 0.4.1 for wxGTK
640 // Revision 1.4 1998/10/02 06:40:35 RD
642 // Version 0.4 of wxPython for MSW.
644 // Revision 1.3 1998/08/18 19:48:14 RD
645 // more wxGTK compatibility things.
647 // It builds now but there are serious runtime problems...
649 // Revision 1.2 1998/08/15 07:36:28 RD
650 // - Moved the header in the .i files out of the code that gets put into
651 // the .cpp files. It caused CVS conflicts because of the RCS ID being
652 // different each time.
654 // - A few minor fixes.
656 // Revision 1.1 1998/08/09 08:25:49 RD