]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_textctrl.i
remove sole makefile.dmc in tree
[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 MAKE_CONST_WXSTRING(TextCtrlNameStr);
19
20 //---------------------------------------------------------------------------
21 %newgroup
22
23 enum {
24 // Style flags
25 wxTE_NO_VSCROLL,
26 wxTE_AUTO_SCROLL,
27
28 wxTE_READONLY,
29 wxTE_MULTILINE,
30 wxTE_PROCESS_TAB,
31
32 // alignment flags
33 wxTE_LEFT,
34 wxTE_CENTER,
35 wxTE_RIGHT,
36 wxTE_CENTRE,
37
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
40 wxTE_RICH,
41
42 wxTE_PROCESS_ENTER,
43 wxTE_PASSWORD,
44
45 // automatically detect the URLs and generate the events when mouse is
46 // moved/clicked over an URL
47 //
48 // this is for Win32 richedit controls only so far
49 wxTE_AUTO_URL,
50
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
53 wxTE_NOHIDESEL,
54
55 // use wxHSCROLL (wxTE_DONTWRAP) to not wrap text at all, wxTE_CHARWRAP to
56 // wrap it at any position and wxTE_WORDWRAP to wrap at words boundary
57 //
58 // if no wrapping style is given at all, the control wraps at word boundary
59 wxTE_DONTWRAP,
60 wxTE_CHARWRAP,
61 wxTE_WORDWRAP,
62 wxTE_BESTWRAP,
63
64 // force using RichEdit version 2.0 or 3.0 instead of 1.0 (default) for
65 // wxTE_RICH controls - can be used together with or instead of wxTE_RICH
66 wxTE_RICH2,
67
68 wxTE_CAPITALIZE,
69 };
70
71 %pythoncode { TE_LINEWRAP = TE_CHARWRAP }
72
73 // deprecated synonymns
74 %pythoncode {
75 PROCESS_ENTER = TE_PROCESS_ENTER
76 PASSWORD = TE_PASSWORD
77 }
78
79
80
81 enum wxTextAttrAlignment
82 {
83 wxTEXT_ALIGNMENT_DEFAULT,
84 wxTEXT_ALIGNMENT_LEFT,
85 wxTEXT_ALIGNMENT_CENTRE,
86 wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
87 wxTEXT_ALIGNMENT_RIGHT,
88 wxTEXT_ALIGNMENT_JUSTIFIED
89 };
90
91 enum {
92 // Flags to indicate which attributes are being applied
93 wxTEXT_ATTR_TEXT_COLOUR,
94 wxTEXT_ATTR_BACKGROUND_COLOUR,
95 wxTEXT_ATTR_FONT_FACE,
96 wxTEXT_ATTR_FONT_SIZE,
97 wxTEXT_ATTR_FONT_WEIGHT,
98 wxTEXT_ATTR_FONT_ITALIC,
99 wxTEXT_ATTR_FONT_UNDERLINE,
100 wxTEXT_ATTR_FONT,
101 wxTEXT_ATTR_ALIGNMENT,
102 wxTEXT_ATTR_LEFT_INDENT,
103 wxTEXT_ATTR_RIGHT_INDENT,
104 wxTEXT_ATTR_TABS
105 };
106
107 enum wxTextCtrlHitTestResult
108 {
109 wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
110 wxTE_HT_BEFORE, // either to the left or upper
111 wxTE_HT_ON_TEXT, // directly on
112 wxTE_HT_BELOW, // below [the last line]
113 wxTE_HT_BEYOND // after [the end of line]
114 };
115
116
117 enum {
118 wxOutOfRangeTextCoord,
119 wxInvalidTextCoord,
120
121 wxTEXT_TYPE_ANY
122 };
123
124 //---------------------------------------------------------------------------
125
126 // wxTextAttr: a structure containing the visual attributes of a text
127 class wxTextAttr
128 {
129 public:
130 wxTextAttr(const wxColour& colText = wxNullColour,
131 const wxColour& colBack = wxNullColour,
132 const wxFont& font = wxNullFont,
133 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
134 ~wxTextAttr();
135
136 // operations
137 void Init();
138
139 // merges the attributes of the base and the overlay objects and returns
140 // the result; the parameter attributes take precedence
141 //
142 // WARNING: the order of arguments is the opposite of Combine()
143 static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay);
144
145 // // merges the attributes of this object and overlay
146 // void Merge(const wxTextAttr& overlay);
147
148
149 // setters
150 void SetTextColour(const wxColour& colText);
151 void SetBackgroundColour(const wxColour& colBack);
152 void SetFont(const wxFont& font, long flags = wxTEXT_ATTR_FONT);
153 void SetAlignment(wxTextAttrAlignment alignment);
154 void SetTabs(const wxArrayInt& tabs);
155 void SetLeftIndent(int indent, int subIndent=0);
156 void SetRightIndent(int indent);
157 void SetFlags(long flags);
158
159 // accessors
160 bool HasTextColour() const;
161 bool HasBackgroundColour() const;
162 bool HasFont() const;
163 bool HasAlignment() const;
164 bool HasTabs() const;
165 bool HasLeftIndent() const;
166 bool HasRightIndent() const;
167 bool HasFlag(long flag) const;
168
169 const wxColour& GetTextColour() const;
170 const wxColour& GetBackgroundColour() const;
171 const wxFont& GetFont() const;
172 wxTextAttrAlignment GetAlignment() const;
173 const wxArrayInt& GetTabs() const;
174 long GetLeftIndent() const;
175 long GetLeftSubIndent() const;
176 long GetRightIndent() const;
177 long GetFlags() const;
178
179 // returns False if we have any attributes set, True otherwise
180 bool IsDefault() const;
181
182 // return the attribute having the valid font and colours: it uses the
183 // attributes set in attr and falls back first to attrDefault and then to
184 // the text control font/colours for those attributes which are not set
185 static wxTextAttr Combine(const wxTextAttr& attr,
186 const wxTextAttr& attrDef,
187 const wxTextCtrl *text);
188
189 %property(Alignment, GetAlignment, SetAlignment, doc="See `GetAlignment` and `SetAlignment`");
190 %property(BackgroundColour, GetBackgroundColour, SetBackgroundColour, doc="See `GetBackgroundColour` and `SetBackgroundColour`");
191 %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`");
192 %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`");
193 %property(LeftIndent, GetLeftIndent, SetLeftIndent, doc="See `GetLeftIndent` and `SetLeftIndent`");
194 %property(LeftSubIndent, GetLeftSubIndent, doc="See `GetLeftSubIndent`");
195 %property(RightIndent, GetRightIndent, SetRightIndent, doc="See `GetRightIndent` and `SetRightIndent`");
196 %property(Tabs, GetTabs, SetTabs, doc="See `GetTabs` and `SetTabs`");
197 %property(TextColour, GetTextColour, SetTextColour, doc="See `GetTextColour` and `SetTextColour`");
198 };
199
200 //---------------------------------------------------------------------------
201
202 // wxTextCtrl: a single or multiple line text zone where user can enter and
203 // edit text
204 MustHaveApp(wxTextCtrl);
205 class wxTextCtrl : public wxControl
206 {
207 public:
208 %pythonAppend wxTextCtrl "self._setOORInfo(self)"
209 %pythonAppend wxTextCtrl() ""
210 %typemap(out) wxTextCtrl*; // turn off this typemap
211
212 wxTextCtrl(wxWindow* parent, wxWindowID id=-1,
213 const wxString& value = wxPyEmptyString,
214 const wxPoint& pos = wxDefaultPosition,
215 const wxSize& size = wxDefaultSize,
216 long style = 0,
217 const wxValidator& validator = wxDefaultValidator,
218 const wxString& name = wxPyTextCtrlNameStr);
219 %RenameCtor(PreTextCtrl, wxTextCtrl());
220
221 // Turn it back on again
222 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); }
223
224 bool Create(wxWindow* parent, wxWindowID id=-1,
225 const wxString& value = wxPyEmptyString,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize,
228 long style = 0,
229 const wxValidator& validator = wxDefaultValidator,
230 const wxString& name = wxPyTextCtrlNameStr);
231
232
233 virtual wxString GetValue() const;
234 virtual void SetValue(const wxString& value);
235
236 virtual bool IsEmpty() const;
237
238 virtual void ChangeValue(const wxString &value);
239
240 virtual wxString GetRange(long from, long to) const;
241
242 virtual int GetLineLength(long lineNo) const;
243 virtual wxString GetLineText(long lineNo) const;
244 virtual int GetNumberOfLines() const;
245
246 virtual bool IsModified() const;
247 virtual bool IsEditable() const;
248
249 // more readable flag testing methods
250 bool IsSingleLine() const;
251 bool IsMultiLine() const;
252
253
254 DocDeclAStr(
255 virtual void, GetSelection(long* OUTPUT, long* OUTPUT) const,
256 "GetSelection() -> (from, to)",
257 "If the return values from and to are the same, there is no selection.", "");
258
259 virtual wxString GetStringSelection() const;
260
261
262 // editing
263 virtual void Clear();
264 virtual void Replace(long from, long to, const wxString& value);
265 virtual void Remove(long from, long to);
266
267 // load/save the controls contents from/to the file
268 virtual bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY);
269 virtual bool SaveFile(const wxString& file = wxPyEmptyString, int fileType = wxTEXT_TYPE_ANY);
270
271 // sets/clears the dirty flag
272 virtual void MarkDirty();
273 virtual void DiscardEdits();
274 void SetModified(bool modified);
275
276 // set the max number of characters which may be entered in a single line
277 // text control
278 virtual void SetMaxLength(unsigned long len);
279
280 // writing text inserts it at the current position, appending always
281 // inserts it at the end
282 virtual void WriteText(const wxString& text);
283 virtual void AppendText(const wxString& text);
284
285 // insert the character which would have resulted from this key event,
286 // return True if anything has been inserted
287 virtual bool EmulateKeyPress(const wxKeyEvent& event);
288
289 // text control under some platforms supports the text styles: these
290 // methods allow to apply the given text style to the given selection or to
291 // set/get the style which will be used for all appended text
292 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
293 virtual bool GetStyle(long position, wxTextAttr& style);
294 virtual bool SetDefaultStyle(const wxTextAttr& style);
295 virtual const wxTextAttr& GetDefaultStyle() const;
296
297 // translate between the position (which is just an index in the text ctrl
298 // considering all its contents as a single strings) and (x, y) coordinates
299 // which represent column and line.
300 virtual long XYToPosition(long x, long y) const;
301 DocDeclA(
302 virtual /*bool*/ void, PositionToXY(long pos, long *OUTPUT, long *OUTPUT) const,
303 "PositionToXY(long pos) -> (x, y)");
304
305 virtual void ShowPosition(long pos);
306
307
308 DocDeclAStr(
309 virtual wxTextCtrlHitTestResult, HitTest(const wxPoint& pt,
310 long* OUTPUT, long* OUTPUT) const,
311 "HitTest(Point pt) -> (result, col, row)",
312 "Find the row, col coresponding to the character at the point given in
313 pixels. NB: pt is in device coords but is not adjusted for the client
314 area origin nor scrolling.", "");
315
316
317 DocDeclAStrName(
318 virtual wxTextCtrlHitTestResult , HitTest(const wxPoint& pt, long *OUTPUT) const,
319 "HitTestPos(Point pt) -> (result, position)",
320 "Find the character position in the text coresponding to the point
321 given in pixels. NB: pt is in device coords but is not adjusted for
322 the client area origin nor scrolling. ", "",
323 HitTestPos);
324
325
326
327 // Clipboard operations
328 virtual void Copy();
329 virtual void Cut();
330 virtual void Paste();
331
332 virtual bool CanCopy() const;
333 virtual bool CanCut() const;
334 virtual bool CanPaste() const;
335
336 // Undo/redo
337 virtual void Undo();
338 virtual void Redo();
339
340 virtual bool CanUndo() const;
341 virtual bool CanRedo() const;
342
343 // Insertion point
344 virtual void SetInsertionPoint(long pos);
345 virtual void SetInsertionPointEnd();
346 virtual long GetInsertionPoint() const;
347 virtual long GetLastPosition() const;
348
349 virtual void SetSelection(long from, long to);
350 virtual void SelectAll();
351 virtual void SetEditable(bool editable);
352
353 #ifdef __WXMAC__
354 virtual void MacCheckSpelling(bool check);
355 #else
356 %extend {
357 void MacCheckSpelling(bool check) {}
358 }
359 #endif
360
361 // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does
362 void SendTextUpdatedEvent();
363
364 #ifdef __WXMSW__
365 // Caret handling (Windows only)
366 bool ShowNativeCaret(bool show = true);
367 bool HideNativeCaret();
368 #endif
369
370 %extend {
371 // TODO: Add more file-like methods
372 void write(const wxString& text) {
373 self->AppendText(text);
374 }
375 }
376
377 // TODO: replace this when the method is really added to wxTextCtrl
378 %extend {
379 wxString GetString(long from, long to) {
380 return self->GetValue().Mid(from, to - from);
381 }
382 }
383
384 static wxVisualAttributes
385 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
386
387 %property(DefaultStyle, GetDefaultStyle, SetDefaultStyle, doc="See `GetDefaultStyle` and `SetDefaultStyle`");
388 %property(InsertionPoint, GetInsertionPoint, SetInsertionPoint, doc="See `GetInsertionPoint` and `SetInsertionPoint`");
389 %property(LastPosition, GetLastPosition, doc="See `GetLastPosition`");
390 %property(NumberOfLines, GetNumberOfLines, doc="See `GetNumberOfLines`");
391 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
392 %property(StringSelection, GetStringSelection, doc="See `GetStringSelection`");
393 %property(Value, GetValue, SetValue, doc="See `GetValue` and `SetValue`");
394 };
395
396 //---------------------------------------------------------------------------
397
398
399 %constant wxEventType wxEVT_COMMAND_TEXT_UPDATED;
400 %constant wxEventType wxEVT_COMMAND_TEXT_ENTER;
401 %constant wxEventType wxEVT_COMMAND_TEXT_URL;
402 %constant wxEventType wxEVT_COMMAND_TEXT_MAXLEN;
403
404
405 class wxTextUrlEvent : public wxCommandEvent
406 {
407 public:
408 wxTextUrlEvent(int winid, const wxMouseEvent& evtMouse,
409 long start, long end);
410
411 // get the mouse event which happend over the URL
412 const wxMouseEvent& GetMouseEvent();
413
414 // get the start of the URL
415 long GetURLStart() const;
416
417 // get the end of the URL
418 long GetURLEnd() const;
419
420 %property(MouseEvent, GetMouseEvent, doc="See `GetMouseEvent`");
421 %property(URLEnd, GetURLEnd, doc="See `GetURLEnd`");
422 %property(URLStart, GetURLStart, doc="See `GetURLStart`");
423 };
424
425
426 %pythoncode {
427 EVT_TEXT = wx.PyEventBinder( wxEVT_COMMAND_TEXT_UPDATED, 1)
428 EVT_TEXT_ENTER = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)
429 EVT_TEXT_URL = wx.PyEventBinder( wxEVT_COMMAND_TEXT_URL, 1)
430 EVT_TEXT_MAXLEN = wx.PyEventBinder( wxEVT_COMMAND_TEXT_MAXLEN, 1)
431 }
432
433
434
435
436 //---------------------------------------------------------------------------
437