X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/354aa1e366a57d896e2cf0943c687b24e8db688c..5c5ab9ebc3a7dd441c9e3b25cb3daf8f733c374f:/src/gtk1/radiobox.cpp diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 9d5d677395..352ec74493 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -18,9 +18,10 @@ #include "wx/dialog.h" #include "wx/frame.h" -#include "gdk/gdk.h" -#include "gtk/gtk.h" -#include "gdk/gdkkeysyms.h" +#include +#include +#include + #include "wx/gtk/win_gtk.h" //----------------------------------------------------------------------------- @@ -34,7 +35,7 @@ extern bool g_isIdle; // data //----------------------------------------------------------------------------- -extern bool g_blockEventsOnDrag; +extern bool g_blockEventsOnDrag; //----------------------------------------------------------------------------- // "clicked" @@ -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) ); @@ -125,6 +180,16 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, m_x+10, m_y+10+(i*24), 10, 10 ); } + m_parent->DoAddChild( this ); + + PostCreation(); + + ApplyWidgetStyle(); + + SetLabel( title ); + + SetFont( parent->GetFont() ); + wxSize ls = LayoutItems(); wxSize newSize = size; @@ -132,15 +197,8 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, if (newSize.y == -1) newSize.y = ls.y; SetSize( newSize.x, newSize.y ); - m_parent->DoAddChild( this ); - - PostCreation(); - - SetLabel( title ); - SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); - SetFont( parent->GetFont() ); Show( TRUE ); @@ -334,7 +392,6 @@ void wxRadioBox::SetFocus() if (button->active) { gtk_widget_grab_focus( GTK_WIDGET(button) ); - return; } node = node->Next(); @@ -352,11 +409,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 @@ -522,7 +579,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) @@ -534,7 +591,7 @@ void wxRadioBox::DisableEvents() } } -void wxRadioBox::EnableEvents() +void wxRadioBox::GtkEnableEvents() { wxNode *node = m_boxes.First(); while (node) @@ -565,6 +622,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;