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" 26*52d13b84SAndre 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 36*52d13b84SAndre Fischer FocusManager::FocusLocation::FocusLocation (const PanelComponent eComponent, const sal_Int32 nIndex) 37*52d13b84SAndre Fischer : meComponent(eComponent), 38*52d13b84SAndre Fischer mnIndex(nIndex) 3965908a7eSAndre Fischer { 4065908a7eSAndre Fischer } 4165908a7eSAndre Fischer 4265908a7eSAndre Fischer 43*52d13b84SAndre Fischer 44*52d13b84SAndre Fischer 45*52d13b84SAndre Fischer FocusManager::FocusManager (const ::boost::function<void(const Panel&)>& rShowPanelFunctor) 46*52d13b84SAndre Fischer : mpDeckTitleBar(), 47*52d13b84SAndre Fischer maPanels(), 4865908a7eSAndre Fischer maButtons(), 49*52d13b84SAndre 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 { 66*52d13b84SAndre Fischer FocusDeckTitle(); 6765908a7eSAndre Fischer } 6865908a7eSAndre Fischer 6965908a7eSAndre Fischer 7065908a7eSAndre Fischer 7165908a7eSAndre Fischer 7265908a7eSAndre Fischer void FocusManager::Clear (void) 7365908a7eSAndre Fischer { 74*52d13b84SAndre Fischer SetDeckTitle(NULL); 7565908a7eSAndre Fischer ClearPanels(); 7665908a7eSAndre Fischer ClearButtons(); 7765908a7eSAndre Fischer } 7865908a7eSAndre Fischer 7965908a7eSAndre Fischer 8065908a7eSAndre Fischer 81*52d13b84SAndre 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 } 96*52d13b84SAndre Fischer 97*52d13b84SAndre 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 { 10665908a7eSAndre Fischer ::std::vector<Window*> aButtons; 10765908a7eSAndre Fischer for (::std::vector<Window*>::iterator iButton(aButtons.begin()),iEnd(aButtons.end()); 10865908a7eSAndre Fischer iButton!=iEnd; 10965908a7eSAndre Fischer ++iButton) 11065908a7eSAndre Fischer { 11165908a7eSAndre Fischer UnregisterWindow(**iButton); 11265908a7eSAndre Fischer } 11365908a7eSAndre Fischer } 11465908a7eSAndre Fischer 11565908a7eSAndre Fischer 11665908a7eSAndre Fischer 11765908a7eSAndre Fischer 118*52d13b84SAndre Fischer void FocusManager::SetDeckTitle (DeckTitleBar* pDeckTitleBar) 119*52d13b84SAndre Fischer { 120*52d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 121*52d13b84SAndre Fischer { 122*52d13b84SAndre Fischer UnregisterWindow(*mpDeckTitleBar); 123*52d13b84SAndre Fischer UnregisterWindow(mpDeckTitleBar->GetToolBox()); 124*52d13b84SAndre Fischer } 125*52d13b84SAndre Fischer mpDeckTitleBar = pDeckTitleBar; 126*52d13b84SAndre Fischer 127*52d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 128*52d13b84SAndre Fischer { 129*52d13b84SAndre Fischer RegisterWindow(*mpDeckTitleBar); 130*52d13b84SAndre Fischer RegisterWindow(mpDeckTitleBar->GetToolBox()); 131*52d13b84SAndre Fischer } 132*52d13b84SAndre Fischer } 133*52d13b84SAndre Fischer 134*52d13b84SAndre Fischer 135*52d13b84SAndre Fischer 136*52d13b84SAndre Fischer 13765908a7eSAndre Fischer void FocusManager::SetPanels (const SharedPanelContainer& rPanels) 13865908a7eSAndre Fischer { 13965908a7eSAndre Fischer ClearPanels(); 14065908a7eSAndre Fischer for(SharedPanelContainer::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end()); 14165908a7eSAndre Fischer iPanel!=iEnd; 14265908a7eSAndre Fischer ++iPanel) 14365908a7eSAndre Fischer { 14465908a7eSAndre Fischer RegisterWindow(**iPanel); 14565908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 14665908a7eSAndre Fischer { 14765908a7eSAndre Fischer RegisterWindow(*(*iPanel)->GetTitleBar()); 14865908a7eSAndre Fischer RegisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 14965908a7eSAndre Fischer } 150*52d13b84SAndre Fischer 151*52d13b84SAndre Fischer // Register also as child event listener at the panel. 152*52d13b84SAndre Fischer (*iPanel)->AddChildEventListener(LINK(this, FocusManager, ChildEventListener)); 153*52d13b84SAndre Fischer 15465908a7eSAndre Fischer maPanels.push_back(iPanel->get()); 15565908a7eSAndre Fischer } 15665908a7eSAndre Fischer } 15765908a7eSAndre Fischer 15865908a7eSAndre Fischer 15965908a7eSAndre Fischer 16065908a7eSAndre Fischer 16165908a7eSAndre Fischer void FocusManager::SetButtons (const ::std::vector<Button*>& rButtons) 16265908a7eSAndre Fischer { 16365908a7eSAndre Fischer ClearButtons(); 16465908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(rButtons.begin()),iEnd(rButtons.end()); 16565908a7eSAndre Fischer iButton!=iEnd; 16665908a7eSAndre Fischer ++iButton) 16765908a7eSAndre Fischer { 16865908a7eSAndre Fischer RegisterWindow(**iButton); 16965908a7eSAndre Fischer maButtons.push_back(*iButton); 17065908a7eSAndre Fischer } 17165908a7eSAndre Fischer } 17265908a7eSAndre Fischer 17365908a7eSAndre Fischer 17465908a7eSAndre Fischer 17565908a7eSAndre Fischer 17665908a7eSAndre Fischer void FocusManager::RegisterWindow (Window& rWindow) 17765908a7eSAndre Fischer { 17865908a7eSAndre Fischer rWindow.AddEventListener(LINK(this, FocusManager, WindowEventListener)); 17965908a7eSAndre Fischer } 18065908a7eSAndre Fischer 18165908a7eSAndre Fischer 18265908a7eSAndre Fischer 18365908a7eSAndre Fischer 18465908a7eSAndre Fischer void FocusManager::UnregisterWindow (Window& rWindow) 18565908a7eSAndre Fischer { 18665908a7eSAndre Fischer rWindow.RemoveEventListener(LINK(this, FocusManager, WindowEventListener)); 18765908a7eSAndre Fischer } 18865908a7eSAndre Fischer 18965908a7eSAndre Fischer 19065908a7eSAndre Fischer 19165908a7eSAndre Fischer 192*52d13b84SAndre Fischer FocusManager::FocusLocation FocusManager::GetFocusLocation (const Window& rWindow) const 19365908a7eSAndre Fischer { 194*52d13b84SAndre Fischer // Check the deck title. 195*52d13b84SAndre Fischer if (mpDeckTitleBar != NULL) 196*52d13b84SAndre Fischer if (mpDeckTitleBar == &rWindow) 197*52d13b84SAndre Fischer return FocusLocation(PC_DeckTitle, -1); 198*52d13b84SAndre Fischer else if (&mpDeckTitleBar->GetToolBox() == &rWindow) 199*52d13b84SAndre Fischer return FocusLocation(PC_DeckToolBox, -1); 20065908a7eSAndre Fischer 201*52d13b84SAndre Fischer // Search the panels. 20265908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex) 20365908a7eSAndre Fischer { 20465908a7eSAndre Fischer if (maPanels[nIndex] == &rWindow) 205*52d13b84SAndre Fischer return FocusLocation(PC_PanelContent, nIndex); 20665908a7eSAndre Fischer TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar(); 20765908a7eSAndre Fischer if (pTitleBar == &rWindow) 208*52d13b84SAndre Fischer return FocusLocation(PC_PanelTitle, nIndex); 20965908a7eSAndre Fischer if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow) 210*52d13b84SAndre Fischer return FocusLocation(PC_PanelToolBox, nIndex); 21165908a7eSAndre Fischer } 21265908a7eSAndre Fischer 213*52d13b84SAndre Fischer // Search the buttons. 21465908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex) 21565908a7eSAndre Fischer if (maButtons[nIndex] == &rWindow) 216*52d13b84SAndre Fischer return FocusLocation(PC_TabBar, nIndex); 217*52d13b84SAndre Fischer 218*52d13b84SAndre Fischer return FocusLocation(PC_None, -1); 21965908a7eSAndre Fischer } 22065908a7eSAndre Fischer 22165908a7eSAndre Fischer 22265908a7eSAndre Fischer 22365908a7eSAndre Fischer 22465908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const 22565908a7eSAndre Fischer { 22665908a7eSAndre Fischer for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end()); 22765908a7eSAndre Fischer iPanel!=iEnd; 22865908a7eSAndre Fischer ++iPanel) 22965908a7eSAndre Fischer { 23065908a7eSAndre Fischer if ((*iPanel)->HasFocus()) 23165908a7eSAndre Fischer return true; 23265908a7eSAndre Fischer else if ((*iPanel)->HasChildPathFocus()) 23365908a7eSAndre Fischer return true; 23465908a7eSAndre Fischer } 23565908a7eSAndre Fischer return false; 23665908a7eSAndre Fischer } 23765908a7eSAndre Fischer 23865908a7eSAndre Fischer 23965908a7eSAndre Fischer 24065908a7eSAndre Fischer 24165908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const 24265908a7eSAndre Fischer { 24365908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end()); 24465908a7eSAndre Fischer iButton!=iEnd; 24565908a7eSAndre Fischer ++iButton) 24665908a7eSAndre Fischer { 24765908a7eSAndre Fischer if ((*iButton)->HasFocus()) 24865908a7eSAndre Fischer return true; 24965908a7eSAndre Fischer } 25065908a7eSAndre Fischer return false; 25165908a7eSAndre Fischer } 25265908a7eSAndre Fischer 25365908a7eSAndre Fischer 25465908a7eSAndre Fischer 25565908a7eSAndre Fischer 256*52d13b84SAndre Fischer void FocusManager::FocusDeckTitle (void) 257*52d13b84SAndre Fischer { 258*52d13b84SAndre Fischer if (IsDeckTitleVisible()) 259*52d13b84SAndre Fischer { 260*52d13b84SAndre Fischer ToolBox& rToolBox = mpDeckTitleBar->GetToolBox(); 261*52d13b84SAndre Fischer if (rToolBox.GetItemCount() > 0) 262*52d13b84SAndre Fischer { 263*52d13b84SAndre Fischer rToolBox.GrabFocus(); 264*52d13b84SAndre Fischer rToolBox.Invalidate(); 265*52d13b84SAndre Fischer } 266*52d13b84SAndre Fischer } 267*52d13b84SAndre Fischer else 268*52d13b84SAndre Fischer FocusPanel(0); 269*52d13b84SAndre Fischer } 270*52d13b84SAndre Fischer 271*52d13b84SAndre Fischer 272*52d13b84SAndre Fischer 273*52d13b84SAndre Fischer 274*52d13b84SAndre Fischer bool FocusManager::IsDeckTitleVisible (void) const 275*52d13b84SAndre Fischer { 276*52d13b84SAndre Fischer return mpDeckTitleBar != NULL && mpDeckTitleBar->IsVisible(); 277*52d13b84SAndre Fischer } 278*52d13b84SAndre Fischer 279*52d13b84SAndre Fischer 280*52d13b84SAndre Fischer 281*52d13b84SAndre Fischer 28265908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) 28365908a7eSAndre Fischer { 28465908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 28565908a7eSAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 28665908a7eSAndre Fischer if (pTitleBar!=NULL && pTitleBar->IsVisible()) 28765908a7eSAndre Fischer { 28865908a7eSAndre Fischer rPanel.SetExpanded(true); 28965908a7eSAndre Fischer pTitleBar->GrabFocus(); 29065908a7eSAndre Fischer } 29165908a7eSAndre Fischer else 29265908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 293*52d13b84SAndre Fischer if (maShowPanelFunctor) 294*52d13b84SAndre Fischer maShowPanelFunctor(rPanel); 29565908a7eSAndre Fischer } 29665908a7eSAndre Fischer 29765908a7eSAndre Fischer 29865908a7eSAndre Fischer 29965908a7eSAndre Fischer 30065908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 30165908a7eSAndre Fischer { 30265908a7eSAndre Fischer Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 30365908a7eSAndre Fischer if (pWindow != NULL) 30465908a7eSAndre Fischer pWindow->GrabFocus(); 30565908a7eSAndre Fischer } 30665908a7eSAndre Fischer 30765908a7eSAndre Fischer 30865908a7eSAndre Fischer 30965908a7eSAndre Fischer 31065908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 31165908a7eSAndre Fischer { 31265908a7eSAndre Fischer maButtons[nButtonIndex]->GrabFocus(); 31365908a7eSAndre Fischer maButtons[nButtonIndex]->Invalidate(); 31465908a7eSAndre Fischer } 31565908a7eSAndre Fischer 31665908a7eSAndre Fischer 31765908a7eSAndre Fischer 31865908a7eSAndre Fischer 31965908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 32065908a7eSAndre Fischer { 32165908a7eSAndre Fischer maButtons[nButtonIndex]->Click(); 32265908a7eSAndre Fischer if (nButtonIndex > 0) 32365908a7eSAndre Fischer if ( ! maPanels.empty()) 32465908a7eSAndre Fischer FocusPanel(0); 32565908a7eSAndre Fischer maButtons[nButtonIndex]->GetParent()->Invalidate(); 32665908a7eSAndre Fischer } 32765908a7eSAndre Fischer 32865908a7eSAndre Fischer 32965908a7eSAndre Fischer 33065908a7eSAndre Fischer 33165908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow) 33265908a7eSAndre Fischer { 33365908a7eSAndre Fischer ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow)); 33465908a7eSAndre Fischer if (iPanel != maPanels.end()) 33565908a7eSAndre Fischer { 33665908a7eSAndre Fischer UnregisterWindow(rWindow); 33765908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 33865908a7eSAndre Fischer { 33965908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 34065908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 34165908a7eSAndre Fischer } 34265908a7eSAndre Fischer maPanels.erase(iPanel); 34365908a7eSAndre Fischer return; 34465908a7eSAndre Fischer } 34565908a7eSAndre Fischer 34665908a7eSAndre Fischer ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow)); 34765908a7eSAndre Fischer if (iButton != maButtons.end()) 34865908a7eSAndre Fischer { 34965908a7eSAndre Fischer UnregisterWindow(rWindow); 35065908a7eSAndre Fischer maButtons.erase(iButton); 35165908a7eSAndre Fischer return; 35265908a7eSAndre Fischer } 35365908a7eSAndre Fischer } 35465908a7eSAndre Fischer 35565908a7eSAndre Fischer 35665908a7eSAndre Fischer 35765908a7eSAndre Fischer 35865908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel ( 359*52d13b84SAndre Fischer const FocusLocation aFocusLocation, 36065908a7eSAndre Fischer const sal_Int32 nDirection) 36165908a7eSAndre Fischer { 362*52d13b84SAndre Fischer const bool bHasToolBoxItem ( 363*52d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GetItemCount() > 0); 364*52d13b84SAndre Fischer switch (aFocusLocation.meComponent) 36565908a7eSAndre Fischer { 366*52d13b84SAndre Fischer case PC_PanelTitle: 367*52d13b84SAndre Fischer if (nDirection > 0 && bHasToolBoxItem) 368*52d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GetToolBox().GrabFocus(); 36965908a7eSAndre Fischer else 370*52d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 37165908a7eSAndre Fischer return true; 37265908a7eSAndre Fischer 373*52d13b84SAndre Fischer case PC_PanelToolBox: 374*52d13b84SAndre Fischer if (nDirection < 0 && bHasToolBoxItem) 375*52d13b84SAndre Fischer maPanels[aFocusLocation.mnIndex]->GetTitleBar()->GrabFocus(); 37665908a7eSAndre Fischer else 377*52d13b84SAndre Fischer FocusPanelContent(aFocusLocation.mnIndex); 37865908a7eSAndre Fischer return true; 37965908a7eSAndre Fischer 38065908a7eSAndre Fischer default: 38165908a7eSAndre Fischer return false; 38265908a7eSAndre Fischer } 38365908a7eSAndre Fischer } 38465908a7eSAndre Fischer 38565908a7eSAndre Fischer 38665908a7eSAndre Fischer 38765908a7eSAndre Fischer 38865908a7eSAndre Fischer void FocusManager::HandleKeyEvent ( 38965908a7eSAndre Fischer const KeyCode& rKeyCode, 39065908a7eSAndre Fischer const Window& rWindow) 39165908a7eSAndre Fischer { 392*52d13b84SAndre Fischer const FocusLocation aLocation (GetFocusLocation(rWindow)); 39365908a7eSAndre Fischer 39465908a7eSAndre Fischer switch (rKeyCode.GetCode()) 39565908a7eSAndre Fischer { 396*52d13b84SAndre Fischer case KEY_SPACE: 397*52d13b84SAndre Fischer switch (aLocation.meComponent) 398*52d13b84SAndre Fischer { 399*52d13b84SAndre Fischer case PC_PanelTitle: 400*52d13b84SAndre Fischer // Toggle panel between expanded and collapsed. 401*52d13b84SAndre Fischer maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded()); 40265908a7eSAndre Fischer break; 40365908a7eSAndre Fischer 404*52d13b84SAndre Fischer case PC_TabBar: 40565908a7eSAndre Fischer // Activate the button. 406*52d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 407*52d13b84SAndre Fischer break; 408*52d13b84SAndre Fischer 409*52d13b84SAndre Fischer default: 410*52d13b84SAndre Fischer break; 41165908a7eSAndre Fischer } 41265908a7eSAndre Fischer return; 41365908a7eSAndre Fischer 41465908a7eSAndre Fischer case KEY_RETURN: 415*52d13b84SAndre Fischer switch (aLocation.meComponent) 41665908a7eSAndre Fischer { 417*52d13b84SAndre Fischer case PC_DeckToolBox: 418*52d13b84SAndre Fischer FocusButton(0); 419*52d13b84SAndre Fischer break; 420*52d13b84SAndre Fischer 421*52d13b84SAndre Fischer case PC_PanelTitle: 42265908a7eSAndre Fischer // Enter the panel. 423*52d13b84SAndre Fischer FocusPanelContent(aLocation.mnIndex); 424*52d13b84SAndre Fischer break; 425*52d13b84SAndre Fischer 426*52d13b84SAndre Fischer case PC_TabBar: 42765908a7eSAndre Fischer // Activate the button. 428*52d13b84SAndre Fischer ClickButton(aLocation.mnIndex); 429*52d13b84SAndre Fischer break; 430*52d13b84SAndre Fischer 431*52d13b84SAndre Fischer default: 432*52d13b84SAndre Fischer break; 43365908a7eSAndre Fischer } 43465908a7eSAndre Fischer return; 43565908a7eSAndre Fischer 43665908a7eSAndre Fischer case KEY_TAB: 437*52d13b84SAndre Fischer switch (aLocation.meComponent) 43865908a7eSAndre Fischer { 439*52d13b84SAndre Fischer case PC_PanelTitle: 440*52d13b84SAndre Fischer case PC_PanelToolBox: 441*52d13b84SAndre Fischer case PC_PanelContent: 44265908a7eSAndre Fischer if (rKeyCode.IsShift()) 443*52d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, -1); 44465908a7eSAndre Fischer else 445*52d13b84SAndre Fischer MoveFocusInsidePanel(aLocation, +1); 446*52d13b84SAndre Fischer break; 447*52d13b84SAndre Fischer 448*52d13b84SAndre Fischer default: 449*52d13b84SAndre Fischer break; 45065908a7eSAndre Fischer } 45165908a7eSAndre Fischer break; 45265908a7eSAndre Fischer 45365908a7eSAndre Fischer case KEY_LEFT: 45465908a7eSAndre Fischer case KEY_UP: 455*52d13b84SAndre Fischer switch (aLocation.meComponent) 45665908a7eSAndre Fischer { 457*52d13b84SAndre Fischer case PC_PanelTitle: 458*52d13b84SAndre Fischer case PC_PanelToolBox: 459*52d13b84SAndre Fischer case PC_PanelContent: 460*52d13b84SAndre Fischer // Go to previous panel or the deck title. 461*52d13b84SAndre Fischer if (aLocation.mnIndex > 0) 462*52d13b84SAndre Fischer FocusPanel(aLocation.mnIndex-1); 463*52d13b84SAndre Fischer else if (IsDeckTitleVisible()) 464*52d13b84SAndre Fischer FocusDeckTitle(); 465*52d13b84SAndre Fischer else 466*52d13b84SAndre Fischer FocusButton(maButtons.size()-1); 467*52d13b84SAndre Fischer break; 468*52d13b84SAndre Fischer 469*52d13b84SAndre Fischer case PC_DeckTitle: 470*52d13b84SAndre Fischer case PC_DeckToolBox: 471*52d13b84SAndre Fischer // Focus the last button. 472*52d13b84SAndre Fischer FocusButton(maButtons.size()-1); 473*52d13b84SAndre Fischer break; 474*52d13b84SAndre Fischer 475*52d13b84SAndre Fischer case PC_TabBar: 476*52d13b84SAndre Fischer // Go to previous tab bar item. 477*52d13b84SAndre Fischer if (aLocation.mnIndex == 0) 478*52d13b84SAndre Fischer FocusPanel(maPanels.size()-1); 479*52d13b84SAndre Fischer else 480*52d13b84SAndre Fischer FocusButton((aLocation.mnIndex + maButtons.size() - 1) % maButtons.size()); 481*52d13b84SAndre Fischer break; 482*52d13b84SAndre Fischer 483*52d13b84SAndre Fischer default: 484*52d13b84SAndre Fischer break; 48565908a7eSAndre Fischer } 48665908a7eSAndre Fischer break; 48765908a7eSAndre Fischer 48865908a7eSAndre Fischer case KEY_RIGHT: 48965908a7eSAndre Fischer case KEY_DOWN: 490*52d13b84SAndre Fischer switch(aLocation.meComponent) 49165908a7eSAndre Fischer { 492*52d13b84SAndre Fischer case PC_PanelTitle: 493*52d13b84SAndre Fischer case PC_PanelToolBox: 494*52d13b84SAndre Fischer case PC_PanelContent: 495*52d13b84SAndre Fischer // Go to next panel. 496*52d13b84SAndre Fischer if (aLocation.mnIndex < maPanels.size()-1) 497*52d13b84SAndre Fischer FocusPanel(aLocation.mnIndex+1); 498*52d13b84SAndre Fischer else 499*52d13b84SAndre Fischer FocusButton(0); 500*52d13b84SAndre Fischer break; 501*52d13b84SAndre Fischer 502*52d13b84SAndre Fischer case PC_DeckTitle: 503*52d13b84SAndre Fischer case PC_DeckToolBox: 504*52d13b84SAndre Fischer // Focus the first panel. 505*52d13b84SAndre Fischer FocusPanel(0); 506*52d13b84SAndre Fischer break; 507*52d13b84SAndre Fischer 508*52d13b84SAndre Fischer case PC_TabBar: 509*52d13b84SAndre Fischer // Go to next tab bar item. 510*52d13b84SAndre Fischer if (aLocation.mnIndex < maButtons.size()-1) 511*52d13b84SAndre Fischer FocusButton(aLocation.mnIndex + 1); 512*52d13b84SAndre Fischer else if (IsDeckTitleVisible()) 513*52d13b84SAndre Fischer FocusDeckTitle(); 514*52d13b84SAndre Fischer else 515*52d13b84SAndre Fischer FocusPanel(0); 516*52d13b84SAndre Fischer break; 517*52d13b84SAndre Fischer 518*52d13b84SAndre Fischer default: 51965908a7eSAndre Fischer break; 52065908a7eSAndre Fischer } 52165908a7eSAndre Fischer break; 52265908a7eSAndre Fischer } 52365908a7eSAndre Fischer } 52465908a7eSAndre Fischer 52565908a7eSAndre Fischer 52665908a7eSAndre Fischer 52765908a7eSAndre Fischer 52865908a7eSAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent) 52965908a7eSAndre Fischer { 53065908a7eSAndre Fischer if (pEvent == NULL) 53165908a7eSAndre Fischer return 0; 53265908a7eSAndre Fischer 53365908a7eSAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 53465908a7eSAndre Fischer return 0; 53565908a7eSAndre Fischer 53665908a7eSAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 53765908a7eSAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 53865908a7eSAndre Fischer if (pSource == NULL) 53965908a7eSAndre Fischer return 0; 54065908a7eSAndre Fischer 54165908a7eSAndre Fischer switch (pWindowEvent->GetId()) 54265908a7eSAndre Fischer { 54365908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 54465908a7eSAndre Fischer { 54565908a7eSAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 54665908a7eSAndre Fischer HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource); 54765908a7eSAndre Fischer return 1; 54865908a7eSAndre Fischer } 54965908a7eSAndre Fischer 55065908a7eSAndre Fischer case VCLEVENT_OBJECT_DYING: 55165908a7eSAndre Fischer RemoveWindow(*pSource); 55265908a7eSAndre Fischer return 1; 55365908a7eSAndre Fischer 55465908a7eSAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 55565908a7eSAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 55665908a7eSAndre Fischer pSource->Invalidate(); 55765908a7eSAndre Fischer } 558*52d13b84SAndre Fischer 55965908a7eSAndre Fischer return 0; 56065908a7eSAndre Fischer } 56165908a7eSAndre Fischer 56265908a7eSAndre Fischer 56365908a7eSAndre Fischer 564*52d13b84SAndre Fischer 565*52d13b84SAndre Fischer IMPL_LINK(FocusManager, ChildEventListener, VclSimpleEvent*, pEvent) 566*52d13b84SAndre Fischer { 567*52d13b84SAndre Fischer if (pEvent == NULL) 568*52d13b84SAndre Fischer return 0; 569*52d13b84SAndre Fischer 570*52d13b84SAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 571*52d13b84SAndre Fischer return 0; 572*52d13b84SAndre Fischer 573*52d13b84SAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 574*52d13b84SAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 575*52d13b84SAndre Fischer if (pSource == NULL) 576*52d13b84SAndre Fischer return 0; 577*52d13b84SAndre Fischer 578*52d13b84SAndre Fischer switch (pWindowEvent->GetId()) 579*52d13b84SAndre Fischer { 580*52d13b84SAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 581*52d13b84SAndre Fischer { 582*52d13b84SAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 583*52d13b84SAndre Fischer 584*52d13b84SAndre Fischer // Go up the window hierarchy to find the parent of the 585*52d13b84SAndre Fischer // event source which is known to us. 586*52d13b84SAndre Fischer Window* pWindow = pSource; 587*52d13b84SAndre Fischer FocusLocation aLocation (PC_None, -1); 588*52d13b84SAndre Fischer while (true) 589*52d13b84SAndre Fischer { 590*52d13b84SAndre Fischer if (pWindow == NULL) 591*52d13b84SAndre Fischer break; 592*52d13b84SAndre Fischer aLocation = GetFocusLocation(*pWindow); 593*52d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 594*52d13b84SAndre Fischer break; 595*52d13b84SAndre Fischer pWindow = pWindow->GetParent(); 596*52d13b84SAndre Fischer } 597*52d13b84SAndre Fischer 598*52d13b84SAndre Fischer if (aLocation.meComponent != PC_None) 599*52d13b84SAndre Fischer { 600*52d13b84SAndre Fischer switch (pKeyEvent->GetKeyCode().GetCode()) 601*52d13b84SAndre Fischer { 602*52d13b84SAndre Fischer case KEY_ESCAPE: 603*52d13b84SAndre Fischer // Return focus back to the panel title. 604*52d13b84SAndre Fischer FocusPanel(aLocation.mnIndex); 605*52d13b84SAndre Fischer break; 606*52d13b84SAndre Fischer 607*52d13b84SAndre Fischer default: 608*52d13b84SAndre Fischer break; 609*52d13b84SAndre Fischer } 610*52d13b84SAndre Fischer } 611*52d13b84SAndre Fischer break; 612*52d13b84SAndre Fischer } 613*52d13b84SAndre Fischer 614*52d13b84SAndre Fischer default: 615*52d13b84SAndre Fischer break; 616*52d13b84SAndre Fischer } 617*52d13b84SAndre Fischer 618*52d13b84SAndre Fischer return 1; 619*52d13b84SAndre Fischer } 620*52d13b84SAndre Fischer 621*52d13b84SAndre Fischer 62265908a7eSAndre Fischer } } // end of namespace sfx2::sidebar 623