]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | typedef struct _GtkTextMark GtkTextMark; | |
c801d85f | 15 | |
c801d85f | 16 | //----------------------------------------------------------------------------- |
a1b82138 | 17 | // wxTextCtrl |
c801d85f KB |
18 | //----------------------------------------------------------------------------- |
19 | ||
20123d49 | 20 | class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase |
c801d85f | 21 | { |
a1b82138 | 22 | public: |
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 | ||
0ec1179b | 47 | virtual void WriteText(const wxString& text); |
a1b82138 | 48 | virtual wxString GetValue() const; |
28fdd8db | 49 | virtual bool IsEmpty() const; |
a1b82138 VZ |
50 | |
51 | virtual int GetLineLength(long lineNo) const; | |
52 | virtual wxString GetLineText(long lineNo) const; | |
53 | virtual int GetNumberOfLines() const; | |
54 | ||
55 | virtual bool IsModified() const; | |
56 | virtual bool IsEditable() const; | |
57 | ||
a1b82138 VZ |
58 | virtual void GetSelection(long* from, long* to) const; |
59 | ||
a1b82138 VZ |
60 | virtual void Remove(long from, long to); |
61 | ||
3a9fa0d6 | 62 | virtual void MarkDirty(); |
a1b82138 VZ |
63 | virtual void DiscardEdits(); |
64 | ||
17665a2b VZ |
65 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); |
66 | ||
a1b82138 VZ |
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; | |
0efe5ba7 | 71 | virtual bool PositionToXY(long pos, long *x, long *y) const; |
a1b82138 VZ |
72 | |
73 | virtual void ShowPosition(long pos); | |
74 | ||
c04ec496 | 75 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; |
4aae4a08 RD |
76 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, |
77 | wxTextCoord *col, | |
78 | wxTextCoord *row) const | |
79 | { | |
80 | return wxTextCtrlBase::HitTest(pt, col, row); | |
81 | } | |
c04ec496 | 82 | |
a1b82138 VZ |
83 | // Clipboard operations |
84 | virtual void Copy(); | |
85 | virtual void Cut(); | |
86 | virtual void Paste(); | |
7c41ac7b | 87 | |
a1b82138 VZ |
88 | // Insertion point |
89 | virtual void SetInsertionPoint(long pos); | |
a1b82138 | 90 | virtual long GetInsertionPoint() const; |
7d8268a1 | 91 | virtual wxTextPos GetLastPosition() const; |
a1b82138 VZ |
92 | |
93 | virtual void SetSelection(long from, long to); | |
94 | virtual void SetEditable(bool editable); | |
ca8b28f2 | 95 | |
927637fd VZ |
96 | // Overridden wxWindow methods |
97 | virtual void SetWindowStyleFlag( long style ); | |
7d8268a1 | 98 | virtual bool Enable( bool enable = true ); |
68df5777 | 99 | |
a1b82138 VZ |
100 | // Implementation from now on |
101 | void OnDropFiles( wxDropFilesEvent &event ); | |
c801d85f | 102 | void OnChar( wxKeyEvent &event ); |
7c41ac7b | 103 | |
e702ff0f JS |
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); | |
109 | ||
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); | |
115 | ||
17665a2b VZ |
116 | bool SetFont(const wxFont& font); |
117 | bool SetForegroundColour(const wxColour& colour); | |
118 | bool SetBackgroundColour(const wxColour& colour); | |
68dda785 | 119 | |
2830bf19 | 120 | GtkWidget* GetConnectWidget(); |
c04ec496 | 121 | |
c04ec496 | 122 | void SetUpdateFont(bool WXUNUSED(update)) { } |
a1b82138 | 123 | |
0cc7251e VZ |
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(); | |
127 | virtual void Thaw(); | |
7d8268a1 | 128 | |
ce2f50e3 VZ |
129 | // implementation only from now on |
130 | ||
fdca68a6 JS |
131 | // wxGTK-specific: called recursively by Enable, |
132 | // to give widgets an oppprtunity to correct their colours after they | |
133 | // have been changed by Enable | |
47a8a4d5 | 134 | virtual void OnEnabled( bool enable ) ; |
fdca68a6 | 135 | |
ce2f50e3 | 136 | // tell the control to ignore next text changed signal |
f6519b40 | 137 | void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; } |
ce2f50e3 VZ |
138 | |
139 | // should we ignore the changed signal? always resets the flag | |
140 | bool IgnoreTextUpdate(); | |
141 | ||
6964cbba VZ |
142 | // call this to indicate that the control is about to be changed |
143 | // programmatically and so m_modified flag shouldn't be set | |
144 | void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; } | |
145 | ||
146 | // should we mark the control as dirty? always resets the flag | |
147 | bool MarkDirtyOnChange(); | |
148 | ||
8312c461 VZ |
149 | // always let GTK have mouse release events for multiline controls |
150 | virtual bool GTKProcessEvent(wxEvent& event) const; | |
151 | ||
6964cbba | 152 | |
9d522606 RD |
153 | static wxVisualAttributes |
154 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
7d8268a1 | 155 | |
50679f94 | 156 | // has the control been frozen by Freeze()? |
5a3ef194 | 157 | bool IsFrozen() const { return m_freezeCount > 0; } |
50679f94 | 158 | |
f68586e5 | 159 | protected: |
0ec1179b | 160 | // overridden wxWindow virtual methods |
f68586e5 | 161 | virtual wxSize DoGetBestSize() const; |
ef5c70f9 VZ |
162 | virtual void DoApplyWidgetStyle(GtkRcStyle *style); |
163 | virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; | |
f68586e5 | 164 | |
0ec1179b VZ |
165 | // overridden wxTextEntry virtual methods |
166 | virtual const wxWindow *GetEditableWindow() const { return this; } | |
167 | virtual GtkEditable *GetEditable() const; | |
168 | virtual void EnableTextChangedEvents(bool enable); | |
169 | ||
01041145 VZ |
170 | // common part of all ctors |
171 | void Init(); | |
172 | ||
9d522606 RD |
173 | // Widgets that use the style->base colour for the BG colour should |
174 | // override this and return true. | |
175 | virtual bool UseGTKStyleBase() const { return true; } | |
176 | ||
ee2ec18e | 177 | virtual void DoSetValue(const wxString &value, int flags = 0); |
f6519b40 | 178 | |
927637fd VZ |
179 | // wrappers hiding the differences between functions doing the same thing |
180 | // for GtkTextView and GtkEntry (all of them use current window style to | |
181 | // set the given characteristic) | |
182 | void GTKSetEditable(); | |
183 | void GTKSetVisibility(); | |
184 | void GTKSetWrapMode(); | |
185 | void GTKSetJustification(); | |
186 | ||
a1b82138 | 187 | private: |
01041145 VZ |
188 | // change the font for everything in this control |
189 | void ChangeFontGlobally(); | |
190 | ||
0d91b234 VZ |
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 | |
194 | // encoding | |
195 | wxFontEncoding GetTextEncoding() const; | |
196 | ||
86e37f69 VZ |
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 | |
199 | // both | |
200 | void *GetTextObject() const | |
201 | { | |
202 | return IsMultiLine() ? wx_static_cast(void *, m_buffer) | |
203 | : wx_static_cast(void *, m_text); | |
204 | } | |
205 | ||
0d91b234 | 206 | |
86e37f69 | 207 | // the widget used for single line controls |
903f689b | 208 | GtkWidget *m_text; |
ce2f50e3 VZ |
209 | |
210 | bool m_modified:1; | |
6964cbba | 211 | bool m_dontMarkDirty:1; |
a1b82138 | 212 | |
f6519b40 VZ |
213 | int m_countUpdatesToIgnore; |
214 | ||
41b81aed | 215 | // Our text buffer. Convenient, and holds the buffer while using |
5a3ef194 | 216 | // a dummy one when frozen |
41b81aed RR |
217 | GtkTextBuffer *m_buffer; |
218 | ||
219 | // number of calls to Freeze() minus number of calls to Thaw() | |
5a3ef194 PC |
220 | unsigned m_freezeCount; |
221 | GtkTextMark* m_showPositionOnThaw; | |
9440c3d0 KH |
222 | |
223 | // For wxTE_AUTO_URL | |
224 | void OnUrlMouseEvent(wxMouseEvent&); | |
225 | GdkCursor *m_gdkHandCursor; | |
226 | GdkCursor *m_gdkXTermCursor; | |
41b81aed | 227 | |
a1b82138 | 228 | DECLARE_EVENT_TABLE() |
777105f2 | 229 | DECLARE_DYNAMIC_CLASS(wxTextCtrl) |
c801d85f KB |
230 | }; |
231 | ||
5a3ef194 | 232 | #endif // _WX_GTK_TEXTCTRL_H_ |