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;
195 // If the return values from and to are the same, there is no selection.
196 virtual void GetSelection(long* OUTPUT, long* OUTPUT) const;
198 virtual wxString GetStringSelection() const;
202 virtual void Clear();
203 virtual void Replace(long from, long to, const wxString& value);
204 virtual void Remove(long from, long to);
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);
210 // sets/clears the dirty flag
211 virtual void MarkDirty();
212 virtual void DiscardEdits();
214 // set the max number of characters which may be entered in a single line
216 virtual void SetMaxLength(unsigned long len);
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);
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);
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;
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;
241 virtual void ShowPosition(long pos);
243 // Clipboard operations
246 virtual void Paste();
248 virtual bool CanCopy() const;
249 virtual bool CanCut() const;
250 virtual bool CanPaste() const;
256 virtual bool CanUndo() const;
257 virtual bool CanRedo() const;
260 virtual void SetInsertionPoint(long pos);
261 virtual void SetInsertionPointEnd();
262 virtual long GetInsertionPoint() const;
263 virtual long GetLastPosition() const;
265 virtual void SetSelection(long from, long to);
266 virtual void SelectAll();
267 virtual void SetEditable(bool editable);
270 // Caret handling (Windows only)
271 bool ShowNativeCaret(bool show = true);
272 bool HideNativeCaret();
276 // TODO: Add more file-like methods
277 void write(const wxString& text) {
278 self->AppendText(text);
282 // TODO: replace this when the method is really added to wxTextCtrl
284 wxString GetString(long from, long to) {
285 return self->GetValue().Mid(from, to - from);
291 //---------------------------------------------------------------------------
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;
300 class wxTextUrlEvent : public wxCommandEvent
303 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
304 long start, long end);
306 // get the mouse event which happend over the URL
307 const wxMouseEvent& GetMouseEvent();
309 // get the start of the URL
310 long GetURLStart() const;
312 // get the end of the URL
313 long GetURLEnd() const;
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)
327 //---------------------------------------------------------------------------