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