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 
80     enum PanelComponent
81     {
82         PC_DeckTitle,
83         PC_DeckToolBox,
84         PC_PanelTitle,
85         PC_PanelToolBox,
86         PC_PanelContent,
87         PC_TabBar,
88         PC_None
89     };
90     class FocusLocation
91     {
92     public:
93         PanelComponent meComponent;
94         sal_Int32 mnIndex;
95         FocusLocation (const PanelComponent eComponent, const sal_Int32 nIndex);
96     };
97 
98     /** Listen for key events for panels and buttons.
99     */
100     DECL_LINK(WindowEventListener, VclSimpleEvent*);
101     DECL_LINK(ChildEventListener, VclSimpleEvent*);
102 
103     void ClearPanels (void);
104     void ClearButtons (void);
105 
106     /** Let the focus manager listen for window events for the given
107         window.
108     */
109     void RegisterWindow (Window& rWindow);
110     void UnregisterWindow (Window& rWindow);
111 
112     /** Remove the window from the panel or the button container.
113     */
114     void RemoveWindow (Window& rWindow);
115 
116     bool IsAnyPanelFocused (void) const;
117     bool IsAnyButtonFocused (void) const;
118 
119     void FocusDeckTitle (void);
120     bool IsDeckTitleVisible (void) const;
121 
122     /** Set the focus to the title bar of the panel or, if the the
123         title bar is not visible, directly to the panel.
124     */
125     void FocusPanel (const sal_Int32 nPanelIndex);
126     void FocusPanelContent (const sal_Int32 nPanelIndex);
127     void FocusButton (const sal_Int32 nButtonIndex);
128     void ClickButton (const sal_Int32 nButtonIndex);
129     bool MoveFocusInsidePanel (
130         const FocusLocation aLocation,
131         const sal_Int32 nDirection);
132 
133     void HandleKeyEvent (
134         const KeyCode& rKeyCode,
135         const Window& rWindow);
136 
137     FocusLocation GetFocusLocation (const Window& rWindow) const;
138 
139 };
140 
141 } } // end of namespace sfx2::sidebar
142 
143 #endif
144