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