]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/textctrl.cpp
Added missing const to wxGTK's wxMDIChildFrame::GetToolbar; added bc_ide.txt instruct...
[wxWidgets.git] / src / gtk1 / textctrl.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: textctrl.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "textctrl.h"
12#endif
13
14#include "wx/textctrl.h"
15#include "wx/utils.h"
16#include "wx/intl.h"
17#include "wx/settings.h"
18
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <ctype.h>
22
23#include "gdk/gdk.h"
24#include "gtk/gtk.h"
25#include "gdk/gdkkeysyms.h"
26
27//-----------------------------------------------------------------------------
28// data
29//-----------------------------------------------------------------------------
30
31extern bool g_blockEventsOnDrag;
32
33//-----------------------------------------------------------------------------
34// "changed"
35//-----------------------------------------------------------------------------
36
37static void
38gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
39{
40 win->SetModified();
41
42 win->CalculateScrollbar();
43
44 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId );
45 event.SetString( copystring(win->GetValue()) );
46 event.SetEventObject( win );
47 win->GetEventHandler()->ProcessEvent( event );
48 delete[] event.GetString();
49}
50
51//-----------------------------------------------------------------------------
52// "size_allocate"
53//-----------------------------------------------------------------------------
54
55static void
56gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(alloc), wxTextCtrl *win )
57{
58 win->CalculateScrollbar();
59}
60
61//-----------------------------------------------------------------------------
62// wxTextCtrl
63//-----------------------------------------------------------------------------
64
65IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
66
67BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
68 EVT_CHAR(wxTextCtrl::OnChar)
69END_EVENT_TABLE()
70
71#ifndef NO_TEXT_WINDOW_STREAM
72wxTextCtrl::wxTextCtrl() : streambuf()
73{
74 if (allocate()) setp(base(),ebuf());
75
76 m_modified = FALSE;
77}
78#else
79wxTextCtrl::wxTextCtrl()
80{
81 m_modified = FALSE;
82}
83#endif
84
85#ifndef NO_TEXT_WINDOW_STREAM
86wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
87 const wxPoint &pos, const wxSize &size,
88 int style, const wxValidator& validator, const wxString &name ) : streambuf()
89{
90 if (allocate()) setp(base(),ebuf());
91
92 m_modified = FALSE;
93 Create( parent, id, value, pos, size, style, validator, name );
94}
95#else
96wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
97 const wxPoint &pos, const wxSize &size,
98 int style, const wxValidator& validator, const wxString &name )
99{
100 m_modified = FALSE;
101 Create( parent, id, value, pos, size, style, validator, name );
102}
103#endif
104
105bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
106 const wxPoint &pos, const wxSize &size,
107 int style, const wxValidator& validator, const wxString &name )
108{
109 m_needParent = TRUE;
110 m_acceptsFocus = TRUE;
111
112 PreCreation( parent, id, pos, size, style, name );
113
114 SetValidator( validator );
115
116 m_vScrollbarVisible = TRUE;
117
118 bool multi_line = (style & wxTE_MULTILINE) != 0;
119 if ( multi_line )
120 {
121 // a multi-line edit control: create a vertical scrollbar by default and
122 // horizontal if requested
123 bool bHasHScrollbar = (style & wxHSCROLL) != 0;
124
125 // create our control...
126 m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
127
128 // ... and put into the upper left hand corner of the table
129 m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE);
130 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
131
132 gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1,
133 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
134 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
135 0, 0);
136
137 // put the horizontal scrollbar in the lower left hand corner
138 if (bHasHScrollbar)
139 {
140 GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
141 GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
142
143 gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2,
144 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
145 GTK_FILL,
146 0, 0);
147 gtk_widget_show(hscrollbar);
148 }
149
150 // finally, put the vertical scrollbar in the upper right corner
151 m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
152 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
153
154 gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1,
155 GTK_FILL,
156 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
157 0, 0);
158 gtk_widget_show( m_vScrollbar );
159
160 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
161 GTK_SIGNAL_FUNC(gtk_text_size_callback), (gpointer)this );
162 }
163 else
164 {
165 // a single-line text control: no need for scrollbars
166 m_widget =
167 m_text = gtk_entry_new();
168 }
169
170 wxSize newSize = size;
171 if (newSize.x == -1) newSize.x = 80;
172 if (newSize.y == -1) newSize.y = 26;
173 SetSize( newSize.x, newSize.y );
174
175 m_parent->AddChild( this );
176
177 (m_parent->m_insertCallback)( m_parent, this );
178
179 PostCreation();
180
181 if (multi_line)
182 {
183 gtk_widget_realize(m_text);
184 gtk_widget_show(m_text);
185 }
186
187 // we want to be notified about text changes
188 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
189 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
190
191 if (!value.IsEmpty())
192 {
193 gint tmp = 0;
194 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp );
195
196 if (multi_line)
197 {
198 /* bring editable's cursor uptodate. bug in GTK. */
199
200 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
201 }
202 }
203
204 if (style & wxTE_PASSWORD)
205 {
206 if (!multi_line)
207 gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
208 }
209
210 if (style & wxTE_READONLY)
211 {
212 if (!multi_line)
213 gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE );
214 }
215 else
216 {
217 if (multi_line)
218 gtk_text_set_editable( GTK_TEXT(m_text), 1 );
219 }
220
221 Show( TRUE );
222
223 SetBackgroundColour( parent->GetBackgroundColour() );
224 SetForegroundColour( parent->GetForegroundColour() );
225
226 return TRUE;
227}
228
229void wxTextCtrl::CalculateScrollbar()
230{
231 if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
232
233 GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
234
235 if (adj->upper - adj->page_size < 0.8)
236 {
237 if (m_vScrollbarVisible)
238 {
239 gtk_widget_hide( m_vScrollbar );
240
241 m_vScrollbarVisible = FALSE;
242 }
243 }
244 else
245 {
246 if (!m_vScrollbarVisible)
247 {
248 gtk_widget_show( m_vScrollbar );
249
250 m_vScrollbarVisible = TRUE;
251 }
252 }
253}
254
255wxString wxTextCtrl::GetValue() const
256{
257 wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
258
259 wxString tmp;
260 if (m_windowStyle & wxTE_MULTILINE)
261 {
262 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
263 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
264 tmp = text;
265 g_free( text );
266 }
267 else
268 {
269 tmp = gtk_entry_get_text( GTK_ENTRY(m_text) );
270 }
271 return tmp;
272}
273
274void wxTextCtrl::SetValue( const wxString &value )
275{
276 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
277
278 wxString tmp = "";
279 if (!value.IsNull()) tmp = value;
280 if (m_windowStyle & wxTE_MULTILINE)
281 {
282 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
283 gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
284 len = 0;
285 gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp, tmp.Length(), &len );
286 }
287 else
288 {
289 gtk_entry_set_text( GTK_ENTRY(m_text), tmp );
290 }
291}
292
293void wxTextCtrl::WriteText( const wxString &text )
294{
295 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
296
297 if (text.IsNull()) return;
298
299 if (m_windowStyle & wxTE_MULTILINE)
300 {
301 /* this moves the cursor pos to behind the inserted text */
302 gint len = GTK_EDITABLE(m_text)->current_pos;
303 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
304
305 /* bring editable's cursor uptodate. bug in GTK. */
306 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
307 }
308 else
309 {
310 /* this moves the cursor pos to behind the inserted text */
311 gint len = GTK_EDITABLE(m_text)->current_pos;
312 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
313
314 /* bring editable's cursor uptodate. bug in GTK. */
315 GTK_EDITABLE(m_text)->current_pos += text.Len();
316
317 /* bring entry's cursor uptodate. bug in GTK. */
318 gtk_entry_set_position( GTK_ENTRY(m_text), GTK_EDITABLE(m_text)->current_pos );
319 }
320}
321
322void wxTextCtrl::AppendText( const wxString &text )
323{
324 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
325
326 if (m_windowStyle & wxTE_MULTILINE)
327 {
328 /* we'll insert at the last position */
329 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
330 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
331
332 /* bring editable's cursor uptodate. bug in GTK. */
333 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
334 }
335 else
336 {
337 gtk_entry_append_text( GTK_ENTRY(m_text), text );
338 }
339}
340
341bool wxTextCtrl::LoadFile( const wxString &file )
342{
343 wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
344
345 if (!wxFileExists(file)) return FALSE;
346
347 Clear();
348
349 FILE *fp = (FILE*) NULL;
350 struct stat statb;
351
352 if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
353 !(fp = fopen ((char*) (const char*) file, "r")))
354 {
355 return FALSE;
356 }
357 else
358 {
359 gint len = statb.st_size;
360 char *text;
361 if (!(text = (char*)malloc ((unsigned) (len + 1))))
362 {
363 fclose (fp);
364 return FALSE;
365 }
366 if (fread (text, sizeof (char), len, fp) != (size_t) len)
367 {
368 }
369 fclose (fp);
370
371 text[len] = 0;
372
373 if (m_windowStyle & wxTE_MULTILINE)
374 {
375 gint pos = 0;
376 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos );
377 }
378 else
379 {
380 gtk_entry_set_text( GTK_ENTRY(m_text), text );
381 }
382
383 free (text);
384 m_modified = FALSE;
385 return TRUE;
386 }
387 return FALSE;
388}
389
390bool wxTextCtrl::SaveFile( const wxString &file )
391{
392 wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" );
393
394 if (file == "") return FALSE;
395
396 FILE *fp;
397
398 if (!(fp = fopen ((char*) (const char*) file, "w")))
399 {
400 return FALSE;
401 }
402 else
403 {
404 char *text = (char*) NULL;
405 gint len = 0;
406
407 if (m_windowStyle & wxTE_MULTILINE)
408 {
409 len = gtk_text_get_length( GTK_TEXT(m_text) );
410 text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
411 }
412 else
413 {
414 text = gtk_entry_get_text( GTK_ENTRY(m_text) );
415 }
416
417 if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
418 {
419 // Did not write whole file
420 }
421
422 // Make sure newline terminates the file
423 if (text[len - 1] != '\n')
424 fputc ('\n', fp);
425
426 fclose (fp);
427
428 if (m_windowStyle & wxTE_MULTILINE) g_free( text );
429
430 m_modified = FALSE;
431 return TRUE;
432 }
433
434 return TRUE;
435}
436
437wxString wxTextCtrl::GetLineText( long lineNo ) const
438{
439 if (m_windowStyle & wxTE_MULTILINE)
440 {
441 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
442 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
443
444 if (text)
445 {
446 wxString buf("");
447 long i;
448 int currentLine = 0;
449 for (i = 0; currentLine != lineNo && text[i]; i++ )
450 if (text[i] == '\n')
451 currentLine++;
452 // Now get the text
453 int j;
454 for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
455 buf += text[i];
456
457 g_free( text );
458 return buf;
459 }
460 else
461 return wxEmptyString;
462 }
463 else
464 {
465 if (lineNo == 0) return GetValue();
466 return wxEmptyString;
467 }
468}
469
470void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
471{
472 /* If you implement this, don't forget to update the documentation!
473 * (file docs/latex/wx/text.tex) */
474 wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" );
475}
476
477long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
478{
479 if ( m_windowStyle & wxTE_MULTILINE )
480 {
481 wxString text = GetValue();
482
483 // cast to prevent warning. But pos really should've been unsigned.
484 if( (unsigned long)pos > text.Len() )
485 return FALSE;
486
487 *x=0; // First Col
488 *y=0; // First Line
489
490 const char* stop = text.c_str() + pos;
491 for ( const char *p = text.c_str(); p < stop; p++ )
492 {
493 if (*p == '\n')
494 {
495 (*y)++;
496 *x=0;
497 }
498 else
499 (*x)++;
500 }
501 }
502 else // single line control
503 {
504 if ( pos <= GTK_ENTRY(m_text)->text_length )
505 {
506 *y = 0;
507 *x = pos;
508 }
509 else
510 {
511 // index out of bounds
512 return FALSE;
513 }
514 }
515
516 return TRUE;
517}
518
519long wxTextCtrl::XYToPosition(long x, long y ) const
520{
521 if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
522
523 long pos=0;
524 for( int i=0; i<y; i++ ) pos += GetLineLength(i) + 1; // one for '\n'
525
526 pos += x;
527 return pos;
528}
529
530int wxTextCtrl::GetLineLength(long lineNo) const
531{
532 wxString str = GetLineText (lineNo);
533 return (int) str.Length();
534}
535
536int wxTextCtrl::GetNumberOfLines() const
537{
538 if (m_windowStyle & wxTE_MULTILINE)
539 {
540 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
541 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
542
543 if (text)
544 {
545 int currentLine = 0;
546 for (int i = 0; i < len; i++ )
547 {
548 if (text[i] == '\n')
549 currentLine++;
550 }
551 g_free( text );
552
553 // currentLine is 0 based, add 1 to get number of lines
554 return currentLine + 1;
555 }
556 else
557 {
558 return 0;
559 }
560 }
561 else
562 {
563 return 1;
564 }
565}
566
567void wxTextCtrl::SetInsertionPoint( long pos )
568{
569 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
570
571 if (m_windowStyle & wxTE_MULTILINE)
572 {
573 /* seems to be broken in GTK 1.0.X:
574 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
575
576 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
577 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
578
579 /* we fake a set_point by inserting and deleting. as the user
580 isn't supposed to get to know about thos non-sense, we
581 disconnect so that no events are sent to the user program. */
582
583 gint tmp = (gint)pos;
584 gtk_editable_insert_text( GTK_EDITABLE(m_text), " ", 1, &tmp );
585 gtk_editable_delete_text( GTK_EDITABLE(m_text), tmp-1, tmp );
586
587 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
588 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
589
590 /* bring editable's cursor uptodate. another bug in GTK. */
591
592 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
593 }
594 else
595 {
596 gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos );
597
598 /* bring editable's cursor uptodate. bug in GTK. */
599
600 GTK_EDITABLE(m_text)->current_pos = pos;
601 }
602}
603
604void wxTextCtrl::SetInsertionPointEnd()
605{
606 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
607
608 if (m_windowStyle & wxTE_MULTILINE)
609 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text)));
610 else
611 gtk_entry_set_position( GTK_ENTRY(m_text), -1 );
612}
613
614void wxTextCtrl::SetEditable( bool editable )
615{
616 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
617
618 if (m_windowStyle & wxTE_MULTILINE)
619 gtk_text_set_editable( GTK_TEXT(m_text), editable );
620 else
621 gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
622}
623
624void wxTextCtrl::SetSelection( long from, long to )
625{
626 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
627
628 gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
629}
630
631void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
632{
633 wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" );
634}
635
636long wxTextCtrl::GetInsertionPoint() const
637{
638 wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" );
639
640 return (long) GTK_EDITABLE(m_text)->current_pos;
641}
642
643long wxTextCtrl::GetLastPosition() const
644{
645 wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" );
646
647 int pos = 0;
648 if (m_windowStyle & wxTE_MULTILINE)
649 pos = gtk_text_get_length( GTK_TEXT(m_text) );
650 else
651 pos = GTK_ENTRY(m_text)->text_length;
652
653 return (long)pos;
654}
655
656void wxTextCtrl::Remove( long from, long to )
657{
658 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
659
660 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
661}
662
663void wxTextCtrl::Replace( long from, long to, const wxString &value )
664{
665 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
666
667 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
668 if (value.IsNull()) return;
669 gint pos = (gint)from;
670 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
671}
672
673void wxTextCtrl::Cut()
674{
675 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
676
677#if (GTK_MINOR_VERSION == 1)
678 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
679#else
680 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
681#endif
682}
683
684void wxTextCtrl::Copy()
685{
686 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
687
688#if (GTK_MINOR_VERSION == 1)
689 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
690#else
691 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
692#endif
693}
694
695void wxTextCtrl::Paste()
696{
697 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
698
699#if (GTK_MINOR_VERSION == 1)
700 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
701#else
702 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
703#endif
704}
705
706void wxTextCtrl::Clear()
707{
708 SetValue( "" );
709}
710
711void wxTextCtrl::OnChar( wxKeyEvent &key_event )
712{
713 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
714
715 if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
716 {
717 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
718 event.SetEventObject(this);
719 if (GetEventHandler()->ProcessEvent(event)) return;
720 }
721
722 key_event.Skip();
723}
724
725#ifndef NO_TEXT_WINDOW_STREAM
726int wxTextCtrl::overflow( int WXUNUSED(c) )
727{
728 int len = pptr() - pbase();
729 char *txt = new char[len+1];
730 strncpy(txt, pbase(), len);
731 txt[len] = '\0';
732 (*this) << txt;
733 setp(pbase(), epptr());
734 delete[] txt;
735 return EOF;
736}
737
738int wxTextCtrl::sync()
739{
740 int len = pptr() - pbase();
741 char *txt = new char[len+1];
742 strncpy(txt, pbase(), len);
743 txt[len] = '\0';
744 (*this) << txt;
745 setp(pbase(), epptr());
746 delete[] txt;
747 return 0;
748}
749
750int wxTextCtrl::underflow()
751{
752 return EOF;
753}
754
755wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
756{
757 AppendText(s);
758 return *this;
759}
760
761wxTextCtrl& wxTextCtrl::operator<<(float f)
762{
763 static char buf[100];
764 sprintf(buf, "%.2f", f);
765 AppendText(buf);
766 return *this;
767}
768
769wxTextCtrl& wxTextCtrl::operator<<(double d)
770{
771 static char buf[100];
772 sprintf(buf, "%.2f", d);
773 AppendText(buf);
774 return *this;
775}
776
777wxTextCtrl& wxTextCtrl::operator<<(int i)
778{
779 static char buf[100];
780 sprintf(buf, "%i", i);
781 AppendText(buf);
782 return *this;
783}
784
785wxTextCtrl& wxTextCtrl::operator<<(long i)
786{
787 static char buf[100];
788 sprintf(buf, "%ld", i);
789 AppendText(buf);
790 return *this;
791}
792
793wxTextCtrl& wxTextCtrl::operator<<(const char c)
794{
795 char buf[2];
796
797 buf[0] = c;
798 buf[1] = 0;
799 AppendText(buf);
800 return *this;
801}
802#endif
803
804GtkWidget* wxTextCtrl::GetConnectWidget()
805{
806 return GTK_WIDGET(m_text);
807}
808
809bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
810{
811 if (m_windowStyle & wxTE_MULTILINE)
812 return (window == GTK_TEXT(m_text)->text_area);
813 else
814 return (window == GTK_ENTRY(m_text)->text_area);
815}
816
817void wxTextCtrl::SetFont( const wxFont &WXUNUSED(font) )
818{
819 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
820
821 // doesn't work
822}
823
824void wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
825{
826 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
827
828 // doesn't work
829}
830
831void wxTextCtrl::SetBackgroundColour( const wxColour &colour )
832{
833 wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
834
835 wxControl::SetBackgroundColour( colour );
836
837 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
838 if (sysbg.Red() == colour.Red() &&
839 sysbg.Green() == colour.Green() &&
840 sysbg.Blue() == colour.Blue())
841 {
842 return;
843 }
844
845 if (!m_backgroundColour.Ok()) return;
846
847 if (m_windowStyle & wxTE_MULTILINE)
848 {
849 GdkWindow *window = GTK_TEXT(m_text)->text_area;
850 m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
851 gdk_window_set_background( window, m_backgroundColour.GetColor() );
852 gdk_window_clear( window );
853 }
854}
855
856void wxTextCtrl::ApplyWidgetStyle()
857{
858 if (m_windowStyle & wxTE_MULTILINE)
859 {
860 // how ?
861 }
862 else
863 {
864 SetWidgetStyle();
865 gtk_widget_set_style( m_text, m_widgetStyle );
866 }
867}
868