]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_textctrl.i
Add wx.Dialog.Get/SetAffirmativeId and Get/SetEscapeId
[wxWidgets.git] / wxPython / src / _textctrl.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _textctrl.i
3// Purpose: SWIG interface defs for wxTextCtrl and related classes
4//
5// Author: Robin Dunn
6//
7// Created: 10-June-1998
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17
b2dc1044 18MAKE_CONST_WXSTRING(TextCtrlNameStr);
d14a1e28
RD
19
20//---------------------------------------------------------------------------
21%newgroup
22
23enum {
24 // Style flags
25 wxTE_NO_VSCROLL,
26 wxTE_AUTO_SCROLL,
27
28 wxTE_READONLY,
29 wxTE_MULTILINE,
30 wxTE_PROCESS_TAB,
31
32 // alignment flags
33 wxTE_LEFT,
34 wxTE_CENTER,
35 wxTE_RIGHT,
36 wxTE_CENTRE,
37
38 // this style means to use RICHEDIT control and does something only under
39 // wxMSW and Win32 and is silently ignored under all other platforms
40 wxTE_RICH,
41
42 wxTE_PROCESS_ENTER,
43 wxTE_PASSWORD,
44
45 // automatically detect the URLs and generate the events when mouse is
46 // moved/clicked over an URL
47 //
48 // this is for Win32 richedit controls only so far
49 wxTE_AUTO_URL,
50
51 // by default, the Windows text control doesn't show the selection when it
52 // doesn't have focus - use this style to force it to always show it
53 wxTE_NOHIDESEL,
54
c4c1e8d6
RD
55 // use wxHSCROLL (wxTE_DONTWRAP) to not wrap text at all, wxTE_CHARWRAP to
56 // wrap it at any position and wxTE_WORDWRAP to wrap at words boundary
57 //
58 // if no wrapping style is given at all, the control wraps at word boundary
d14a1e28 59 wxTE_DONTWRAP,
c4c1e8d6 60 wxTE_CHARWRAP,
d14a1e28 61 wxTE_WORDWRAP,
c4c1e8d6
RD
62 wxTE_BESTWRAP,
63
64 // obsolete synonym
65 wxTE_LINEWRAP,
d14a1e28
RD
66
67 // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for
68 // wxTE_RICH controls - can be used together with or instead of wxTE_RICH
69 wxTE_RICH2,
4fee07f2
RD
70
71 wxTE_CAPITALIZE,
d14a1e28
RD
72};
73
74
75enum wxTextAttrAlignment
76{
77 wxTEXT_ALIGNMENT_DEFAULT,
78 wxTEXT_ALIGNMENT_LEFT,
79 wxTEXT_ALIGNMENT_CENTRE,
80 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
81 wxTEXT_ALIGNMENT_RIGHT,
82 wxTEXT_ALIGNMENT_JUSTIFIED
83};
84
85enum {
86 // Flags to indicate which attributes are being applied
87 wxTEXT_ATTR_TEXT_COLOUR,
88 wxTEXT_ATTR_BACKGROUND_COLOUR,
89 wxTEXT_ATTR_FONT_FACE,
90 wxTEXT_ATTR_FONT_SIZE,
91 wxTEXT_ATTR_FONT_WEIGHT,
92 wxTEXT_ATTR_FONT_ITALIC,
93 wxTEXT_ATTR_FONT_UNDERLINE,
94 wxTEXT_ATTR_FONT,
95 wxTEXT_ATTR_ALIGNMENT,
96 wxTEXT_ATTR_LEFT_INDENT,
97 wxTEXT_ATTR_RIGHT_INDENT,
98 wxTEXT_ATTR_TABS
99};
100
1e53cf51
RD
101enum wxTextCtrlHitTestResult
102{
103 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
104 wxTE_HT_BEFORE, // either to the left or upper
105 wxTE_HT_ON_TEXT, // directly on
106 wxTE_HT_BELOW, // below [the last line]
107 wxTE_HT_BEYOND // after [the end of line]
108};
109
aeee37c3
RD
110
111enum {
112 wxOutOfRangeTextCoord,
113 wxInvalidTextCoord
114};
115
d14a1e28
RD
116//---------------------------------------------------------------------------
117
118// wxTextAttr: a structure containing the visual attributes of a text
119class wxTextAttr
120{
121public:
015256c0 122 wxTextAttr(const wxColour& colText = wxNullColour,
d14a1e28
RD
123 const wxColour& colBack = wxNullColour,
124 const wxFont& font = wxNullFont,
125 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
2b9048c5
RD
126 ~wxTextAttr();
127
d14a1e28
RD
128 // operations
129 void Init();
130
131 // setters
132 void SetTextColour(const wxColour& colText);
133 void SetBackgroundColour(const wxColour& colBack);
134 void SetFont(const wxFont& font, long flags = wxTEXT_ATTR_FONT);
135 void SetAlignment(wxTextAttrAlignment alignment);
136 void SetTabs(const wxArrayInt& tabs);
6d2e144a 137 void SetLeftIndent(int indent, int subIndent=0);
d14a1e28
RD
138 void SetRightIndent(int indent);
139 void SetFlags(long flags);
140
141 // accessors
142 bool HasTextColour() const;
143 bool HasBackgroundColour() const;
144 bool HasFont() const;
145 bool HasAlignment() const;
146 bool HasTabs() const;
147 bool HasLeftIndent() const;
148 bool HasRightIndent() const;
149 bool HasFlag(long flag) const;
150
151 const wxColour& GetTextColour() const;
152 const wxColour& GetBackgroundColour() const;
153 const wxFont& GetFont() const;
154 wxTextAttrAlignment GetAlignment() const;
155 const wxArrayInt& GetTabs() const;
156 long GetLeftIndent() const;
6d2e144a 157 long GetLeftSubIndent() const;
d14a1e28
RD
158 long GetRightIndent() const;
159 long GetFlags() const;
160
dd9f7fea 161 // returns False if we have any attributes set, True otherwise
d14a1e28
RD
162 bool IsDefault() const;
163
164 // return the attribute having the valid font and colours: it uses the
165 // attributes set in attr and falls back first to attrDefault and then to
166 // the text control font/colours for those attributes which are not set
167 static wxTextAttr Combine(const wxTextAttr& attr,
168 const wxTextAttr& attrDef,
169 const wxTextCtrl *text);
170};
171
172//---------------------------------------------------------------------------
173
174// wxTextCtrl: a single or multiple line text zone where user can enter and
175// edit text
ab1f7d2a 176MustHaveApp(wxTextCtrl);
d14a1e28
RD
177class wxTextCtrl : public wxControl
178{
179public:
2b9048c5
RD
180 %pythonAppend wxTextCtrl "self._setOORInfo(self)"
181 %pythonAppend wxTextCtrl() ""
b39c3fa0 182 %typemap(out) wxTextCtrl*; // turn off this typemap
d14a1e28 183
d5573410 184 wxTextCtrl(wxWindow* parent, wxWindowID id=-1,
d14a1e28
RD
185 const wxString& value = wxPyEmptyString,
186 const wxPoint& pos = wxDefaultPosition,
187 const wxSize& size = wxDefaultSize,
188 long style = 0,
189 const wxValidator& validator = wxDefaultValidator,
190 const wxString& name = wxPyTextCtrlNameStr);
1b8c7ba6 191 %RenameCtor(PreTextCtrl, wxTextCtrl());
d14a1e28 192
b39c3fa0
RD
193 // Turn it back on again
194 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); }
195
d5573410 196 bool Create(wxWindow* parent, wxWindowID id=-1,
d14a1e28
RD
197 const wxString& value = wxPyEmptyString,
198 const wxPoint& pos = wxDefaultPosition,
199 const wxSize& size = wxDefaultSize,
200 long style = 0,
201 const wxValidator& validator = wxDefaultValidator,
202 const wxString& name = wxPyTextCtrlNameStr);
203
204
205 virtual wxString GetValue() const;
206 virtual void SetValue(const wxString& value);
207
208 virtual wxString GetRange(long from, long to) const;
209
210 virtual int GetLineLength(long lineNo) const;
211 virtual wxString GetLineText(long lineNo) const;
212 virtual int GetNumberOfLines() const;
213
214 virtual bool IsModified() const;
215 virtual bool IsEditable() const;
216
217 // more readable flag testing methods
218 bool IsSingleLine() const;
219 bool IsMultiLine() const;
220
322913ce
RD
221
222 DocDeclAStr(
223 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
224 "GetSelection() -> (from, to)",
d07d2bc9 225 "If the return values from and to are the same, there is no selection.", "");
d14a1e28
RD
226
227 virtual wxString GetStringSelection() const;
228
229
230 // editing
231 virtual void Clear();
232 virtual void Replace(long from, long to, const wxString& value);
233 virtual void Remove(long from, long to);
234
235 // load/save the controls contents from/to the file
236 virtual bool LoadFile(const wxString& file);
237 virtual bool SaveFile(const wxString& file = wxPyEmptyString);
238
239 // sets/clears the dirty flag
240 virtual void MarkDirty();
241 virtual void DiscardEdits();
242
243 // set the max number of characters which may be entered in a single line
244 // text control
245 virtual void SetMaxLength(unsigned long len);
246
247 // writing text inserts it at the current position, appending always
248 // inserts it at the end
249 virtual void WriteText(const wxString& text);
250 virtual void AppendText(const wxString& text);
251
252 // insert the character which would have resulted from this key event,
dd9f7fea 253 // return True if anything has been inserted
d14a1e28
RD
254 virtual bool EmulateKeyPress(const wxKeyEvent& event);
255
256 // text control under some platforms supports the text styles: these
257 // methods allow to apply the given text style to the given selection or to
258 // set/get the style which will be used for all appended text
259 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
260 virtual bool GetStyle(long position, wxTextAttr& style);
261 virtual bool SetDefaultStyle(const wxTextAttr& style);
262 virtual const wxTextAttr& GetDefaultStyle() const;
263
264 // translate between the position (which is just an index in the text ctrl
265 // considering all its contents as a single strings) and (x, y) coordinates
266 // which represent column and line.
267 virtual long XYToPosition(long x, long y) const;
322913ce
RD
268 DocDeclA(
269 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
270 "PositionToXY(long pos) -> (x, y)");
d14a1e28
RD
271
272 virtual void ShowPosition(long pos);
273
1e53cf51
RD
274
275 DocDeclAStr(
276 virtual wxTextCtrlHitTestResult, HitTest(const wxPoint& pt,
277 long* OUTPUT, long* OUTPUT) const,
50ed1e35 278 "HitTest(Point pt) -> (result, col, row)",
1e61c543
RD
279 "Find the row, col coresponding to the character at the point given in
280pixels. NB: pt is in device coords but is not adjusted for the client
281area origin nor scrolling.", "");
1e53cf51
RD
282
283
1e61c543
RD
284 DocDeclAStrName(
285 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
286 "HitTestPos(Point pt) -> (result, position)",
287 "Find the character position in the text coresponding to the point
288given in pixels. NB: pt is in device coords but is not adjusted for
289the client area origin nor scrolling. ", "",
290 HitTestPos);
291
292
293
d14a1e28
RD
294 // Clipboard operations
295 virtual void Copy();
296 virtual void Cut();
297 virtual void Paste();
298
299 virtual bool CanCopy() const;
300 virtual bool CanCut() const;
301 virtual bool CanPaste() const;
302
303 // Undo/redo
304 virtual void Undo();
305 virtual void Redo();
306
307 virtual bool CanUndo() const;
308 virtual bool CanRedo() const;
309
310 // Insertion point
311 virtual void SetInsertionPoint(long pos);
312 virtual void SetInsertionPointEnd();
313 virtual long GetInsertionPoint() const;
314 virtual long GetLastPosition() const;
315
316 virtual void SetSelection(long from, long to);
317 virtual void SelectAll();
318 virtual void SetEditable(bool editable);
319
320#ifdef __WXMSW__
321 // Caret handling (Windows only)
a72f4631 322 bool ShowNativeCaret(bool show = true);
d14a1e28
RD
323 bool HideNativeCaret();
324#endif
325
326 %extend {
327 // TODO: Add more file-like methods
328 void write(const wxString& text) {
329 self->AppendText(text);
330 }
331 }
332
333 // TODO: replace this when the method is really added to wxTextCtrl
334 %extend {
335 wxString GetString(long from, long to) {
336 return self->GetValue().Mid(from, to - from);
337 }
338 }
339
880715c9
RD
340 static wxVisualAttributes
341 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
d14a1e28
RD
342};
343
344//---------------------------------------------------------------------------
345
346
347%constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
348%constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
349%constant wxEventType wxEVT_COMMAND_TEXT_URL;
350%constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
351
352
353class wxTextUrlEvent : public wxCommandEvent
354{
355public:
356 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
357 long start, long end);
358
359 // get the mouse event which happend over the URL
360 const wxMouseEvent& GetMouseEvent();
361
362 // get the start of the URL
363 long GetURLStart() const;
364
365 // get the end of the URL
366 long GetURLEnd() const;
367};
368
369
370%pythoncode {
371EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
372EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
373EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
374EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
375}
376
377
378
379
380//---------------------------------------------------------------------------
381