]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/textctrl.h
define wxUSE_MFC as 0 if it's not defined (fixes gcc -Wundef warning)
[wxWidgets.git] / include / wx / gtk1 / 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
12028905 14#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
bf3e0fbd 15 #pragma interface "textctrl.h"
f5abe911
RR
16#endif
17
c801d85f 18//-----------------------------------------------------------------------------
a1b82138 19// wxTextCtrl
c801d85f
KB
20//-----------------------------------------------------------------------------
21
20123d49 22class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
c801d85f 23{
a1b82138 24public:
01041145 25 wxTextCtrl() { Init(); }
13111b2a
VZ
26 wxTextCtrl(wxWindow *parent,
27 wxWindowID id,
28 const wxString &value = wxEmptyString,
29 const wxPoint &pos = wxDefaultPosition,
30 const wxSize &size = wxDefaultSize,
31 long style = 0,
32 const wxValidator& validator = wxDefaultValidator,
33 const wxString &name = wxTextCtrlNameStr);
34
9440c3d0
KH
35 ~wxTextCtrl();
36
13111b2a
VZ
37 bool Create(wxWindow *parent,
38 wxWindowID id,
39 const wxString &value = wxEmptyString,
40 const wxPoint &pos = wxDefaultPosition,
41 const wxSize &size = wxDefaultSize,
42 long style = 0,
43 const wxValidator& validator = wxDefaultValidator,
44 const wxString &name = wxTextCtrlNameStr);
a1b82138
VZ
45
46 // implement base class pure virtuals
47 // ----------------------------------
48
49 virtual wxString GetValue() const;
50 virtual void SetValue(const wxString& value);
51
52 virtual int GetLineLength(long lineNo) const;
53 virtual wxString GetLineText(long lineNo) const;
54 virtual int GetNumberOfLines() const;
55
56 virtual bool IsModified() const;
57 virtual bool IsEditable() const;
58
59 // If the return values from and to are the same, there is no selection.
60 virtual void GetSelection(long* from, long* to) const;
61
62 // operations
63 // ----------
64
65 // editing
66 virtual void Clear();
67 virtual void Replace(long from, long to, const wxString& value);
68 virtual void Remove(long from, long to);
69
3a9fa0d6
VZ
70 // sets/clears the dirty flag
71 virtual void MarkDirty();
a1b82138
VZ
72 virtual void DiscardEdits();
73
d7eee191
VZ
74 virtual void SetMaxLength(unsigned long len);
75
a1b82138
VZ
76 // writing text inserts it at the current position, appending always
77 // inserts it at the end
78 virtual void WriteText(const wxString& text);
79 virtual void AppendText(const wxString& text);
80
17665a2b
VZ
81 // apply text attribute to the range of text (only works with richedit
82 // controls)
83 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
84
a1b82138
VZ
85 // translate between the position (which is just an index in the text ctrl
86 // considering all its contents as a single strings) and (x, y) coordinates
87 // which represent column and line.
88 virtual long XYToPosition(long x, long y) const;
0efe5ba7 89 virtual bool PositionToXY(long pos, long *x, long *y) const;
a1b82138
VZ
90
91 virtual void ShowPosition(long pos);
92
c04ec496
VZ
93#ifdef __WXGTK20__
94 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
4aae4a08
RD
95 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
96 wxTextCoord *col,
97 wxTextCoord *row) const
98 {
99 return wxTextCtrlBase::HitTest(pt, col, row);
100 }
c04ec496
VZ
101#endif // __WXGTK20__
102
a1b82138
VZ
103 // Clipboard operations
104 virtual void Copy();
105 virtual void Cut();
106 virtual void Paste();
7c41ac7b 107
ca8b28f2
JS
108 // Undo/redo
109 virtual void Undo();
110 virtual void Redo();
111
112 virtual bool CanUndo() const;
113 virtual bool CanRedo() const;
114
a1b82138
VZ
115 // Insertion point
116 virtual void SetInsertionPoint(long pos);
117 virtual void SetInsertionPointEnd();
118 virtual long GetInsertionPoint() const;
7d8268a1 119 virtual wxTextPos GetLastPosition() const;
a1b82138
VZ
120
121 virtual void SetSelection(long from, long to);
122 virtual void SetEditable(bool editable);
ca8b28f2 123
7d8268a1 124 virtual bool Enable( bool enable = true );
68df5777 125
a1b82138
VZ
126 // Implementation from now on
127 void OnDropFiles( wxDropFilesEvent &event );
c801d85f 128 void OnChar( wxKeyEvent &event );
7c41ac7b 129
e702ff0f
JS
130 void OnCut(wxCommandEvent& event);
131 void OnCopy(wxCommandEvent& event);
132 void OnPaste(wxCommandEvent& event);
133 void OnUndo(wxCommandEvent& event);
134 void OnRedo(wxCommandEvent& event);
135
136 void OnUpdateCut(wxUpdateUIEvent& event);
137 void OnUpdateCopy(wxUpdateUIEvent& event);
138 void OnUpdatePaste(wxUpdateUIEvent& event);
139 void OnUpdateUndo(wxUpdateUIEvent& event);
140 void OnUpdateRedo(wxUpdateUIEvent& event);
141
17665a2b
VZ
142 bool SetFont(const wxFont& font);
143 bool SetForegroundColour(const wxColour& colour);
144 bool SetBackgroundColour(const wxColour& colour);
68dda785 145
2830bf19 146 GtkWidget* GetConnectWidget();
b4071e91 147 bool IsOwnGtkWindow( GdkWindow *window );
f40fdaa3 148 void DoApplyWidgetStyle(GtkRcStyle *style);
2830bf19 149 void CalculateScrollbar();
65045edd 150 void OnInternalIdle();
c04ec496
VZ
151
152#ifdef __WXGTK20__
153 void SetUpdateFont(bool WXUNUSED(update)) { }
154#else // !__WXGTK20__
155 void SetUpdateFont(bool update) { m_updateFont = update; }
01041145 156 void UpdateFontIfNeeded();
c04ec496 157#endif // __WXGTK20__/!__WXGTK20__
a1b82138 158
7d8268a1 159 void SetModified() { m_modified = true; }
0efe5ba7 160
0cc7251e
VZ
161 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
162 // avoid horrible flicker/scrolling back and forth
163 virtual void Freeze();
164 virtual void Thaw();
7d8268a1 165
9cd6d737
VZ
166 // textctrl specific scrolling
167 virtual bool ScrollLines(int lines);
168 virtual bool ScrollPages(int pages);
169
ce2f50e3
VZ
170 // implementation only from now on
171
fdca68a6
JS
172 // wxGTK-specific: called recursively by Enable,
173 // to give widgets an oppprtunity to correct their colours after they
174 // have been changed by Enable
175 virtual void OnParentEnable( bool enable ) ;
176
ce2f50e3
VZ
177 // tell the control to ignore next text changed signal
178 void IgnoreNextTextUpdate();
179
180 // should we ignore the changed signal? always resets the flag
181 bool IgnoreTextUpdate();
182
9d522606
RD
183 static wxVisualAttributes
184 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
7d8268a1 185
f68586e5
VZ
186protected:
187 virtual wxSize DoGetBestSize() const;
188
01041145
VZ
189 // common part of all ctors
190 void Init();
191
9cd6d737
VZ
192 // get the vertical adjustment, if any, NULL otherwise
193 GtkAdjustment *GetVAdj() const;
194
195 // scroll the control by the given number of pixels, return true if the
196 // scroll position changed
197 bool DoScroll(GtkAdjustment *adj, int diff);
198
9d522606
RD
199 // Widgets that use the style->base colour for the BG colour should
200 // override this and return true.
201 virtual bool UseGTKStyleBase() const { return true; }
202
41b81aed
RR
203#ifdef __WXGTK20__
204 // has the control been frozen by Freeze()?
205 bool IsFrozen() const { return m_frozenness > 0; }
206#endif
7d8268a1 207
a1b82138 208private:
01041145
VZ
209 // change the font for everything in this control
210 void ChangeFontGlobally();
211
903f689b 212 GtkWidget *m_text;
2830bf19 213 GtkWidget *m_vScrollbar;
ce2f50e3
VZ
214
215 bool m_modified:1;
216 bool m_vScrollbarVisible:1;
c04ec496 217#ifndef __WXGTK20__
ce2f50e3 218 bool m_updateFont:1;
c04ec496 219#endif // !__WXGTK20__
ce2f50e3 220 bool m_ignoreNextUpdate:1;
a1b82138 221
41b81aed
RR
222#ifdef __WXGTK20__
223 // Our text buffer. Convenient, and holds the buffer while using
224 // a dummy one when m_frozenness > 0
225 GtkTextBuffer *m_buffer;
226
227 // number of calls to Freeze() minus number of calls to Thaw()
228 unsigned int m_frozenness;
9440c3d0
KH
229
230 // For wxTE_AUTO_URL
231 void OnUrlMouseEvent(wxMouseEvent&);
232 GdkCursor *m_gdkHandCursor;
233 GdkCursor *m_gdkXTermCursor;
7d8268a1 234#endif
41b81aed 235
a1b82138 236 DECLARE_EVENT_TABLE()
777105f2 237 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
c801d85f
KB
238};
239
240#endif // __GTKTEXTCTRLH__
241