]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/textctrl.h
Implement for selection code.
[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
5a3ef194
PC
11#ifndef _WX_GTK_TEXTCTRL_H_
12#define _WX_GTK_TEXTCTRL_H_
13
14typedef struct _GtkTextMark GtkTextMark;
c801d85f 15
c801d85f 16//-----------------------------------------------------------------------------
a1b82138 17// wxTextCtrl
c801d85f
KB
18//-----------------------------------------------------------------------------
19
20123d49 20class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
c801d85f 21{
a1b82138 22public:
01041145 23 wxTextCtrl() { Init(); }
13111b2a
VZ
24 wxTextCtrl(wxWindow *parent,
25 wxWindowID id,
26 const wxString &value = wxEmptyString,
27 const wxPoint &pos = wxDefaultPosition,
28 const wxSize &size = wxDefaultSize,
29 long style = 0,
30 const wxValidator& validator = wxDefaultValidator,
31 const wxString &name = wxTextCtrlNameStr);
32
d3c7fc99 33 virtual ~wxTextCtrl();
9440c3d0 34
13111b2a
VZ
35 bool Create(wxWindow *parent,
36 wxWindowID id,
37 const wxString &value = wxEmptyString,
38 const wxPoint &pos = wxDefaultPosition,
39 const wxSize &size = wxDefaultSize,
40 long style = 0,
41 const wxValidator& validator = wxDefaultValidator,
42 const wxString &name = wxTextCtrlNameStr);
a1b82138
VZ
43
44 // implement base class pure virtuals
45 // ----------------------------------
46
47 virtual wxString GetValue() const;
28fdd8db 48 virtual bool IsEmpty() const;
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
927637fd
VZ
120 // Overridden wxWindow methods
121 virtual void SetWindowStyleFlag( long style );
7d8268a1 122 virtual bool Enable( bool enable = true );
68df5777 123
a1b82138
VZ
124 // Implementation from now on
125 void OnDropFiles( wxDropFilesEvent &event );
c801d85f 126 void OnChar( wxKeyEvent &event );
7c41ac7b 127
e702ff0f
JS
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);
133
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);
139
17665a2b
VZ
140 bool SetFont(const wxFont& font);
141 bool SetForegroundColour(const wxColour& colour);
142 bool SetBackgroundColour(const wxColour& colour);
68dda785 143
2830bf19 144 GtkWidget* GetConnectWidget();
c04ec496 145
c04ec496 146 void SetUpdateFont(bool WXUNUSED(update)) { }
a1b82138 147
0cc7251e
VZ
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();
151 virtual void Thaw();
7d8268a1 152
ce2f50e3
VZ
153 // implementation only from now on
154
fdca68a6
JS
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
47a8a4d5 158 virtual void OnEnabled( bool enable ) ;
fdca68a6 159
ce2f50e3 160 // tell the control to ignore next text changed signal
f6519b40 161 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
ce2f50e3
VZ
162
163 // should we ignore the changed signal? always resets the flag
164 bool IgnoreTextUpdate();
165
6964cbba
VZ
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; }
169
170 // should we mark the control as dirty? always resets the flag
171 bool MarkDirtyOnChange();
172
8312c461
VZ
173 // always let GTK have mouse release events for multiline controls
174 virtual bool GTKProcessEvent(wxEvent& event) const;
175
6964cbba 176
9d522606
RD
177 static wxVisualAttributes
178 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
7d8268a1 179
50679f94 180 // has the control been frozen by Freeze()?
5a3ef194 181 bool IsFrozen() const { return m_freezeCount > 0; }
50679f94 182
f68586e5
VZ
183protected:
184 virtual wxSize DoGetBestSize() const;
ef5c70f9
VZ
185 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
186 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
f68586e5 187
01041145
VZ
188 // common part of all ctors
189 void Init();
190
9d522606
RD
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; }
194
ee2ec18e 195 virtual void DoSetValue(const wxString &value, int flags = 0);
f6519b40 196
927637fd
VZ
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();
204
a1b82138 205private:
01041145
VZ
206 // change the font for everything in this control
207 void ChangeFontGlobally();
208
0d91b234
VZ
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
212 // encoding
213 wxFontEncoding GetTextEncoding() const;
214
215
903f689b 216 GtkWidget *m_text;
ce2f50e3
VZ
217
218 bool m_modified:1;
6964cbba 219 bool m_dontMarkDirty:1;
a1b82138 220
f6519b40
VZ
221 int m_countUpdatesToIgnore;
222
41b81aed 223 // Our text buffer. Convenient, and holds the buffer while using
5a3ef194 224 // a dummy one when frozen
41b81aed
RR
225 GtkTextBuffer *m_buffer;
226
227 // number of calls to Freeze() minus number of calls to Thaw()
5a3ef194
PC
228 unsigned m_freezeCount;
229 GtkTextMark* m_showPositionOnThaw;
9440c3d0
KH
230
231 // For wxTE_AUTO_URL
232 void OnUrlMouseEvent(wxMouseEvent&);
233 GdkCursor *m_gdkHandCursor;
234 GdkCursor *m_gdkXTermCursor;
41b81aed 235
a1b82138 236 DECLARE_EVENT_TABLE()
777105f2 237 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
c801d85f
KB
238};
239
5a3ef194 240#endif // _WX_GTK_TEXTCTRL_H_