]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
f96aa4d9 | 5 | // Id: $Id$ |
a81258be | 6 | // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin |
13289f04 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "textctrl.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/textctrl.h" | |
15 | #include "wx/utils.h" | |
1a5a8367 | 16 | #include <wx/intl.h> |
c801d85f | 17 | |
a81258be RR |
18 | #include <sys/types.h> |
19 | #include <sys/stat.h> | |
20 | #include <ctype.h> | |
21 | ||
c801d85f | 22 | //----------------------------------------------------------------------------- |
2f2aa628 | 23 | // "changed" |
c801d85f KB |
24 | //----------------------------------------------------------------------------- |
25 | ||
6de97a3b | 26 | static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) |
484e45bf | 27 | { |
9406d962 | 28 | win->SetModified(); |
903f689b RR |
29 | |
30 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId ); | |
31 | wxString val( win->GetValue() ); | |
32 | if (!val.IsNull()) event.m_commandString = WXSTRINGCAST val; | |
33 | event.SetEventObject( win ); | |
34 | win->GetEventHandler()->ProcessEvent( event ); | |
6de97a3b | 35 | } |
112892b9 | 36 | |
2f2aa628 RR |
37 | //----------------------------------------------------------------------------- |
38 | // wxTextCtrl | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) | |
42 | ||
c801d85f | 43 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) |
903f689b | 44 | EVT_CHAR(wxTextCtrl::OnChar) |
c801d85f KB |
45 | END_EVENT_TABLE() |
46 | ||
03f38c58 | 47 | wxTextCtrl::wxTextCtrl() : streambuf() |
c801d85f | 48 | { |
6de97a3b | 49 | if (allocate()) setp(base(),ebuf()); |
13289f04 | 50 | |
112892b9 | 51 | m_modified = FALSE; |
6de97a3b | 52 | } |
c801d85f | 53 | |
debe6624 | 54 | wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value, |
484e45bf | 55 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 56 | int style, const wxValidator& validator, const wxString &name ) : streambuf() |
c801d85f | 57 | { |
6de97a3b | 58 | if (allocate()) setp(base(),ebuf()); |
13289f04 | 59 | |
112892b9 | 60 | m_modified = FALSE; |
6de97a3b RR |
61 | Create( parent, id, value, pos, size, style, validator, name ); |
62 | } | |
c801d85f | 63 | |
debe6624 | 64 | bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, |
484e45bf | 65 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 66 | int style, const wxValidator& validator, const wxString &name ) |
c801d85f KB |
67 | { |
68 | m_needParent = TRUE; | |
484e45bf | 69 | |
c801d85f | 70 | PreCreation( parent, id, pos, size, style, name ); |
484e45bf | 71 | |
6de97a3b RR |
72 | SetValidator( validator ); |
73 | ||
13289f04 | 74 | bool bMultiLine = (style & wxTE_MULTILINE) != 0; |
5796ed40 | 75 | if ( bMultiLine ) |
47908e25 | 76 | { |
13289f04 VZ |
77 | // a multi-line edit control: create a vertical scrollbar by default and |
78 | // horizontal if requested | |
79 | bool bHasHScrollbar = (style & wxHSCROLL) != 0; | |
80 | ||
81 | // create our control... | |
c67daf87 | 82 | m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); |
13289f04 VZ |
83 | |
84 | // ... and put into the upper left hand corner of the table | |
85 | m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE); | |
86 | gtk_table_attach(GTK_TABLE(m_widget), m_text, 0, 1, 0, 1, | |
87 | GTK_FILL | GTK_EXPAND, | |
88 | GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
89 | 0, 0); | |
90 | ||
91 | // put the horizontal scrollbar in the lower left hand corner | |
903f689b RR |
92 | if (bHasHScrollbar) |
93 | { | |
13289f04 VZ |
94 | GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); |
95 | gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2, | |
96 | GTK_EXPAND | GTK_FILL, | |
97 | GTK_FILL, | |
98 | 0, 0); | |
99 | gtk_widget_show(hscrollbar); | |
100 | } | |
101 | ||
102 | // finally, put the vertical scrollbar in the upper right corner | |
103 | GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_TEXT(m_text)->vadj); | |
104 | gtk_table_attach(GTK_TABLE(m_widget), vscrollbar, 1, 2, 0, 1, | |
105 | GTK_FILL, | |
106 | GTK_EXPAND | GTK_FILL | GTK_SHRINK, | |
107 | 0, 0); | |
903f689b | 108 | gtk_widget_show( vscrollbar ); |
13289f04 | 109 | } |
903f689b RR |
110 | else |
111 | { | |
13289f04 VZ |
112 | // a single-line text control: no need for scrollbars |
113 | m_widget = | |
114 | m_text = gtk_entry_new(); | |
115 | } | |
484e45bf | 116 | |
c801d85f KB |
117 | wxSize newSize = size; |
118 | if (newSize.x == -1) newSize.x = 80; | |
119 | if (newSize.y == -1) newSize.y = 26; | |
120 | SetSize( newSize.x, newSize.y ); | |
484e45bf | 121 | |
c801d85f | 122 | PostCreation(); |
484e45bf | 123 | |
903f689b RR |
124 | if (bMultiLine) |
125 | { | |
13289f04 VZ |
126 | gtk_widget_realize(m_text); |
127 | gtk_widget_show(m_text); | |
128 | } | |
129 | ||
484e45bf | 130 | // we want to be notified about text changes |
13289f04 | 131 | gtk_signal_connect(GTK_OBJECT(m_text), "changed", |
484e45bf VZ |
132 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), |
133 | (gpointer)this); | |
134 | ||
7f4dc78d RR |
135 | if (!value.IsNull()) |
136 | { | |
137 | gint tmp = 0; | |
13289f04 | 138 | gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp ); |
6de97a3b | 139 | } |
484e45bf | 140 | |
5796ed40 | 141 | if (style & wxTE_READONLY) |
112892b9 RR |
142 | { |
143 | } | |
144 | else | |
145 | { | |
903f689b | 146 | if (bMultiLine) |
13289f04 | 147 | gtk_text_set_editable( GTK_TEXT(m_text), 1 ); |
6de97a3b | 148 | } |
484e45bf | 149 | |
c801d85f | 150 | Show( TRUE ); |
484e45bf | 151 | |
f96aa4d9 RR |
152 | SetBackgroundColour( parent->GetBackgroundColour() ); |
153 | ||
c801d85f | 154 | return TRUE; |
6de97a3b | 155 | } |
c801d85f | 156 | |
03f38c58 | 157 | wxString wxTextCtrl::GetValue() const |
c801d85f | 158 | { |
a81258be RR |
159 | wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" ); |
160 | ||
c801d85f KB |
161 | wxString tmp; |
162 | if (m_windowStyle & wxTE_MULTILINE) | |
163 | { | |
13289f04 | 164 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
a81258be RR |
165 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); |
166 | tmp = text; | |
167 | g_free( text ); | |
c801d85f KB |
168 | } |
169 | else | |
170 | { | |
13289f04 | 171 | tmp = gtk_entry_get_text( GTK_ENTRY(m_text) ); |
6de97a3b | 172 | } |
c801d85f | 173 | return tmp; |
6de97a3b | 174 | } |
c801d85f KB |
175 | |
176 | void wxTextCtrl::SetValue( const wxString &value ) | |
177 | { | |
f96aa4d9 RR |
178 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
179 | ||
c801d85f KB |
180 | wxString tmp = ""; |
181 | if (!value.IsNull()) tmp = value; | |
182 | if (m_windowStyle & wxTE_MULTILINE) | |
183 | { | |
13289f04 VZ |
184 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
185 | gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len ); | |
c801d85f | 186 | len = 0; |
13289f04 | 187 | gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp, tmp.Length(), &len ); |
c801d85f KB |
188 | } |
189 | else | |
190 | { | |
13289f04 | 191 | gtk_entry_set_text( GTK_ENTRY(m_text), tmp ); |
6de97a3b RR |
192 | } |
193 | } | |
c801d85f KB |
194 | |
195 | void wxTextCtrl::WriteText( const wxString &text ) | |
196 | { | |
f96aa4d9 RR |
197 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
198 | ||
c801d85f | 199 | if (text.IsNull()) return; |
484e45bf | 200 | |
c801d85f KB |
201 | if (m_windowStyle & wxTE_MULTILINE) |
202 | { | |
13289f04 VZ |
203 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
204 | gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len ); | |
c801d85f KB |
205 | } |
206 | else | |
207 | { | |
13289f04 | 208 | gtk_entry_append_text( GTK_ENTRY(m_text), text ); |
6de97a3b RR |
209 | } |
210 | } | |
c801d85f | 211 | |
a81258be | 212 | bool wxTextCtrl::LoadFile( const wxString &file ) |
c801d85f | 213 | { |
a81258be RR |
214 | wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" ); |
215 | ||
216 | if (!wxFileExists(file)) return FALSE; | |
2ad3a34e | 217 | |
a81258be RR |
218 | Clear(); |
219 | ||
220 | FILE *fp = NULL; | |
221 | struct stat statb; | |
222 | ||
223 | if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || | |
224 | !(fp = fopen ((char*) (const char*) file, "r"))) | |
225 | { | |
226 | return FALSE; | |
227 | } | |
228 | else | |
229 | { | |
230 | gint len = statb.st_size; | |
231 | char *text; | |
232 | if (!(text = (char*)malloc ((unsigned) (len + 1)))) | |
233 | { | |
234 | fclose (fp); | |
235 | return FALSE; | |
236 | } | |
237 | if (fread (text, sizeof (char), len, fp) != (size_t) len) | |
238 | { | |
239 | } | |
240 | fclose (fp); | |
241 | ||
242 | text[len] = 0; | |
243 | ||
244 | if (m_windowStyle & wxTE_MULTILINE) | |
245 | { | |
246 | gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len ); | |
247 | } | |
248 | else | |
249 | { | |
250 | gtk_entry_set_text( GTK_ENTRY(m_text), text ); | |
251 | } | |
252 | ||
253 | free (text); | |
254 | m_modified = FALSE; | |
255 | return TRUE; | |
256 | } | |
112892b9 | 257 | return FALSE; |
6de97a3b | 258 | } |
c801d85f | 259 | |
a81258be | 260 | bool wxTextCtrl::SaveFile( const wxString &file ) |
c801d85f | 261 | { |
a81258be RR |
262 | wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" ); |
263 | ||
264 | if (file == "") return FALSE; | |
265 | ||
266 | FILE *fp; | |
2ad3a34e | 267 | |
a81258be RR |
268 | if (!(fp = fopen ((char*) (const char*) file, "w"))) |
269 | { | |
270 | return FALSE; | |
271 | } | |
272 | else | |
273 | { | |
274 | char *text = NULL; | |
275 | gint len = 0; | |
276 | ||
277 | if (m_windowStyle & wxTE_MULTILINE) | |
278 | { | |
279 | len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
280 | text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
281 | } | |
282 | else | |
283 | { | |
284 | text = gtk_entry_get_text( GTK_ENTRY(m_text) ); | |
285 | } | |
286 | ||
287 | if (fwrite (text, sizeof (char), len, fp) != (size_t) len) | |
288 | { | |
289 | // Did not write whole file | |
290 | } | |
291 | ||
292 | // Make sure newline terminates the file | |
293 | if (text[len - 1] != '\n') | |
294 | fputc ('\n', fp); | |
295 | ||
296 | fclose (fp); | |
297 | ||
298 | if (m_windowStyle & wxTE_MULTILINE) g_free( text ); | |
299 | ||
300 | m_modified = FALSE; | |
301 | return TRUE; | |
302 | } | |
303 | ||
304 | return TRUE; | |
6de97a3b | 305 | } |
c801d85f | 306 | |
debe6624 | 307 | wxString wxTextCtrl::GetLineText( long lineNo ) const |
c801d85f | 308 | { |
a81258be RR |
309 | if (m_windowStyle & wxTE_MULTILINE) |
310 | { | |
311 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
312 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
313 | ||
314 | if (text) | |
315 | { | |
316 | wxString buf(""); | |
317 | long i; | |
318 | int currentLine = 0; | |
319 | for (i = 0; currentLine != lineNo && text[i]; i++ ) | |
320 | if (text[i] == '\n') | |
321 | currentLine++; | |
322 | // Now get the text | |
323 | int j; | |
324 | for (j = 0; text[i] && text[i] != '\n'; i++, j++ ) | |
325 | buf += text[i]; | |
326 | ||
327 | g_free( text ); | |
328 | return buf; | |
329 | } | |
330 | else | |
331 | return wxEmptyString; | |
332 | } | |
333 | else | |
334 | { | |
335 | if (lineNo == 0) return GetValue(); | |
336 | return wxEmptyString; | |
337 | } | |
6de97a3b | 338 | } |
c801d85f | 339 | |
a81258be RR |
340 | void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) ) |
341 | { | |
342 | wxFAIL_MSG( "wxTextCtrl::GetLineText( lineNo ) not implemented" ); | |
343 | } | |
112892b9 | 344 | |
a81258be | 345 | long wxTextCtrl::PositionToXY( long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y) ) const |
c801d85f | 346 | { |
a81258be RR |
347 | wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); |
348 | ||
349 | return 0; | |
6de97a3b | 350 | } |
c801d85f | 351 | |
a81258be | 352 | long wxTextCtrl::XYToPosition( long WXUNUSED(x), long WXUNUSED(y) ) const |
c801d85f | 353 | { |
a81258be RR |
354 | wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); |
355 | ||
356 | return 0; | |
6de97a3b | 357 | } |
c801d85f | 358 | |
a81258be | 359 | int wxTextCtrl::GetLineLength(long lineNo) const |
c801d85f | 360 | { |
a81258be RR |
361 | wxString str = GetLineText (lineNo); |
362 | return (int) str.Length(); | |
6de97a3b | 363 | } |
c801d85f | 364 | |
a81258be | 365 | int wxTextCtrl::GetNumberOfLines() const |
c801d85f | 366 | { |
a81258be RR |
367 | if (m_windowStyle & wxTE_MULTILINE) |
368 | { | |
369 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
370 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
371 | ||
372 | if (text) | |
373 | { | |
374 | int currentLine = 0; | |
375 | for (int i = 0; i < len; i++ ) | |
376 | if (text[i] == '\n') | |
377 | currentLine++; | |
378 | ||
379 | g_free( text ); | |
380 | return currentLine; | |
381 | } | |
382 | else | |
383 | return 0; | |
384 | } | |
385 | else | |
386 | { | |
387 | return 1; | |
388 | } | |
6de97a3b | 389 | } |
c801d85f | 390 | |
debe6624 | 391 | void wxTextCtrl::SetInsertionPoint( long pos ) |
c801d85f | 392 | { |
a81258be RR |
393 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
394 | ||
c801d85f KB |
395 | int tmp = (int) pos; |
396 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 397 | gtk_text_set_point( GTK_TEXT(m_text), tmp ); |
c801d85f | 398 | else |
13289f04 | 399 | gtk_entry_set_position( GTK_ENTRY(m_text), tmp ); |
6de97a3b | 400 | } |
c801d85f | 401 | |
03f38c58 | 402 | void wxTextCtrl::SetInsertionPointEnd() |
c801d85f | 403 | { |
f96aa4d9 RR |
404 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
405 | ||
c801d85f KB |
406 | int pos = 0; |
407 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 408 | pos = gtk_text_get_length( GTK_TEXT(m_text) ); |
c801d85f | 409 | else |
13289f04 | 410 | pos = GTK_ENTRY(m_text)->text_length; |
c801d85f | 411 | SetInsertionPoint( pos-1 ); |
6de97a3b | 412 | } |
c801d85f | 413 | |
debe6624 | 414 | void wxTextCtrl::SetEditable( bool editable ) |
c801d85f | 415 | { |
f96aa4d9 RR |
416 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
417 | ||
c801d85f | 418 | if (m_windowStyle & wxTE_MULTILINE) |
13289f04 | 419 | gtk_text_set_editable( GTK_TEXT(m_text), editable ); |
c801d85f | 420 | else |
13289f04 | 421 | gtk_entry_set_editable( GTK_ENTRY(m_text), editable ); |
6de97a3b | 422 | } |
c801d85f | 423 | |
debe6624 | 424 | void wxTextCtrl::SetSelection( long from, long to ) |
c801d85f | 425 | { |
f96aa4d9 RR |
426 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
427 | ||
13289f04 | 428 | gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
6de97a3b | 429 | } |
c801d85f | 430 | |
debe6624 | 431 | void wxTextCtrl::ShowPosition( long WXUNUSED(pos) ) |
c801d85f | 432 | { |
f96aa4d9 | 433 | wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" ); |
6de97a3b | 434 | } |
c801d85f | 435 | |
03f38c58 | 436 | long wxTextCtrl::GetInsertionPoint() const |
c801d85f | 437 | { |
f96aa4d9 RR |
438 | wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" ); |
439 | ||
13289f04 | 440 | return (long) GTK_EDITABLE(m_text)->current_pos; |
6de97a3b | 441 | } |
c801d85f | 442 | |
03f38c58 | 443 | long wxTextCtrl::GetLastPosition() const |
c801d85f | 444 | { |
f96aa4d9 RR |
445 | wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" ); |
446 | ||
c801d85f KB |
447 | int pos = 0; |
448 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 449 | pos = gtk_text_get_length( GTK_TEXT(m_text) ); |
c801d85f | 450 | else |
13289f04 | 451 | pos = GTK_ENTRY(m_text)->text_length; |
c801d85f | 452 | return (long)pos-1; |
6de97a3b | 453 | } |
c801d85f | 454 | |
debe6624 | 455 | void wxTextCtrl::Remove( long from, long to ) |
c801d85f | 456 | { |
f96aa4d9 RR |
457 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
458 | ||
13289f04 | 459 | gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
6de97a3b | 460 | } |
c801d85f | 461 | |
debe6624 | 462 | void wxTextCtrl::Replace( long from, long to, const wxString &value ) |
c801d85f | 463 | { |
f96aa4d9 RR |
464 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
465 | ||
13289f04 | 466 | gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
c801d85f KB |
467 | if (value.IsNull()) return; |
468 | gint pos = (gint)to; | |
13289f04 | 469 | gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); |
6de97a3b | 470 | } |
c801d85f | 471 | |
03f38c58 | 472 | void wxTextCtrl::Cut() |
c801d85f | 473 | { |
f96aa4d9 RR |
474 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
475 | ||
75ed1d15 GL |
476 | #if (GTK_MINOR_VERSION == 1) |
477 | gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) ); | |
478 | #else | |
13289f04 | 479 | gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 480 | #endif |
6de97a3b | 481 | } |
c801d85f | 482 | |
03f38c58 | 483 | void wxTextCtrl::Copy() |
c801d85f | 484 | { |
f96aa4d9 RR |
485 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
486 | ||
75ed1d15 GL |
487 | #if (GTK_MINOR_VERSION == 1) |
488 | gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) ); | |
489 | #else | |
13289f04 | 490 | gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 491 | #endif |
6de97a3b | 492 | } |
c801d85f | 493 | |
03f38c58 | 494 | void wxTextCtrl::Paste() |
c801d85f | 495 | { |
f96aa4d9 RR |
496 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
497 | ||
75ed1d15 GL |
498 | #if (GTK_MINOR_VERSION == 1) |
499 | gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) ); | |
500 | #else | |
13289f04 | 501 | gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 502 | #endif |
6de97a3b | 503 | } |
c801d85f | 504 | |
03f38c58 | 505 | void wxTextCtrl::Clear() |
c801d85f KB |
506 | { |
507 | SetValue( "" ); | |
6de97a3b | 508 | } |
c801d85f | 509 | |
903f689b | 510 | void wxTextCtrl::OnChar( wxKeyEvent &key_event ) |
c801d85f | 511 | { |
903f689b RR |
512 | if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER)) |
513 | { | |
514 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
515 | event.SetEventObject(this); | |
903f689b RR |
516 | if (GetEventHandler()->ProcessEvent(event)) return; |
517 | } | |
518 | else if (key_event.KeyCode() == WXK_TAB) | |
519 | { | |
520 | wxNavigationKeyEvent event; | |
521 | event.SetDirection( key_event.m_shiftDown ); | |
522 | event.SetWindowChange(FALSE); | |
523 | event.SetEventObject(this); | |
524 | ||
525 | if (GetEventHandler()->ProcessEvent(event)) return; | |
526 | } | |
527 | key_event.Skip(); | |
6de97a3b | 528 | } |
c801d85f | 529 | |
46dc76ba | 530 | int wxTextCtrl::overflow( int WXUNUSED(c) ) |
c801d85f | 531 | { |
c801d85f KB |
532 | int len = pptr() - pbase(); |
533 | char *txt = new char[len+1]; | |
534 | strncpy(txt, pbase(), len); | |
535 | txt[len] = '\0'; | |
536 | (*this) << txt; | |
537 | setp(pbase(), epptr()); | |
538 | delete[] txt; | |
539 | return EOF; | |
6de97a3b | 540 | } |
c801d85f | 541 | |
03f38c58 | 542 | int wxTextCtrl::sync() |
c801d85f | 543 | { |
c801d85f KB |
544 | int len = pptr() - pbase(); |
545 | char *txt = new char[len+1]; | |
546 | strncpy(txt, pbase(), len); | |
547 | txt[len] = '\0'; | |
548 | (*this) << txt; | |
549 | setp(pbase(), epptr()); | |
550 | delete[] txt; | |
551 | return 0; | |
6de97a3b | 552 | } |
c801d85f | 553 | |
03f38c58 | 554 | int wxTextCtrl::underflow() |
c801d85f KB |
555 | { |
556 | return EOF; | |
6de97a3b | 557 | } |
c801d85f KB |
558 | |
559 | wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) | |
560 | { | |
561 | WriteText(s); | |
562 | return *this; | |
563 | } | |
564 | ||
debe6624 | 565 | wxTextCtrl& wxTextCtrl::operator<<(float f) |
c801d85f KB |
566 | { |
567 | static char buf[100]; | |
568 | sprintf(buf, "%.2f", f); | |
569 | WriteText(buf); | |
570 | return *this; | |
571 | } | |
572 | ||
debe6624 | 573 | wxTextCtrl& wxTextCtrl::operator<<(double d) |
c801d85f KB |
574 | { |
575 | static char buf[100]; | |
576 | sprintf(buf, "%.2f", d); | |
577 | WriteText(buf); | |
578 | return *this; | |
579 | } | |
580 | ||
debe6624 | 581 | wxTextCtrl& wxTextCtrl::operator<<(int i) |
c801d85f KB |
582 | { |
583 | static char buf[100]; | |
584 | sprintf(buf, "%i", i); | |
585 | WriteText(buf); | |
586 | return *this; | |
587 | } | |
588 | ||
debe6624 | 589 | wxTextCtrl& wxTextCtrl::operator<<(long i) |
c801d85f KB |
590 | { |
591 | static char buf[100]; | |
592 | sprintf(buf, "%ld", i); | |
593 | WriteText(buf); | |
594 | return *this; | |
595 | } | |
596 | ||
597 | wxTextCtrl& wxTextCtrl::operator<<(const char c) | |
598 | { | |
599 | char buf[2]; | |
600 | ||
601 | buf[0] = c; | |
602 | buf[1] = 0; | |
603 | WriteText(buf); | |
604 | return *this; | |
605 | } | |
606 | ||
03f38c58 | 607 | GtkWidget* wxTextCtrl::GetConnectWidget() |
e3e65dac RR |
608 | { |
609 | return GTK_WIDGET(m_text); | |
6de97a3b | 610 | } |
e3e65dac | 611 | |
903f689b RR |
612 | bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window ) |
613 | { | |
614 | if (m_windowStyle & wxTE_MULTILINE) | |
615 | return (window == GTK_TEXT(m_text)->text_area); | |
616 | else | |
617 | return (window == GTK_ENTRY(m_text)->text_area); | |
618 | } | |
e3e65dac | 619 | |
868a2826 RR |
620 | void wxTextCtrl::SetFont( const wxFont &font ) |
621 | { | |
f96aa4d9 RR |
622 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
623 | ||
a81258be | 624 | wxControl::SetFont( font ); |
868a2826 | 625 | |
a81258be | 626 | // doesn't work |
868a2826 | 627 | } |
e3e65dac | 628 | |
68dda785 VZ |
629 | void wxTextCtrl::SetBackgroundColour( const wxColour &colour ) |
630 | { | |
631 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); | |
a81258be RR |
632 | |
633 | wxControl::SetBackgroundColour( colour ); | |
634 | ||
f96aa4d9 | 635 | if (!m_backgroundColour.Ok()) return; |
fc54776e | 636 | |
f96aa4d9 RR |
637 | if (m_windowStyle & wxTE_MULTILINE) |
638 | { | |
639 | GdkWindow *window = GTK_TEXT(m_text)->text_area; | |
640 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); | |
641 | gdk_window_set_background( window, m_backgroundColour.GetColor() ); | |
642 | gdk_window_clear( window ); | |
643 | } | |
644 | else | |
645 | { | |
a81258be | 646 | gtk_widget_set_style( m_text, m_widgetStyle ); |
f96aa4d9 | 647 | } |
68dda785 | 648 | } |
f96aa4d9 | 649 |