1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/x11/textctrl.h
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef __X11TEXTCTRLH__
11 #define __X11TEXTCTRLH__
13 // Set to 1 to use wxUniv's implementation, 0
15 #define wxUSE_UNIV_TEXTCTRL 1
17 #if wxUSE_UNIV_TEXTCTRL
18 #include "wx/univ/textctrl.h"
21 #include "wx/scrolwin.h"
22 #include "wx/arrstr.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
39 wxSOURCE_UNDO_INSERT_LINE
,
44 class wxSourceUndoStep
: public wxObject
47 wxSourceUndoStep( wxSourceUndo type
, int y1
, int y2
, wxTextCtrl
*owner
);
58 wxArrayString m_lines
;
64 wxSourceLine( const wxString
&text
= wxEmptyString
)
72 WX_DECLARE_OBJARRAY(wxSourceLine
, wxSourceLineArray
);
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
, public wxScrollHelper
89 wxTextCtrl() { Init(); }
90 wxTextCtrl(wxWindow
*parent
,
92 const wxString
&value
= wxEmptyString
,
93 const wxPoint
&pos
= wxDefaultPosition
,
94 const wxSize
&size
= wxDefaultSize
,
96 const wxValidator
& validator
= wxDefaultValidator
,
97 const wxString
&name
= wxTextCtrlNameStr
);
98 virtual ~wxTextCtrl();
100 bool Create(wxWindow
*parent
,
102 const wxString
&value
= wxEmptyString
,
103 const wxPoint
&pos
= wxDefaultPosition
,
104 const wxSize
&size
= wxDefaultSize
,
106 const wxValidator
& validator
= wxDefaultValidator
,
107 const wxString
&name
= wxTextCtrlNameStr
);
109 // required for scrolling with wxScrollHelper
110 // ------------------------------------------
112 virtual void PrepareDC(wxDC
& dc
) { DoPrepareDC(dc
); }
114 // implement base class pure virtuals
115 // ----------------------------------
117 virtual void ChangeValue(const wxString
&value
);
119 virtual int GetLineLength(long lineNo
) const;
120 virtual wxString
GetLineText(long lineNo
) const;
121 virtual int GetNumberOfLines() const;
123 virtual bool IsModified() const;
124 virtual bool IsEditable() const;
126 // more readable flag testing methods
127 // ----------------------------------
129 bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD
) != 0; }
130 bool WrapLines() const { return false; }
132 // If the return values from and to are the same, there is no selection.
133 virtual void GetSelection(long* from
, long* to
) const;
139 virtual void Clear();
140 virtual void Replace(long from
, long to
, const wxString
& value
);
141 virtual void Remove(long from
, long to
);
143 // clears the dirty flag
144 virtual void DiscardEdits();
146 virtual void SetMaxLength(unsigned long len
);
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
);
153 // apply text attribute to the range of text (only works with richedit
155 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
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;
163 virtual void ShowPosition(long pos
);
165 // Clipboard operations
168 virtual void Paste();
172 virtual void Redo() {}
174 virtual bool CanUndo() const { return (m_undos
.GetCount() > 0); }
175 virtual bool CanRedo() const { return false; }
178 virtual void SetInsertionPoint(long pos
);
179 virtual void SetInsertionPointEnd();
180 virtual long GetInsertionPoint() const;
181 virtual wxTextPos
GetLastPosition() const;
183 virtual void SetSelection(long from
, long to
);
184 virtual void SetEditable(bool editable
);
186 virtual bool Enable( bool enable
= true );
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
);
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
);
200 bool SetFont(const wxFont
& font
);
201 bool SetForegroundColour(const wxColour
& colour
);
202 bool SetBackgroundColour(const wxColour
& colour
);
204 void SetModified() { m_modified
= true; }
206 // textctrl specific scrolling
207 virtual bool ScrollLines(int lines
);
208 virtual bool ScrollPages(int pages
);
210 // not part of the wxTextCtrl API from now on..
212 void SetLanguage( wxSourceLanguage lang
= wxSOURCE_LANG_NONE
);
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
, size_t &pos
);
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
);
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();
259 // common part of all ctors
262 virtual wxSize
DoGetBestSize() const;
264 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
266 friend class wxSourceUndoStep
;
268 wxSourceLineArray m_lines
;
271 wxColour m_sourceColour
;
272 wxColour m_commentColour
;
273 wxColour m_stringColour
;
278 int m_selStartX
,m_selStartY
;
279 int m_selEndX
,m_selEndY
;
291 wxArrayString m_keywords
;
292 wxColour m_keywordColour
;
294 wxArrayString m_defines
;
295 wxColour m_defineColour
;
297 wxArrayString m_variables
;
298 wxColour m_variableColour
;
300 wxSourceLanguage m_lang
;
310 DECLARE_EVENT_TABLE()
311 DECLARE_DYNAMIC_CLASS(wxTextCtrl
);
314 //-----------------------------------------------------------------------------
315 // this is superfluous here but helps to compile
316 //-----------------------------------------------------------------------------
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")
333 // clipboard operations
334 #define wxACTION_TEXT_COPY wxT("copy")
335 #define wxACTION_TEXT_CUT wxT("cut")
336 #define wxACTION_TEXT_PASTE wxT("paste")
338 // insert text at the cursor position: the text is in strArg of PerformAction
339 #define wxACTION_TEXT_INSERT wxT("insert")
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")
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")
354 #define wxACTION_TEXT_UNDO wxT("undo")
355 #define wxACTION_TEXT_REDO wxT("redo")
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
361 class WXDLLIMPEXP_CORE 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
;
382 // wxUSE_UNIV_TEXTCTRL
384 #endif // __X11TEXTCTRLH__