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