Avoid potential negative array index access to cached text.
[LibreOffice.git] / sfx2 / inc / commandpopup / CommandPopup.hxx
blobc93a283608c3cec37547c81fd7f2035e7c1e5122
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/.
8 */
10 #pragma once
12 #include <utility>
13 #include <vcl/weld.hxx>
15 #include <com/sun/star/uno/XComponentContext.hpp>
16 #include <com/sun/star/frame/XFrame.hpp>
17 #include <com/sun/star/container/XIndexAccess.hpp>
18 #include <com/sun/star/i18n/XCharacterClassification.hpp>
19 #include <com/sun/star/util/XURLTransformer.hpp>
21 #include <functional>
22 #include <unordered_set>
24 struct CurrentEntry final
26 OUString m_aCommandURL;
27 OUString m_aTooltip;
29 CurrentEntry(OUString aCommandURL, OUString aTooltip)
30 : m_aCommandURL(std::move(aCommandURL))
31 , m_aTooltip(std::move(aTooltip))
36 struct MenuContent final
38 OUString m_aCommandURL;
39 OUString m_aMenuLabel;
40 OUString m_aSearchableMenuLabel;
41 OUString m_aFullLabelWithPath;
42 OUString m_aTooltip;
43 std::vector<MenuContent> m_aSubMenuContent;
46 class MenuContentHandler final
48 private:
49 css::uno::Reference<css::uno::XComponentContext> m_xContext;
50 css::uno::Reference<css::frame::XFrame> m_xFrame;
51 css::uno::Reference<css::i18n::XCharacterClassification> m_xCharacterClassification;
52 css::uno::Reference<css::util::XURLTransformer> m_xURLTransformer;
54 MenuContent m_aMenuContent;
55 OUString m_sModuleLongName;
56 OUString toLower(OUString const& rString);
57 std::unordered_set<OUString> m_aAdded;
59 public:
60 MenuContentHandler(css::uno::Reference<css::frame::XFrame> const& xFrame);
62 void gatherMenuContent(css::uno::Reference<css::container::XIndexAccess> const& xIndexAccess,
63 MenuContent& rMenuContent);
65 void findInMenu(OUString const& rText, std::unique_ptr<weld::TreeView>& rpCommandTreeView,
66 std::vector<CurrentEntry>& rCommandList);
68 private:
69 void findInMenuRecursive(
70 MenuContent const& rMenuContent, OUString const& rText,
71 std::unique_ptr<weld::TreeView>& rpCommandTreeView, std::vector<CurrentEntry>& rCommandList,
72 std::function<bool(MenuContent const&, OUString const&)> const& rSearchCriterium);
74 void addCommandIfPossible(MenuContent const& rMenuContent,
75 const std::unique_ptr<weld::TreeView>& rpCommandTreeView,
76 std::vector<CurrentEntry>& rCommandList);
79 class CommandListBox final
81 private:
82 std::unique_ptr<weld::Builder> mxBuilder;
83 std::unique_ptr<weld::Popover> mxPopover;
84 std::unique_ptr<weld::Entry> mpEntry;
85 std::unique_ptr<weld::TreeView> mpCommandTreeView;
87 std::vector<CurrentEntry> maCommandList;
88 std::unique_ptr<MenuContentHandler> mpMenuContentHandler;
90 DECL_LINK(QueryTooltip, const weld::TreeIter&, OUString);
91 DECL_LINK(RowActivated, weld::TreeView&, bool);
92 DECL_LINK(ModifyHdl, weld::Entry&, void);
93 DECL_LINK(TreeViewKeyPress, const KeyEvent&, bool);
95 void dispatchCommandAndClose(OUString const& rCommand);
97 public:
98 CommandListBox(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
99 void connect_closed(const Link<weld::Popover&, void>& rLink)
101 mxPopover->connect_closed(rLink);
105 class CommandPopupHandler final
107 private:
108 std::unique_ptr<CommandListBox> mpListBox;
110 public:
111 void showPopup(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
112 DECL_LINK(PopupModeEnd, weld::Popover&, void);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */