]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/radiobox.cpp
Corrected some things in, and some thing revealed by
[wxWidgets.git] / src / gtk / radiobox.cpp
index 05dde830a4ada99020184e6ba00449441c9c5ac2..6dda8dc6c4ff0eef59272fc33567036ab672a29a 100644 (file)
 #include "wx/dialog.h"
 #include "wx/frame.h"
 
-#include "gdk/gdk.h"
-#include "gtk/gtk.h"
-#include "gdk/gdkkeysyms.h"
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
 #include "wx/gtk/win_gtk.h"
 
 //-----------------------------------------------------------------------------
@@ -62,6 +63,57 @@ static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRad
     rb->GetEventHandler()->ProcessEvent(event);
 }
 
+//-----------------------------------------------------------------------------
+// "key_press_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
+{
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
+    if (!rb->m_hasVMT) return FALSE;
+    if (g_blockEventsOnDrag) return FALSE;
+
+    if ((gdk_event->keyval != GDK_Up) &&
+        (gdk_event->keyval != GDK_Down) &&
+        (gdk_event->keyval != GDK_Left) &&
+        (gdk_event->keyval != GDK_Right))
+    {
+        return FALSE;
+    }
+    
+    wxNode *node = rb->m_boxes.Find( (wxObject*) widget );
+    if (!node)
+    {
+        return FALSE;
+    }
+    
+    gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
+    
+    if ((gdk_event->keyval == GDK_Up) ||
+        (gdk_event->keyval == GDK_Left))
+    {
+        if (node == rb->m_boxes.First())
+           node = rb->m_boxes.Last();
+       else
+           node = node->Previous();
+    }
+    else
+    {
+        if (node == rb->m_boxes.Last())
+           node = rb->m_boxes.First();
+       else
+           node = node->Next();
+    }
+    
+    GtkWidget *button = (GtkWidget*) node->Data();
+       
+    gtk_widget_grab_focus( button );
+    
+    return TRUE;
+}
+
 //-----------------------------------------------------------------------------
 // wxRadioBox
 //-----------------------------------------------------------------------------
@@ -111,6 +163,9 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
 
         m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) );
 
+        gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
+           GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
+          
         m_boxes.Append( (wxObject*) m_radio );
 
         ConnectWidget( GTK_WIDGET(m_radio) );
@@ -351,11 +406,11 @@ void wxRadioBox::SetSelection( int n )
 
     GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
 
-    DisableEvents();
+    GtkDisableEvents();
     
     gtk_toggle_button_set_state( button, 1 );
     
-    EnableEvents();
+    GtkEnableEvents();
 }
 
 int wxRadioBox::GetSelection(void) const
@@ -521,7 +576,7 @@ void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
     wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented."));
 }
 
-void wxRadioBox::DisableEvents()
+void wxRadioBox::GtkDisableEvents()
 {
     wxNode *node = m_boxes.First();
     while (node)
@@ -533,7 +588,7 @@ void wxRadioBox::DisableEvents()
     }
 }
 
-void wxRadioBox::EnableEvents()
+void wxRadioBox::GtkEnableEvents()
 {
     wxNode *node = m_boxes.First();
     while (node)
@@ -564,6 +619,19 @@ void wxRadioBox::ApplyWidgetStyle()
     }
 }
 
+#if wxUSE_TOOLTIPS
+void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
+{
+    wxNode *node = m_boxes.First();
+    while (node)
+    {
+        GtkWidget *widget = GTK_WIDGET( node->Data() );
+        gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
+        node = node->Next();
+    }
+}
+#endif // wxUSE_TOOLTIPS
+
 bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
 {
     if (window == m_widget->window) return TRUE;