]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls.i
Lots of changes for wxPython to start using many of the new featues in
[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 wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n);
462 if (data) {
463 Py_INCREF(data->m_obj);
464 return data->m_obj;
465 } else {
466 Py_INCREF(Py_None);
467 return Py_None;
468 }
469 }
470
471 void SetClientData(int n, PyObject* clientData) {
472 wxPyClientData* data = new wxPyClientData(clientData);
473 self->SetClientObject(n, data);
474 }
475 }
476
477 };
478
479
480
481 #else
482 // MSW's version derives from wxChoice
483
484 class wxComboBox : public wxChoice {
485 public:
486 wxComboBox(wxWindow* parent, wxWindowID id,
487 const wxString& value = wxPyEmptyString,
488 const wxPoint& pos = wxDefaultPosition,
489 const wxSize& size = wxDefaultSize,
490 int LCOUNT=0, wxString* choices=NULL,
491 long style = 0,
492 const wxValidator& validator = wxDefaultValidator,
493 const wxString& name = wxPyComboBoxNameStr);
494 %name(wxPreComboBox)wxComboBox();
495
496 bool Create(wxWindow* parent, wxWindowID id,
497 const wxString& value = wxPyEmptyString,
498 const wxPoint& pos = wxDefaultPosition,
499 const wxSize& size = wxDefaultSize,
500 int LCOUNT=0, wxString* choices=NULL,
501 long style = 0,
502 const wxValidator& validator = wxDefaultValidator,
503 const wxString& name = wxPyComboBoxNameStr);
504
505 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
506 %pragma(python) addtomethod = "wxPreComboBox:val._setOORInfo(val)"
507
508 void Copy();
509 void Cut();
510 long GetInsertionPoint();
511 long GetLastPosition();
512 wxString GetValue();
513 void Paste();
514 void Replace(long from, long to, const wxString& text);
515 void Remove(long from, long to);
516 void SetInsertionPoint(long pos);
517 void SetInsertionPointEnd();
518 void SetSelection(int n);
519 %name(SetMark)void SetSelection(long from, long to);
520 void SetValue(const wxString& text);
521 void SetEditable(bool editable);
522 };
523 #endif
524
525
526 //----------------------------------------------------------------------
527
528 class wxGauge : public wxControl {
529 public:
530 wxGauge(wxWindow* parent, wxWindowID id, int range,
531 const wxPoint& pos = wxDefaultPosition,
532 const wxSize& size = wxDefaultSize,
533 long style = wxGA_HORIZONTAL,
534 const wxValidator& validator = wxDefaultValidator,
535 const wxString& name = wxPyGaugeNameStr);
536 %name(wxPreGauge)wxGauge();
537
538 bool Create(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
545 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
546 %pragma(python) addtomethod = "wxPreGauge:val._setOORInfo(val)"
547
548 int GetBezelFace();
549 int GetRange();
550 int GetShadowWidth();
551 int GetValue();
552 void SetBezelFace(int width);
553 void SetRange(int range);
554 void SetShadowWidth(int width);
555 void SetValue(int pos);
556 };
557
558 //----------------------------------------------------------------------
559
560 class wxStaticBox : public wxControl {
561 public:
562 wxStaticBox(wxWindow* parent, wxWindowID id, const wxString& label,
563 const wxPoint& pos = wxDefaultPosition,
564 const wxSize& size = wxDefaultSize,
565 long style = 0,
566 const wxString& name = wxPyStaticBoxNameStr);
567 %name(wxPreStaticBox)wxStaticBox();
568
569 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
570 const wxPoint& pos = wxDefaultPosition,
571 const wxSize& size = wxDefaultSize,
572 long style = 0,
573 const wxString& name = wxPyStaticBoxNameStr);
574
575 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
576 %pragma(python) addtomethod = "wxPreStaticBox:val._setOORInfo(val)"
577 };
578
579
580 //----------------------------------------------------------------------
581
582
583 class wxStaticLine : public wxControl {
584 public:
585 wxStaticLine( wxWindow *parent, wxWindowID id,
586 const wxPoint &pos = wxDefaultPosition,
587 const wxSize &size = wxDefaultSize,
588 long style = wxLI_HORIZONTAL,
589 const wxString& name = wxPyStaticTextNameStr);
590 %name(wxPreStaticLine)wxStaticLine();
591
592 bool Create( wxWindow *parent, wxWindowID id,
593 const wxPoint &pos = wxDefaultPosition,
594 const wxSize &size = wxDefaultSize,
595 long style = wxLI_HORIZONTAL,
596 const wxString& name = wxPyStaticTextNameStr);
597
598 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
599 %pragma(python) addtomethod = "wxPreStaticLine:val._setOORInfo(val)"
600 };
601
602
603 //----------------------------------------------------------------------
604
605 class wxStaticText : public wxControl {
606 public:
607 wxStaticText(wxWindow* parent, wxWindowID id, const wxString& label,
608 const wxPoint& pos = wxDefaultPosition,
609 const wxSize& size = wxDefaultSize,
610 long style = 0,
611 const wxString& name = wxPyStaticTextNameStr);
612 %name(wxPreStaticText)wxStaticText();
613
614 bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
615 const wxPoint& pos = wxDefaultPosition,
616 const wxSize& size = wxDefaultSize,
617 long style = 0,
618 const wxString& name = wxPyStaticTextNameStr);
619
620 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
621 %pragma(python) addtomethod = "wxPreStaticText:val._setOORInfo(val)"
622
623 wxString GetLabel();
624 void SetLabel(const wxString& label);
625 };
626
627 //----------------------------------------------------------------------
628
629 class wxListBox : public wxControlWithItems {
630 public:
631 wxListBox(wxWindow* parent, wxWindowID id,
632 const wxPoint& pos = wxDefaultPosition,
633 const wxSize& size = wxDefaultSize,
634 int LCOUNT, wxString* choices = NULL,
635 long style = 0,
636 const wxValidator& validator = wxDefaultValidator,
637 const wxString& name = wxPyListBoxNameStr);
638 %name(wxPreListBox)wxListBox();
639
640 bool Create(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
648 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
649 %pragma(python) addtomethod = "wxPreListBox:val._setOORInfo(val)"
650
651 void Clear();
652 void Deselect(int n);
653
654 // int GetSelections(int **selections);
655 %addmethods {
656 PyObject* GetSelections() {
657 wxArrayInt lst;
658 self->GetSelections(lst);
659 PyObject *tup = PyTuple_New(lst.GetCount());
660 for(size_t i=0; i<lst.GetCount(); i++) {
661 PyTuple_SetItem(tup, i, PyInt_FromLong(lst[i]));
662 }
663 return tup;
664 }
665 }
666
667
668 void InsertItems(int LCOUNT, wxString* choices, int pos);
669
670 bool IsSelected(const int n);
671 bool Selected(const int n);
672 void Set(int LCOUNT, wxString* choices);
673 void SetFirstItem(int n);
674 %name(SetFirstItemStr)void SetFirstItem(const wxString& string);
675 void SetSelection(int n, bool select = TRUE);
676 void SetString(int n, const wxString& string);
677 void SetStringSelection(const wxString& string, bool select = TRUE);
678 };
679
680
681 //----------------------------------------------------------------------
682
683 class wxCheckListBox : public wxListBox {
684 public:
685 wxCheckListBox(wxWindow *parent, wxWindowID id,
686 const wxPoint& pos = wxDefaultPosition,
687 const wxSize& size = wxDefaultSize,
688 int LCOUNT = 0,
689 wxString* choices = NULL,
690 long style = 0,
691 const wxValidator& validator = wxDefaultValidator,
692 const wxString& name = wxPyListBoxNameStr);
693 %name(wxPreCheckListBox)wxCheckListBox();
694
695 bool Create(wxWindow *parent, wxWindowID id,
696 const wxPoint& pos = wxDefaultPosition,
697 const wxSize& size = wxDefaultSize,
698 int LCOUNT = 0,
699 wxString* choices = NULL,
700 long style = 0,
701 const wxValidator& validator = wxDefaultValidator,
702 const wxString& name = wxPyListBoxNameStr);
703
704 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
705 %pragma(python) addtomethod = "wxPreCheckListBox:val._setOORInfo(val)"
706
707 bool IsChecked(int uiIndex);
708 void Check(int uiIndex, int bCheck = TRUE);
709 void InsertItems(int LCOUNT, wxString* choices, int pos);
710
711 #ifndef __WXMAC__
712 int GetItemHeight();
713 #endif
714
715 // return the index of the item at this position or wxNOT_FOUND
716 int HitTest(const wxPoint& pt) const;
717 %name(HitTestXY)int HitTest(wxCoord x, wxCoord y) const;
718
719 };
720
721 //----------------------------------------------------------------------
722
723 enum {
724 // Styles
725 wxTE_NO_VSCROLL,
726 wxTE_AUTO_SCROLL,
727 wxTE_READONLY,
728 wxTE_MULTILINE,
729 wxTE_PROCESS_TAB,
730 wxTE_LEFT,
731 wxTE_CENTER,
732 wxTE_RIGHT,
733 wxTE_CENTRE,
734 wxTE_RICH,
735 wxTE_PROCESS_ENTER,
736 wxTE_PASSWORD,
737 wxTE_AUTO_URL,
738 wxTE_NOHIDESEL,
739 wxTE_DONTWRAP,
740 wxTE_LINEWRAP,
741 wxTE_WORDWRAP,
742 wxTE_RICH2,
743
744 // Flags to indicate which attributes are being applied
745 wxTEXT_ATTR_TEXT_COLOUR,
746 wxTEXT_ATTR_BACKGROUND_COLOUR,
747 wxTEXT_ATTR_FONT_FACE,
748 wxTEXT_ATTR_FONT_SIZE,
749 wxTEXT_ATTR_FONT_WEIGHT,
750 wxTEXT_ATTR_FONT_ITALIC,
751 wxTEXT_ATTR_FONT_UNDERLINE,
752 wxTEXT_ATTR_FONT,
753 wxTEXT_ATTR_ALIGNMENT,
754 wxTEXT_ATTR_LEFT_INDENT,
755 wxTEXT_ATTR_RIGHT_INDENT,
756 wxTEXT_ATTR_TABS,
757
758 };
759
760
761 enum wxTextAttrAlignment
762 {
763 wxTEXT_ALIGNMENT_DEFAULT,
764 wxTEXT_ALIGNMENT_LEFT,
765 wxTEXT_ALIGNMENT_CENTRE,
766 wxTEXT_ALIGNMENT_CENTER,
767 wxTEXT_ALIGNMENT_RIGHT,
768 wxTEXT_ALIGNMENT_JUSTIFIED
769 };
770
771
772
773
774 class wxTextAttr
775 {
776 public:
777 // ctors
778 wxTextAttr(const wxColour& colText = wxNullColour,
779 const wxColour& colBack = wxNullColour,
780 const wxFont& font = wxNullFont,
781 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
782 ~wxTextAttr();
783
784 void Init();
785
786 // setters
787 void SetTextColour(const wxColour& colText);
788 void SetBackgroundColour(const wxColour& colBack);
789 void SetFont(const wxFont& font);
790 void SetAlignment(wxTextAttrAlignment alignment);
791 void SetTabs(const wxArrayInt& tabs);
792 void SetLeftIndent(int indent);
793 void SetRightIndent(int indent);
794 void SetFlags(long flags);
795
796 // accessors
797 bool HasTextColour() const;
798 bool HasBackgroundColour() const;
799 bool HasFont() const;
800 bool HasAlignment() const;
801 bool HasTabs() const;
802 bool HasLeftIndent() const;
803 bool HasRightIndent() const;
804 bool HasFlag(long flag) const;
805
806 wxColour GetTextColour() const;
807 wxColour GetBackgroundColour() const;
808 wxFont GetFont() const;
809 wxTextAttrAlignment GetAlignment();
810 const wxArrayInt& GetTabs() const;
811 long GetLeftIndent() const;
812 long GetRightIndent() const;
813 long GetFlags() const;
814
815
816 // returns false if we have any attributes set, true otherwise
817 bool IsDefault();
818
819 // return the attribute having the valid font and colours: it uses the
820 // attributes set in attr and falls back first to attrDefault and then to
821 // the text control font/colours for those attributes which are not set
822 static wxTextAttr Combine(const wxTextAttr& attr,
823 const wxTextAttr& attrDef,
824 const wxTextCtrl *text);
825 };
826
827
828
829 class wxTextCtrl : public wxControl {
830 public:
831 wxTextCtrl(wxWindow* parent, wxWindowID id,
832 const wxString& value = wxPyEmptyString,
833 const wxPoint& pos = wxDefaultPosition,
834 const wxSize& size = wxDefaultSize,
835 long style = 0,
836 const wxValidator& validator = wxDefaultValidator,
837 const wxString& name = wxPyTextCtrlNameStr);
838 %name(wxPreTextCtrl)wxTextCtrl();
839
840 bool Create(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
848 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
849 %pragma(python) addtomethod = "wxPreTextCtrl:val._setOORInfo(val)"
850
851
852 wxString GetValue() const;
853 void SetValue(const wxString& value);
854
855 wxString GetRange(long from, long to);
856
857 int GetLineLength(long lineNo) const;
858 wxString GetLineText(long lineNo) const;
859 int GetNumberOfLines() const;
860
861 bool IsModified() const;
862 bool IsEditable() const;
863
864 // If the return values from and to are the same, there is no selection.
865 void GetSelection(long* OUTPUT, long* OUTPUT) const;
866 wxString GetStringSelection();
867
868 void Clear();
869 void Replace(long from, long to, const wxString& value);
870 void Remove(long from, long to);
871
872 // load/save the controls contents from/to the file
873 bool LoadFile(const wxString& file);
874 bool SaveFile(const wxString& file = wxPyEmptyString);
875
876 // clears the dirty flag
877 void DiscardEdits();
878
879 // set the max number of characters which may be entered in a single line
880 // text control
881 void SetMaxLength(unsigned long len);
882
883 // writing text inserts it at the current position, appending always
884 // inserts it at the end
885 void WriteText(const wxString& text);
886 void AppendText(const wxString& text);
887
888 // insert the character which would have resulted from this key event,
889 // return TRUE if anything has been inserted
890 bool EmulateKeyPress(const wxKeyEvent& event);
891
892 // text control under some platforms supports the text styles: these
893 // methods allow to apply the given text style to the given selection or to
894 // set/get the style which will be used for all appended text
895 bool SetStyle(long start, long end, const wxTextAttr& style);
896 bool SetDefaultStyle(const wxTextAttr& style);
897 const wxTextAttr& GetDefaultStyle() const;
898 bool GetStyle(long position, wxTextAttr& style);
899
900 // translate between the position (which is just an index in the text ctrl
901 // considering all its contents as a single strings) and (x, y) coordinates
902 // which represent column and line.
903 long XYToPosition(long x, long y) const;
904 void PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const;
905
906 //bool PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const;
907 // TODO: check return value, raise exception.
908
909 void ShowPosition(long pos);
910
911 // Clipboard operations
912 void Copy();
913 void Cut();
914 void Paste();
915
916 bool CanCopy() const;
917 bool CanCut() const;
918 bool CanPaste() const;
919
920 // Undo/redo
921 void Undo();
922 void Redo();
923
924 bool CanUndo() const;
925 bool CanRedo() const;
926
927 // Insertion point
928 void SetInsertionPoint(long pos);
929 void SetInsertionPointEnd();
930 long GetInsertionPoint() const;
931 long GetLastPosition() const;
932
933 void SetSelection(long from, long to);
934 void SelectAll();
935 void SetEditable(bool editable);
936
937 bool IsSingleLine();
938 bool IsMultiLine();
939
940
941 %addmethods {
942 void write(const wxString& text) {
943 self->AppendText(text);
944 }
945 }
946
947 // TODO: replace this when the method is really added to wxTextCtrl
948 %addmethods {
949 wxString GetString(long from, long to) {
950 return self->GetValue().Mid(from, to - from);
951 }
952 }
953 };
954
955 //----------------------------------------------------------------------
956
957 class wxScrollBar : public wxControl {
958 public:
959 wxScrollBar(wxWindow* parent, wxWindowID id = -1,
960 const wxPoint& pos = wxDefaultPosition,
961 const wxSize& size = wxDefaultSize,
962 long style = wxSB_HORIZONTAL,
963 const wxValidator& validator = wxDefaultValidator,
964 const wxString& name = wxPyScrollBarNameStr);
965 %name(wxPreScrollBar)wxScrollBar();
966
967 bool Create(wxWindow* parent, wxWindowID id = -1,
968 const wxPoint& pos = wxDefaultPosition,
969 const wxSize& size = wxDefaultSize,
970 long style = wxSB_HORIZONTAL,
971 const wxValidator& validator = wxDefaultValidator,
972 const wxString& name = wxPyScrollBarNameStr);
973
974 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
975 %pragma(python) addtomethod = "wxPreScrollBar:val._setOORInfo(val)"
976
977 int GetRange();
978 int GetPageSize();
979 int GetThumbPosition();
980 int GetThumbSize();
981 %name(GetThumbLength) int GetThumbSize(); // to match the docs
982
983 bool IsVertical();
984
985 void SetThumbPosition(int viewStart);
986 void SetScrollbar(int position, int thumbSize,
987 int range, int pageSize,
988 bool refresh = TRUE);
989 };
990
991 //----------------------------------------------------------------------
992
993 class wxSpinButton : public wxControl {
994 public:
995 wxSpinButton(wxWindow* parent, wxWindowID id = -1,
996 const wxPoint& pos = wxDefaultPosition,
997 const wxSize& size = wxDefaultSize,
998 long style = wxSP_HORIZONTAL,
999 const wxString& name = wxPySPIN_BUTTON_NAME);
1000 %name(wxPreSpinButton)wxSpinButton();
1001
1002 bool Create(wxWindow* parent, wxWindowID id = -1,
1003 const wxPoint& pos = wxDefaultPosition,
1004 const wxSize& size = wxDefaultSize,
1005 long style = wxSP_HORIZONTAL,
1006 const wxString& name = wxPySPIN_BUTTON_NAME);
1007
1008 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1009 %pragma(python) addtomethod = "wxPreSpinButton:val._setOORInfo(val)"
1010
1011 int GetMax();
1012 int GetMin();
1013 int GetValue();
1014 void SetRange(int min, int max);
1015 void SetValue(int value);
1016 };
1017
1018 //----------------------------------------------------------------------
1019
1020 class wxStaticBitmap : public wxControl {
1021 public:
1022 wxStaticBitmap(wxWindow* parent, wxWindowID id,
1023 const wxBitmap& bitmap,
1024 const wxPoint& pos = wxDefaultPosition,
1025 const wxSize& size = wxDefaultSize,
1026 long style = 0,
1027 const wxString& name = wxPyStaticBitmapNameStr);
1028 %name(wxPreStaticBitmap)wxStaticBitmap();
1029
1030 bool Create(wxWindow* parent, wxWindowID id,
1031 const wxBitmap& bitmap,
1032 const wxPoint& pos = wxDefaultPosition,
1033 const wxSize& size = wxDefaultSize,
1034 long style = 0,
1035 const wxString& name = wxPyStaticBitmapNameStr);
1036
1037 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1038 %pragma(python) addtomethod = "wxPreStaticBitmap:val._setOORInfo(val)"
1039
1040 wxBitmap GetBitmap();
1041 void SetBitmap(const wxBitmap& bitmap);
1042 void SetIcon(const wxIcon& icon);
1043 };
1044
1045 //----------------------------------------------------------------------
1046
1047 class wxRadioBox : public wxControl {
1048 public:
1049 wxRadioBox(wxWindow* parent, wxWindowID id,
1050 const wxString& label,
1051 const wxPoint& point = wxDefaultPosition,
1052 const wxSize& size = wxDefaultSize,
1053 int LCOUNT = 0, wxString* choices = NULL,
1054 int majorDimension = 0,
1055 long style = wxRA_HORIZONTAL,
1056 const wxValidator& validator = wxDefaultValidator,
1057 const wxString& name = wxPyRadioBoxNameStr);
1058 %name(wxPreRadioBox)wxRadioBox();
1059
1060 bool Create(wxWindow* parent, wxWindowID id,
1061 const wxString& label,
1062 const wxPoint& point = wxDefaultPosition,
1063 const wxSize& size = wxDefaultSize,
1064 int LCOUNT = 0, wxString* choices = NULL,
1065 int majorDimension = 0,
1066 long style = wxRA_HORIZONTAL,
1067 const wxValidator& validator = wxDefaultValidator,
1068 const wxString& name = wxPyRadioBoxNameStr);
1069
1070 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1071 %pragma(python) addtomethod = "wxPreRadioBox:val._setOORInfo(val)"
1072
1073 void Enable(bool enable);
1074 %name(EnableItem)void Enable(int n, bool enable);
1075 int FindString(const wxString& string);
1076
1077 wxString GetString(int n);
1078 void SetString(int n, const wxString& label);
1079 %pragma(python) addtoclass = "
1080 GetItemLabel = GetString
1081 SetItemLabel = SetString
1082 "
1083 #ifndef __WXGTK__
1084 int GetColumnCount();
1085 int GetRowCount();
1086 int GetNextItem(int item, wxDirection dir, long style);
1087 #endif
1088
1089 int GetSelection();
1090 wxString GetStringSelection();
1091 int GetCount();
1092 %pragma(python) addtoclass = "Number = GetCount"
1093
1094 void SetSelection(int n);
1095 void SetStringSelection(const wxString& string);
1096 void Show(bool show);
1097 %name(ShowItem)void Show(int item, bool show);
1098 };
1099
1100 //----------------------------------------------------------------------
1101
1102 class wxRadioButton : public wxControl {
1103 public:
1104 wxRadioButton(wxWindow* parent, wxWindowID id,
1105 const wxString& label,
1106 const wxPoint& pos = wxDefaultPosition,
1107 const wxSize& size = wxDefaultSize,
1108 long style = 0,
1109 const wxValidator& validator = wxDefaultValidator,
1110 const wxString& name = wxPyRadioButtonNameStr);
1111 %name(wxPreRadioButton)wxRadioButton();
1112
1113 bool Create(wxWindow* parent, wxWindowID id,
1114 const wxString& label,
1115 const wxPoint& pos = wxDefaultPosition,
1116 const wxSize& size = wxDefaultSize,
1117 long style = 0,
1118 const wxValidator& validator = wxDefaultValidator,
1119 const wxString& name = wxPyRadioButtonNameStr);
1120
1121 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1122 %pragma(python) addtomethod = "wxPreRadioButton:val._setOORInfo(val)"
1123
1124 bool GetValue();
1125 void SetValue(bool value);
1126 };
1127
1128 //----------------------------------------------------------------------
1129
1130 class wxSlider : public wxControl {
1131 public:
1132 wxSlider(wxWindow* parent, wxWindowID id,
1133 int value, int minValue, int maxValue,
1134 const wxPoint& point = wxDefaultPosition,
1135 const wxSize& size = wxDefaultSize,
1136 long style = wxSL_HORIZONTAL,
1137 const wxValidator& validator = wxDefaultValidator,
1138 const wxString& name = wxPySliderNameStr);
1139 %name(wxPreSlider)wxSlider();
1140
1141 bool Create(wxWindow* parent, wxWindowID id,
1142 int value, int minValue, int maxValue,
1143 const wxPoint& point = wxDefaultPosition,
1144 const wxSize& size = wxDefaultSize,
1145 long style = wxSL_HORIZONTAL,
1146 const wxValidator& validator = wxDefaultValidator,
1147 const wxString& name = wxPySliderNameStr);
1148
1149 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1150 %pragma(python) addtomethod = "wxPreSlider:val._setOORInfo(val)"
1151
1152 void ClearSel();
1153 void ClearTicks();
1154 int GetLineSize();
1155 int GetMax();
1156 int GetMin();
1157 int GetPageSize();
1158 int GetSelEnd();
1159 int GetSelStart();
1160 int GetThumbLength();
1161 int GetTickFreq();
1162 int GetValue();
1163 void SetRange(int minValue, int maxValue);
1164 void SetTickFreq(int n, int pos);
1165 void SetLineSize(int lineSize);
1166 void SetPageSize(int pageSize);
1167 void SetSelection(int startPos, int endPos);
1168 void SetThumbLength(int len);
1169 void SetTick(int tickPos);
1170 void SetValue(int value);
1171 };
1172
1173
1174 //----------------------------------------------------------------------
1175
1176 class wxSpinCtrl : public wxSpinButton {
1177 public:
1178 wxSpinCtrl(wxWindow *parent,
1179 wxWindowID id = -1,
1180 const wxString& value = wxPyEmptyString,
1181 const wxPoint& pos = wxDefaultPosition,
1182 const wxSize& size = wxDefaultSize,
1183 long style = wxSP_ARROW_KEYS,
1184 int min = 0, int max = 100, int initial = 0,
1185 const wxString& name = wxPySpinCtrlNameStr);
1186 %name(wxPreSpinCtrl)wxSpinCtrl();
1187
1188 bool Create(wxWindow *parent,
1189 wxWindowID id = -1,
1190 const wxString& value = wxPyEmptyString,
1191 const wxPoint& pos = wxDefaultPosition,
1192 const wxSize& size = wxDefaultSize,
1193 long style = wxSP_ARROW_KEYS,
1194 int min = 0, int max = 100, int initial = 0,
1195 const wxString& name = wxPySpinCtrlNameStr);
1196
1197 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1198 %pragma(python) addtomethod = "wxPreSpinCtrl:val._setOORInfo(val)"
1199
1200 int GetMax();
1201 int GetMin();
1202 int GetValue();
1203 void SetRange(int min, int max);
1204 void SetValue(int value);
1205 #ifdef __WXGTK__
1206 %addmethods {
1207 void SetSelection(long from, long to) {
1208 }
1209 }
1210 #else
1211 void SetSelection(long from, long to);
1212 #endif
1213 };
1214
1215
1216 //----------------------------------------------------------------------
1217
1218 #ifndef __WXMAC__
1219 enum { wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, };
1220
1221 class wxToggleButton : public wxControl {
1222 public:
1223 wxToggleButton(wxWindow *parent,
1224 wxWindowID id,
1225 const wxString& label,
1226 const wxPoint& pos = wxDefaultPosition,
1227 const wxSize& size = wxDefaultSize,
1228 long style = 0,
1229 const wxValidator& validator = wxDefaultValidator,
1230 const wxString& name = wxPyCheckBoxNameStr);
1231 %name(wxPreToggleButton)wxToggleButton();
1232
1233 bool Create(wxWindow *parent,
1234 wxWindowID id,
1235 const wxString& label,
1236 const wxPoint& pos = wxDefaultPosition,
1237 const wxSize& size = wxDefaultSize,
1238 long style = 0,
1239 const wxValidator& validator = wxDefaultValidator,
1240 const wxString& name = wxPyCheckBoxNameStr);
1241
1242 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1243 %pragma(python) addtomethod = "wxPreToggleButton:val._setOORInfo(val)"
1244
1245 void SetValue(bool value);
1246 bool GetValue() const ;
1247 void SetLabel(const wxString& label);
1248
1249 };
1250
1251 #endif
1252
1253 //----------------------------------------------------------------------
1254 //----------------------------------------------------------------------
1255 //----------------------------------------------------------------------
1256
1257
1258