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