]> git.saurik.com Git - wxWidgets.git/blame - include/wx/x11/textctrl.h
TRUE->true, FALSE->false replacements.
[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
8// Licence: wxWindows licence
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
4175e952
RR
136 bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); }
137 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
138 bool WrapLines() const { return FALSE; }
6b0d8a01 139
4175e952
RR
140 // If the return values from and to are the same, there is no selection.
141 virtual void GetSelection(long* from, long* to) const;
142
143 // operations
144 // ----------
145
146 // editing
147 virtual void Clear();
148 virtual void Replace(long from, long to, const wxString& value);
149 virtual void Remove(long from, long to);
150
151 // clears the dirty flag
152 virtual void DiscardEdits();
153
154 virtual void SetMaxLength(unsigned long len);
155
156 // writing text inserts it at the current position, appending always
157 // inserts it at the end
158 virtual void WriteText(const wxString& text);
159 virtual void AppendText(const wxString& text);
160
161 // apply text attribute to the range of text (only works with richedit
162 // controls)
163 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
164
165 // translate between the position (which is just an index in the text ctrl
166 // considering all its contents as a single strings) and (x, y) coordinates
167 // which represent column and line.
168 virtual long XYToPosition(long x, long y) const;
169 virtual bool PositionToXY(long pos, long *x, long *y) const;
170
171 virtual void ShowPosition(long pos);
172
173 // Clipboard operations
174 virtual void Copy();
175 virtual void Cut();
176 virtual void Paste();
177
178 // Undo/redo
179 virtual void Undo();
180 virtual void Redo() {}
181
182 virtual bool CanUndo() const { return (m_undos.GetCount() > 0); }
183 virtual bool CanRedo() const { return FALSE; }
184
185 // Insertion point
186 virtual void SetInsertionPoint(long pos);
187 virtual void SetInsertionPointEnd();
188 virtual long GetInsertionPoint() const;
189 virtual long GetLastPosition() const;
190
191 virtual void SetSelection(long from, long to);
192 virtual void SetEditable(bool editable);
193
6b0d8a01 194 virtual bool Enable( bool enable = TRUE );
4175e952
RR
195
196 void OnCut(wxCommandEvent& event);
197 void OnCopy(wxCommandEvent& event);
198 void OnPaste(wxCommandEvent& event);
199 void OnUndo(wxCommandEvent& event);
200 void OnRedo(wxCommandEvent& event);
201
202 void OnUpdateCut(wxUpdateUIEvent& event);
203 void OnUpdateCopy(wxUpdateUIEvent& event);
204 void OnUpdatePaste(wxUpdateUIEvent& event);
205 void OnUpdateUndo(wxUpdateUIEvent& event);
206 void OnUpdateRedo(wxUpdateUIEvent& event);
207
208 bool SetFont(const wxFont& font);
209 bool SetForegroundColour(const wxColour& colour);
210 bool SetBackgroundColour(const wxColour& colour);
211
212 void SetModified() { m_modified = TRUE; }
213
214 virtual void Freeze();
215 virtual void Thaw();
216
217 // textctrl specific scrolling
218 virtual bool ScrollLines(int lines);
219 virtual bool ScrollPages(int pages);
220
221 // not part of the wxTextCtrl API from now on..
6b0d8a01 222
46e87167 223 void SetLanguage( wxSourceLanguage lang = wxSOURCE_LANG_NONE );
4175e952
RR
224
225 void Delete();
226 void DeleteLine();
6b0d8a01 227
4175e952
RR
228 void Indent();
229 void Unindent();
6b0d8a01 230
4175e952
RR
231 bool HasSelection();
232 void ClearSelection();
6b0d8a01 233
4175e952
RR
234 int GetCursorX() { return m_cursorX; }
235 int GetCursorY() { return m_cursorY; }
236 bool IsModified() { return m_modified; }
237 bool OverwriteMode() { return m_overwrite; }
238
239 // implementation from now on...
6b0d8a01 240
82434104
RR
241 int PosToPixel( int line, int pos );
242 int PixelToPos( int line, int pixel );
4175e952
RR
243
244 void SearchForBrackets();
6b0d8a01 245
4175e952
RR
246 void DoChar( char c );
247 void DoBack();
248 void DoDelete();
249 void DoReturn();
250 void DoDClick();
6b0d8a01 251
46e87167
RR
252 wxString GetNextToken( wxString &line, size_t &pos );
253
254 void DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, const wxString &origin, const wxColour &colour);
4175e952
RR
255 void DrawLine( wxDC &dc, int x, int y, const wxString &line, int lineNum );
256 void OnPaint( wxPaintEvent &event );
46e87167 257 void OnEraseBackground( wxEraseEvent &event );
4175e952
RR
258 void OnMouse( wxMouseEvent &event );
259 void OnChar( wxKeyEvent &event );
968602f8
JS
260 void OnSetFocus( wxFocusEvent& event );
261 void OnKillFocus( wxFocusEvent& event );
6b0d8a01 262
e39af974 263 void OnInternalIdle();
4175e952
RR
264 void RefreshLine( int n );
265 void RefreshDown( int n );
266 void MoveCursor( int new_x, int new_y, bool shift = FALSE, bool centre = FALSE );
267 void MyAdjustScrollbars();
6b0d8a01 268
4175e952
RR
269protected:
270 // common part of all ctors
271 void Init();
272
273 virtual wxSize DoGetBestSize() const;
274
275 friend class wxSourceUndoStep;
276
277 wxSourceLineArray m_lines;
278
279 wxFont m_sourceFont;
280 wxColour m_sourceColour;
281 wxColour m_commentColour;
282 wxColour m_stringColour;
6b0d8a01 283
4175e952
RR
284 int m_cursorX;
285 int m_cursorY;
6b0d8a01 286
4175e952
RR
287 int m_selStartX,m_selStartY;
288 int m_selEndX,m_selEndY;
6b0d8a01 289
4175e952
RR
290 int m_lineHeight;
291 int m_charWidth;
6b0d8a01 292
4175e952 293 int m_longestLine;
6b0d8a01 294
4175e952
RR
295 bool m_overwrite;
296 bool m_modified;
297 bool m_editable;
298 bool m_ignoreInput;
6b0d8a01 299
4175e952
RR
300 wxArrayString m_keywords;
301 wxColour m_keywordColour;
6b0d8a01 302
4175e952
RR
303 wxArrayString m_defines;
304 wxColour m_defineColour;
6b0d8a01 305
4175e952
RR
306 wxArrayString m_variables;
307 wxColour m_variableColour;
6b0d8a01 308
4175e952 309 wxSourceLanguage m_lang;
6b0d8a01 310
4175e952 311 wxList m_undos;
6b0d8a01 312
4175e952 313 bool m_capturing;
6b0d8a01 314
4175e952
RR
315 int m_bracketX;
316 int m_bracketY;
317
318private:
319 DECLARE_EVENT_TABLE()
320 DECLARE_DYNAMIC_CLASS(wxTextCtrl);
321};
322
323//-----------------------------------------------------------------------------
324// this is superfluous here but helps to compile
325//-----------------------------------------------------------------------------
326
327// cursor movement and also selection and delete operations
328#define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
329#define wxACTION_TEXT_FIRST _T("first") // go to pos 0
330#define wxACTION_TEXT_LAST _T("last") // go to last pos
331#define wxACTION_TEXT_HOME _T("home")
332#define wxACTION_TEXT_END _T("end")
333#define wxACTION_TEXT_LEFT _T("left")
334#define wxACTION_TEXT_RIGHT _T("right")
335#define wxACTION_TEXT_UP _T("up")
336#define wxACTION_TEXT_DOWN _T("down")
337#define wxACTION_TEXT_WORD_LEFT _T("wordleft")
338#define wxACTION_TEXT_WORD_RIGHT _T("wordright")
339#define wxACTION_TEXT_PAGE_UP _T("pageup")
340#define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
341
342// clipboard operations
343#define wxACTION_TEXT_COPY _T("copy")
344#define wxACTION_TEXT_CUT _T("cut")
345#define wxACTION_TEXT_PASTE _T("paste")
346
347// insert text at the cursor position: the text is in strArg of PerformAction
348#define wxACTION_TEXT_INSERT _T("insert")
349
350// if the action starts with either of these prefixes and the rest of the
351// string is one of the movement commands, it means to select/delete text from
352// the current cursor position to the new one
353#define wxACTION_TEXT_PREFIX_SEL _T("sel")
354#define wxACTION_TEXT_PREFIX_DEL _T("del")
355
356// mouse selection
357#define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
358#define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
359#define wxACTION_TEXT_SEL_WORD _T("wordsel")
360#define wxACTION_TEXT_SEL_LINE _T("linesel")
361
362// undo or redo
363#define wxACTION_TEXT_UNDO _T("undo")
364#define wxACTION_TEXT_REDO _T("redo")
365
366// ----------------------------------------------------------------------------
367// wxTextCtrl types
368// ----------------------------------------------------------------------------
369
370// wxTextPos is the position in the text
371typedef long wxTextPos;
372
373// wxTextCoord is the line or row number (which should have been unsigned but
374// is long for backwards compatibility)
375typedef long wxTextCoord;
376
377class WXDLLEXPORT wxStdTextCtrlInputHandler : public wxStdInputHandler
378{
379public:
380 wxStdTextCtrlInputHandler(wxInputHandler *inphand) : wxStdInputHandler(inphand) {}
381
382 virtual bool HandleKey(wxInputConsumer *consumer,
383 const wxKeyEvent& event,
384 bool pressed) { return FALSE; }
385 virtual bool HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { return FALSE; }
386 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { return FALSE; }
387 virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event) { return FALSE; }
388
389protected:
390 // get the position of the mouse click
391 static wxTextPos HitTest(const wxTextCtrl *text, const wxPoint& pos) { return 0; }
392
393 // capture data
394 wxTextCtrl *m_winCapture;
395};
396
47cd6610
JS
397#endif
398// wxUSE_UNIV_TEXTCTRL
399
400#endif // __X11TEXTCTRLH__
4175e952 401