]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/textctrl.cpp
add GetValue,GetRange and GetMessage helpers
[wxWidgets.git] / src / gtk / textctrl.cpp
index 7e5b5f5472b761bfa86711b3d290f2e9f38b6317..8d5648bd771f946606161dbfcef2c8e2493d72a4 100644 (file)
@@ -494,6 +494,27 @@ au_delete_range_callback(GtkTextBuffer * WXUNUSED(buffer),
 }
 }
 
+//-----------------------------------------------------------------------------
+//  "populate_popup" from text control and "unmap" from its poup menu
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void
+gtk_textctrl_popup_unmap( GtkMenu *WXUNUSED(menu), wxTextCtrl* win )
+{
+    win->GTKEnableFocusOutEvent();
+}
+}
+
+extern "C" {
+static void
+gtk_textctrl_populate_popup( GtkEntry *WXUNUSED(entry), GtkMenu *menu, wxTextCtrl *win )
+{
+    win->GTKDisableFocusOutEvent();
+
+    g_signal_connect (menu, "unmap", G_CALLBACK (gtk_textctrl_popup_unmap), win );
+}
+}
 
 //-----------------------------------------------------------------------------
 //  "changed"
@@ -501,7 +522,7 @@ au_delete_range_callback(GtkTextBuffer * WXUNUSED(buffer),
 
 extern "C" {
 static void
-gtk_text_changed_callback( GtkWidget * WXUNUSED(widget), wxTextCtrl *win )
+gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
 {
     if ( win->IgnoreTextUpdate() )
         return;
@@ -685,8 +706,9 @@ bool wxTextCtrl::Create( wxWindow *parent,
 
         if (style & wxNO_BORDER)
             g_object_set (m_text, "has-frame", FALSE, NULL);
-            
+
     }
+    g_object_ref(m_widget);
 
     m_parent->DoAddChild( this );
 
@@ -711,6 +733,11 @@ bool wxTextCtrl::Create( wxWindow *parent,
                           G_CALLBACK (gtk_text_changed_callback), this);
     }
 
+    // Catch to disable focus out handling
+    g_signal_connect (m_text, "populate_popup",
+                      G_CALLBACK (gtk_textctrl_populate_popup),
+                      this);
+
     if (!value.empty())
     {
         SetValue( value );
@@ -959,16 +986,16 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags )
     {
         if ( !(flags & SetValue_SendEvent) )
             EnableTextChangedEvents(false);
-        
+
         gtk_text_buffer_set_text( m_buffer, "", 0 );
-            
+
         if ( !(flags & SetValue_SendEvent) )
             EnableTextChangedEvents(true);
-            
+
         return;
     }
 
-#ifdef wxUSE_UNICODE
+#if wxUSE_UNICODE
     const wxCharBuffer buffer(value.utf8_str());
 #else
     wxFontEncoding enc = m_defaultStyle.HasFont()
@@ -1006,9 +1033,6 @@ void wxTextCtrl::DoSetValue( const wxString &value, int flags )
     {
         EnableTextChangedEvents(true);
     }
-
-    // This was added after discussion on the list
-    SetInsertionPoint(0);
 }
 
 void wxTextCtrl::WriteText( const wxString &text )
@@ -1024,7 +1048,7 @@ void wxTextCtrl::WriteText( const wxString &text )
         return;
     }
 
-#ifdef wxUSE_UNICODE
+#if wxUSE_UNICODE
     const wxCharBuffer buffer(text.utf8_str());
 #else
     // check if we have a specific style for the current position
@@ -1320,7 +1344,7 @@ void wxTextCtrl::SetSelection( long from, long to )
         gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
         gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
 
-        gtk_text_buffer_place_cursor( m_buffer, &toi );
+        gtk_text_buffer_place_cursor( m_buffer, &fromi );
         gtk_text_buffer_move_mark_by_name( m_buffer, "selection_bound", &fromi );
     }
     else // single line