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 void ChangeValue(const wxString
&value
);
121 virtual int GetLineLength(long lineNo
) const;
122 virtual wxString
GetLineText(long lineNo
) const;
123 virtual int GetNumberOfLines() const;
125 virtual bool IsModified() const;
126 virtual bool IsEditable() const;
128 // more readable flag testing methods
129 // ----------------------------------
131 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD
) != 0; }
132 bool WrapLines() const { return false; }
134 // If the return values from and to are the same, there is no selection.
135 virtual void GetSelection(long* from
, long* to
) const;
141 virtual void Clear();
142 virtual void Replace(long from
, long to
, const wxString
& value
);
143 virtual void Remove(long from
, long to
);
145 // clears the dirty flag
146 virtual void DiscardEdits();
148 virtual void SetMaxLength(unsigned long len
);
150 // writing text inserts it at the current position, appending always
151 // inserts it at the end
152 virtual void WriteText(const wxString
& text
);
153 virtual void AppendText(const wxString
& text
);
155 // apply text attribute to the range of text (only works with richedit
157 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
159 // translate between the position (which is just an index in the text ctrl
160 // considering all its contents as a single strings) and (x, y) coordinates
161 // which represent column and line.
162 virtual long XYToPosition(long x
, long y
) const;
163 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
165 virtual void ShowPosition(long pos
);
167 // Clipboard operations
170 virtual void Paste();
174 virtual void Redo() {}
176 virtual bool CanUndo() const { return (m_undos
.GetCount() > 0); }
177 virtual bool CanRedo() const { return false; }
180 virtual void SetInsertionPoint(long pos
);
181 virtual void SetInsertionPointEnd();
182 virtual long GetInsertionPoint() const;
183 virtual wxTextPos
GetLastPosition() const;
185 virtual void SetSelection(long from
, long to
);
186 virtual void SetEditable(bool editable
);
188 virtual bool Enable( bool enable
= true );
190 void OnCut(wxCommandEvent
& event
);
191 void OnCopy(wxCommandEvent
& event
);
192 void OnPaste(wxCommandEvent
& event
);
193 void OnUndo(wxCommandEvent
& event
);
194 void OnRedo(wxCommandEvent
& event
);
196 void OnUpdateCut(wxUpdateUIEvent
& event
);
197 void OnUpdateCopy(wxUpdateUIEvent
& event
);
198 void OnUpdatePaste(wxUpdateUIEvent
& event
);
199 void OnUpdateUndo(wxUpdateUIEvent
& event
);
200 void OnUpdateRedo(wxUpdateUIEvent
& event
);
202 bool SetFont(const wxFont
& font
);
203 bool SetForegroundColour(const wxColour
& colour
);
204 bool SetBackgroundColour(const wxColour
& colour
);
206 void SetModified() { m_modified
= true; }
208 virtual void Freeze();
211 // textctrl specific scrolling
212 virtual bool ScrollLines(int lines
);
213 virtual bool ScrollPages(int pages
);
215 // not part of the wxTextCtrl API from now on..
217 void SetLanguage( wxSourceLanguage lang
= wxSOURCE_LANG_NONE
);
226 void ClearSelection();
228 int GetCursorX() { return m_cursorX
; }
229 int GetCursorY() { return m_cursorY
; }
230 bool IsModified() { return m_modified
; }
231 bool OverwriteMode() { return m_overwrite
; }
233 // implementation from now on...
235 int PosToPixel( int line
, int pos
);
236 int PixelToPos( int line
, int pixel
);
238 void SearchForBrackets();
240 void DoChar( char c
);
246 wxString
GetNextToken( wxString
&line
, size_t &pos
);
248 void DrawLinePart( wxDC
&dc
, int x
, int y
, const wxString
&toDraw
, const wxString
&origin
, const wxColour
&colour
);
249 void DrawLine( wxDC
&dc
, int x
, int y
, const wxString
&line
, int lineNum
);
250 void OnPaint( wxPaintEvent
&event
);
251 void OnEraseBackground( wxEraseEvent
&event
);
252 void OnMouse( wxMouseEvent
&event
);
253 void OnChar( wxKeyEvent
&event
);
254 void OnSetFocus( wxFocusEvent
& event
);
255 void OnKillFocus( wxFocusEvent
& event
);
257 void OnInternalIdle();
258 void RefreshLine( int n
);
259 void RefreshDown( int n
);
260 void MoveCursor( int new_x
, int new_y
, bool shift
= false, bool centre
= false );
261 void MyAdjustScrollbars();
264 // common part of all ctors
267 virtual wxSize
DoGetBestSize() const;
269 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
271 friend class wxSourceUndoStep
;
273 wxSourceLineArray m_lines
;
276 wxColour m_sourceColour
;
277 wxColour m_commentColour
;
278 wxColour m_stringColour
;
283 int m_selStartX
,m_selStartY
;
284 int m_selEndX
,m_selEndY
;
296 wxArrayString m_keywords
;
297 wxColour m_keywordColour
;
299 wxArrayString m_defines
;
300 wxColour m_defineColour
;
302 wxArrayString m_variables
;
303 wxColour m_variableColour
;
305 wxSourceLanguage m_lang
;
315 DECLARE_EVENT_TABLE()
316 DECLARE_DYNAMIC_CLASS(wxTextCtrl
);
319 //-----------------------------------------------------------------------------
320 // this is superfluous here but helps to compile
321 //-----------------------------------------------------------------------------
323 // cursor movement and also selection and delete operations
324 #define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
325 #define wxACTION_TEXT_FIRST _T("first") // go to pos 0
326 #define wxACTION_TEXT_LAST _T("last") // go to last pos
327 #define wxACTION_TEXT_HOME _T("home")
328 #define wxACTION_TEXT_END _T("end")
329 #define wxACTION_TEXT_LEFT _T("left")
330 #define wxACTION_TEXT_RIGHT _T("right")
331 #define wxACTION_TEXT_UP _T("up")
332 #define wxACTION_TEXT_DOWN _T("down")
333 #define wxACTION_TEXT_WORD_LEFT _T("wordleft")
334 #define wxACTION_TEXT_WORD_RIGHT _T("wordright")
335 #define wxACTION_TEXT_PAGE_UP _T("pageup")
336 #define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
338 // clipboard operations
339 #define wxACTION_TEXT_COPY _T("copy")
340 #define wxACTION_TEXT_CUT _T("cut")
341 #define wxACTION_TEXT_PASTE _T("paste")
343 // insert text at the cursor position: the text is in strArg of PerformAction
344 #define wxACTION_TEXT_INSERT _T("insert")
346 // if the action starts with either of these prefixes and the rest of the
347 // string is one of the movement commands, it means to select/delete text from
348 // the current cursor position to the new one
349 #define wxACTION_TEXT_PREFIX_SEL _T("sel")
350 #define wxACTION_TEXT_PREFIX_DEL _T("del")
353 #define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
354 #define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
355 #define wxACTION_TEXT_SEL_WORD _T("wordsel")
356 #define wxACTION_TEXT_SEL_LINE _T("linesel")
359 #define wxACTION_TEXT_UNDO _T("undo")
360 #define wxACTION_TEXT_REDO _T("redo")
362 // ----------------------------------------------------------------------------
364 // ----------------------------------------------------------------------------
366 class WXDLLEXPORT wxStdTextCtrlInputHandler
: public wxStdInputHandler
369 wxStdTextCtrlInputHandler(wxInputHandler
*inphand
) : wxStdInputHandler(inphand
) {}
371 virtual bool HandleKey(wxInputConsumer
*consumer
,
372 const wxKeyEvent
& event
,
373 bool pressed
) { return false; }
374 virtual bool HandleMouse(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
375 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
376 virtual bool HandleFocus(wxInputConsumer
*consumer
, const wxFocusEvent
& event
) { return false; }
379 // get the position of the mouse click
380 static wxTextPos
HitTest(const wxTextCtrl
*text
, const wxPoint
& pos
) { return 0; }
383 wxTextCtrl
*m_winCapture
;
387 // wxUSE_UNIV_TEXTCTRL
389 #endif // __X11TEXTCTRLH__