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