From b98d804b283dc391ef112f734393696eea0a4ee4 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 11 Feb 1999 20:44:38 +0000 Subject: [PATCH] Added CTRL-TAB navigation to notebook Added ESC -> Cancel convresion Added greying out of tooltips (I had some spare minutes) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1683 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/notebook.h | 2 ++ include/wx/gtk1/notebook.h | 2 ++ samples/toolbar/test.cpp | 2 ++ src/gtk/notebook.cpp | 18 +++++++++++++++++- src/gtk/tbargtk.cpp | 35 ++++++++++++++++++++++++++++++++++- src/gtk/window.cpp | 16 ++++++++++++++-- src/gtk1/notebook.cpp | 18 +++++++++++++++++- src/gtk1/tbargtk.cpp | 35 ++++++++++++++++++++++++++++++++++- src/gtk1/window.cpp | 16 ++++++++++++++-- 9 files changed, 136 insertions(+), 8 deletions(-) diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index 1c2aa872b9..97c86e7ee9 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -153,6 +153,7 @@ public: // get the panel which represents the given page wxWindow *GetPage(int nPage) const; + void OnNavigationKey(wxNavigationKeyEvent& event); // implementation @@ -171,6 +172,7 @@ public: size_t m_idHandler; // the change page handler id DECLARE_DYNAMIC_CLASS(wxNotebook) + DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index 1c2aa872b9..97c86e7ee9 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -153,6 +153,7 @@ public: // get the panel which represents the given page wxWindow *GetPage(int nPage) const; + void OnNavigationKey(wxNavigationKeyEvent& event); // implementation @@ -171,6 +172,7 @@ public: size_t m_idHandler; // the change page handler id DECLARE_DYNAMIC_CLASS(wxNotebook) + DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index 298851bbc7..994cb5e0bf 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -140,6 +140,8 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) currentX += width + 5; toolBar->AddSeparator(); toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); + + toolBar->EnableTool( wxID_PRINT, FALSE ); toolBar->Realize(); diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 7eee0d5246..96be1af67e 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -127,6 +127,10 @@ gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNo if (g_blockEventsOnDrag) return FALSE; if (!notebook->HasVMT()) return FALSE; + + /* this code makes jumping down from the handles of the notebooks + to the actual items in the visible notebook page possible with + the down-arrow key */ if (gdk_event->keyval != GDK_Down) return FALSE; @@ -184,6 +188,10 @@ static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) +BEGIN_EVENT_TABLE(wxNotebook, wxControl) + EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) +END_EVENT_TABLE() + void wxNotebook::Init() { m_imageList = (wxImageList *) NULL; @@ -381,7 +389,7 @@ void wxNotebook::AdvanceSelection( bool bForward ) if (bForward) SetSelection( sel == max ? 0 : sel + 1 ); else - SetSelection( sel == 0 ? max : sel - 1 ); + SetSelection( sel == 0 ? max-1 : sel - 1 ); } void wxNotebook::SetImageList( wxImageList* imageList ) @@ -624,6 +632,14 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, return TRUE; } +void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) +{ + if (event.IsWindowChange()) + AdvanceSelection( event.GetDirection() ); + else + event.Skip(); +} + wxWindow *wxNotebook::GetPage( int page ) const { wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 5712f800d3..6b9e683864 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -78,8 +78,37 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) { if (g_blockEventsOnDrag) return TRUE; + + /* we grey-out the tip text of disabled tool */ + + wxToolBar *tb = tool->m_owner; + + if (tool->m_enabled) + { + if (tb->m_fg->red != 0) + { + tb->m_fg->red = 0; + tb->m_fg->green = 0; + tb->m_fg->blue = 0; + gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); + gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); + } + } + else + { + if (tb->m_fg->red == 0) + { + tb->m_fg->red = 33000; + tb->m_fg->green = 33000; + tb->m_fg->blue = 33000; + gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); + gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); + } + } + + /* emit the event */ - tool->m_owner->OnMouseEnter( tool->m_index ); + tb->OnMouseEnter( tool->m_index ); return FALSE; } @@ -301,8 +330,12 @@ void wxToolBar::EnableTool(int toolIndex, bool enable) { tool->m_enabled = enable; +/* we don't disable the tools for now as the bitmaps don't get + greyed anyway and this also disables tooltips + if (tool->m_item) gtk_widget_set_sensitive( tool->m_item, enable ); +*/ return; } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 3e33241748..369948cb0b 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -355,13 +355,25 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e ((win->m_windowStyle & wxTE_PROCESS_TAB) == 0)) { wxNavigationKeyEvent new_event; + /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); - new_event.SetWindowChange( FALSE ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); new_event.SetCurrentFocus( win ); ret = win->GetEventHandler()->ProcessEvent( new_event ); } + if ( (!ret) && + (gdk_event->keyval == GDK_Escape) ) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( win ); + ret = win->GetEventHandler()->ProcessEvent( new_event ); + } + /* + Damn, I forgot why this didn't work, but it didn't work. + // win is a panel: up can be propagated to the panel if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) && (gdk_event->keyval == GDK_Up)) @@ -501,7 +513,7 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk if (ret) { - gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" ); } return ret; diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 7eee0d5246..96be1af67e 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -127,6 +127,10 @@ gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNo if (g_blockEventsOnDrag) return FALSE; if (!notebook->HasVMT()) return FALSE; + + /* this code makes jumping down from the handles of the notebooks + to the actual items in the visible notebook page possible with + the down-arrow key */ if (gdk_event->keyval != GDK_Down) return FALSE; @@ -184,6 +188,10 @@ static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) +BEGIN_EVENT_TABLE(wxNotebook, wxControl) + EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) +END_EVENT_TABLE() + void wxNotebook::Init() { m_imageList = (wxImageList *) NULL; @@ -381,7 +389,7 @@ void wxNotebook::AdvanceSelection( bool bForward ) if (bForward) SetSelection( sel == max ? 0 : sel + 1 ); else - SetSelection( sel == 0 ? max : sel - 1 ); + SetSelection( sel == 0 ? max-1 : sel - 1 ); } void wxNotebook::SetImageList( wxImageList* imageList ) @@ -624,6 +632,14 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, return TRUE; } +void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) +{ + if (event.IsWindowChange()) + AdvanceSelection( event.GetDirection() ); + else + event.Skip(); +} + wxWindow *wxNotebook::GetPage( int page ) const { wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 5712f800d3..6b9e683864 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -78,8 +78,37 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) { if (g_blockEventsOnDrag) return TRUE; + + /* we grey-out the tip text of disabled tool */ + + wxToolBar *tb = tool->m_owner; + + if (tool->m_enabled) + { + if (tb->m_fg->red != 0) + { + tb->m_fg->red = 0; + tb->m_fg->green = 0; + tb->m_fg->blue = 0; + gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); + gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); + } + } + else + { + if (tb->m_fg->red == 0) + { + tb->m_fg->red = 33000; + tb->m_fg->green = 33000; + tb->m_fg->blue = 33000; + gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); + gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); + } + } + + /* emit the event */ - tool->m_owner->OnMouseEnter( tool->m_index ); + tb->OnMouseEnter( tool->m_index ); return FALSE; } @@ -301,8 +330,12 @@ void wxToolBar::EnableTool(int toolIndex, bool enable) { tool->m_enabled = enable; +/* we don't disable the tools for now as the bitmaps don't get + greyed anyway and this also disables tooltips + if (tool->m_item) gtk_widget_set_sensitive( tool->m_item, enable ); +*/ return; } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 3e33241748..369948cb0b 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -355,13 +355,25 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e ((win->m_windowStyle & wxTE_PROCESS_TAB) == 0)) { wxNavigationKeyEvent new_event; + /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); - new_event.SetWindowChange( FALSE ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); new_event.SetCurrentFocus( win ); ret = win->GetEventHandler()->ProcessEvent( new_event ); } + if ( (!ret) && + (gdk_event->keyval == GDK_Escape) ) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( win ); + ret = win->GetEventHandler()->ProcessEvent( new_event ); + } + /* + Damn, I forgot why this didn't work, but it didn't work. + // win is a panel: up can be propagated to the panel if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) && (gdk_event->keyval == GDK_Up)) @@ -501,7 +513,7 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk if (ret) { - gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" ); } return ret; -- 2.45.2