FocusManager.cxx (8a1a651a) | FocusManager.cxx (441705db) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 33 unchanged lines hidden (view full) --- 42 43 44 45 46FocusManager::FocusManager (const ::boost::function<void(const Panel&)>& rShowPanelFunctor) 47 : mpDeckTitleBar(), 48 maPanels(), 49 maButtons(), | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 33 unchanged lines hidden (view full) --- 42 43 44 45 46FocusManager::FocusManager (const ::boost::function<void(const Panel&)>& rShowPanelFunctor) 47 : mpDeckTitleBar(), 48 maPanels(), 49 maButtons(), |
50 maShowPanelFunctor(rShowPanelFunctor) | 50 maShowPanelFunctor(rShowPanelFunctor), 51 mbObservingContentControlFocus(false), 52 mpFirstFocusedContentControl(NULL) |
51{ 52} 53 54 55 56 57FocusManager::~FocusManager (void) 58{ --- 195 unchanged lines hidden (view full) --- 254 return false; 255} 256 257 258 259 260void FocusManager::FocusDeckTitle (void) 261{ | 53{ 54} 55 56 57 58 59FocusManager::~FocusManager (void) 60{ --- 195 unchanged lines hidden (view full) --- 256 return false; 257} 258 259 260 261 262void FocusManager::FocusDeckTitle (void) 263{ |
262 if (IsDeckTitleVisible()) | 264 if (mpDeckTitleBar != NULL) |
263 { | 265 { |
264 ToolBox& rToolBox = mpDeckTitleBar->GetToolBox(); 265 if (rToolBox.GetItemCount() > 0) | 266 if (IsDeckTitleVisible()) |
266 { | 267 { |
268 mpDeckTitleBar->GrabFocus(); 269 } 270 else if (mpDeckTitleBar->GetToolBox().GetItemCount() > 0) 271 { 272 ToolBox& rToolBox = mpDeckTitleBar->GetToolBox(); |
|
267 rToolBox.GrabFocus(); 268 rToolBox.Invalidate(); 269 } | 273 rToolBox.GrabFocus(); 274 rToolBox.Invalidate(); 275 } |
276 else 277 FocusPanel(0, false); |
|
270 } 271 else | 278 } 279 else |
272 FocusPanel(0); | 280 FocusPanel(0, false); |
273} 274 275 276 277 278bool FocusManager::IsDeckTitleVisible (void) const 279{ 280 return mpDeckTitleBar != NULL && mpDeckTitleBar->IsVisible(); 281} 282 283 284 285 | 281} 282 283 284 285 286bool FocusManager::IsDeckTitleVisible (void) const 287{ 288 return mpDeckTitleBar != NULL && mpDeckTitleBar->IsVisible(); 289} 290 291 292 293 |
286void FocusManager::FocusPanel (const sal_Int32 nPanelIndex) | 294bool FocusManager::IsPanelTitleVisible (const sal_Int32 nPanelIndex) const |
287{ 288 if (nPanelIndex<0 || nPanelIndex>=static_cast<sal_Int32>(maPanels.size())) | 295{ 296 if (nPanelIndex<0 || nPanelIndex>=static_cast<sal_Int32>(maPanels.size())) |
297 return false; 298 299 TitleBar* pTitleBar = maPanels[nPanelIndex]->GetTitleBar(); 300 if (pTitleBar==NULL) 301 return false; 302 return pTitleBar->IsVisible(); 303} 304 305 306 307 308void FocusManager::FocusPanel ( 309 const sal_Int32 nPanelIndex, 310 const bool bFallbackToDeckTitle) 311{ 312 if (nPanelIndex<0 || nPanelIndex>=static_cast<sal_Int32>(maPanels.size())) 313 { 314 if (bFallbackToDeckTitle) 315 FocusDeckTitle(); |
|
289 return; | 316 return; |
317 } 318 |
|
290 Panel& rPanel (*maPanels[nPanelIndex]); 291 TitleBar* pTitleBar = rPanel.GetTitleBar(); 292 if (pTitleBar!=NULL && pTitleBar->IsVisible()) 293 { 294 rPanel.SetExpanded(true); 295 pTitleBar->GrabFocus(); 296 } | 319 Panel& rPanel (*maPanels[nPanelIndex]); 320 TitleBar* pTitleBar = rPanel.GetTitleBar(); 321 if (pTitleBar!=NULL && pTitleBar->IsVisible()) 322 { 323 rPanel.SetExpanded(true); 324 pTitleBar->GrabFocus(); 325 } |
326 else if (bFallbackToDeckTitle) 327 { 328 // The panel title is not visible, fall back to the deck 329 // title. 330 // Make sure that the desk title is visible here to prevent a 331 // loop when both the title of panel 0 and the deck title are 332 // not present. 333 if (IsDeckTitleVisible()) 334 FocusDeckTitle(); 335 else 336 FocusPanelContent(nPanelIndex); 337 } |
|
297 else 298 FocusPanelContent(nPanelIndex); | 338 else 339 FocusPanelContent(nPanelIndex); |
340 |
|
299 if (maShowPanelFunctor) 300 maShowPanelFunctor(rPanel); 301} 302 303 304 305 306void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 307{ 308 Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 309 if (pWindow != NULL) | 341 if (maShowPanelFunctor) 342 maShowPanelFunctor(rPanel); 343} 344 345 346 347 348void FocusManager::FocusPanelContent (const sal_Int32 nPanelIndex) 349{ 350 Window* pWindow = VCLUnoHelper::GetWindow(maPanels[nPanelIndex]->GetElementWindow()); 351 if (pWindow != NULL) |
352 { 353 mbObservingContentControlFocus = true; |
|
310 pWindow->GrabFocus(); | 354 pWindow->GrabFocus(); |
355 mbObservingContentControlFocus = false; 356 } |
|
311} 312 313 314 315 316void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 317{ 318 maButtons[nButtonIndex]->GrabFocus(); 319 maButtons[nButtonIndex]->Invalidate(); 320} 321 322 323 324 325void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 326{ 327 maButtons[nButtonIndex]->Click(); 328 if (nButtonIndex > 0) 329 if ( ! maPanels.empty()) | 357} 358 359 360 361 362void FocusManager::FocusButton (const sal_Int32 nButtonIndex) 363{ 364 maButtons[nButtonIndex]->GrabFocus(); 365 maButtons[nButtonIndex]->Invalidate(); 366} 367 368 369 370 371void FocusManager::ClickButton (const sal_Int32 nButtonIndex) 372{ 373 maButtons[nButtonIndex]->Click(); 374 if (nButtonIndex > 0) 375 if ( ! maPanels.empty()) |
330 FocusPanel(0); | 376 FocusPanel(0, true); |
331 maButtons[nButtonIndex]->GetParent()->Invalidate(); 332} 333 334 335 336 337void FocusManager::RemoveWindow (Window& rWindow) 338{ --- 47 unchanged lines hidden (view full) --- 386 default: 387 return false; 388 } 389} 390 391 392 393 | 377 maButtons[nButtonIndex]->GetParent()->Invalidate(); 378} 379 380 381 382 383void FocusManager::RemoveWindow (Window& rWindow) 384{ --- 47 unchanged lines hidden (view full) --- 432 default: 433 return false; 434 } 435} 436 437 438 439 |
440bool FocusManager::MoveFocusInsideDeckTitle ( 441 const FocusLocation aFocusLocation, 442 const sal_Int32 nDirection) 443{ 444 // Note that when the title bar of the first (and only) panel is 445 // not visible then the deck title takes its place and the focus 446 // is moved between a) deck title, b) deck closer and c) content 447 // of panel 0. 448 const bool bHasToolBoxItem ( 449 mpDeckTitleBar->GetToolBox().GetItemCount() > 0); 450 switch (aFocusLocation.meComponent) 451 { 452 case PC_DeckTitle: 453 if (nDirection<0 && ! IsPanelTitleVisible(0)) 454 FocusPanelContent(0); 455 else if (bHasToolBoxItem) 456 mpDeckTitleBar->GetToolBox().GrabFocus(); 457 return true; 458 459 case PC_DeckToolBox: 460 if (nDirection>0 && ! IsPanelTitleVisible(0)) 461 FocusPanelContent(0); 462 else 463 mpDeckTitleBar->GrabFocus(); 464 return true; 465 466 default: 467 return false; 468 } 469} 470 471 472 473 |
|
394void FocusManager::HandleKeyEvent ( 395 const KeyCode& rKeyCode, 396 const Window& rWindow) 397{ 398 const FocusLocation aLocation (GetFocusLocation(rWindow)); | 474void FocusManager::HandleKeyEvent ( 475 const KeyCode& rKeyCode, 476 const Window& rWindow) 477{ 478 const FocusLocation aLocation (GetFocusLocation(rWindow)); |
399 | 479 mpLastFocusedWindow = NULL; 480 |
400 switch (rKeyCode.GetCode()) 401 { 402 case KEY_SPACE: 403 switch (aLocation.meComponent) 404 { 405 case PC_PanelTitle: 406 // Toggle panel between expanded and collapsed. 407 maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded()); --- 27 unchanged lines hidden (view full) --- 435 break; 436 437 default: 438 break; 439 } 440 return; 441 442 case KEY_TAB: | 481 switch (rKeyCode.GetCode()) 482 { 483 case KEY_SPACE: 484 switch (aLocation.meComponent) 485 { 486 case PC_PanelTitle: 487 // Toggle panel between expanded and collapsed. 488 maPanels[aLocation.mnIndex]->SetExpanded( ! maPanels[aLocation.mnIndex]->IsExpanded()); --- 27 unchanged lines hidden (view full) --- 516 break; 517 518 default: 519 break; 520 } 521 return; 522 523 case KEY_TAB: |
524 { 525 const sal_Int32 nDirection ( 526 rKeyCode.IsShift() 527 ? -1 528 : +1); |
|
443 switch (aLocation.meComponent) 444 { 445 case PC_PanelTitle: 446 case PC_PanelToolBox: 447 case PC_PanelContent: | 529 switch (aLocation.meComponent) 530 { 531 case PC_PanelTitle: 532 case PC_PanelToolBox: 533 case PC_PanelContent: |
448 if (rKeyCode.IsShift()) 449 MoveFocusInsidePanel(aLocation, -1); 450 else 451 MoveFocusInsidePanel(aLocation, +1); | 534 MoveFocusInsidePanel(aLocation, nDirection); |
452 break; 453 | 535 break; 536 |
537 case PC_DeckTitle: 538 case PC_DeckToolBox: 539 MoveFocusInsideDeckTitle(aLocation, nDirection); 540 break; 541 |
|
454 default: 455 break; 456 } 457 break; | 542 default: 543 break; 544 } 545 break; |
458 | 546 } 547 |
459 case KEY_LEFT: 460 case KEY_UP: 461 switch (aLocation.meComponent) 462 { 463 case PC_PanelTitle: 464 case PC_PanelToolBox: 465 case PC_PanelContent: 466 // Go to previous panel or the deck title. 467 if (aLocation.mnIndex > 0) | 548 case KEY_LEFT: 549 case KEY_UP: 550 switch (aLocation.meComponent) 551 { 552 case PC_PanelTitle: 553 case PC_PanelToolBox: 554 case PC_PanelContent: 555 // Go to previous panel or the deck title. 556 if (aLocation.mnIndex > 0) |
468 FocusPanel(aLocation.mnIndex-1); | 557 FocusPanel(aLocation.mnIndex-1, true); |
469 else if (IsDeckTitleVisible()) 470 FocusDeckTitle(); 471 else 472 FocusButton(maButtons.size()-1); 473 break; 474 475 case PC_DeckTitle: 476 case PC_DeckToolBox: 477 // Focus the last button. 478 FocusButton(maButtons.size()-1); 479 break; 480 481 case PC_TabBar: 482 // Go to previous tab bar item. 483 if (aLocation.mnIndex == 0) | 558 else if (IsDeckTitleVisible()) 559 FocusDeckTitle(); 560 else 561 FocusButton(maButtons.size()-1); 562 break; 563 564 case PC_DeckTitle: 565 case PC_DeckToolBox: 566 // Focus the last button. 567 FocusButton(maButtons.size()-1); 568 break; 569 570 case PC_TabBar: 571 // Go to previous tab bar item. 572 if (aLocation.mnIndex == 0) |
484 FocusPanel(maPanels.size()-1); | 573 FocusPanel(maPanels.size()-1, true); |
485 else 486 FocusButton((aLocation.mnIndex + maButtons.size() - 1) % maButtons.size()); 487 break; 488 489 default: 490 break; 491 } 492 break; 493 494 case KEY_RIGHT: 495 case KEY_DOWN: 496 switch(aLocation.meComponent) 497 { 498 case PC_PanelTitle: 499 case PC_PanelToolBox: 500 case PC_PanelContent: 501 // Go to next panel. 502 if (aLocation.mnIndex < static_cast<sal_Int32>(maPanels.size())-1) | 574 else 575 FocusButton((aLocation.mnIndex + maButtons.size() - 1) % maButtons.size()); 576 break; 577 578 default: 579 break; 580 } 581 break; 582 583 case KEY_RIGHT: 584 case KEY_DOWN: 585 switch(aLocation.meComponent) 586 { 587 case PC_PanelTitle: 588 case PC_PanelToolBox: 589 case PC_PanelContent: 590 // Go to next panel. 591 if (aLocation.mnIndex < static_cast<sal_Int32>(maPanels.size())-1) |
503 FocusPanel(aLocation.mnIndex+1); | 592 FocusPanel(aLocation.mnIndex+1, false); |
504 else 505 FocusButton(0); 506 break; 507 508 case PC_DeckTitle: 509 case PC_DeckToolBox: 510 // Focus the first panel. | 593 else 594 FocusButton(0); 595 break; 596 597 case PC_DeckTitle: 598 case PC_DeckToolBox: 599 // Focus the first panel. |
511 FocusPanel(0); | 600 if (IsPanelTitleVisible(0)) 601 FocusPanel(0, false); 602 else 603 FocusButton(0); |
512 break; 513 514 case PC_TabBar: 515 // Go to next tab bar item. 516 if (aLocation.mnIndex < static_cast<sal_Int32>(maButtons.size())-1) 517 FocusButton(aLocation.mnIndex + 1); 518 else if (IsDeckTitleVisible()) 519 FocusDeckTitle(); 520 else | 604 break; 605 606 case PC_TabBar: 607 // Go to next tab bar item. 608 if (aLocation.mnIndex < static_cast<sal_Int32>(maButtons.size())-1) 609 FocusButton(aLocation.mnIndex + 1); 610 else if (IsDeckTitleVisible()) 611 FocusDeckTitle(); 612 else |
521 FocusPanel(0); | 613 FocusPanel(0, true); |
522 break; 523 524 default: 525 break; 526 } 527 break; 528 } 529} --- 56 unchanged lines hidden (view full) --- 586 return 0; 587 588 switch (pWindowEvent->GetId()) 589 { 590 case VCLEVENT_WINDOW_KEYINPUT: 591 { 592 KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 593 | 614 break; 615 616 default: 617 break; 618 } 619 break; 620 } 621} --- 56 unchanged lines hidden (view full) --- 678 return 0; 679 680 switch (pWindowEvent->GetId()) 681 { 682 case VCLEVENT_WINDOW_KEYINPUT: 683 { 684 KeyEvent* pKeyEvent = static_cast<KeyEvent*>(pWindowEvent->GetData()); 685 |
594 // Go up the window hierarchy to find the parent of the 595 // event source which is known to us. | 686 // Go up the window hierarchy to find out whether the 687 // parent of the event source is known to us. |
596 Window* pWindow = pSource; 597 FocusLocation aLocation (PC_None, -1); 598 while (true) 599 { 600 if (pWindow == NULL) 601 break; 602 aLocation = GetFocusLocation(*pWindow); 603 if (aLocation.meComponent != PC_None) 604 break; 605 pWindow = pWindow->GetParent(); 606 } 607 608 if (aLocation.meComponent != PC_None) 609 { 610 switch (pKeyEvent->GetKeyCode().GetCode()) 611 { 612 case KEY_ESCAPE: 613 // Return focus back to the panel title. | 688 Window* pWindow = pSource; 689 FocusLocation aLocation (PC_None, -1); 690 while (true) 691 { 692 if (pWindow == NULL) 693 break; 694 aLocation = GetFocusLocation(*pWindow); 695 if (aLocation.meComponent != PC_None) 696 break; 697 pWindow = pWindow->GetParent(); 698 } 699 700 if (aLocation.meComponent != PC_None) 701 { 702 switch (pKeyEvent->GetKeyCode().GetCode()) 703 { 704 case KEY_ESCAPE: 705 // Return focus back to the panel title. |
614 FocusPanel(aLocation.mnIndex); | 706 FocusPanel(aLocation.mnIndex, true); |
615 break; 616 | 707 break; 708 |
709 case KEY_TAB: 710 if (mpFirstFocusedContentControl!=NULL 711 && mpLastFocusedWindow == mpFirstFocusedContentControl) 712 { 713 // Move focus back to panel (or deck) 714 // title. 715 FocusPanel(aLocation.mnIndex, true); 716 } 717 break; 718 |
|
617 default: 618 break; 619 } 620 } 621 return 1; 622 } 623 | 719 default: 720 break; 721 } 722 } 723 return 1; 724 } 725 |
726 case VCLEVENT_WINDOW_GETFOCUS: 727 // Keep track of focused controls in panel content. 728 // Remember the first focused control. When it is later 729 // focused again due to pressing the TAB key then the 730 // focus is moved to the panel or deck title. 731 mpLastFocusedWindow = pSource; 732 if (mbObservingContentControlFocus) 733 mpFirstFocusedContentControl = pSource; 734 break; 735 |
|
624 default: 625 break; 626 } 627 628 return 0; 629} 630 631 632} } // end of namespace sfx2::sidebar | 736 default: 737 break; 738 } 739 740 return 0; 741} 742 743 744} } // end of namespace sfx2::sidebar |