]>
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 | ||
c801d85f KB |
11 | #ifndef __GTKTEXTCTRLH__ |
12 | #define __GTKTEXTCTRLH__ | |
13 | ||
c801d85f | 14 | //----------------------------------------------------------------------------- |
a1b82138 | 15 | // wxTextCtrl |
c801d85f KB |
16 | //----------------------------------------------------------------------------- |
17 | ||
20123d49 | 18 | class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase |
c801d85f | 19 | { |
a1b82138 | 20 | public: |
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 | ||
9440c3d0 KH |
31 | ~wxTextCtrl(); |
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; | |
46 | virtual void SetValue(const wxString& value); | |
47 | ||
48 | virtual int GetLineLength(long lineNo) const; | |
49 | virtual wxString GetLineText(long lineNo) const; | |
50 | virtual int GetNumberOfLines() const; | |
51 | ||
52 | virtual bool IsModified() const; | |
53 | virtual bool IsEditable() const; | |
54 | ||
55 | // If the return values from and to are the same, there is no selection. | |
56 | virtual void GetSelection(long* from, long* to) const; | |
57 | ||
58 | // operations | |
59 | // ---------- | |
60 | ||
61 | // editing | |
62 | virtual void Clear(); | |
63 | virtual void Replace(long from, long to, const wxString& value); | |
64 | virtual void Remove(long from, long to); | |
65 | ||
3a9fa0d6 VZ |
66 | // sets/clears the dirty flag |
67 | virtual void MarkDirty(); | |
a1b82138 VZ |
68 | virtual void DiscardEdits(); |
69 | ||
d7eee191 VZ |
70 | virtual void SetMaxLength(unsigned long len); |
71 | ||
a1b82138 VZ |
72 | // writing text inserts it at the current position, appending always |
73 | // inserts it at the end | |
74 | virtual void WriteText(const wxString& text); | |
75 | virtual void AppendText(const wxString& text); | |
76 | ||
17665a2b VZ |
77 | // apply text attribute to the range of text (only works with richedit |
78 | // controls) | |
79 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); | |
80 | ||
a1b82138 VZ |
81 | // translate between the position (which is just an index in the text ctrl |
82 | // considering all its contents as a single strings) and (x, y) coordinates | |
83 | // which represent column and line. | |
84 | virtual long XYToPosition(long x, long y) const; | |
0efe5ba7 | 85 | virtual bool PositionToXY(long pos, long *x, long *y) const; |
a1b82138 VZ |
86 | |
87 | virtual void ShowPosition(long pos); | |
88 | ||
c04ec496 | 89 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; |
4aae4a08 RD |
90 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, |
91 | wxTextCoord *col, | |
92 | wxTextCoord *row) const | |
93 | { | |
94 | return wxTextCtrlBase::HitTest(pt, col, row); | |
95 | } | |
c04ec496 | 96 | |
a1b82138 VZ |
97 | // Clipboard operations |
98 | virtual void Copy(); | |
99 | virtual void Cut(); | |
100 | virtual void Paste(); | |
7c41ac7b | 101 | |
ca8b28f2 JS |
102 | // Undo/redo |
103 | virtual void Undo(); | |
104 | virtual void Redo(); | |
105 | ||
106 | virtual bool CanUndo() const; | |
107 | virtual bool CanRedo() const; | |
108 | ||
a1b82138 VZ |
109 | // Insertion point |
110 | virtual void SetInsertionPoint(long pos); | |
111 | virtual void SetInsertionPointEnd(); | |
112 | virtual long GetInsertionPoint() const; | |
7d8268a1 | 113 | virtual wxTextPos GetLastPosition() const; |
a1b82138 VZ |
114 | |
115 | virtual void SetSelection(long from, long to); | |
116 | virtual void SetEditable(bool editable); | |
ca8b28f2 | 117 | |
7d8268a1 | 118 | virtual bool Enable( bool enable = true ); |
68df5777 | 119 | |
a1b82138 VZ |
120 | // Implementation from now on |
121 | void OnDropFiles( wxDropFilesEvent &event ); | |
c801d85f | 122 | void OnChar( wxKeyEvent &event ); |
7c41ac7b | 123 | |
e702ff0f JS |
124 | void OnCut(wxCommandEvent& event); |
125 | void OnCopy(wxCommandEvent& event); | |
126 | void OnPaste(wxCommandEvent& event); | |
127 | void OnUndo(wxCommandEvent& event); | |
128 | void OnRedo(wxCommandEvent& event); | |
129 | ||
130 | void OnUpdateCut(wxUpdateUIEvent& event); | |
131 | void OnUpdateCopy(wxUpdateUIEvent& event); | |
132 | void OnUpdatePaste(wxUpdateUIEvent& event); | |
133 | void OnUpdateUndo(wxUpdateUIEvent& event); | |
134 | void OnUpdateRedo(wxUpdateUIEvent& event); | |
135 | ||
17665a2b VZ |
136 | bool SetFont(const wxFont& font); |
137 | bool SetForegroundColour(const wxColour& colour); | |
138 | bool SetBackgroundColour(const wxColour& colour); | |
68dda785 | 139 | |
2830bf19 | 140 | GtkWidget* GetConnectWidget(); |
2830bf19 | 141 | void CalculateScrollbar(); |
c04ec496 | 142 | |
c04ec496 | 143 | void SetUpdateFont(bool WXUNUSED(update)) { } |
a1b82138 | 144 | |
0cc7251e VZ |
145 | // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to |
146 | // avoid horrible flicker/scrolling back and forth | |
147 | virtual void Freeze(); | |
148 | virtual void Thaw(); | |
7d8268a1 | 149 | |
ce2f50e3 VZ |
150 | // implementation only from now on |
151 | ||
fdca68a6 JS |
152 | // wxGTK-specific: called recursively by Enable, |
153 | // to give widgets an oppprtunity to correct their colours after they | |
154 | // have been changed by Enable | |
155 | virtual void OnParentEnable( bool enable ) ; | |
156 | ||
ce2f50e3 | 157 | // tell the control to ignore next text changed signal |
6964cbba | 158 | void IgnoreNextTextUpdate() { m_ignoreNextUpdate = true; } |
ce2f50e3 VZ |
159 | |
160 | // should we ignore the changed signal? always resets the flag | |
161 | bool IgnoreTextUpdate(); | |
162 | ||
6964cbba VZ |
163 | // call this to indicate that the control is about to be changed |
164 | // programmatically and so m_modified flag shouldn't be set | |
165 | void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; } | |
166 | ||
167 | // should we mark the control as dirty? always resets the flag | |
168 | bool MarkDirtyOnChange(); | |
169 | ||
170 | ||
9d522606 RD |
171 | static wxVisualAttributes |
172 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
7d8268a1 | 173 | |
f68586e5 VZ |
174 | protected: |
175 | virtual wxSize DoGetBestSize() const; | |
ef5c70f9 VZ |
176 | virtual void DoApplyWidgetStyle(GtkRcStyle *style); |
177 | virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; | |
f68586e5 | 178 | |
01041145 VZ |
179 | // common part of all ctors |
180 | void Init(); | |
181 | ||
9d522606 RD |
182 | // Widgets that use the style->base colour for the BG colour should |
183 | // override this and return true. | |
184 | virtual bool UseGTKStyleBase() const { return true; } | |
185 | ||
41b81aed RR |
186 | // has the control been frozen by Freeze()? |
187 | bool IsFrozen() const { return m_frozenness > 0; } | |
7d8268a1 | 188 | |
a1b82138 | 189 | private: |
01041145 VZ |
190 | // change the font for everything in this control |
191 | void ChangeFontGlobally(); | |
192 | ||
0d91b234 VZ |
193 | // get the encoding which is used in this control: this looks at our font |
194 | // and default style but not the current style (i.e. the style for the | |
195 | // current position); returns wxFONTENCODING_SYSTEM if we have no specific | |
196 | // encoding | |
197 | wxFontEncoding GetTextEncoding() const; | |
198 | ||
199 | ||
903f689b | 200 | GtkWidget *m_text; |
ce2f50e3 VZ |
201 | |
202 | bool m_modified:1; | |
ce2f50e3 | 203 | bool m_ignoreNextUpdate:1; |
6964cbba | 204 | bool m_dontMarkDirty:1; |
a1b82138 | 205 | |
41b81aed RR |
206 | // Our text buffer. Convenient, and holds the buffer while using |
207 | // a dummy one when m_frozenness > 0 | |
208 | GtkTextBuffer *m_buffer; | |
209 | ||
210 | // number of calls to Freeze() minus number of calls to Thaw() | |
211 | unsigned int m_frozenness; | |
9440c3d0 KH |
212 | |
213 | // For wxTE_AUTO_URL | |
214 | void OnUrlMouseEvent(wxMouseEvent&); | |
215 | GdkCursor *m_gdkHandCursor; | |
216 | GdkCursor *m_gdkXTermCursor; | |
41b81aed | 217 | |
a1b82138 | 218 | DECLARE_EVENT_TABLE() |
777105f2 | 219 | DECLARE_DYNAMIC_CLASS(wxTextCtrl) |
c801d85f KB |
220 | }; |
221 | ||
222 | #endif // __GTKTEXTCTRLH__ | |
223 |