Simplify using designated initializers
[LibreOffice.git] / include / sfx2 / sidebar / FocusManager.hxx
blob6eaa877b4dca02454e2118fa6498c8be0f8cbc8d
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/keycod.hxx>
25 namespace weld {
26 class Widget;
29 namespace sfx2::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(std::function<void(const Panel&)> aShowPanelFunctor);
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();
65 void GrabFocusPanel();
67 void SetDeck(Deck* pDeck);
68 void SetPanels(const SharedPanelContainer& rPanels);
69 void SetButtons(const std::vector<weld::Widget*>& rButtons);
71 private:
72 VclPtr<Deck> mxDeck;
73 DeckTitleBar* mpDeckTitleBar;
74 SharedPanelContainer maPanels;
75 std::vector<weld::Widget*> maButtons;
76 const std::function<void(const Panel&)> maShowPanelFunctor;
78 enum PanelComponent
80 PC_DeckToolBox,
81 PC_PanelTitle,
82 PC_PanelToolBox,
83 PC_PanelContent,
84 PC_TabBar,
85 PC_None
87 class FocusLocation
89 public:
90 PanelComponent meComponent;
91 sal_Int32 mnIndex;
92 FocusLocation(const PanelComponent eComponent, const sal_Int32 nIndex);
95 /** Listen for key events for panels and buttons.
97 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
99 void ClearPanels();
100 void ClearButtons();
102 /** Let the focus manager listen for window events for the given
103 window.
105 void RegisterWindow(weld::Widget& rWidget);
106 static void UnregisterWindow(weld::Widget& rWidget);
108 void FocusDeckTitle();
109 bool IsDeckTitleVisible() const;
111 /** Set the focus to the title bar of the panel or, if the
112 title bar is not visible, directly to the panel.
113 @param nPanelIndex
114 Index of the panel to focus.
115 @param bFallbackToDeckTitle
116 When the panel title bar is not visible then The fallback
117 bias defines whether to focus the deck (true) or the panel
118 content (false) will be focused instead.
120 void FocusPanel(const sal_Int32 nPanelIndex,
121 const bool bFallbackToDeckTitle);
123 void FocusPanelContent(const sal_Int32 nPanelIndex);
124 void FocusButton(const sal_Int32 nButtonIndex);
125 void MoveFocusInsidePanel(const FocusLocation& rLocation,
126 const sal_Int32 nDirection);
128 bool HandleKeyEvent(const vcl::KeyCode& rKeyCode,
129 const FocusLocation& rLocation);
131 FocusLocation GetFocusLocation() const;
135 } // end of namespace sfx2::sidebar
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */