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"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
40 wxSOURCE_UNDO_INSERT_LINE
,
45 class wxSourceUndoStep
: public wxObject
48 wxSourceUndoStep( wxSourceUndo type
, int y1
, int y2
, wxTextCtrl
*owner
);
59 wxArrayString m_lines
;
65 wxSourceLine( const wxString
&text
= wxEmptyString
)
73 WX_DECLARE_OBJARRAY(wxSourceLine
, wxSourceLineArray
);
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
, public wxScrollHelper
90 wxTextCtrl() { Init(); }
91 wxTextCtrl(wxWindow
*parent
,
93 const wxString
&value
= wxEmptyString
,
94 const wxPoint
&pos
= wxDefaultPosition
,
95 const wxSize
&size
= wxDefaultSize
,
97 const wxValidator
& validator
= wxDefaultValidator
,
98 const wxString
&name
= wxTextCtrlNameStr
);
99 virtual ~wxTextCtrl();
101 bool Create(wxWindow
*parent
,
103 const wxString
&value
= wxEmptyString
,
104 const wxPoint
&pos
= wxDefaultPosition
,
105 const wxSize
&size
= wxDefaultSize
,
107 const wxValidator
& validator
= wxDefaultValidator
,
108 const wxString
&name
= wxTextCtrlNameStr
);
110 // required for scrolling with wxScrollHelper
111 // ------------------------------------------
113 virtual void PrepareDC(wxDC
& dc
) { DoPrepareDC(dc
); }
115 // implement base class pure virtuals
116 // ----------------------------------
118 virtual void ChangeValue(const wxString
&value
);
120 virtual int GetLineLength(long lineNo
) const;
121 virtual wxString
GetLineText(long lineNo
) const;
122 virtual int GetNumberOfLines() const;
124 virtual bool IsModified() const;
125 virtual bool IsEditable() const;
127 // more readable flag testing methods
128 // ----------------------------------
130 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD
) != 0; }
131 bool WrapLines() const { return false; }
133 // If the return values from and to are the same, there is no selection.
134 virtual void GetSelection(long* from
, long* to
) const;
140 virtual void Clear();
141 virtual void Replace(long from
, long to
, const wxString
& value
);
142 virtual void Remove(long from
, long to
);
144 // clears the dirty flag
145 virtual void DiscardEdits();
147 virtual void SetMaxLength(unsigned long len
);
149 // writing text inserts it at the current position, appending always
150 // inserts it at the end
151 virtual void WriteText(const wxString
& text
);
152 virtual void AppendText(const wxString
& text
);
154 // apply text attribute to the range of text (only works with richedit
156 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
158 // translate between the position (which is just an index in the text ctrl
159 // considering all its contents as a single strings) and (x, y) coordinates
160 // which represent column and line.
161 virtual long XYToPosition(long x
, long y
) const;
162 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
164 virtual void ShowPosition(long pos
);
166 // Clipboard operations
169 virtual void Paste();
173 virtual void Redo() {}
175 virtual bool CanUndo() const { return (m_undos
.GetCount() > 0); }
176 virtual bool CanRedo() const { return false; }
179 virtual void SetInsertionPoint(long pos
);
180 virtual void SetInsertionPointEnd();
181 virtual long GetInsertionPoint() const;
182 virtual wxTextPos
GetLastPosition() const;
184 virtual void SetSelection(long from
, long to
);
185 virtual void SetEditable(bool editable
);
187 virtual bool Enable( bool enable
= true );
189 void OnCut(wxCommandEvent
& event
);
190 void OnCopy(wxCommandEvent
& event
);
191 void OnPaste(wxCommandEvent
& event
);
192 void OnUndo(wxCommandEvent
& event
);
193 void OnRedo(wxCommandEvent
& event
);
195 void OnUpdateCut(wxUpdateUIEvent
& event
);
196 void OnUpdateCopy(wxUpdateUIEvent
& event
);
197 void OnUpdatePaste(wxUpdateUIEvent
& event
);
198 void OnUpdateUndo(wxUpdateUIEvent
& event
);
199 void OnUpdateRedo(wxUpdateUIEvent
& event
);
201 bool SetFont(const wxFont
& font
);
202 bool SetForegroundColour(const wxColour
& colour
);
203 bool SetBackgroundColour(const wxColour
& colour
);
205 void SetModified() { m_modified
= true; }
207 // textctrl specific scrolling
208 virtual bool ScrollLines(int lines
);
209 virtual bool ScrollPages(int pages
);
211 // not part of the wxTextCtrl API from now on..
213 void SetLanguage( wxSourceLanguage lang
= wxSOURCE_LANG_NONE
);
222 void ClearSelection();
224 int GetCursorX() { return m_cursorX
; }
225 int GetCursorY() { return m_cursorY
; }
226 bool IsModified() { return m_modified
; }
227 bool OverwriteMode() { return m_overwrite
; }
229 // implementation from now on...
231 int PosToPixel( int line
, int pos
);
232 int PixelToPos( int line
, int pixel
);
234 void SearchForBrackets();
236 void DoChar( char c
);
242 wxString
GetNextToken( wxString
&line
, size_t &pos
);
244 void DrawLinePart( wxDC
&dc
, int x
, int y
, const wxString
&toDraw
, const wxString
&origin
, const wxColour
&colour
);
245 void DrawLine( wxDC
&dc
, int x
, int y
, const wxString
&line
, int lineNum
);
246 void OnPaint( wxPaintEvent
&event
);
247 void OnEraseBackground( wxEraseEvent
&event
);
248 void OnMouse( wxMouseEvent
&event
);
249 void OnChar( wxKeyEvent
&event
);
250 void OnSetFocus( wxFocusEvent
& event
);
251 void OnKillFocus( wxFocusEvent
& event
);
253 void OnInternalIdle();
254 void RefreshLine( int n
);
255 void RefreshDown( int n
);
256 void MoveCursor( int new_x
, int new_y
, bool shift
= false, bool centre
= false );
257 void MyAdjustScrollbars();
260 // common part of all ctors
263 virtual wxSize
DoGetBestSize() const;
265 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
267 friend class wxSourceUndoStep
;
269 wxSourceLineArray m_lines
;
272 wxColour m_sourceColour
;
273 wxColour m_commentColour
;
274 wxColour m_stringColour
;
279 int m_selStartX
,m_selStartY
;
280 int m_selEndX
,m_selEndY
;
292 wxArrayString m_keywords
;
293 wxColour m_keywordColour
;
295 wxArrayString m_defines
;
296 wxColour m_defineColour
;
298 wxArrayString m_variables
;
299 wxColour m_variableColour
;
301 wxSourceLanguage m_lang
;
311 DECLARE_EVENT_TABLE()
312 DECLARE_DYNAMIC_CLASS(wxTextCtrl
);
315 //-----------------------------------------------------------------------------
316 // this is superfluous here but helps to compile
317 //-----------------------------------------------------------------------------
319 // cursor movement and also selection and delete operations
320 #define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
321 #define wxACTION_TEXT_FIRST _T("first") // go to pos 0
322 #define wxACTION_TEXT_LAST _T("last") // go to last pos
323 #define wxACTION_TEXT_HOME _T("home")
324 #define wxACTION_TEXT_END _T("end")
325 #define wxACTION_TEXT_LEFT _T("left")
326 #define wxACTION_TEXT_RIGHT _T("right")
327 #define wxACTION_TEXT_UP _T("up")
328 #define wxACTION_TEXT_DOWN _T("down")
329 #define wxACTION_TEXT_WORD_LEFT _T("wordleft")
330 #define wxACTION_TEXT_WORD_RIGHT _T("wordright")
331 #define wxACTION_TEXT_PAGE_UP _T("pageup")
332 #define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
334 // clipboard operations
335 #define wxACTION_TEXT_COPY _T("copy")
336 #define wxACTION_TEXT_CUT _T("cut")
337 #define wxACTION_TEXT_PASTE _T("paste")
339 // insert text at the cursor position: the text is in strArg of PerformAction
340 #define wxACTION_TEXT_INSERT _T("insert")
342 // if the action starts with either of these prefixes and the rest of the
343 // string is one of the movement commands, it means to select/delete text from
344 // the current cursor position to the new one
345 #define wxACTION_TEXT_PREFIX_SEL _T("sel")
346 #define wxACTION_TEXT_PREFIX_DEL _T("del")
349 #define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
350 #define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
351 #define wxACTION_TEXT_SEL_WORD _T("wordsel")
352 #define wxACTION_TEXT_SEL_LINE _T("linesel")
355 #define wxACTION_TEXT_UNDO _T("undo")
356 #define wxACTION_TEXT_REDO _T("redo")
358 // ----------------------------------------------------------------------------
360 // ----------------------------------------------------------------------------
362 class WXDLLEXPORT wxStdTextCtrlInputHandler
: public wxStdInputHandler
365 wxStdTextCtrlInputHandler(wxInputHandler
*inphand
) : wxStdInputHandler(inphand
) {}
367 virtual bool HandleKey(wxInputConsumer
*consumer
,
368 const wxKeyEvent
& event
,
369 bool pressed
) { return false; }
370 virtual bool HandleMouse(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
371 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
) { return false; }
372 virtual bool HandleFocus(wxInputConsumer
*consumer
, const wxFocusEvent
& event
) { return false; }
375 // get the position of the mouse click
376 static wxTextPos
HitTest(const wxTextCtrl
*text
, const wxPoint
& pos
) { return 0; }
379 wxTextCtrl
*m_winCapture
;
383 // wxUSE_UNIV_TEXTCTRL
385 #endif // __X11TEXTCTRLH__