/src/libreoffice/vcl/source/control/managedmenubutton.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
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 | | |
10 | | #include <comphelper/processfactory.hxx> |
11 | | #include <comphelper/propertyvalue.hxx> |
12 | | |
13 | | #include <managedmenubutton.hxx> |
14 | | #include <vcl/menu.hxx> |
15 | | |
16 | | #include <com/sun/star/frame/ModuleManager.hpp> |
17 | | #include <com/sun/star/frame/theDesktop.hpp> |
18 | | #include <com/sun/star/frame/thePopupMenuControllerFactory.hpp> |
19 | | |
20 | | ManagedMenuButton::ManagedMenuButton(vcl::Window* pParent, WinBits nStyle) |
21 | 0 | : MenuButton(pParent, nStyle) |
22 | 0 | { |
23 | 0 | SetImageAlign(ImageAlign::Left); |
24 | 0 | } Unexecuted instantiation: ManagedMenuButton::ManagedMenuButton(vcl::Window*, long) Unexecuted instantiation: ManagedMenuButton::ManagedMenuButton(vcl::Window*, long) |
25 | | |
26 | | ManagedMenuButton::~ManagedMenuButton() |
27 | 0 | { |
28 | 0 | disposeOnce(); |
29 | 0 | } |
30 | | |
31 | | void ManagedMenuButton::dispose() |
32 | 0 | { |
33 | 0 | css::uno::Reference<css::lang::XComponent> xComponent(m_xPopupController, css::uno::UNO_QUERY); |
34 | 0 | if (xComponent.is()) |
35 | 0 | xComponent->dispose(); |
36 | |
|
37 | 0 | m_xPopupMenu.clear(); |
38 | 0 | m_xPopupController.clear(); |
39 | 0 | MenuButton::dispose(); |
40 | 0 | } |
41 | | |
42 | | void ManagedMenuButton::PrepareExecute() |
43 | 0 | { |
44 | 0 | if (!GetPopupMenu()) |
45 | 0 | SetPopupMenu(VclPtr<PopupMenu>::Create(), true); |
46 | |
|
47 | 0 | MenuButton::PrepareExecute(); |
48 | |
|
49 | 0 | if (m_xPopupController.is()) |
50 | 0 | { |
51 | 0 | m_xPopupController->updatePopupMenu(); |
52 | 0 | return; |
53 | 0 | } |
54 | | |
55 | 0 | if (!m_xPopupMenu.is()) |
56 | 0 | m_xPopupMenu = GetPopupMenu()->CreateMenuInterface(); |
57 | | |
58 | | // FIXME: get the frame from the parent VclBuilder. |
59 | 0 | const css::uno::Reference<css::uno::XComponentContext>& xContext(comphelper::getProcessComponentContext()); |
60 | 0 | css::uno::Reference<css::frame::XDesktop2> xDesktop(css::frame::theDesktop::get(xContext)); |
61 | 0 | css::uno::Reference<css::frame::XFrame> xFrame(xDesktop->getActiveFrame()); |
62 | 0 | if (!xFrame.is()) |
63 | 0 | return; |
64 | | |
65 | 0 | OUString aModuleName; |
66 | 0 | try |
67 | 0 | { |
68 | 0 | css::uno::Reference<css::frame::XModuleManager> xModuleManager(css::frame::ModuleManager::create(xContext)); |
69 | 0 | aModuleName = xModuleManager->identify(xFrame); |
70 | 0 | } |
71 | 0 | catch( const css::uno::Exception& ) |
72 | 0 | {} |
73 | |
|
74 | 0 | css::uno::Sequence<css::uno::Any> aArgs { |
75 | 0 | css::uno::Any(comphelper::makePropertyValue(u"ModuleIdentifier"_ustr, aModuleName)), |
76 | 0 | css::uno::Any(comphelper::makePropertyValue(u"Frame"_ustr, css::uno::Any(xFrame))), |
77 | 0 | css::uno::Any(comphelper::makePropertyValue(u"InToolbar"_ustr, css::uno::Any(true))) |
78 | 0 | }; |
79 | |
|
80 | 0 | const OUString aCommand(GetCommand()); |
81 | 0 | if (!aCommand.isEmpty() && GetPopupMenu()->GetItemCount() == 0) |
82 | 0 | { |
83 | 0 | css::uno::Reference<css::frame::XUIControllerFactory> xPopupMenuControllerFactory = |
84 | 0 | css::frame::thePopupMenuControllerFactory::get(xContext); |
85 | |
|
86 | 0 | if (xPopupMenuControllerFactory->hasController(aCommand, aModuleName)) |
87 | 0 | m_xPopupController.set(xPopupMenuControllerFactory->createInstanceWithArgumentsAndContext( |
88 | 0 | aCommand, aArgs, xContext), css::uno::UNO_QUERY); |
89 | 0 | } |
90 | | |
91 | | // No registered controller found, use one the can handle arbitrary menus (e.g. defined in .ui file). |
92 | 0 | if (!m_xPopupController.is()) |
93 | 0 | m_xPopupController.set(xContext->getServiceManager()->createInstanceWithArgumentsAndContext( |
94 | 0 | u"com.sun.star.comp.framework.ResourceMenuController"_ustr, aArgs, xContext), css::uno::UNO_QUERY); |
95 | |
|
96 | 0 | if (m_xPopupController.is()) |
97 | 0 | m_xPopupController->setPopupMenu(m_xPopupMenu); |
98 | 0 | } |
99 | | |
100 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |