LibreOffice Module vcl (master) 1
managedmenubutton.cxx
Go to the documentation of this file.
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
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
21 : MenuButton(pParent, nStyle)
22{
24}
25
27{
29}
30
32{
33 css::uno::Reference<css::lang::XComponent> xComponent(m_xPopupController, css::uno::UNO_QUERY);
34 if (xComponent.is())
35 xComponent->dispose();
36
37 m_xPopupMenu.clear();
38 m_xPopupController.clear();
40}
41
43{
44 if (!GetPopupMenu())
46
48
49 if (m_xPopupController.is())
50 {
51 m_xPopupController->updatePopupMenu();
52 return;
53 }
54
55 if (!m_xPopupMenu.is())
57
58 // FIXME: get the frame from the parent VclBuilder.
59 css::uno::Reference<css::uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
60 css::uno::Reference<css::frame::XDesktop2> xDesktop(css::frame::theDesktop::get(xContext));
61 css::uno::Reference<css::frame::XFrame> xFrame(xDesktop->getActiveFrame());
62 if (!xFrame.is())
63 return;
64
65 OUString aModuleName;
66 try
67 {
68 css::uno::Reference<css::frame::XModuleManager> xModuleManager(css::frame::ModuleManager::create(xContext));
69 aModuleName = xModuleManager->identify(xFrame);
70 }
71 catch( const css::uno::Exception& )
72 {}
73
74 css::uno::Sequence<css::uno::Any> aArgs {
75 css::uno::Any(comphelper::makePropertyValue("ModuleIdentifier", aModuleName)),
76 css::uno::Any(comphelper::makePropertyValue("Frame", css::uno::Any(xFrame))),
77 css::uno::Any(comphelper::makePropertyValue("InToolbar", css::uno::Any(true)))
78 };
79
80 const OUString aCommand(GetCommand());
81 if (!aCommand.isEmpty() && GetPopupMenu()->GetItemCount() == 0)
82 {
83 css::uno::Reference<css::frame::XUIControllerFactory> xPopupMenuControllerFactory =
84 css::frame::thePopupMenuControllerFactory::get(xContext);
85
86 if (xPopupMenuControllerFactory->hasController(aCommand, aModuleName))
87 m_xPopupController.set(xPopupMenuControllerFactory->createInstanceWithArgumentsAndContext(
88 aCommand, aArgs, xContext), css::uno::UNO_QUERY);
89 }
90
91 // No registered controller found, use one the can handle arbitrary menus (e.g. defined in .ui file).
92 if (!m_xPopupController.is())
93 m_xPopupController.set(xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
94 "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY);
95
96 if (m_xPopupController.is())
97 m_xPopupController->setPopupMenu(m_xPopupMenu);
98}
99
100/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void SetImageAlign(ImageAlign eAlign)
Definition: button.cxx:153
OUString const & GetCommand() const
Definition: button.hxx:84
ManagedMenuButton(vcl::Window *pParent, WinBits nStyle)
css::uno::Reference< css::frame::XPopupMenuController > m_xPopupController
void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
css::uno::Reference< css::awt::XPopupMenu > m_xPopupMenu
~ManagedMenuButton() override
void Activate() override
void SetPopupMenu(PopupMenu *pNewMenu)
Definition: menubtn.cxx:241
PopupMenu * GetPopupMenu() const
Definition: menubtn.hxx:82
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: menubtn.cxx:163
virtual void Activate() override
Definition: menubtn.cxx:228
css::uno::Reference< css::awt::XPopupMenu > CreateMenuInterface()
Definition: menu.cxx:3104
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: vclptr.hxx:58
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Reference< XFrame > xFrame
OUString aCommand
sal_Int64 WinBits
Definition: wintypes.hxx:109