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