X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4db172a3b318df9aff178eb6c5da149d56e0859..b5fe65c81983fb99a7937592a6ddda236f7dc4d0:/src/gtk1/textctrl.cpp diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 36ac27ffd4..41caee9f64 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -13,21 +13,22 @@ #include "wx/textctrl.h" #ifndef WX_PRECOMP + #include "wx/app.h" #include "wx/intl.h" #include "wx/log.h" + #include "wx/utils.h" + #include "wx/panel.h" + #include "wx/settings.h" + #include "wx/math.h" #endif -#include "wx/utils.h" -#include "wx/math.h" -#include "wx/settings.h" -#include "wx/panel.h" #include "wx/strconv.h" #include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo()) +#include "wx/evtloop.h" #include #include #include -#include "wx/math.h" #include "wx/gtk1/private.h" #include @@ -56,8 +57,21 @@ static void wxGtkTextInsert(GtkWidget *text, const char *txt, size_t len) { - GdkFont *font = attr.HasFont() ? attr.GetFont().GetInternalFont() - : NULL; + wxFont tmpFont; + GdkFont *font; + if (attr.HasFont()) + { + tmpFont = attr.GetFont(); + + // FIXME: if this crashes because tmpFont goes out of scope and the GdkFont is + // deleted, then we need to call gdk_font_ref on font. + // This is because attr.GetFont() now returns a temporary font since wxTextAttr + // no longer stores a wxFont object, for efficiency. + + font = tmpFont.GetInternalFont(); + } + else + font = NULL; GdkColor *colFg = attr.HasTextColour() ? attr.GetTextColour().GetColor() : NULL; @@ -77,9 +91,9 @@ static void wxGtkTextInsert(GtkWidget *text, extern "C" { static void gtk_insert_text_callback(GtkEditable *editable, - const gchar *new_text, - gint new_text_length, - gint *position, + const gchar *WXUNUSED(new_text), + gint WXUNUSED(new_text_length), + gint *WXUNUSED(position), wxTextCtrl *win) { if (g_isIdle) @@ -88,7 +102,7 @@ gtk_insert_text_callback(GtkEditable *editable, // we should only be called if we have a max len limit at all GtkEntry *entry = GTK_ENTRY (editable); - wxCHECK_RET( entry->text_max_length, _T("shouldn't be called") ); + wxCHECK_RET( entry->text_max_length, wxT("shouldn't be called") ); // check that we don't overflow the max length limit // @@ -107,7 +121,7 @@ gtk_insert_text_callback(GtkEditable *editable, wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, win->GetId()); event.SetEventObject(win); event.SetString(win->GetValue()); - win->GetEventHandler()->ProcessEvent( event ); + win->HandleWindowEvent( event ); } } } @@ -118,7 +132,7 @@ gtk_insert_text_callback(GtkEditable *editable, extern "C" { static void -gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) +gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { if ( win->IgnoreTextUpdate() ) return; @@ -133,7 +147,7 @@ gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win ) wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->HandleWindowEvent( event ); } } @@ -163,8 +177,6 @@ gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) // which implicitly calls wxYield()) so we override GtkText::draw() and simply // don't do anything if we're inside wxYield() -extern bool wxIsInsideYield; - extern "C" { typedef void (*GtkDrawCallback)(GtkWidget *widget, GdkRectangle *rect); } @@ -174,10 +186,11 @@ static GtkDrawCallback gs_gtk_text_draw = NULL; extern "C" { static void wxgtk_text_draw( GtkWidget *widget, GdkRectangle *rect) { - if ( !wxIsInsideYield ) + wxEventLoopBase* loop = wxEventLoopBase::GetActive(); + if ( loop && !loop->IsYielding() ) { wxCHECK_RET( gs_gtk_text_draw != wxgtk_text_draw, - _T("infinite recursion in wxgtk_text_draw aborted") ); + wxT("infinite recursion in wxgtk_text_draw aborted") ); gs_gtk_text_draw(widget, rect); } @@ -188,9 +201,9 @@ static void wxgtk_text_draw( GtkWidget *widget, GdkRectangle *rect) // wxTextCtrl //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) -BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) +BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_CHAR(wxTextCtrl::OnChar) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) @@ -212,7 +225,7 @@ void wxTextCtrl::Init() m_modified = false; SetUpdateFont(false); m_text = - m_vScrollbar = (GtkWidget *)NULL; + m_vScrollbar = NULL; } wxTextCtrl::~wxTextCtrl() @@ -260,7 +273,7 @@ bool wxTextCtrl::Create( wxWindow *parent, if (multi_line) { // create our control ... - m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); + m_text = gtk_text_new( NULL, NULL ); // ... and put into the upper left hand corner of the table bool bHasHScrollbar = false; @@ -393,7 +406,7 @@ void wxTextCtrl::CalculateScrollbar() } } -wxString wxTextCtrl::GetValue() const +wxString wxTextCtrl::DoGetValue() const { wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") ); @@ -413,10 +426,16 @@ wxString wxTextCtrl::GetValue() const return tmp; } -void wxTextCtrl::SetValue( const wxString &value ) +void wxTextCtrl::DoSetValue( const wxString &value, int flags ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); + if ( !(flags & SetValue_SendEvent) ) + { + // do not generate events + IgnoreNextTextUpdate(); + } + if (m_windowStyle & wxTE_MULTILINE) { gint len = gtk_text_get_length( GTK_TEXT(m_text) ); @@ -458,7 +477,7 @@ void wxTextCtrl::WriteText( const wxString &text ) // resetting the style and appending some more text wouldn't work: if // we don't specify the style explicitly, the old style would be used gtk_editable_delete_selection( GTK_EDITABLE(m_text) ); - wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.Len()); + wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.length()); // we called wxGtkTextInsert with correct font, no need to do anything // in UpdateFontIfNeeded() any longer @@ -478,7 +497,7 @@ void wxTextCtrl::WriteText( const wxString &text ) // This moves the cursor pos to behind the inserted text. gint len = GET_EDITABLE_POS(m_text); - gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.Len(), &len ); + gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.length(), &len ); // Bring entry's cursor uptodate. gtk_entry_set_position( GTK_ENTRY(m_text), len ); @@ -542,7 +561,7 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const wxString text = GetValue(); // cast to prevent warning. But pos really should've been unsigned. - if( (unsigned long)pos > text.Len() ) + if( (unsigned long)pos > text.length() ) return false; *x=0; // First Col @@ -685,32 +704,26 @@ void wxTextCtrl::SetEditable( bool editable ) } } -bool wxTextCtrl::Enable( bool enable ) +void wxTextCtrl::DoEnable( bool enable ) { - if (!wxWindowBase::Enable(enable)) - { - // nothing to do - return false; - } - if (m_windowStyle & wxTE_MULTILINE) { gtk_text_set_editable( GTK_TEXT(m_text), enable ); - OnParentEnable(enable); } else { gtk_widget_set_sensitive( m_text, enable ); } - - return true; } // wxGTK-specific: called recursively by Enable, // to give widgets an oppprtunity to correct their colours after they // have been changed by Enable -void wxTextCtrl::OnParentEnable( bool enable ) +void wxTextCtrl::OnEnabled( bool WXUNUSED(enable) ) { + if ( IsSingleLine() ) + return; + // If we have a custom background colour, we use this colour in both // disabled and enabled mode, or we end up with a different colour under the // text. @@ -805,7 +818,7 @@ void wxTextCtrl::SetSelection( long from, long to ) !GTK_TEXT(m_text)->line_start_cache ) { // tell the programmer that it didn't work - wxLogDebug(_T("Can't call SetSelection() before realizing the control")); + wxLogDebug(wxT("Can't call SetSelection() before realizing the control")); return; } @@ -987,7 +1000,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject(this); event.SetString(GetValue()); - if (GetEventHandler()->ProcessEvent(event)) return; + if (HandleWindowEvent(event)) return; } if ((key_event.GetKeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE)) @@ -1060,7 +1073,7 @@ void wxTextCtrl::ChangeFontGlobally() // possible! wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont, - _T("shouldn't be called for single line controls") ); + wxT("shouldn't be called for single line controls") ); wxString value = GetValue(); if ( !value.empty() ) @@ -1134,7 +1147,7 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) gint l = gtk_text_get_length( GTK_TEXT(m_text) ); wxCHECK_MSG( start >= 0 && end <= l, false, - _T("invalid range in wxTextCtrl::SetStyle") ); + wxT("invalid range in wxTextCtrl::SetStyle") ); gint old_pos = gtk_editable_get_position( GTK_EDITABLE(m_text) ); char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), start, end ); @@ -1235,7 +1248,7 @@ void wxTextCtrl::OnInternalIdle() if (cursor.Ok()) { - GdkWindow *window = (GdkWindow*) NULL; + GdkWindow *window = NULL; if (HasFlag(wxTE_MULTILINE)) window = GTK_TEXT(m_text)->text_area; else @@ -1278,7 +1291,7 @@ wxSize wxTextCtrl::DoGetBestSize() const // freeze/thaw // ---------------------------------------------------------------------------- -void wxTextCtrl::Freeze() +void wxTextCtrl::DoFreeze() { if ( HasFlag(wxTE_MULTILINE) ) { @@ -1286,7 +1299,7 @@ void wxTextCtrl::Freeze() } } -void wxTextCtrl::Thaw() +void wxTextCtrl::DoThaw() { if ( HasFlag(wxTE_MULTILINE) ) {