]>
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 | ||
24f54e45 | 33 | virtual ~wxTextCtrl() wxNOEXCEPT; |
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 | 65 | virtual bool SetStyle(long start, long end, const wxTextAttr& style); |
e9ee2270 | 66 | virtual bool GetStyle(long position, wxTextAttr& style); |
17665a2b | 67 | |
a1b82138 VZ |
68 | // translate between the position (which is just an index in the text ctrl |
69 | // considering all its contents as a single strings) and (x, y) coordinates | |
70 | // which represent column and line. | |
71 | virtual long XYToPosition(long x, long y) const; | |
0efe5ba7 | 72 | virtual bool PositionToXY(long pos, long *x, long *y) const; |
a1b82138 VZ |
73 | |
74 | virtual void ShowPosition(long pos); | |
75 | ||
c04ec496 | 76 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; |
4aae4a08 RD |
77 | virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, |
78 | wxTextCoord *col, | |
79 | wxTextCoord *row) const | |
80 | { | |
81 | return wxTextCtrlBase::HitTest(pt, col, row); | |
82 | } | |
c04ec496 | 83 | |
a1b82138 VZ |
84 | // Clipboard operations |
85 | virtual void Copy(); | |
86 | virtual void Cut(); | |
87 | virtual void Paste(); | |
7c41ac7b | 88 | |
a1b82138 VZ |
89 | // Insertion point |
90 | virtual void SetInsertionPoint(long pos); | |
a1b82138 | 91 | virtual long GetInsertionPoint() const; |
7d8268a1 | 92 | virtual wxTextPos GetLastPosition() const; |
a1b82138 VZ |
93 | |
94 | virtual void SetSelection(long from, long to); | |
95 | virtual void SetEditable(bool editable); | |
ca8b28f2 | 96 | |
927637fd VZ |
97 | // Overridden wxWindow methods |
98 | virtual void SetWindowStyleFlag( long style ); | |
7d8268a1 | 99 | virtual bool Enable( bool enable = true ); |
68df5777 | 100 | |
a1b82138 VZ |
101 | // Implementation from now on |
102 | void OnDropFiles( wxDropFilesEvent &event ); | |
c801d85f | 103 | void OnChar( wxKeyEvent &event ); |
7c41ac7b | 104 | |
e702ff0f JS |
105 | void OnCut(wxCommandEvent& event); |
106 | void OnCopy(wxCommandEvent& event); | |
107 | void OnPaste(wxCommandEvent& event); | |
108 | void OnUndo(wxCommandEvent& event); | |
109 | void OnRedo(wxCommandEvent& event); | |
110 | ||
111 | void OnUpdateCut(wxUpdateUIEvent& event); | |
112 | void OnUpdateCopy(wxUpdateUIEvent& event); | |
113 | void OnUpdatePaste(wxUpdateUIEvent& event); | |
114 | void OnUpdateUndo(wxUpdateUIEvent& event); | |
115 | void OnUpdateRedo(wxUpdateUIEvent& event); | |
116 | ||
17665a2b VZ |
117 | bool SetFont(const wxFont& font); |
118 | bool SetForegroundColour(const wxColour& colour); | |
119 | bool SetBackgroundColour(const wxColour& colour); | |
68dda785 | 120 | |
2830bf19 | 121 | GtkWidget* GetConnectWidget(); |
c04ec496 | 122 | |
c04ec496 | 123 | void SetUpdateFont(bool WXUNUSED(update)) { } |
a1b82138 | 124 | |
ce2f50e3 VZ |
125 | // implementation only from now on |
126 | ||
ce2f50e3 | 127 | // tell the control to ignore next text changed signal |
f6519b40 | 128 | void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; } |
ce2f50e3 VZ |
129 | |
130 | // should we ignore the changed signal? always resets the flag | |
131 | bool IgnoreTextUpdate(); | |
132 | ||
6964cbba VZ |
133 | // call this to indicate that the control is about to be changed |
134 | // programmatically and so m_modified flag shouldn't be set | |
135 | void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; } | |
136 | ||
137 | // should we mark the control as dirty? always resets the flag | |
138 | bool MarkDirtyOnChange(); | |
139 | ||
8312c461 VZ |
140 | // always let GTK have mouse release events for multiline controls |
141 | virtual bool GTKProcessEvent(wxEvent& event) const; | |
142 | ||
6964cbba | 143 | |
9d522606 RD |
144 | static wxVisualAttributes |
145 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
7d8268a1 | 146 | |
f68586e5 | 147 | protected: |
3c75d8ba PC |
148 | // wxGTK-specific: called recursively by Enable, |
149 | // to give widgets an oppprtunity to correct their colours after they | |
150 | // have been changed by Enable | |
151 | virtual void OnEnabled(bool enable); | |
152 | ||
0ec1179b | 153 | // overridden wxWindow virtual methods |
f68586e5 | 154 | virtual wxSize DoGetBestSize() const; |
ef5c70f9 VZ |
155 | virtual void DoApplyWidgetStyle(GtkRcStyle *style); |
156 | virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; | |
f68586e5 | 157 | |
7a78a937 VZ |
158 | virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const; |
159 | ||
17808a75 VZ |
160 | virtual void DoFreeze(); |
161 | virtual void DoThaw(); | |
162 | ||
9d522606 RD |
163 | // Widgets that use the style->base colour for the BG colour should |
164 | // override this and return true. | |
165 | virtual bool UseGTKStyleBase() const { return true; } | |
166 | ||
ee2ec18e | 167 | virtual void DoSetValue(const wxString &value, int flags = 0); |
f6519b40 | 168 | |
6ce83213 VZ |
169 | virtual wxPoint DoPositionToCoords(long pos) const; |
170 | ||
927637fd VZ |
171 | // wrappers hiding the differences between functions doing the same thing |
172 | // for GtkTextView and GtkEntry (all of them use current window style to | |
173 | // set the given characteristic) | |
174 | void GTKSetEditable(); | |
175 | void GTKSetVisibility(); | |
ff805cac | 176 | void GTKSetActivatesDefault(); |
927637fd VZ |
177 | void GTKSetWrapMode(); |
178 | void GTKSetJustification(); | |
179 | ||
a1b82138 | 180 | private: |
95dc31e0 PC |
181 | void Init(); |
182 | ||
3c75d8ba | 183 | // overridden wxTextEntry virtual methods |
3c75d8ba | 184 | virtual GtkEditable *GetEditable() const; |
0847e36e | 185 | virtual GtkEntry *GetEntry() const; |
3c75d8ba PC |
186 | virtual void EnableTextChangedEvents(bool enable); |
187 | ||
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 | { | |
5c33522f VZ |
202 | return IsMultiLine() ? static_cast<void *>(m_buffer) |
203 | : static_cast<void *>(m_text); | |
86e37f69 VZ |
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 | ||
5a3ef194 | 219 | GtkTextMark* m_showPositionOnThaw; |
385e8575 | 220 | GSList* m_anonymousMarkList; |
9440c3d0 KH |
221 | |
222 | // For wxTE_AUTO_URL | |
223 | void OnUrlMouseEvent(wxMouseEvent&); | |
41b81aed | 224 | |
a1b82138 | 225 | DECLARE_EVENT_TABLE() |
777105f2 | 226 | DECLARE_DYNAMIC_CLASS(wxTextCtrl) |
c801d85f KB |
227 | }; |
228 | ||
5a3ef194 | 229 | #endif // _WX_GTK_TEXTCTRL_H_ |