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/convert.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <cppuhelper/queryinterface.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <tools/debug.hxx>
29 #include <vcl/dialoghelper.hxx>
30 #include <vcl/graph.hxx>
31 #include <vcl/menu.hxx>
32 #include <vcl/keycod.hxx>
33 #include <vcl/image.hxx>
34 #include <vcl/svapp.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( "stardiv.Toolkit." );
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 "com.sun.star.awt.PopupMenu",
192 "stardiv.vcl.PopupMenu"};
194 return css::uno::Sequence
<OUString
>{
195 "com.sun.star.awt.MenuBar",
196 "stardiv.vcl.MenuBar"};
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
),
511 VCLRectangle( rPos
),
512 static_cast<PopupMenuFlags
>(nFlags
) | PopupMenuFlags::NoMouseUpClose
);
516 void SAL_CALL
VCLXMenu::setCommand(
518 const OUString
& aCommand
)
520 SolarMutexGuard aSolarGuard
;
521 std::unique_lock
aGuard( maMutex
);
524 mpMenu
->SetItemCommand( nItemId
, aCommand
);
527 OUString SAL_CALL
VCLXMenu::getCommand(
530 SolarMutexGuard aSolarGuard
;
531 std::unique_lock
aGuard( maMutex
);
533 OUString aItemCommand
;
535 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
539 void SAL_CALL
VCLXMenu::setHelpCommand(
541 const OUString
& aHelp
)
543 SolarMutexGuard aSolarGuard
;
544 std::unique_lock
aGuard( maMutex
);
547 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
550 OUString SAL_CALL
VCLXMenu::getHelpCommand(
553 SolarMutexGuard aSolarGuard
;
554 std::unique_lock
aGuard( maMutex
);
556 OUString aHelpCommand
;
558 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
565 Image
lcl_XGraphic2VCLImage(
566 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
570 if ( !xGraphic
.is() )
573 aImage
= Image( xGraphic
);
574 const ::Size aCurSize
= aImage
.GetSizePixel();
575 const sal_Int32 nCurWidth
= aCurSize
.Width();
576 const sal_Int32 nCurHeight
= aCurSize
.Height();
577 constexpr sal_Int32
nIdeal( 16 );
579 if ( nCurWidth
> 0 && nCurHeight
> 0 )
581 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
583 sal_Int32 nIdealWidth
= std::min(nCurWidth
, nIdeal
);
584 sal_Int32 nIdealHeight
= std::min(nCurHeight
, nIdeal
);
586 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
588 bool bModified( false );
589 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
590 bModified
= aBitmapEx
.Scale( aNewSize
, BmpScaleFlag::BestQuality
);
593 aImage
= Image( aBitmapEx
);
599 /** Copied from include/svtools/acceleratorexecute.hxx */
600 css::awt::KeyEvent
lcl_VCLKey2AWTKey(
601 const vcl::KeyCode
& aVCLKey
)
603 css::awt::KeyEvent aAWTKey
;
604 aAWTKey
.Modifiers
= 0;
605 aAWTKey
.KeyCode
= static_cast<sal_Int16
>(aVCLKey
.GetCode());
607 if (aVCLKey
.IsShift())
608 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
609 if (aVCLKey
.IsMod1())
610 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
611 if (aVCLKey
.IsMod2())
612 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
613 if (aVCLKey
.IsMod3())
614 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
619 vcl::KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
621 bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
622 bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
623 bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
624 bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
625 sal_uInt16 nKey
= static_cast<sal_uInt16
>(aAWTKey
.KeyCode
);
627 return vcl::KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
633 sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( )
635 SolarMutexGuard aSolarGuard
;
636 std::unique_lock
aGuard( maMutex
);
637 return IsPopupMenu();
640 void SAL_CALL
VCLXMenu::clear( )
642 SolarMutexGuard aSolarGuard
;
643 std::unique_lock
aGuard( maMutex
);
649 css::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType(
650 ::sal_Int16 nItemPos
)
652 SolarMutexGuard aSolarGuard
;
653 std::unique_lock
aGuard( maMutex
);
655 css::awt::MenuItemType aMenuItemType
=
656 css::awt::MenuItemType_DONTKNOW
;
659 aMenuItemType
= static_cast<css::awt::MenuItemType
>(mpMenu
->GetItemType( nItemPos
));
662 return aMenuItemType
;
665 void SAL_CALL
VCLXMenu::hideDisabledEntries(
668 SolarMutexGuard aSolarGuard
;
669 std::unique_lock
aGuard( maMutex
);
673 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::HideDisabledEntries
);
675 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::HideDisabledEntries
);
680 sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
682 SolarMutexGuard aSolarGuard
;
683 std::unique_lock
aGuard( maMutex
);
685 if ( mpMenu
&& IsPopupMenu() )
686 return vcl::IsInPopupMenuExecute();
692 void SAL_CALL
VCLXMenu::endExecute()
694 SolarMutexGuard aSolarGuard
;
695 std::unique_lock
aGuard( maMutex
);
697 if ( mpMenu
&& IsPopupMenu() )
698 static_cast<PopupMenu
*>( mpMenu
.get() )->EndExecute();
702 void SAL_CALL
VCLXMenu::enableAutoMnemonics(
705 SolarMutexGuard aSolarGuard
;
706 std::unique_lock
aGuard( maMutex
);
710 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
712 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics
);
717 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent(
719 const css::awt::KeyEvent
& aKeyEvent
)
721 SolarMutexGuard aSolarGuard
;
722 std::unique_lock
aGuard( maMutex
);
724 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
726 vcl::KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
727 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
732 css::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent(
733 ::sal_Int16 nItemId
)
735 SolarMutexGuard aSolarGuard
;
736 std::unique_lock
aGuard( maMutex
);
738 css::awt::KeyEvent aKeyEvent
;
739 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
741 vcl::KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
742 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
749 void SAL_CALL
VCLXMenu::setHelpText(
751 const OUString
& sHelpText
)
753 SolarMutexGuard aSolarGuard
;
754 std::unique_lock
aGuard( maMutex
);
756 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
758 mpMenu
->SetHelpText( nItemId
, sHelpText
);
763 OUString SAL_CALL
VCLXMenu::getHelpText(
764 ::sal_Int16 nItemId
)
766 SolarMutexGuard aSolarGuard
;
767 std::unique_lock
aGuard( maMutex
);
770 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
772 sHelpText
= mpMenu
->GetHelpText( nItemId
);
779 void SAL_CALL
VCLXMenu::setTipHelpText(
781 const OUString
& sTipHelpText
)
783 SolarMutexGuard aSolarGuard
;
784 std::unique_lock
aGuard( maMutex
);
786 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
788 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
793 OUString SAL_CALL
VCLXMenu::getTipHelpText(
794 ::sal_Int16 nItemId
)
796 SolarMutexGuard aSolarGuard
;
797 std::unique_lock
aGuard( maMutex
);
799 OUString sTipHelpText
;
800 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
802 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
808 void SAL_CALL
VCLXMenu::setItemImage(
810 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
813 SolarMutexGuard aSolarGuard
;
814 std::unique_lock
aGuard( maMutex
);
816 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
818 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
819 mpMenu
->SetItemImage( nItemId
, aImage
);
824 css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
825 VCLXMenu::getItemImage(
826 ::sal_Int16 nItemId
)
828 SolarMutexGuard aSolarGuard
;
829 std::unique_lock
aGuard( maMutex
);
831 css::uno::Reference
< css::graphic::XGraphic
> rxGraphic
;
833 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
835 Image aImage
= mpMenu
->GetItemImage( nItemId
);
837 rxGraphic
= Graphic(aImage
.GetBitmapEx()).GetXGraphic();
842 void VCLXMenu::setUserValue(sal_uInt16 nItemId
, void* nUserValue
, MenuUserDataReleaseFunction aFunc
)
844 SolarMutexGuard aSolarGuard
;
845 std::unique_lock
aGuard(maMutex
);
847 mpMenu
->SetUserValue(nItemId
, nUserValue
, aFunc
);
850 void* VCLXMenu::getUserValue(sal_uInt16 nItemId
)
852 SolarMutexGuard aSolarGuard
;
853 std::unique_lock
aGuard(maMutex
);
855 return mpMenu
->GetUserValue(nItemId
);
858 VCLXMenuBar::VCLXMenuBar()
860 ImplCreateMenu( false );
863 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( static_cast<Menu
*>(pMenuBar
) )
867 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
868 stardiv_Toolkit_VCLXMenuBar_get_implementation(
869 css::uno::XComponentContext
*,
870 css::uno::Sequence
<css::uno::Any
> const &)
872 return cppu::acquire(new VCLXMenuBar());
875 VCLXPopupMenu::VCLXPopupMenu()
877 ImplCreateMenu( true );
880 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( static_cast<Menu
*>(pPopMenu
) )
885 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
886 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
887 css::uno::XComponentContext
*,
888 css::uno::Sequence
<css::uno::Any
> const &)
890 return cppu::acquire(new VCLXPopupMenu());
893 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */