X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/692c9b869686c97963c693e99efba19edeaba8cc..600902562da4b1008c006a1d9daca40fc932b7ef:/src/gtk1/textctrl.cpp diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 9def3e02e4..94718d2f35 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -155,7 +155,9 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) wxapp_install_idle_handler(); win->SetModified(); +#ifndef __WXGTK20__ win->UpdateFontIfNeeded(); +#endif // !__WXGTK20__ wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); @@ -239,7 +241,7 @@ void wxTextCtrl::Init() { m_ignoreNextUpdate = m_modified = FALSE; - m_updateFont = FALSE; + SetUpdateFont(FALSE); m_text = m_vScrollbar = (GtkWidget *)NULL; } @@ -577,6 +579,11 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( text.empty() ) return; + // gtk_text_changed_callback() will set m_modified to true but m_modified + // shouldn't be changed by the program writing to the text control itself, + // so save the old value and restore when we're done + bool oldModified = m_modified; + if ( m_windowStyle & wxTE_MULTILINE ) { #ifdef __WXGTK20__ @@ -586,6 +593,12 @@ void wxTextCtrl::WriteText( const wxString &text ) #else wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) ); #endif + if ( !buffer ) + { + // what else can we do? at least don't crash... + return; + } + GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); // TODO: Call whatever is needed to delete the selection. @@ -612,7 +625,7 @@ void wxTextCtrl::WriteText( const wxString &text ) // in UpdateFontIfNeeded() any longer if ( !text.empty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); } // Bring editable's cursor back uptodate. @@ -644,7 +657,7 @@ void wxTextCtrl::WriteText( const wxString &text ) gtk_entry_set_position( GTK_ENTRY(m_text), len ); } - m_modified = TRUE; + m_modified = oldModified; } void wxTextCtrl::AppendText( const wxString &text ) @@ -808,14 +821,19 @@ void wxTextCtrl::SetInsertionPoint( long pos ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); - if (m_windowStyle & wxTE_MULTILINE) + if ( IsMultiLine() ) { #ifdef __WXGTK20__ GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) ); GtkTextIter iter; gtk_text_buffer_get_iter_at_offset( text_buffer, &iter, pos ); gtk_text_buffer_place_cursor( text_buffer, &iter ); -#else + gtk_text_view_scroll_mark_onscreen + ( + GTK_TEXT_VIEW(m_text), + gtk_text_buffer_get_insert( text_buffer ) + ); +#else // GTK+ 1.x gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); @@ -832,7 +850,7 @@ void wxTextCtrl::SetInsertionPoint( long pos ) // bring editable's cursor uptodate. Bug in GTK. SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) )); -#endif +#endif // GTK+ 2/1 } else { @@ -1401,7 +1419,7 @@ bool wxTextCtrl::SetFont( const wxFont &font ) if ( m_windowStyle & wxTE_MULTILINE ) { - m_updateFont = TRUE; + SetUpdateFont(TRUE); m_defaultStyle.SetFont(font); @@ -1415,25 +1433,37 @@ void wxTextCtrl::ChangeFontGlobally() { // this method is very inefficient and hence should be called as rarely as // possible! + // + // TODO: it can be implemented much more efficiently for GTK2 +#ifndef __WXGTK20__ wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont, + _T("shouldn't be called for single line controls") ); +#else + wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE), + _T("shouldn't be called for single line controls") ); +#endif wxString value = GetValue(); if ( !value.IsEmpty() ) { - m_updateFont = FALSE; + SetUpdateFont(FALSE); Clear(); AppendText(value); } } +#ifndef __WXGTK20__ + void wxTextCtrl::UpdateFontIfNeeded() { if ( m_updateFont ) ChangeFontGlobally(); } +#endif // GTK+ 1.x + bool wxTextCtrl::SetForegroundColour(const wxColour& colour) { if ( !wxControl::SetForegroundColour(colour) ) @@ -1701,16 +1731,18 @@ void wxTextCtrl::Thaw() GtkAdjustment *wxTextCtrl::GetVAdj() const { + if ( !IsMultiLine() ) + return NULL; + #ifdef __WXGTK20__ - return NULL; + return gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(m_widget)); #else - return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL; + return GTK_TEXT(m_text)->vadj; #endif } bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) { -#ifndef __WXGTK20__ float value = adj->value + diff; if ( value < 0 ) @@ -1729,39 +1761,38 @@ bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) adj->value = value; +#ifdef __WXGTK20__ + gtk_adjustment_value_changed(GTK_ADJUSTMENT(adj)); +#else gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); - #endif + return TRUE; } bool wxTextCtrl::ScrollLines(int lines) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; +#ifdef __WXGTK20__ + int diff = (int)ceil(lines*adj->step_increment); +#else // this is hardcoded to 10 in GTK+ 1.2 (great idea) - static const int KEY_SCROLL_PIXELS = 10; - - return DoScroll(adj, lines*KEY_SCROLL_PIXELS); + int diff = 10*lines; #endif + + return DoScroll(adj, diff); } bool wxTextCtrl::ScrollPages(int pages) { -#ifdef __WXGTK20__ - return FALSE; -#else GtkAdjustment *adj = GetVAdj(); if ( !adj ) return FALSE; return DoScroll(adj, (int)ceil(pages*adj->page_increment)); -#endif }