Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / FocusManager.hxx
blobf93f9e82c3682d3b339b78a1c9c71bce6daf854e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SFX2_SOURCE_SIDEBAR_FOCUSMANAGER_HXX
20 #define INCLUDED_SFX2_SOURCE_SIDEBAR_FOCUSMANAGER_HXX
22 #include "Panel.hxx"
23 #include <tools/link.hxx>
24 #include <vcl/keycod.hxx>
26 class Button;
27 class VclSimpleEvent;
29 namespace sfx2 { namespace sidebar {
31 class DeckTitleBar;
33 /** Concentrate all focus handling in this class.
35 There is one ring of windows that accept the input focus which are
36 cycled through with the arrow keys:
37 - the closer in the deck title (present only when docked)
38 - the panel title bars
39 - the tab bar items
41 When the focus is in a panel title then focus travels over
42 - the panel title
43 - the panel closer
44 - the panel content
46 Once the focus is in the panel content then focus cycles through
47 all controls inside the panel but not back to the title bar of
48 the panel. Escape places the focus back in the panel title.
50 class FocusManager
52 public:
53 FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor);
54 ~FocusManager();
56 /** Forget all panels and buttons. Remove all window listeners.
58 void Clear();
60 /** Transfer the focus into the sidebar tree of windows. This is
61 typically called from the SidebarChildWindow as result of
62 pressing the F6 key.
64 void GrabFocus();
66 void SetDeckTitle(DeckTitleBar* pDeckTitleBar);
67 void SetPanels(const SharedPanelContainer& rPanels);
68 void SetButtons(const ::std::vector<Button*>& rButtons);
70 private:
71 VclPtr<DeckTitleBar> mpDeckTitleBar;
72 std::vector<VclPtr<Panel> > maPanels;
73 std::vector<VclPtr<Button> > maButtons;
74 const std::function<void(const Panel&)> maShowPanelFunctor;
75 bool mbObservingContentControlFocus;
76 VclPtr<vcl::Window> mpFirstFocusedContentControl;
77 VclPtr<vcl::Window> mpLastFocusedWindow;
79 enum PanelComponent
81 PC_DeckTitle,
82 PC_DeckToolBox,
83 PC_PanelTitle,
84 PC_PanelToolBox,
85 PC_PanelContent,
86 PC_TabBar,
87 PC_None
89 class FocusLocation
91 public:
92 PanelComponent meComponent;
93 sal_Int32 mnIndex;
94 FocusLocation(const PanelComponent eComponent, const sal_Int32 nIndex);
97 /** Listen for key events for panels and buttons.
99 DECL_LINK(WindowEventListener, VclSimpleEvent*);
100 DECL_LINK(ChildEventListener, VclSimpleEvent*);
102 void ClearPanels();
103 void ClearButtons();
105 /** Let the focus manager listen for window events for the given
106 window.
108 void RegisterWindow(vcl::Window& rWindow);
109 void UnregisterWindow(vcl::Window& rWindow);
111 /** Remove the window from the panel or the button container.
113 void RemoveWindow(vcl::Window& rWindow);
115 void FocusDeckTitle();
116 bool IsDeckTitleVisible() const;
117 bool IsPanelTitleVisible(const sal_Int32 nPanelIndex) const;
119 /** Set the focus to the title bar of the panel or, if the
120 title bar is not visible, directly to the panel.
121 @param nPanelIndex
122 Index of the panel to focus.
123 @param bFallbackToDeckTitle
124 When the panel title bar is not visible then The fallback
125 bias defines whether to focus the deck (true) or the panel
126 content (false) will be focused instead.
128 void FocusPanel(const sal_Int32 nPanelIndex,
129 const bool bFallbackToDeckTitle);
131 void FocusPanelContent(const sal_Int32 nPanelIndex);
132 void FocusButton(const sal_Int32 nButtonIndex);
133 void ClickButton(const sal_Int32 nButtonIndex);
134 bool MoveFocusInsidePanel(const FocusLocation& rLocation,
135 const sal_Int32 nDirection);
136 bool MoveFocusInsideDeckTitle(const FocusLocation& rLocation,
137 const sal_Int32 nDirection);
139 void HandleKeyEvent(const vcl::KeyCode& rKeyCode,
140 const vcl::Window& rWindow);
142 FocusLocation GetFocusLocation(const vcl::Window& rWindow) const;
146 } } // end of namespace sfx2::sidebar
148 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */