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 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #ifndef SFX_SIDEBAR_FOCUS_MANAGER_HXX 23 #define SFX_SIDEBAR_FOCUS_MANAGER_HXX 24 25 #include "Panel.hxx" 26 #include <tools/link.hxx> 27 28 class Button; 29 class KeyCode; 30 class VclSimpleEvent; 31 32 33 namespace sfx2 { namespace sidebar { 34 35 class DeckTitleBar; 36 37 /** Concentrate all focus handling in this class. 38 39 There is one ring of windows that accept the input focus which are 40 cycled through with the arrow keys: 41 - the closer in the deck title (present only when docked) 42 - the panel title bars 43 - the tab bar items 44 45 When the focus is in a panel title then focus travels over 46 - the panel title 47 - the panel closer 48 - the panel content 49 50 Once the focus is in the panel content then focus cycles through 51 all controls inside the panel but not back to the title bar of 52 the panel. Escape places the focus back in the panel title. 53 */ 54 class FocusManager 55 { 56 public: 57 FocusManager (const ::boost::function<void(const Panel&)>& rShowPanelFunctor); 58 ~FocusManager (void); 59 60 /** Forget all panels and buttons. Remove all window listeners. 61 */ 62 void Clear (void); 63 64 /** Transfer the focus into the sidebar tree of windows. This is 65 typically called from the SidebarChildWindow as result of 66 pressing the F6 key. 67 */ 68 void GrabFocus (void); 69 70 void SetDeckTitle (DeckTitleBar* pDeckTitleBar); 71 void SetPanels (const SharedPanelContainer& rPanels); 72 void SetButtons (const ::std::vector<Button*>& rButtons); 73 74 private: 75 DeckTitleBar* mpDeckTitleBar; 76 ::std::vector<Panel*> maPanels; 77 ::std::vector<Button*> maButtons; 78 const ::boost::function<void(const Panel&)> maShowPanelFunctor; 79 bool mbObservingContentControlFocus; 80 Window* mpFirstFocusedContentControl; 81 Window* mpLastFocusedWindow; 82 83 enum PanelComponent 84 { 85 PC_DeckTitle, 86 PC_DeckToolBox, 87 PC_PanelTitle, 88 PC_PanelToolBox, 89 PC_PanelContent, 90 PC_TabBar, 91 PC_None 92 }; 93 class FocusLocation 94 { 95 public: 96 PanelComponent meComponent; 97 sal_Int32 mnIndex; 98 FocusLocation (const PanelComponent eComponent, const sal_Int32 nIndex); 99 }; 100 101 /** Listen for key events for panels and buttons. 102 */ 103 DECL_LINK(WindowEventListener, VclSimpleEvent*); 104 DECL_LINK(ChildEventListener, VclSimpleEvent*); 105 106 void ClearPanels (void); 107 void ClearButtons (void); 108 109 /** Let the focus manager listen for window events for the given 110 window. 111 */ 112 void RegisterWindow (Window& rWindow); 113 void UnregisterWindow (Window& rWindow); 114 115 /** Remove the window from the panel or the button container. 116 */ 117 void RemoveWindow (Window& rWindow); 118 119 bool IsAnyPanelFocused (void) const; 120 bool IsAnyButtonFocused (void) const; 121 122 void FocusDeckTitle (void); 123 bool IsDeckTitleVisible (void) const; 124 bool IsPanelTitleVisible (const sal_Int32 nPanelIndex) const; 125 126 /** Set the focus to the title bar of the panel or, if the the 127 title bar is not visible, directly to the panel. 128 @param nPanelIndex 129 Index of the panel to focus. 130 @param bFallbackToDeckTitle 131 When the panel title bar is not visible then The fallback 132 bias defines whether to focus the deck (true) or the panel 133 content (false) will be focused instead. 134 */ 135 void FocusPanel ( 136 const sal_Int32 nPanelIndex, 137 const bool bFallbackToDeckTitle); 138 139 void FocusPanelContent (const sal_Int32 nPanelIndex); 140 void FocusButton (const sal_Int32 nButtonIndex); 141 void ClickButton (const sal_Int32 nButtonIndex); 142 bool MoveFocusInsidePanel ( 143 const FocusLocation aLocation, 144 const sal_Int32 nDirection); 145 bool MoveFocusInsideDeckTitle ( 146 const FocusLocation aLocation, 147 const sal_Int32 nDirection); 148 149 void HandleKeyEvent ( 150 const KeyCode& rKeyCode, 151 const Window& rWindow); 152 153 FocusLocation GetFocusLocation (const Window& rWindow) const; 154 155 }; 156 157 } } // end of namespace sfx2::sidebar 158 159 #endif 160