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