]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_textctrl.i
Fixes for later WinCE versions
[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 // If the return values from and to are the same, there is no selection.
196 virtual void GetSelection(long* OUTPUT, long* OUTPUT) const;
197
198 virtual wxString GetStringSelection() const;
199
200
201 // editing
202 virtual void Clear();
203 virtual void Replace(long from, long to, const wxString& value);
204 virtual void Remove(long from, long to);
205
206 // load/save the controls contents from/to the file
207 virtual bool LoadFile(const wxString& file);
208 virtual bool SaveFile(const wxString& file = wxPyEmptyString);
209
210 // sets/clears the dirty flag
211 virtual void MarkDirty();
212 virtual void DiscardEdits();
213
214 // set the max number of characters which may be entered in a single line
215 // text control
216 virtual void SetMaxLength(unsigned long len);
217
218 // writing text inserts it at the current position, appending always
219 // inserts it at the end
220 virtual void WriteText(const wxString& text);
221 virtual void AppendText(const wxString& text);
222
223 // insert the character which would have resulted from this key event,
224 // return TRUE if anything has been inserted
225 virtual bool EmulateKeyPress(const wxKeyEvent& event);
226
227 // text control under some platforms supports the text styles: these
228 // methods allow to apply the given text style to the given selection or to
229 // set/get the style which will be used for all appended text
230 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
231 virtual bool GetStyle(long position, wxTextAttr& style);
232 virtual bool SetDefaultStyle(const wxTextAttr& style);
233 virtual const wxTextAttr& GetDefaultStyle() const;
234
235 // translate between the position (which is just an index in the text ctrl
236 // considering all its contents as a single strings) and (x, y) coordinates
237 // which represent column and line.
238 virtual long XYToPosition(long x, long y) const;
239 virtual /*bool*/ void PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const;
240
241 virtual void ShowPosition(long pos);
242
243 // Clipboard operations
244 virtual void Copy();
245 virtual void Cut();
246 virtual void Paste();
247
248 virtual bool CanCopy() const;
249 virtual bool CanCut() const;
250 virtual bool CanPaste() const;
251
252 // Undo/redo
253 virtual void Undo();
254 virtual void Redo();
255
256 virtual bool CanUndo() const;
257 virtual bool CanRedo() const;
258
259 // Insertion point
260 virtual void SetInsertionPoint(long pos);
261 virtual void SetInsertionPointEnd();
262 virtual long GetInsertionPoint() const;
263 virtual long GetLastPosition() const;
264
265 virtual void SetSelection(long from, long to);
266 virtual void SelectAll();
267 virtual void SetEditable(bool editable);
268
269 #ifdef __WXMSW__
270 // Caret handling (Windows only)
271 bool ShowNativeCaret(bool show = true);
272 bool HideNativeCaret();
273 #endif
274
275 %extend {
276 // TODO: Add more file-like methods
277 void write(const wxString& text) {
278 self->AppendText(text);
279 }
280 }
281
282 // TODO: replace this when the method is really added to wxTextCtrl
283 %extend {
284 wxString GetString(long from, long to) {
285 return self->GetValue().Mid(from, to - from);
286 }
287 }
288
289 };
290
291 //---------------------------------------------------------------------------
292
293
294 %constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
295 %constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
296 %constant wxEventType wxEVT_COMMAND_TEXT_URL;
297 %constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
298
299
300 class wxTextUrlEvent : public wxCommandEvent
301 {
302 public:
303 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
304 long start, long end);
305
306 // get the mouse event which happend over the URL
307 const wxMouseEvent& GetMouseEvent();
308
309 // get the start of the URL
310 long GetURLStart() const;
311
312 // get the end of the URL
313 long GetURLEnd() const;
314 };
315
316
317 %pythoncode {
318 EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
319 EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
320 EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
321 EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
322 }
323
324
325
326
327 //---------------------------------------------------------------------------
328