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" 2665908a7eSAndre Fischer #include "Tools.hxx" 2765908a7eSAndre Fischer #include "TitleBar.hxx" 2865908a7eSAndre Fischer #include <vcl/button.hxx> 2965908a7eSAndre Fischer #include <vcl/toolbox.hxx> 3065908a7eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 3165908a7eSAndre Fischer 3265908a7eSAndre Fischer 3365908a7eSAndre Fischer namespace sfx2 { namespace sidebar { 3465908a7eSAndre Fischer 3565908a7eSAndre Fischer namespace 3665908a7eSAndre Fischer { 3765908a7eSAndre Fischer enum PanelComponent 3865908a7eSAndre Fischer { 3965908a7eSAndre Fischer PC_TitleBar, 4065908a7eSAndre Fischer PC_ToolBox, 4165908a7eSAndre Fischer PC_Content, 4265908a7eSAndre Fischer PC_None 4365908a7eSAndre Fischer }; 4465908a7eSAndre Fischer 4565908a7eSAndre Fischer PanelComponent GetFocusedComponent (const Panel& rPanel) 4665908a7eSAndre Fischer { 4765908a7eSAndre Fischer if (rPanel.HasFocus()) 4865908a7eSAndre Fischer return PC_Content; 4965908a7eSAndre Fischer else if (rPanel.GetTitleBar() != NULL) 5065908a7eSAndre Fischer if (rPanel.GetTitleBar()->HasFocus()) 5165908a7eSAndre Fischer return PC_TitleBar; 5265908a7eSAndre Fischer else if (rPanel.GetTitleBar()->GetToolBox().HasFocus()) 5365908a7eSAndre Fischer return PC_ToolBox; 54*76d44fc7SPavel Janík 55*76d44fc7SPavel Janík return PC_None; 5665908a7eSAndre Fischer } 5765908a7eSAndre Fischer } 5865908a7eSAndre Fischer 5965908a7eSAndre Fischer 6065908a7eSAndre Fischer FocusManager::FocusManager (void) 6165908a7eSAndre Fischer : maPanels(), 6265908a7eSAndre Fischer maButtons(), 6365908a7eSAndre Fischer mpTopLevelWindow(NULL) 6465908a7eSAndre Fischer { 6565908a7eSAndre Fischer } 6665908a7eSAndre Fischer 6765908a7eSAndre Fischer 6865908a7eSAndre Fischer 6965908a7eSAndre Fischer 7065908a7eSAndre Fischer FocusManager::~FocusManager (void) 7165908a7eSAndre Fischer { 7265908a7eSAndre Fischer Clear(); 7365908a7eSAndre Fischer } 7465908a7eSAndre Fischer 7565908a7eSAndre Fischer 7665908a7eSAndre Fischer 7765908a7eSAndre Fischer 7865908a7eSAndre Fischer void FocusManager::GrabFocus (void) 7965908a7eSAndre Fischer { 8065908a7eSAndre Fischer if ( ! maPanels.empty()) 8165908a7eSAndre Fischer FocusPanel(0); 8265908a7eSAndre Fischer } 8365908a7eSAndre Fischer 8465908a7eSAndre Fischer 8565908a7eSAndre Fischer 8665908a7eSAndre Fischer 8765908a7eSAndre Fischer void FocusManager::Clear (void) 8865908a7eSAndre Fischer { 8965908a7eSAndre Fischer ClearPanels(); 9065908a7eSAndre Fischer ClearButtons(); 9165908a7eSAndre Fischer } 9265908a7eSAndre Fischer 9365908a7eSAndre Fischer 9465908a7eSAndre Fischer 9565908a7eSAndre Fischer void FocusManager::ClearPanels (void) 9665908a7eSAndre Fischer { 9765908a7eSAndre Fischer SetTopLevelWindow(NULL); 9865908a7eSAndre Fischer 9965908a7eSAndre Fischer ::std::vector<Panel*> aPanels; 10065908a7eSAndre Fischer aPanels.swap(maPanels); 10165908a7eSAndre Fischer for (::std::vector<Panel*>::iterator iPanel(aPanels.begin()),iEnd(aPanels.end()); 10265908a7eSAndre Fischer iPanel!=iEnd; 10365908a7eSAndre Fischer ++iPanel) 10465908a7eSAndre Fischer { 10565908a7eSAndre Fischer UnregisterWindow(**iPanel); 10665908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 10765908a7eSAndre Fischer { 10865908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 10965908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 11065908a7eSAndre Fischer } 11165908a7eSAndre Fischer } 11265908a7eSAndre Fischer } 11365908a7eSAndre Fischer 11465908a7eSAndre Fischer 11565908a7eSAndre Fischer 11665908a7eSAndre Fischer 11765908a7eSAndre Fischer void FocusManager::ClearButtons (void) 11865908a7eSAndre Fischer { 11965908a7eSAndre Fischer ::std::vector<Window*> aButtons; 12065908a7eSAndre Fischer for (::std::vector<Window*>::iterator iButton(aButtons.begin()),iEnd(aButtons.end()); 12165908a7eSAndre Fischer iButton!=iEnd; 12265908a7eSAndre Fischer ++iButton) 12365908a7eSAndre Fischer { 12465908a7eSAndre Fischer UnregisterWindow(**iButton); 12565908a7eSAndre Fischer } 12665908a7eSAndre Fischer } 12765908a7eSAndre Fischer 12865908a7eSAndre Fischer 12965908a7eSAndre Fischer 13065908a7eSAndre Fischer 13165908a7eSAndre Fischer void FocusManager::SetPanels (const SharedPanelContainer& rPanels) 13265908a7eSAndre Fischer { 13365908a7eSAndre Fischer ClearPanels(); 13465908a7eSAndre Fischer for(SharedPanelContainer::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end()); 13565908a7eSAndre Fischer iPanel!=iEnd; 13665908a7eSAndre Fischer ++iPanel) 13765908a7eSAndre Fischer { 13865908a7eSAndre Fischer RegisterWindow(**iPanel); 13965908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 14065908a7eSAndre Fischer { 14165908a7eSAndre Fischer RegisterWindow(*(*iPanel)->GetTitleBar()); 14265908a7eSAndre Fischer RegisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 14365908a7eSAndre Fischer } 14465908a7eSAndre Fischer maPanels.push_back(iPanel->get()); 14565908a7eSAndre Fischer } 14665908a7eSAndre Fischer 14765908a7eSAndre Fischer RegisterTopLevelListener(); 14865908a7eSAndre Fischer } 14965908a7eSAndre Fischer 15065908a7eSAndre Fischer 15165908a7eSAndre Fischer 15265908a7eSAndre Fischer 15365908a7eSAndre Fischer void FocusManager::SetButtons (const ::std::vector<Button*>& rButtons) 15465908a7eSAndre Fischer { 15565908a7eSAndre Fischer ClearButtons(); 15665908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(rButtons.begin()),iEnd(rButtons.end()); 15765908a7eSAndre Fischer iButton!=iEnd; 15865908a7eSAndre Fischer ++iButton) 15965908a7eSAndre Fischer { 16065908a7eSAndre Fischer RegisterWindow(**iButton); 16165908a7eSAndre Fischer maButtons.push_back(*iButton); 16265908a7eSAndre Fischer } 16365908a7eSAndre Fischer } 16465908a7eSAndre Fischer 16565908a7eSAndre Fischer 16665908a7eSAndre Fischer 16765908a7eSAndre Fischer 16865908a7eSAndre Fischer void FocusManager::RegisterWindow (Window& rWindow) 16965908a7eSAndre Fischer { 17065908a7eSAndre Fischer rWindow.AddEventListener(LINK(this, FocusManager, WindowEventListener)); 17165908a7eSAndre Fischer } 17265908a7eSAndre Fischer 17365908a7eSAndre Fischer 17465908a7eSAndre Fischer 17565908a7eSAndre Fischer 17665908a7eSAndre Fischer void FocusManager::UnregisterWindow (Window& rWindow) 17765908a7eSAndre Fischer { 17865908a7eSAndre Fischer rWindow.RemoveEventListener(LINK(this, FocusManager, WindowEventListener)); 17965908a7eSAndre Fischer } 18065908a7eSAndre Fischer 18165908a7eSAndre Fischer 18265908a7eSAndre Fischer 18365908a7eSAndre Fischer 18465908a7eSAndre Fischer void FocusManager::RegisterTopLevelListener (void) 18565908a7eSAndre Fischer { 18665908a7eSAndre Fischer if (maPanels.empty()) 18765908a7eSAndre Fischer return; 18865908a7eSAndre Fischer Window* pWindow = maPanels.front(); 18965908a7eSAndre Fischer while (pWindow != NULL && pWindow->GetParent()!=NULL) 19065908a7eSAndre Fischer { 19165908a7eSAndre Fischer pWindow = pWindow->GetParent(); 19265908a7eSAndre Fischer } 19365908a7eSAndre Fischer SetTopLevelWindow(pWindow); 19465908a7eSAndre Fischer } 19565908a7eSAndre Fischer 19665908a7eSAndre Fischer 19765908a7eSAndre Fischer 19865908a7eSAndre Fischer 19965908a7eSAndre Fischer void FocusManager::SetTopLevelWindow (Window* pWindow) 20065908a7eSAndre Fischer { 20165908a7eSAndre Fischer if (mpTopLevelWindow != pWindow) 20265908a7eSAndre Fischer { 20365908a7eSAndre Fischer if (mpTopLevelWindow != NULL) 20465908a7eSAndre Fischer { 20565908a7eSAndre Fischer UnregisterWindow(*mpTopLevelWindow); 20665908a7eSAndre Fischer mpTopLevelWindow->RemoveChildEventListener(LINK(this, FocusManager, WindowEventListener)); 20765908a7eSAndre Fischer } 20865908a7eSAndre Fischer mpTopLevelWindow = pWindow; 20965908a7eSAndre Fischer if (mpTopLevelWindow != NULL) 21065908a7eSAndre Fischer { 21165908a7eSAndre Fischer RegisterWindow(*mpTopLevelWindow); 21265908a7eSAndre Fischer mpTopLevelWindow->AddChildEventListener(LINK(this, FocusManager, WindowEventListener)); 21365908a7eSAndre Fischer } 21465908a7eSAndre Fischer } 21565908a7eSAndre Fischer } 21665908a7eSAndre Fischer 21765908a7eSAndre Fischer 21865908a7eSAndre Fischer 21965908a7eSAndre Fischer 22065908a7eSAndre Fischer sal_Int32 FocusManager::GetPanelIndex (const Window& rWindow) const 22165908a7eSAndre Fischer { 22265908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex) 22365908a7eSAndre Fischer { 22465908a7eSAndre Fischer if (maPanels[nIndex] == &rWindow) 22565908a7eSAndre Fischer return nIndex; 22665908a7eSAndre Fischer TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar(); 22765908a7eSAndre Fischer if (pTitleBar == &rWindow) 22865908a7eSAndre Fischer return nIndex; 22965908a7eSAndre Fischer if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow) 23065908a7eSAndre Fischer return nIndex; 23165908a7eSAndre Fischer } 23265908a7eSAndre Fischer return -1; 23365908a7eSAndre Fischer } 23465908a7eSAndre Fischer 23565908a7eSAndre Fischer 23665908a7eSAndre Fischer 23765908a7eSAndre Fischer 23865908a7eSAndre Fischer sal_Int32 FocusManager::GetButtonIndex (const Window& rWindow) const 23965908a7eSAndre Fischer { 24065908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex) 24165908a7eSAndre Fischer if (maButtons[nIndex] == &rWindow) 24265908a7eSAndre Fischer return nIndex; 24365908a7eSAndre Fischer return -1; 24465908a7eSAndre Fischer } 24565908a7eSAndre Fischer 24665908a7eSAndre Fischer 24765908a7eSAndre Fischer 24865908a7eSAndre Fischer 24965908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const 25065908a7eSAndre Fischer { 25165908a7eSAndre Fischer for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end()); 25265908a7eSAndre Fischer iPanel!=iEnd; 25365908a7eSAndre Fischer ++iPanel) 25465908a7eSAndre Fischer { 25565908a7eSAndre Fischer if ((*iPanel)->HasFocus()) 25665908a7eSAndre Fischer return true; 25765908a7eSAndre Fischer else if ((*iPanel)->HasChildPathFocus()) 25865908a7eSAndre Fischer return true; 25965908a7eSAndre Fischer } 26065908a7eSAndre Fischer return false; 26165908a7eSAndre Fischer } 26265908a7eSAndre Fischer 26365908a7eSAndre Fischer 26465908a7eSAndre Fischer 26565908a7eSAndre Fischer 26665908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const 26765908a7eSAndre Fischer { 26865908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end()); 26965908a7eSAndre Fischer iButton!=iEnd; 27065908a7eSAndre Fischer ++iButton) 27165908a7eSAndre Fischer { 27265908a7eSAndre Fischer if ((*iButton)->HasFocus()) 27365908a7eSAndre Fischer return true; 27465908a7eSAndre Fischer } 27565908a7eSAndre Fischer return false; 27665908a7eSAndre Fischer } 27765908a7eSAndre Fischer 27865908a7eSAndre Fischer 27965908a7eSAndre Fischer 28065908a7eSAndre Fischer 28165908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) 28265908a7eSAndre Fischer { 28365908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 28465908a7eSAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 28565908a7eSAndre Fischer if (pTitleBar!=NULL && pTitleBar->IsVisible()) 28665908a7eSAndre Fischer { 28765908a7eSAndre Fischer rPanel.SetExpanded(true); 28865908a7eSAndre Fischer pTitleBar->GrabFocus(); 28965908a7eSAndre Fischer } 29065908a7eSAndre Fischer else 29165908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 29265908a7eSAndre Fischer } 29365908a7eSAndre Fischer 29465908a7eSAndre Fischer 29565908a7eSAndre Fischer 29665908a7eSAndre Fischer 29765908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 29865908a7eSAndre Fischer { 29965908a7eSAndre Fischer Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 30065908a7eSAndre Fischer if (pWindow != NULL) 30165908a7eSAndre Fischer pWindow->GrabFocus(); 30265908a7eSAndre Fischer } 30365908a7eSAndre Fischer 30465908a7eSAndre Fischer 30565908a7eSAndre Fischer 30665908a7eSAndre Fischer 30765908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 30865908a7eSAndre Fischer { 30965908a7eSAndre Fischer maButtons[nButtonIndex]->GrabFocus(); 31065908a7eSAndre Fischer maButtons[nButtonIndex]->Invalidate(); 31165908a7eSAndre Fischer } 31265908a7eSAndre Fischer 31365908a7eSAndre Fischer 31465908a7eSAndre Fischer 31565908a7eSAndre Fischer 31665908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 31765908a7eSAndre Fischer { 31865908a7eSAndre Fischer maButtons[nButtonIndex]->Click(); 31965908a7eSAndre Fischer if (nButtonIndex > 0) 32065908a7eSAndre Fischer if ( ! maPanels.empty()) 32165908a7eSAndre Fischer FocusPanel(0); 32265908a7eSAndre Fischer maButtons[nButtonIndex]->GetParent()->Invalidate(); 32365908a7eSAndre Fischer } 32465908a7eSAndre Fischer 32565908a7eSAndre Fischer 32665908a7eSAndre Fischer 32765908a7eSAndre Fischer 32865908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow) 32965908a7eSAndre Fischer { 33065908a7eSAndre Fischer ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow)); 33165908a7eSAndre Fischer if (iPanel != maPanels.end()) 33265908a7eSAndre Fischer { 33365908a7eSAndre Fischer UnregisterWindow(rWindow); 33465908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 33565908a7eSAndre Fischer { 33665908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 33765908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 33865908a7eSAndre Fischer } 33965908a7eSAndre Fischer maPanels.erase(iPanel); 34065908a7eSAndre Fischer return; 34165908a7eSAndre Fischer } 34265908a7eSAndre Fischer 34365908a7eSAndre Fischer ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow)); 34465908a7eSAndre Fischer if (iButton != maButtons.end()) 34565908a7eSAndre Fischer { 34665908a7eSAndre Fischer UnregisterWindow(rWindow); 34765908a7eSAndre Fischer maButtons.erase(iButton); 34865908a7eSAndre Fischer return; 34965908a7eSAndre Fischer } 35065908a7eSAndre Fischer } 35165908a7eSAndre Fischer 35265908a7eSAndre Fischer 35365908a7eSAndre Fischer 35465908a7eSAndre Fischer 35565908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel ( 35665908a7eSAndre Fischer const sal_Int32 nPanelIndex, 35765908a7eSAndre Fischer const sal_Int32 nDirection) 35865908a7eSAndre Fischer { 35965908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 36065908a7eSAndre Fischer switch (GetFocusedComponent(rPanel)) 36165908a7eSAndre Fischer { 36265908a7eSAndre Fischer case PC_TitleBar: 36365908a7eSAndre Fischer if (nDirection > 0) 36465908a7eSAndre Fischer rPanel.GetTitleBar()->GetToolBox().GrabFocus(); 36565908a7eSAndre Fischer else 36665908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 36765908a7eSAndre Fischer return true; 36865908a7eSAndre Fischer 36965908a7eSAndre Fischer case PC_ToolBox: 37065908a7eSAndre Fischer if (nDirection > 0) 37165908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 37265908a7eSAndre Fischer else 37365908a7eSAndre Fischer rPanel.GetTitleBar()->GrabFocus(); 37465908a7eSAndre Fischer return true; 37565908a7eSAndre Fischer 37665908a7eSAndre Fischer default: 37765908a7eSAndre Fischer return false; 37865908a7eSAndre Fischer } 37965908a7eSAndre Fischer } 38065908a7eSAndre Fischer 38165908a7eSAndre Fischer 38265908a7eSAndre Fischer 38365908a7eSAndre Fischer 38465908a7eSAndre Fischer long FocusManager::NotifyDockingWindowEvent (const KeyEvent& rKeyEvent) 38565908a7eSAndre Fischer { 38665908a7eSAndre Fischer switch(rKeyEvent.GetKeyCode().GetCode()) 38765908a7eSAndre Fischer { 38865908a7eSAndre Fischer case KEY_F6: 38965908a7eSAndre Fischer if (rKeyEvent.GetKeyCode().IsShift()) 39065908a7eSAndre Fischer { 39165908a7eSAndre Fischer if (IsAnyButtonFocused()) 39265908a7eSAndre Fischer { 39365908a7eSAndre Fischer FocusPanel(0); 39465908a7eSAndre Fischer return 1; 39565908a7eSAndre Fischer } 39665908a7eSAndre Fischer } 39765908a7eSAndre Fischer else 39865908a7eSAndre Fischer { 39965908a7eSAndre Fischer if (IsAnyPanelFocused()) 40065908a7eSAndre Fischer { 40165908a7eSAndre Fischer FocusButton(0); 40265908a7eSAndre Fischer return 1; 40365908a7eSAndre Fischer } 40465908a7eSAndre Fischer } 40565908a7eSAndre Fischer break; 40665908a7eSAndre Fischer } 40765908a7eSAndre Fischer return 0; 40865908a7eSAndre Fischer } 40965908a7eSAndre Fischer 41065908a7eSAndre Fischer 41165908a7eSAndre Fischer 41265908a7eSAndre Fischer 41365908a7eSAndre Fischer void FocusManager::HandleKeyEvent ( 41465908a7eSAndre Fischer const KeyCode& rKeyCode, 41565908a7eSAndre Fischer const Window& rWindow) 41665908a7eSAndre Fischer { 41765908a7eSAndre Fischer if (rKeyCode.GetModifier() != 0) 41865908a7eSAndre Fischer return; 41965908a7eSAndre Fischer 42065908a7eSAndre Fischer const sal_Int32 nPanelIndex (GetPanelIndex(rWindow)); 421*76d44fc7SPavel Janík // const bool bIsPanelTitleFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow); 422*76d44fc7SPavel Janík // const bool bIsPanelToolBoxFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow); 42365908a7eSAndre Fischer sal_Int32 nButtonIndex (nPanelIndex==-1 ? GetButtonIndex(rWindow) : -1); 42465908a7eSAndre Fischer 42565908a7eSAndre Fischer switch (rKeyCode.GetCode()) 42665908a7eSAndre Fischer { 42765908a7eSAndre Fischer case KEY_F6: 42865908a7eSAndre Fischer if (nPanelIndex >= 0) 42965908a7eSAndre Fischer FocusButton(0); 43065908a7eSAndre Fischer else 43165908a7eSAndre Fischer return; 43265908a7eSAndre Fischer break; 43365908a7eSAndre Fischer 43465908a7eSAndre Fischer case KEY_SPACE: 43565908a7eSAndre Fischer if (nPanelIndex >= 0) 43665908a7eSAndre Fischer { 43765908a7eSAndre Fischer if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar) 43865908a7eSAndre Fischer { 43965908a7eSAndre Fischer // Toggle the expansion state. 44065908a7eSAndre Fischer maPanels[nPanelIndex]->SetExpanded( ! maPanels[nPanelIndex]->IsExpanded()); 44165908a7eSAndre Fischer } 44265908a7eSAndre Fischer } 44365908a7eSAndre Fischer else if (nButtonIndex >= 0) 44465908a7eSAndre Fischer { 44565908a7eSAndre Fischer // Activate the button. 44665908a7eSAndre Fischer ClickButton(nButtonIndex); 44765908a7eSAndre Fischer } 44865908a7eSAndre Fischer return; 44965908a7eSAndre Fischer 45065908a7eSAndre Fischer case KEY_RETURN: 45165908a7eSAndre Fischer if (nPanelIndex >= 0) 45265908a7eSAndre Fischer { 45365908a7eSAndre Fischer if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar) 45465908a7eSAndre Fischer { 45565908a7eSAndre Fischer // Enter the panel. 45665908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 45765908a7eSAndre Fischer } 45865908a7eSAndre Fischer } 45965908a7eSAndre Fischer else if (nButtonIndex >= 0) 46065908a7eSAndre Fischer { 46165908a7eSAndre Fischer // Activate the button. 46265908a7eSAndre Fischer ClickButton(nButtonIndex); 46365908a7eSAndre Fischer } 46465908a7eSAndre Fischer return; 46565908a7eSAndre Fischer 46665908a7eSAndre Fischer case KEY_TAB: 46765908a7eSAndre Fischer if (nPanelIndex >= 0) 46865908a7eSAndre Fischer { 46965908a7eSAndre Fischer if (rKeyCode.IsShift()) 47065908a7eSAndre Fischer MoveFocusInsidePanel(nPanelIndex, -1); 47165908a7eSAndre Fischer else 47265908a7eSAndre Fischer MoveFocusInsidePanel(nPanelIndex, +1); 47365908a7eSAndre Fischer } 47465908a7eSAndre Fischer break; 47565908a7eSAndre Fischer 47665908a7eSAndre Fischer case KEY_LEFT: 47765908a7eSAndre Fischer case KEY_UP: 47865908a7eSAndre Fischer // Go to previous element in focus ring. 47965908a7eSAndre Fischer if (nPanelIndex >= 0) 48065908a7eSAndre Fischer { 48165908a7eSAndre Fischer FocusPanel((nPanelIndex + maPanels.size() - 1) % maPanels.size()); 48265908a7eSAndre Fischer } 48365908a7eSAndre Fischer else if (nButtonIndex >= 0) 48465908a7eSAndre Fischer { 48565908a7eSAndre Fischer FocusButton((nButtonIndex + maButtons.size() - 1) % maButtons.size()); 48665908a7eSAndre Fischer } 48765908a7eSAndre Fischer break; 48865908a7eSAndre Fischer 48965908a7eSAndre Fischer case KEY_RIGHT: 49065908a7eSAndre Fischer case KEY_DOWN: 49165908a7eSAndre Fischer // Go to next element in focus ring. 49265908a7eSAndre Fischer if (nPanelIndex >= 0) 49365908a7eSAndre Fischer { 49465908a7eSAndre Fischer FocusPanel((nPanelIndex + 1) % maPanels.size()); 49565908a7eSAndre Fischer } 49665908a7eSAndre Fischer else if (nButtonIndex >= 0) 49765908a7eSAndre Fischer { 49865908a7eSAndre Fischer FocusButton((nButtonIndex + 1) % maButtons.size()); 49965908a7eSAndre Fischer } 50065908a7eSAndre Fischer break; 50165908a7eSAndre Fischer } 50265908a7eSAndre Fischer } 50365908a7eSAndre Fischer 50465908a7eSAndre Fischer 50565908a7eSAndre Fischer 50665908a7eSAndre Fischer 50765908a7eSAndre Fischer void FocusManager::HandleTopLevelEvent (VclWindowEvent& rEvent) 50865908a7eSAndre Fischer { 50965908a7eSAndre Fischer switch (rEvent.GetId()) 51065908a7eSAndre Fischer { 51165908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 51265908a7eSAndre Fischer { 51365908a7eSAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(rEvent.GetData()); 51465908a7eSAndre Fischer switch (pKeyEvent->GetKeyCode().GetCode()) 51565908a7eSAndre Fischer { 51665908a7eSAndre Fischer case KEY_F6: 51765908a7eSAndre Fischer OSL_TRACE(""); 51865908a7eSAndre Fischer break; 51965908a7eSAndre Fischer } 52065908a7eSAndre Fischer } 52165908a7eSAndre Fischer } 52265908a7eSAndre Fischer } 52365908a7eSAndre Fischer 52465908a7eSAndre Fischer 52565908a7eSAndre Fischer 52665908a7eSAndre Fischer 52765908a7eSAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent) 52865908a7eSAndre Fischer { 52965908a7eSAndre Fischer if (pEvent == NULL) 53065908a7eSAndre Fischer return 0; 53165908a7eSAndre Fischer 53265908a7eSAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 53365908a7eSAndre Fischer return 0; 53465908a7eSAndre Fischer 53565908a7eSAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 53665908a7eSAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 53765908a7eSAndre Fischer if (pSource == NULL) 53865908a7eSAndre Fischer return 0; 53965908a7eSAndre Fischer 54065908a7eSAndre Fischer if (pSource == mpTopLevelWindow) 54165908a7eSAndre Fischer HandleTopLevelEvent(*pWindowEvent); 54265908a7eSAndre Fischer else 54365908a7eSAndre Fischer switch (pWindowEvent->GetId()) 54465908a7eSAndre Fischer { 54565908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 54665908a7eSAndre Fischer { 54765908a7eSAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 54865908a7eSAndre Fischer HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource); 54965908a7eSAndre Fischer return 1; 55065908a7eSAndre Fischer } 55165908a7eSAndre Fischer 55265908a7eSAndre Fischer case VCLEVENT_OBJECT_DYING: 55365908a7eSAndre Fischer RemoveWindow(*pSource); 55465908a7eSAndre Fischer return 1; 55565908a7eSAndre Fischer 55665908a7eSAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 55765908a7eSAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 55865908a7eSAndre Fischer pSource->Invalidate(); 55965908a7eSAndre Fischer } 56065908a7eSAndre Fischer return 0; 56165908a7eSAndre Fischer } 56265908a7eSAndre Fischer 56365908a7eSAndre Fischer 56465908a7eSAndre Fischer 56565908a7eSAndre Fischer } } // end of namespace sfx2::sidebar 566