1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <toolkit/awt/vclxmenu.hxx>
21 #include <toolkit/helper/vclunohelper.hxx>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <tools/debug.hxx>
28 #include <vcl/dialoghelper.hxx>
29 #include <vcl/graph.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/keycod.hxx>
32 #include <vcl/image.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/unohelp.hxx>
35 #include <vcl/window.hxx>
37 #include <com/sun/star/awt/KeyModifier.hpp>
40 : maMenuListeners( *this )
46 VCLXMenu::VCLXMenu( Menu
* pMenu
)
47 : maMenuListeners( *this )
55 maPopupMenuRefs
.clear();
59 mpMenu
->RemoveEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
60 mpMenu
.disposeAndClear();
64 bool VCLXMenu::IsPopupMenu() const
66 return (mpMenu
&& ! mpMenu
->IsMenuBar());
69 void VCLXMenu::ImplCreateMenu( bool bPopup
)
71 DBG_ASSERT( !mpMenu
, "CreateMenu: Menu exists!" );
74 mpMenu
= VclPtr
<PopupMenu
>::Create();
76 mpMenu
= VclPtr
<MenuBar
>::Create();
78 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
81 void VCLXMenu::ImplAddListener()
84 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
87 IMPL_LINK( VCLXMenu
, MenuEventListener
, VclMenuEvent
&, rMenuEvent
, void )
89 DBG_ASSERT( rMenuEvent
.GetMenu() && mpMenu
, "Menu???" );
91 if ( rMenuEvent
.GetMenu() != mpMenu
) // Also called for the root menu
94 switch ( rMenuEvent
.GetId() )
96 case VclEventId::MenuSelect
:
98 if ( maMenuListeners
.getLength() )
100 css::awt::MenuEvent aEvent
;
101 aEvent
.Source
= getXWeak();
102 aEvent
.MenuId
= mpMenu
->GetCurItemId();
103 maMenuListeners
.itemSelected( aEvent
);
107 case VclEventId::ObjectDying
:
112 case VclEventId::MenuHighlight
:
114 if ( maMenuListeners
.getLength() )
116 css::awt::MenuEvent aEvent
;
117 aEvent
.Source
= getXWeak();
118 aEvent
.MenuId
= mpMenu
->GetCurItemId();
119 maMenuListeners
.itemHighlighted( aEvent
);
123 case VclEventId::MenuActivate
:
125 if ( maMenuListeners
.getLength() )
127 css::awt::MenuEvent aEvent
;
128 aEvent
.Source
= getXWeak();
129 aEvent
.MenuId
= mpMenu
->GetCurItemId();
130 maMenuListeners
.itemActivated( aEvent
);
134 case VclEventId::MenuDeactivate
:
136 if ( maMenuListeners
.getLength() )
138 css::awt::MenuEvent aEvent
;
139 aEvent
.Source
= getXWeak();
140 aEvent
.MenuId
= mpMenu
->GetCurItemId();
141 maMenuListeners
.itemDeactivated( aEvent
);
146 // ignore accessibility events
147 case VclEventId::MenuEnable
:
148 case VclEventId::MenuInsertItem
:
149 case VclEventId::MenuRemoveItem
:
150 case VclEventId::MenuSubmenuActivate
:
151 case VclEventId::MenuSubmenuDeactivate
:
152 case VclEventId::MenuSubmenuChanged
:
153 case VclEventId::MenuDehighlight
:
154 case VclEventId::MenuDisable
:
155 case VclEventId::MenuItemRoleChanged
:
156 case VclEventId::MenuItemTextChanged
:
157 case VclEventId::MenuItemChecked
:
158 case VclEventId::MenuItemUnchecked
:
159 case VclEventId::MenuShow
:
160 case VclEventId::MenuHide
:
163 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
168 OUString SAL_CALL
VCLXMenu::getImplementationName( )
170 std::unique_lock
aGuard( maMutex
);
171 const bool bIsPopupMenu
= IsPopupMenu();
174 OUString
implName( u
"stardiv.Toolkit."_ustr
);
176 implName
+= "VCLXPopupMenu";
178 implName
+= "VCLXMenuBar";
183 css::uno::Sequence
< OUString
> SAL_CALL
VCLXMenu::getSupportedServiceNames( )
185 std::unique_lock
aGuard( maMutex
);
186 const bool bIsPopupMenu
= IsPopupMenu();
190 return css::uno::Sequence
<OUString
>{
191 u
"com.sun.star.awt.PopupMenu"_ustr
,
192 u
"stardiv.vcl.PopupMenu"_ustr
};
194 return css::uno::Sequence
<OUString
>{
195 u
"com.sun.star.awt.MenuBar"_ustr
,
196 u
"stardiv.vcl.MenuBar"_ustr
};
199 sal_Bool SAL_CALL
VCLXMenu::supportsService(const OUString
& rServiceName
)
201 return cppu::supportsService(this, rServiceName
);
204 css::uno::Any
VCLXMenu::queryInterface(
205 const css::uno::Type
& rType
)
207 std::unique_lock
aGuard( maMutex
);
208 const bool bIsPopupMenu
= IsPopupMenu();
214 aRet
= ::cppu::queryInterface( rType
,
215 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
216 static_cast< css::awt::XPopupMenu
* >(this),
217 static_cast< css::lang::XTypeProvider
* >(this),
218 static_cast< css::lang::XServiceInfo
* >(this) );
220 aRet
= ::cppu::queryInterface( rType
,
221 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
222 static_cast< css::awt::XMenuBar
* >(this),
223 static_cast< css::lang::XTypeProvider
* >(this),
224 static_cast< css::lang::XServiceInfo
* >(this) );
226 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
230 css::uno::Sequence
< css::uno::Type
> VCLXMenu::getTypes()
232 std::unique_lock
aGuard( maMutex
);
233 const bool bIsPopupMenu
= IsPopupMenu();
238 static cppu::OTypeCollection
collectionPopupMenu(
239 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
240 cppu::UnoType
<css::awt::XPopupMenu
>::get(),
241 cppu::UnoType
<css::lang::XServiceInfo
>::get());
242 return collectionPopupMenu
.getTypes();
246 static cppu::OTypeCollection
collectionMenuBar(
247 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
248 cppu::UnoType
<css::awt::XMenuBar
>::get(),
249 cppu::UnoType
<css::lang::XServiceInfo
>::get());
250 return collectionMenuBar
.getTypes();
255 css::uno::Sequence
< sal_Int8
> VCLXMenu::getImplementationId()
257 return css::uno::Sequence
<sal_Int8
>();
260 void VCLXMenu::addMenuListener(
261 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
263 std::unique_lock
aGuard( maMutex
);
265 maMenuListeners
.addInterface( rxListener
);
268 void VCLXMenu::removeMenuListener(
269 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
271 std::unique_lock
aGuard( maMutex
);
273 maMenuListeners
.removeInterface( rxListener
);
276 void VCLXMenu::insertItem(
278 const OUString
& aText
,
279 sal_Int16 nItemStyle
,
282 SolarMutexGuard aSolarGuard
;
283 std::unique_lock
aGuard( maMutex
);
286 mpMenu
->InsertItem(nItemId
, aText
, static_cast<MenuItemBits
>(nItemStyle
), {}, nPos
);
289 void VCLXMenu::removeItem(
293 SolarMutexGuard aSolarGuard
;
294 std::unique_lock
aGuard( maMutex
);
299 sal_Int32 nItemCount
= static_cast<sal_Int32
>(mpMenu
->GetItemCount());
300 if ((nCount
> 0) && (nPos
>= 0) && (nPos
< nItemCount
))
302 sal_Int16 nP
= sal::static_int_cast
< sal_Int16
>(
303 std::min( static_cast<int>(nPos
+nCount
), static_cast<int>(nItemCount
) ));
305 mpMenu
->RemoveItem( --nP
);
309 sal_Int16
VCLXMenu::getItemCount( )
311 SolarMutexGuard aSolarGuard
;
312 std::unique_lock
aGuard( maMutex
);
314 return mpMenu
? mpMenu
->GetItemCount() : 0;
317 sal_Int16
VCLXMenu::getItemId(
320 SolarMutexGuard aSolarGuard
;
321 std::unique_lock
aGuard( maMutex
);
323 return mpMenu
? mpMenu
->GetItemId( nPos
) : 0;
326 sal_Int16
VCLXMenu::getItemPos(
329 SolarMutexGuard aSolarGuard
;
330 std::unique_lock
aGuard( maMutex
);
332 return mpMenu
? mpMenu
->GetItemPos( nId
) : 0;
335 void VCLXMenu::enableItem(
339 SolarMutexGuard aSolarGuard
;
340 std::unique_lock
aGuard( maMutex
);
343 mpMenu
->EnableItem( nItemId
, bEnable
);
346 sal_Bool
VCLXMenu::isItemEnabled(
349 SolarMutexGuard aSolarGuard
;
350 std::unique_lock
aGuard( maMutex
);
352 return mpMenu
&& mpMenu
->IsItemEnabled( nItemId
);
355 void VCLXMenu::setItemText(
357 const OUString
& aText
)
359 SolarMutexGuard aSolarGuard
;
360 std::unique_lock
aGuard( maMutex
);
363 mpMenu
->SetItemText( nItemId
, aText
);
366 OUString
VCLXMenu::getItemText(
369 SolarMutexGuard aSolarGuard
;
370 std::unique_lock
aGuard( maMutex
);
374 aItemText
= mpMenu
->GetItemText( nItemId
);
378 void VCLXMenu::setPopupMenu(
380 const css::uno::Reference
< css::awt::XPopupMenu
>& rxPopupMenu
)
382 SolarMutexGuard aSolarGuard
;
383 std::unique_lock
aGuard( maMutex
);
385 VCLXMenu
* pVCLMenu
= dynamic_cast<VCLXMenu
*>( rxPopupMenu
.get() );
386 DBG_ASSERT( pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
388 if ( mpMenu
&& pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu() )
390 maPopupMenuRefs
.push_back( rxPopupMenu
);
392 mpMenu
->SetPopupMenu( nItemId
, static_cast<PopupMenu
*>( pVCLMenu
->GetMenu() ) );
396 css::uno::Reference
< css::awt::XPopupMenu
> VCLXMenu::getPopupMenu(
399 SolarMutexGuard aSolarGuard
;
400 std::unique_lock
aGuard( maMutex
);
402 css::uno::Reference
< css::awt::XPopupMenu
> aRef
;
403 Menu
* pMenu
= mpMenu
? mpMenu
->GetPopupMenu( nItemId
) : nullptr;
406 for ( size_t n
= maPopupMenuRefs
.size(); n
; )
408 css::uno::Reference
< css::awt::XPopupMenu
>& rRef
= maPopupMenuRefs
[ --n
];
409 Menu
* pM
= static_cast<VCLXMenu
*>(rRef
.get())->GetMenu();
417 If the popup menu is not inserted via setPopupMenu then
418 maPopupMenuRefs won't have an entry for it, so create an XPopupMenu
421 This means that this vcl PopupMenu "pMenu" either existed as a child
422 of the vcl Menu "mpMenu" before the VCLXMenu was created for that or
423 it was added directly via vcl.
427 aRef
= new VCLXPopupMenu( static_cast<PopupMenu
*>(pMenu
) );
429 In any case, the VCLXMenu has ownership of "mpMenu" and will
430 destroy it in the VCLXMenu dtor.
432 Similarly because VCLXPopupMenu takes ownership of the vcl
433 PopupMenu "pMenu", the underlying vcl popup will be destroyed
434 when VCLXPopupMenu is, so we should add it now to
435 maPopupMenuRefs to ensure its lifecycle is at least bound to
436 the VCLXMenu that owns the parent "mpMenu" similarly to
437 PopupMenus added via the more conventional setPopupMenu.
439 maPopupMenuRefs
.push_back( aRef
);
445 // css::awt::XPopupMenu
446 void VCLXMenu::insertSeparator(
449 SolarMutexGuard aSolarGuard
;
450 std::unique_lock
aGuard( maMutex
);
453 mpMenu
->InsertSeparator({}, nPos
);
456 void VCLXMenu::setDefaultItem(
459 std::unique_lock
aGuard( maMutex
);
461 mnDefaultItem
= nItemId
;
464 sal_Int16
VCLXMenu::getDefaultItem( )
466 std::unique_lock
aGuard( maMutex
);
468 return mnDefaultItem
;
471 void VCLXMenu::checkItem(
475 SolarMutexGuard aSolarGuard
;
476 std::unique_lock
aGuard( maMutex
);
479 mpMenu
->CheckItem( nItemId
, bCheck
);
482 sal_Bool
VCLXMenu::isItemChecked(
485 SolarMutexGuard aSolarGuard
;
486 std::unique_lock
aGuard( maMutex
);
488 return mpMenu
&& mpMenu
->IsItemChecked( nItemId
);
491 sal_Int16
VCLXMenu::execute(
492 const css::uno::Reference
< css::awt::XWindowPeer
>& rxWindowPeer
,
493 const css::awt::Rectangle
& rPos
,
496 SolarMutexGuard aSolarGuard
;
499 std::unique_lock
aGuard( maMutex
);
500 if ( !mpMenu
|| !IsPopupMenu() )
503 PopupMenu
* pPopupMenu
= static_cast<PopupMenu
*>(pMenu
.get());
504 MenuFlags nMenuFlags
= pPopupMenu
->GetMenuFlags();
505 // #102790# context menus shall never show disabled entries
506 nMenuFlags
|= MenuFlags::HideDisabledEntries
;
507 pPopupMenu
->SetMenuFlags(nMenuFlags
);
508 // cannot call this with mutex locked because it will call back into us
509 return pPopupMenu
->Execute(
510 VCLUnoHelper::GetWindow(rxWindowPeer
), vcl::unohelper::ConvertToVCLRect(rPos
),
511 static_cast<PopupMenuFlags
>(nFlags
) | PopupMenuFlags::NoMouseUpClose
);
515 void SAL_CALL
VCLXMenu::setCommand(
517 const OUString
& aCommand
)
519 SolarMutexGuard aSolarGuard
;
520 std::unique_lock
aGuard( maMutex
);
523 mpMenu
->SetItemCommand( nItemId
, aCommand
);
526 OUString SAL_CALL
VCLXMenu::getCommand(
529 SolarMutexGuard aSolarGuard
;
530 std::unique_lock
aGuard( maMutex
);
532 OUString aItemCommand
;
534 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
538 void SAL_CALL
VCLXMenu::setHelpCommand(
540 const OUString
& aHelp
)
542 SolarMutexGuard aSolarGuard
;
543 std::unique_lock
aGuard( maMutex
);
546 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
549 OUString SAL_CALL
VCLXMenu::getHelpCommand(
552 SolarMutexGuard aSolarGuard
;
553 std::unique_lock
aGuard( maMutex
);
555 OUString aHelpCommand
;
557 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
564 Image
lcl_XGraphic2VCLImage(
565 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
569 if ( !xGraphic
.is() )
572 aImage
= Image( xGraphic
);
573 const ::Size aCurSize
= aImage
.GetSizePixel();
574 const sal_Int32 nCurWidth
= aCurSize
.Width();
575 const sal_Int32 nCurHeight
= aCurSize
.Height();
576 constexpr sal_Int32
nIdeal( 16 );
578 if ( nCurWidth
> 0 && nCurHeight
> 0 )
580 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
582 sal_Int32 nIdealWidth
= std::min(nCurWidth
, nIdeal
);
583 sal_Int32 nIdealHeight
= std::min(nCurHeight
, nIdeal
);
585 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
587 bool bModified( false );
588 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
589 bModified
= aBitmapEx
.Scale( aNewSize
, BmpScaleFlag::BestQuality
);
592 aImage
= Image( aBitmapEx
);
598 /** Copied from include/svtools/acceleratorexecute.hxx */
599 css::awt::KeyEvent
lcl_VCLKey2AWTKey(
600 const vcl::KeyCode
& aVCLKey
)
602 css::awt::KeyEvent aAWTKey
;
603 aAWTKey
.Modifiers
= 0;
604 aAWTKey
.KeyCode
= static_cast<sal_Int16
>(aVCLKey
.GetCode());
606 if (aVCLKey
.IsShift())
607 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
608 if (aVCLKey
.IsMod1())
609 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
610 if (aVCLKey
.IsMod2())
611 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
612 if (aVCLKey
.IsMod3())
613 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
618 vcl::KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
620 bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
621 bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
622 bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
623 bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
624 sal_uInt16 nKey
= static_cast<sal_uInt16
>(aAWTKey
.KeyCode
);
626 return vcl::KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
632 sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( )
634 SolarMutexGuard aSolarGuard
;
635 std::unique_lock
aGuard( maMutex
);
636 return IsPopupMenu();
639 void SAL_CALL
VCLXMenu::clear( )
641 SolarMutexGuard aSolarGuard
;
642 std::unique_lock
aGuard( maMutex
);
648 css::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType(
649 ::sal_Int16 nItemPos
)
651 SolarMutexGuard aSolarGuard
;
652 std::unique_lock
aGuard( maMutex
);
654 css::awt::MenuItemType aMenuItemType
=
655 css::awt::MenuItemType_DONTKNOW
;
658 aMenuItemType
= static_cast<css::awt::MenuItemType
>(mpMenu
->GetItemType( nItemPos
));
661 return aMenuItemType
;
664 void SAL_CALL
VCLXMenu::hideDisabledEntries(
667 SolarMutexGuard aSolarGuard
;
668 std::unique_lock
aGuard( maMutex
);
672 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::HideDisabledEntries
);
674 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::HideDisabledEntries
);
679 sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
681 SolarMutexGuard aSolarGuard
;
682 std::unique_lock
aGuard( maMutex
);
684 if ( mpMenu
&& IsPopupMenu() )
685 return vcl::IsInPopupMenuExecute();
691 void SAL_CALL
VCLXMenu::endExecute()
693 SolarMutexGuard aSolarGuard
;
694 std::unique_lock
aGuard( maMutex
);
696 if ( mpMenu
&& IsPopupMenu() )
697 static_cast<PopupMenu
*>( mpMenu
.get() )->EndExecute();
701 void SAL_CALL
VCLXMenu::enableAutoMnemonics(
704 SolarMutexGuard aSolarGuard
;
705 std::unique_lock
aGuard( maMutex
);
709 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
711 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics
);
716 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent(
718 const css::awt::KeyEvent
& aKeyEvent
)
720 SolarMutexGuard aSolarGuard
;
721 std::unique_lock
aGuard( maMutex
);
723 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
725 vcl::KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
726 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
731 css::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent(
732 ::sal_Int16 nItemId
)
734 SolarMutexGuard aSolarGuard
;
735 std::unique_lock
aGuard( maMutex
);
737 css::awt::KeyEvent aKeyEvent
;
738 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
740 vcl::KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
741 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
748 void SAL_CALL
VCLXMenu::setHelpText(
750 const OUString
& sHelpText
)
752 SolarMutexGuard aSolarGuard
;
753 std::unique_lock
aGuard( maMutex
);
755 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
757 mpMenu
->SetHelpText( nItemId
, sHelpText
);
762 OUString SAL_CALL
VCLXMenu::getHelpText(
763 ::sal_Int16 nItemId
)
765 SolarMutexGuard aSolarGuard
;
766 std::unique_lock
aGuard( maMutex
);
769 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
771 sHelpText
= mpMenu
->GetHelpText( nItemId
);
778 void SAL_CALL
VCLXMenu::setTipHelpText(
780 const OUString
& sTipHelpText
)
782 SolarMutexGuard aSolarGuard
;
783 std::unique_lock
aGuard( maMutex
);
785 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
787 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
792 OUString SAL_CALL
VCLXMenu::getTipHelpText(
793 ::sal_Int16 nItemId
)
795 SolarMutexGuard aSolarGuard
;
796 std::unique_lock
aGuard( maMutex
);
798 OUString sTipHelpText
;
799 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
801 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
807 void SAL_CALL
VCLXMenu::setItemImage(
809 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
812 SolarMutexGuard aSolarGuard
;
813 std::unique_lock
aGuard( maMutex
);
815 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
817 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
818 mpMenu
->SetItemImage( nItemId
, aImage
);
823 css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
824 VCLXMenu::getItemImage(
825 ::sal_Int16 nItemId
)
827 SolarMutexGuard aSolarGuard
;
828 std::unique_lock
aGuard( maMutex
);
830 css::uno::Reference
< css::graphic::XGraphic
> rxGraphic
;
832 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
834 Image aImage
= mpMenu
->GetItemImage( nItemId
);
836 rxGraphic
= Graphic(aImage
.GetBitmapEx()).GetXGraphic();
841 void VCLXMenu::setUserValue(sal_uInt16 nItemId
, void* nUserValue
, MenuUserDataReleaseFunction aFunc
)
843 SolarMutexGuard aSolarGuard
;
844 std::unique_lock
aGuard(maMutex
);
846 mpMenu
->SetUserValue(nItemId
, nUserValue
, aFunc
);
849 void* VCLXMenu::getUserValue(sal_uInt16 nItemId
)
851 SolarMutexGuard aSolarGuard
;
852 std::unique_lock
aGuard(maMutex
);
854 return mpMenu
->GetUserValue(nItemId
);
857 VCLXMenuBar::VCLXMenuBar()
859 ImplCreateMenu( false );
862 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( static_cast<Menu
*>(pMenuBar
) )
866 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
867 stardiv_Toolkit_VCLXMenuBar_get_implementation(
868 css::uno::XComponentContext
*,
869 css::uno::Sequence
<css::uno::Any
> const &)
871 return cppu::acquire(new VCLXMenuBar());
874 VCLXPopupMenu::VCLXPopupMenu()
876 ImplCreateMenu( true );
879 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( static_cast<Menu
*>(pPopMenu
) )
884 VCLXPopupMenu::~VCLXPopupMenu() = default;
886 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
887 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
888 css::uno::XComponentContext
*,
889 css::uno::Sequence
<css::uno::Any
> const &)
891 return cppu::acquire(new VCLXPopupMenu());
894 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */