]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/textctrl.h
8cde769c6b4a49b6c6abbf803c0f2cd25bd43467
[wxWidgets.git] / include / wx / gtk / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
13
14 //-----------------------------------------------------------------------------
15 // wxTextCtrl
16 //-----------------------------------------------------------------------------
17
18 class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
19 {
20 public:
21 wxTextCtrl() { Init(); }
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
31 virtual ~wxTextCtrl();
32
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);
41
42 // implement base class pure virtuals
43 // ----------------------------------
44
45 virtual wxString GetValue() const;
46 virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
47
48 virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
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
68 // sets/clears the dirty flag
69 virtual void MarkDirty();
70 virtual void DiscardEdits();
71
72 virtual void SetMaxLength(unsigned long len);
73
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
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
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;
88
89 virtual void ShowPosition(long pos);
90
91 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
92 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
93 wxTextCoord *col,
94 wxTextCoord *row) const
95 {
96 return wxTextCtrlBase::HitTest(pt, col, row);
97 }
98
99 // Clipboard operations
100 virtual void Copy();
101 virtual void Cut();
102 virtual void Paste();
103
104 // Undo/redo
105 virtual void Undo();
106 virtual void Redo();
107
108 virtual bool CanUndo() const;
109 virtual bool CanRedo() const;
110
111 // Insertion point
112 virtual void SetInsertionPoint(long pos);
113 virtual void SetInsertionPointEnd();
114 virtual long GetInsertionPoint() const;
115 virtual wxTextPos GetLastPosition() const;
116
117 virtual void SetSelection(long from, long to);
118 virtual void SetEditable(bool editable);
119
120 virtual bool Enable( bool enable = true );
121
122 // Implementation from now on
123 void OnDropFiles( wxDropFilesEvent &event );
124 void OnChar( wxKeyEvent &event );
125
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
138 bool SetFont(const wxFont& font);
139 bool SetForegroundColour(const wxColour& colour);
140 bool SetBackgroundColour(const wxColour& colour);
141
142 GtkWidget* GetConnectWidget();
143 void CalculateScrollbar();
144
145 void SetUpdateFont(bool WXUNUSED(update)) { }
146
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();
151
152 // implementation only from now on
153
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
159 // tell the control to ignore next text changed signal
160 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
161
162 // should we ignore the changed signal? always resets the flag
163 bool IgnoreTextUpdate();
164
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
172 // always let GTK have mouse release events for multiline controls
173 virtual bool GTKProcessEvent(wxEvent& event) const;
174
175
176 static wxVisualAttributes
177 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
178
179 protected:
180 virtual wxSize DoGetBestSize() const;
181 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
182 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
183
184 // common part of all ctors
185 void Init();
186
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
191 // has the control been frozen by Freeze()?
192 bool IsFrozen() const { return m_frozenness > 0; }
193
194 void DoSetValue(const wxString &value, int flags = 0);
195
196 private:
197 // change the font for everything in this control
198 void ChangeFontGlobally();
199
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
207 GtkWidget *m_text;
208
209 bool m_modified:1;
210 bool m_dontMarkDirty:1;
211
212 int m_countUpdatesToIgnore;
213
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;
220
221 // For wxTE_AUTO_URL
222 void OnUrlMouseEvent(wxMouseEvent&);
223 GdkCursor *m_gdkHandCursor;
224 GdkCursor *m_gdkXTermCursor;
225
226 DECLARE_EVENT_TABLE()
227 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
228 };
229
230 #endif // __GTKTEXTCTRLH__
231