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