Kaydet (Commit) 3f6fcaa9 authored tarafından Jim Raykowski's avatar Jim Raykowski

tdf#105881 Toolbar keyboard navigation fixes

This patch makes toolbar keyboard navigation wrap to the begining or end
toolbar item and enables access to the overflow menu using the keyboard.

Change-Id: I5975b0f731beb00cf26f8e8a33e6ea4fa9322881
Reviewed-on: https://gerrit.libreoffice.org/71718
Tested-by: Jenkins
Reviewed-by: 's avatarJim Raykowski <raykowj@gmail.com>
üst 7ca7d61d
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include <comphelper/sequence.hxx> #include <comphelper/sequence.hxx>
#include <svtools/miscopt.hxx> #include <svtools/miscopt.hxx>
#include <svtools/imgdef.hxx> #include <svtools/imgdef.hxx>
#include <vcl/event.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/menu.hxx> #include <vcl/menu.hxx>
#include <vcl/syswin.hxx> #include <vcl/syswin.hxx>
...@@ -1567,6 +1568,13 @@ IMPL_LINK( ToolBarManager, MenuButton, ToolBox*, pToolBar, void ) ...@@ -1567,6 +1568,13 @@ IMPL_LINK( ToolBarManager, MenuButton, ToolBox*, pToolBar, void )
pOverflowToolBar->EnableDocking(); pOverflowToolBar->EnableDocking();
pOverflowToolBar->AddEventListener( LINK( this, ToolBarManager, OverflowEventListener ) ); pOverflowToolBar->AddEventListener( LINK( this, ToolBarManager, OverflowEventListener ) );
vcl::Window::GetDockingManager()->StartPopupMode( pToolBar, pOverflowToolBar, FloatWinPopupFlags::AllMouseButtonClose ); vcl::Window::GetDockingManager()->StartPopupMode( pToolBar, pOverflowToolBar, FloatWinPopupFlags::AllMouseButtonClose );
// send HOME key to subtoolbar in order to select first item if keyboard activated
if(pToolBar->IsKeyEvent() )
{
::KeyEvent aEvent( 0, vcl::KeyCode( KEY_HOME ) );
pOverflowToolBar->KeyInput(aEvent);
}
} }
IMPL_LINK( ToolBarManager, OverflowEventListener, VclWindowEvent&, rWindowEvent, void ) IMPL_LINK( ToolBarManager, OverflowEventListener, VclWindowEvent&, rWindowEvent, void )
......
...@@ -147,6 +147,7 @@ struct ImplToolBoxPrivateData ...@@ -147,6 +147,7 @@ struct ImplToolBoxPrivateData
mbKeyInputDisabled:1, // no KEY input if all items disabled, closing/docking will be allowed though mbKeyInputDisabled:1, // no KEY input if all items disabled, closing/docking will be allowed though
mbIsPaintLocked:1, // don't allow paints mbIsPaintLocked:1, // don't allow paints
mbMenubuttonSelected:1, // menu button is highlighted mbMenubuttonSelected:1, // menu button is highlighted
mbMenubuttonWasLastSelected:1, // menu button was highlighted when focus was lost
mbNativeButtons:1, // system supports native toolbar buttons mbNativeButtons:1, // system supports native toolbar buttons
mbWillUsePopupMode:1, // this toolbox will be opened in popup mode mbWillUsePopupMode:1, // this toolbox will be opened in popup mode
mbDropDownByKeyboard:1; // tells whether a dropdown was started by key input mbDropDownByKeyboard:1; // tells whether a dropdown was started by key input
......
...@@ -3896,11 +3896,20 @@ bool ToolBox::EventNotify( NotifyEvent& rNEvt ) ...@@ -3896,11 +3896,20 @@ bool ToolBox::EventNotify( NotifyEvent& rNEvt )
if( rNEvt.GetWindow() == this ) if( rNEvt.GetWindow() == this )
{ {
// the toolbar itself got the focus // the toolbar itself got the focus
if( mnLastFocusItemId != 0 ) if( mnLastFocusItemId != 0 || mpData->mbMenubuttonWasLastSelected )
{ {
// restore last item // restore last item
ImplChangeHighlight( ImplGetItem( mnLastFocusItemId ) ); if( mpData->mbMenubuttonWasLastSelected )
mnLastFocusItemId = 0; {
ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton();
}
else
{
ImplChangeHighlight( ImplGetItem( mnLastFocusItemId ) );
mnLastFocusItemId = 0;
}
} }
else if( (GetGetFocusFlags() & (GetFocusFlags::Backward|GetFocusFlags::Tab) ) == (GetFocusFlags::Backward|GetFocusFlags::Tab)) else if( (GetGetFocusFlags() & (GetFocusFlags::Backward|GetFocusFlags::Tab) ) == (GetFocusFlags::Backward|GetFocusFlags::Tab))
// Shift-TAB was pressed in the parent // Shift-TAB was pressed in the parent
...@@ -3934,6 +3943,7 @@ bool ToolBox::EventNotify( NotifyEvent& rNEvt ) ...@@ -3934,6 +3943,7 @@ bool ToolBox::EventNotify( NotifyEvent& rNEvt )
{ {
// deselect // deselect
ImplHideFocus(); ImplHideFocus();
mpData->mbMenubuttonWasLastSelected = false;
mnHighItemId = 0; mnHighItemId = 0;
mnCurPos = ITEM_NOTFOUND; mnCurPos = ITEM_NOTFOUND;
} }
...@@ -4458,18 +4468,17 @@ bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode ) ...@@ -4458,18 +4468,17 @@ bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode )
{ {
if( ImplCloseLastPopup( GetParent() ) ) if( ImplCloseLastPopup( GetParent() ) )
return bRet; return bRet;
mbIsKeyEvent = true;
if ( maMenuButtonHdl.IsSet() ) if ( maMenuButtonHdl.IsSet() )
maMenuButtonHdl.Call( this ); maMenuButtonHdl.Call( this );
else else
ExecuteCustomMenu( mpData->maMenubuttonItem.maRect ); ExecuteCustomMenu( mpData->maMenubuttonItem.maRect );
mpData->mbMenubuttonWasLastSelected = true;
mbIsKeyEvent = false;
} }
else if( mnHighItemId && ImplGetItem( mnHighItemId ) && else if( mnHighItemId && ImplGetItem( mnHighItemId ) &&
(ImplGetItem( mnHighItemId )->mnBits & ToolBoxItemBits::DROPDOWN) ) (ImplGetItem( mnHighItemId )->mnBits & ToolBoxItemBits::DROPDOWN) )
{ {
if( ImplCloseLastPopup( GetParent() ) )
return bRet;
mnDownItemId = mnCurItemId = mnHighItemId; mnDownItemId = mnCurItemId = mnHighItemId;
mnCurPos = GetItemPos( mnCurItemId ); mnCurPos = GetItemPos( mnCurItemId );
mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
...@@ -4844,6 +4853,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4844,6 +4853,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
// menubutton highlighted ? // menubutton highlighted ?
if( mpData->mbMenubuttonSelected ) if( mpData->mbMenubuttonSelected )
{ {
mpData->mbMenubuttonSelected = false;
if( bUp ) if( bUp )
{ {
// select last valid non-clipped item // select last valid non-clipped item
...@@ -4880,6 +4890,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4880,6 +4890,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() ) if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() )
{ {
ImplChangeHighlight( nullptr ); ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); InvalidateMenuButton();
} }
else else
...@@ -4891,9 +4902,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4891,9 +4902,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
// Select last valid item // Select last valid item
// docked toolbars have the menubutton as last item - if this button is enabled // docked toolbars have the menubutton as last item - if this button is enabled
if( IsMenuEnabled() && !ImplIsFloatingMode() ) if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
{ {
ImplChangeHighlight( nullptr ); ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); InvalidateMenuButton();
} }
else else
...@@ -4926,9 +4938,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4926,9 +4938,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
return false; return false;
// highlight the menu button if it is the last item // highlight the menu button if it is the last item
if( IsMenuEnabled() && !ImplIsFloatingMode() ) if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
{ {
ImplChangeHighlight( nullptr ); ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); InvalidateMenuButton();
return true; return true;
} }
...@@ -4944,9 +4957,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4944,9 +4957,10 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
return false; return false;
// highlight the menu button if it is the last item // highlight the menu button if it is the last item
if( IsMenuEnabled() && !ImplIsFloatingMode() ) if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
{ {
ImplChangeHighlight( nullptr ); ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); InvalidateMenuButton();
return true; return true;
} }
...@@ -4966,6 +4980,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) ...@@ -4966,6 +4980,7 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
{ {
// select the menu button if a clipped item would be selected // select the menu button if a clipped item would be selected
ImplChangeHighlight( nullptr ); ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); InvalidateMenuButton();
} }
else if( i != nCount ) else if( i != nCount )
...@@ -4994,6 +5009,7 @@ void ToolBox::ImplHideFocus() ...@@ -4994,6 +5009,7 @@ void ToolBox::ImplHideFocus()
{ {
if( mnHighItemId ) if( mnHighItemId )
{ {
mpData->mbMenubuttonWasLastSelected = false;
ImplToolItem* pItem = ImplGetItem( mnHighItemId ); ImplToolItem* pItem = ImplGetItem( mnHighItemId );
if( pItem && pItem->mpWindow ) if( pItem && pItem->mpWindow )
{ {
...@@ -5005,7 +5021,9 @@ void ToolBox::ImplHideFocus() ...@@ -5005,7 +5021,9 @@ void ToolBox::ImplHideFocus()
if ( mpData && mpData->mbMenubuttonSelected ) if ( mpData && mpData->mbMenubuttonSelected )
{ {
mpData->mbMenubuttonWasLastSelected = true;
// remove highlight from menubutton // remove highlight from menubutton
mpData->mbMenubuttonSelected = false;
InvalidateMenuButton(); InvalidateMenuButton();
} }
} }
......
...@@ -62,6 +62,7 @@ ImplToolBoxPrivateData::ImplToolBoxPrivateData() ...@@ -62,6 +62,7 @@ ImplToolBoxPrivateData::ImplToolBoxPrivateData()
mbAssumeFloating = false; mbAssumeFloating = false;
mbKeyInputDisabled = false; mbKeyInputDisabled = false;
mbMenubuttonSelected = false; mbMenubuttonSelected = false;
mbMenubuttonWasLastSelected = false;
mbWillUsePopupMode = false; mbWillUsePopupMode = false;
mbDropDownByKeyboard = false; mbDropDownByKeyboard = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment