]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_textctrl.i
use the right number in the tarball filename
[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
d14a1e28
RD
64 // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for
65 // wxTE_RICH controls - can be used together with or instead of wxTE_RICH
66 wxTE_RICH2,
4fee07f2
RD
67
68 wxTE_CAPITALIZE,
d14a1e28
RD
69};
70
15648073
RD
71%pythoncode { TE_LINEWRAP = TE_CHARWRAP }
72
73
d14a1e28
RD
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,
f5263701
RD
113 wxInvalidTextCoord,
114
115 wxTEXT_TYPE_ANY
aeee37c3
RD
116};
117
d14a1e28
RD
118//---------------------------------------------------------------------------
119
120// wxTextAttr: a structure containing the visual attributes of a text
121class wxTextAttr
122{
123public:
015256c0 124 wxTextAttr(const wxColour& colText = wxNullColour,
d14a1e28
RD
125 const wxColour& colBack = wxNullColour,
126 const wxFont& font = wxNullFont,
127 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
2b9048c5
RD
128 ~wxTextAttr();
129
d14a1e28
RD
130 // operations
131 void Init();
132
68d76e73
RD
133 // merges the attributes of the base and the overlay objects and returns
134 // the result; the parameter attributes take precedence
135 //
136 // WARNING: the order of arguments is the opposite of Combine()
137 static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay);
138
139// // merges the attributes of this object and overlay
140// void Merge(const wxTextAttr& overlay);
141
142
d14a1e28
RD
143 // setters
144 void SetTextColour(const wxColour& colText);
145 void SetBackgroundColour(const wxColour& colBack);
146 void SetFont(const wxFont& font, long flags = wxTEXT_ATTR_FONT);
147 void SetAlignment(wxTextAttrAlignment alignment);
148 void SetTabs(const wxArrayInt& tabs);
6d2e144a 149 void SetLeftIndent(int indent, int subIndent=0);
d14a1e28
RD
150 void SetRightIndent(int indent);
151 void SetFlags(long flags);
152
153 // accessors
154 bool HasTextColour() const;
155 bool HasBackgroundColour() const;
156 bool HasFont() const;
157 bool HasAlignment() const;
158 bool HasTabs() const;
159 bool HasLeftIndent() const;
160 bool HasRightIndent() const;
161 bool HasFlag(long flag) const;
162
163 const wxColour& GetTextColour() const;
164 const wxColour& GetBackgroundColour() const;
165 const wxFont& GetFont() const;
166 wxTextAttrAlignment GetAlignment() const;
167 const wxArrayInt& GetTabs() const;
168 long GetLeftIndent() const;
6d2e144a 169 long GetLeftSubIndent() const;
d14a1e28
RD
170 long GetRightIndent() const;
171 long GetFlags() const;
172
dd9f7fea 173 // returns False if we have any attributes set, True otherwise
d14a1e28
RD
174 bool IsDefault() const;
175
176 // return the attribute having the valid font and colours: it uses the
177 // attributes set in attr and falls back first to attrDefault and then to
178 // the text control font/colours for those attributes which are not set
179 static wxTextAttr Combine(const wxTextAttr& attr,
180 const wxTextAttr& attrDef,
181 const wxTextCtrl *text);
994453b8
RD
182
183 %property(Alignment, GetAlignment, SetAlignment, doc="See `GetAlignment` and `SetAlignment`");
184 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
185 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
186 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
187 %property(LeftIndent, GetLeftIndent, SetLeftIndent, doc="See `GetLeftIndent` and `SetLeftIndent`");
188 %property(LeftSubIndent, GetLeftSubIndent, doc="See `GetLeftSubIndent`");
189 %property(RightIndent, GetRightIndent, SetRightIndent, doc="See `GetRightIndent` and `SetRightIndent`");
190 %property(Tabs, GetTabs, SetTabs, doc="See `GetTabs` and `SetTabs`");
191 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
d14a1e28
RD
192};
193
194//---------------------------------------------------------------------------
195
196// wxTextCtrl: a single or multiple line text zone where user can enter and
197// edit text
ab1f7d2a 198MustHaveApp(wxTextCtrl);
d14a1e28
RD
199class wxTextCtrl : public wxControl
200{
201public:
2b9048c5
RD
202 %pythonAppend wxTextCtrl "self._setOORInfo(self)"
203 %pythonAppend wxTextCtrl() ""
b39c3fa0 204 %typemap(out) wxTextCtrl*; // turn off this typemap
d14a1e28 205
d5573410 206 wxTextCtrl(wxWindow* parent, wxWindowID id=-1,
d14a1e28
RD
207 const wxString& value = wxPyEmptyString,
208 const wxPoint& pos = wxDefaultPosition,
209 const wxSize& size = wxDefaultSize,
210 long style = 0,
211 const wxValidator& validator = wxDefaultValidator,
212 const wxString& name = wxPyTextCtrlNameStr);
1b8c7ba6 213 %RenameCtor(PreTextCtrl, wxTextCtrl());
d14a1e28 214
b39c3fa0
RD
215 // Turn it back on again
216 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); }
217
d5573410 218 bool Create(wxWindow* parent, wxWindowID id=-1,
d14a1e28
RD
219 const wxString& value = wxPyEmptyString,
220 const wxPoint& pos = wxDefaultPosition,
221 const wxSize& size = wxDefaultSize,
222 long style = 0,
223 const wxValidator& validator = wxDefaultValidator,
224 const wxString& name = wxPyTextCtrlNameStr);
225
226
227 virtual wxString GetValue() const;
228 virtual void SetValue(const wxString& value);
229
3f3bf980
RD
230 virtual bool IsEmpty() const;
231
232 virtual void ChangeValue(const wxString &value);
233
d14a1e28
RD
234 virtual wxString GetRange(long from, long to) const;
235
236 virtual int GetLineLength(long lineNo) const;
237 virtual wxString GetLineText(long lineNo) const;
238 virtual int GetNumberOfLines() const;
239
240 virtual bool IsModified() const;
241 virtual bool IsEditable() const;
242
243 // more readable flag testing methods
244 bool IsSingleLine() const;
245 bool IsMultiLine() const;
246
322913ce
RD
247
248 DocDeclAStr(
249 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
250 "GetSelection() -> (from, to)",
d07d2bc9 251 "If the return values from and to are the same, there is no selection.", "");
d14a1e28
RD
252
253 virtual wxString GetStringSelection() const;
254
255
256 // editing
257 virtual void Clear();
258 virtual void Replace(long from, long to, const wxString& value);
259 virtual void Remove(long from, long to);
260
261 // load/save the controls contents from/to the file
f5263701
RD
262 virtual bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY);
263 virtual bool SaveFile(const wxString& file = wxPyEmptyString, int fileType = wxTEXT_TYPE_ANY);
d14a1e28
RD
264
265 // sets/clears the dirty flag
266 virtual void MarkDirty();
267 virtual void DiscardEdits();
48e71d8a
RD
268 void SetModified(bool modified);
269
d14a1e28
RD
270 // set the max number of characters which may be entered in a single line
271 // text control
272 virtual void SetMaxLength(unsigned long len);
273
274 // writing text inserts it at the current position, appending always
275 // inserts it at the end
276 virtual void WriteText(const wxString& text);
277 virtual void AppendText(const wxString& text);
278
279 // insert the character which would have resulted from this key event,
dd9f7fea 280 // return True if anything has been inserted
d14a1e28
RD
281 virtual bool EmulateKeyPress(const wxKeyEvent& event);
282
283 // text control under some platforms supports the text styles: these
284 // methods allow to apply the given text style to the given selection or to
285 // set/get the style which will be used for all appended text
286 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
287 virtual bool GetStyle(long position, wxTextAttr& style);
288 virtual bool SetDefaultStyle(const wxTextAttr& style);
289 virtual const wxTextAttr& GetDefaultStyle() const;
290
291 // translate between the position (which is just an index in the text ctrl
292 // considering all its contents as a single strings) and (x, y) coordinates
293 // which represent column and line.
294 virtual long XYToPosition(long x, long y) const;
322913ce
RD
295 DocDeclA(
296 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
297 "PositionToXY(long pos) -> (x, y)");
d14a1e28
RD
298
299 virtual void ShowPosition(long pos);
300
1e53cf51
RD
301
302 DocDeclAStr(
303 virtual wxTextCtrlHitTestResult, HitTest(const wxPoint& pt,
304 long* OUTPUT, long* OUTPUT) const,
50ed1e35 305 "HitTest(Point pt) -> (result, col, row)",
1e61c543
RD
306 "Find the row, col coresponding to the character at the point given in
307pixels. NB: pt is in device coords but is not adjusted for the client
308area origin nor scrolling.", "");
1e53cf51
RD
309
310
1e61c543
RD
311 DocDeclAStrName(
312 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
313 "HitTestPos(Point pt) -> (result, position)",
314 "Find the character position in the text coresponding to the point
315given in pixels. NB: pt is in device coords but is not adjusted for
316the client area origin nor scrolling. ", "",
317 HitTestPos);
318
319
320
d14a1e28
RD
321 // Clipboard operations
322 virtual void Copy();
323 virtual void Cut();
324 virtual void Paste();
325
326 virtual bool CanCopy() const;
327 virtual bool CanCut() const;
328 virtual bool CanPaste() const;
329
330 // Undo/redo
331 virtual void Undo();
332 virtual void Redo();
333
334 virtual bool CanUndo() const;
335 virtual bool CanRedo() const;
336
337 // Insertion point
338 virtual void SetInsertionPoint(long pos);
339 virtual void SetInsertionPointEnd();
340 virtual long GetInsertionPoint() const;
341 virtual long GetLastPosition() const;
342
343 virtual void SetSelection(long from, long to);
344 virtual void SelectAll();
345 virtual void SetEditable(bool editable);
346
3f3bf980
RD
347 // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does
348 void SendTextUpdatedEvent();
349
d14a1e28
RD
350#ifdef __WXMSW__
351 // Caret handling (Windows only)
a72f4631 352 bool ShowNativeCaret(bool show = true);
d14a1e28
RD
353 bool HideNativeCaret();
354#endif
355
356 %extend {
357 // TODO: Add more file-like methods
358 void write(const wxString& text) {
359 self->AppendText(text);
360 }
361 }
362
363 // TODO: replace this when the method is really added to wxTextCtrl
364 %extend {
365 wxString GetString(long from, long to) {
366 return self->GetValue().Mid(from, to - from);
367 }
368 }
369
880715c9
RD
370 static wxVisualAttributes
371 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
994453b8
RD
372
373 %property(DefaultStyle, GetDefaultStyle, SetDefaultStyle, doc="See `GetDefaultStyle` and `SetDefaultStyle`");
374 %property(InsertionPoint, GetInsertionPoint, SetInsertionPoint, doc="See `GetInsertionPoint` and `SetInsertionPoint`");
375 %property(LastPosition, GetLastPosition, doc="See `GetLastPosition`");
376 %property(NumberOfLines, GetNumberOfLines, doc="See `GetNumberOfLines`");
377 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
378 %property(StringSelection, GetStringSelection, doc="See `GetStringSelection`");
379 %property(Value, GetValue, SetValue, doc="See `GetValue` and `SetValue`");
d14a1e28
RD
380};
381
382//---------------------------------------------------------------------------
383
384
385%constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
386%constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
387%constant wxEventType wxEVT_COMMAND_TEXT_URL;
388%constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
389
390
391class wxTextUrlEvent : public wxCommandEvent
392{
393public:
394 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
395 long start, long end);
396
397 // get the mouse event which happend over the URL
398 const wxMouseEvent& GetMouseEvent();
399
400 // get the start of the URL
401 long GetURLStart() const;
402
403 // get the end of the URL
404 long GetURLEnd() const;
994453b8
RD
405
406 %property(MouseEvent, GetMouseEvent, doc="See `GetMouseEvent`");
407 %property(URLEnd, GetURLEnd, doc="See `GetURLEnd`");
408 %property(URLStart, GetURLStart, doc="See `GetURLStart`");
d14a1e28
RD
409};
410
411
412%pythoncode {
413EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
414EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
415EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
416EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
417}
418
419
420
421
422//---------------------------------------------------------------------------
423