1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for wxTextCtrl and related classes
7 // Created: 10-June-1998
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
18 MAKE_CONST_WXSTRING(TextCtrlNameStr);
20 //---------------------------------------------------------------------------
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
45 // automatically detect the URLs and generate the events when mouse is
46 // moved/clicked over an URL
48 // this is for Win32 richedit controls only so far
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
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
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
67 enum wxTextAttrAlignment
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
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,
87 wxTEXT_ATTR_ALIGNMENT,
88 wxTEXT_ATTR_LEFT_INDENT,
89 wxTEXT_ATTR_RIGHT_INDENT,
93 enum wxTextCtrlHitTestResult
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]
102 //---------------------------------------------------------------------------
104 // wxTextAttr: a structure containing the visual attributes of a text
108 %nokwargs wxTextAttr;
110 wxTextAttr(const wxColour& colText,
111 const wxColour& colBack = wxNullColour,
112 const wxFont& font = wxNullFont,
113 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
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, int subIndent=0);
126 void SetRightIndent(int indent);
127 void SetFlags(long flags);
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;
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 GetLeftSubIndent() const;
146 long GetRightIndent() const;
147 long GetFlags() const;
149 // returns False if we have any attributes set, True otherwise
150 bool IsDefault() const;
152 // return the attribute having the valid font and colours: it uses the
153 // attributes set in attr and falls back first to attrDefault and then to
154 // the text control font/colours for those attributes which are not set
155 static wxTextAttr Combine(const wxTextAttr& attr,
156 const wxTextAttr& attrDef,
157 const wxTextCtrl *text);
160 //---------------------------------------------------------------------------
162 // wxTextCtrl: a single or multiple line text zone where user can enter and
164 MustHaveApp(wxTextCtrl);
165 class wxTextCtrl : public wxControl
168 %pythonAppend wxTextCtrl "self._setOORInfo(self)"
169 %pythonAppend wxTextCtrl() ""
171 wxTextCtrl(wxWindow* parent, wxWindowID id=-1,
172 const wxString& value = wxPyEmptyString,
173 const wxPoint& pos = wxDefaultPosition,
174 const wxSize& size = wxDefaultSize,
176 const wxValidator& validator = wxDefaultValidator,
177 const wxString& name = wxPyTextCtrlNameStr);
178 %name(PreTextCtrl)wxTextCtrl();
180 bool Create(wxWindow* parent, wxWindowID id=-1,
181 const wxString& value = wxPyEmptyString,
182 const wxPoint& pos = wxDefaultPosition,
183 const wxSize& size = wxDefaultSize,
185 const wxValidator& validator = wxDefaultValidator,
186 const wxString& name = wxPyTextCtrlNameStr);
189 virtual wxString GetValue() const;
190 virtual void SetValue(const wxString& value);
192 virtual wxString GetRange(long from, long to) const;
194 virtual int GetLineLength(long lineNo) const;
195 virtual wxString GetLineText(long lineNo) const;
196 virtual int GetNumberOfLines() const;
198 virtual bool IsModified() const;
199 virtual bool IsEditable() const;
201 // more readable flag testing methods
202 bool IsSingleLine() const;
203 bool IsMultiLine() const;
207 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
208 "GetSelection() -> (from, to)",
209 "If the return values from and to are the same, there is no selection.", "");
211 virtual wxString GetStringSelection() const;
215 virtual void Clear();
216 virtual void Replace(long from, long to, const wxString& value);
217 virtual void Remove(long from, long to);
219 // load/save the controls contents from/to the file
220 virtual bool LoadFile(const wxString& file);
221 virtual bool SaveFile(const wxString& file = wxPyEmptyString);
223 // sets/clears the dirty flag
224 virtual void MarkDirty();
225 virtual void DiscardEdits();
227 // set the max number of characters which may be entered in a single line
229 virtual void SetMaxLength(unsigned long len);
231 // writing text inserts it at the current position, appending always
232 // inserts it at the end
233 virtual void WriteText(const wxString& text);
234 virtual void AppendText(const wxString& text);
236 // insert the character which would have resulted from this key event,
237 // return True if anything has been inserted
238 virtual bool EmulateKeyPress(const wxKeyEvent& event);
240 // text control under some platforms supports the text styles: these
241 // methods allow to apply the given text style to the given selection or to
242 // set/get the style which will be used for all appended text
243 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
244 virtual bool GetStyle(long position, wxTextAttr& style);
245 virtual bool SetDefaultStyle(const wxTextAttr& style);
246 virtual const wxTextAttr& GetDefaultStyle() const;
248 // translate between the position (which is just an index in the text ctrl
249 // considering all its contents as a single strings) and (x, y) coordinates
250 // which represent column and line.
251 virtual long XYToPosition(long x, long y) const;
253 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
254 "PositionToXY(long pos) -> (x, y)");
256 virtual void ShowPosition(long pos);
260 virtual wxTextCtrlHitTestResult, HitTest(const wxPoint& pt,
261 long* OUTPUT, long* OUTPUT) const,
262 "HitTest(Point pt) -> (result, row, col)",
263 "Find the character at position given in pixels. NB: pt is in device
264 coords but is not adjusted for the client area origin nor scrolling", "");
267 // Clipboard operations
270 virtual void Paste();
272 virtual bool CanCopy() const;
273 virtual bool CanCut() const;
274 virtual bool CanPaste() const;
280 virtual bool CanUndo() const;
281 virtual bool CanRedo() const;
284 virtual void SetInsertionPoint(long pos);
285 virtual void SetInsertionPointEnd();
286 virtual long GetInsertionPoint() const;
287 virtual long GetLastPosition() const;
289 virtual void SetSelection(long from, long to);
290 virtual void SelectAll();
291 virtual void SetEditable(bool editable);
294 // Caret handling (Windows only)
295 bool ShowNativeCaret(bool show = True);
296 bool HideNativeCaret();
300 // TODO: Add more file-like methods
301 void write(const wxString& text) {
302 self->AppendText(text);
306 // TODO: replace this when the method is really added to wxTextCtrl
308 wxString GetString(long from, long to) {
309 return self->GetValue().Mid(from, to - from);
313 static wxVisualAttributes
314 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
317 //---------------------------------------------------------------------------
320 %constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
321 %constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
322 %constant wxEventType wxEVT_COMMAND_TEXT_URL;
323 %constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
326 class wxTextUrlEvent : public wxCommandEvent
329 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
330 long start, long end);
332 // get the mouse event which happend over the URL
333 const wxMouseEvent& GetMouseEvent();
335 // get the start of the URL
336 long GetURLStart() const;
338 // get the end of the URL
339 long GetURLEnd() const;
344 EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
345 EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
346 EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
347 EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
353 //---------------------------------------------------------------------------