]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/textctrl.cpp
Move some things to wxBitmapBase to avoid much duplication.
[wxWidgets.git] / src / gtk / textctrl.cpp
index 1c599667a9ac6ece15be13356aa5735e60904aa3..79cdce64654dd503464221035182b0f73086c281 100644 (file)
 #include "wx/gtk/private.h"
 #include <gdk/gdkkeysyms.h>
 
 #include "wx/gtk/private.h"
 #include <gdk/gdkkeysyms.h>
 
-//-----------------------------------------------------------------------------
-// data
-//-----------------------------------------------------------------------------
-
-extern wxWindowGTK *g_delayedFocus;
-
 // ----------------------------------------------------------------------------
 // helpers
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // helpers
 // ----------------------------------------------------------------------------
@@ -75,10 +69,9 @@ static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer,
 
     if (attr.HasFont())
     {
 
     if (attr.HasFont())
     {
-        char *font_string;
         PangoFontDescription *font_description = attr.GetFont().GetNativeFontInfo()->description;
         PangoFontDescription *font_description = attr.GetFont().GetNativeFontInfo()->description;
-        font_string = pango_font_description_to_string(font_description);
-        g_snprintf(buf, sizeof(buf), "WXFONT %s", font_string);
+        wxGtkString font_string(pango_font_description_to_string(font_description));
+        g_snprintf(buf, sizeof(buf), "WXFONT %s", font_string.c_str());
         tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
                                          buf );
         if (!tag)
         tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
                                          buf );
         if (!tag)
@@ -86,7 +79,6 @@ static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer,
                                               "font-desc", font_description,
                                               NULL );
         gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
                                               "font-desc", font_description,
                                               NULL );
         gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
-        g_free (font_string);
 
         if (attr.GetFont().GetUnderlined())
         {
 
         if (attr.GetFont().GetUnderlined())
         {
@@ -793,13 +785,11 @@ wxString wxTextCtrl::GetValue() const
         gtk_text_buffer_get_start_iter( m_buffer, &start );
         GtkTextIter end;
         gtk_text_buffer_get_end_iter( m_buffer, &end );
         gtk_text_buffer_get_start_iter( m_buffer, &start );
         GtkTextIter end;
         gtk_text_buffer_get_end_iter( m_buffer, &end );
-        gchar *text = gtk_text_buffer_get_text( m_buffer, &start, &end, TRUE );
+        wxGtkString text(gtk_text_buffer_get_text(m_buffer, &start, &end, true));
 
         const wxWxCharBuffer buf = wxGTK_CONV_BACK(text);
         if ( buf )
             tmp = buf;
 
         const wxWxCharBuffer buf = wxGTK_CONV_BACK(text);
         if ( buf )
             tmp = buf;
-
-        g_free( text );
     }
     else
     {
     }
     else
     {
@@ -846,7 +836,9 @@ void wxTextCtrl::SetValue( const wxString &value )
         const wxCharBuffer buffer(wxGTK_CONV_ENC(value, GetTextEncoding()));
         if ( !buffer )
         {
         const wxCharBuffer buffer(wxGTK_CONV_ENC(value, GetTextEncoding()));
         if ( !buffer )
         {
-            // what else can we do? at least don't crash...
+            // see comment in WriteText() as to why we must warn the user about
+            // this
+            wxLogWarning(_("Failed to set text in the text control."));
             return;
         }
 
             return;
         }
 
@@ -857,10 +849,11 @@ void wxTextCtrl::SetValue( const wxString &value )
     }
     else // single line
     {
     }
     else // single line
     {
-        // gtk_entry_set_text() emits two "changed" signals because internally
-        // it calls gtk_editable_delete_text() and gtk_editable_insert_text()
-        // but we want to have only one event
-        IgnoreNextTextUpdate();
+        // gtk_entry_set_text() emits two "changed" signals if the control is
+        // not empty because internally it calls gtk_editable_delete_text() and
+        // gtk_editable_insert_text() but we want to have only one event
+        if ( !GetValue().empty() )
+            IgnoreNextTextUpdate();
 
         gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) );
     }
 
         gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) );
     }
@@ -945,22 +938,22 @@ void wxTextCtrl::AppendText( const wxString &text )
 
 wxString wxTextCtrl::GetLineText( long lineNo ) const
 {
 
 wxString wxTextCtrl::GetLineText( long lineNo ) const
 {
+    wxString result;
     if ( IsMultiLine() )
     {
         GtkTextIter line;
         gtk_text_buffer_get_iter_at_line(m_buffer,&line,lineNo);
         GtkTextIter end = line;
         gtk_text_iter_forward_to_line_end(&end);
     if ( IsMultiLine() )
     {
         GtkTextIter line;
         gtk_text_buffer_get_iter_at_line(m_buffer,&line,lineNo);
         GtkTextIter end = line;
         gtk_text_iter_forward_to_line_end(&end);
-        gchar *text = gtk_text_buffer_get_text(m_buffer,&line,&end,TRUE);
-        wxString result(wxGTK_CONV_BACK(text));
-        g_free(text);
-        return result;
+        wxGtkString text(gtk_text_buffer_get_text(m_buffer, &line, &end, true));
+        result = wxGTK_CONV_BACK(text);
     }
     else
     {
     }
     else
     {
-        if (lineNo == 0) return GetValue();
-        return wxEmptyString;
+        if (lineNo == 0)
+            result = GetValue();
     }
     }
+    return result;
 }
 
 void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
 }
 
 void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
@@ -1545,15 +1538,16 @@ GtkWidget* wxTextCtrl::GetConnectWidget()
     return GTK_WIDGET(m_text);
 }
 
     return GTK_WIDGET(m_text);
 }
 
-bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
+GdkWindow *wxTextCtrl::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
 {
     if ( IsMultiLine() )
     {
 {
     if ( IsMultiLine() )
     {
-        return window == gtk_text_view_get_window( GTK_TEXT_VIEW( m_text ), GTK_TEXT_WINDOW_TEXT );  // pure guesswork
+        return gtk_text_view_get_window(GTK_TEXT_VIEW(m_text),
+                                        GTK_TEXT_WINDOW_TEXT );
     }
     else
     {
     }
     else
     {
-        return (window == GTK_ENTRY(m_text)->text_area);
+        return GTK_ENTRY(m_text)->text_area;
     }
 }
 
     }
 }
 
@@ -1715,24 +1709,6 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
     event.Enable( CanRedo() );
 }
 
     event.Enable( CanRedo() );
 }
 
-void wxTextCtrl::OnInternalIdle()
-{
-    // Check if we have to show window now
-    if (GtkShowFromOnIdle()) return;
-
-    if (g_delayedFocus == this)
-    {
-        if (GTK_WIDGET_REALIZED(m_widget))
-        {
-            gtk_widget_grab_focus( m_widget );
-            g_delayedFocus = NULL;
-        }
-    }
-    
-    if (wxUpdateUIEvent::CanUpdate(this))
-        UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
-}
-
 wxSize wxTextCtrl::DoGetBestSize() const
 {
     // FIXME should be different for multi-line controls...
 wxSize wxTextCtrl::DoGetBestSize() const
 {
     // FIXME should be different for multi-line controls...
@@ -1837,6 +1813,18 @@ void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent& event)
     GetEventHandler()->ProcessEvent(url_event);
 }
 
     GetEventHandler()->ProcessEvent(url_event);
 }
 
+bool wxTextCtrl::GTKProcessEvent(wxEvent& event) const
+{
+    bool rc = wxTextCtrlBase::GTKProcessEvent(event);
+
+    // GtkTextView starts a drag operation when left mouse button is pressed
+    // and ends it when it is released and if it doesn't get the release event
+    // the next click on a control results in an assertion failure inside
+    // gtk_text_view_start_selection_drag() which simply *kills* the program
+    // without anything we can do about it, so always let GTK+ have this event
+    return rc && (IsSingleLine() || event.GetEventType() != wxEVT_LEFT_UP);
+}
+
 // static
 wxVisualAttributes
 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
 // static
 wxVisualAttributes
 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))