1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __X11TEXTCTRLH__
12 #define __X11TEXTCTRLH__
15 #pragma interface "textctrl.h"
18 #include "wx/scrolwin.h"
19 #include "wx/dynarray.h"
20 #include "wx/datetime.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
37 wxSOURCE_UNDO_INSERT_LINE
,
42 class wxSourceUndoStep
: public wxObject
45 wxSourceUndoStep( wxSourceUndo type
, int y1
, int y2
, wxTextCtrl
*owner
);
56 wxArrayString m_lines
;
62 wxSourceLine( const wxString
&text
= wxEmptyString
)
70 WX_DECLARE_OBJARRAY(wxSourceLine
, wxSourceLineArray
);
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 class wxTextCtrl
: public wxTextCtrlBase
, public wxScrollHelper
87 wxTextCtrl() { Init(); }
88 wxTextCtrl(wxWindow
*parent
,
90 const wxString
&value
= wxEmptyString
,
91 const wxPoint
&pos
= wxDefaultPosition
,
92 const wxSize
&size
= wxDefaultSize
,
94 const wxValidator
& validator
= wxDefaultValidator
,
95 const wxString
&name
= wxTextCtrlNameStr
);
97 bool Create(wxWindow
*parent
,
99 const wxString
&value
= wxEmptyString
,
100 const wxPoint
&pos
= wxDefaultPosition
,
101 const wxSize
&size
= wxDefaultSize
,
103 const wxValidator
& validator
= wxDefaultValidator
,
104 const wxString
&name
= wxTextCtrlNameStr
);
106 // required for scrolling with wxScrollHelper
107 // ------------------------------------------
109 virtual void PrepareDC(wxDC
& dc
) { DoPrepareDC(dc
); }
111 // implement base class pure virtuals
112 // ----------------------------------
114 virtual wxString
GetValue() const;
115 virtual void SetValue(const wxString
& value
);
117 virtual int GetLineLength(long lineNo
) const;
118 virtual wxString
GetLineText(long lineNo
) const;
119 virtual int GetNumberOfLines() const;
121 virtual bool IsModified() const;
122 virtual bool IsEditable() const;
124 // more readable flag testing methods
125 // ----------------------------------
127 bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE
); }
128 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD
) != 0; }
129 bool WrapLines() const { return FALSE
; }
131 // If the return values from and to are the same, there is no selection.
132 virtual void GetSelection(long* from
, long* to
) const;
138 virtual void Clear();
139 virtual void Replace(long from
, long to
, const wxString
& value
);
140 virtual void Remove(long from
, long to
);
142 // clears the dirty flag
143 virtual void DiscardEdits();
145 virtual void SetMaxLength(unsigned long len
);
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
);
152 // apply text attribute to the range of text (only works with richedit
154 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
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;
162 virtual void ShowPosition(long pos
);
164 // Clipboard operations
167 virtual void Paste();
171 virtual void Redo() {}
173 virtual bool CanUndo() const { return (m_undos
.GetCount() > 0); }
174 virtual bool CanRedo() const { return FALSE
; }
177 virtual void SetInsertionPoint(long pos
);
178 virtual void SetInsertionPointEnd();
179 virtual long GetInsertionPoint() const;
180 virtual long GetLastPosition() const;
182 virtual void SetSelection(long from
, long to
);
183 virtual void SetEditable(bool editable
);
185 virtual bool Enable( bool enable
);
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
);
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
);
199 bool SetFont(const wxFont
& font
);
200 bool SetForegroundColour(const wxColour
& colour
);
201 bool SetBackgroundColour(const wxColour
& colour
);
203 void SetModified() { m_modified
= TRUE
; }
205 virtual void Freeze();
208 // textctrl specific scrolling
209 virtual bool ScrollLines(int lines
);
210 virtual bool ScrollPages(int pages
);
212 // not part of the wxTextCtrl API from now on..
221 void ClearSelection();
223 int GetCursorX() { return m_cursorX
; }
224 int GetCursorY() { return m_cursorY
; }
225 bool IsModified() { return m_modified
; }
226 bool OverwriteMode() { return m_overwrite
; }
228 // implementation from now on...
230 int PosToPixel( int line
, int pos
);
231 int PixelToPos( int line
, int pixel
);
233 void SearchForBrackets();
235 void DoChar( char c
);
241 wxString
GetNextToken( wxString
&line
, int &pos
);
242 void DrawLine( wxDC
&dc
, int x
, int y
, const wxString
&line
, int lineNum
);
243 void OnPaint( wxPaintEvent
&event
);
244 void OnMouse( wxMouseEvent
&event
);
245 void OnChar( wxKeyEvent
&event
);
246 void OnIdle( wxIdleEvent
&event
);
248 void RefreshLine( int n
);
249 void RefreshDown( int n
);
250 void MoveCursor( int new_x
, int new_y
, bool shift
= FALSE
, bool centre
= FALSE
);
251 void MyAdjustScrollbars();
254 // common part of all ctors
257 virtual wxSize
DoGetBestSize() const;
259 friend class wxSourceUndoStep
;
261 wxSourceLineArray m_lines
;
264 wxColour m_sourceColour
;
265 wxColour m_commentColour
;
266 wxColour m_stringColour
;
271 int m_selStartX
,m_selStartY
;
272 int m_selEndX
,m_selEndY
;
284 wxArrayString m_keywords
;
285 wxColour m_keywordColour
;
287 wxArrayString m_defines
;
288 wxColour m_defineColour
;
290 wxArrayString m_variables
;
291 wxColour m_variableColour
;
293 wxSourceLanguage m_lang
;
303 DECLARE_EVENT_TABLE()
304 DECLARE_DYNAMIC_CLASS(wxTextCtrl
);
307 //-----------------------------------------------------------------------------
308 // this is superfluous here but helps to compile
309 //-----------------------------------------------------------------------------
311 // cursor movement and also selection and delete operations
312 #define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
313 #define wxACTION_TEXT_FIRST _T("first") // go to pos 0
314 #define wxACTION_TEXT_LAST _T("last") // go to last pos
315 #define wxACTION_TEXT_HOME _T("home")
316 #define wxACTION_TEXT_END _T("end")
317 #define wxACTION_TEXT_LEFT _T("left")
318 #define wxACTION_TEXT_RIGHT _T("right")
319 #define wxACTION_TEXT_UP _T("up")
320 #define wxACTION_TEXT_DOWN _T("down")
321 #define wxACTION_TEXT_WORD_LEFT _T("wordleft")
322 #define wxACTION_TEXT_WORD_RIGHT _T("wordright")
323 #define wxACTION_TEXT_PAGE_UP _T("pageup")
324 #define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
326 // clipboard operations
327 #define wxACTION_TEXT_COPY _T("copy")
328 #define wxACTION_TEXT_CUT _T("cut")
329 #define wxACTION_TEXT_PASTE _T("paste")
331 // insert text at the cursor position: the text is in strArg of PerformAction
332 #define wxACTION_TEXT_INSERT _T("insert")
334 // if the action starts with either of these prefixes and the rest of the
335 // string is one of the movement commands, it means to select/delete text from
336 // the current cursor position to the new one
337 #define wxACTION_TEXT_PREFIX_SEL _T("sel")
338 #define wxACTION_TEXT_PREFIX_DEL _T("del")
341 #define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
342 #define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
343 #define wxACTION_TEXT_SEL_WORD _T("wordsel")
344 #define wxACTION_TEXT_SEL_LINE _T("linesel")
347 #define wxACTION_TEXT_UNDO _T("undo")
348 #define wxACTION_TEXT_REDO _T("redo")
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 // wxTextPos is the position in the text
355 typedef long wxTextPos
;
357 // wxTextCoord is the line or row number (which should have been unsigned but
358 // is long for backwards compatibility)
359 typedef long wxTextCoord
;
361 class WXDLLEXPORT wxStdTextCtrlInputHandler
: public wxStdInputHandler
364 wxStdTextCtrlInputHandler(wxInputHandler
*inphand
) : wxStdInputHandler(inphand
) {}
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
; }
374 // get the position of the mouse click
375 static wxTextPos
HitTest(const wxTextCtrl
*text
, const wxPoint
& pos
) { return 0; }
378 wxTextCtrl
*m_winCapture
;
381 #endif // __GTKTEXTCTRLH__