X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a4cb8587164bcadbc8a85ddac5c4a6dbfc43e2aa..14722c43c30918cd8fbba956b50ac3426d2fe339:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 1695375359..613f33abf5 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -666,6 +666,16 @@ static void wxFillOtherKeyEventFields(wxKeyEvent& event, event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0; + // At least with current Linux systems, MOD5 corresponds to AltGr key and + // we represent it, for consistency with Windows, which really allows to + // use Ctrl+Alt as a replacement for AltGr if this key is not present, as a + // combination of these two modifiers. + if ( gdk_event->state & GDK_MOD5_MASK ) + { + event.m_controlDown = + event.m_altDown = true; + } + // Normally we take the state of modifiers directly from the low level GDK // event but unfortunately GDK uses a different convention from MSW for the // key events corresponding to the modifier keys themselves: in it, when @@ -711,8 +721,6 @@ static void wxFillOtherKeyEventFields(wxKeyEvent& event, event.m_rawCode = (wxUint32) gdk_event->keyval; event.m_rawFlags = gdk_event->hardware_keycode; - wxGetMousePosition(&event.m_x, &event.m_y); - win->ScreenToClient(&event.m_x, &event.m_y); event.SetEventObject( win ); } @@ -951,8 +959,37 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), return TRUE; } - // Emit KEY_DOWN event - ret = win->HandleWindowEvent( event ); + // Next check for accelerators. +#if wxUSE_ACCEL + wxWindowGTK *ancestor = win; + while (ancestor) + { + int command = ancestor->GetAcceleratorTable()->GetCommand( event ); + if (command != -1) + { + wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command ); + ret = ancestor->HandleWindowEvent( menu_event ); + + if ( !ret ) + { + // if the accelerator wasn't handled as menu event, try + // it as button click (for compatibility with other + // platforms): + wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command ); + ret = ancestor->HandleWindowEvent( button_event ); + } + + break; + } + if (ancestor->IsTopLevel()) + break; + ancestor = ancestor->GetParent(); + } +#endif // wxUSE_ACCEL + + // If not an accelerator, then emit KEY_DOWN event + if ( !ret ) + ret = win->HandleWindowEvent( event ); } else { @@ -981,44 +1018,13 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), if (return_after_IM) return FALSE; -#if wxUSE_ACCEL - if (!ret) - { - wxWindowGTK *ancestor = win; - while (ancestor) - { - int command = ancestor->GetAcceleratorTable()->GetCommand( event ); - if (command != -1) - { - wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command ); - ret = ancestor->HandleWindowEvent( menu_event ); - - if ( !ret ) - { - // if the accelerator wasn't handled as menu event, try - // it as button click (for compatibility with other - // platforms): - wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command ); - ret = ancestor->HandleWindowEvent( button_event ); - } - - break; - } - if (ancestor->IsTopLevel()) - break; - ancestor = ancestor->GetParent(); - } - } -#endif // wxUSE_ACCEL - // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x // will only be sent if it is not in an accelerator table. if (!ret) { - long key_code; KeySym keysym = gdk_event->keyval; // Find key code for EVT_CHAR and EVT_CHAR_HOOK events - key_code = wxTranslateKeySymToWXKey(keysym, true /* isChar */); + long key_code = wxTranslateKeySymToWXKey(keysym, true /* isChar */); if ( !key_code ) { if ( wxIsAsciiKeysym(keysym) ) @@ -1040,6 +1046,9 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), key_code); eventChar.m_keyCode = key_code; +#if wxUSE_UNICODE + eventChar.m_uniChar = gdk_keyval_to_unicode(key_code); +#endif // wxUSE_UNICODE AdjustCharEventKeyCodes(eventChar); @@ -2205,6 +2214,71 @@ wxWindowGTK::wxWindowGTK( wxWindow *parent, Create( parent, id, pos, size, style, name ); } +void wxWindowGTK::GTKCreateScrolledWindowWith(GtkWidget* view) +{ + wxASSERT_MSG( HasFlag(wxHSCROLL) || HasFlag(wxVSCROLL), + wxS("Must not be called if scrolling is not needed.") ); + + m_widget = gtk_scrolled_window_new( NULL, NULL ); + + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + + // There is a conflict with default bindings at GTK+ + // level between scrolled windows and notebooks both of which want to use + // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal + // direction and notebooks for changing pages -- we decide that if we don't + // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it + // means we can get working keyboard navigation in notebooks + if ( !HasFlag(wxHSCROLL) ) + { + GtkBindingSet * + bindings = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget)); + if ( bindings ) + { + gtk_binding_entry_remove(bindings, GDK_Page_Up, GDK_CONTROL_MASK); + gtk_binding_entry_remove(bindings, GDK_Page_Down, GDK_CONTROL_MASK); + } + } + + if (HasFlag(wxALWAYS_SHOW_SB)) + { + gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS ); + } + else + { + gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); + } + + m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow)); + m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow)); + if (GetLayoutDirection() == wxLayout_RightToLeft) + gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE ); + + gtk_container_add( GTK_CONTAINER(m_widget), view ); + + // connect various scroll-related events + for ( int dir = 0; dir < ScrollDir_Max; dir++ ) + { + // these handlers block mouse events to any window during scrolling + // such as motion events and prevent GTK and wxWidgets from fighting + // over where the slider should be + g_signal_connect(m_scrollBar[dir], "button_press_event", + G_CALLBACK(gtk_scrollbar_button_press_event), this); + g_signal_connect(m_scrollBar[dir], "button_release_event", + G_CALLBACK(gtk_scrollbar_button_release_event), this); + + gulong handler_id = g_signal_connect(m_scrollBar[dir], "event_after", + G_CALLBACK(gtk_scrollbar_event_after), this); + g_signal_handler_block(m_scrollBar[dir], handler_id); + + // these handlers get notified when scrollbar slider moves + g_signal_connect_after(m_scrollBar[dir], "value_changed", + G_CALLBACK(gtk_scrollbar_value_changed), this); + } + + gtk_widget_show( view ); +} + bool wxWindowGTK::Create( wxWindow *parent, wxWindowID id, const wxPoint &pos, @@ -2243,66 +2317,7 @@ bool wxWindowGTK::Create( wxWindow *parent, if (!HasFlag(wxHSCROLL) && !HasFlag(wxVSCROLL)) m_widget = m_wxwindow; else - { - m_widget = gtk_scrolled_window_new( NULL, NULL ); - - GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); - - // There is a conflict with default bindings at GTK+ - // level between scrolled windows and notebooks both of which want to use - // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal - // direction and notebooks for changing pages -- we decide that if we don't - // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it - // means we can get working keyboard navigation in notebooks - if ( !HasFlag(wxHSCROLL) ) - { - GtkBindingSet * - bindings = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget)); - if ( bindings ) - { - gtk_binding_entry_remove(bindings, GDK_Page_Up, GDK_CONTROL_MASK); - gtk_binding_entry_remove(bindings, GDK_Page_Down, GDK_CONTROL_MASK); - } - } - - if (HasFlag(wxALWAYS_SHOW_SB)) - { - gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS ); - } - else - { - gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); - } - - m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow)); - m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow)); - if (GetLayoutDirection() == wxLayout_RightToLeft) - gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE ); - - gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); - - // connect various scroll-related events - for ( int dir = 0; dir < ScrollDir_Max; dir++ ) - { - // these handlers block mouse events to any window during scrolling - // such as motion events and prevent GTK and wxWidgets from fighting - // over where the slider should be - g_signal_connect(m_scrollBar[dir], "button_press_event", - G_CALLBACK(gtk_scrollbar_button_press_event), this); - g_signal_connect(m_scrollBar[dir], "button_release_event", - G_CALLBACK(gtk_scrollbar_button_release_event), this); - - gulong handler_id = g_signal_connect(m_scrollBar[dir], "event_after", - G_CALLBACK(gtk_scrollbar_event_after), this); - g_signal_handler_block(m_scrollBar[dir], handler_id); - - // these handlers get notified when scrollbar slider moves - g_signal_connect_after(m_scrollBar[dir], "value_changed", - G_CALLBACK(gtk_scrollbar_value_changed), this); - } - - gtk_widget_show( m_wxwindow ); - } + GTKCreateScrolledWindowWith(m_wxwindow); g_object_ref(m_widget); if (m_parent)