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