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