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 { 106*611a5f08SAndre Fischer ::std::vector<Button*> aButtons; 107*611a5f08SAndre Fischer aButtons.swap(maButtons); 108*611a5f08SAndre 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) 19752d13b84SAndre Fischer if (mpDeckTitleBar == &rWindow) 19852d13b84SAndre Fischer return FocusLocation(PC_DeckTitle, -1); 19952d13b84SAndre Fischer else if (&mpDeckTitleBar->GetToolBox() == &rWindow) 20052d13b84SAndre Fischer return FocusLocation(PC_DeckToolBox, -1); 20152d13b84SAndre Fischer 20252d13b84SAndre Fischer // Search the panels. 20365908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex) 20465908a7eSAndre Fischer { 20565908a7eSAndre Fischer if (maPanels[nIndex] == &rWindow) 20652d13b84SAndre Fischer return FocusLocation(PC_PanelContent, nIndex); 20765908a7eSAndre Fischer TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar(); 20865908a7eSAndre Fischer if (pTitleBar == &rWindow) 20952d13b84SAndre Fischer return FocusLocation(PC_PanelTitle, nIndex); 21065908a7eSAndre Fischer if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow) 21152d13b84SAndre Fischer return FocusLocation(PC_PanelToolBox, nIndex); 21265908a7eSAndre Fischer } 21365908a7eSAndre Fischer 21452d13b84SAndre Fischer // Search the buttons. 21565908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex) 21665908a7eSAndre Fischer if (maButtons[nIndex] == &rWindow) 21752d13b84SAndre Fischer return FocusLocation(PC_TabBar, nIndex); 21852d13b84SAndre Fischer 21952d13b84SAndre Fischer return FocusLocation(PC_None, -1); 22065908a7eSAndre Fischer } 22152d13b84SAndre Fischer 22265908a7eSAndre Fischer 22365908a7eSAndre Fischer 22465908a7eSAndre Fischer 22565908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const 22665908a7eSAndre Fischer { 22765908a7eSAndre Fischer for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end()); 22865908a7eSAndre Fischer iPanel!=iEnd; 22965908a7eSAndre Fischer ++iPanel) 23065908a7eSAndre Fischer { 23165908a7eSAndre Fischer if ((*iPanel)->HasFocus()) 23265908a7eSAndre Fischer return true; 23365908a7eSAndre Fischer else if ((*iPanel)->HasChildPathFocus()) 23465908a7eSAndre Fischer return true; 23565908a7eSAndre Fischer } 23665908a7eSAndre Fischer return false; 23765908a7eSAndre Fischer } 23865908a7eSAndre Fischer 23965908a7eSAndre Fischer 24065908a7eSAndre Fischer 24165908a7eSAndre Fischer 24265908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const 24365908a7eSAndre Fischer { 24465908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end()); 24565908a7eSAndre Fischer iButton!=iEnd; 24665908a7eSAndre Fischer ++iButton) 24765908a7eSAndre Fischer { 24865908a7eSAndre Fischer if ((*iButton)->HasFocus()) 24965908a7eSAndre Fischer return true; 25065908a7eSAndre Fischer } 25165908a7eSAndre Fischer return false; 25265908a7eSAndre Fischer } 25365908a7eSAndre Fischer 25465908a7eSAndre Fischer 25565908a7eSAndre Fischer 25665908a7eSAndre Fischer 25752d13b84SAndre Fischer void FocusManager::FocusDeckTitle (void) 25852d13b84SAndre Fischer { 25952d13b84SAndre Fischer if (IsDeckTitleVisible()) 26052d13b84SAndre Fischer { 26152d13b84SAndre Fischer ToolBox& rToolBox = mpDeckTitleBar->GetToolBox(); 26252d13b84SAndre Fischer if (rToolBox.GetItemCount() > 0) 26352d13b84SAndre Fischer { 26452d13b84SAndre Fischer rToolBox.GrabFocus(); 26552d13b84SAndre Fischer rToolBox.Invalidate(); 26652d13b84SAndre Fischer } 26752d13b84SAndre Fischer } 26852d13b84SAndre Fischer else 26952d13b84SAndre Fischer FocusPanel(0); 27052d13b84SAndre Fischer } 27152d13b84SAndre Fischer 27252d13b84SAndre Fischer 27352d13b84SAndre Fischer 27452d13b84SAndre Fischer 27552d13b84SAndre Fischer bool FocusManager::IsDeckTitleVisible (void) const 27652d13b84SAndre Fischer { 27752d13b84SAndre Fischer return mpDeckTitleBar != NULL && mpDeckTitleBar->IsVisible(); 27852d13b84SAndre Fischer } 27952d13b84SAndre Fischer 28052d13b84SAndre Fischer 28152d13b84SAndre Fischer 28252d13b84SAndre Fischer 28365908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) 28465908a7eSAndre Fischer { 285*611a5f08SAndre Fischer if (nPanelIndex<0 || nPanelIndex>=maPanels.size()) 286*611a5f08SAndre Fischer return; 28765908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 28865908a7eSAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 28965908a7eSAndre Fischer if (pTitleBar!=NULL && pTitleBar->IsVisible()) 29065908a7eSAndre Fischer { 29165908a7eSAndre Fischer rPanel.SetExpanded(true); 29265908a7eSAndre Fischer pTitleBar->GrabFocus(); 29365908a7eSAndre Fischer } 29465908a7eSAndre Fischer else 29565908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 29652d13b84SAndre Fischer if (maShowPanelFunctor) 29752d13b84SAndre Fischer maShowPanelFunctor(rPanel); 29865908a7eSAndre Fischer } 29965908a7eSAndre Fischer 30065908a7eSAndre Fischer 30165908a7eSAndre Fischer 30265908a7eSAndre Fischer 30365908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 30465908a7eSAndre Fischer { 30565908a7eSAndre Fischer Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 30665908a7eSAndre Fischer if (pWindow != NULL) 30765908a7eSAndre Fischer pWindow->GrabFocus(); 30865908a7eSAndre Fischer } 30965908a7eSAndre Fischer 31065908a7eSAndre Fischer 31165908a7eSAndre Fischer 31265908a7eSAndre Fischer 31365908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 31465908a7eSAndre Fischer { 31565908a7eSAndre Fischer maButtons[nButtonIndex]->GrabFocus(); 31665908a7eSAndre Fischer maButtons[nButtonIndex]->Invalidate(); 31765908a7eSAndre Fischer } 31865908a7eSAndre Fischer 31965908a7eSAndre Fischer 32065908a7eSAndre Fischer 32165908a7eSAndre Fischer 32265908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 32365908a7eSAndre Fischer { 32465908a7eSAndre Fischer maButtons[nButtonIndex]->Click(); 32565908a7eSAndre Fischer if (nButtonIndex > 0) 32665908a7eSAndre Fischer if ( ! maPanels.empty()) 32765908a7eSAndre Fischer FocusPanel(0); 32865908a7eSAndre Fischer maButtons[nButtonIndex]->GetParent()->Invalidate(); 32965908a7eSAndre Fischer } 33065908a7eSAndre Fischer 33165908a7eSAndre Fischer 33265908a7eSAndre Fischer 33365908a7eSAndre Fischer 33465908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow) 33565908a7eSAndre Fischer { 33665908a7eSAndre Fischer ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow)); 33765908a7eSAndre Fischer if (iPanel != maPanels.end()) 33865908a7eSAndre Fischer { 33965908a7eSAndre Fischer UnregisterWindow(rWindow); 34065908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 34165908a7eSAndre Fischer { 34265908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 34365908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 34465908a7eSAndre Fischer } 34565908a7eSAndre Fischer maPanels.erase(iPanel); 34665908a7eSAndre Fischer return; 34765908a7eSAndre Fischer } 34865908a7eSAndre Fischer 34965908a7eSAndre Fischer ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow)); 35065908a7eSAndre Fischer if (iButton != maButtons.end()) 35165908a7eSAndre Fischer { 35265908a7eSAndre Fischer UnregisterWindow(rWindow); 35365908a7eSAndre Fischer maButtons.erase(iButton); 35465908a7eSAndre Fischer return; 35565908a7eSAndre Fischer } 35665908a7eSAndre Fischer } 35765908a7eSAndre Fischer 35865908a7eSAndre Fischer 35965908a7eSAndre Fischer 36065908a7eSAndre Fischer 36165908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel ( 36252d13b84SAndre Fischer const FocusLocation aFocusLocation, 36365908a7eSAndre Fischer const sal_Int32 nDirection) 36465908a7eSAndre Fischer { 36552d13b84SAndre Fischer const bool bHasToolBoxItem ( 36652d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GetItemCount() > 0); 36752d13b84SAndre Fischer switch (aFocusLocation.meComponent) 36865908a7eSAndre Fischer { 36952d13b84SAndre Fischer case PC_PanelTitle: 37052d13b84SAndre Fischer if (nDirection > 0 && bHasToolBoxItem) 37152d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GrabFocus(); 37265908a7eSAndre Fischer else 37352d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 37465908a7eSAndre Fischer return true; 37565908a7eSAndre Fischer 37652d13b84SAndre Fischer case PC_PanelToolBox: 37752d13b84SAndre Fischer if (nDirection < 0 && bHasToolBoxItem) 37852d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GrabFocus(); 37965908a7eSAndre Fischer else 38052d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 38165908a7eSAndre Fischer return true; 38265908a7eSAndre Fischer 38365908a7eSAndre Fischer default: 38465908a7eSAndre Fischer return false; 38565908a7eSAndre Fischer } 38665908a7eSAndre Fischer } 38765908a7eSAndre Fischer 38865908a7eSAndre Fischer 38965908a7eSAndre Fischer 39065908a7eSAndre Fischer 39165908a7eSAndre Fischer void FocusManager::HandleKeyEvent ( 39265908a7eSAndre Fischer const KeyCode& rKeyCode, 39365908a7eSAndre Fischer const Window& rWindow) 39465908a7eSAndre Fischer { 39552d13b84SAndre Fischer const FocusLocation aLocation (GetFocusLocation(rWindow)); 39665908a7eSAndre Fischer 39765908a7eSAndre Fischer switch (rKeyCode.GetCode()) 39865908a7eSAndre Fischer { 39965908a7eSAndre Fischer case KEY_SPACE: 40052d13b84SAndre Fischer switch (aLocation.meComponent) 40165908a7eSAndre Fischer { 40252d13b84SAndre Fischer case PC_PanelTitle: 40352d13b84SAndre Fischer // Toggle panel between expanded and collapsed. 40452d13b84SAndre Fischer maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded()); 40552d13b84SAndre Fischer break; 40652d13b84SAndre Fischer 40752d13b84SAndre Fischer case PC_TabBar: 40852d13b84SAndre Fischer // Activate the button. 40952d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 41052d13b84SAndre Fischer break; 41152d13b84SAndre Fischer 41252d13b84SAndre Fischer default: 41352d13b84SAndre Fischer break; 41465908a7eSAndre Fischer } 41565908a7eSAndre Fischer return; 41665908a7eSAndre Fischer 41765908a7eSAndre Fischer case KEY_RETURN: 41852d13b84SAndre Fischer switch (aLocation.meComponent) 41965908a7eSAndre Fischer { 42052d13b84SAndre Fischer case PC_DeckToolBox: 42152d13b84SAndre Fischer FocusButton(0); 42252d13b84SAndre Fischer break; 42352d13b84SAndre Fischer 42452d13b84SAndre Fischer case PC_PanelTitle: 42565908a7eSAndre Fischer // Enter the panel. 42652d13b84SAndre Fischer FocusPanelContent(aLocation.mnIndex); 42752d13b84SAndre Fischer break; 42852d13b84SAndre Fischer 42952d13b84SAndre Fischer case PC_TabBar: 43052d13b84SAndre Fischer // Activate the button. 43152d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 43252d13b84SAndre Fischer break; 43352d13b84SAndre Fischer 43452d13b84SAndre Fischer default: 43552d13b84SAndre Fischer break; 43665908a7eSAndre Fischer } 43765908a7eSAndre Fischer return; 43865908a7eSAndre Fischer 43965908a7eSAndre Fischer case KEY_TAB: 44052d13b84SAndre Fischer switch (aLocation.meComponent) 44165908a7eSAndre Fischer { 44252d13b84SAndre Fischer case PC_PanelTitle: 44352d13b84SAndre Fischer case PC_PanelToolBox: 44452d13b84SAndre Fischer case PC_PanelContent: 44552d13b84SAndre Fischer if (rKeyCode.IsShift()) 44652d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, -1); 44752d13b84SAndre Fischer else 44852d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, +1); 44952d13b84SAndre Fischer break; 45052d13b84SAndre Fischer 45152d13b84SAndre Fischer default: 45252d13b84SAndre Fischer break; 45365908a7eSAndre Fischer } 45465908a7eSAndre Fischer break; 45565908a7eSAndre Fischer 45665908a7eSAndre Fischer case KEY_LEFT: 45765908a7eSAndre Fischer case KEY_UP: 45852d13b84SAndre Fischer switch (aLocation.meComponent) 45965908a7eSAndre Fischer { 46052d13b84SAndre Fischer case PC_PanelTitle: 46152d13b84SAndre Fischer case PC_PanelToolBox: 46252d13b84SAndre Fischer case PC_PanelContent: 46352d13b84SAndre Fischer // Go to previous panel or the deck title. 46452d13b84SAndre Fischer if (aLocation.mnIndex > 0) 46552d13b84SAndre Fischer FocusPanel(aLocation.mnIndex-1); 46652d13b84SAndre Fischer else if (IsDeckTitleVisible()) 46752d13b84SAndre Fischer FocusDeckTitle(); 46852d13b84SAndre Fischer else 46952d13b84SAndre Fischer FocusButton(maButtons.size()-1); 47052d13b84SAndre Fischer break; 47152d13b84SAndre Fischer 47252d13b84SAndre Fischer case PC_DeckTitle: 47352d13b84SAndre Fischer case PC_DeckToolBox: 47452d13b84SAndre Fischer // Focus the last button. 47552d13b84SAndre Fischer FocusButton(maButtons.size()-1); 47652d13b84SAndre Fischer break; 47752d13b84SAndre Fischer 47852d13b84SAndre Fischer case PC_TabBar: 47952d13b84SAndre Fischer // Go to previous tab bar item. 48052d13b84SAndre Fischer if (aLocation.mnIndex == 0) 48152d13b84SAndre Fischer FocusPanel(maPanels.size()-1); 48252d13b84SAndre Fischer else 48352d13b84SAndre Fischer FocusButton((aLocation.mnIndex + maButtons.size() - 1) % maButtons.size()); 48452d13b84SAndre Fischer break; 48552d13b84SAndre Fischer 48652d13b84SAndre Fischer default: 48752d13b84SAndre Fischer break; 48865908a7eSAndre Fischer } 48965908a7eSAndre Fischer break; 49065908a7eSAndre Fischer 49165908a7eSAndre Fischer case KEY_RIGHT: 49265908a7eSAndre Fischer case KEY_DOWN: 49352d13b84SAndre Fischer switch(aLocation.meComponent) 49465908a7eSAndre Fischer { 49552d13b84SAndre Fischer case PC_PanelTitle: 49652d13b84SAndre Fischer case PC_PanelToolBox: 49752d13b84SAndre Fischer case PC_PanelContent: 49852d13b84SAndre Fischer // Go to next panel. 49952d13b84SAndre Fischer if (aLocation.mnIndex < maPanels.size()-1) 50052d13b84SAndre Fischer FocusPanel(aLocation.mnIndex+1); 50152d13b84SAndre Fischer else 50252d13b84SAndre Fischer FocusButton(0); 50352d13b84SAndre Fischer break; 50452d13b84SAndre Fischer 50552d13b84SAndre Fischer case PC_DeckTitle: 50652d13b84SAndre Fischer case PC_DeckToolBox: 50752d13b84SAndre Fischer // Focus the first panel. 50852d13b84SAndre Fischer FocusPanel(0); 50952d13b84SAndre Fischer break; 51052d13b84SAndre Fischer 51152d13b84SAndre Fischer case PC_TabBar: 51252d13b84SAndre Fischer // Go to next tab bar item. 51352d13b84SAndre Fischer if (aLocation.mnIndex < maButtons.size()-1) 51452d13b84SAndre Fischer FocusButton(aLocation.mnIndex + 1); 51552d13b84SAndre Fischer else if (IsDeckTitleVisible()) 51652d13b84SAndre Fischer FocusDeckTitle(); 51752d13b84SAndre Fischer else 51852d13b84SAndre Fischer FocusPanel(0); 51952d13b84SAndre Fischer break; 52052d13b84SAndre Fischer 52152d13b84SAndre Fischer default: 52252d13b84SAndre Fischer break; 52365908a7eSAndre Fischer } 52465908a7eSAndre Fischer break; 52565908a7eSAndre Fischer } 52665908a7eSAndre Fischer } 52765908a7eSAndre Fischer 52865908a7eSAndre Fischer 52965908a7eSAndre Fischer 53065908a7eSAndre Fischer 53152d13b84SAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent) 53265908a7eSAndre Fischer { 53352d13b84SAndre Fischer if (pEvent == NULL) 53452d13b84SAndre Fischer return 0; 53552d13b84SAndre Fischer 53652d13b84SAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 53752d13b84SAndre Fischer return 0; 53852d13b84SAndre Fischer 53952d13b84SAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 54052d13b84SAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 54152d13b84SAndre Fischer if (pSource == NULL) 54252d13b84SAndre Fischer return 0; 54352d13b84SAndre Fischer 54452d13b84SAndre Fischer switch (pWindowEvent->GetId()) 54565908a7eSAndre Fischer { 54665908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 54765908a7eSAndre Fischer { 54852d13b84SAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 54952d13b84SAndre Fischer HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource); 55052d13b84SAndre Fischer return 1; 55165908a7eSAndre Fischer } 55252d13b84SAndre Fischer 55352d13b84SAndre Fischer case VCLEVENT_OBJECT_DYING: 55452d13b84SAndre Fischer RemoveWindow(*pSource); 55552d13b84SAndre Fischer return 1; 55652d13b84SAndre Fischer 55752d13b84SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 55852d13b84SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 55952d13b84SAndre Fischer pSource->Invalidate(); 56065908a7eSAndre Fischer } 56152d13b84SAndre Fischer 56252d13b84SAndre Fischer return 0; 56365908a7eSAndre Fischer } 56465908a7eSAndre Fischer 56565908a7eSAndre Fischer 56665908a7eSAndre Fischer 56765908a7eSAndre Fischer 56852d13b84SAndre Fischer IMPL_LINK(FocusManager, ChildEventListener, VclSimpleEvent*, pEvent) 56965908a7eSAndre Fischer { 57065908a7eSAndre Fischer if (pEvent == NULL) 57165908a7eSAndre Fischer return 0; 57265908a7eSAndre Fischer 57365908a7eSAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 57465908a7eSAndre Fischer return 0; 57565908a7eSAndre Fischer 57665908a7eSAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 57765908a7eSAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 57865908a7eSAndre Fischer if (pSource == NULL) 57965908a7eSAndre Fischer return 0; 58065908a7eSAndre Fischer 58152d13b84SAndre Fischer switch (pWindowEvent->GetId()) 58252d13b84SAndre Fischer { 58352d13b84SAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 58465908a7eSAndre Fischer { 58552d13b84SAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 58652d13b84SAndre Fischer 58752d13b84SAndre Fischer // Go up the window hierarchy to find the parent of the 58852d13b84SAndre Fischer // event source which is known to us. 58952d13b84SAndre Fischer Window* pWindow = pSource; 59052d13b84SAndre Fischer FocusLocation aLocation (PC_None, -1); 59152d13b84SAndre Fischer while (true) 59265908a7eSAndre Fischer { 59352d13b84SAndre Fischer if (pWindow == NULL) 59452d13b84SAndre Fischer break; 59552d13b84SAndre Fischer aLocation = GetFocusLocation(*pWindow); 59652d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 59752d13b84SAndre Fischer break; 59852d13b84SAndre Fischer pWindow = pWindow->GetParent(); 59965908a7eSAndre Fischer } 60052d13b84SAndre Fischer 60152d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 60252d13b84SAndre Fischer { 60352d13b84SAndre Fischer switch (pKeyEvent->GetKeyCode().GetCode()) 60452d13b84SAndre Fischer { 60552d13b84SAndre Fischer case KEY_ESCAPE: 60652d13b84SAndre Fischer // Return focus back to the panel title. 60752d13b84SAndre Fischer FocusPanel(aLocation.mnIndex); 60852d13b84SAndre Fischer break; 60965908a7eSAndre Fischer 61052d13b84SAndre Fischer default: 61152d13b84SAndre Fischer break; 61252d13b84SAndre Fischer } 61352d13b84SAndre Fischer } 61452d13b84SAndre Fischer break; 61565908a7eSAndre Fischer } 61665908a7eSAndre Fischer 61752d13b84SAndre Fischer default: 61852d13b84SAndre Fischer break; 61952d13b84SAndre Fischer } 62052d13b84SAndre Fischer 62152d13b84SAndre Fischer return 1; 62252d13b84SAndre Fischer } 62365908a7eSAndre Fischer 62465908a7eSAndre Fischer 62565908a7eSAndre Fischer } } // end of namespace sfx2::sidebar 626