]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/textctrl.h
added wxTextCtrl::ChangeValue() which is the same as SetValue() but doesn't send...
[wxWidgets.git] / include / wx / gtk / textctrl.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
6b0d8a01 2// Name: wx/gtk/textctrl.h
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
7c41ac7b 6// Id: $Id$
371a5b4e 7// Copyright: (c) 1998 Robert Roebling
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
c801d85f
KB
11#ifndef __GTKTEXTCTRLH__
12#define __GTKTEXTCTRLH__
13
c801d85f 14//-----------------------------------------------------------------------------
a1b82138 15// wxTextCtrl
c801d85f
KB
16//-----------------------------------------------------------------------------
17
20123d49 18class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
c801d85f 19{
a1b82138 20public:
01041145 21 wxTextCtrl() { Init(); }
13111b2a
VZ
22 wxTextCtrl(wxWindow *parent,
23 wxWindowID id,
24 const wxString &value = wxEmptyString,
25 const wxPoint &pos = wxDefaultPosition,
26 const wxSize &size = wxDefaultSize,
27 long style = 0,
28 const wxValidator& validator = wxDefaultValidator,
29 const wxString &name = wxTextCtrlNameStr);
30
d3c7fc99 31 virtual ~wxTextCtrl();
9440c3d0 32
13111b2a
VZ
33 bool Create(wxWindow *parent,
34 wxWindowID id,
35 const wxString &value = wxEmptyString,
36 const wxPoint &pos = wxDefaultPosition,
37 const wxSize &size = wxDefaultSize,
38 long style = 0,
39 const wxValidator& validator = wxDefaultValidator,
40 const wxString &name = wxTextCtrlNameStr);
a1b82138
VZ
41
42 // implement base class pure virtuals
43 // ----------------------------------
44
45 virtual wxString GetValue() const;
f6519b40
VZ
46 virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
47
48 virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
a1b82138
VZ
49
50 virtual int GetLineLength(long lineNo) const;
51 virtual wxString GetLineText(long lineNo) const;
52 virtual int GetNumberOfLines() const;
53
54 virtual bool IsModified() const;
55 virtual bool IsEditable() const;
56
57 // If the return values from and to are the same, there is no selection.
58 virtual void GetSelection(long* from, long* to) const;
59
60 // operations
61 // ----------
62
63 // editing
64 virtual void Clear();
65 virtual void Replace(long from, long to, const wxString& value);
66 virtual void Remove(long from, long to);
67
3a9fa0d6
VZ
68 // sets/clears the dirty flag
69 virtual void MarkDirty();
a1b82138
VZ
70 virtual void DiscardEdits();
71
d7eee191
VZ
72 virtual void SetMaxLength(unsigned long len);
73
a1b82138
VZ
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);
78
17665a2b
VZ
79 // apply text attribute to the range of text (only works with richedit
80 // controls)
81 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
82
a1b82138
VZ
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;
0efe5ba7 87 virtual bool PositionToXY(long pos, long *x, long *y) const;
a1b82138
VZ
88
89 virtual void ShowPosition(long pos);
90
c04ec496 91 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
4aae4a08
RD
92 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
93 wxTextCoord *col,
94 wxTextCoord *row) const
95 {
96 return wxTextCtrlBase::HitTest(pt, col, row);
97 }
c04ec496 98
a1b82138
VZ
99 // Clipboard operations
100 virtual void Copy();
101 virtual void Cut();
102 virtual void Paste();
7c41ac7b 103
ca8b28f2
JS
104 // Undo/redo
105 virtual void Undo();
106 virtual void Redo();
107
108 virtual bool CanUndo() const;
109 virtual bool CanRedo() const;
110
a1b82138
VZ
111 // Insertion point
112 virtual void SetInsertionPoint(long pos);
113 virtual void SetInsertionPointEnd();
114 virtual long GetInsertionPoint() const;
7d8268a1 115 virtual wxTextPos GetLastPosition() const;
a1b82138
VZ
116
117 virtual void SetSelection(long from, long to);
118 virtual void SetEditable(bool editable);
ca8b28f2 119
7d8268a1 120 virtual bool Enable( bool enable = true );
68df5777 121
a1b82138
VZ
122 // Implementation from now on
123 void OnDropFiles( wxDropFilesEvent &event );
c801d85f 124 void OnChar( wxKeyEvent &event );
7c41ac7b 125
e702ff0f
JS
126 void OnCut(wxCommandEvent& event);
127 void OnCopy(wxCommandEvent& event);
128 void OnPaste(wxCommandEvent& event);
129 void OnUndo(wxCommandEvent& event);
130 void OnRedo(wxCommandEvent& event);
131
132 void OnUpdateCut(wxUpdateUIEvent& event);
133 void OnUpdateCopy(wxUpdateUIEvent& event);
134 void OnUpdatePaste(wxUpdateUIEvent& event);
135 void OnUpdateUndo(wxUpdateUIEvent& event);
136 void OnUpdateRedo(wxUpdateUIEvent& event);
137
17665a2b
VZ
138 bool SetFont(const wxFont& font);
139 bool SetForegroundColour(const wxColour& colour);
140 bool SetBackgroundColour(const wxColour& colour);
68dda785 141
2830bf19 142 GtkWidget* GetConnectWidget();
2830bf19 143 void CalculateScrollbar();
c04ec496 144
c04ec496 145 void SetUpdateFont(bool WXUNUSED(update)) { }
a1b82138 146
0cc7251e
VZ
147 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
148 // avoid horrible flicker/scrolling back and forth
149 virtual void Freeze();
150 virtual void Thaw();
7d8268a1 151
ce2f50e3
VZ
152 // implementation only from now on
153
fdca68a6
JS
154 // wxGTK-specific: called recursively by Enable,
155 // to give widgets an oppprtunity to correct their colours after they
156 // have been changed by Enable
157 virtual void OnParentEnable( bool enable ) ;
158
ce2f50e3 159 // tell the control to ignore next text changed signal
f6519b40 160 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
ce2f50e3
VZ
161
162 // should we ignore the changed signal? always resets the flag
163 bool IgnoreTextUpdate();
164
6964cbba
VZ
165 // call this to indicate that the control is about to be changed
166 // programmatically and so m_modified flag shouldn't be set
167 void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
168
169 // should we mark the control as dirty? always resets the flag
170 bool MarkDirtyOnChange();
171
8312c461
VZ
172 // always let GTK have mouse release events for multiline controls
173 virtual bool GTKProcessEvent(wxEvent& event) const;
174
6964cbba 175
9d522606
RD
176 static wxVisualAttributes
177 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
7d8268a1 178
f68586e5
VZ
179protected:
180 virtual wxSize DoGetBestSize() const;
ef5c70f9
VZ
181 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
182 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
f68586e5 183
01041145
VZ
184 // common part of all ctors
185 void Init();
186
9d522606
RD
187 // Widgets that use the style->base colour for the BG colour should
188 // override this and return true.
189 virtual bool UseGTKStyleBase() const { return true; }
190
41b81aed
RR
191 // has the control been frozen by Freeze()?
192 bool IsFrozen() const { return m_frozenness > 0; }
7d8268a1 193
f6519b40
VZ
194 void DoSetValue(const wxString &value, int flags = 0);
195
a1b82138 196private:
01041145
VZ
197 // change the font for everything in this control
198 void ChangeFontGlobally();
199
0d91b234
VZ
200 // get the encoding which is used in this control: this looks at our font
201 // and default style but not the current style (i.e. the style for the
202 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
203 // encoding
204 wxFontEncoding GetTextEncoding() const;
205
206
903f689b 207 GtkWidget *m_text;
ce2f50e3
VZ
208
209 bool m_modified:1;
6964cbba 210 bool m_dontMarkDirty:1;
a1b82138 211
f6519b40
VZ
212 int m_countUpdatesToIgnore;
213
41b81aed
RR
214 // Our text buffer. Convenient, and holds the buffer while using
215 // a dummy one when m_frozenness > 0
216 GtkTextBuffer *m_buffer;
217
218 // number of calls to Freeze() minus number of calls to Thaw()
219 unsigned int m_frozenness;
9440c3d0
KH
220
221 // For wxTE_AUTO_URL
222 void OnUrlMouseEvent(wxMouseEvent&);
223 GdkCursor *m_gdkHandCursor;
224 GdkCursor *m_gdkXTermCursor;
41b81aed 225
a1b82138 226 DECLARE_EVENT_TABLE()
777105f2 227 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
c801d85f
KB
228};
229
230#endif // __GTKTEXTCTRLH__
231