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 //---------------------------------------------------------------------------
19 DECLARE_DEF_STRING(TextCtrlNameStr);
22 //---------------------------------------------------------------------------
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
47 // automatically detect the URLs and generate the events when mouse is
48 // moved/clicked over an URL
50 // this is for Win32 richedit controls only so far
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
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
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
69 enum wxTextAttrAlignment
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
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,
89 wxTEXT_ATTR_ALIGNMENT,
90 wxTEXT_ATTR_LEFT_INDENT,
91 wxTEXT_ATTR_RIGHT_INDENT,
95 //---------------------------------------------------------------------------
97 // wxTextAttr: a structure containing the visual attributes of a text
101 %nokwargs wxTextAttr;
103 wxTextAttr(const wxColour& colText,
104 const wxColour& colBack = wxNullColour,
105 const wxFont& font = wxNullFont,
106 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
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);
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;
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;
140 // returns False if we have any attributes set, True otherwise
141 bool IsDefault() const;
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);
151 //---------------------------------------------------------------------------
153 // wxTextCtrl: a single or multiple line text zone where user can enter and
155 class wxTextCtrl : public wxControl
158 %addtofunc wxTextCtrl "self._setOORInfo(self)"
159 %addtofunc wxTextCtrl() ""
161 wxTextCtrl(wxWindow* parent, wxWindowID id,
162 const wxString& value = wxPyEmptyString,
163 const wxPoint& pos = wxDefaultPosition,
164 const wxSize& size = wxDefaultSize,
166 const wxValidator& validator = wxDefaultValidator,
167 const wxString& name = wxPyTextCtrlNameStr);
168 %name(PreTextCtrl)wxTextCtrl();
170 bool Create(wxWindow* parent, wxWindowID id,
171 const wxString& value = wxPyEmptyString,
172 const wxPoint& pos = wxDefaultPosition,
173 const wxSize& size = wxDefaultSize,
175 const wxValidator& validator = wxDefaultValidator,
176 const wxString& name = wxPyTextCtrlNameStr);
179 virtual wxString GetValue() const;
180 virtual void SetValue(const wxString& value);
182 virtual wxString GetRange(long from, long to) const;
184 virtual int GetLineLength(long lineNo) const;
185 virtual wxString GetLineText(long lineNo) const;
186 virtual int GetNumberOfLines() const;
188 virtual bool IsModified() const;
189 virtual bool IsEditable() const;
191 // more readable flag testing methods
192 bool IsSingleLine() const;
193 bool IsMultiLine() const;
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.");
201 virtual wxString GetStringSelection() const;
205 virtual void Clear();
206 virtual void Replace(long from, long to, const wxString& value);
207 virtual void Remove(long from, long to);
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);
213 // sets/clears the dirty flag
214 virtual void MarkDirty();
215 virtual void DiscardEdits();
217 // set the max number of characters which may be entered in a single line
219 virtual void SetMaxLength(unsigned long len);
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);
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);
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;
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;
243 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
244 "PositionToXY(long pos) -> (x, y)");
246 virtual void ShowPosition(long pos);
248 // Clipboard operations
251 virtual void Paste();
253 virtual bool CanCopy() const;
254 virtual bool CanCut() const;
255 virtual bool CanPaste() const;
261 virtual bool CanUndo() const;
262 virtual bool CanRedo() const;
265 virtual void SetInsertionPoint(long pos);
266 virtual void SetInsertionPointEnd();
267 virtual long GetInsertionPoint() const;
268 virtual long GetLastPosition() const;
270 virtual void SetSelection(long from, long to);
271 virtual void SelectAll();
272 virtual void SetEditable(bool editable);
275 // Caret handling (Windows only)
276 bool ShowNativeCaret(bool show = True);
277 bool HideNativeCaret();
281 // TODO: Add more file-like methods
282 void write(const wxString& text) {
283 self->AppendText(text);
287 // TODO: replace this when the method is really added to wxTextCtrl
289 wxString GetString(long from, long to) {
290 return self->GetValue().Mid(from, to - from);
296 //---------------------------------------------------------------------------
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;
305 class wxTextUrlEvent : public wxCommandEvent
308 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
309 long start, long end);
311 // get the mouse event which happend over the URL
312 const wxMouseEvent& GetMouseEvent();
314 // get the start of the URL
315 long GetURLStart() const;
317 // get the end of the URL
318 long GetURLEnd() const;
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)
332 //---------------------------------------------------------------------------