1*65908a7eSAndre Fischer /************************************************************** 2*65908a7eSAndre Fischer * 3*65908a7eSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*65908a7eSAndre Fischer * or more contributor license agreements. See the NOTICE file 5*65908a7eSAndre Fischer * distributed with this work for additional information 6*65908a7eSAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*65908a7eSAndre Fischer * to you under the Apache License, Version 2.0 (the 8*65908a7eSAndre Fischer * "License"); you may not use this file except in compliance 9*65908a7eSAndre Fischer * with the License. You may obtain a copy of the License at 10*65908a7eSAndre Fischer * 11*65908a7eSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*65908a7eSAndre Fischer * 13*65908a7eSAndre Fischer * Unless required by applicable law or agreed to in writing, 14*65908a7eSAndre Fischer * software distributed under the License is distributed on an 15*65908a7eSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*65908a7eSAndre Fischer * KIND, either express or implied. See the License for the 17*65908a7eSAndre Fischer * specific language governing permissions and limitations 18*65908a7eSAndre Fischer * under the License. 19*65908a7eSAndre Fischer * 20*65908a7eSAndre Fischer *************************************************************/ 21*65908a7eSAndre Fischer 22*65908a7eSAndre Fischer #include "precompiled_sfx2.hxx" 23*65908a7eSAndre Fischer 24*65908a7eSAndre Fischer #include "FocusManager.hxx" 25*65908a7eSAndre Fischer #include "Panel.hxx" 26*65908a7eSAndre Fischer #include "Tools.hxx" 27*65908a7eSAndre Fischer #include "TitleBar.hxx" 28*65908a7eSAndre Fischer #include <vcl/button.hxx> 29*65908a7eSAndre Fischer #include <vcl/toolbox.hxx> 30*65908a7eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 31*65908a7eSAndre Fischer 32*65908a7eSAndre Fischer 33*65908a7eSAndre Fischer namespace sfx2 { namespace sidebar { 34*65908a7eSAndre Fischer 35*65908a7eSAndre Fischer namespace 36*65908a7eSAndre Fischer { 37*65908a7eSAndre Fischer enum PanelComponent 38*65908a7eSAndre Fischer { 39*65908a7eSAndre Fischer PC_TitleBar, 40*65908a7eSAndre Fischer PC_ToolBox, 41*65908a7eSAndre Fischer PC_Content, 42*65908a7eSAndre Fischer PC_None 43*65908a7eSAndre Fischer }; 44*65908a7eSAndre Fischer 45*65908a7eSAndre Fischer PanelComponent GetFocusedComponent (const Panel& rPanel) 46*65908a7eSAndre Fischer { 47*65908a7eSAndre Fischer if (rPanel.HasFocus()) 48*65908a7eSAndre Fischer return PC_Content; 49*65908a7eSAndre Fischer else if (rPanel.GetTitleBar() != NULL) 50*65908a7eSAndre Fischer if (rPanel.GetTitleBar()->HasFocus()) 51*65908a7eSAndre Fischer return PC_TitleBar; 52*65908a7eSAndre Fischer else if (rPanel.GetTitleBar()->GetToolBox().HasFocus()) 53*65908a7eSAndre Fischer return PC_ToolBox; 54*65908a7eSAndre Fischer else 55*65908a7eSAndre Fischer return PC_None; 56*65908a7eSAndre Fischer } 57*65908a7eSAndre Fischer } 58*65908a7eSAndre Fischer 59*65908a7eSAndre Fischer 60*65908a7eSAndre Fischer FocusManager::FocusManager (void) 61*65908a7eSAndre Fischer : maPanels(), 62*65908a7eSAndre Fischer maButtons(), 63*65908a7eSAndre Fischer mpTopLevelWindow(NULL) 64*65908a7eSAndre Fischer { 65*65908a7eSAndre Fischer } 66*65908a7eSAndre Fischer 67*65908a7eSAndre Fischer 68*65908a7eSAndre Fischer 69*65908a7eSAndre Fischer 70*65908a7eSAndre Fischer FocusManager::~FocusManager (void) 71*65908a7eSAndre Fischer { 72*65908a7eSAndre Fischer Clear(); 73*65908a7eSAndre Fischer } 74*65908a7eSAndre Fischer 75*65908a7eSAndre Fischer 76*65908a7eSAndre Fischer 77*65908a7eSAndre Fischer 78*65908a7eSAndre Fischer void FocusManager::GrabFocus (void) 79*65908a7eSAndre Fischer { 80*65908a7eSAndre Fischer if ( ! maPanels.empty()) 81*65908a7eSAndre Fischer FocusPanel(0); 82*65908a7eSAndre Fischer } 83*65908a7eSAndre Fischer 84*65908a7eSAndre Fischer 85*65908a7eSAndre Fischer 86*65908a7eSAndre Fischer 87*65908a7eSAndre Fischer void FocusManager::Clear (void) 88*65908a7eSAndre Fischer { 89*65908a7eSAndre Fischer ClearPanels(); 90*65908a7eSAndre Fischer ClearButtons(); 91*65908a7eSAndre Fischer } 92*65908a7eSAndre Fischer 93*65908a7eSAndre Fischer 94*65908a7eSAndre Fischer 95*65908a7eSAndre Fischer void FocusManager::ClearPanels (void) 96*65908a7eSAndre Fischer { 97*65908a7eSAndre Fischer SetTopLevelWindow(NULL); 98*65908a7eSAndre Fischer 99*65908a7eSAndre Fischer ::std::vector<Panel*> aPanels; 100*65908a7eSAndre Fischer aPanels.swap(maPanels); 101*65908a7eSAndre Fischer for (::std::vector<Panel*>::iterator iPanel(aPanels.begin()),iEnd(aPanels.end()); 102*65908a7eSAndre Fischer iPanel!=iEnd; 103*65908a7eSAndre Fischer ++iPanel) 104*65908a7eSAndre Fischer { 105*65908a7eSAndre Fischer UnregisterWindow(**iPanel); 106*65908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 107*65908a7eSAndre Fischer { 108*65908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 109*65908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 110*65908a7eSAndre Fischer } 111*65908a7eSAndre Fischer } 112*65908a7eSAndre Fischer } 113*65908a7eSAndre Fischer 114*65908a7eSAndre Fischer 115*65908a7eSAndre Fischer 116*65908a7eSAndre Fischer 117*65908a7eSAndre Fischer void FocusManager::ClearButtons (void) 118*65908a7eSAndre Fischer { 119*65908a7eSAndre Fischer ::std::vector<Window*> aButtons; 120*65908a7eSAndre Fischer for (::std::vector<Window*>::iterator iButton(aButtons.begin()),iEnd(aButtons.end()); 121*65908a7eSAndre Fischer iButton!=iEnd; 122*65908a7eSAndre Fischer ++iButton) 123*65908a7eSAndre Fischer { 124*65908a7eSAndre Fischer UnregisterWindow(**iButton); 125*65908a7eSAndre Fischer } 126*65908a7eSAndre Fischer } 127*65908a7eSAndre Fischer 128*65908a7eSAndre Fischer 129*65908a7eSAndre Fischer 130*65908a7eSAndre Fischer 131*65908a7eSAndre Fischer void FocusManager::SetPanels (const SharedPanelContainer& rPanels) 132*65908a7eSAndre Fischer { 133*65908a7eSAndre Fischer ClearPanels(); 134*65908a7eSAndre Fischer for(SharedPanelContainer::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end()); 135*65908a7eSAndre Fischer iPanel!=iEnd; 136*65908a7eSAndre Fischer ++iPanel) 137*65908a7eSAndre Fischer { 138*65908a7eSAndre Fischer RegisterWindow(**iPanel); 139*65908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 140*65908a7eSAndre Fischer { 141*65908a7eSAndre Fischer RegisterWindow(*(*iPanel)->GetTitleBar()); 142*65908a7eSAndre Fischer RegisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 143*65908a7eSAndre Fischer } 144*65908a7eSAndre Fischer maPanels.push_back(iPanel->get()); 145*65908a7eSAndre Fischer } 146*65908a7eSAndre Fischer 147*65908a7eSAndre Fischer RegisterTopLevelListener(); 148*65908a7eSAndre Fischer } 149*65908a7eSAndre Fischer 150*65908a7eSAndre Fischer 151*65908a7eSAndre Fischer 152*65908a7eSAndre Fischer 153*65908a7eSAndre Fischer void FocusManager::SetButtons (const ::std::vector<Button*>& rButtons) 154*65908a7eSAndre Fischer { 155*65908a7eSAndre Fischer ClearButtons(); 156*65908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(rButtons.begin()),iEnd(rButtons.end()); 157*65908a7eSAndre Fischer iButton!=iEnd; 158*65908a7eSAndre Fischer ++iButton) 159*65908a7eSAndre Fischer { 160*65908a7eSAndre Fischer RegisterWindow(**iButton); 161*65908a7eSAndre Fischer maButtons.push_back(*iButton); 162*65908a7eSAndre Fischer } 163*65908a7eSAndre Fischer } 164*65908a7eSAndre Fischer 165*65908a7eSAndre Fischer 166*65908a7eSAndre Fischer 167*65908a7eSAndre Fischer 168*65908a7eSAndre Fischer void FocusManager::RegisterWindow (Window& rWindow) 169*65908a7eSAndre Fischer { 170*65908a7eSAndre Fischer rWindow.AddEventListener(LINK(this, FocusManager, WindowEventListener)); 171*65908a7eSAndre Fischer } 172*65908a7eSAndre Fischer 173*65908a7eSAndre Fischer 174*65908a7eSAndre Fischer 175*65908a7eSAndre Fischer 176*65908a7eSAndre Fischer void FocusManager::UnregisterWindow (Window& rWindow) 177*65908a7eSAndre Fischer { 178*65908a7eSAndre Fischer rWindow.RemoveEventListener(LINK(this, FocusManager, WindowEventListener)); 179*65908a7eSAndre Fischer } 180*65908a7eSAndre Fischer 181*65908a7eSAndre Fischer 182*65908a7eSAndre Fischer 183*65908a7eSAndre Fischer 184*65908a7eSAndre Fischer void FocusManager::RegisterTopLevelListener (void) 185*65908a7eSAndre Fischer { 186*65908a7eSAndre Fischer if (maPanels.empty()) 187*65908a7eSAndre Fischer return; 188*65908a7eSAndre Fischer Window* pWindow = maPanels.front(); 189*65908a7eSAndre Fischer while (pWindow != NULL && pWindow->GetParent()!=NULL) 190*65908a7eSAndre Fischer { 191*65908a7eSAndre Fischer pWindow = pWindow->GetParent(); 192*65908a7eSAndre Fischer } 193*65908a7eSAndre Fischer SetTopLevelWindow(pWindow); 194*65908a7eSAndre Fischer } 195*65908a7eSAndre Fischer 196*65908a7eSAndre Fischer 197*65908a7eSAndre Fischer 198*65908a7eSAndre Fischer 199*65908a7eSAndre Fischer void FocusManager::SetTopLevelWindow (Window* pWindow) 200*65908a7eSAndre Fischer { 201*65908a7eSAndre Fischer if (mpTopLevelWindow != pWindow) 202*65908a7eSAndre Fischer { 203*65908a7eSAndre Fischer if (mpTopLevelWindow != NULL) 204*65908a7eSAndre Fischer { 205*65908a7eSAndre Fischer UnregisterWindow(*mpTopLevelWindow); 206*65908a7eSAndre Fischer mpTopLevelWindow->RemoveChildEventListener(LINK(this, FocusManager, WindowEventListener)); 207*65908a7eSAndre Fischer } 208*65908a7eSAndre Fischer mpTopLevelWindow = pWindow; 209*65908a7eSAndre Fischer if (mpTopLevelWindow != NULL) 210*65908a7eSAndre Fischer { 211*65908a7eSAndre Fischer RegisterWindow(*mpTopLevelWindow); 212*65908a7eSAndre Fischer mpTopLevelWindow->AddChildEventListener(LINK(this, FocusManager, WindowEventListener)); 213*65908a7eSAndre Fischer } 214*65908a7eSAndre Fischer } 215*65908a7eSAndre Fischer } 216*65908a7eSAndre Fischer 217*65908a7eSAndre Fischer 218*65908a7eSAndre Fischer 219*65908a7eSAndre Fischer 220*65908a7eSAndre Fischer sal_Int32 FocusManager::GetPanelIndex (const Window& rWindow) const 221*65908a7eSAndre Fischer { 222*65908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maPanels.size()); nIndex<nCount; ++nIndex) 223*65908a7eSAndre Fischer { 224*65908a7eSAndre Fischer if (maPanels[nIndex] == &rWindow) 225*65908a7eSAndre Fischer return nIndex; 226*65908a7eSAndre Fischer TitleBar* pTitleBar = maPanels[nIndex]->GetTitleBar(); 227*65908a7eSAndre Fischer if (pTitleBar == &rWindow) 228*65908a7eSAndre Fischer return nIndex; 229*65908a7eSAndre Fischer if (pTitleBar!=NULL && &pTitleBar->GetToolBox()==&rWindow) 230*65908a7eSAndre Fischer return nIndex; 231*65908a7eSAndre Fischer } 232*65908a7eSAndre Fischer return -1; 233*65908a7eSAndre Fischer } 234*65908a7eSAndre Fischer 235*65908a7eSAndre Fischer 236*65908a7eSAndre Fischer 237*65908a7eSAndre Fischer 238*65908a7eSAndre Fischer sal_Int32 FocusManager::GetButtonIndex (const Window& rWindow) const 239*65908a7eSAndre Fischer { 240*65908a7eSAndre Fischer for (sal_Int32 nIndex=0,nCount(maButtons.size()); nIndex<nCount; ++nIndex) 241*65908a7eSAndre Fischer if (maButtons[nIndex] == &rWindow) 242*65908a7eSAndre Fischer return nIndex; 243*65908a7eSAndre Fischer return -1; 244*65908a7eSAndre Fischer } 245*65908a7eSAndre Fischer 246*65908a7eSAndre Fischer 247*65908a7eSAndre Fischer 248*65908a7eSAndre Fischer 249*65908a7eSAndre Fischer bool FocusManager::IsAnyPanelFocused (void) const 250*65908a7eSAndre Fischer { 251*65908a7eSAndre Fischer for (::std::vector<Panel*>::const_iterator iPanel(maPanels.begin()),iEnd(maPanels.end()); 252*65908a7eSAndre Fischer iPanel!=iEnd; 253*65908a7eSAndre Fischer ++iPanel) 254*65908a7eSAndre Fischer { 255*65908a7eSAndre Fischer if ((*iPanel)->HasFocus()) 256*65908a7eSAndre Fischer return true; 257*65908a7eSAndre Fischer else if ((*iPanel)->HasChildPathFocus()) 258*65908a7eSAndre Fischer return true; 259*65908a7eSAndre Fischer } 260*65908a7eSAndre Fischer return false; 261*65908a7eSAndre Fischer } 262*65908a7eSAndre Fischer 263*65908a7eSAndre Fischer 264*65908a7eSAndre Fischer 265*65908a7eSAndre Fischer 266*65908a7eSAndre Fischer bool FocusManager::IsAnyButtonFocused (void) const 267*65908a7eSAndre Fischer { 268*65908a7eSAndre Fischer for (::std::vector<Button*>::const_iterator iButton(maButtons.begin()),iEnd(maButtons.end()); 269*65908a7eSAndre Fischer iButton!=iEnd; 270*65908a7eSAndre Fischer ++iButton) 271*65908a7eSAndre Fischer { 272*65908a7eSAndre Fischer if ((*iButton)->HasFocus()) 273*65908a7eSAndre Fischer return true; 274*65908a7eSAndre Fischer } 275*65908a7eSAndre Fischer return false; 276*65908a7eSAndre Fischer } 277*65908a7eSAndre Fischer 278*65908a7eSAndre Fischer 279*65908a7eSAndre Fischer 280*65908a7eSAndre Fischer 281*65908a7eSAndre Fischer void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) 282*65908a7eSAndre Fischer { 283*65908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 284*65908a7eSAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 285*65908a7eSAndre Fischer if (pTitleBar!=NULL && pTitleBar->IsVisible()) 286*65908a7eSAndre Fischer { 287*65908a7eSAndre Fischer rPanel.SetExpanded(true); 288*65908a7eSAndre Fischer pTitleBar->GrabFocus(); 289*65908a7eSAndre Fischer } 290*65908a7eSAndre Fischer else 291*65908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 292*65908a7eSAndre Fischer } 293*65908a7eSAndre Fischer 294*65908a7eSAndre Fischer 295*65908a7eSAndre Fischer 296*65908a7eSAndre Fischer 297*65908a7eSAndre Fischer void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 298*65908a7eSAndre Fischer { 299*65908a7eSAndre Fischer Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 300*65908a7eSAndre Fischer if (pWindow != NULL) 301*65908a7eSAndre Fischer pWindow->GrabFocus(); 302*65908a7eSAndre Fischer } 303*65908a7eSAndre Fischer 304*65908a7eSAndre Fischer 305*65908a7eSAndre Fischer 306*65908a7eSAndre Fischer 307*65908a7eSAndre Fischer void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 308*65908a7eSAndre Fischer { 309*65908a7eSAndre Fischer maButtons[nButtonIndex]->GrabFocus(); 310*65908a7eSAndre Fischer maButtons[nButtonIndex]->Invalidate(); 311*65908a7eSAndre Fischer } 312*65908a7eSAndre Fischer 313*65908a7eSAndre Fischer 314*65908a7eSAndre Fischer 315*65908a7eSAndre Fischer 316*65908a7eSAndre Fischer void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 317*65908a7eSAndre Fischer { 318*65908a7eSAndre Fischer maButtons[nButtonIndex]->Click(); 319*65908a7eSAndre Fischer if (nButtonIndex > 0) 320*65908a7eSAndre Fischer if ( ! maPanels.empty()) 321*65908a7eSAndre Fischer FocusPanel(0); 322*65908a7eSAndre Fischer maButtons[nButtonIndex]->GetParent()->Invalidate(); 323*65908a7eSAndre Fischer } 324*65908a7eSAndre Fischer 325*65908a7eSAndre Fischer 326*65908a7eSAndre Fischer 327*65908a7eSAndre Fischer 328*65908a7eSAndre Fischer void FocusManager::RemoveWindow (Window& rWindow) 329*65908a7eSAndre Fischer { 330*65908a7eSAndre Fischer ::std::vector<Panel*>::iterator iPanel (::std::find(maPanels.begin(), maPanels.end(), &rWindow)); 331*65908a7eSAndre Fischer if (iPanel != maPanels.end()) 332*65908a7eSAndre Fischer { 333*65908a7eSAndre Fischer UnregisterWindow(rWindow); 334*65908a7eSAndre Fischer if ((*iPanel)->GetTitleBar() != NULL) 335*65908a7eSAndre Fischer { 336*65908a7eSAndre Fischer UnregisterWindow(*(*iPanel)->GetTitleBar()); 337*65908a7eSAndre Fischer UnregisterWindow((*iPanel)->GetTitleBar()->GetToolBox()); 338*65908a7eSAndre Fischer } 339*65908a7eSAndre Fischer maPanels.erase(iPanel); 340*65908a7eSAndre Fischer return; 341*65908a7eSAndre Fischer } 342*65908a7eSAndre Fischer 343*65908a7eSAndre Fischer ::std::vector<Button*>::iterator iButton (::std::find(maButtons.begin(), maButtons.end(), &rWindow)); 344*65908a7eSAndre Fischer if (iButton != maButtons.end()) 345*65908a7eSAndre Fischer { 346*65908a7eSAndre Fischer UnregisterWindow(rWindow); 347*65908a7eSAndre Fischer maButtons.erase(iButton); 348*65908a7eSAndre Fischer return; 349*65908a7eSAndre Fischer } 350*65908a7eSAndre Fischer } 351*65908a7eSAndre Fischer 352*65908a7eSAndre Fischer 353*65908a7eSAndre Fischer 354*65908a7eSAndre Fischer 355*65908a7eSAndre Fischer bool FocusManager::MoveFocusInsidePanel ( 356*65908a7eSAndre Fischer const sal_Int32 nPanelIndex, 357*65908a7eSAndre Fischer const sal_Int32 nDirection) 358*65908a7eSAndre Fischer { 359*65908a7eSAndre Fischer Panel& rPanel (*maPanels[nPanelIndex]); 360*65908a7eSAndre Fischer switch (GetFocusedComponent(rPanel)) 361*65908a7eSAndre Fischer { 362*65908a7eSAndre Fischer case PC_TitleBar: 363*65908a7eSAndre Fischer if (nDirection > 0) 364*65908a7eSAndre Fischer rPanel.GetTitleBar()->GetToolBox().GrabFocus(); 365*65908a7eSAndre Fischer else 366*65908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 367*65908a7eSAndre Fischer return true; 368*65908a7eSAndre Fischer 369*65908a7eSAndre Fischer case PC_ToolBox: 370*65908a7eSAndre Fischer if (nDirection > 0) 371*65908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 372*65908a7eSAndre Fischer else 373*65908a7eSAndre Fischer rPanel.GetTitleBar()->GrabFocus(); 374*65908a7eSAndre Fischer return true; 375*65908a7eSAndre Fischer 376*65908a7eSAndre Fischer default: 377*65908a7eSAndre Fischer return false; 378*65908a7eSAndre Fischer } 379*65908a7eSAndre Fischer } 380*65908a7eSAndre Fischer 381*65908a7eSAndre Fischer 382*65908a7eSAndre Fischer 383*65908a7eSAndre Fischer 384*65908a7eSAndre Fischer long FocusManager::NotifyDockingWindowEvent (const KeyEvent& rKeyEvent) 385*65908a7eSAndre Fischer { 386*65908a7eSAndre Fischer switch(rKeyEvent.GetKeyCode().GetCode()) 387*65908a7eSAndre Fischer { 388*65908a7eSAndre Fischer case KEY_F6: 389*65908a7eSAndre Fischer if (rKeyEvent.GetKeyCode().IsShift()) 390*65908a7eSAndre Fischer { 391*65908a7eSAndre Fischer if (IsAnyButtonFocused()) 392*65908a7eSAndre Fischer { 393*65908a7eSAndre Fischer FocusPanel(0); 394*65908a7eSAndre Fischer return 1; 395*65908a7eSAndre Fischer } 396*65908a7eSAndre Fischer } 397*65908a7eSAndre Fischer else 398*65908a7eSAndre Fischer { 399*65908a7eSAndre Fischer if (IsAnyPanelFocused()) 400*65908a7eSAndre Fischer { 401*65908a7eSAndre Fischer FocusButton(0); 402*65908a7eSAndre Fischer return 1; 403*65908a7eSAndre Fischer } 404*65908a7eSAndre Fischer } 405*65908a7eSAndre Fischer break; 406*65908a7eSAndre Fischer } 407*65908a7eSAndre Fischer return 0; 408*65908a7eSAndre Fischer } 409*65908a7eSAndre Fischer 410*65908a7eSAndre Fischer 411*65908a7eSAndre Fischer 412*65908a7eSAndre Fischer 413*65908a7eSAndre Fischer void FocusManager::HandleKeyEvent ( 414*65908a7eSAndre Fischer const KeyCode& rKeyCode, 415*65908a7eSAndre Fischer const Window& rWindow) 416*65908a7eSAndre Fischer { 417*65908a7eSAndre Fischer if (rKeyCode.GetModifier() != 0) 418*65908a7eSAndre Fischer return; 419*65908a7eSAndre Fischer 420*65908a7eSAndre Fischer const sal_Int32 nPanelIndex (GetPanelIndex(rWindow)); 421*65908a7eSAndre Fischer const bool bIsPanelTitleFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow); 422*65908a7eSAndre Fischer const bool bIsPanelToolBoxFocused (nPanelIndex>=0 && maPanels[nPanelIndex] != &rWindow); 423*65908a7eSAndre Fischer sal_Int32 nButtonIndex (nPanelIndex==-1 ? GetButtonIndex(rWindow) : -1); 424*65908a7eSAndre Fischer 425*65908a7eSAndre Fischer switch (rKeyCode.GetCode()) 426*65908a7eSAndre Fischer { 427*65908a7eSAndre Fischer case KEY_F6: 428*65908a7eSAndre Fischer if (nPanelIndex >= 0) 429*65908a7eSAndre Fischer FocusButton(0); 430*65908a7eSAndre Fischer else 431*65908a7eSAndre Fischer return; 432*65908a7eSAndre Fischer break; 433*65908a7eSAndre Fischer 434*65908a7eSAndre Fischer case KEY_SPACE: 435*65908a7eSAndre Fischer if (nPanelIndex >= 0) 436*65908a7eSAndre Fischer { 437*65908a7eSAndre Fischer if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar) 438*65908a7eSAndre Fischer { 439*65908a7eSAndre Fischer // Toggle the expansion state. 440*65908a7eSAndre Fischer maPanels[nPanelIndex]->SetExpanded( ! maPanels[nPanelIndex]->IsExpanded()); 441*65908a7eSAndre Fischer } 442*65908a7eSAndre Fischer } 443*65908a7eSAndre Fischer else if (nButtonIndex >= 0) 444*65908a7eSAndre Fischer { 445*65908a7eSAndre Fischer // Activate the button. 446*65908a7eSAndre Fischer ClickButton(nButtonIndex); 447*65908a7eSAndre Fischer } 448*65908a7eSAndre Fischer return; 449*65908a7eSAndre Fischer 450*65908a7eSAndre Fischer case KEY_RETURN: 451*65908a7eSAndre Fischer if (nPanelIndex >= 0) 452*65908a7eSAndre Fischer { 453*65908a7eSAndre Fischer if (GetFocusedComponent(*maPanels[nPanelIndex]) == PC_TitleBar) 454*65908a7eSAndre Fischer { 455*65908a7eSAndre Fischer // Enter the panel. 456*65908a7eSAndre Fischer FocusPanelContent(nPanelIndex); 457*65908a7eSAndre Fischer } 458*65908a7eSAndre Fischer } 459*65908a7eSAndre Fischer else if (nButtonIndex >= 0) 460*65908a7eSAndre Fischer { 461*65908a7eSAndre Fischer // Activate the button. 462*65908a7eSAndre Fischer ClickButton(nButtonIndex); 463*65908a7eSAndre Fischer } 464*65908a7eSAndre Fischer return; 465*65908a7eSAndre Fischer 466*65908a7eSAndre Fischer case KEY_TAB: 467*65908a7eSAndre Fischer if (nPanelIndex >= 0) 468*65908a7eSAndre Fischer { 469*65908a7eSAndre Fischer if (rKeyCode.IsShift()) 470*65908a7eSAndre Fischer MoveFocusInsidePanel(nPanelIndex, -1); 471*65908a7eSAndre Fischer else 472*65908a7eSAndre Fischer MoveFocusInsidePanel(nPanelIndex, +1); 473*65908a7eSAndre Fischer } 474*65908a7eSAndre Fischer break; 475*65908a7eSAndre Fischer 476*65908a7eSAndre Fischer case KEY_LEFT: 477*65908a7eSAndre Fischer case KEY_UP: 478*65908a7eSAndre Fischer // Go to previous element in focus ring. 479*65908a7eSAndre Fischer if (nPanelIndex >= 0) 480*65908a7eSAndre Fischer { 481*65908a7eSAndre Fischer FocusPanel((nPanelIndex + maPanels.size() - 1) % maPanels.size()); 482*65908a7eSAndre Fischer } 483*65908a7eSAndre Fischer else if (nButtonIndex >= 0) 484*65908a7eSAndre Fischer { 485*65908a7eSAndre Fischer FocusButton((nButtonIndex + maButtons.size() - 1) % maButtons.size()); 486*65908a7eSAndre Fischer } 487*65908a7eSAndre Fischer break; 488*65908a7eSAndre Fischer 489*65908a7eSAndre Fischer case KEY_RIGHT: 490*65908a7eSAndre Fischer case KEY_DOWN: 491*65908a7eSAndre Fischer // Go to next element in focus ring. 492*65908a7eSAndre Fischer if (nPanelIndex >= 0) 493*65908a7eSAndre Fischer { 494*65908a7eSAndre Fischer FocusPanel((nPanelIndex + 1) % maPanels.size()); 495*65908a7eSAndre Fischer } 496*65908a7eSAndre Fischer else if (nButtonIndex >= 0) 497*65908a7eSAndre Fischer { 498*65908a7eSAndre Fischer FocusButton((nButtonIndex + 1) % maButtons.size()); 499*65908a7eSAndre Fischer } 500*65908a7eSAndre Fischer break; 501*65908a7eSAndre Fischer } 502*65908a7eSAndre Fischer } 503*65908a7eSAndre Fischer 504*65908a7eSAndre Fischer 505*65908a7eSAndre Fischer 506*65908a7eSAndre Fischer 507*65908a7eSAndre Fischer void FocusManager::HandleTopLevelEvent (VclWindowEvent& rEvent) 508*65908a7eSAndre Fischer { 509*65908a7eSAndre Fischer switch (rEvent.GetId()) 510*65908a7eSAndre Fischer { 511*65908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 512*65908a7eSAndre Fischer { 513*65908a7eSAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(rEvent.GetData()); 514*65908a7eSAndre Fischer switch (pKeyEvent->GetKeyCode().GetCode()) 515*65908a7eSAndre Fischer { 516*65908a7eSAndre Fischer case KEY_F6: 517*65908a7eSAndre Fischer OSL_TRACE(""); 518*65908a7eSAndre Fischer break; 519*65908a7eSAndre Fischer } 520*65908a7eSAndre Fischer } 521*65908a7eSAndre Fischer } 522*65908a7eSAndre Fischer } 523*65908a7eSAndre Fischer 524*65908a7eSAndre Fischer 525*65908a7eSAndre Fischer 526*65908a7eSAndre Fischer 527*65908a7eSAndre Fischer IMPL_LINK(FocusManager, WindowEventListener, VclSimpleEvent*, pEvent) 528*65908a7eSAndre Fischer { 529*65908a7eSAndre Fischer if (pEvent == NULL) 530*65908a7eSAndre Fischer return 0; 531*65908a7eSAndre Fischer 532*65908a7eSAndre Fischer if ( ! pEvent->ISA(VclWindowEvent)) 533*65908a7eSAndre Fischer return 0; 534*65908a7eSAndre Fischer 535*65908a7eSAndre Fischer VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent); 536*65908a7eSAndre Fischer Window* pSource = pWindowEvent->GetWindow(); 537*65908a7eSAndre Fischer if (pSource == NULL) 538*65908a7eSAndre Fischer return 0; 539*65908a7eSAndre Fischer 540*65908a7eSAndre Fischer if (pSource == mpTopLevelWindow) 541*65908a7eSAndre Fischer HandleTopLevelEvent(*pWindowEvent); 542*65908a7eSAndre Fischer else 543*65908a7eSAndre Fischer switch (pWindowEvent->GetId()) 544*65908a7eSAndre Fischer { 545*65908a7eSAndre Fischer case VCLEVENT_WINDOW_KEYINPUT: 546*65908a7eSAndre Fischer { 547*65908a7eSAndre Fischer KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 548*65908a7eSAndre Fischer HandleKeyEvent(pKeyEvent->GetKeyCode(), *pSource); 549*65908a7eSAndre Fischer return 1; 550*65908a7eSAndre Fischer } 551*65908a7eSAndre Fischer 552*65908a7eSAndre Fischer case VCLEVENT_OBJECT_DYING: 553*65908a7eSAndre Fischer RemoveWindow(*pSource); 554*65908a7eSAndre Fischer return 1; 555*65908a7eSAndre Fischer 556*65908a7eSAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 557*65908a7eSAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 558*65908a7eSAndre Fischer pSource->Invalidate(); 559*65908a7eSAndre Fischer } 560*65908a7eSAndre Fischer return 0; 561*65908a7eSAndre Fischer } 562*65908a7eSAndre Fischer 563*65908a7eSAndre Fischer 564*65908a7eSAndre Fischer 565*65908a7eSAndre Fischer } } // end of namespace sfx2::sidebar 566