1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
14 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
18 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
21 wxTextCtrl() { Init(); }
22 wxTextCtrl(wxWindow
*parent
,
24 const wxString
&value
= wxEmptyString
,
25 const wxPoint
&pos
= wxDefaultPosition
,
26 const wxSize
&size
= wxDefaultSize
,
28 const wxValidator
& validator
= wxDefaultValidator
,
29 const wxString
&name
= wxTextCtrlNameStr
);
31 virtual ~wxTextCtrl();
33 bool Create(wxWindow
*parent
,
35 const wxString
&value
= wxEmptyString
,
36 const wxPoint
&pos
= wxDefaultPosition
,
37 const wxSize
&size
= wxDefaultSize
,
39 const wxValidator
& validator
= wxDefaultValidator
,
40 const wxString
&name
= wxTextCtrlNameStr
);
42 // implement base class pure virtuals
43 // ----------------------------------
45 virtual wxString
GetValue() const;
46 virtual bool IsEmpty() const;
48 virtual int GetLineLength(long lineNo
) const;
49 virtual wxString
GetLineText(long lineNo
) const;
50 virtual int GetNumberOfLines() const;
52 virtual bool IsModified() const;
53 virtual bool IsEditable() const;
55 // If the return values from and to are the same, there is no selection.
56 virtual void GetSelection(long* from
, long* to
) const;
63 virtual void Replace(long from
, long to
, const wxString
& value
);
64 virtual void Remove(long from
, long to
);
66 // sets/clears the dirty flag
67 virtual void MarkDirty();
68 virtual void DiscardEdits();
70 virtual void SetMaxLength(unsigned long len
);
72 // writing text inserts it at the current position, appending always
73 // inserts it at the end
74 virtual void WriteText(const wxString
& text
);
75 virtual void AppendText(const wxString
& text
);
77 // apply text attribute to the range of text (only works with richedit
79 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
81 // translate between the position (which is just an index in the text ctrl
82 // considering all its contents as a single strings) and (x, y) coordinates
83 // which represent column and line.
84 virtual long XYToPosition(long x
, long y
) const;
85 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
87 virtual void ShowPosition(long pos
);
89 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
90 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
92 wxTextCoord
*row
) const
94 return wxTextCtrlBase::HitTest(pt
, col
, row
);
97 // Clipboard operations
100 virtual void Paste();
106 virtual bool CanUndo() const;
107 virtual bool CanRedo() const;
110 virtual void SetInsertionPoint(long pos
);
111 virtual void SetInsertionPointEnd();
112 virtual long GetInsertionPoint() const;
113 virtual wxTextPos
GetLastPosition() const;
115 virtual void SetSelection(long from
, long to
);
116 virtual void SetEditable(bool editable
);
118 virtual bool Enable( bool enable
= true );
120 // Implementation from now on
121 void OnDropFiles( wxDropFilesEvent
&event
);
122 void OnChar( wxKeyEvent
&event
);
124 void OnCut(wxCommandEvent
& event
);
125 void OnCopy(wxCommandEvent
& event
);
126 void OnPaste(wxCommandEvent
& event
);
127 void OnUndo(wxCommandEvent
& event
);
128 void OnRedo(wxCommandEvent
& event
);
130 void OnUpdateCut(wxUpdateUIEvent
& event
);
131 void OnUpdateCopy(wxUpdateUIEvent
& event
);
132 void OnUpdatePaste(wxUpdateUIEvent
& event
);
133 void OnUpdateUndo(wxUpdateUIEvent
& event
);
134 void OnUpdateRedo(wxUpdateUIEvent
& event
);
136 bool SetFont(const wxFont
& font
);
137 bool SetForegroundColour(const wxColour
& colour
);
138 bool SetBackgroundColour(const wxColour
& colour
);
140 GtkWidget
* GetConnectWidget();
141 void CalculateScrollbar();
143 void SetUpdateFont(bool WXUNUSED(update
)) { }
145 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
146 // avoid horrible flicker/scrolling back and forth
147 virtual void Freeze();
150 // implementation only from now on
152 // wxGTK-specific: called recursively by Enable,
153 // to give widgets an oppprtunity to correct their colours after they
154 // have been changed by Enable
155 virtual void OnParentEnable( bool enable
) ;
157 // tell the control to ignore next text changed signal
158 void IgnoreNextTextUpdate(int n
= 1) { m_countUpdatesToIgnore
= n
; }
160 // should we ignore the changed signal? always resets the flag
161 bool IgnoreTextUpdate();
163 // call this to indicate that the control is about to be changed
164 // programmatically and so m_modified flag shouldn't be set
165 void DontMarkDirtyOnNextChange() { m_dontMarkDirty
= true; }
167 // should we mark the control as dirty? always resets the flag
168 bool MarkDirtyOnChange();
170 // always let GTK have mouse release events for multiline controls
171 virtual bool GTKProcessEvent(wxEvent
& event
) const;
174 static wxVisualAttributes
175 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
177 // has the control been frozen by Freeze()?
178 bool IsFrozen() const { return m_frozenness
> 0; }
181 virtual wxSize
DoGetBestSize() const;
182 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
183 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
185 // common part of all ctors
188 // Widgets that use the style->base colour for the BG colour should
189 // override this and return true.
190 virtual bool UseGTKStyleBase() const { return true; }
192 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
195 // change the font for everything in this control
196 void ChangeFontGlobally();
198 // get the encoding which is used in this control: this looks at our font
199 // and default style but not the current style (i.e. the style for the
200 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
202 wxFontEncoding
GetTextEncoding() const;
208 bool m_dontMarkDirty
:1;
210 int m_countUpdatesToIgnore
;
212 // Our text buffer. Convenient, and holds the buffer while using
213 // a dummy one when m_frozenness > 0
214 GtkTextBuffer
*m_buffer
;
216 // number of calls to Freeze() minus number of calls to Thaw()
217 unsigned int m_frozenness
;
220 void OnUrlMouseEvent(wxMouseEvent
&);
221 GdkCursor
*m_gdkHandCursor
;
222 GdkCursor
*m_gdkXTermCursor
;
224 DECLARE_EVENT_TABLE()
225 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
228 #endif // __GTKTEXTCTRLH__