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