Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / sfx2 / sidebar / TabBar.hxx
blob6ef0fc9c3ddd54882fef11e226aa16245c26f6e8
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/ResourceManager.hxx>
23 #include <vcl/InterimItemWindow.hxx>
25 #include <functional>
27 namespace com::sun::star::frame { class XFrame; }
29 namespace svt { class AcceleratorExecute; }
31 namespace weld { class Toolbar; }
33 namespace sfx2::sidebar {
35 class FocusManager;
36 class SidebarController;
38 /** The tab bar is the container for the individual tabs.
40 class TabBar final : public InterimItemWindow
42 friend class TabBarUIObject;
43 public:
44 /** DeckMenuData has entries for display name, and a flag:
45 - isCurrentDeck for the deck selection data
46 - isEnabled for the show/hide menu
48 class DeckMenuData
50 public:
51 OUString msDisplayName;
52 bool mbIsCurrentDeck;
53 bool mbIsActive;
54 bool mbIsEnabled;
56 typedef ::std::function<void (
57 weld::Menu& rMainMenu, weld::Menu& rSubMenu,
58 const ::std::vector<DeckMenuData>& rMenuData)> PopupMenuProvider;
59 TabBar (
60 vcl::Window* pParentWindow,
61 const css::uno::Reference<css::frame::XFrame>& rxFrame,
62 ::std::function<void (const OUString& rsDeckId)> aDeckActivationFunctor,
63 PopupMenuProvider aPopupMenuProvider,
64 SidebarController* rParentSidebarController);
66 weld::Container* GetContainer() { return m_xContainer.get(); }
68 virtual ~TabBar() override;
69 virtual void dispose() override;
71 virtual void DataChanged (const DataChangedEvent& rDataChangedEvent) override;
72 virtual bool EventNotify (NotifyEvent& rEvent) override;
74 static sal_Int32 GetDefaultWidth();
76 void SetDecks (
77 const ResourceManager::DeckContextDescriptorContainer& rDecks);
78 void HighlightDeck (std::u16string_view rsDeckId);
79 void RemoveDeckHighlight ();
80 OUString const & GetDeckIdForIndex (const sal_Int32 nIndex) const;
81 void ToggleHideFlag (const sal_Int32 nIndex);
82 void RestoreHideFlags();
84 void UpdateFocusManager (FocusManager& rFocusManager);
86 /// Enables/Disables the menu button. Used by LoKit.
87 void EnableMenuButton(const bool bEnable);
89 virtual FactoryFunction GetUITestFactory() const override;
90 private:
91 css::uno::Reference<css::frame::XFrame> mxFrame;
93 // This unusual auxiliary builder is because without a toplevel GtkWindow
94 // gtk will warn on loading a .ui with an accelerator defined, so use a
95 // temporary toplevel to suppress that and move the contents after load
96 std::unique_ptr<weld::Builder> mxAuxBuilder;
97 std::unique_ptr<weld::Box> mxTempToplevel;
98 std::unique_ptr<weld::Widget> mxContents;
100 std::unique_ptr<weld::MenuButton> mxMenuButton;
101 std::unique_ptr<weld::Menu> mxMainMenu;
102 std::unique_ptr<weld::Menu> mxSubMenu;
103 std::unique_ptr<weld::Widget> mxMeasureBox;
104 class Item
106 private:
107 TabBar& mrTabBar;
108 std::unique_ptr<weld::Builder> mxBuilder;
109 public:
110 Item(TabBar& rTabBar);
111 ~Item();
112 DECL_LINK(HandleClick, const OUString&, void);
113 std::unique_ptr<weld::Toolbar> mxButton;
114 OUString msDeckId;
115 ::std::function<void (const OUString& rsDeckId)> maDeckActivationFunctor;
116 bool mbIsHidden;
117 bool mbIsHiddenByDefault;
119 typedef ::std::vector<std::unique_ptr<Item>> ItemContainer;
120 ItemContainer maItems;
121 const ::std::function<void (const OUString& rsDeckId)> maDeckActivationFunctor;
122 PopupMenuProvider maPopupMenuProvider;
124 void CreateTabItem(weld::Toolbar& rButton, const DeckDescriptor& rDeckDescriptor);
125 css::uno::Reference<css::graphic::XGraphic> GetItemImage(const DeckDescriptor& rDeskDescriptor) const;
126 void UpdateButtonIcons();
128 DECL_LINK(OnToolboxClicked, weld::Toggleable&, void);
130 SidebarController* pParentSidebarController;
131 std::unique_ptr<svt::AcceleratorExecute> mpAccel;
136 } // end of namespace sfx2::sidebar
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */