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 //---------------------------------------------------------------------------
95 // wxTextAttr: a structure containing the visual attributes of a text
101 wxTextAttr(const wxColour& colText,
102 const wxColour& colBack = wxNullColour,
103 const wxFont& font = wxNullFont,
104 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
110 void SetTextColour(const wxColour& colText);
111 void SetBackgroundColour(const wxColour& colBack);
112 void SetFont(const wxFont& font, long flags = wxTEXT_ATTR_FONT);
113 void SetAlignment(wxTextAttrAlignment alignment);
114 void SetTabs(const wxArrayInt& tabs);
115 void SetLeftIndent(int indent);
116 void SetRightIndent(int indent);
117 void SetFlags(long flags);
120 bool HasTextColour() const;
121 bool HasBackgroundColour() const;
122 bool HasFont() const;
123 bool HasAlignment() const;
124 bool HasTabs() const;
125 bool HasLeftIndent() const;
126 bool HasRightIndent() const;
127 bool HasFlag(long flag) const;
129 const wxColour& GetTextColour() const;
130 const wxColour& GetBackgroundColour() const;
131 const wxFont& GetFont() const;
132 wxTextAttrAlignment GetAlignment() const;
133 const wxArrayInt& GetTabs() const;
134 long GetLeftIndent() const;
135 long GetRightIndent() const;
136 long GetFlags() const;
138 // returns False if we have any attributes set, True otherwise
139 bool IsDefault() const;
141 // return the attribute having the valid font and colours: it uses the
142 // attributes set in attr and falls back first to attrDefault and then to
143 // the text control font/colours for those attributes which are not set
144 static wxTextAttr Combine(const wxTextAttr& attr,
145 const wxTextAttr& attrDef,
146 const wxTextCtrl *text);
149 //---------------------------------------------------------------------------
151 // wxTextCtrl: a single or multiple line text zone where user can enter and
153 class wxTextCtrl : public wxControl
156 %addtofunc wxTextCtrl "self._setOORInfo(self)"
157 %addtofunc wxTextCtrl() ""
159 wxTextCtrl(wxWindow* parent, wxWindowID id,
160 const wxString& value = wxPyEmptyString,
161 const wxPoint& pos = wxDefaultPosition,
162 const wxSize& size = wxDefaultSize,
164 const wxValidator& validator = wxDefaultValidator,
165 const wxString& name = wxPyTextCtrlNameStr);
166 %name(PreTextCtrl)wxTextCtrl();
168 bool Create(wxWindow* parent, wxWindowID id,
169 const wxString& value = wxPyEmptyString,
170 const wxPoint& pos = wxDefaultPosition,
171 const wxSize& size = wxDefaultSize,
173 const wxValidator& validator = wxDefaultValidator,
174 const wxString& name = wxPyTextCtrlNameStr);
177 virtual wxString GetValue() const;
178 virtual void SetValue(const wxString& value);
180 virtual wxString GetRange(long from, long to) const;
182 virtual int GetLineLength(long lineNo) const;
183 virtual wxString GetLineText(long lineNo) const;
184 virtual int GetNumberOfLines() const;
186 virtual bool IsModified() const;
187 virtual bool IsEditable() const;
189 // more readable flag testing methods
190 bool IsSingleLine() const;
191 bool IsMultiLine() const;
195 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
196 "GetSelection() -> (from, to)",
197 "If the return values from and to are the same, there is no selection.");
199 virtual wxString GetStringSelection() const;
203 virtual void Clear();
204 virtual void Replace(long from, long to, const wxString& value);
205 virtual void Remove(long from, long to);
207 // load/save the controls contents from/to the file
208 virtual bool LoadFile(const wxString& file);
209 virtual bool SaveFile(const wxString& file = wxPyEmptyString);
211 // sets/clears the dirty flag
212 virtual void MarkDirty();
213 virtual void DiscardEdits();
215 // set the max number of characters which may be entered in a single line
217 virtual void SetMaxLength(unsigned long len);
219 // writing text inserts it at the current position, appending always
220 // inserts it at the end
221 virtual void WriteText(const wxString& text);
222 virtual void AppendText(const wxString& text);
224 // insert the character which would have resulted from this key event,
225 // return True if anything has been inserted
226 virtual bool EmulateKeyPress(const wxKeyEvent& event);
228 // text control under some platforms supports the text styles: these
229 // methods allow to apply the given text style to the given selection or to
230 // set/get the style which will be used for all appended text
231 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
232 virtual bool GetStyle(long position, wxTextAttr& style);
233 virtual bool SetDefaultStyle(const wxTextAttr& style);
234 virtual const wxTextAttr& GetDefaultStyle() const;
236 // translate between the position (which is just an index in the text ctrl
237 // considering all its contents as a single strings) and (x, y) coordinates
238 // which represent column and line.
239 virtual long XYToPosition(long x, long y) const;
241 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
242 "PositionToXY(long pos) -> (x, y)");
244 virtual void ShowPosition(long pos);
246 // Clipboard operations
249 virtual void Paste();
251 virtual bool CanCopy() const;
252 virtual bool CanCut() const;
253 virtual bool CanPaste() const;
259 virtual bool CanUndo() const;
260 virtual bool CanRedo() const;
263 virtual void SetInsertionPoint(long pos);
264 virtual void SetInsertionPointEnd();
265 virtual long GetInsertionPoint() const;
266 virtual long GetLastPosition() const;
268 virtual void SetSelection(long from, long to);
269 virtual void SelectAll();
270 virtual void SetEditable(bool editable);
273 // Caret handling (Windows only)
274 bool ShowNativeCaret(bool show = True);
275 bool HideNativeCaret();
279 // TODO: Add more file-like methods
280 void write(const wxString& text) {
281 self->AppendText(text);
285 // TODO: replace this when the method is really added to wxTextCtrl
287 wxString GetString(long from, long to) {
288 return self->GetValue().Mid(from, to - from);
294 //---------------------------------------------------------------------------
297 %constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
298 %constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
299 %constant wxEventType wxEVT_COMMAND_TEXT_URL;
300 %constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
303 class wxTextUrlEvent : public wxCommandEvent
306 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
307 long start, long end);
309 // get the mouse event which happend over the URL
310 const wxMouseEvent& GetMouseEvent();
312 // get the start of the URL
313 long GetURLStart() const;
315 // get the end of the URL
316 long GetURLEnd() const;
321 EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
322 EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
323 EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
324 EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
330 //---------------------------------------------------------------------------