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