Bump version to 21.06.18.1
[LibreOffice.git] / include / sfx2 / sidebar / FocusManager.hxx
blob2370ff3f801c0f6e5a5be17d255a211c1f156174
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 #pragma once
21 #include <sfx2/sidebar/Panel.hxx>
22 #include <tools/link.hxx>
23 #include <vcl/vclevent.hxx>
24 #include <vcl/keycod.hxx>
26 namespace weld {
27 class Widget;
30 namespace sfx2::sidebar {
32 class DeckTitleBar;
34 /** Concentrate all focus handling in this class.
36 There is one ring of windows that accept the input focus which are
37 cycled through with the arrow keys:
38 - the closer in the deck title (present only when docked)
39 - the panel title bars
40 - the tab bar items
42 When the focus is in a panel title then focus travels over
43 - the panel title
44 - the panel closer
45 - the panel content
47 Once the focus is in the panel content then focus cycles through
48 all controls inside the panel but not back to the title bar of
49 the panel. Escape places the focus back in the panel title.
51 class FocusManager
53 public:
54 FocusManager(const std::function<void(const Panel&)>& rShowPanelFunctor);
55 ~FocusManager();
57 /** Forget all panels and buttons. Remove all window listeners.
59 void Clear();
61 /** Transfer the focus into the sidebar tree of windows. This is
62 typically called from the SidebarChildWindow as result of
63 pressing the F6 key.
65 void GrabFocus();
66 void GrabFocusPanel();
68 void SetDeck(Deck* pDeck);
69 void SetPanels(const SharedPanelContainer& rPanels);
70 void SetButtons(const std::vector<weld::Widget*>& rButtons);
72 private:
73 VclPtr<Deck> mxDeck;
74 DeckTitleBar* mpDeckTitleBar;
75 SharedPanelContainer maPanels;
76 std::vector<weld::Widget*> maButtons;
77 const std::function<void(const Panel&)> maShowPanelFunctor;
79 enum PanelComponent
81 PC_DeckToolBox,
82 PC_PanelTitle,
83 PC_PanelToolBox,
84 PC_PanelContent,
85 PC_TabBar,
86 PC_None
88 class FocusLocation
90 public:
91 PanelComponent meComponent;
92 sal_Int32 mnIndex;
93 FocusLocation(const PanelComponent eComponent, const sal_Int32 nIndex);
96 /** Listen for key events for panels and buttons.
98 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
100 void ClearPanels();
101 void ClearButtons();
103 /** Let the focus manager listen for window events for the given
104 window.
106 void RegisterWindow(weld::Widget& rWidget);
107 static void UnregisterWindow(weld::Widget& rWidget);
109 void FocusDeckTitle();
110 bool IsDeckTitleVisible() const;
111 bool IsPanelTitleVisible(const sal_Int32 nPanelIndex) const;
113 /** Set the focus to the title bar of the panel or, if the
114 title bar is not visible, directly to the panel.
115 @param nPanelIndex
116 Index of the panel to focus.
117 @param bFallbackToDeckTitle
118 When the panel title bar is not visible then The fallback
119 bias defines whether to focus the deck (true) or the panel
120 content (false) will be focused instead.
122 void FocusPanel(const sal_Int32 nPanelIndex,
123 const bool bFallbackToDeckTitle);
125 void FocusPanelContent(const sal_Int32 nPanelIndex);
126 void FocusButton(const sal_Int32 nButtonIndex);
127 void ClickButton(const sal_Int32 nButtonIndex);
128 void MoveFocusInsidePanel(const FocusLocation& rLocation,
129 const sal_Int32 nDirection);
130 bool MoveFocusInsideDeckTitle(const FocusLocation& rLocation,
131 const sal_Int32 nDirection);
133 bool HandleKeyEvent(const vcl::KeyCode& rKeyCode,
134 const FocusLocation& rLocation);
136 FocusLocation GetFocusLocation() const;
140 } // end of namespace sfx2::sidebar
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */