1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/x11/textctrl.h
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __X11TEXTCTRLH__
12 #define __X11TEXTCTRLH__
14 // Set to 1 to use wxUniv's implementation, 0
16 #define wxUSE_UNIV_TEXTCTRL 1
18 #if wxUSE_UNIV_TEXTCTRL
19 #include "wx/univ/textctrl.h"
22 #include "wx/scrolwin.h"
23 #include "wx/arrstr.h"
24 #include "wx/datetime.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class WXDLLIMPEXP_CORE wxTextCtrl
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
41 wxSOURCE_UNDO_INSERT_LINE
,
46 class wxSourceUndoStep
: public wxObject
49 wxSourceUndoStep( wxSourceUndo type
, int y1
, int y2
, wxTextCtrl
*owner
);
60 wxArrayString m_lines
;
66 wxSourceLine( const wxString
&text
= wxEmptyString
)
74 WX_DECLARE_OBJARRAY(wxSourceLine
, wxSourceLineArray
);
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
, public wxScrollHelper
91 wxTextCtrl() { Init(); }
92 wxTextCtrl(wxWindow
*parent
,
94 const wxString
&value
= wxEmptyString
,
95 const wxPoint
&pos
= wxDefaultPosition
,
96 const wxSize
&size
= wxDefaultSize
,
98 const wxValidator
& validator
= wxDefaultValidator
,
99 const wxString
&name
= wxTextCtrlNameStr
);
100 virtual ~wxTextCtrl();
102 bool Create(wxWindow
*parent
,
104 const wxString
&value
= wxEmptyString
,
105 const wxPoint
&pos
= wxDefaultPosition
,
106 const wxSize
&size
= wxDefaultSize
,
108 const wxValidator
& validator
= wxDefaultValidator
,
109 const wxString
&name
= wxTextCtrlNameStr
);
111 // required for scrolling with wxScrollHelper
112 // ------------------------------------------
114 virtual void PrepareDC(wxDC
& dc
) { DoPrepareDC(dc
); }
116 // implement base class pure virtuals
117 // ----------------------------------
119 virtual wxString
GetValue() const;
120 virtual void SetValue(const wxString
& value
)
121 { ChangeValue(value
); SendTextUpdatedEvent(); }
123 virtual void ChangeValue(const wxString
&value
);
125 virtual int GetLineLength(long lineNo
) const;
126 virtual wxString
GetLineText(long lineNo
) const;
127 virtual int GetNumberOfLines() const;
129 virtual bool IsModified() const;
130 virtual bool IsEditable() const;
132 // more readable flag testing methods
133 // ----------------------------------
136 // it seems now in wxTextCtrlBase
137 bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE
); }
139 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD
) != 0; }
140 bool WrapLines() const { return false; }
142 // If the return values from and to are the same, there is no selection.
143 virtual void GetSelection(long* from
, long* to
) const;
149 virtual void Clear();
150 virtual void Replace(long from
, long to
, const wxString
& value
);
151 virtual void Remove(long from
, long to
);
153 // clears the dirty flag
154 virtual void DiscardEdits();
156 virtual void SetMaxLength(unsigned long len
);
158 // writing text inserts it at the current position, appending always
159 // inserts it at the end
160 virtual void WriteText(const wxString
& text
);
161 virtual void AppendText(const wxString
& text
);
163 // apply text attribute to the range of text (only works with richedit
165 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
167 // translate between the position (which is just an index in the text ctrl
168 // considering all its contents as a single strings) and (x, y) coordinates
169 // which represent column and line.
170 virtual long XYToPosition(long x
, long y
) const;
171 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
173 virtual void ShowPosition(long pos
);
175 // Clipboard operations
178 virtual void Paste();
182 virtual void Redo() {}
184 virtual bool CanUndo() const { return (m_undos
.GetCount() > 0); }
185 virtual bool CanRedo() const { return false; }
188 virtual void SetInsertionPoint(long pos
);
189 virtual void SetInsertionPointEnd();
190 virtual long GetInsertionPoint() const;
191 virtual wxTextPos
GetLastPosition() const;
193 virtual void SetSelection(long from
, long to
);
194 virtual void SetEditable(bool editable
);
196 virtual bool Enable( bool enable
= true );
198 void OnCut(wxCommandEvent
& event
);
199 void OnCopy(wxCommandEvent
& event
);
200 void OnPaste(wxCommandEvent
& event
);
201 void OnUndo(wxCommandEvent
& event
);
202 void OnRedo(wxCommandEvent
& event
);
204 void OnUpdateCut(wxUpdateUIEvent
& event
);
205 void OnUpdateCopy(wxUpdateUIEvent
& event
);
206 void OnUpdatePaste(wxUpdateUIEvent
& event
);
207 void OnUpdateUndo(wxUpdateUIEvent
& event
);
208 void OnUpdateRedo(wxUpdateUIEvent
& event
);
210 bool SetFont(const wxFont
& font
);
211 bool SetForegroundColour(const wxColour
& colour
);
212 bool SetBackgroundColour(const wxColour
& colour
);
214 void SetModified() { m_modified
= true; }
216 virtual void Freeze();
219 // textctrl specific scrolling
220 virtual bool ScrollLines(int lines
);
221 virtual bool ScrollPages(int pages
);
223 // not part of the wxTextCtrl API from now on..
225 void SetLanguage( wxSourceLanguage lang
= wxSOURCE_LANG_NONE
);
234 void ClearSelection();
236 int GetCursorX() { return m_cursorX
; }
237 int GetCursorY() { return m_cursorY
; }
238 bool IsModified() { return m_modified
; }
239 bool OverwriteMode() { return m_overwrite
; }
241 // implementation from now on...
243 int PosToPixel( int line
, int pos
);
244 int PixelToPos( int line
, int pixel
);
246 void SearchForBrackets();
248 void DoChar( char c
);
254 wxString
GetNextToken( wxString
&line
, size_t &pos
);
256 void DrawLinePart( wxDC
&dc
, int x
, int y
, const wxString
&toDraw
, const wxString
&origin
, const wxColour
&colour
);
257 void DrawLine( wxDC
&dc
, int x
, int y
, const wxString
&line
, int lineNum
);
258 void OnPaint( wxPaintEvent
&event
);
259 void OnEraseBackground( wxEraseEvent
&event
);
260 void OnMouse( wxMouseEvent
&event
);
261 void OnChar( wxKeyEvent
&event
);
262 void OnSetFocus( wxFocusEvent
& event
);
263 void OnKillFocus( wxFocusEvent
& event
);
265 void OnInternalIdle();
266 void RefreshLine( int n
);
267 void RefreshDown( int n
);
268 void MoveCursor( int new_x
, int new_y
, bool shift
= false, bool centre
= false );
269 void MyAdjustScrollbars();
272 // common part of all ctors
275 virtual wxSize
DoGetBestSize() const;
277 friend class wxSourceUndoStep
;
279 wxSourceLineArray m_lines
;
282 wxColour m_sourceColour
;
283 wxColour m_commentColour
;
284 wxColour m_stringColour
;
289 int m_selStartX
,m_selStartY
;
290 int m_selEndX
,m_selEndY
;
302 wxArrayString m_keywords
;
303 wxColour m_keywordColour
;
305 wxArrayString m_defines
;
306 wxColour m_defineColour
;
308 wxArrayString m_variables
;
309 wxColour m_variableColour
;
311 wxSourceLanguage m_lang
;
321 DECLARE_EVENT_TABLE()
322 DECLARE_DYNAMIC_CLASS(wxTextCtrl
);
325 //-----------------------------------------------------------------------------
326 // this is superfluous here but helps to compile
327 //-----------------------------------------------------------------------------
329 // cursor movement and also selection and delete operations
330 #define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
331 #define wxACTION_TEXT_FIRST _T("first") // go to pos 0
332 #define wxACTION_TEXT_LAST _T("last") // go to last pos
333 #define wxACTION_TEXT_HOME _T("home")
334 #define wxACTION_TEXT_END _T("end")
335 #define wxACTION_TEXT_LEFT _T("left")
336 #define wxACTION_TEXT_RIGHT _T("right")
337 #define wxACTION_TEXT_UP _T("up")
338 #define wxACTION_TEXT_DOWN _T("down")
339 #define wxACTION_TEXT_WORD_LEFT _T("wordleft")
340 #define wxACTION_TEXT_WORD_RIGHT _T("wordright")
341 #define wxACTION_TEXT_PAGE_UP _T("pageup")
342 #define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
344 // clipboard operations
345 #define wxACTION_TEXT_COPY _T("copy")
346 #define wxACTION_TEXT_CUT _T("cut")
347 #define wxACTION_TEXT_PASTE _T("paste")
349 // insert text at the cursor position: the text is in strArg of PerformAction
350 #define wxACTION_TEXT_INSERT _T("insert")
352 // if the action starts with either of these prefixes and the rest of the
353 // string is one of the movement commands, it means to select/delete text from
354 // the current cursor position to the new one
355 #define wxACTION_TEXT_PREFIX_SEL _T("sel")
356 #define wxACTION_TEXT_PREFIX_DEL _T("del")
359 #define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
360 #define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
361 #define wxACTION_TEXT_SEL_WORD _T("wordsel")
362 #define wxACTION_TEXT_SEL_LINE _T("linesel")
365 #define wxACTION_TEXT_UNDO _T("undo")
366 #define wxACTION_TEXT_REDO _T("redo")
368 // ----------------------------------------------------------------------------
370 // ----------------------------------------------------------------------------
372 class WXDLLEXPORT wxStdTextCtrlInputHandler
: public wxStdInputHandler
375 wxStdTextCtrlInputHandler(wxInputHandler
*inphand
) : wxStdInputHandler(inphand
) {}
377 virtual bool HandleKey(wxInputConsumer
*consumer
,
378 const wxKeyEvent
& event
,
379 bool pressed
) { return false; }
380 virtual bool HandleMouse(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
381 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
382 virtual bool HandleFocus(wxInputConsumer
*consumer
, const wxFocusEvent
& event
) { return false; }
385 // get the position of the mouse click
386 static wxTextPos
HitTest(const wxTextCtrl
*text
, const wxPoint
& pos
) { return 0; }
389 wxTextCtrl
*m_winCapture
;
393 // wxUSE_UNIV_TEXTCTRL
395 #endif // __X11TEXTCTRLH__