tdf#119461 Fix focus hidden on deck collapse
Makes Space key behavior the same as mouse click. Focus remains on the
tab button when the deck collapses.
Makes Enter key never collapses the deck but to open if collapsed and
always place focus on the first panel title.
Change-Id: Id6d7624e88b421dcfc62f3d0e79986f10c76a65d
diff --git a/include/sfx2/sidebar/FocusManager.hxx b/include/sfx2/sidebar/FocusManager.hxx
index 84464c4..c089419 100644
--- a/include/sfx2/sidebar/FocusManager.hxx
+++ b/include/sfx2/sidebar/FocusManager.hxx
@@ -50,7 +50,8 @@ class DeckTitleBar;
class FocusManager
{
public:
FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor);
FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor,
const std::function<bool(const sal_Int32)> &rIsDeckOpenFunctor);
~FocusManager();
/** Forget all panels and buttons. Remove all window listeners.
@@ -63,6 +64,7 @@ public:
*/
void GrabFocus();
void GrabFocusPanel();
void GrabFocusButton(const sal_Int32 nIndex);
void SetDeckTitle(DeckTitleBar* pDeckTitleBar);
void SetPanels(const SharedPanelContainer& rPanels);
@@ -73,6 +75,7 @@ private:
std::vector<VclPtr<Panel> > maPanels;
std::vector<VclPtr<Button> > maButtons;
const std::function<void(const Panel&)> maShowPanelFunctor;
const std::function<bool(const sal_Int32)> mbIsDeckOpenFunctor;
bool mbObservingContentControlFocus;
VclPtr<vcl::Window> mpFirstFocusedContentControl;
VclPtr<vcl::Window> mpLastFocusedWindow;
diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 33cdfc3..8274605 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -125,7 +125,7 @@ public:
/** Show only the tab bar, not the deck.
*/
void RequestCloseDeck();
void RequestCloseDeck(bool bFocusMenuTab = false);
/** Open the deck area and restore the parent window to its old width.
*/
@@ -135,6 +135,8 @@ public:
*/
bool IsDeckVisible(const OUString& rsDeckId);
bool IsDeckOpen(const sal_Int32 nIndex = -1);
FocusManager& GetFocusManager() { return maFocusManager;}
ResourceManager* GetResourceManager() { return mpResourceManager.get();}
diff --git a/include/sfx2/sidebar/TabBar.hxx b/include/sfx2/sidebar/TabBar.hxx
index e9ce313..e0f12a5 100644
--- a/include/sfx2/sidebar/TabBar.hxx
+++ b/include/sfx2/sidebar/TabBar.hxx
@@ -86,6 +86,7 @@ public:
void HighlightDeck (const OUString& rsDeckId);
void RemoveDeckHighlight ();
OUString const & GetDeckIdForIndex (const sal_Int32 nIndex) const;
sal_Int32 GetDeckIndexForId (const OUString& rsDeckId);
void ToggleHideFlag (const sal_Int32 nIndex);
void RestoreHideFlags();
diff --git a/sfx2/source/sidebar/FocusManager.cxx b/sfx2/source/sidebar/FocusManager.cxx
index acdb50f..2442912 100644
--- a/sfx2/source/sidebar/FocusManager.cxx
+++ b/sfx2/source/sidebar/FocusManager.cxx
@@ -35,11 +35,13 @@ FocusManager::FocusLocation::FocusLocation (const PanelComponent eComponent, con
{
}
FocusManager::FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor)
FocusManager::FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor,
const std::function<bool(const sal_Int32)>& rIsDeckOpenFunctor)
: mpDeckTitleBar(),
maPanels(),
maButtons(),
maShowPanelFunctor(rShowPanelFunctor),
mbIsDeckOpenFunctor(rIsDeckOpenFunctor),
mbObservingContentControlFocus(false),
mpFirstFocusedContentControl(nullptr),
mpLastFocusedWindow(nullptr)
@@ -61,6 +63,11 @@ void FocusManager::GrabFocusPanel()
FocusPanel(0, false);
}
void FocusManager::GrabFocusButton(const sal_Int32 nIndex)
{
FocusButton(nIndex);
}
void FocusManager::Clear()
{
SetDeckTitle(nullptr);
@@ -275,10 +282,13 @@ void FocusManager::FocusButton (const sal_Int32 nButtonIndex)
void FocusManager::ClickButton (const sal_Int32 nButtonIndex)
{
maButtons[nButtonIndex]->Click();
if (mbIsDeckOpenFunctor)
{
if (!mbIsDeckOpenFunctor(-1) || !mbIsDeckOpenFunctor(nButtonIndex-1))
maButtons[nButtonIndex]->Click();
}
if (nButtonIndex > 0)
if ( ! maPanels.empty())
FocusPanel(0, true);
FocusPanel(0, true);
maButtons[nButtonIndex]->GetParent()->Invalidate();
}
@@ -379,11 +389,6 @@ void FocusManager::HandleKeyEvent (
maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded());
break;
case PC_TabBar:
// Activate the button.
ClickButton(aLocation.mnIndex);
break;
default:
break;
}
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index ba7b121..b227af8 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -109,7 +109,8 @@ SidebarController::SidebarController (
mbIsDeckOpen(),
mbFloatingDeckClosed(!pParentWindow->IsFloatingMode()),
mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()),
maFocusManager([this](const Panel& rPanel){ return this->ShowPanel(rPanel); }),
maFocusManager([this](const Panel& rPanel){ return this->ShowPanel(rPanel); },
[this](const sal_Int32 nIndex){ return this->IsDeckOpen(nIndex); }),
mxReadOnlyModeDispatch(),
mbIsDocumentReadOnly(false),
mpSplitWindow(nullptr),
@@ -1105,13 +1106,13 @@ IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu, bool)
return true;
}
void SidebarController::RequestCloseDeck()
void SidebarController::RequestCloseDeck(bool bFocusMenuTab)
{
mbIsDeckRequestedOpen = false;
UpdateDeckOpenState();
// remove highlight from TabBar, because Deck will be closed
mpTabBar->RemoveDeckHighlight();
sal_Int32 nIndex(bFocusMenuTab ? 0 : mpTabBar->GetDeckIndexForId(mpCurrentDeck->GetId()));
maFocusManager.GrabFocusButton(nIndex);
}
void SidebarController::RequestOpenDeck()
@@ -1120,6 +1121,16 @@ void SidebarController::RequestOpenDeck()
UpdateDeckOpenState();
}
bool SidebarController::IsDeckOpen(const sal_Int32 nIndex)
{
if (nIndex >= 0)
{
OUString asDeckId(mpTabBar->GetDeckIdForIndex(nIndex));
return IsDeckVisible(asDeckId);
}
return mbIsDeckOpen && mbIsDeckOpen.get();
}
bool SidebarController::IsDeckVisible(const OUString& rsDeckId)
{
return mbIsDeckOpen && mbIsDeckOpen.get() && msCurrentDeckId == rsDeckId;
diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx
index a36a7f9..9487e80 100644
--- a/sfx2/source/sidebar/TabBar.cxx
+++ b/sfx2/source/sidebar/TabBar.cxx
@@ -301,6 +301,18 @@ OUString const & TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const
return maItems[nIndex].msDeckId;
}
sal_Int32 TabBar::GetDeckIndexForId (const OUString& rsDeckId)
{
sal_Int32 nIndex(1);
for (auto const& item : maItems)
{
if (item.msDeckId == rsDeckId)
return nIndex;
nIndex++;
}
return 0;
}
void TabBar::ToggleHideFlag (const sal_Int32 nIndex)
{
if (nIndex<0 || static_cast<size_t>(nIndex) >= maItems.size())