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