165908a7eSAndre Fischer /************************************************************** 265908a7eSAndre Fischer * 365908a7eSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 465908a7eSAndre Fischer * or more contributor license agreements. See the NOTICE file 565908a7eSAndre Fischer * distributed with this work for additional information 665908a7eSAndre Fischer * regarding copyright ownership. The ASF licenses this file 765908a7eSAndre Fischer * to you under the Apache License, Version 2.0 (the 865908a7eSAndre Fischer * "License"); you may not use this file except in compliance 965908a7eSAndre Fischer * with the License. You may obtain a copy of the License at 1065908a7eSAndre Fischer * 1165908a7eSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1265908a7eSAndre Fischer * 1365908a7eSAndre Fischer * Unless required by applicable law or agreed to in writing, 1465908a7eSAndre Fischer * software distributed under the License is distributed on an 1565908a7eSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1665908a7eSAndre Fischer * KIND, either express or implied. See the License for the 1765908a7eSAndre Fischer * specific language governing permissions and limitations 1865908a7eSAndre Fischer * under the License. 1965908a7eSAndre Fischer * 2065908a7eSAndre Fischer *************************************************************/ 2165908a7eSAndre Fischer 2265908a7eSAndre Fischer #include "precompiled_sfx2.hxx" 2365908a7eSAndre Fischer 2465908a7eSAndre Fischer #include "FocusManager.hxx" 2565908a7eSAndre Fischer #include "Panel.hxx" 2652d13b84SAndre Fischer #include "DeckTitleBar.hxx" 27f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx" 2865908a7eSAndre Fischer #include "TitleBar.hxx" 2965908a7eSAndre Fischer #include <vcl/button.hxx> 3065908a7eSAndre Fischer #include <vcl/toolbox.hxx> 3165908a7eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 3265908a7eSAndre Fischer 3365908a7eSAndre Fischer 3465908a7eSAndre Fischer namespace sfx2 { namespace sidebar { 3565908a7eSAndre Fischer 3652d13b84SAndre Fischer FocusManager::FocusLocation::FocusLocation (const PanelComponent eComponent, const sal_Int32 nIndex) 3752d13b84SAndre Fischer : meComponent(eComponent), 3852d13b84SAndre Fischer mnIndex(nIndex) 3965908a7eSAndre Fischer { 4065908a7eSAndre Fischer } 4165908a7eSAndre Fischer 4265908a7eSAndre Fischer 4352d13b84SAndre Fischer 4452d13b84SAndre Fischer 4552d13b84SAndre Fischer FocusManager::FocusManager (const ::boost::function<void(const Panel&)>& rShowPanelFunctor) 4652d13b84SAndre Fischer : mpDeckTitleBar(), 4752d13b84SAndre Fischer maPanels(), 4865908a7eSAndre Fischer maButtons(), 4952d13b84SAndre Fischer maShowPanelFunctor(rShowPanelFunctor) 5065908a7eSAndre Fischer { 5165908a7eSAndre Fischer } 5265908a7eSAndre Fischer 5365908a7eSAndre Fischer 5465908a7eSAndre Fischer 5565908a7eSAndre Fischer 5665908a7eSAndre Fischer FocusManager::~FocusManager (void) 5765908a7eSAndre Fischer { 5865908a7eSAndre Fischer Clear(); 5965908a7eSAndre Fischer } 6065908a7eSAndre Fischer 6165908a7eSAndre Fischer 6265908a7eSAndre Fischer 6365908a7eSAndre Fischer 6465908a7eSAndre Fischer void FocusManager::GrabFocus (void) 6565908a7eSAndre Fischer { 6652d13b84SAndre Fischer FocusDeckTitle(); 6765908a7eSAndre Fischer } 6865908a7eSAndre Fischer 6965908a7eSAndre Fischer 7065908a7eSAndre Fischer 7165908a7eSAndre Fischer 7265908a7eSAndre Fischer void FocusManager::Clear (void) 7365908a7eSAndre Fischer { 7452d13b84SAndre Fischer SetDeckTitle(NULL); 7565908a7eSAndre Fischer ClearPanels(); 7665908a7eSAndre Fischer ClearButtons(); 7765908a7eSAndre Fischer } 7865908a7eSAndre Fischer 7965908a7eSAndre Fischer 8065908a7eSAndre Fischer 8152d13b84SAndre Fischer 8265908a7eSAndre Fischer void FocusManager::ClearPanels (void) 8365908a7eSAndre Fischer { 8465908a7eSAndre Fischer ::std::vector<Panel*> aPanels; 8565908a7eSAndre Fischer aPanels.swap(maPanels); 8665908a7eSAndre Fischer for (::std::vector<Panel*>::iterator iPanel(aPanels.begin()),iEnd(aPanels.end()); 8765908a7eSAndre Fischer iPanel!=iEnd; 8865908a7eSAndre Fischer ++iPanel) 8965908a7eSAndre Fischer { 9065908a7eSAndre Fischer UnregisterWindow(**iPanel); 9165908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 9265908a7eSAndre Fischer { 9365908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 9465908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 9565908a7eSAndre Fischer } 9652d13b84SAndre Fischer 9752d13b84SAndre Fischer (*iPanel)->RemoveChildEventListener(LINK(this, FocusManager, ChildEventListener)); 9865908a7eSAndre Fischer } 9965908a7eSAndre Fischer } 10065908a7eSAndre Fischer 10165908a7eSAndre Fischer 10265908a7eSAndre Fischer 10365908a7eSAndre Fischer 10465908a7eSAndre Fischer void FocusManager::ClearButtons (void) 10565908a7eSAndre Fischer { 106611a5f08SAndre Fischer ::std::vector<Button*> aButtons; 107611a5f08SAndre Fischer aButtons.swap(maButtons); 108611a5f08SAndre Fischer for (::std::vector<Button*>::iterator iButton(aButtons.begin()),iEnd(aButtons.end()); 10965908a7eSAndre Fischer iButton!=iEnd; 11065908a7eSAndre Fischer ++iButton) 11165908a7eSAndre Fischer { 11265908a7eSAndre Fischer UnregisterWindow(**iButton); 11365908a7eSAndre Fischer } 11465908a7eSAndre Fischer } 11565908a7eSAndre Fischer 11665908a7eSAndre Fischer 11765908a7eSAndre Fischer 11865908a7eSAndre Fischer 11952d13b84SAndre Fischer void FocusManager::SetDeckTitle (DeckTitleBar* pDeckTitleBar) 12052d13b84SAndre Fischer { 12152d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 12252d13b84SAndre Fischer { 12352d13b84SAndre Fischer UnregisterWindow(*mpDeckTitleBar); 12452d13b84SAndre Fischer UnregisterWindow(mpDeckTitleBar->GetToolBox()); 12552d13b84SAndre Fischer } 12652d13b84SAndre Fischer mpDeckTitleBar = pDeckTitleBar; 12752d13b84SAndre Fischer 12852d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 12952d13b84SAndre Fischer { 13052d13b84SAndre Fischer RegisterWindow(*mpDeckTitleBar); 13152d13b84SAndre Fischer RegisterWindow(mpDeckTitleBar->GetToolBox()); 13252d13b84SAndre Fischer } 13352d13b84SAndre Fischer } 13452d13b84SAndre Fischer 13552d13b84SAndre Fischer 13652d13b84SAndre Fischer 13752d13b84SAndre Fischer 13865908a7eSAndre Fischer void FocusManager::SetPanels (const SharedPanelContainer& rPanels) 13965908a7eSAndre Fischer { 14065908a7eSAndre Fischer ClearPanels(); 14165908a7eSAndre Fischer for(SharedPanelContainer::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end()); 14265908a7eSAndre Fischer iPanel!=iEnd; 14365908a7eSAndre Fischer ++iPanel) 14465908a7eSAndre Fischer { 14565908a7eSAndre Fischer RegisterWindow(**iPanel); 14665908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 14765908a7eSAndre Fischer { 14865908a7eSAndre Fischer RegisterWindow(*(*iPanel)->GetTitleBar()); 14965908a7eSAndre Fischer RegisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 15065908a7eSAndre Fischer } 15152d13b84SAndre Fischer 15252d13b84SAndre Fischer // Register also as child event listener at the panel. 15352d13b84SAndre Fischer (*iPanel)->AddChildEventListener(LINK(this, FocusManager, ChildEventListener)); 15452d13b84SAndre Fischer 15565908a7eSAndre Fischer maPanels.push_back(iPanel->get()); 15665908a7eSAndre Fischer } 15765908a7eSAndre Fischer } 15865908a7eSAndre Fischer 15965908a7eSAndre Fischer 16065908a7eSAndre Fischer 16165908a7eSAndre Fischer 16265908a7eSAndre Fischer void FocusManager::SetButtons (const ::std::vector<Button*>& rButtons) 16365908a7eSAndre Fischer { 16465908a7eSAndre Fischer ClearButtons(); 16565908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(rButtons.begin()),iEnd(rButtons.end()); 16665908a7eSAndre Fischer iButton!=iEnd; 16765908a7eSAndre Fischer ++iButton) 16865908a7eSAndre Fischer { 16965908a7eSAndre Fischer RegisterWindow(**iButton); 17065908a7eSAndre Fischer maButtons.push_back(*iButton); 17165908a7eSAndre Fischer } 17265908a7eSAndre Fischer } 17365908a7eSAndre Fischer 17465908a7eSAndre Fischer 17565908a7eSAndre Fischer 17665908a7eSAndre Fischer 17765908a7eSAndre Fischer void FocusManager::RegisterWindow (Window& rWindow) 17865908a7eSAndre Fischer { 17965908a7eSAndre Fischer rWindow.AddEventListener(LINK(this, FocusManager, WindowEventListener)); 18065908a7eSAndre Fischer } 18165908a7eSAndre Fischer 18265908a7eSAndre Fischer 18365908a7eSAndre Fischer 18465908a7eSAndre Fischer 18565908a7eSAndre Fischer void FocusManager::UnregisterWindow (Window& rWindow) 18665908a7eSAndre Fischer { 18765908a7eSAndre Fischer rWindow.RemoveEventListener(LINK(this, FocusManager, WindowEventListener)); 18865908a7eSAndre Fischer } 18965908a7eSAndre Fischer 19065908a7eSAndre Fischer 19165908a7eSAndre Fischer 19265908a7eSAndre Fischer 19352d13b84SAndre Fischer FocusManager::FocusLocation FocusManager::GetFocusLocation (const Window& rWindow) const 19465908a7eSAndre Fischer { 19552d13b84SAndre Fischer // Check the deck title. 19652d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 197*edc7f530SAndre Fischer { 19852d13b84SAndre Fischer if (mpDeckTitleBar == &rWindow) 19952d13b84SAndre Fischer return FocusLocation(PC_DeckTitle, -1); 20052d13b84SAndre Fischer else if (&mpDeckTitleBar->GetToolBox() == &rWindow) 20152d13b84SAndre Fischer return FocusLocation(PC_DeckToolBox, -1); 202*edc7f530SAndre Fischer } 203*edc7f530SAndre Fischer 20452d13b84SAndre Fischer // Search the panels. 20565908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex) 20665908a7eSAndre Fischer { 20765908a7eSAndre Fischer if (maPanels[nIndex] == &rWindow) 20852d13b84SAndre Fischer return FocusLocation(PC_PanelContent, nIndex); 20965908a7eSAndre Fischer TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar(); 21065908a7eSAndre Fischer if (pTitleBar == &rWindow) 21152d13b84SAndre Fischer return FocusLocation(PC_PanelTitle, nIndex); 21265908a7eSAndre Fischer if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow) 21352d13b84SAndre Fischer return FocusLocation(PC_PanelToolBox, nIndex); 21465908a7eSAndre Fischer } 21565908a7eSAndre Fischer 21652d13b84SAndre Fischer // Search the buttons. 21765908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex) 21865908a7eSAndre Fischer if (maButtons[nIndex] == &rWindow) 21952d13b84SAndre Fischer return FocusLocation(PC_TabBar, nIndex); 22052d13b84SAndre Fischer 22152d13b84SAndre Fischer return FocusLocation(PC_None, -1); 22265908a7eSAndre Fischer } 22352d13b84SAndre Fischer 22465908a7eSAndre Fischer 22565908a7eSAndre Fischer 22665908a7eSAndre Fischer 22765908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const 22865908a7eSAndre Fischer { 22965908a7eSAndre Fischer for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end()); 23065908a7eSAndre Fischer iPanel!=iEnd; 23165908a7eSAndre Fischer ++iPanel) 23265908a7eSAndre Fischer { 23365908a7eSAndre Fischer if ((*iPanel)->HasFocus()) 23465908a7eSAndre Fischer return true; 23565908a7eSAndre Fischer else if ((*iPanel)->HasChildPathFocus()) 23665908a7eSAndre Fischer return true; 23765908a7eSAndre Fischer } 23865908a7eSAndre Fischer return false; 23965908a7eSAndre Fischer } 24065908a7eSAndre Fischer 24165908a7eSAndre Fischer 24265908a7eSAndre Fischer 24365908a7eSAndre Fischer 24465908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const 24565908a7eSAndre Fischer { 24665908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end()); 24765908a7eSAndre Fischer iButton!=iEnd; 24865908a7eSAndre Fischer ++iButton) 24965908a7eSAndre Fischer { 25065908a7eSAndre Fischer if ((*iButton)->HasFocus()) 25165908a7eSAndre Fischer return true; 25265908a7eSAndre Fischer } 25365908a7eSAndre Fischer return false; 25465908a7eSAndre Fischer } 25565908a7eSAndre Fischer 25665908a7eSAndre Fischer 25765908a7eSAndre Fischer 25865908a7eSAndre Fischer 25952d13b84SAndre Fischer void FocusManager::FocusDeckTitle (void) 26052d13b84SAndre Fischer { 26152d13b84SAndre Fischer if (IsDeckTitleVisible()) 26252d13b84SAndre Fischer { 26352d13b84SAndre Fischer ToolBox& rToolBox = mpDeckTitleBar->GetToolBox(); 26452d13b84SAndre Fischer if (rToolBox.GetItemCount() > 0) 26552d13b84SAndre Fischer { 26652d13b84SAndre Fischer rToolBox.GrabFocus(); 26752d13b84SAndre Fischer rToolBox.Invalidate(); 26852d13b84SAndre Fischer } 26952d13b84SAndre Fischer } 27052d13b84SAndre Fischer else 27152d13b84SAndre Fischer FocusPanel(0); 27252d13b84SAndre Fischer } 27352d13b84SAndre Fischer 27452d13b84SAndre Fischer 27552d13b84SAndre Fischer 27652d13b84SAndre Fischer 27752d13b84SAndre Fischer bool FocusManager::IsDeckTitleVisible (void) const 27852d13b84SAndre Fischer { 27952d13b84SAndre Fischer return mpDeckTitleBar != NULL && mpDeckTitleBar->IsVisible(); 28052d13b84SAndre Fischer } 28152d13b84SAndre Fischer 28252d13b84SAndre Fischer 28352d13b84SAndre Fischer 28452d13b84SAndre Fischer 28565908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) 28665908a7eSAndre Fischer { 2870f2fd489SPavel Janík if (nPanelIndex<0 || nPanelIndex>=static_cast<sal_Int32>(maPanels.size())) 288611a5f08SAndre Fischer return; 28965908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 29065908a7eSAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 29165908a7eSAndre Fischer if (pTitleBar!=NULL && pTitleBar->IsVisible()) 29265908a7eSAndre Fischer { 29365908a7eSAndre Fischer rPanel.SetExpanded(true); 29465908a7eSAndre Fischer pTitleBar->GrabFocus(); 29565908a7eSAndre Fischer } 29665908a7eSAndre Fischer else 29765908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 29852d13b84SAndre Fischer if (maShowPanelFunctor) 29952d13b84SAndre Fischer maShowPanelFunctor(rPanel); 30065908a7eSAndre Fischer } 30165908a7eSAndre Fischer 30265908a7eSAndre Fischer 30365908a7eSAndre Fischer 30465908a7eSAndre Fischer 30565908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 30665908a7eSAndre Fischer { 30765908a7eSAndre Fischer Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 30865908a7eSAndre Fischer if (pWindow != NULL) 30965908a7eSAndre Fischer pWindow->GrabFocus(); 31065908a7eSAndre Fischer } 31165908a7eSAndre Fischer 31265908a7eSAndre Fischer 31365908a7eSAndre Fischer 31465908a7eSAndre Fischer 31565908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 31665908a7eSAndre Fischer { 31765908a7eSAndre Fischer maButtons[nButtonIndex]->GrabFocus(); 31865908a7eSAndre Fischer maButtons[nButtonIndex]->Invalidate(); 31965908a7eSAndre Fischer } 32065908a7eSAndre Fischer 32165908a7eSAndre Fischer 32265908a7eSAndre Fischer 32365908a7eSAndre Fischer 32465908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 32565908a7eSAndre Fischer { 32665908a7eSAndre Fischer maButtons[nButtonIndex]->Click(); 32765908a7eSAndre Fischer if (nButtonIndex > 0) 32865908a7eSAndre Fischer if ( ! maPanels.empty()) 32965908a7eSAndre Fischer FocusPanel(0); 33065908a7eSAndre Fischer maButtons[nButtonIndex]->GetParent()->Invalidate(); 33165908a7eSAndre Fischer } 33265908a7eSAndre Fischer 33365908a7eSAndre Fischer 33465908a7eSAndre Fischer 33565908a7eSAndre Fischer 33665908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow) 33765908a7eSAndre Fischer { 33865908a7eSAndre Fischer ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow)); 33965908a7eSAndre Fischer if (iPanel != maPanels.end()) 34065908a7eSAndre Fischer { 34165908a7eSAndre Fischer UnregisterWindow(rWindow); 34265908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 34365908a7eSAndre Fischer { 34465908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 34565908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 34665908a7eSAndre Fischer } 34765908a7eSAndre Fischer maPanels.erase(iPanel); 34865908a7eSAndre Fischer return; 34965908a7eSAndre Fischer } 35065908a7eSAndre Fischer 35165908a7eSAndre Fischer ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow)); 35265908a7eSAndre Fischer if (iButton != maButtons.end()) 35365908a7eSAndre Fischer { 35465908a7eSAndre Fischer UnregisterWindow(rWindow); 35565908a7eSAndre Fischer maButtons.erase(iButton); 35665908a7eSAndre Fischer return; 35765908a7eSAndre Fischer } 35865908a7eSAndre Fischer } 35965908a7eSAndre Fischer 36065908a7eSAndre Fischer 36165908a7eSAndre Fischer 36265908a7eSAndre Fischer 36365908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel ( 36452d13b84SAndre Fischer const FocusLocation aFocusLocation, 36565908a7eSAndre Fischer const sal_Int32 nDirection) 36665908a7eSAndre Fischer { 36752d13b84SAndre Fischer const bool bHasToolBoxItem ( 36852d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GetItemCount() > 0); 36952d13b84SAndre Fischer switch (aFocusLocation.meComponent) 37065908a7eSAndre Fischer { 37152d13b84SAndre Fischer case PC_PanelTitle: 37252d13b84SAndre Fischer if (nDirection > 0 && bHasToolBoxItem) 37352d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GrabFocus(); 37465908a7eSAndre Fischer else 37552d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 37665908a7eSAndre Fischer return true; 37765908a7eSAndre Fischer 37852d13b84SAndre Fischer case PC_PanelToolBox: 37952d13b84SAndre Fischer if (nDirection < 0 && bHasToolBoxItem) 38052d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GrabFocus(); 38165908a7eSAndre Fischer else 38252d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 38365908a7eSAndre Fischer return true; 38465908a7eSAndre Fischer 38565908a7eSAndre Fischer default: 38665908a7eSAndre Fischer return false; 38765908a7eSAndre Fischer } 38865908a7eSAndre Fischer } 38965908a7eSAndre Fischer 39065908a7eSAndre Fischer 39165908a7eSAndre Fischer 39265908a7eSAndre Fischer 39365908a7eSAndre Fischer void FocusManager::HandleKeyEvent ( 39465908a7eSAndre Fischer const KeyCode& rKeyCode, 39565908a7eSAndre Fischer const Window& rWindow) 39665908a7eSAndre Fischer { 39752d13b84SAndre Fischer const FocusLocation aLocation (GetFocusLocation(rWindow)); 39865908a7eSAndre Fischer 39965908a7eSAndre Fischer switch (rKeyCode.GetCode()) 40065908a7eSAndre Fischer { 40165908a7eSAndre Fischer case KEY_SPACE: 40252d13b84SAndre Fischer switch (aLocation.meComponent) 40365908a7eSAndre Fischer { 40452d13b84SAndre Fischer case PC_PanelTitle: 40552d13b84SAndre Fischer // Toggle panel between expanded and collapsed. 40652d13b84SAndre Fischer maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded()); 40752d13b84SAndre Fischer break; 40852d13b84SAndre Fischer 40952d13b84SAndre Fischer case PC_TabBar: 41052d13b84SAndre Fischer // Activate the button. 41152d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 41252d13b84SAndre Fischer break; 41352d13b84SAndre Fischer 41452d13b84SAndre Fischer default: 41552d13b84SAndre Fischer break; 41665908a7eSAndre Fischer } 41765908a7eSAndre Fischer return; 41865908a7eSAndre Fischer 41965908a7eSAndre Fischer case KEY_RETURN: 42052d13b84SAndre Fischer switch (aLocation.meComponent) 42165908a7eSAndre Fischer { 42252d13b84SAndre Fischer case PC_DeckToolBox: 42352d13b84SAndre Fischer FocusButton(0); 42452d13b84SAndre Fischer break; 42552d13b84SAndre Fischer 42652d13b84SAndre Fischer case PC_PanelTitle: 42765908a7eSAndre Fischer // Enter the panel. 42852d13b84SAndre Fischer FocusPanelContent(aLocation.mnIndex); 42952d13b84SAndre Fischer break; 43052d13b84SAndre Fischer 43152d13b84SAndre Fischer case PC_TabBar: 43252d13b84SAndre Fischer // Activate the button. 43352d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 43452d13b84SAndre Fischer break; 43552d13b84SAndre Fischer 43652d13b84SAndre Fischer default: 43752d13b84SAndre Fischer break; 43865908a7eSAndre Fischer } 43965908a7eSAndre Fischer return; 44065908a7eSAndre Fischer 44165908a7eSAndre Fischer case KEY_TAB: 44252d13b84SAndre Fischer switch (aLocation.meComponent) 44365908a7eSAndre Fischer { 44452d13b84SAndre Fischer case PC_PanelTitle: 44552d13b84SAndre Fischer case PC_PanelToolBox: 44652d13b84SAndre Fischer case PC_PanelContent: 44752d13b84SAndre Fischer if (rKeyCode.IsShift()) 44852d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, -1); 44952d13b84SAndre Fischer else 45052d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, +1); 45152d13b84SAndre Fischer break; 45252d13b84SAndre Fischer 45352d13b84SAndre Fischer default: 45452d13b84SAndre Fischer break; 45565908a7eSAndre Fischer } 45665908a7eSAndre Fischer break; 45765908a7eSAndre Fischer 45865908a7eSAndre Fischer case KEY_LEFT: 45965908a7eSAndre Fischer case KEY_UP: 46052d13b84SAndre Fischer switch (aLocation.meComponent) 46165908a7eSAndre Fischer { 46252d13b84SAndre Fischer case PC_PanelTitle: 46352d13b84SAndre Fischer case PC_PanelToolBox: 46452d13b84SAndre Fischer case PC_PanelContent: 46552d13b84SAndre Fischer // Go to previous panel or the deck title. 46652d13b84SAndre Fischer if (aLocation.mnIndex > 0) 46752d13b84SAndre Fischer FocusPanel(aLocation.mnIndex-1); 46852d13b84SAndre Fischer else if (IsDeckTitleVisible()) 46952d13b84SAndre Fischer FocusDeckTitle(); 47052d13b84SAndre Fischer else 47152d13b84SAndre Fischer FocusButton(maButtons.size()-1); 47252d13b84SAndre Fischer break; 47352d13b84SAndre Fischer 47452d13b84SAndre Fischer case PC_DeckTitle: 47552d13b84SAndre Fischer case PC_DeckToolBox: 47652d13b84SAndre Fischer // Focus the last button. 47752d13b84SAndre Fischer FocusButton(maButtons.size()-1); 47852d13b84SAndre Fischer break; 47952d13b84SAndre Fischer 48052d13b84SAndre Fischer case PC_TabBar: 48152d13b84SAndre Fischer // Go to previous tab bar item. 48252d13b84SAndre Fischer if (aLocation.mnIndex == 0) 48352d13b84SAndre Fischer FocusPanel(maPanels.size()-1); 48452d13b84SAndre Fischer else 48552d13b84SAndre Fischer FocusButton((aLocation.mnIndex + maButtons.size() - 1) % maButtons.size()); 48652d13b84SAndre Fischer break; 48752d13b84SAndre Fischer 48852d13b84SAndre Fischer default: 48952d13b84SAndre Fischer break; 49065908a7eSAndre Fischer } 49165908a7eSAndre Fischer break; 49265908a7eSAndre Fischer 49365908a7eSAndre Fischer case KEY_RIGHT: 49465908a7eSAndre Fischer case KEY_DOWN: 49552d13b84SAndre Fischer switch(aLocation.meComponent) 49665908a7eSAndre Fischer { 49752d13b84SAndre Fischer case PC_PanelTitle: 49852d13b84SAndre Fischer case PC_PanelToolBox: 49952d13b84SAndre Fischer case PC_PanelContent: 50052d13b84SAndre Fischer // Go to next panel. 5010f2fd489SPavel Janík if (aLocation.mnIndex < static_cast<sal_Int32>(maPanels.size())-1) 50252d13b84SAndre Fischer FocusPanel(aLocation.mnIndex+1); 50352d13b84SAndre Fischer else 50452d13b84SAndre Fischer FocusButton(0); 50552d13b84SAndre Fischer break; 50652d13b84SAndre Fischer 50752d13b84SAndre Fischer case PC_DeckTitle: 50852d13b84SAndre Fischer case PC_DeckToolBox: 50952d13b84SAndre Fischer // Focus the first panel. 51052d13b84SAndre Fischer FocusPanel(0); 51152d13b84SAndre Fischer break; 51252d13b84SAndre Fischer 51352d13b84SAndre Fischer case PC_TabBar: 51452d13b84SAndre Fischer // Go to next tab bar item. 5150f2fd489SPavel Janík if (aLocation.mnIndex < static_cast<sal_Int32>(maButtons.size())-1) 51652d13b84SAndre Fischer FocusButton(aLocation.mnIndex + 1); 51752d13b84SAndre Fischer else if (IsDeckTitleVisible()) 51852d13b84SAndre Fischer FocusDeckTitle(); 51952d13b84SAndre Fischer else 52052d13b84SAndre Fischer FocusPanel(0); 52152d13b84SAndre Fischer break; 52252d13b84SAndre Fischer 52352d13b84SAndre Fischer default: 52452d13b84SAndre Fischer break; 52565908a7eSAndre Fischer } 52665908a7eSAndre Fischer break; 52765908a7eSAndre Fischer } 52865908a7eSAndre Fischer } 52965908a7eSAndre Fischer 53065908a7eSAndre Fischer 53165908a7eSAndre Fischer 53265908a7eSAndre Fischer 53352d13b84SAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent) 53465908a7eSAndre Fischer { 53552d13b84SAndre Fischer if (pEvent == NULL) 53652d13b84SAndre Fischer return 0; 53752d13b84SAndre Fischer 53852d13b84SAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 53952d13b84SAndre Fischer return 0; 54052d13b84SAndre Fischer 54152d13b84SAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 54252d13b84SAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 54352d13b84SAndre Fischer if (pSource == NULL) 54452d13b84SAndre Fischer return 0; 54552d13b84SAndre Fischer 54652d13b84SAndre Fischer switch (pWindowEvent->GetId()) 54765908a7eSAndre Fischer { 54865908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 54965908a7eSAndre Fischer { 55052d13b84SAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 55152d13b84SAndre Fischer HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource); 55252d13b84SAndre Fischer return 1; 55365908a7eSAndre Fischer } 55452d13b84SAndre Fischer 55552d13b84SAndre Fischer case VCLEVENT_OBJECT_DYING: 55652d13b84SAndre Fischer RemoveWindow(*pSource); 55752d13b84SAndre Fischer return 1; 55852d13b84SAndre Fischer 55952d13b84SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 56052d13b84SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 56152d13b84SAndre Fischer pSource->Invalidate(); 56265908a7eSAndre Fischer } 56352d13b84SAndre Fischer 56452d13b84SAndre Fischer return 0; 56565908a7eSAndre Fischer } 56665908a7eSAndre Fischer 56765908a7eSAndre Fischer 56865908a7eSAndre Fischer 56965908a7eSAndre Fischer 57052d13b84SAndre Fischer IMPL_LINK(FocusManager, ChildEventListener, VclSimpleEvent*, pEvent) 57165908a7eSAndre Fischer { 57265908a7eSAndre Fischer if (pEvent == NULL) 57365908a7eSAndre Fischer return 0; 57465908a7eSAndre Fischer 57565908a7eSAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 57665908a7eSAndre Fischer return 0; 57765908a7eSAndre Fischer 57865908a7eSAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 57965908a7eSAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 58065908a7eSAndre Fischer if (pSource == NULL) 58165908a7eSAndre Fischer return 0; 58265908a7eSAndre Fischer 58352d13b84SAndre Fischer switch (pWindowEvent->GetId()) 58452d13b84SAndre Fischer { 58552d13b84SAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 58665908a7eSAndre Fischer { 58752d13b84SAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 58852d13b84SAndre Fischer 58952d13b84SAndre Fischer // Go up the window hierarchy to find the parent of the 59052d13b84SAndre Fischer // event source which is known to us. 59152d13b84SAndre Fischer Window* pWindow = pSource; 59252d13b84SAndre Fischer FocusLocation aLocation (PC_None, -1); 59352d13b84SAndre Fischer while (true) 59465908a7eSAndre Fischer { 59552d13b84SAndre Fischer if (pWindow == NULL) 59652d13b84SAndre Fischer break; 59752d13b84SAndre Fischer aLocation = GetFocusLocation(*pWindow); 59852d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 59952d13b84SAndre Fischer break; 60052d13b84SAndre Fischer pWindow = pWindow->GetParent(); 60165908a7eSAndre Fischer } 60252d13b84SAndre Fischer 60352d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 60452d13b84SAndre Fischer { 60552d13b84SAndre Fischer switch (pKeyEvent->GetKeyCode().GetCode()) 60652d13b84SAndre Fischer { 60752d13b84SAndre Fischer case KEY_ESCAPE: 60852d13b84SAndre Fischer // Return focus back to the panel title. 60952d13b84SAndre Fischer FocusPanel(aLocation.mnIndex); 61052d13b84SAndre Fischer break; 61165908a7eSAndre Fischer 61252d13b84SAndre Fischer default: 61352d13b84SAndre Fischer break; 61452d13b84SAndre Fischer } 61552d13b84SAndre Fischer } 61652d13b84SAndre Fischer break; 61765908a7eSAndre Fischer } 61865908a7eSAndre Fischer 61952d13b84SAndre Fischer default: 62052d13b84SAndre Fischer break; 62152d13b84SAndre Fischer } 62252d13b84SAndre Fischer 62352d13b84SAndre Fischer return 1; 62452d13b84SAndre Fischer } 62565908a7eSAndre Fischer 62665908a7eSAndre Fischer 62765908a7eSAndre Fischer } } // end of namespace sfx2::sidebar 628