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 wxString
GetValue() const;
48 virtual bool IsEmpty() const;
50 virtual int GetLineLength(long lineNo
) const;
51 virtual wxString
GetLineText(long lineNo
) const;
52 virtual int GetNumberOfLines() const;
54 virtual bool IsModified() const;
55 virtual bool IsEditable() const;
57 // If the return values from and to are the same, there is no selection.
58 virtual void GetSelection(long* from
, long* to
) const;
65 virtual void Replace(long from
, long to
, const wxString
& value
);
66 virtual void Remove(long from
, long to
);
68 // sets/clears the dirty flag
69 virtual void MarkDirty();
70 virtual void DiscardEdits();
72 virtual void SetMaxLength(unsigned long len
);
74 // writing text inserts it at the current position, appending always
75 // inserts it at the end
76 virtual void WriteText(const wxString
& text
);
77 virtual void AppendText(const wxString
& text
);
79 // apply text attribute to the range of text (only works with richedit
81 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
83 // translate between the position (which is just an index in the text ctrl
84 // considering all its contents as a single strings) and (x, y) coordinates
85 // which represent column and line.
86 virtual long XYToPosition(long x
, long y
) const;
87 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
89 virtual void ShowPosition(long pos
);
91 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
92 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
94 wxTextCoord
*row
) const
96 return wxTextCtrlBase::HitTest(pt
, col
, row
);
99 // Clipboard operations
102 virtual void Paste();
108 virtual bool CanUndo() const;
109 virtual bool CanRedo() const;
112 virtual void SetInsertionPoint(long pos
);
113 virtual void SetInsertionPointEnd();
114 virtual long GetInsertionPoint() const;
115 virtual wxTextPos
GetLastPosition() const;
117 virtual void SetSelection(long from
, long to
);
118 virtual void SetEditable(bool editable
);
120 // Overridden wxWindow methods
121 virtual void SetWindowStyleFlag( long style
);
122 virtual bool Enable( bool enable
= true );
124 // Implementation from now on
125 void OnDropFiles( wxDropFilesEvent
&event
);
126 void OnChar( wxKeyEvent
&event
);
128 void OnCut(wxCommandEvent
& event
);
129 void OnCopy(wxCommandEvent
& event
);
130 void OnPaste(wxCommandEvent
& event
);
131 void OnUndo(wxCommandEvent
& event
);
132 void OnRedo(wxCommandEvent
& event
);
134 void OnUpdateCut(wxUpdateUIEvent
& event
);
135 void OnUpdateCopy(wxUpdateUIEvent
& event
);
136 void OnUpdatePaste(wxUpdateUIEvent
& event
);
137 void OnUpdateUndo(wxUpdateUIEvent
& event
);
138 void OnUpdateRedo(wxUpdateUIEvent
& event
);
140 bool SetFont(const wxFont
& font
);
141 bool SetForegroundColour(const wxColour
& colour
);
142 bool SetBackgroundColour(const wxColour
& colour
);
144 GtkWidget
* GetConnectWidget();
146 void SetUpdateFont(bool WXUNUSED(update
)) { }
148 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
149 // avoid horrible flicker/scrolling back and forth
150 virtual void Freeze();
153 // implementation only from now on
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 OnParentEnable( bool enable
) ;
160 // tell the control to ignore next text changed signal
161 void IgnoreNextTextUpdate(int n
= 1) { m_countUpdatesToIgnore
= n
; }
163 // should we ignore the changed signal? always resets the flag
164 bool IgnoreTextUpdate();
166 // call this to indicate that the control is about to be changed
167 // programmatically and so m_modified flag shouldn't be set
168 void DontMarkDirtyOnNextChange() { m_dontMarkDirty
= true; }
170 // should we mark the control as dirty? always resets the flag
171 bool MarkDirtyOnChange();
173 // always let GTK have mouse release events for multiline controls
174 virtual bool GTKProcessEvent(wxEvent
& event
) const;
177 static wxVisualAttributes
178 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
180 // has the control been frozen by Freeze()?
181 bool IsFrozen() const { return m_freezeCount
> 0; }
184 virtual wxSize
DoGetBestSize() const;
185 virtual void DoApplyWidgetStyle(GtkRcStyle
*style
);
186 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
188 // common part of all ctors
191 // Widgets that use the style->base colour for the BG colour should
192 // override this and return true.
193 virtual bool UseGTKStyleBase() const { return true; }
195 virtual void DoSetValue(const wxString
&value
, int flags
= 0);
197 // wrappers hiding the differences between functions doing the same thing
198 // for GtkTextView and GtkEntry (all of them use current window style to
199 // set the given characteristic)
200 void GTKSetEditable();
201 void GTKSetVisibility();
202 void GTKSetWrapMode();
203 void GTKSetJustification();
206 // change the font for everything in this control
207 void ChangeFontGlobally();
209 // get the encoding which is used in this control: this looks at our font
210 // and default style but not the current style (i.e. the style for the
211 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
213 wxFontEncoding
GetTextEncoding() const;
219 bool m_dontMarkDirty
:1;
221 int m_countUpdatesToIgnore
;
223 // Our text buffer. Convenient, and holds the buffer while using
224 // a dummy one when frozen
225 GtkTextBuffer
*m_buffer
;
227 // number of calls to Freeze() minus number of calls to Thaw()
228 unsigned m_freezeCount
;
229 GtkTextMark
* m_showPositionOnThaw
;
232 void OnUrlMouseEvent(wxMouseEvent
&);
233 GdkCursor
*m_gdkHandCursor
;
234 GdkCursor
*m_gdkXTermCursor
;
236 DECLARE_EVENT_TABLE()
237 DECLARE_DYNAMIC_CLASS(wxTextCtrl
)
240 #endif // _WX_GTK_TEXTCTRL_H_