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