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 #ifndef SFX_SIDEBAR_FOCUS_MANAGER_HXX
23*65908a7eSAndre Fischer #define SFX_SIDEBAR_FOCUS_MANAGER_HXX
24*65908a7eSAndre Fischer 
25*65908a7eSAndre Fischer #include "Panel.hxx"
26*65908a7eSAndre Fischer #include <tools/link.hxx>
27*65908a7eSAndre Fischer 
28*65908a7eSAndre Fischer class Button;
29*65908a7eSAndre Fischer class KeyCode;
30*65908a7eSAndre Fischer class VclSimpleEvent;
31*65908a7eSAndre Fischer 
32*65908a7eSAndre Fischer namespace sfx2 { namespace sidebar {
33*65908a7eSAndre Fischer 
34*65908a7eSAndre Fischer /** Concentrate all focus handling in this class.
35*65908a7eSAndre Fischer     There are two rings of windows that accept the input focus: panels
36*65908a7eSAndre Fischer     and tab bar buttons.
37*65908a7eSAndre Fischer     Arrow keys move the focus between them.  Tab moves focus between rings.
38*65908a7eSAndre Fischer */
39*65908a7eSAndre Fischer class FocusManager
40*65908a7eSAndre Fischer {
41*65908a7eSAndre Fischer public:
42*65908a7eSAndre Fischer     FocusManager (void);
43*65908a7eSAndre Fischer     ~FocusManager (void);
44*65908a7eSAndre Fischer 
45*65908a7eSAndre Fischer     /** Forget all panels and buttons.  Remove all window listeners.
46*65908a7eSAndre Fischer     */
47*65908a7eSAndre Fischer     void Clear (void);
48*65908a7eSAndre Fischer 
49*65908a7eSAndre Fischer     /** Transfer the focus into the sidebar tree of windows.  This is
50*65908a7eSAndre Fischer         typically called from the SidebarChildWindow as result of
51*65908a7eSAndre Fischer         pressing the F6 key.
52*65908a7eSAndre Fischer     */
53*65908a7eSAndre Fischer     void GrabFocus (void);
54*65908a7eSAndre Fischer 
55*65908a7eSAndre Fischer     /** Handle the key event that was sent to the docking window.
56*65908a7eSAndre Fischer     */
57*65908a7eSAndre Fischer     long NotifyDockingWindowEvent (const KeyEvent& rKeyEvent);
58*65908a7eSAndre Fischer 
59*65908a7eSAndre Fischer     void SetPanels (const SharedPanelContainer& rPanels);
60*65908a7eSAndre Fischer 
61*65908a7eSAndre Fischer     void SetButtons (const ::std::vector<Button*>& rButtons);
62*65908a7eSAndre Fischer 
63*65908a7eSAndre Fischer private:
64*65908a7eSAndre Fischer     ::std::vector<Panel*> maPanels;
65*65908a7eSAndre Fischer     ::std::vector<Button*> maButtons;
66*65908a7eSAndre Fischer     Window* mpTopLevelWindow;
67*65908a7eSAndre Fischer 
68*65908a7eSAndre Fischer     /** Listen for key events for panels and buttons.
69*65908a7eSAndre Fischer     */
70*65908a7eSAndre Fischer     DECL_LINK(WindowEventListener, VclSimpleEvent*);
71*65908a7eSAndre Fischer 
72*65908a7eSAndre Fischer     void ClearPanels (void);
73*65908a7eSAndre Fischer     void ClearButtons (void);
74*65908a7eSAndre Fischer 
75*65908a7eSAndre Fischer     /** Let the focus manager listen for window events for the given
76*65908a7eSAndre Fischer         window.
77*65908a7eSAndre Fischer     */
78*65908a7eSAndre Fischer     void RegisterWindow (Window& rWindow);
79*65908a7eSAndre Fischer     void UnregisterWindow (Window& rWindow);
80*65908a7eSAndre Fischer     void RegisterTopLevelListener (void);
81*65908a7eSAndre Fischer 
82*65908a7eSAndre Fischer     /** Remove the window from the panel or the button container.
83*65908a7eSAndre Fischer     */
84*65908a7eSAndre Fischer     void RemoveWindow (Window& rWindow);
85*65908a7eSAndre Fischer 
86*65908a7eSAndre Fischer     sal_Int32 GetPanelIndex (const Window& rWindow) const;
87*65908a7eSAndre Fischer     sal_Int32 GetButtonIndex (const Window& rWindow) const;
88*65908a7eSAndre Fischer     bool IsAnyPanelFocused (void) const;
89*65908a7eSAndre Fischer     bool IsAnyButtonFocused (void) const;
90*65908a7eSAndre Fischer 
91*65908a7eSAndre Fischer     /** Set the focus to the title bar of the panel or, if the the
92*65908a7eSAndre Fischer         title bar is not visible, directly to the panel.
93*65908a7eSAndre Fischer     */
94*65908a7eSAndre Fischer     void FocusPanel (const sal_Int32 nPanelIndex);
95*65908a7eSAndre Fischer     void FocusPanelContent (const sal_Int32 nPanelIndex);
96*65908a7eSAndre Fischer     void FocusButton (const sal_Int32 nButtonIndex);
97*65908a7eSAndre Fischer     void ClickButton (const sal_Int32 nButtonIndex);
98*65908a7eSAndre Fischer     bool MoveFocusInsidePanel (
99*65908a7eSAndre Fischer         const sal_Int32 nPanelIndex,
100*65908a7eSAndre Fischer         const sal_Int32 nDirection);
101*65908a7eSAndre Fischer 
102*65908a7eSAndre Fischer     void HandleKeyEvent (
103*65908a7eSAndre Fischer         const KeyCode& rKeyCode,
104*65908a7eSAndre Fischer         const Window& rWindow);
105*65908a7eSAndre Fischer 
106*65908a7eSAndre Fischer     void SetTopLevelWindow (Window* pWindow);
107*65908a7eSAndre Fischer     void HandleTopLevelEvent (VclWindowEvent& rEvent);
108*65908a7eSAndre Fischer };
109*65908a7eSAndre Fischer 
110*65908a7eSAndre Fischer } } // end of namespace sfx2::sidebar
111*65908a7eSAndre Fischer 
112*65908a7eSAndre Fischer #endif
113