1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "textctrl.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
17 #include "wx/textctrl.h"
21 #include "wx/settings.h"
23 #include "wx/strconv.h"
24 #include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
26 #include <sys/types.h>
29 #include <math.h> // for fabs
31 #include "wx/gtk/private.h"
32 #include <gdk/gdkkeysyms.h>
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern void wxapp_install_idle_handler();
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 extern bool g_blockEventsOnDrag
;
46 extern wxCursor g_globalCursor
;
47 extern wxWindowGTK
*g_delayedFocus
;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 static void wxGtkTextInsert(GtkWidget
*text
,
55 GtkTextBuffer
*text_buffer
,
56 const wxTextAttr
& attr
,
60 PangoFontDescription
*font_description
= attr
.HasFont()
61 ? attr
.GetFont().GetNativeFontInfo()->description
64 GdkColor
*colFg
= attr
.HasTextColour() ? attr
.GetTextColour().GetColor()
67 GdkColor
*colBg
= attr
.HasBackgroundColour()
68 ? attr
.GetBackgroundColour().GetColor()
72 tag
= gtk_text_buffer_create_tag( text_buffer
, NULL
, "font-desc", font_description
,
73 "foreground-gdk", colFg
,
74 "background-gdk", colBg
, NULL
);
77 gtk_text_buffer_get_iter_at_mark( text_buffer
, &iter
,
78 gtk_text_buffer_get_insert (text_buffer
) );
80 gtk_text_buffer_insert_with_tags( text_buffer
, &iter
, buffer
, strlen(buffer
), tag
, NULL
);
83 static void wxGtkTextInsert(GtkWidget
*text
,
84 const wxTextAttr
& attr
,
88 GdkFont
*font
= attr
.HasFont() ? attr
.GetFont().GetInternalFont()
91 GdkColor
*colFg
= attr
.HasTextColour() ? attr
.GetTextColour().GetColor()
94 GdkColor
*colBg
= attr
.HasBackgroundColour()
95 ? attr
.GetBackgroundColour().GetColor()
98 gtk_text_insert( GTK_TEXT(text
), font
, colFg
, colBg
, txt
, len
);
102 // ----------------------------------------------------------------------------
103 // "insert_text" for GtkEntry
104 // ----------------------------------------------------------------------------
107 gtk_insert_text_callback(GtkEditable
*editable
,
108 const gchar
*new_text
,
109 gint new_text_length
,
114 wxapp_install_idle_handler();
116 // we should only be called if we have a max len limit at all
117 GtkEntry
*entry
= GTK_ENTRY (editable
);
119 wxCHECK_RET( entry
->text_max_length
, _T("shouldn't be called") );
121 // check that we don't overflow the max length limit
123 // FIXME: this doesn't work when we paste a string which is going to be
125 if ( entry
->text_length
== entry
->text_max_length
)
127 // we don't need to run the base class version at all
128 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable
), "insert_text");
130 // remember that the next changed signal is to be ignored to avoid
131 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
132 win
->IgnoreNextTextUpdate();
134 // and generate the correct one ourselves
135 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, win
->GetId());
136 event
.SetEventObject(win
);
137 event
.SetString(win
->GetValue());
138 win
->GetEventHandler()->ProcessEvent( event
);
142 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
147 gtk_text_changed_callback( GtkWidget
*widget
, wxTextCtrl
*win
)
149 if ( win
->IgnoreTextUpdate() )
152 if (!win
->m_hasVMT
) return;
155 wxapp_install_idle_handler();
159 win
->UpdateFontIfNeeded();
160 #endif // !__WXGTK20__
162 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
163 event
.SetEventObject( win
);
164 event
.SetString( win
->GetValue() );
165 win
->GetEventHandler()->ProcessEvent( event
);
168 //-----------------------------------------------------------------------------
169 // "changed" from vertical scrollbar
170 //-----------------------------------------------------------------------------
174 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
176 if (!win
->m_hasVMT
) return;
179 wxapp_install_idle_handler();
181 win
->CalculateScrollbar();
185 // ----------------------------------------------------------------------------
186 // redraw callback for multiline text
187 // ----------------------------------------------------------------------------
191 // redrawing a GtkText from inside a wxYield() call results in crashes (the
192 // text sample shows it in its "Add lines" command which shows wxProgressDialog
193 // which implicitly calls wxYield()) so we override GtkText::draw() and simply
194 // don't do anything if we're inside wxYield()
196 extern bool wxIsInsideYield
;
199 typedef void (*GtkDrawCallback
)(GtkWidget
*widget
, GdkRectangle
*rect
);
202 static GtkDrawCallback gs_gtk_text_draw
= NULL
;
205 void wxgtk_text_draw( GtkWidget
*widget
, GdkRectangle
*rect
)
207 if ( !wxIsInsideYield
)
209 wxCHECK_RET( gs_gtk_text_draw
!= wxgtk_text_draw
,
210 _T("infinite recursion in wxgtk_text_draw aborted") );
212 gs_gtk_text_draw(widget
, rect
);
216 #endif // __WXGTK20__
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
224 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
225 EVT_CHAR(wxTextCtrl::OnChar
)
227 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
228 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
229 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
230 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
231 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
233 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
234 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
235 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
236 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
237 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
240 void wxTextCtrl::Init()
244 SetUpdateFont(FALSE
);
246 m_vScrollbar
= (GtkWidget
*)NULL
;
249 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
251 const wxString
&value
,
255 const wxValidator
& validator
,
256 const wxString
&name
)
260 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
263 bool wxTextCtrl::Create( wxWindow
*parent
,
265 const wxString
&value
,
269 const wxValidator
& validator
,
270 const wxString
&name
)
273 m_acceptsFocus
= TRUE
;
275 if (!PreCreation( parent
, pos
, size
) ||
276 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
278 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
283 m_vScrollbarVisible
= FALSE
;
285 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
288 GtkTextBuffer
*buffer
= NULL
;
295 m_text
= gtk_text_view_new();
297 buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
299 // create scrolled window
300 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
301 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget
),
302 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
304 // Insert view into scrolled window
305 gtk_container_add( GTK_CONTAINER(m_widget
), m_text
);
307 // Global settings which can be overridden by tags, I guess.
308 if (HasFlag( wxHSCROLL
) || HasFlag( wxTE_DONTWRAP
))
309 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), GTK_WRAP_NONE
);
311 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), GTK_WRAP_WORD
);
313 if (!HasFlag(wxNO_BORDER
))
314 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(m_widget
), GTK_SHADOW_IN
);
316 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
318 // create our control ...
319 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
321 // ... and put into the upper left hand corner of the table
322 bool bHasHScrollbar
= FALSE
;
323 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
324 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
325 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
326 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
327 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
331 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
333 // finally, put the vertical scrollbar in the upper right corner
334 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
335 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
336 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
338 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
344 // a single-line text control: no need for scrollbars
346 m_text
= gtk_entry_new();
349 m_parent
->DoAddChild( this );
351 m_focusWidget
= m_text
;
356 gtk_widget_show(m_text
);
361 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
362 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
364 // only initialize gs_gtk_text_draw once, starting from the next the
365 // klass::draw will already be wxgtk_text_draw
366 if ( !gs_gtk_text_draw
)
369 draw
= GTK_WIDGET_CLASS(GTK_OBJECT(m_text
)->klass
)->draw
;
371 gs_gtk_text_draw
= draw
;
373 draw
= wxgtk_text_draw
;
378 if (!value
.IsEmpty())
384 #if !GTK_CHECK_VERSION(1, 2, 0)
385 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
386 // gtk_editable_insert_text()
387 gtk_widget_realize(m_text
);
392 wxWX2MBbuf val
= value
.mbc_str();
393 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
395 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
400 // Bring editable's cursor uptodate. Bug in GTK.
401 SET_EDITABLE_POS(m_text
, gtk_text_get_point( GTK_TEXT(m_text
) ));
407 if (style
& wxTE_PASSWORD
)
410 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
413 if (style
& wxTE_READONLY
)
416 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
419 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text
), FALSE
);
425 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
432 if (style
& wxTE_RIGHT
)
433 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_RIGHT
);
434 else if (style
& wxTE_CENTRE
)
435 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_CENTER
);
436 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
438 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
439 #if GTK_CHECK_VERSION(2, 3, 5)
442 if (style
& wxTE_RIGHT
)
443 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 1.0 );
444 else if (style
& wxTE_CENTRE
)
445 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 0.5 );
448 #endif // __WXGTK20__
450 // We want to be notified about text changes.
454 g_signal_connect( G_OBJECT(buffer
), "changed",
455 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
461 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
462 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
465 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
467 wxTextAttr
attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
468 SetDefaultStyle( attrDef
);
474 void wxTextCtrl::CalculateScrollbar()
477 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
479 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
481 if (adj
->upper
- adj
->page_size
< 0.8)
483 if (m_vScrollbarVisible
)
485 gtk_widget_hide( m_vScrollbar
);
486 m_vScrollbarVisible
= FALSE
;
491 if (!m_vScrollbarVisible
)
493 gtk_widget_show( m_vScrollbar
);
494 m_vScrollbarVisible
= TRUE
;
500 wxString
wxTextCtrl::GetValue() const
502 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
505 if (m_windowStyle
& wxTE_MULTILINE
)
508 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
511 gtk_text_buffer_get_start_iter( text_buffer
, &start
);
513 gtk_text_buffer_get_end_iter( text_buffer
, &end
);
514 gchar
*text
= gtk_text_buffer_get_text( text_buffer
, &start
, &end
, TRUE
);
517 wxWCharBuffer
buffer( wxConvUTF8
.cMB2WX( text
) );
519 wxCharBuffer
buffer( wxConvLocal
.cWC2WX( wxConvUTF8
.cMB2WC( text
) ) );
525 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
526 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
533 tmp
= wxGTK_CONV_BACK( gtk_entry_get_text( GTK_ENTRY(m_text
) ) );
539 void wxTextCtrl::SetValue( const wxString
&value
)
541 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
543 if (m_windowStyle
& wxTE_MULTILINE
)
548 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( value
) );
550 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( value
) ) );
552 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
553 gtk_text_buffer_set_text( text_buffer
, buffer
, strlen(buffer
) );
556 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
557 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
559 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
.mbc_str(), value
.Length(), &len
);
564 gtk_entry_set_text( GTK_ENTRY(m_text
), wxGTK_CONV( value
) );
567 // GRG, Jun/2000: Changed this after a lot of discussion in
568 // the lists. wxWidgets 2.2 will have a set of flags to
569 // customize this behaviour.
570 SetInsertionPoint(0);
575 void wxTextCtrl::WriteText( const wxString
&text
)
577 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
582 // gtk_text_changed_callback() will set m_modified to true but m_modified
583 // shouldn't be changed by the program writing to the text control itself,
584 // so save the old value and restore when we're done
585 bool oldModified
= m_modified
;
587 if ( m_windowStyle
& wxTE_MULTILINE
)
592 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
594 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
598 // what else can we do? at least don't crash...
602 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
604 // TODO: Call whatever is needed to delete the selection.
605 wxGtkTextInsert( m_text
, text_buffer
, m_defaultStyle
, buffer
);
607 GtkAdjustment
*adj
= gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget
) );
608 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
609 if ( adj
->value
== adj
->upper
- adj
->page_size
)
611 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
),
612 gtk_text_buffer_get_insert( text_buffer
), 0.0, FALSE
, 0.0, 1.0 );
615 // After cursor movements, gtk_text_get_point() is wrong by one.
616 gtk_text_set_point( GTK_TEXT(m_text
), GET_EDITABLE_POS(m_text
) );
618 // always use m_defaultStyle, even if it is empty as otherwise
619 // resetting the style and appending some more text wouldn't work: if
620 // we don't specify the style explicitly, the old style would be used
621 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
622 wxGtkTextInsert(m_text
, m_defaultStyle
, text
.c_str(), text
.Len());
624 // we called wxGtkTextInsert with correct font, no need to do anything
625 // in UpdateFontIfNeeded() any longer
628 SetUpdateFont(FALSE
);
631 // Bring editable's cursor back uptodate.
632 SET_EDITABLE_POS(m_text
, gtk_text_get_point( GTK_TEXT(m_text
) ));
633 #endif // GTK 1.x/2.0
637 // First remove the selection if there is one
638 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
640 // This moves the cursor pos to behind the inserted text.
641 gint len
= GET_EDITABLE_POS(m_text
);
646 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
648 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
650 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buffer
, strlen(buffer
), &len
);
653 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
.c_str(), text
.Len(), &len
);
656 // Bring entry's cursor uptodate.
657 gtk_entry_set_position( GTK_ENTRY(m_text
), len
);
660 m_modified
= oldModified
;
663 void wxTextCtrl::AppendText( const wxString
&text
)
665 SetInsertionPointEnd();
669 wxString
wxTextCtrl::GetLineText( long lineNo
) const
671 if (m_windowStyle
& wxTE_MULTILINE
)
674 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
675 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
679 wxString
buf(wxT(""));
682 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
687 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
695 return wxEmptyString
;
698 GtkTextBuffer
*text_buffer
;
699 text_buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(m_text
));
701 gtk_text_buffer_get_iter_at_line(text_buffer
,&line
,lineNo
);
703 gtk_text_buffer_get_end_iter(text_buffer
,&end
);
704 gchar
*text
= gtk_text_buffer_get_text(text_buffer
,&line
,&end
,TRUE
);
705 wxString
result(wxGTK_CONV_BACK(text
));
707 return result
.BeforeFirst(wxT('\n'));
712 if (lineNo
== 0) return GetValue();
713 return wxEmptyString
;
717 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
719 /* If you implement this, don't forget to update the documentation!
720 * (file docs/latex/wx/text.tex) */
721 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
724 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
726 if ( m_windowStyle
& wxTE_MULTILINE
)
728 wxString text
= GetValue();
730 // cast to prevent warning. But pos really should've been unsigned.
731 if( (unsigned long)pos
> text
.Len() )
737 const wxChar
* stop
= text
.c_str() + pos
;
738 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
749 else // single line control
751 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
758 // index out of bounds
766 long wxTextCtrl::XYToPosition(long x
, long y
) const
768 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
771 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
777 int wxTextCtrl::GetLineLength(long lineNo
) const
779 wxString str
= GetLineText (lineNo
);
780 return (int) str
.Length();
783 int wxTextCtrl::GetNumberOfLines() const
785 if (m_windowStyle
& wxTE_MULTILINE
)
788 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
790 return gtk_text_buffer_get_line_count( buffer
);
792 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
793 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
798 for (int i
= 0; i
< len
; i
++ )
805 // currentLine is 0 based, add 1 to get number of lines
806 return currentLine
+ 1;
820 void wxTextCtrl::SetInsertionPoint( long pos
)
822 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
827 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
829 gtk_text_buffer_get_iter_at_offset( text_buffer
, &iter
, pos
);
830 gtk_text_buffer_place_cursor( text_buffer
, &iter
);
831 gtk_text_view_scroll_mark_onscreen
833 GTK_TEXT_VIEW(m_text
),
834 gtk_text_buffer_get_insert( text_buffer
)
837 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
838 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
840 /* we fake a set_point by inserting and deleting. as the user
841 isn't supposed to get to know about this non-sense, we
842 disconnect so that no events are sent to the user program. */
844 gint tmp
= (gint
)pos
;
845 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
846 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
848 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
849 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
851 // bring editable's cursor uptodate. Bug in GTK.
852 SET_EDITABLE_POS(m_text
, gtk_text_get_point( GTK_TEXT(m_text
) ));
857 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
859 // Bring editable's cursor uptodate. Bug in GTK.
860 SET_EDITABLE_POS(m_text
, (guint32
)pos
);
864 void wxTextCtrl::SetInsertionPointEnd()
866 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
868 if (m_windowStyle
& wxTE_MULTILINE
)
871 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
873 gtk_text_buffer_get_end_iter( text_buffer
, &end
);
874 gtk_text_buffer_place_cursor( text_buffer
, &end
);
876 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
881 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
885 void wxTextCtrl::SetEditable( bool editable
)
887 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
889 if (m_windowStyle
& wxTE_MULTILINE
)
892 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text
), editable
);
894 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
899 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
903 bool wxTextCtrl::Enable( bool enable
)
905 if (!wxWindowBase::Enable(enable
))
911 if (m_windowStyle
& wxTE_MULTILINE
)
914 SetEditable( enable
);
916 gtk_text_set_editable( GTK_TEXT(m_text
), enable
);
917 OnParentEnable(enable
);
922 gtk_widget_set_sensitive( m_text
, enable
);
928 // wxGTK-specific: called recursively by Enable,
929 // to give widgets an oppprtunity to correct their colours after they
930 // have been changed by Enable
931 void wxTextCtrl::OnParentEnable( bool enable
)
933 // If we have a custom background colour, we use this colour in both
934 // disabled and enabled mode, or we end up with a different colour under the
936 wxColour oldColour
= GetBackgroundColour();
939 // Need to set twice or it'll optimize the useful stuff out
940 if (oldColour
== * wxWHITE
)
941 SetBackgroundColour(*wxBLACK
);
943 SetBackgroundColour(*wxWHITE
);
944 SetBackgroundColour(oldColour
);
948 void wxTextCtrl::MarkDirty()
953 void wxTextCtrl::DiscardEdits()
958 // ----------------------------------------------------------------------------
959 // max text length support
960 // ----------------------------------------------------------------------------
962 void wxTextCtrl::IgnoreNextTextUpdate()
964 m_ignoreNextUpdate
= TRUE
;
967 bool wxTextCtrl::IgnoreTextUpdate()
969 if ( m_ignoreNextUpdate
)
971 m_ignoreNextUpdate
= FALSE
;
979 void wxTextCtrl::SetMaxLength(unsigned long len
)
981 if ( !HasFlag(wxTE_MULTILINE
) )
983 gtk_entry_set_max_length(GTK_ENTRY(m_text
), len
);
985 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
986 // we had tried to enter more text than allowed by max text length and
987 // the text wasn't really changed
989 // to detect this and generate TEXT_MAXLEN event instead of
990 // TEXT_CHANGED one in this case we also catch "insert_text" signal
992 // when max len is set to 0 we disconnect our handler as it means that
993 // we shouldn't check anything any more
996 gtk_signal_connect( GTK_OBJECT(m_text
),
998 GTK_SIGNAL_FUNC(gtk_insert_text_callback
),
1003 gtk_signal_disconnect_by_func
1006 GTK_SIGNAL_FUNC(gtk_insert_text_callback
),
1013 void wxTextCtrl::SetSelection( long from
, long to
)
1015 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1017 if (from
== -1 && to
== -1)
1020 to
= GetValue().Length();
1024 if ( (m_windowStyle
& wxTE_MULTILINE
) &&
1025 !GTK_TEXT(m_text
)->line_start_cache
)
1027 // tell the programmer that it didn't work
1028 wxLogDebug(_T("Can't call SetSelection() before realizing the control"));
1033 if (m_windowStyle
& wxTE_MULTILINE
)
1036 GtkTextBuffer
*buf
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1038 GtkTextIter fromi
, toi
;
1039 gtk_text_buffer_get_iter_at_offset( buf
, &fromi
, from
);
1040 gtk_text_buffer_get_iter_at_offset( buf
, &toi
, to
);
1042 gtk_text_buffer_place_cursor( buf
, &toi
);
1043 gtk_text_buffer_move_mark_by_name( buf
, "selection_bound", &fromi
);
1045 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1050 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1054 void wxTextCtrl::ShowPosition( long pos
)
1056 if (m_windowStyle
& wxTE_MULTILINE
)
1059 GtkTextBuffer
*buf
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1061 gtk_text_buffer_get_start_iter( buf
, &iter
);
1062 gtk_text_iter_set_offset( &iter
, pos
);
1063 GtkTextMark
*mark
= gtk_text_buffer_create_mark( buf
, NULL
, &iter
, TRUE
);
1064 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
), mark
, 0.0, FALSE
, 0.0, 0.0 );
1066 GtkAdjustment
*vp
= GTK_TEXT(m_text
)->vadj
;
1067 float totalLines
= (float) GetNumberOfLines();
1070 PositionToXY(pos
, &posX
, &posY
);
1071 float posLine
= (float) posY
;
1072 float p
= (posLine
/totalLines
)*(vp
->upper
- vp
->lower
) + vp
->lower
;
1073 gtk_adjustment_set_value(GTK_TEXT(m_text
)->vadj
, p
);
1074 #endif // GTK 1.x/2.x
1080 wxTextCtrlHitTestResult
1081 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
1083 if ( !IsMultiLine() )
1086 return wxTE_HT_UNKNOWN
;
1090 gtk_text_view_window_to_buffer_coords
1092 GTK_TEXT_VIEW(m_text
),
1093 GTK_TEXT_WINDOW_TEXT
,
1099 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &iter
, x
, y
);
1101 *pos
= gtk_text_iter_get_offset(&iter
);
1103 return wxTE_HT_ON_TEXT
;
1106 #endif // __WXGTK20__
1108 long wxTextCtrl::GetInsertionPoint() const
1110 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1113 if (m_windowStyle
& wxTE_MULTILINE
)
1115 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1117 // There is no direct accessor for the cursor, but
1118 // internally, the cursor is the "mark" called
1119 // "insert" in the text view's btree structure.
1121 GtkTextMark
*mark
= gtk_text_buffer_get_insert( text_buffer
);
1123 gtk_text_buffer_get_iter_at_mark( text_buffer
, &cursor
, mark
);
1125 return gtk_text_iter_get_offset( &cursor
);
1130 return (long) GET_EDITABLE_POS(m_text
);
1134 long wxTextCtrl::GetLastPosition() const
1136 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1140 if (m_windowStyle
& wxTE_MULTILINE
)
1143 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1145 gtk_text_buffer_get_end_iter( text_buffer
, &end
);
1147 pos
= gtk_text_iter_get_offset( &end
);
1149 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
1154 pos
= GTK_ENTRY(m_text
)->text_length
;
1160 void wxTextCtrl::Remove( long from
, long to
)
1162 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1165 if (m_windowStyle
& wxTE_MULTILINE
)
1168 text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1170 GtkTextIter fromi
, toi
;
1171 gtk_text_buffer_get_iter_at_offset( text_buffer
, &fromi
, from
);
1172 gtk_text_buffer_get_iter_at_offset( text_buffer
, &toi
, to
);
1174 gtk_text_buffer_delete( text_buffer
, &fromi
, &toi
);
1178 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1181 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
1183 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1187 if (!value
.IsEmpty())
1190 SetInsertionPoint( from
);
1193 gint pos
= (gint
)from
;
1195 wxWX2MBbuf buf
= value
.mbc_str();
1196 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
1198 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
1199 #endif // wxUSE_UNICODE
1200 #endif // GTK 1.x/2.x
1204 void wxTextCtrl::Cut()
1206 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1209 if (m_windowStyle
& wxTE_MULTILINE
)
1210 g_signal_emit_by_name(m_text
, "cut-clipboard");
1213 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text
) DUMMY_CLIPBOARD_ARG
);
1216 void wxTextCtrl::Copy()
1218 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1221 if (m_windowStyle
& wxTE_MULTILINE
)
1222 g_signal_emit_by_name(m_text
, "copy-clipboard");
1225 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text
) DUMMY_CLIPBOARD_ARG
);
1228 void wxTextCtrl::Paste()
1230 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1233 if (m_windowStyle
& wxTE_MULTILINE
)
1234 g_signal_emit_by_name(m_text
, "paste-clipboard");
1237 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text
) DUMMY_CLIPBOARD_ARG
);
1241 void wxTextCtrl::Undo()
1244 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
1247 void wxTextCtrl::Redo()
1250 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
1253 bool wxTextCtrl::CanUndo() const
1256 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
1260 bool wxTextCtrl::CanRedo() const
1263 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
1267 // If the return values from and to are the same, there is no
1269 void wxTextCtrl::GetSelection(long* fromOut
, long* toOut
) const
1271 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1275 bool haveSelection
= FALSE
;
1278 if (m_windowStyle
& wxTE_MULTILINE
)
1280 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text
));
1281 GtkTextIter ifrom
, ito
;
1282 if ( gtk_text_buffer_get_selection_bounds(buffer
, &ifrom
, &ito
) )
1284 haveSelection
= TRUE
;
1285 from
= gtk_text_iter_get_offset(&ifrom
);
1286 to
= gtk_text_iter_get_offset(&ito
);
1289 else // not multi-line
1291 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text
),
1294 haveSelection
= TRUE
;
1298 if ( (GTK_EDITABLE(m_text
)->has_selection
) )
1300 haveSelection
= TRUE
;
1301 from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
1302 to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
1306 if (! haveSelection
)
1307 from
= to
= GetInsertionPoint();
1311 // exchange them to be compatible with wxMSW
1324 bool wxTextCtrl::IsEditable() const
1326 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
1329 if (m_windowStyle
& wxTE_MULTILINE
)
1331 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text
));
1335 return gtk_editable_get_editable(GTK_EDITABLE(m_text
));
1338 return GTK_EDITABLE(m_text
)->editable
;
1342 bool wxTextCtrl::IsModified() const
1347 void wxTextCtrl::Clear()
1349 SetValue( wxT("") );
1352 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
1354 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1356 if ((key_event
.GetKeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
1358 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1359 event
.SetEventObject(this);
1360 event
.SetString(GetValue());
1361 if (GetEventHandler()->ProcessEvent(event
)) return;
1364 if ((key_event
.GetKeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
1366 // This will invoke the dialog default action, such
1367 // as the clicking the default button.
1369 wxWindow
*top_frame
= m_parent
;
1370 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
1371 top_frame
= top_frame
->GetParent();
1373 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
1375 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
1377 if (window
->default_widget
)
1379 gtk_widget_activate (window
->default_widget
);
1388 GtkWidget
* wxTextCtrl::GetConnectWidget()
1390 return GTK_WIDGET(m_text
);
1393 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
1395 if (m_windowStyle
& wxTE_MULTILINE
)
1398 return window
== gtk_text_view_get_window( GTK_TEXT_VIEW( m_text
), GTK_TEXT_WINDOW_TEXT
); // pure guesswork
1400 return (window
== GTK_TEXT(m_text
)->text_area
);
1405 return (window
== GTK_ENTRY(m_text
)->text_area
);
1409 // the font will change for subsequent text insertiongs
1410 bool wxTextCtrl::SetFont( const wxFont
&font
)
1412 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
1414 if ( !wxTextCtrlBase::SetFont(font
) )
1416 // font didn't change, nothing to do
1420 if ( m_windowStyle
& wxTE_MULTILINE
)
1422 SetUpdateFont(TRUE
);
1424 m_defaultStyle
.SetFont(font
);
1426 ChangeFontGlobally();
1432 void wxTextCtrl::ChangeFontGlobally()
1434 // this method is very inefficient and hence should be called as rarely as
1437 // TODO: it can be implemented much more efficiently for GTK2
1438 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
)
1443 _T("shouldn't be called for single line controls") );
1445 wxString value
= GetValue();
1446 if ( !value
.IsEmpty() )
1448 SetUpdateFont(FALSE
);
1457 void wxTextCtrl::UpdateFontIfNeeded()
1460 ChangeFontGlobally();
1465 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1467 if ( !wxControl::SetForegroundColour(colour
) )
1470 // update default fg colour too
1471 m_defaultStyle
.SetTextColour(colour
);
1476 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
1478 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
1480 if ( !wxControl::SetBackgroundColour( colour
) )
1483 if (!m_widget
->window
)
1486 if (!m_backgroundColour
.Ok())
1489 if (m_windowStyle
& wxTE_MULTILINE
)
1492 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
1495 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
1496 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
1497 gdk_window_clear( window
);
1501 // change active background color too
1502 m_defaultStyle
.SetBackgroundColour( colour
);
1507 bool wxTextCtrl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1509 if ( m_windowStyle
& wxTE_MULTILINE
)
1511 if ( style
.IsDefault() )
1517 GtkTextBuffer
*text_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
1518 gint l
= gtk_text_buffer_get_char_count( text_buffer
);
1520 wxCHECK_MSG( start
>= 0 && end
<= l
, FALSE
,
1521 _T("invalid range in wxTextCtrl::SetStyle") );
1523 GtkTextIter starti
, endi
;
1524 gtk_text_buffer_get_iter_at_offset( text_buffer
, &starti
, start
);
1525 gtk_text_buffer_get_iter_at_offset( text_buffer
, &endi
, end
);
1527 // use the attributes from style which are set in it and fall back
1528 // first to the default style and then to the text control default
1529 // colours for the others
1530 wxTextAttr attr
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
1532 PangoFontDescription
*font_description
= attr
.HasFont()
1533 ? attr
.GetFont().GetNativeFontInfo()->description
1536 GdkColor
*colFg
= attr
.HasTextColour() ? attr
.GetTextColour().GetColor()
1539 GdkColor
*colBg
= attr
.HasBackgroundColour()
1540 ? attr
.GetBackgroundColour().GetColor()
1544 tag
= gtk_text_buffer_create_tag( text_buffer
, NULL
, "font-desc", font_description
,
1545 "foreground-gdk", colFg
,
1546 "background-gdk", colBg
, NULL
);
1547 gtk_text_buffer_apply_tag( text_buffer
, tag
, &starti
, &endi
);
1551 // VERY dirty way to do that - removes the required text and re-adds it
1552 // with styling (FIXME)
1554 gint l
= gtk_text_get_length( GTK_TEXT(m_text
) );
1556 wxCHECK_MSG( start
>= 0 && end
<= l
, FALSE
,
1557 _T("invalid range in wxTextCtrl::SetStyle") );
1559 gint old_pos
= gtk_editable_get_position( GTK_EDITABLE(m_text
) );
1560 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), start
, end
);
1561 wxString
tmp(text
,*wxConvCurrent
);
1564 gtk_editable_delete_text( GTK_EDITABLE(m_text
), start
, end
);
1565 gtk_editable_set_position( GTK_EDITABLE(m_text
), start
);
1568 wxWX2MBbuf buf
= tmp
.mbc_str();
1569 const char *txt
= buf
;
1570 size_t txtlen
= strlen(buf
);
1572 const char *txt
= tmp
;
1573 size_t txtlen
= tmp
.length();
1576 // use the attributes from style which are set in it and fall back
1577 // first to the default style and then to the text control default
1578 // colours for the others
1579 wxGtkTextInsert(m_text
,
1580 wxTextAttr::Combine(style
, m_defaultStyle
, this),
1584 /* does not seem to help under GTK+ 1.2 !!!
1585 gtk_editable_set_position( GTK_EDITABLE(m_text), old_pos ); */
1586 SetInsertionPoint( old_pos
);
1592 // cannot do this for GTK+'s Entry widget
1597 void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
1599 gtk_widget_modify_style(m_text
, style
);
1602 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1607 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1612 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1617 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1622 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1627 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1629 event
.Enable( CanCut() );
1632 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1634 event
.Enable( CanCopy() );
1637 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1639 event
.Enable( CanPaste() );
1642 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1644 event
.Enable( CanUndo() );
1647 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1649 event
.Enable( CanRedo() );
1652 void wxTextCtrl::OnInternalIdle()
1654 wxCursor cursor
= m_cursor
;
1655 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1660 GdkWindow
*window
= (GdkWindow
*) NULL
;
1661 if (HasFlag(wxTE_MULTILINE
))
1662 window
= GTK_TEXT(m_text
)->text_area
;
1664 window
= GTK_ENTRY(m_text
)->text_area
;
1667 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1669 if (!g_globalCursor
.Ok())
1670 cursor
= *wxSTANDARD_CURSOR
;
1672 window
= m_widget
->window
;
1673 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
1674 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1678 if (g_delayedFocus
== this)
1680 if (GTK_WIDGET_REALIZED(m_widget
))
1682 gtk_widget_grab_focus( m_widget
);
1683 g_delayedFocus
= NULL
;
1687 if (wxUpdateUIEvent::CanUpdate(this))
1688 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1691 wxSize
wxTextCtrl::DoGetBestSize() const
1693 // FIXME should be different for multi-line controls...
1694 wxSize
ret( wxControl::DoGetBestSize() );
1695 wxSize
best(80, ret
.y
);
1696 CacheBestSize(best
);
1700 // ----------------------------------------------------------------------------
1702 // ----------------------------------------------------------------------------
1704 void wxTextCtrl::Freeze()
1707 if ( HasFlag(wxTE_MULTILINE
) )
1709 gtk_text_freeze(GTK_TEXT(m_text
));
1714 void wxTextCtrl::Thaw()
1717 if ( HasFlag(wxTE_MULTILINE
) )
1719 GTK_TEXT(m_text
)->vadj
->value
= 0.0;
1721 gtk_text_thaw(GTK_TEXT(m_text
));
1726 // ----------------------------------------------------------------------------
1728 // ----------------------------------------------------------------------------
1730 GtkAdjustment
*wxTextCtrl::GetVAdj() const
1732 if ( !IsMultiLine() )
1736 return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget
));
1738 return GTK_TEXT(m_text
)->vadj
;
1742 bool wxTextCtrl::DoScroll(GtkAdjustment
*adj
, int diff
)
1744 float value
= adj
->value
+ diff
;
1749 float upper
= adj
->upper
- adj
->page_size
;
1750 if ( value
> upper
)
1753 // did we noticeably change the scroll position?
1754 if ( fabs(adj
->value
- value
) < 0.2 )
1756 // well, this is what Robert does in wxScrollBar, so it must be good...
1763 gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj
));
1765 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
1771 bool wxTextCtrl::ScrollLines(int lines
)
1773 GtkAdjustment
*adj
= GetVAdj();
1778 int diff
= (int)ceil(lines
*adj
->step_increment
);
1780 // this is hardcoded to 10 in GTK+ 1.2 (great idea)
1781 int diff
= 10*lines
;
1784 return DoScroll(adj
, diff
);
1787 bool wxTextCtrl::ScrollPages(int pages
)
1789 GtkAdjustment
*adj
= GetVAdj();
1793 return DoScroll(adj
, (int)ceil(pages
*adj
->page_increment
));
1799 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1801 return GetDefaultAttributesFromGTKWidget(gtk_entry_new
, true);