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