]> git.saurik.com Git - wxWidgets.git/blame - include/wx/x11/textctrl.h
avoid causing idle event from GetValue(), fixes #11013
[wxWidgets.git] / include / wx / x11 / textctrl.h
CommitLineData
4175e952 1/////////////////////////////////////////////////////////////////////////////
6b0d8a01 2// Name: wx/x11/textctrl.h
4175e952
RR
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id: $Id$
7// Copyright: (c) 1998 Robert Roebling
65571936 8// Licence: wxWindows licence
4175e952
RR
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef __X11TEXTCTRLH__
12#define __X11TEXTCTRLH__
13
47cd6610
JS
14// Set to 1 to use wxUniv's implementation, 0
15// to use wxX11's.
16#define wxUSE_UNIV_TEXTCTRL 1
17
18#if wxUSE_UNIV_TEXTCTRL
19#include "wx/univ/textctrl.h"
20#else
21
4175e952 22#include "wx/scrolwin.h"
d122f8c7 23#include "wx/arrstr.h"
4175e952
RR
24
25//-----------------------------------------------------------------------------
26// classes
27//-----------------------------------------------------------------------------
28
b5dbe15d 29class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
4175e952
RR
30
31//-----------------------------------------------------------------------------
32// helpers
33//-----------------------------------------------------------------------------
34
35enum wxSourceUndo
36{
37 wxSOURCE_UNDO_LINE,
38 wxSOURCE_UNDO_ENTER,
39 wxSOURCE_UNDO_BACK,
40 wxSOURCE_UNDO_INSERT_LINE,
41 wxSOURCE_UNDO_DELETE,
42 wxSOURCE_UNDO_PASTE
43};
44
45class wxSourceUndoStep: public wxObject
46{
47public:
48 wxSourceUndoStep( wxSourceUndo type, int y1, int y2, wxTextCtrl *owner );
6b0d8a01 49
4175e952 50 void Undo();
6b0d8a01 51
4175e952
RR
52 wxSourceUndo m_type;
53 int m_y1;
54 int m_y2;
55 int m_cursorX;
56 int m_cursorY;
57 wxTextCtrl *m_owner;
58 wxString m_text;
59 wxArrayString m_lines;
60};
61
62class wxSourceLine
63{
64public:
65 wxSourceLine( const wxString &text = wxEmptyString )
66 {
67 m_text = text;
68 }
6b0d8a01 69
4175e952
RR
70 wxString m_text;
71};
72
73WX_DECLARE_OBJARRAY(wxSourceLine, wxSourceLineArray);
74
75enum wxSourceLanguage
76{
77 wxSOURCE_LANG_NONE,
78 wxSOURCE_LANG_CPP,
79 wxSOURCE_LANG_PERL,
80 wxSOURCE_LANG_PYTHON
81};
82
83//-----------------------------------------------------------------------------
84// wxTextCtrl
85//-----------------------------------------------------------------------------
86
968eb2ef 87class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase, public wxScrollHelper
4175e952
RR
88{
89public:
90 wxTextCtrl() { Init(); }
91 wxTextCtrl(wxWindow *parent,
92 wxWindowID id,
93 const wxString &value = wxEmptyString,
94 const wxPoint &pos = wxDefaultPosition,
95 const wxSize &size = wxDefaultSize,
96 long style = 0,
97 const wxValidator& validator = wxDefaultValidator,
98 const wxString &name = wxTextCtrlNameStr);
d122f8c7 99 virtual ~wxTextCtrl();
4175e952
RR
100
101 bool Create(wxWindow *parent,
102 wxWindowID id,
103 const wxString &value = wxEmptyString,
104 const wxPoint &pos = wxDefaultPosition,
105 const wxSize &size = wxDefaultSize,
106 long style = 0,
107 const wxValidator& validator = wxDefaultValidator,
108 const wxString &name = wxTextCtrlNameStr);
6b0d8a01 109
4175e952
RR
110 // required for scrolling with wxScrollHelper
111 // ------------------------------------------
112
113 virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
6b0d8a01 114
4175e952
RR
115 // implement base class pure virtuals
116 // ----------------------------------
117
f6519b40 118 virtual void ChangeValue(const wxString &value);
4175e952
RR
119
120 virtual int GetLineLength(long lineNo) const;
121 virtual wxString GetLineText(long lineNo) const;
122 virtual int GetNumberOfLines() const;
123
124 virtual bool IsModified() const;
125 virtual bool IsEditable() const;
126
127 // more readable flag testing methods
128 // ----------------------------------
6b0d8a01 129
4175e952 130 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
21f8cd6f 131 bool WrapLines() const { return false; }
6b0d8a01 132
4175e952
RR
133 // If the return values from and to are the same, there is no selection.
134 virtual void GetSelection(long* from, long* to) const;
135
136 // operations
137 // ----------
138
139 // editing
140 virtual void Clear();
141 virtual void Replace(long from, long to, const wxString& value);
142 virtual void Remove(long from, long to);
143
144 // clears the dirty flag
145 virtual void DiscardEdits();
146
147 virtual void SetMaxLength(unsigned long len);
148
149 // writing text inserts it at the current position, appending always
150 // inserts it at the end
151 virtual void WriteText(const wxString& text);
152 virtual void AppendText(const wxString& text);
153
154 // apply text attribute to the range of text (only works with richedit
155 // controls)
156 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
157
158 // translate between the position (which is just an index in the text ctrl
159 // considering all its contents as a single strings) and (x, y) coordinates
160 // which represent column and line.
161 virtual long XYToPosition(long x, long y) const;
162 virtual bool PositionToXY(long pos, long *x, long *y) const;
163
164 virtual void ShowPosition(long pos);
165
166 // Clipboard operations
167 virtual void Copy();
168 virtual void Cut();
169 virtual void Paste();
170
171 // Undo/redo
172 virtual void Undo();
173 virtual void Redo() {}
174
175 virtual bool CanUndo() const { return (m_undos.GetCount() > 0); }
7d8268a1 176 virtual bool CanRedo() const { return false; }
4175e952
RR
177
178 // Insertion point
179 virtual void SetInsertionPoint(long pos);
180 virtual void SetInsertionPointEnd();
181 virtual long GetInsertionPoint() const;
7d8268a1 182 virtual wxTextPos GetLastPosition() const;
4175e952
RR
183
184 virtual void SetSelection(long from, long to);
185 virtual void SetEditable(bool editable);
186
7d8268a1 187 virtual bool Enable( bool enable = true );
4175e952
RR
188
189 void OnCut(wxCommandEvent& event);
190 void OnCopy(wxCommandEvent& event);
191 void OnPaste(wxCommandEvent& event);
192 void OnUndo(wxCommandEvent& event);
193 void OnRedo(wxCommandEvent& event);
194
195 void OnUpdateCut(wxUpdateUIEvent& event);
196 void OnUpdateCopy(wxUpdateUIEvent& event);
197 void OnUpdatePaste(wxUpdateUIEvent& event);
198 void OnUpdateUndo(wxUpdateUIEvent& event);
199 void OnUpdateRedo(wxUpdateUIEvent& event);
200
201 bool SetFont(const wxFont& font);
202 bool SetForegroundColour(const wxColour& colour);
203 bool SetBackgroundColour(const wxColour& colour);
204
7d8268a1 205 void SetModified() { m_modified = true; }
4175e952 206
4175e952
RR
207 // textctrl specific scrolling
208 virtual bool ScrollLines(int lines);
209 virtual bool ScrollPages(int pages);
210
211 // not part of the wxTextCtrl API from now on..
6b0d8a01 212
46e87167 213 void SetLanguage( wxSourceLanguage lang = wxSOURCE_LANG_NONE );
4175e952
RR
214
215 void Delete();
216 void DeleteLine();
6b0d8a01 217
4175e952
RR
218 void Indent();
219 void Unindent();
6b0d8a01 220
4175e952
RR
221 bool HasSelection();
222 void ClearSelection();
6b0d8a01 223
4175e952
RR
224 int GetCursorX() { return m_cursorX; }
225 int GetCursorY() { return m_cursorY; }
226 bool IsModified() { return m_modified; }
227 bool OverwriteMode() { return m_overwrite; }
228
229 // implementation from now on...
6b0d8a01 230
82434104
RR
231 int PosToPixel( int line, int pos );
232 int PixelToPos( int line, int pixel );
4175e952
RR
233
234 void SearchForBrackets();
6b0d8a01 235
4175e952
RR
236 void DoChar( char c );
237 void DoBack();
238 void DoDelete();
239 void DoReturn();
240 void DoDClick();
6b0d8a01 241
46e87167
RR
242 wxString GetNextToken( wxString &line, size_t &pos );
243
244 void DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, const wxString &origin, const wxColour &colour);
4175e952
RR
245 void DrawLine( wxDC &dc, int x, int y, const wxString &line, int lineNum );
246 void OnPaint( wxPaintEvent &event );
46e87167 247 void OnEraseBackground( wxEraseEvent &event );
4175e952
RR
248 void OnMouse( wxMouseEvent &event );
249 void OnChar( wxKeyEvent &event );
968602f8
JS
250 void OnSetFocus( wxFocusEvent& event );
251 void OnKillFocus( wxFocusEvent& event );
6b0d8a01 252
e39af974 253 void OnInternalIdle();
4175e952
RR
254 void RefreshLine( int n );
255 void RefreshDown( int n );
7d8268a1 256 void MoveCursor( int new_x, int new_y, bool shift = false, bool centre = false );
4175e952 257 void MyAdjustScrollbars();
6b0d8a01 258
4175e952
RR
259protected:
260 // common part of all ctors
261 void Init();
262
263 virtual wxSize DoGetBestSize() const;
264
ee2ec18e
VZ
265 virtual void DoSetValue(const wxString& value, int flags = 0);
266
4175e952
RR
267 friend class wxSourceUndoStep;
268
269 wxSourceLineArray m_lines;
270
271 wxFont m_sourceFont;
272 wxColour m_sourceColour;
273 wxColour m_commentColour;
274 wxColour m_stringColour;
6b0d8a01 275
4175e952
RR
276 int m_cursorX;
277 int m_cursorY;
6b0d8a01 278
4175e952
RR
279 int m_selStartX,m_selStartY;
280 int m_selEndX,m_selEndY;
6b0d8a01 281
4175e952
RR
282 int m_lineHeight;
283 int m_charWidth;
6b0d8a01 284
4175e952 285 int m_longestLine;
6b0d8a01 286
4175e952
RR
287 bool m_overwrite;
288 bool m_modified;
289 bool m_editable;
290 bool m_ignoreInput;
6b0d8a01 291
4175e952
RR
292 wxArrayString m_keywords;
293 wxColour m_keywordColour;
6b0d8a01 294
4175e952
RR
295 wxArrayString m_defines;
296 wxColour m_defineColour;
6b0d8a01 297
4175e952
RR
298 wxArrayString m_variables;
299 wxColour m_variableColour;
6b0d8a01 300
4175e952 301 wxSourceLanguage m_lang;
6b0d8a01 302
4175e952 303 wxList m_undos;
6b0d8a01 304
4175e952 305 bool m_capturing;
6b0d8a01 306
4175e952
RR
307 int m_bracketX;
308 int m_bracketY;
309
310private:
311 DECLARE_EVENT_TABLE()
312 DECLARE_DYNAMIC_CLASS(wxTextCtrl);
313};
314
315//-----------------------------------------------------------------------------
316// this is superfluous here but helps to compile
317//-----------------------------------------------------------------------------
318
319// cursor movement and also selection and delete operations
9a83f860
VZ
320#define wxACTION_TEXT_GOTO wxT("goto") // to pos in numArg
321#define wxACTION_TEXT_FIRST wxT("first") // go to pos 0
322#define wxACTION_TEXT_LAST wxT("last") // go to last pos
323#define wxACTION_TEXT_HOME wxT("home")
324#define wxACTION_TEXT_END wxT("end")
325#define wxACTION_TEXT_LEFT wxT("left")
326#define wxACTION_TEXT_RIGHT wxT("right")
327#define wxACTION_TEXT_UP wxT("up")
328#define wxACTION_TEXT_DOWN wxT("down")
329#define wxACTION_TEXT_WORD_LEFT wxT("wordleft")
330#define wxACTION_TEXT_WORD_RIGHT wxT("wordright")
331#define wxACTION_TEXT_PAGE_UP wxT("pageup")
332#define wxACTION_TEXT_PAGE_DOWN wxT("pagedown")
4175e952
RR
333
334// clipboard operations
9a83f860
VZ
335#define wxACTION_TEXT_COPY wxT("copy")
336#define wxACTION_TEXT_CUT wxT("cut")
337#define wxACTION_TEXT_PASTE wxT("paste")
4175e952
RR
338
339// insert text at the cursor position: the text is in strArg of PerformAction
9a83f860 340#define wxACTION_TEXT_INSERT wxT("insert")
4175e952
RR
341
342// if the action starts with either of these prefixes and the rest of the
343// string is one of the movement commands, it means to select/delete text from
344// the current cursor position to the new one
9a83f860
VZ
345#define wxACTION_TEXT_PREFIX_SEL wxT("sel")
346#define wxACTION_TEXT_PREFIX_DEL wxT("del")
4175e952
RR
347
348// mouse selection
9a83f860
VZ
349#define wxACTION_TEXT_ANCHOR_SEL wxT("anchorsel")
350#define wxACTION_TEXT_EXTEND_SEL wxT("extendsel")
351#define wxACTION_TEXT_SEL_WORD wxT("wordsel")
352#define wxACTION_TEXT_SEL_LINE wxT("linesel")
4175e952
RR
353
354// undo or redo
9a83f860
VZ
355#define wxACTION_TEXT_UNDO wxT("undo")
356#define wxACTION_TEXT_REDO wxT("redo")
4175e952
RR
357
358// ----------------------------------------------------------------------------
359// wxTextCtrl types
360// ----------------------------------------------------------------------------
361
53a2db12 362class WXDLLIMPEXP_CORE wxStdTextCtrlInputHandler : public wxStdInputHandler
4175e952
RR
363{
364public:
365 wxStdTextCtrlInputHandler(wxInputHandler *inphand) : wxStdInputHandler(inphand) {}
366
367 virtual bool HandleKey(wxInputConsumer *consumer,
368 const wxKeyEvent& event,
7d8268a1
WS
369 bool pressed) { return false; }
370 virtual bool HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
371 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
372 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event) { return false; }
4175e952
RR
373
374protected:
375 // get the position of the mouse click
376 static wxTextPos HitTest(const wxTextCtrl *text, const wxPoint& pos) { return 0; }
377
378 // capture data
379 wxTextCtrl *m_winCapture;
380};
381
47cd6610
JS
382#endif
383// wxUSE_UNIV_TEXTCTRL
384
385#endif // __X11TEXTCTRLH__
4175e952 386