1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_TEXTCTRL_H_
12 #define _WX_GTK_TEXTCTRL_H_
14 typedef struct _GtkTextMark GtkTextMark
;
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
20 class WXDLLIMPEXP_CORE wxTextCtrl
: public wxTextCtrlBase
23 wxTextCtrl() { Init(); }
24 wxTextCtrl(wxWindow
*parent
,
26 const wxString
&value
= wxEmptyString
,
27 const wxPoint
&pos
= wxDefaultPosition
,
28 const wxSize
&size
= wxDefaultSize
,
30 const wxValidator
& validator
= wxDefaultValidator
,
31 const wxString
&name
= wxTextCtrlNameStr
);
33 virtual ~wxTextCtrl();
35 bool Create(wxWindow
*parent
,
37 const wxString
&value
= wxEmptyString
,
38 const wxPoint
&pos
= wxDefaultPosition
,
39 const wxSize
&size
= wxDefaultSize
,
41 const wxValidator
& validator
= wxDefaultValidator
,
42 const wxString
&name
= wxTextCtrlNameStr
);
44 // implement base class pure virtuals
45 // ----------------------------------
47 virtual void WriteText(const wxString
& text
);
48 virtual wxString
GetValue() const;
49 virtual bool IsEmpty() const;
51 virtual int GetLineLength(long lineNo
) const;
52 virtual wxString
GetLineText(long lineNo
) const;
53 virtual int GetNumberOfLines() const;
55 virtual bool IsModified() const;
56 virtual bool IsEditable() const;
58 virtual void GetSelection(long* from
, long* to
) const;
60 virtual void Remove(long from
, long to
);
62 virtual void MarkDirty();
63 virtual void DiscardEdits();
65 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
67 // translate between the position (which is just an index in the text ctrl
68 // considering all its contents as a single strings) and (x, y) coordinates
69 // which represent column and line.
70 virtual long XYToPosition(long x
, long y
) const;
71 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
73 virtual void ShowPosition(long pos
);
75 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
76 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
78 wxTextCoord
*row
) const
80 return wxTextCtrlBase::HitTest(pt
, col
, row
);
83 // Clipboard operations
89 virtual void SetInsertionPoint(long pos
);
90 virtual long GetInsertionPoint() const;
91 virtual wxTextPos
GetLastPosition() const;
93 virtual void SetSelection(long from
, long to
);
94 virtual void SetEditable(bool editable
);
96 // Overridden wxWindow methods
97 virtual void SetWindowStyleFlag( long style
);
98 virtual bool Enable( bool enable
= true );
100 // Implementation from now on
101 void OnDropFiles( wxDropFilesEvent
&event
);
102 void OnChar( wxKeyEvent
&event
);
104 void OnCut(wxCommandEvent
& event
);
105 void OnCopy(wxCommandEvent
& event
);
106 void OnPaste(wxCommandEvent
& event
);
107 void OnUndo(wxCommandEvent
& event
);
108 void OnRedo(wxCommandEvent
& event
);
110 void OnUpdateCut(wxUpdateUIEvent
& event
);
111 void OnUpdateCopy(wxUpdateUIEvent
& event
);
112 void OnUpdatePaste(wxUpdateUIEvent
& event
);
113 void OnUpdateUndo(wxUpdateUIEvent
& event
);
114 void OnUpdateRedo(wxUpdateUIEvent
& event
);
116 bool SetFont(const wxFont
& font
);
117 bool SetForegroundColour(const wxColour
& colour
);
118 bool SetBackgroundColour(const wxColour
& colour
);
120 GtkWidget
* GetConnectWidget();
122 void SetUpdateFont(bool WXUNUSED(update
)) { }
124 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
125 // avoid horrible flicker/scrolling back and forth
126 virtual void Freeze();
129 // implementation only from now on
131 // tell the control to ignore next text changed signal
132 void IgnoreNextTextUpdate(int n
= 1) { m_countUpdatesToIgnore
= n
; }
134 // should we ignore the changed signal? always resets the flag
135 bool IgnoreTextUpdate();
137 // call this to indicate that the control is about to be changed
138 // programmatically and so m_modified flag shouldn't be set
139 void DontMarkDirtyOnNextChange() { m_dontMarkDirty
= true; }
141 // should we mark the control as dirty? always resets the flag
142 bool MarkDirtyOnChange();
144 // always let GTK have mouse release events for multiline controls
145 virtual bool GTKProcessEvent(wxEvent
& event
) const;
148 static wxVisualAttributes
149 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
151 // has the control been frozen by Freeze()?
152 bool IsFrozen() const { return m_freezeCount
> 0; }
155 // wxGTK-specific: called recursively by Enable,
156 // to give widgets an oppprtunity to correct their colours after they
157 // have been changed by Enable
158 virtual void OnEnabled(bool enable
);
160 // overridden wxWindow virtual methods
161 virtual wxSize
DoGetBestSize() const;
162 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
163 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
165 // common part of all ctors
168 // Widgets that use the style->base colour for the BG colour should
169 // override this and return true.
170 virtual bool UseGTKStyleBase() const { return true; }
172 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
174 // wrappers hiding the differences between functions doing the same thing
175 // for GtkTextView and GtkEntry (all of them use current window style to
176 // set the given characteristic)
177 void GTKSetEditable();
178 void GTKSetVisibility();
179 void GTKSetWrapMode();
180 void GTKSetJustification();
183 // overridden wxTextEntry virtual methods
184 virtual const wxWindow
*GetEditableWindow() const { return this; }
185 virtual GtkEditable
*GetEditable() const;
186 virtual void EnableTextChangedEvents(bool enable
);
188 // change the font for everything in this control
189 void ChangeFontGlobally();
191 // get the encoding which is used in this control: this looks at our font
192 // and default style but not the current style (i.e. the style for the
193 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
195 wxFontEncoding
GetTextEncoding() const;
197 // returns either m_text or m_buffer depending on whether the control is
198 // single- or multi-line; convenient for the GTK+ functions which work with
200 void *GetTextObject() const
202 return IsMultiLine() ? wx_static_cast(void *, m_buffer
)
203 : wx_static_cast(void *, m_text
);
207 // the widget used for single line controls
211 bool m_dontMarkDirty
:1;
213 int m_countUpdatesToIgnore
;
215 // Our text buffer. Convenient, and holds the buffer while using
216 // a dummy one when frozen
217 GtkTextBuffer
*m_buffer
;
219 // number of calls to Freeze() minus number of calls to Thaw()
220 unsigned m_freezeCount
;
221 GtkTextMark
* m_showPositionOnThaw
;
224 void OnUrlMouseEvent(wxMouseEvent
&);
225 GdkCursor
*m_gdkHandCursor
;
226 GdkCursor
*m_gdkXTermCursor
;
228 DECLARE_EVENT_TABLE()
229 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
232 #endif // _WX_GTK_TEXTCTRL_H_