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