]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_textctrl.i
Added a typecheck typmap for wxString
[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 //---------------------------------------------------------------------------
94
95 // wxTextAttr: a structure containing the visual attributes of a text
96 class wxTextAttr
97 {
98 public:
99 %nokwargs wxTextAttr;
100 wxTextAttr();
101 wxTextAttr(const wxColour& colText,
102 const wxColour& colBack = wxNullColour,
103 const wxFont& font = wxNullFont,
104 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
105 ~wxTextAttr();
106
107 // operations
108 void Init();
109
110 // setters
111 void SetTextColour(const wxColour& colText);
112 void SetBackgroundColour(const wxColour& colBack);
113 void SetFont(const wxFont& font, long flags = wxTEXT_ATTR_FONT);
114 void SetAlignment(wxTextAttrAlignment alignment);
115 void SetTabs(const wxArrayInt& tabs);
116 void SetLeftIndent(int indent);
117 void SetRightIndent(int indent);
118 void SetFlags(long flags);
119
120 // accessors
121 bool HasTextColour() const;
122 bool HasBackgroundColour() const;
123 bool HasFont() const;
124 bool HasAlignment() const;
125 bool HasTabs() const;
126 bool HasLeftIndent() const;
127 bool HasRightIndent() const;
128 bool HasFlag(long flag) const;
129
130 const wxColour& GetTextColour() const;
131 const wxColour& GetBackgroundColour() const;
132 const wxFont& GetFont() const;
133 wxTextAttrAlignment GetAlignment() const;
134 const wxArrayInt& GetTabs() const;
135 long GetLeftIndent() const;
136 long GetRightIndent() const;
137 long GetFlags() const;
138
139 // returns False if we have any attributes set, True otherwise
140 bool IsDefault() const;
141
142 // return the attribute having the valid font and colours: it uses the
143 // attributes set in attr and falls back first to attrDefault and then to
144 // the text control font/colours for those attributes which are not set
145 static wxTextAttr Combine(const wxTextAttr& attr,
146 const wxTextAttr& attrDef,
147 const wxTextCtrl *text);
148 };
149
150 //---------------------------------------------------------------------------
151
152 // wxTextCtrl: a single or multiple line text zone where user can enter and
153 // edit text
154 class wxTextCtrl : public wxControl
155 {
156 public:
157 %pythonAppend wxTextCtrl "self._setOORInfo(self)"
158 %pythonAppend wxTextCtrl() ""
159
160 wxTextCtrl(wxWindow* parent, wxWindowID id,
161 const wxString& value = wxPyEmptyString,
162 const wxPoint& pos = wxDefaultPosition,
163 const wxSize& size = wxDefaultSize,
164 long style = 0,
165 const wxValidator& validator = wxDefaultValidator,
166 const wxString& name = wxPyTextCtrlNameStr);
167 %name(PreTextCtrl)wxTextCtrl();
168
169 bool Create(wxWindow* parent, wxWindowID id,
170 const wxString& value = wxPyEmptyString,
171 const wxPoint& pos = wxDefaultPosition,
172 const wxSize& size = wxDefaultSize,
173 long style = 0,
174 const wxValidator& validator = wxDefaultValidator,
175 const wxString& name = wxPyTextCtrlNameStr);
176
177
178 virtual wxString GetValue() const;
179 virtual void SetValue(const wxString& value);
180
181 virtual wxString GetRange(long from, long to) const;
182
183 virtual int GetLineLength(long lineNo) const;
184 virtual wxString GetLineText(long lineNo) const;
185 virtual int GetNumberOfLines() const;
186
187 virtual bool IsModified() const;
188 virtual bool IsEditable() const;
189
190 // more readable flag testing methods
191 bool IsSingleLine() const;
192 bool IsMultiLine() const;
193
194
195 DocDeclAStr(
196 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
197 "GetSelection() -> (from, to)",
198 "If the return values from and to are the same, there is no selection.");
199
200 virtual wxString GetStringSelection() const;
201
202
203 // editing
204 virtual void Clear();
205 virtual void Replace(long from, long to, const wxString& value);
206 virtual void Remove(long from, long to);
207
208 // load/save the controls contents from/to the file
209 virtual bool LoadFile(const wxString& file);
210 virtual bool SaveFile(const wxString& file = wxPyEmptyString);
211
212 // sets/clears the dirty flag
213 virtual void MarkDirty();
214 virtual void DiscardEdits();
215
216 // set the max number of characters which may be entered in a single line
217 // text control
218 virtual void SetMaxLength(unsigned long len);
219
220 // writing text inserts it at the current position, appending always
221 // inserts it at the end
222 virtual void WriteText(const wxString& text);
223 virtual void AppendText(const wxString& text);
224
225 // insert the character which would have resulted from this key event,
226 // return True if anything has been inserted
227 virtual bool EmulateKeyPress(const wxKeyEvent& event);
228
229 // text control under some platforms supports the text styles: these
230 // methods allow to apply the given text style to the given selection or to
231 // set/get the style which will be used for all appended text
232 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
233 virtual bool GetStyle(long position, wxTextAttr& style);
234 virtual bool SetDefaultStyle(const wxTextAttr& style);
235 virtual const wxTextAttr& GetDefaultStyle() const;
236
237 // translate between the position (which is just an index in the text ctrl
238 // considering all its contents as a single strings) and (x, y) coordinates
239 // which represent column and line.
240 virtual long XYToPosition(long x, long y) const;
241 DocDeclA(
242 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
243 "PositionToXY(long pos) -> (x, y)");
244
245 virtual void ShowPosition(long pos);
246
247 // Clipboard operations
248 virtual void Copy();
249 virtual void Cut();
250 virtual void Paste();
251
252 virtual bool CanCopy() const;
253 virtual bool CanCut() const;
254 virtual bool CanPaste() const;
255
256 // Undo/redo
257 virtual void Undo();
258 virtual void Redo();
259
260 virtual bool CanUndo() const;
261 virtual bool CanRedo() const;
262
263 // Insertion point
264 virtual void SetInsertionPoint(long pos);
265 virtual void SetInsertionPointEnd();
266 virtual long GetInsertionPoint() const;
267 virtual long GetLastPosition() const;
268
269 virtual void SetSelection(long from, long to);
270 virtual void SelectAll();
271 virtual void SetEditable(bool editable);
272
273 #ifdef __WXMSW__
274 // Caret handling (Windows only)
275 bool ShowNativeCaret(bool show = True);
276 bool HideNativeCaret();
277 #endif
278
279 %extend {
280 // TODO: Add more file-like methods
281 void write(const wxString& text) {
282 self->AppendText(text);
283 }
284 }
285
286 // TODO: replace this when the method is really added to wxTextCtrl
287 %extend {
288 wxString GetString(long from, long to) {
289 return self->GetValue().Mid(from, to - from);
290 }
291 }
292
293 };
294
295 //---------------------------------------------------------------------------
296
297
298 %constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
299 %constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
300 %constant wxEventType wxEVT_COMMAND_TEXT_URL;
301 %constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
302
303
304 class wxTextUrlEvent : public wxCommandEvent
305 {
306 public:
307 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
308 long start, long end);
309
310 // get the mouse event which happend over the URL
311 const wxMouseEvent& GetMouseEvent();
312
313 // get the start of the URL
314 long GetURLStart() const;
315
316 // get the end of the URL
317 long GetURLEnd() const;
318 };
319
320
321 %pythoncode {
322 EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
323 EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
324 EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
325 EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
326 }
327
328
329
330
331 //---------------------------------------------------------------------------
332