22#include <com/sun/star/frame/XDispatch.hpp>
23#include <com/sun/star/frame/XDispatchProvider.hpp>
24#include <com/sun/star/frame/XFrame.hpp>
25#include <com/sun/star/frame/XStatusListener.hpp>
26#include <com/sun/star/util/XURLTransformer.hpp>
35#include <osl/mutex.hxx>
36#include <unordered_map>
39#include <bitmaps.hlst>
45 ".uno:ConvertToButton",
46 ".uno:ConvertToFixed",
48 ".uno:ConvertToCheckBox",
49 ".uno:ConvertToRadio",
50 ".uno:ConvertToGroup",
51 ".uno:ConvertToCombo",
52 ".uno:ConvertToImageBtn",
53 ".uno:ConvertToFileControl",
56 ".uno:ConvertToNumeric",
57 ".uno:ConvertToCurrency",
58 ".uno:ConvertToPattern",
59 ".uno:ConvertToImageControl",
60 ".uno:ConvertToFormatted",
61 ".uno:ConvertToScrollBar",
62 ".uno:ConvertToSpinButton",
63 ".uno:ConvertToNavigationBar"
68 RID_STR_PROPTITLE_EDIT,
69 RID_STR_PROPTITLE_PUSHBUTTON,
70 RID_STR_PROPTITLE_FIXEDTEXT,
71 RID_STR_PROPTITLE_LISTBOX,
72 RID_STR_PROPTITLE_CHECKBOX,
73 RID_STR_PROPTITLE_RADIOBUTTON,
74 RID_STR_PROPTITLE_GROUPBOX,
75 RID_STR_PROPTITLE_COMBOBOX,
76 RID_STR_PROPTITLE_IMAGEBUTTON,
77 RID_STR_PROPTITLE_FILECONTROL,
78 RID_STR_PROPTITLE_DATEFIELD,
79 RID_STR_PROPTITLE_TIMEFIELD,
80 RID_STR_PROPTITLE_NUMERICFIELD,
81 RID_STR_PROPTITLE_CURRENCYFIELD,
82 RID_STR_PROPTITLE_PATTERNFIELD,
83 RID_STR_PROPTITLE_IMAGECONTROL,
84 RID_STR_PROPTITLE_FORMATTED,
85 RID_STR_PROPTITLE_SCROLLBAR,
86 RID_STR_PROPTITLE_SPINBUTTON,
87 RID_STR_PROPTITLE_NAVBAR
97 RID_SVXBMP_RADIOBUTTON,
100 RID_SVXBMP_IMAGEBUTTON,
101 RID_SVXBMP_FILECONTROL,
102 RID_SVXBMP_DATEFIELD,
103 RID_SVXBMP_TIMEFIELD,
104 RID_SVXBMP_NUMERICFIELD,
105 RID_SVXBMP_CURRENCYFIELD,
106 RID_SVXBMP_PATTERNFIELD,
107 RID_SVXBMP_IMAGECONTROL,
108 RID_SVXBMP_FORMATTEDFIELD,
109 RID_SVXBMP_SCROLLBAR,
110 RID_SVXBMP_SPINBUTTON,
111 RID_SVXBMP_NAVIGATIONBAR
115using namespace css::uno;
116using namespace css::lang;
117using namespace css::frame;
118using namespace css::beans;
122class ControlMenuController :
public svt::PopupMenuControllerBase
124 using svt::PopupMenuControllerBase::disposing;
127 explicit ControlMenuController(
const uno::Reference< uno::XComponentContext >& xContext );
132 return "com.sun.star.comp.framework.ControlMenuController";
142 return {
"com.sun.star.frame.PopupMenuController"};
146 virtual void SAL_CALL updatePopupMenu()
override;
149 virtual void SAL_CALL statusChanged(
const frame::FeatureStateEvent& Event )
override;
152 virtual void SAL_CALL
itemActivated(
const awt::MenuEvent& rEvent )
override;
155 virtual void SAL_CALL disposing(
const lang::EventObject& Source )
override;
159 virtual void initializeImpl( std::unique_lock<std::mutex>& rGuard,
const uno::Sequence< uno::Any >& aArguments )
override;
161 class UrlToDispatchMap :
public std::unordered_map< OUString,
162 uno::Reference< frame::XDispatch > >
167 UrlToDispatchMap().swap( *
this );
171 void updateImagesPopupMenu(Reference<awt::XPopupMenu>
const& rPopupMenu);
172 void fillPopupMenu(uno::Reference<awt::XPopupMenu>
const& rPopupMenu);
174 bool m_bShowMenuImages : 1;
175 UrlToDispatchMap m_aURLToDispatchMap;
178ControlMenuController::ControlMenuController(
const css::uno::Reference< css::uno::XComponentContext >& xContext)
179 :
svt::PopupMenuControllerBase(xContext)
187void ControlMenuController::updateImagesPopupMenu(Reference<awt::XPopupMenu>
const& rPopupMenu)
193 sal_Int16 nItemId =
i + 1;
194 if (m_bShowMenuImages)
198 rPopupMenu->setItemImage(nItemId, aGraphic.GetXGraphic(),
false);
201 rPopupMenu->setItemImage(nItemId,
nullptr,
false);
206void ControlMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >
const & rPopupMenu )
208 resetPopupMenu( rPopupMenu );
212 sal_Int16 nItemId =
i + 1;
213 OUString sCommand(OUString::createFromAscii(
aCommands[i]));
215 rPopupMenu->setCommand(nItemId, sCommand);
216 rPopupMenu->enableItem(nItemId,
false);
219 updateImagesPopupMenu(rPopupMenu);
221 rPopupMenu->hideDisabledEntries(
true);
227void SAL_CALL ControlMenuController::disposing(
const EventObject& )
229 Reference< css::awt::XMenuListener > xHolder(
this);
235 if ( m_xPopupMenu.is() )
236 m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(
this) );
237 m_xPopupMenu.clear();
241void SAL_CALL ControlMenuController::statusChanged(
const FeatureStateEvent& Event )
248 sal_Int16 nItemId = 0;
251 if ( Event.FeatureURL.Complete.equalsAscii(
aCommands[i] ))
261 m_xPopupMenu->enableItem(nItemId, Event.IsEnabled);
265void SAL_CALL ControlMenuController::itemActivated(
const css::awt::MenuEvent& )
275 if (bShowMenuImages != m_bShowMenuImages)
277 m_bShowMenuImages = bShowMenuImages;
278 updateImagesPopupMenu(m_xPopupMenu);
283void SAL_CALL ControlMenuController::updatePopupMenu()
287 throwIfDisposed(aLock);
289 if ( !(
m_xFrame.is() && m_xPopupMenu.is()) )
293 Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
294 fillPopupMenu( m_xPopupMenu );
295 m_aURLToDispatchMap.free();
302 Reference< XDispatch >
xDispatch = xDispatchProvider->queryDispatch(
aTargetURL, OUString(), 0 );
309 m_aURLToDispatchMap.emplace(
aTargetURL.Complete, xDispatch );
315void ControlMenuController::initializeImpl( std::unique_lock<std::mutex>& rGuard,
const Sequence< Any >& aArguments )
317 svt::PopupMenuControllerBase::initializeImpl(rGuard, aArguments);
321extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
323 css::uno::XComponentContext *context,
324 css::uno::Sequence<css::uno::Any>
const &)
326 return cppu::acquire(
new ControlMenuController(context));
css::uno::Reference< css::lang::XComponent > m_xFrame
css::uno::Reference< css::frame::XDispatch > m_xDispatch
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool GetUseImagesInMenus() const
Reference< XDispatch > xDispatch
OUString FwkResId(TranslateId aId)
void SAL_CALL itemActivated(const css::awt::MenuEvent &rEvent) override
#define SAL_N_ELEMENTS(arr)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)