]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/textctrl.cpp
correct a bug in the MSW code using wxMask
[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"
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 26static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
484e45bf 27{
9406d962 28 win->SetModified();
8bbe427f 29
903f689b
RR
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
41IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
42
c801d85f 43BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
903f689b 44 EVT_CHAR(wxTextCtrl::OnChar)
c801d85f
KB
45END_EVENT_TABLE()
46
03f38c58 47wxTextCtrl::wxTextCtrl() : streambuf()
c801d85f 48{
6de97a3b 49 if (allocate()) setp(base(),ebuf());
13289f04 50
112892b9 51 m_modified = FALSE;
6de97a3b 52}
c801d85f 53
debe6624 54wxTextCtrl::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 64bool 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
ec758a20
RR
74 bool multi_line = (style & wxTE_MULTILINE) != 0;
75 if ( multi_line )
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);
f5368809 86 gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1,
41dee9d0 87 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
f5368809
RR
88 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
89 0, 0);
13289f04
VZ
90
91 // put the horizontal scrollbar in the lower left hand corner
8bbe427f 92 if (bHasHScrollbar)
903f689b 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,
f5368809 96 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
13289f04
VZ
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,
f5368809 106 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
13289f04 107 0, 0);
903f689b 108 gtk_widget_show( vscrollbar );
13289f04 109 }
8bbe427f 110 else
903f689b 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
6ca41e57
RR
122 m_parent->AddChild( this );
123
124 (m_parent->m_insertCallback)( m_parent, this );
8bbe427f 125
c801d85f 126 PostCreation();
484e45bf 127
8bbe427f 128 if (multi_line)
903f689b 129 {
13289f04
VZ
130 gtk_widget_realize(m_text);
131 gtk_widget_show(m_text);
132 }
133
484e45bf 134 // we want to be notified about text changes
13289f04 135 gtk_signal_connect(GTK_OBJECT(m_text), "changed",
484e45bf
VZ
136 GTK_SIGNAL_FUNC(gtk_text_changed_callback),
137 (gpointer)this);
138
7f4dc78d
RR
139 if (!value.IsNull())
140 {
141 gint tmp = 0;
13289f04 142 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp );
6ca41e57 143 SetInsertionPointEnd();
6de97a3b 144 }
484e45bf 145
ec758a20 146 if (style & wxTE_PASSWORD)
112892b9 147 {
ec758a20
RR
148 if (!multi_line)
149 gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
150 }
8bbe427f 151
ec758a20 152 if (style & wxTE_READONLY)
8bbe427f 153 {
ec758a20
RR
154 if (!multi_line)
155 gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE );
112892b9
RR
156 }
157 else
158 {
ec758a20 159 if (multi_line)
13289f04 160 gtk_text_set_editable( GTK_TEXT(m_text), 1 );
6de97a3b 161 }
484e45bf 162
c801d85f 163 Show( TRUE );
484e45bf 164
f96aa4d9 165 SetBackgroundColour( parent->GetBackgroundColour() );
58614078 166 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 167
c801d85f 168 return TRUE;
6de97a3b 169}
c801d85f 170
03f38c58 171wxString wxTextCtrl::GetValue() const
c801d85f 172{
a81258be 173 wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
8bbe427f 174
c801d85f
KB
175 wxString tmp;
176 if (m_windowStyle & wxTE_MULTILINE)
177 {
13289f04 178 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
a81258be
RR
179 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
180 tmp = text;
181 g_free( text );
c801d85f
KB
182 }
183 else
184 {
13289f04 185 tmp = gtk_entry_get_text( GTK_ENTRY(m_text) );
6de97a3b 186 }
c801d85f 187 return tmp;
6de97a3b 188}
c801d85f
KB
189
190void wxTextCtrl::SetValue( const wxString &value )
191{
f96aa4d9 192 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 193
c801d85f
KB
194 wxString tmp = "";
195 if (!value.IsNull()) tmp = value;
196 if (m_windowStyle & wxTE_MULTILINE)
197 {
13289f04
VZ
198 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
199 gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
c801d85f 200 len = 0;
13289f04 201 gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp, tmp.Length(), &len );
c801d85f
KB
202 }
203 else
204 {
13289f04 205 gtk_entry_set_text( GTK_ENTRY(m_text), tmp );
6de97a3b
RR
206 }
207}
c801d85f
KB
208
209void wxTextCtrl::WriteText( const wxString &text )
210{
f96aa4d9 211 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 212
c801d85f 213 if (text.IsNull()) return;
484e45bf 214
c801d85f
KB
215 if (m_windowStyle & wxTE_MULTILINE)
216 {
13289f04
VZ
217 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
218 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
c801d85f
KB
219 }
220 else
221 {
13289f04 222 gtk_entry_append_text( GTK_ENTRY(m_text), text );
6de97a3b
RR
223 }
224}
c801d85f 225
a81258be 226bool wxTextCtrl::LoadFile( const wxString &file )
c801d85f 227{
a81258be 228 wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
8bbe427f 229
a81258be 230 if (!wxFileExists(file)) return FALSE;
2ad3a34e 231
a81258be
RR
232 Clear();
233
234 FILE *fp = NULL;
235 struct stat statb;
8bbe427f 236
a81258be
RR
237 if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
238 !(fp = fopen ((char*) (const char*) file, "r")))
239 {
240 return FALSE;
241 }
242 else
243 {
244 gint len = statb.st_size;
245 char *text;
246 if (!(text = (char*)malloc ((unsigned) (len + 1))))
247 {
248 fclose (fp);
249 return FALSE;
250 }
251 if (fread (text, sizeof (char), len, fp) != (size_t) len)
252 {
253 }
254 fclose (fp);
255
256 text[len] = 0;
8bbe427f 257
a81258be
RR
258 if (m_windowStyle & wxTE_MULTILINE)
259 {
260 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len );
261 }
262 else
263 {
264 gtk_entry_set_text( GTK_ENTRY(m_text), text );
265 }
8bbe427f 266
a81258be
RR
267 free (text);
268 m_modified = FALSE;
269 return TRUE;
270 }
112892b9 271 return FALSE;
6de97a3b 272}
c801d85f 273
a81258be 274bool wxTextCtrl::SaveFile( const wxString &file )
c801d85f 275{
a81258be 276 wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
8bbe427f 277
a81258be 278 if (file == "") return FALSE;
8bbe427f 279
a81258be 280 FILE *fp;
2ad3a34e 281
a81258be
RR
282 if (!(fp = fopen ((char*) (const char*) file, "w")))
283 {
284 return FALSE;
285 }
286 else
287 {
288 char *text = NULL;
289 gint len = 0;
8bbe427f 290
a81258be
RR
291 if (m_windowStyle & wxTE_MULTILINE)
292 {
293 len = gtk_text_get_length( GTK_TEXT(m_text) );
294 text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
295 }
296 else
297 {
298 text = gtk_entry_get_text( GTK_ENTRY(m_text) );
299 }
8bbe427f 300
a81258be
RR
301 if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
302 {
303 // Did not write whole file
304 }
8bbe427f 305
a81258be
RR
306 // Make sure newline terminates the file
307 if (text[len - 1] != '\n')
308 fputc ('\n', fp);
309
310 fclose (fp);
8bbe427f 311
a81258be 312 if (m_windowStyle & wxTE_MULTILINE) g_free( text );
8bbe427f 313
a81258be
RR
314 m_modified = FALSE;
315 return TRUE;
316 }
317
318 return TRUE;
6de97a3b 319}
c801d85f 320
debe6624 321wxString wxTextCtrl::GetLineText( long lineNo ) const
c801d85f 322{
a81258be
RR
323 if (m_windowStyle & wxTE_MULTILINE)
324 {
325 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
326 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
327
328 if (text)
329 {
330 wxString buf("");
331 long i;
332 int currentLine = 0;
333 for (i = 0; currentLine != lineNo && text[i]; i++ )
334 if (text[i] == '\n')
335 currentLine++;
336 // Now get the text
337 int j;
338 for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
339 buf += text[i];
8bbe427f 340
a81258be
RR
341 g_free( text );
342 return buf;
343 }
344 else
345 return wxEmptyString;
346 }
347 else
348 {
349 if (lineNo == 0) return GetValue();
350 return wxEmptyString;
351 }
6de97a3b 352}
c801d85f 353
a81258be
RR
354void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
355{
c67d8618 356 wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" );
a81258be 357}
112892b9 358
e3ca08dd 359long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
c801d85f 360{
e3ca08dd
MR
361 if (!(m_windowStyle & wxTE_MULTILINE))
362 return 0;
363 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
364 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
365 if(!text)
366 return 0;
367 if( pos >= len)
368 return pos=len-1;
8bbe427f 369
e3ca08dd
MR
370 *x=1; // Col 1
371 *y=1; // Line 1
372 for (int i = 0; i < pos; i++ )
373 {
374 if (text[i] == '\n')
375 {
376 (*y)++;
377 *x=1;
378 }
379 else
380 (*x)++;
8bbe427f 381 }
e3ca08dd
MR
382 g_free( text );
383 return 1;
6de97a3b 384}
c801d85f 385
e3ca08dd 386long wxTextCtrl::XYToPosition(long x, long y ) const
c801d85f 387{
e3ca08dd
MR
388 if (!(m_windowStyle & wxTE_MULTILINE))
389 return 0;
390 long pos=0;
8bbe427f 391
e3ca08dd
MR
392 for(int i=1;i<y;i++)
393 pos +=GetLineLength(i);
394 pos +=x-1; // Pos start with 0
395 return pos;
6de97a3b 396}
c801d85f 397
a81258be 398int wxTextCtrl::GetLineLength(long lineNo) const
c801d85f 399{
a81258be
RR
400 wxString str = GetLineText (lineNo);
401 return (int) str.Length();
6de97a3b 402}
c801d85f 403
a81258be 404int wxTextCtrl::GetNumberOfLines() const
c801d85f 405{
a81258be
RR
406 if (m_windowStyle & wxTE_MULTILINE)
407 {
408 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
409 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
410
411 if (text)
412 {
413 int currentLine = 0;
414 for (int i = 0; i < len; i++ )
415 if (text[i] == '\n')
416 currentLine++;
8bbe427f 417
a81258be
RR
418 g_free( text );
419 return currentLine;
420 }
421 else
422 return 0;
423 }
424 else
425 {
426 return 1;
427 }
6de97a3b 428}
c801d85f 429
debe6624 430void wxTextCtrl::SetInsertionPoint( long pos )
c801d85f 431{
a81258be 432 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 433
c801d85f
KB
434 int tmp = (int) pos;
435 if (m_windowStyle & wxTE_MULTILINE)
13289f04 436 gtk_text_set_point( GTK_TEXT(m_text), tmp );
c801d85f 437 else
13289f04 438 gtk_entry_set_position( GTK_ENTRY(m_text), tmp );
6de97a3b 439}
c801d85f 440
03f38c58 441void wxTextCtrl::SetInsertionPointEnd()
c801d85f 442{
f96aa4d9 443 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 444
c801d85f
KB
445 int pos = 0;
446 if (m_windowStyle & wxTE_MULTILINE)
13289f04 447 pos = gtk_text_get_length( GTK_TEXT(m_text) );
c801d85f 448 else
13289f04 449 pos = GTK_ENTRY(m_text)->text_length;
605c9c83 450 SetInsertionPoint((pos-1)>0 ? (pos-1):0);
6de97a3b 451}
c801d85f 452
debe6624 453void wxTextCtrl::SetEditable( bool editable )
c801d85f 454{
f96aa4d9 455 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 456
c801d85f 457 if (m_windowStyle & wxTE_MULTILINE)
13289f04 458 gtk_text_set_editable( GTK_TEXT(m_text), editable );
c801d85f 459 else
13289f04 460 gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
6de97a3b 461}
c801d85f 462
debe6624 463void wxTextCtrl::SetSelection( long from, long to )
c801d85f 464{
f96aa4d9 465 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 466
13289f04 467 gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
6de97a3b 468}
c801d85f 469
debe6624 470void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
c801d85f 471{
f96aa4d9 472 wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" );
6de97a3b 473}
c801d85f 474
03f38c58 475long wxTextCtrl::GetInsertionPoint() const
c801d85f 476{
f96aa4d9 477 wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" );
8bbe427f 478
13289f04 479 return (long) GTK_EDITABLE(m_text)->current_pos;
6de97a3b 480}
c801d85f 481
03f38c58 482long wxTextCtrl::GetLastPosition() const
c801d85f 483{
f96aa4d9 484 wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" );
8bbe427f 485
c801d85f
KB
486 int pos = 0;
487 if (m_windowStyle & wxTE_MULTILINE)
13289f04 488 pos = gtk_text_get_length( GTK_TEXT(m_text) );
c801d85f 489 else
13289f04 490 pos = GTK_ENTRY(m_text)->text_length;
c801d85f 491 return (long)pos-1;
6de97a3b 492}
c801d85f 493
debe6624 494void wxTextCtrl::Remove( long from, long to )
c801d85f 495{
f96aa4d9 496 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 497
13289f04 498 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
6de97a3b 499}
c801d85f 500
debe6624 501void wxTextCtrl::Replace( long from, long to, const wxString &value )
c801d85f 502{
f96aa4d9 503 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 504
13289f04 505 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
c801d85f
KB
506 if (value.IsNull()) return;
507 gint pos = (gint)to;
13289f04 508 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
6de97a3b 509}
c801d85f 510
03f38c58 511void wxTextCtrl::Cut()
c801d85f 512{
f96aa4d9 513 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 514
75ed1d15
GL
515#if (GTK_MINOR_VERSION == 1)
516 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
517#else
13289f04 518 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 519#endif
6de97a3b 520}
c801d85f 521
03f38c58 522void wxTextCtrl::Copy()
c801d85f 523{
f96aa4d9 524 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 525
75ed1d15
GL
526#if (GTK_MINOR_VERSION == 1)
527 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
528#else
13289f04 529 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 530#endif
6de97a3b 531}
c801d85f 532
03f38c58 533void wxTextCtrl::Paste()
c801d85f 534{
f96aa4d9 535 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 536
75ed1d15
GL
537#if (GTK_MINOR_VERSION == 1)
538 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
539#else
13289f04 540 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
75ed1d15 541#endif
6de97a3b 542}
c801d85f 543
03f38c58 544void wxTextCtrl::Clear()
c801d85f
KB
545{
546 SetValue( "" );
6de97a3b 547}
c801d85f 548
903f689b 549void wxTextCtrl::OnChar( wxKeyEvent &key_event )
c801d85f 550{
903f689b
RR
551 if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
552 {
553 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
554 event.SetEventObject(this);
903f689b
RR
555 if (GetEventHandler()->ProcessEvent(event)) return;
556 }
8bbe427f 557 else if (key_event.KeyCode() == WXK_TAB)
903f689b
RR
558 {
559 wxNavigationKeyEvent event;
560 event.SetDirection( key_event.m_shiftDown );
561 event.SetWindowChange(FALSE);
562 event.SetEventObject(this);
563
564 if (GetEventHandler()->ProcessEvent(event)) return;
565 }
566 key_event.Skip();
6de97a3b 567}
c801d85f 568
46dc76ba 569int wxTextCtrl::overflow( int WXUNUSED(c) )
c801d85f 570{
c801d85f
KB
571 int len = pptr() - pbase();
572 char *txt = new char[len+1];
573 strncpy(txt, pbase(), len);
574 txt[len] = '\0';
575 (*this) << txt;
576 setp(pbase(), epptr());
577 delete[] txt;
578 return EOF;
6de97a3b 579}
c801d85f 580
03f38c58 581int wxTextCtrl::sync()
c801d85f 582{
c801d85f
KB
583 int len = pptr() - pbase();
584 char *txt = new char[len+1];
585 strncpy(txt, pbase(), len);
586 txt[len] = '\0';
587 (*this) << txt;
588 setp(pbase(), epptr());
589 delete[] txt;
590 return 0;
6de97a3b 591}
c801d85f 592
03f38c58 593int wxTextCtrl::underflow()
c801d85f
KB
594{
595 return EOF;
6de97a3b 596}
c801d85f
KB
597
598wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
599{
600 WriteText(s);
601 return *this;
602}
603
debe6624 604wxTextCtrl& wxTextCtrl::operator<<(float f)
c801d85f
KB
605{
606 static char buf[100];
607 sprintf(buf, "%.2f", f);
608 WriteText(buf);
609 return *this;
610}
611
debe6624 612wxTextCtrl& wxTextCtrl::operator<<(double d)
c801d85f
KB
613{
614 static char buf[100];
615 sprintf(buf, "%.2f", d);
616 WriteText(buf);
617 return *this;
618}
619
debe6624 620wxTextCtrl& wxTextCtrl::operator<<(int i)
c801d85f
KB
621{
622 static char buf[100];
623 sprintf(buf, "%i", i);
624 WriteText(buf);
625 return *this;
626}
627
debe6624 628wxTextCtrl& wxTextCtrl::operator<<(long i)
c801d85f
KB
629{
630 static char buf[100];
631 sprintf(buf, "%ld", i);
632 WriteText(buf);
633 return *this;
634}
635
636wxTextCtrl& wxTextCtrl::operator<<(const char c)
637{
638 char buf[2];
639
640 buf[0] = c;
641 buf[1] = 0;
642 WriteText(buf);
643 return *this;
644}
645
03f38c58 646GtkWidget* wxTextCtrl::GetConnectWidget()
e3e65dac
RR
647{
648 return GTK_WIDGET(m_text);
6de97a3b 649}
e3e65dac 650
903f689b
RR
651bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
652{
653 if (m_windowStyle & wxTE_MULTILINE)
654 return (window == GTK_TEXT(m_text)->text_area);
655 else
656 return (window == GTK_ENTRY(m_text)->text_area);
657}
e3e65dac 658
58614078 659void wxTextCtrl::SetFont( const wxFont &WXUNUSED(font) )
868a2826 660{
f96aa4d9 661 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 662
58614078
RR
663 // doesn't work
664}
665
666void wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
667{
668 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
8bbe427f 669
a81258be 670 // doesn't work
868a2826 671}
e3e65dac 672
68dda785
VZ
673void wxTextCtrl::SetBackgroundColour( const wxColour &colour )
674{
675 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
a81258be
RR
676
677 wxControl::SetBackgroundColour( colour );
8bbe427f 678
f96aa4d9 679 if (!m_backgroundColour.Ok()) return;
8bbe427f 680
f96aa4d9
RR
681 if (m_windowStyle & wxTE_MULTILINE)
682 {
683 GdkWindow *window = GTK_TEXT(m_text)->text_area;
684 m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
685 gdk_window_set_background( window, m_backgroundColour.GetColor() );
686 gdk_window_clear( window );
687 }
58614078
RR
688}
689
690void wxTextCtrl::ApplyWidgetStyle()
691{
692 if (m_windowStyle & wxTE_MULTILINE)
693 {
694 }
f96aa4d9
RR
695 else
696 {
58614078 697 SetWidgetStyle();
a81258be 698 gtk_widget_set_style( m_text, m_widgetStyle );
f96aa4d9 699 }
68dda785 700}
f96aa4d9 701