]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/textctrl.cpp
1. wxTextControl::SetFont() does something (good or bad - for you to judge)
[wxWidgets.git] / src / gtk / textctrl.cpp
CommitLineData
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"
ae0bdb01
RR
16#include "wx/intl.h"
17#include "wx/settings.h"
c801d85f 18
a81258be
RR
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <ctype.h>
22
83624f79
RR
23#include "gdk/gdk.h"
24#include "gtk/gtk.h"
b292e2f5
RR
25#include "gdk/gdkkeysyms.h"
26
acfd422a
RR
27//-----------------------------------------------------------------------------
28// idle system
29//-----------------------------------------------------------------------------
30
31extern void wxapp_install_idle_handler();
32extern bool g_isIdle;
33
b292e2f5
RR
34//-----------------------------------------------------------------------------
35// data
36//-----------------------------------------------------------------------------
37
38extern bool g_blockEventsOnDrag;
39
c801d85f 40//-----------------------------------------------------------------------------
2f2aa628 41// "changed"
c801d85f
KB
42//-----------------------------------------------------------------------------
43
805dd538 44static void
2830bf19 45gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
484e45bf 46{
a2053b27 47 if (!win->m_hasVMT) return;
805dd538 48
bb69661b 49 if (g_isIdle)
3c679789
RR
50 wxapp_install_idle_handler();
51
034be888 52 win->SetModified();
8bbe427f 53
f03fc89f 54 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
8a85884a 55 event.SetString( win->GetValue() );
2830bf19
RR
56 event.SetEventObject( win );
57 win->GetEventHandler()->ProcessEvent( event );
6de97a3b 58}
112892b9 59
2830bf19 60//-----------------------------------------------------------------------------
034be888 61// "changed" from vertical scrollbar
2830bf19
RR
62//-----------------------------------------------------------------------------
63
805dd538 64static void
034be888 65gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
2830bf19 66{
3c679789 67 if (!win->m_hasVMT) return;
bb69661b
VZ
68
69 if (g_isIdle)
3c679789 70 wxapp_install_idle_handler();
acfd422a 71
2830bf19
RR
72 win->CalculateScrollbar();
73}
74
2f2aa628
RR
75//-----------------------------------------------------------------------------
76// wxTextCtrl
77//-----------------------------------------------------------------------------
78
79IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
80
c801d85f 81BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
2830bf19 82 EVT_CHAR(wxTextCtrl::OnChar)
e702ff0f
JS
83
84 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
85 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
86 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
87 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
88 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
89
90 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
91 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
92 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
93 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
94 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
c801d85f
KB
95END_EVENT_TABLE()
96
38830220 97#if wxUSE_STD_IOSTREAM
03f38c58 98wxTextCtrl::wxTextCtrl() : streambuf()
c801d85f 99{
2830bf19 100 if (allocate()) setp(base(),ebuf());
13289f04 101
2830bf19 102 m_modified = FALSE;
6de97a3b 103}
f5abe911
RR
104#else
105wxTextCtrl::wxTextCtrl()
106{
107 m_modified = FALSE;
108}
109#endif
c801d85f 110
38830220 111#if wxUSE_STD_IOSTREAM
debe6624 112wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
484e45bf 113 const wxPoint &pos, const wxSize &size,
6de97a3b 114 int style, const wxValidator& validator, const wxString &name ) : streambuf()
c801d85f 115{
2830bf19 116 if (allocate()) setp(base(),ebuf());
13289f04 117
2830bf19
RR
118 m_modified = FALSE;
119 Create( parent, id, value, pos, size, style, validator, name );
6de97a3b 120}
f5abe911
RR
121#else
122wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
123 const wxPoint &pos, const wxSize &size,
124 int style, const wxValidator& validator, const wxString &name )
125{
126 m_modified = FALSE;
127 Create( parent, id, value, pos, size, style, validator, name );
128}
129#endif
c801d85f 130
debe6624 131bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
484e45bf 132 const wxPoint &pos, const wxSize &size,
6de97a3b 133 int style, const wxValidator& validator, const wxString &name )
c801d85f 134{
2830bf19 135 m_needParent = TRUE;
b292e2f5 136 m_acceptsFocus = TRUE;
484e45bf 137
2830bf19 138 PreCreation( parent, id, pos, size, style, name );
6de97a3b 139
88ac883a 140#if wxUSE_VALIDATORS
2830bf19 141 SetValidator( validator );
88ac883a 142#endif // wxUSE_VALIDATORS
805dd538 143
034be888 144 m_vScrollbarVisible = FALSE;
13289f04 145
2830bf19 146 bool multi_line = (style & wxTE_MULTILINE) != 0;
ab46dc18 147 if (multi_line)
2830bf19 148 {
034be888
RR
149 /* a multi-line edit control: create a vertical scrollbar by default and
150 horizontal if requested */
2830bf19 151 bool bHasHScrollbar = (style & wxHSCROLL) != 0;
805dd538 152
034be888 153 /* create our control ... */
2830bf19
RR
154 m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
155
034be888 156 /* ... and put into the upper left hand corner of the table */
2830bf19 157 m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE);
5664fc32 158 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
2830bf19 159 gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1,
41dee9d0 160 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
f5368809
RR
161 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
162 0, 0);
bb69661b 163
5c387335
RR
164 /* always wrap words */
165 gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
bb69661b 166
034be888 167 /* put the horizontal scrollbar in the lower left hand corner */
2830bf19
RR
168 if (bHasHScrollbar)
169 {
170 GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
5664fc32 171 GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
2830bf19 172 gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2,
8ce63e9d 173 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
13289f04
VZ
174 GTK_FILL,
175 0, 0);
2830bf19 176 gtk_widget_show(hscrollbar);
13289f04 177
5c387335 178#if (GTK_MINOR_VERSION > 0)
3358d36e
VZ
179 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
180 gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE );
5c387335
RR
181#endif
182 }
bb69661b 183
ab46dc18
RR
184 /* finally, put the vertical scrollbar in the upper right corner */
185 m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
186 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
ab46dc18
RR
187 gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1,
188 GTK_FILL,
189 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
190 0, 0);
2830bf19
RR
191 }
192 else
193 {
034be888 194 /* a single-line text control: no need for scrollbars */
2830bf19
RR
195 m_widget =
196 m_text = gtk_entry_new();
197 }
484e45bf 198
2830bf19
RR
199 wxSize newSize = size;
200 if (newSize.x == -1) newSize.x = 80;
201 if (newSize.y == -1) newSize.y = 26;
202 SetSize( newSize.x, newSize.y );
484e45bf 203
f03fc89f 204 m_parent->DoAddChild( this );
8bbe427f 205
2830bf19 206 PostCreation();
484e45bf 207
2830bf19 208 if (multi_line)
2830bf19 209 gtk_widget_show(m_text);
13289f04 210
034be888 211 /* we want to be notified about text changes */
b292e2f5
RR
212 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
213 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
484e45bf 214
ab46dc18
RR
215 if (multi_line)
216 {
217 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
218 (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
219 }
3358d36e 220
291a8f20 221 if (!value.IsEmpty())
2830bf19
RR
222 {
223 gint tmp = 0;
3358d36e
VZ
224
225#if GTK_MINOR_VERSION == 0
226 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
227 // gtk_editable_insert_text()
228 gtk_widget_realize(m_text);
229#endif // GTK 1.0
230
05939a81 231#if wxUSE_UNICODE
3358d36e 232 wxWX2MBbuf val = value.mbc_str();
05939a81 233 gtk_editable_insert_text( GTK_EDITABLE(m_text), val, strlen(val), &tmp );
3358d36e 234#else // !Unicode
2830bf19 235 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp );
3358d36e
VZ
236#endif // Unicode/!Unicode
237
291a8f20
RR
238 if (multi_line)
239 {
3358d36e
VZ
240 /* bring editable's cursor uptodate. bug in GTK. */
241
242 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
243 }
2830bf19 244 }
484e45bf 245
2830bf19
RR
246 if (style & wxTE_PASSWORD)
247 {
248 if (!multi_line)
249 gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
250 }
8bbe427f 251
2830bf19
RR
252 if (style & wxTE_READONLY)
253 {
254 if (!multi_line)
255 gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE );
256 }
257 else
258 {
259 if (multi_line)
260 gtk_text_set_editable( GTK_TEXT(m_text), 1 );
261 }
3358d36e 262
012a03e0 263 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) );
034be888 264 SetForegroundColour( parent->GetForegroundColour() );
805dd538 265
2830bf19 266 Show( TRUE );
805dd538 267
2830bf19
RR
268 return TRUE;
269}
484e45bf 270
2830bf19
RR
271void wxTextCtrl::CalculateScrollbar()
272{
273 if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
f96aa4d9 274
2830bf19 275 GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
805dd538 276
2830bf19
RR
277 if (adj->upper - adj->page_size < 0.8)
278 {
279 if (m_vScrollbarVisible)
280 {
034be888 281 gtk_widget_hide( m_vScrollbar );
034be888 282 m_vScrollbarVisible = FALSE;
2830bf19
RR
283 }
284 }
285 else
286 {
287 if (!m_vScrollbarVisible)
288 {
034be888 289 gtk_widget_show( m_vScrollbar );
034be888 290 m_vScrollbarVisible = TRUE;
2830bf19
RR
291 }
292 }
6de97a3b 293}
c801d85f 294
03f38c58 295wxString wxTextCtrl::GetValue() const
c801d85f 296{
05939a81 297 wxCHECK_MSG( m_text != NULL, _T(""), _T("invalid text ctrl") );
8bbe427f 298
2830bf19
RR
299 wxString tmp;
300 if (m_windowStyle & wxTE_MULTILINE)
301 {
302 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
303 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
dcf924a3 304 tmp = wxString(text,*wxConvCurrent);
2830bf19
RR
305 g_free( text );
306 }
307 else
308 {
dcf924a3 309 tmp = wxString(gtk_entry_get_text( GTK_ENTRY(m_text) ),*wxConvCurrent);
2830bf19
RR
310 }
311 return tmp;
6de97a3b 312}
c801d85f
KB
313
314void wxTextCtrl::SetValue( const wxString &value )
315{
05939a81 316 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 317
cfb50f14
RR
318 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
319 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 320
05939a81 321 wxString tmp = _T("");
2830bf19
RR
322 if (!value.IsNull()) tmp = value;
323 if (m_windowStyle & wxTE_MULTILINE)
324 {
325 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
326 gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
327 len = 0;
05939a81 328#if wxUSE_UNICODE
3358d36e 329 wxWX2MBbuf tmpbuf = tmp.mbc_str();
05939a81
OK
330 gtk_editable_insert_text( GTK_EDITABLE(m_text), tmpbuf, strlen(tmpbuf), &len );
331#else
332 gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp.mbc_str(), tmp.Length(), &len );
333#endif
2830bf19
RR
334 }
335 else
336 {
05939a81 337 gtk_entry_set_text( GTK_ENTRY(m_text), tmp.mbc_str() );
2830bf19 338 }
bb69661b 339
cfb50f14
RR
340 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
341 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 342}
c801d85f
KB
343
344void wxTextCtrl::WriteText( const wxString &text )
345{
05939a81 346 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 347
2df7be7f 348 if (text.IsEmpty()) return;
484e45bf 349
2df7be7f
RR
350 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
351 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 352
2830bf19
RR
353 if (m_windowStyle & wxTE_MULTILINE)
354 {
291a8f20 355 /* this moves the cursor pos to behind the inserted text */
3358d36e
VZ
356 gint len = GTK_EDITABLE(m_text)->current_pos;
357
05939a81 358#if wxUSE_UNICODE
3358d36e 359 wxWX2MBbuf buf = text.mbc_str();
05939a81
OK
360 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
361#else
2830bf19 362 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
05939a81 363#endif
3358d36e
VZ
364
365 /* bring editable's cursor uptodate. bug in GTK. */
366 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
2830bf19
RR
367 }
368 else
369 {
c46554be 370 /* this moves the cursor pos to behind the inserted text */
3358d36e 371 gint len = GTK_EDITABLE(m_text)->current_pos;
05939a81 372#if wxUSE_UNICODE
3358d36e 373 wxWX2MBbuf buf = text.mbc_str();
05939a81
OK
374 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
375#else
c46554be 376 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
05939a81 377#endif
3358d36e
VZ
378
379 /* bring editable's cursor uptodate. bug in GTK. */
380 GTK_EDITABLE(m_text)->current_pos += text.Len();
381
382 /* bring entry's cursor uptodate. bug in GTK. */
383 gtk_entry_set_position( GTK_ENTRY(m_text), GTK_EDITABLE(m_text)->current_pos );
2830bf19 384 }
bb69661b 385
2df7be7f
RR
386 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
387 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 388}
c801d85f 389
a6e21573
HH
390void wxTextCtrl::AppendText( const wxString &text )
391{
05939a81 392 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
a6e21573 393
2df7be7f
RR
394 if (text.IsEmpty()) return;
395
396 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
397 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 398
a6e21573
HH
399 if (m_windowStyle & wxTE_MULTILINE)
400 {
bb69661b
VZ
401 bool hasSpecialAttributes = m_font.Ok() ||
402 m_foregroundColour.Ok() ||
403 m_backgroundColour.Ok();
404 if ( hasSpecialAttributes )
405 {
406 gtk_text_insert( GTK_TEXT(m_text),
407 m_font.GetInternalFont(),
408 m_foregroundColour.GetColor(),
409 m_backgroundColour.GetColor(),
410 text, text.length());
411
412 }
413 else
414 {
415 /* we'll insert at the last position */
416 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
05939a81 417#if wxUSE_UNICODE
bb69661b
VZ
418 wxWX2MBbuf buf = text.mbc_str();
419 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
05939a81 420#else
bb69661b 421 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
05939a81 422#endif
bb69661b 423 }
3358d36e
VZ
424
425 /* bring editable's cursor uptodate. bug in GTK. */
426 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
a6e21573
HH
427 }
428 else
429 {
05939a81 430 gtk_entry_append_text( GTK_ENTRY(m_text), text.mbc_str() );
a6e21573 431 }
bb69661b 432
2df7be7f
RR
433 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
434 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
a6e21573
HH
435}
436
a81258be 437bool wxTextCtrl::LoadFile( const wxString &file )
c801d85f 438{
2df7be7f 439 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
8bbe427f 440
2df7be7f 441 if (!wxFileExists(file)) return FALSE;
2ad3a34e 442
2df7be7f 443 Clear();
a81258be 444
2df7be7f
RR
445 FILE *fp = (FILE*) NULL;
446 struct stat statb;
8bbe427f 447
2df7be7f
RR
448 if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
449 !(fp = fopen (FNSTRINGCAST file.fn_str(), "r")))
a81258be 450 {
2df7be7f 451 return FALSE;
a81258be 452 }
2df7be7f 453 else
805dd538 454 {
2df7be7f
RR
455 gint len = statb.st_size;
456 char *text;
457 if (!(text = (char*)malloc ((unsigned) (len + 1))))
458 {
459 fclose (fp);
460 return FALSE;
461 }
462 if (fread (text, sizeof (char), len, fp) != (size_t) len)
463 {
464 }
465 fclose (fp);
a81258be 466
2df7be7f 467 text[len] = 0;
8bbe427f 468
2df7be7f
RR
469 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
470 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 471
2df7be7f
RR
472 if (m_windowStyle & wxTE_MULTILINE)
473 {
474 gint pos = 0;
475 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos );
476 }
477 else
478 {
479 gtk_entry_set_text( GTK_ENTRY(m_text), text );
480 }
bb69661b 481
2df7be7f
RR
482 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
483 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 484
2df7be7f
RR
485 free (text);
486 m_modified = FALSE;
487 return TRUE;
a81258be 488 }
2df7be7f 489 return FALSE;
6de97a3b 490}
c801d85f 491
a81258be 492bool wxTextCtrl::SaveFile( const wxString &file )
c801d85f 493{
2df7be7f 494 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
8bbe427f 495
2df7be7f 496 if (file == _T("")) return FALSE;
8bbe427f 497
2df7be7f 498 FILE *fp;
2ad3a34e 499
2df7be7f 500 if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w")))
a81258be 501 {
2df7be7f 502 return FALSE;
a81258be 503 }
2df7be7f 504 else
a81258be 505 {
bbe0af5b 506 char *text = (char*) NULL;
a81258be 507 gint len = 0;
8bbe427f 508
a81258be
RR
509 if (m_windowStyle & wxTE_MULTILINE)
510 {
2df7be7f
RR
511 len = gtk_text_get_length( GTK_TEXT(m_text) );
512 text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
a81258be
RR
513 }
514 else
515 {
2df7be7f 516 text = gtk_entry_get_text( GTK_ENTRY(m_text) );
a81258be 517 }
8bbe427f 518
a81258be 519 if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
96385642
VZ
520 {
521 // Did not write whole file
522 }
8bbe427f 523
a81258be
RR
524 // Make sure newline terminates the file
525 if (text[len - 1] != '\n')
96385642 526 fputc ('\n', fp);
a81258be
RR
527
528 fclose (fp);
8bbe427f 529
a81258be 530 if (m_windowStyle & wxTE_MULTILINE) g_free( text );
8bbe427f 531
a81258be
RR
532 m_modified = FALSE;
533 return TRUE;
534 }
535
2df7be7f 536 return TRUE;
6de97a3b 537}
c801d85f 538
debe6624 539wxString wxTextCtrl::GetLineText( long lineNo ) const
c801d85f 540{
a81258be
RR
541 if (m_windowStyle & wxTE_MULTILINE)
542 {
543 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
544 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
545
546 if (text)
547 {
05939a81 548 wxString buf(_T(""));
a81258be
RR
549 long i;
550 int currentLine = 0;
551 for (i = 0; currentLine != lineNo && text[i]; i++ )
552 if (text[i] == '\n')
553 currentLine++;
554 // Now get the text
555 int j;
556 for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
557 buf += text[i];
8bbe427f 558
a81258be
RR
559 g_free( text );
560 return buf;
561 }
562 else
563 return wxEmptyString;
564 }
565 else
566 {
567 if (lineNo == 0) return GetValue();
568 return wxEmptyString;
569 }
6de97a3b 570}
c801d85f 571
a81258be
RR
572void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
573{
ac0d36b5
HH
574 /* If you implement this, don't forget to update the documentation!
575 * (file docs/latex/wx/text.tex) */
05939a81 576 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
a81258be 577}
112892b9 578
e3ca08dd 579long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
c801d85f 580{
96385642 581 if ( m_windowStyle & wxTE_MULTILINE )
805dd538 582 {
96385642
VZ
583 wxString text = GetValue();
584
6085b116 585 // cast to prevent warning. But pos really should've been unsigned.
2829d9e3 586 if( (unsigned long)pos > text.Len() )
96385642
VZ
587 return FALSE;
588
ac0d36b5
HH
589 *x=0; // First Col
590 *y=0; // First Line
2829d9e3 591
05939a81
OK
592 const wxChar* stop = text.c_str() + pos;
593 for ( const wxChar *p = text.c_str(); p < stop; p++ )
96385642 594 {
05939a81 595 if (*p == _T('\n'))
96385642
VZ
596 {
597 (*y)++;
ac0d36b5 598 *x=0;
96385642
VZ
599 }
600 else
601 (*x)++;
602 }
805dd538 603 }
96385642
VZ
604 else // single line control
605 {
2829d9e3 606 if ( pos <= GTK_ENTRY(m_text)->text_length )
96385642 607 {
ac0d36b5 608 *y = 0;
96385642
VZ
609 *x = pos;
610 }
611 else
612 {
613 // index out of bounds
614 return FALSE;
615 }
8bbe427f 616 }
96385642
VZ
617
618 return TRUE;
6de97a3b 619}
c801d85f 620
e3ca08dd 621long wxTextCtrl::XYToPosition(long x, long y ) const
c801d85f 622{
2830bf19 623 if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
805dd538 624
2830bf19 625 long pos=0;
ac0d36b5 626 for( int i=0; i<y; i++ ) pos += GetLineLength(i) + 1; // one for '\n'
8bbe427f 627
3358d36e 628 pos += x;
2830bf19 629 return pos;
6de97a3b 630}
c801d85f 631
a81258be 632int wxTextCtrl::GetLineLength(long lineNo) const
c801d85f 633{
a81258be
RR
634 wxString str = GetLineText (lineNo);
635 return (int) str.Length();
6de97a3b 636}
c801d85f 637
a81258be 638int wxTextCtrl::GetNumberOfLines() const
c801d85f 639{
2830bf19 640 if (m_windowStyle & wxTE_MULTILINE)
a81258be 641 {
2830bf19
RR
642 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
643 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
644
645 if (text)
646 {
647 int currentLine = 0;
648 for (int i = 0; i < len; i++ )
96385642 649 {
2830bf19 650 if (text[i] == '\n')
96385642
VZ
651 currentLine++;
652 }
2830bf19 653 g_free( text );
2829d9e3
VZ
654
655 // currentLine is 0 based, add 1 to get number of lines
656 return currentLine + 1;
2830bf19
RR
657 }
658 else
96385642 659 {
2830bf19 660 return 0;
96385642 661 }
a81258be
RR
662 }
663 else
2830bf19 664 {
96385642 665 return 1;
2830bf19 666 }
6de97a3b 667}
c801d85f 668
debe6624 669void wxTextCtrl::SetInsertionPoint( long pos )
c801d85f 670{
05939a81 671 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
3358d36e
VZ
672
673 if (m_windowStyle & wxTE_MULTILINE)
291a8f20
RR
674 {
675 /* seems to be broken in GTK 1.0.X:
3358d36e
VZ
676 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
677
291a8f20
RR
678 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
679 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
3358d36e 680
291a8f20 681 /* we fake a set_point by inserting and deleting. as the user
3358d36e
VZ
682 isn't supposed to get to know about thos non-sense, we
683 disconnect so that no events are sent to the user program. */
684
291a8f20
RR
685 gint tmp = (gint)pos;
686 gtk_editable_insert_text( GTK_EDITABLE(m_text), " ", 1, &tmp );
3358d36e
VZ
687 gtk_editable_delete_text( GTK_EDITABLE(m_text), tmp-1, tmp );
688
291a8f20
RR
689 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
690 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
3358d36e
VZ
691
692 /* bring editable's cursor uptodate. another bug in GTK. */
693
694 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
ac0d36b5 695 }
2830bf19 696 else
291a8f20 697 {
d59051dd 698 gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos );
3358d36e
VZ
699
700 /* bring editable's cursor uptodate. bug in GTK. */
701
702 GTK_EDITABLE(m_text)->current_pos = pos;
291a8f20 703 }
6de97a3b 704}
c801d85f 705
03f38c58 706void wxTextCtrl::SetInsertionPointEnd()
c801d85f 707{
05939a81 708 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 709
d59051dd
VZ
710 if (m_windowStyle & wxTE_MULTILINE)
711 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text)));
712 else
713 gtk_entry_set_position( GTK_ENTRY(m_text), -1 );
6de97a3b 714}
c801d85f 715
debe6624 716void wxTextCtrl::SetEditable( bool editable )
c801d85f 717{
05939a81 718 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 719
2830bf19
RR
720 if (m_windowStyle & wxTE_MULTILINE)
721 gtk_text_set_editable( GTK_TEXT(m_text), editable );
722 else
723 gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
6de97a3b 724}
c801d85f 725
debe6624 726void wxTextCtrl::SetSelection( long from, long to )
c801d85f 727{
05939a81 728 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 729
2830bf19 730 gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
6de97a3b 731}
c801d85f 732
910f1f8c 733void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
c801d85f 734{
910f1f8c 735// SetInsertionPoint( pos );
6de97a3b 736}
c801d85f 737
03f38c58 738long wxTextCtrl::GetInsertionPoint() const
c801d85f 739{
05939a81 740 wxCHECK_MSG( m_text != NULL, 0, _T("invalid text ctrl") );
8bbe427f 741
2830bf19 742 return (long) GTK_EDITABLE(m_text)->current_pos;
6de97a3b 743}
c801d85f 744
03f38c58 745long wxTextCtrl::GetLastPosition() const
c801d85f 746{
05939a81 747 wxCHECK_MSG( m_text != NULL, 0, _T("invalid text ctrl") );
8bbe427f 748
2830bf19
RR
749 int pos = 0;
750 if (m_windowStyle & wxTE_MULTILINE)
751 pos = gtk_text_get_length( GTK_TEXT(m_text) );
752 else
753 pos = GTK_ENTRY(m_text)->text_length;
805dd538 754
ac0d36b5 755 return (long)pos;
6de97a3b 756}
c801d85f 757
debe6624 758void wxTextCtrl::Remove( long from, long to )
c801d85f 759{
05939a81 760 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 761
2df7be7f
RR
762 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
763 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 764
2830bf19 765 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
bb69661b 766
2df7be7f
RR
767 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
768 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 769}
c801d85f 770
debe6624 771void wxTextCtrl::Replace( long from, long to, const wxString &value )
c801d85f 772{
05939a81 773 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 774
2df7be7f
RR
775 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
776 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 777
2830bf19 778 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
bb69661b 779
2df7be7f
RR
780 if (!value.IsEmpty())
781 {
782 gint pos = (gint)from;
05939a81 783#if wxUSE_UNICODE
2df7be7f
RR
784 wxWX2MBbuf buf = value.mbc_str();
785 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos );
05939a81 786#else
2df7be7f 787 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
05939a81 788#endif
2df7be7f 789 }
bb69661b 790
2df7be7f
RR
791 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
792 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 793}
c801d85f 794
03f38c58 795void wxTextCtrl::Cut()
c801d85f 796{
05939a81 797 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 798
2df7be7f
RR
799 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
800 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 801
d345e841 802#if (GTK_MINOR_VERSION > 0)
2830bf19 803 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
75ed1d15 804#else
2830bf19 805 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 806#endif
bb69661b 807
2df7be7f
RR
808 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
809 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 810}
c801d85f 811
03f38c58 812void wxTextCtrl::Copy()
c801d85f 813{
05939a81 814 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 815
d345e841 816#if (GTK_MINOR_VERSION > 0)
2830bf19 817 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
75ed1d15 818#else
2830bf19 819 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 820#endif
6de97a3b 821}
c801d85f 822
03f38c58 823void wxTextCtrl::Paste()
c801d85f 824{
05939a81 825 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
8bbe427f 826
2df7be7f
RR
827 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
828 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
bb69661b 829
d345e841 830#if (GTK_MINOR_VERSION > 0)
2830bf19 831 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
75ed1d15 832#else
2830bf19 833 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 834#endif
bb69661b 835
2df7be7f
RR
836 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
837 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
6de97a3b 838}
c801d85f 839
ca8b28f2
JS
840bool wxTextCtrl::CanCopy() const
841{
842 // Can copy if there's a selection
843 long from, to;
844 GetSelection(& from, & to);
845 return (from != to) ;
846}
847
848bool wxTextCtrl::CanCut() const
849{
850 // Can cut if there's a selection
851 long from, to;
852 GetSelection(& from, & to);
853 return (from != to) ;
854}
855
856bool wxTextCtrl::CanPaste() const
857{
858 return IsEditable() ;
859}
860
861// Undo/redo
862void wxTextCtrl::Undo()
863{
864 // TODO
05939a81 865 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
ca8b28f2
JS
866}
867
868void wxTextCtrl::Redo()
869{
870 // TODO
05939a81 871 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
ca8b28f2
JS
872}
873
874bool wxTextCtrl::CanUndo() const
875{
876 // TODO
05939a81 877 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
ca8b28f2
JS
878 return FALSE;
879}
880
881bool wxTextCtrl::CanRedo() const
882{
883 // TODO
05939a81 884 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
ca8b28f2
JS
885 return FALSE;
886}
887
888// If the return values from and to are the same, there is no
889// selection.
890void wxTextCtrl::GetSelection(long* from, long* to) const
891{
05060eeb 892 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
bb69661b 893
05060eeb
RR
894 if (!(GTK_EDITABLE(m_text)->has_selection))
895 {
896 if (from) *from = 0;
bb69661b
VZ
897 if (to) *to = 0;
898 return;
05060eeb 899 }
bb69661b 900
05060eeb
RR
901 if (from) *from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
902 if (to) *to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
ca8b28f2
JS
903}
904
905bool wxTextCtrl::IsEditable() const
906{
05060eeb
RR
907 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
908
909 return GTK_EDITABLE(m_text)->editable;
ca8b28f2
JS
910}
911
03f38c58 912void wxTextCtrl::Clear()
c801d85f 913{
05939a81 914 SetValue( _T("") );
6de97a3b 915}
c801d85f 916
903f689b 917void wxTextCtrl::OnChar( wxKeyEvent &key_event )
c801d85f 918{
05939a81 919 wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
805dd538 920
2830bf19
RR
921 if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
922 {
923 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
924 event.SetEventObject(this);
925 if (GetEventHandler()->ProcessEvent(event)) return;
926 }
903f689b 927
2830bf19 928 key_event.Skip();
6de97a3b 929}
c801d85f 930
38830220 931#if wxUSE_STD_IOSTREAM
46dc76ba 932int wxTextCtrl::overflow( int WXUNUSED(c) )
c801d85f 933{
2830bf19
RR
934 int len = pptr() - pbase();
935 char *txt = new char[len+1];
936 strncpy(txt, pbase(), len);
937 txt[len] = '\0';
938 (*this) << txt;
939 setp(pbase(), epptr());
940 delete[] txt;
941 return EOF;
6de97a3b 942}
c801d85f 943
03f38c58 944int wxTextCtrl::sync()
c801d85f 945{
2830bf19
RR
946 int len = pptr() - pbase();
947 char *txt = new char[len+1];
948 strncpy(txt, pbase(), len);
949 txt[len] = '\0';
950 (*this) << txt;
951 setp(pbase(), epptr());
952 delete[] txt;
953 return 0;
6de97a3b 954}
c801d85f 955
03f38c58 956int wxTextCtrl::underflow()
c801d85f 957{
2830bf19 958 return EOF;
6de97a3b 959}
38830220 960#endif
c801d85f
KB
961
962wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
963{
a6e21573 964 AppendText(s);
2830bf19 965 return *this;
c801d85f
KB
966}
967
debe6624 968wxTextCtrl& wxTextCtrl::operator<<(float f)
c801d85f 969{
2830bf19
RR
970 static char buf[100];
971 sprintf(buf, "%.2f", f);
a6e21573 972 AppendText(buf);
2830bf19 973 return *this;
c801d85f
KB
974}
975
debe6624 976wxTextCtrl& wxTextCtrl::operator<<(double d)
c801d85f 977{
2830bf19
RR
978 static char buf[100];
979 sprintf(buf, "%.2f", d);
a6e21573 980 AppendText(buf);
2830bf19 981 return *this;
c801d85f
KB
982}
983
debe6624 984wxTextCtrl& wxTextCtrl::operator<<(int i)
c801d85f 985{
2830bf19
RR
986 static char buf[100];
987 sprintf(buf, "%i", i);
a6e21573 988 AppendText(buf);
2830bf19 989 return *this;
c801d85f
KB
990}
991
debe6624 992wxTextCtrl& wxTextCtrl::operator<<(long i)
c801d85f 993{
2830bf19
RR
994 static char buf[100];
995 sprintf(buf, "%ld", i);
a6e21573 996 AppendText(buf);
2830bf19 997 return *this;
c801d85f
KB
998}
999
1000wxTextCtrl& wxTextCtrl::operator<<(const char c)
1001{
2830bf19 1002 char buf[2];
c801d85f 1003
2830bf19
RR
1004 buf[0] = c;
1005 buf[1] = 0;
a6e21573 1006 AppendText(buf);
2830bf19 1007 return *this;
c801d85f
KB
1008}
1009
03f38c58 1010GtkWidget* wxTextCtrl::GetConnectWidget()
e3e65dac 1011{
ae0bdb01 1012 return GTK_WIDGET(m_text);
6de97a3b 1013}
e3e65dac 1014
903f689b
RR
1015bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
1016{
ae0bdb01
RR
1017 if (m_windowStyle & wxTE_MULTILINE)
1018 return (window == GTK_TEXT(m_text)->text_area);
1019 else
1020 return (window == GTK_ENTRY(m_text)->text_area);
903f689b 1021}
e3e65dac 1022
bb69661b
VZ
1023// the font will change for subsequent text insertiongs
1024bool wxTextCtrl::SetFont( const wxFont &font )
868a2826 1025{
f03fc89f 1026 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
8bbe427f 1027
bb69661b
VZ
1028 if ( !wxWindowBase::SetFont(font) )
1029 {
1030 // font didn't change, nothing to do
1031 return FALSE;
1032 }
1033
1034 if ( m_windowStyle & wxTE_MULTILINE )
1035 {
1036 // for compatibility with other ports: the font is a global controls
1037 // characteristic, so change the font globally
1038 wxString value = GetValue();
1039 if ( !value.IsEmpty() )
1040 {
1041 Clear();
1042
1043 AppendText(value);
1044 }
1045 }
1046
1047 return TRUE;
58614078
RR
1048}
1049
f03fc89f 1050bool wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
58614078 1051{
f03fc89f 1052 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
8bbe427f 1053
ae0bdb01 1054 // doesn't work
f03fc89f 1055 return FALSE;
868a2826 1056}
e3e65dac 1057
f03fc89f 1058bool wxTextCtrl::SetBackgroundColour( const wxColour &colour )
68dda785 1059{
f03fc89f 1060 wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
a81258be 1061
ae0bdb01 1062 wxControl::SetBackgroundColour( colour );
3358d36e 1063
f03fc89f
VZ
1064 if (!m_widget->window)
1065 return FALSE;
8bbe427f 1066
ae0bdb01 1067 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
805dd538
VZ
1068 if (sysbg.Red() == colour.Red() &&
1069 sysbg.Green() == colour.Green() &&
ae0bdb01
RR
1070 sysbg.Blue() == colour.Blue())
1071 {
f03fc89f 1072 return FALSE; // FIXME or TRUE?
805dd538
VZ
1073 }
1074
f03fc89f
VZ
1075 if (!m_backgroundColour.Ok())
1076 return FALSE;
8bbe427f 1077
ae0bdb01
RR
1078 if (m_windowStyle & wxTE_MULTILINE)
1079 {
1080 GdkWindow *window = GTK_TEXT(m_text)->text_area;
f03fc89f
VZ
1081 if (!window)
1082 return FALSE;
ae0bdb01
RR
1083 m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
1084 gdk_window_set_background( window, m_backgroundColour.GetColor() );
1085 gdk_window_clear( window );
1086 }
f03fc89f
VZ
1087
1088 return TRUE;
58614078
RR
1089}
1090
1091void wxTextCtrl::ApplyWidgetStyle()
1092{
ae0bdb01
RR
1093 if (m_windowStyle & wxTE_MULTILINE)
1094 {
2830bf19 1095 // how ?
805dd538 1096 }
ae0bdb01
RR
1097 else
1098 {
1099 SetWidgetStyle();
1100 gtk_widget_set_style( m_text, m_widgetStyle );
1101 }
68dda785 1102}
f96aa4d9 1103
e702ff0f
JS
1104void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
1105{
1106 Cut();
1107}
1108
1109void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
1110{
1111 Copy();
1112}
1113
1114void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
1115{
1116 Paste();
1117}
1118
1119void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
1120{
1121 Undo();
1122}
1123
1124void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
1125{
1126 Redo();
1127}
1128
1129void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1130{
1131 event.Enable( CanCut() );
1132}
1133
1134void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1135{
1136 event.Enable( CanCopy() );
1137}
1138
1139void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1140{
1141 event.Enable( CanPaste() );
1142}
1143
1144void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1145{
1146 event.Enable( CanUndo() );
1147}
1148
1149void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1150{
1151 event.Enable( CanRedo() );
1152}