1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #pragma once
20 
21 #include <sfx2/sidebar/ResourceManager.hxx>
22 
23 #include <vcl/InterimItemWindow.hxx>
24 
25 #include <functional>
26 
27 namespace com::sun::star::frame { class XFrame; }
28 
29 namespace svt { class AcceleratorExecute; }
30 
31 namespace weld { class Toolbar; }
32 
33 namespace sfx2::sidebar {
34 
35 class FocusManager;
36 class SidebarController;
37 
38 /** The tab bar is the container for the individual tabs.
39 */
40 class TabBar final : public InterimItemWindow
41 {
42 public:
43     /** DeckMenuData has entries for display name, and a flag:
44          - isCurrentDeck for the deck selection data
45          - isEnabled     for the show/hide menu
46     */
47     class DeckMenuData
48     {
49     public:
50         OUString msDisplayName;
51         bool mbIsCurrentDeck;
52         bool mbIsActive;
53         bool mbIsEnabled;
54     };
55     typedef ::std::function<void (
56             weld::Menu& rMainMenu, weld::Menu& rSubMenu,
57             const ::std::vector<DeckMenuData>& rMenuData)> PopupMenuProvider;
58     TabBar (
59         vcl::Window* pParentWindow,
60         const css::uno::Reference<css::frame::XFrame>& rxFrame,
61         const ::std::function<void (const OUString& rsDeckId)>& rDeckActivationFunctor,
62         const PopupMenuProvider& rPopupMenuProvider,
63         SidebarController* rParentSidebarController);
64 
GetContainer()65     weld::Container* GetContainer() { return m_xContainer.get(); }
66 
67     virtual ~TabBar() override;
68     virtual void dispose() override;
69 
70     virtual void DataChanged (const DataChangedEvent& rDataChangedEvent) override;
71     virtual bool EventNotify (NotifyEvent& rEvent) override;
72 
73     static sal_Int32 GetDefaultWidth();
74 
75     void SetDecks (
76         const ResourceManager::DeckContextDescriptorContainer& rDecks);
77     void HighlightDeck (std::u16string_view rsDeckId);
78     void RemoveDeckHighlight ();
79     OUString const & GetDeckIdForIndex (const sal_Int32 nIndex) const;
80     void ToggleHideFlag (const sal_Int32 nIndex);
81     void RestoreHideFlags();
82 
83     void UpdateFocusManager (FocusManager& rFocusManager);
84 
85     /// Enables/Disables the menu button. Used by LoKit.
86     void EnableMenuButton(const bool bEnable);
87 
88 private:
89     css::uno::Reference<css::frame::XFrame> mxFrame;
90 
91     // This unusual auxiliary builder is because without a toplevel GtkWindow
92     // gtk will warn on loading a .ui with an accelerator defined, so use a
93     // temporary toplevel to suppress that and move the contents after load
94     std::unique_ptr<weld::Builder> mxAuxBuilder;
95     std::unique_ptr<weld::Container> mxTempToplevel;
96     std::unique_ptr<weld::Widget> mxContents;
97 
98     std::unique_ptr<weld::MenuButton> mxMenuButton;
99     std::unique_ptr<weld::Menu> mxMainMenu;
100     std::unique_ptr<weld::Menu> mxSubMenu;
101     std::unique_ptr<weld::Widget> mxMeasureBox;
102     class Item
103     {
104     private:
105         TabBar& mrTabBar;
106         std::unique_ptr<weld::Builder> mxBuilder;
107     public:
108         Item(TabBar& rTabBar);
109         ~Item();
110         DECL_LINK(HandleClick, const OString&, void);
111         std::unique_ptr<weld::Toolbar> mxButton;
112         OUString msDeckId;
113         ::std::function<void (const OUString& rsDeckId)> maDeckActivationFunctor;
114         bool mbIsHidden;
115         bool mbIsHiddenByDefault;
116     };
117     typedef ::std::vector<std::unique_ptr<Item>> ItemContainer;
118     ItemContainer maItems;
119     const ::std::function<void (const OUString& rsDeckId)> maDeckActivationFunctor;
120     PopupMenuProvider maPopupMenuProvider;
121 
122     static void CreateTabItem(weld::Toolbar& rButton, const DeckDescriptor& rDeckDescriptor);
123     css::uno::Reference<css::graphic::XGraphic> GetItemImage(const DeckDescriptor& rDeskDescriptor) const;
124     void UpdateButtonIcons();
125 
126     DECL_LINK(OnToolboxClicked, weld::Toggleable&, void);
127 
128     SidebarController* pParentSidebarController;
129     std::unique_ptr<svt::AcceleratorExecute> mpAccel;
130 
131 };
132 
133 
134 } // end of namespace sfx2::sidebar
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
137