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
= static_cast<cppu::OWeakObject
*>(this);
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
= static_cast<cppu::OWeakObject
*>(this);
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
= static_cast<cppu::OWeakObject
*>(this);
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
= static_cast<cppu::OWeakObject
*>(this);
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::MenuItemTextChanged
:
156 case VclEventId::MenuItemChecked
:
157 case VclEventId::MenuItemUnchecked
:
158 case VclEventId::MenuShow
:
159 case VclEventId::MenuHide
:
162 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
167 OUString SAL_CALL
VCLXMenu::getImplementationName( )
169 std::unique_lock
aGuard( maMutex
);
170 const bool bIsPopupMenu
= IsPopupMenu();
173 OUString
implName( "stardiv.Toolkit." );
175 implName
+= "VCLXPopupMenu";
177 implName
+= "VCLXMenuBar";
182 css::uno::Sequence
< OUString
> SAL_CALL
VCLXMenu::getSupportedServiceNames( )
184 std::unique_lock
aGuard( maMutex
);
185 const bool bIsPopupMenu
= IsPopupMenu();
189 return css::uno::Sequence
<OUString
>{
190 "com.sun.star.awt.PopupMenu",
191 "stardiv.vcl.PopupMenu"};
193 return css::uno::Sequence
<OUString
>{
194 "com.sun.star.awt.MenuBar",
195 "stardiv.vcl.MenuBar"};
198 sal_Bool SAL_CALL
VCLXMenu::supportsService(const OUString
& rServiceName
)
200 return cppu::supportsService(this, rServiceName
);
203 css::uno::Any
VCLXMenu::queryInterface(
204 const css::uno::Type
& rType
)
206 std::unique_lock
aGuard( maMutex
);
207 const bool bIsPopupMenu
= IsPopupMenu();
213 aRet
= ::cppu::queryInterface( rType
,
214 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
215 static_cast< css::awt::XPopupMenu
* >(this),
216 static_cast< css::lang::XTypeProvider
* >(this),
217 static_cast< css::lang::XServiceInfo
* >(this) );
219 aRet
= ::cppu::queryInterface( rType
,
220 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
221 static_cast< css::awt::XMenuBar
* >(this),
222 static_cast< css::lang::XTypeProvider
* >(this),
223 static_cast< css::lang::XServiceInfo
* >(this) );
225 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
229 css::uno::Sequence
< css::uno::Type
> VCLXMenu::getTypes()
231 std::unique_lock
aGuard( maMutex
);
232 const bool bIsPopupMenu
= IsPopupMenu();
237 static cppu::OTypeCollection
collectionPopupMenu(
238 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
239 cppu::UnoType
<css::awt::XPopupMenu
>::get(),
240 cppu::UnoType
<css::lang::XServiceInfo
>::get());
241 return collectionPopupMenu
.getTypes();
245 static cppu::OTypeCollection
collectionMenuBar(
246 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
247 cppu::UnoType
<css::awt::XMenuBar
>::get(),
248 cppu::UnoType
<css::lang::XServiceInfo
>::get());
249 return collectionMenuBar
.getTypes();
254 css::uno::Sequence
< sal_Int8
> VCLXMenu::getImplementationId()
256 return css::uno::Sequence
<sal_Int8
>();
259 void VCLXMenu::addMenuListener(
260 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
262 std::unique_lock
aGuard( maMutex
);
264 maMenuListeners
.addInterface( rxListener
);
267 void VCLXMenu::removeMenuListener(
268 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
270 std::unique_lock
aGuard( maMutex
);
272 maMenuListeners
.removeInterface( rxListener
);
275 void VCLXMenu::insertItem(
277 const OUString
& aText
,
278 sal_Int16 nItemStyle
,
281 SolarMutexGuard aSolarGuard
;
282 std::unique_lock
aGuard( maMutex
);
285 mpMenu
->InsertItem(nItemId
, aText
, static_cast<MenuItemBits
>(nItemStyle
), {}, nPos
);
288 void VCLXMenu::removeItem(
292 SolarMutexGuard aSolarGuard
;
293 std::unique_lock
aGuard( maMutex
);
298 sal_Int32 nItemCount
= static_cast<sal_Int32
>(mpMenu
->GetItemCount());
299 if ((nCount
> 0) && (nPos
>= 0) && (nPos
< nItemCount
))
301 sal_Int16 nP
= sal::static_int_cast
< sal_Int16
>(
302 std::min( static_cast<int>(nPos
+nCount
), static_cast<int>(nItemCount
) ));
304 mpMenu
->RemoveItem( --nP
);
308 sal_Int16
VCLXMenu::getItemCount( )
310 SolarMutexGuard aSolarGuard
;
311 std::unique_lock
aGuard( maMutex
);
313 return mpMenu
? mpMenu
->GetItemCount() : 0;
316 sal_Int16
VCLXMenu::getItemId(
319 SolarMutexGuard aSolarGuard
;
320 std::unique_lock
aGuard( maMutex
);
322 return mpMenu
? mpMenu
->GetItemId( nPos
) : 0;
325 sal_Int16
VCLXMenu::getItemPos(
328 SolarMutexGuard aSolarGuard
;
329 std::unique_lock
aGuard( maMutex
);
331 return mpMenu
? mpMenu
->GetItemPos( nId
) : 0;
334 void VCLXMenu::enableItem(
338 SolarMutexGuard aSolarGuard
;
339 std::unique_lock
aGuard( maMutex
);
342 mpMenu
->EnableItem( nItemId
, bEnable
);
345 sal_Bool
VCLXMenu::isItemEnabled(
348 SolarMutexGuard aSolarGuard
;
349 std::unique_lock
aGuard( maMutex
);
351 return mpMenu
&& mpMenu
->IsItemEnabled( nItemId
);
354 void VCLXMenu::setItemText(
356 const OUString
& aText
)
358 SolarMutexGuard aSolarGuard
;
359 std::unique_lock
aGuard( maMutex
);
362 mpMenu
->SetItemText( nItemId
, aText
);
365 OUString
VCLXMenu::getItemText(
368 SolarMutexGuard aSolarGuard
;
369 std::unique_lock
aGuard( maMutex
);
373 aItemText
= mpMenu
->GetItemText( nItemId
);
377 void VCLXMenu::setPopupMenu(
379 const css::uno::Reference
< css::awt::XPopupMenu
>& rxPopupMenu
)
381 SolarMutexGuard aSolarGuard
;
382 std::unique_lock
aGuard( maMutex
);
384 VCLXMenu
* pVCLMenu
= dynamic_cast<VCLXMenu
*>( rxPopupMenu
.get() );
385 DBG_ASSERT( pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
387 if ( mpMenu
&& pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu() )
389 maPopupMenuRefs
.push_back( rxPopupMenu
);
391 mpMenu
->SetPopupMenu( nItemId
, static_cast<PopupMenu
*>( pVCLMenu
->GetMenu() ) );
395 css::uno::Reference
< css::awt::XPopupMenu
> VCLXMenu::getPopupMenu(
398 SolarMutexGuard aSolarGuard
;
399 std::unique_lock
aGuard( maMutex
);
401 css::uno::Reference
< css::awt::XPopupMenu
> aRef
;
402 Menu
* pMenu
= mpMenu
? mpMenu
->GetPopupMenu( nItemId
) : nullptr;
405 for ( size_t n
= maPopupMenuRefs
.size(); n
; )
407 css::uno::Reference
< css::awt::XPopupMenu
>& rRef
= maPopupMenuRefs
[ --n
];
408 Menu
* pM
= static_cast<VCLXMenu
*>(rRef
.get())->GetMenu();
415 // it seems the popup menu is not insert into maPopupMenuRefs
416 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
419 aRef
= new VCLXPopupMenu( static_cast<PopupMenu
*>(pMenu
) );
425 // css::awt::XPopupMenu
426 void VCLXMenu::insertSeparator(
429 SolarMutexGuard aSolarGuard
;
430 std::unique_lock
aGuard( maMutex
);
433 mpMenu
->InsertSeparator({}, nPos
);
436 void VCLXMenu::setDefaultItem(
439 std::unique_lock
aGuard( maMutex
);
441 mnDefaultItem
= nItemId
;
444 sal_Int16
VCLXMenu::getDefaultItem( )
446 std::unique_lock
aGuard( maMutex
);
448 return mnDefaultItem
;
451 void VCLXMenu::checkItem(
455 SolarMutexGuard aSolarGuard
;
456 std::unique_lock
aGuard( maMutex
);
459 mpMenu
->CheckItem( nItemId
, bCheck
);
462 sal_Bool
VCLXMenu::isItemChecked(
465 SolarMutexGuard aSolarGuard
;
466 std::unique_lock
aGuard( maMutex
);
468 return mpMenu
&& mpMenu
->IsItemChecked( nItemId
);
471 sal_Int16
VCLXMenu::execute(
472 const css::uno::Reference
< css::awt::XWindowPeer
>& rxWindowPeer
,
473 const css::awt::Rectangle
& rPos
,
476 SolarMutexGuard aSolarGuard
;
479 std::unique_lock
aGuard( maMutex
);
480 if ( !mpMenu
|| !IsPopupMenu() )
483 // cannot call this with mutex locked because it will call back into us
484 return static_cast<PopupMenu
*>(pMenu
.get())->Execute(
485 VCLUnoHelper::GetWindow( rxWindowPeer
),
486 VCLRectangle( rPos
),
487 static_cast<PopupMenuFlags
>(nFlags
) | PopupMenuFlags::NoMouseUpClose
);
491 void SAL_CALL
VCLXMenu::setCommand(
493 const OUString
& aCommand
)
495 SolarMutexGuard aSolarGuard
;
496 std::unique_lock
aGuard( maMutex
);
499 mpMenu
->SetItemCommand( nItemId
, aCommand
);
502 OUString SAL_CALL
VCLXMenu::getCommand(
505 SolarMutexGuard aSolarGuard
;
506 std::unique_lock
aGuard( maMutex
);
508 OUString aItemCommand
;
510 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
514 void SAL_CALL
VCLXMenu::setHelpCommand(
516 const OUString
& aHelp
)
518 SolarMutexGuard aSolarGuard
;
519 std::unique_lock
aGuard( maMutex
);
522 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
525 OUString SAL_CALL
VCLXMenu::getHelpCommand(
528 SolarMutexGuard aSolarGuard
;
529 std::unique_lock
aGuard( maMutex
);
531 OUString aHelpCommand
;
533 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
540 Image
lcl_XGraphic2VCLImage(
541 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
545 if ( !xGraphic
.is() )
548 aImage
= Image( xGraphic
);
549 const ::Size aCurSize
= aImage
.GetSizePixel();
550 const sal_Int32 nCurWidth
= aCurSize
.Width();
551 const sal_Int32 nCurHeight
= aCurSize
.Height();
552 constexpr sal_Int32
nIdeal( 16 );
554 if ( nCurWidth
> 0 && nCurHeight
> 0 )
556 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
558 sal_Int32 nIdealWidth
= std::min(nCurWidth
, nIdeal
);
559 sal_Int32 nIdealHeight
= std::min(nCurHeight
, nIdeal
);
561 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
563 bool bModified( false );
564 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
565 bModified
= aBitmapEx
.Scale( aNewSize
, BmpScaleFlag::BestQuality
);
568 aImage
= Image( aBitmapEx
);
574 /** Copied from include/svtools/acceleratorexecute.hxx */
575 css::awt::KeyEvent
lcl_VCLKey2AWTKey(
576 const vcl::KeyCode
& aVCLKey
)
578 css::awt::KeyEvent aAWTKey
;
579 aAWTKey
.Modifiers
= 0;
580 aAWTKey
.KeyCode
= static_cast<sal_Int16
>(aVCLKey
.GetCode());
582 if (aVCLKey
.IsShift())
583 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
584 if (aVCLKey
.IsMod1())
585 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
586 if (aVCLKey
.IsMod2())
587 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
588 if (aVCLKey
.IsMod3())
589 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
594 vcl::KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
596 bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
597 bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
598 bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
599 bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
600 sal_uInt16 nKey
= static_cast<sal_uInt16
>(aAWTKey
.KeyCode
);
602 return vcl::KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
608 sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( )
610 SolarMutexGuard aSolarGuard
;
611 std::unique_lock
aGuard( maMutex
);
612 return IsPopupMenu();
615 void SAL_CALL
VCLXMenu::clear( )
617 SolarMutexGuard aSolarGuard
;
618 std::unique_lock
aGuard( maMutex
);
624 css::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType(
625 ::sal_Int16 nItemPos
)
627 SolarMutexGuard aSolarGuard
;
628 std::unique_lock
aGuard( maMutex
);
630 css::awt::MenuItemType aMenuItemType
=
631 css::awt::MenuItemType_DONTKNOW
;
634 aMenuItemType
= static_cast<css::awt::MenuItemType
>(mpMenu
->GetItemType( nItemPos
));
637 return aMenuItemType
;
640 void SAL_CALL
VCLXMenu::hideDisabledEntries(
643 SolarMutexGuard aSolarGuard
;
644 std::unique_lock
aGuard( maMutex
);
648 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::HideDisabledEntries
);
650 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::HideDisabledEntries
);
655 sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
657 SolarMutexGuard aSolarGuard
;
658 std::unique_lock
aGuard( maMutex
);
660 if ( mpMenu
&& IsPopupMenu() )
661 return vcl::IsInPopupMenuExecute();
667 void SAL_CALL
VCLXMenu::endExecute()
669 SolarMutexGuard aSolarGuard
;
670 std::unique_lock
aGuard( maMutex
);
672 if ( mpMenu
&& IsPopupMenu() )
673 static_cast<PopupMenu
*>( mpMenu
.get() )->EndExecute();
677 void SAL_CALL
VCLXMenu::enableAutoMnemonics(
680 SolarMutexGuard aSolarGuard
;
681 std::unique_lock
aGuard( maMutex
);
685 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
687 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics
);
692 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent(
694 const css::awt::KeyEvent
& aKeyEvent
)
696 SolarMutexGuard aSolarGuard
;
697 std::unique_lock
aGuard( maMutex
);
699 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
701 vcl::KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
702 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
707 css::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent(
708 ::sal_Int16 nItemId
)
710 SolarMutexGuard aSolarGuard
;
711 std::unique_lock
aGuard( maMutex
);
713 css::awt::KeyEvent aKeyEvent
;
714 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
716 vcl::KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
717 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
724 void SAL_CALL
VCLXMenu::setHelpText(
726 const OUString
& sHelpText
)
728 SolarMutexGuard aSolarGuard
;
729 std::unique_lock
aGuard( maMutex
);
731 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
733 mpMenu
->SetHelpText( nItemId
, sHelpText
);
738 OUString SAL_CALL
VCLXMenu::getHelpText(
739 ::sal_Int16 nItemId
)
741 SolarMutexGuard aSolarGuard
;
742 std::unique_lock
aGuard( maMutex
);
745 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
747 sHelpText
= mpMenu
->GetHelpText( nItemId
);
754 void SAL_CALL
VCLXMenu::setTipHelpText(
756 const OUString
& sTipHelpText
)
758 SolarMutexGuard aSolarGuard
;
759 std::unique_lock
aGuard( maMutex
);
761 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
763 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
768 OUString SAL_CALL
VCLXMenu::getTipHelpText(
769 ::sal_Int16 nItemId
)
771 SolarMutexGuard aSolarGuard
;
772 std::unique_lock
aGuard( maMutex
);
774 OUString sTipHelpText
;
775 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
777 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
783 void SAL_CALL
VCLXMenu::setItemImage(
785 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
788 SolarMutexGuard aSolarGuard
;
789 std::unique_lock
aGuard( maMutex
);
791 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
793 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
794 mpMenu
->SetItemImage( nItemId
, aImage
);
799 css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
800 VCLXMenu::getItemImage(
801 ::sal_Int16 nItemId
)
803 SolarMutexGuard aSolarGuard
;
804 std::unique_lock
aGuard( maMutex
);
806 css::uno::Reference
< css::graphic::XGraphic
> rxGraphic
;
808 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
810 Image aImage
= mpMenu
->GetItemImage( nItemId
);
812 rxGraphic
= Graphic(aImage
.GetBitmapEx()).GetXGraphic();
817 void VCLXMenu::setUserValue(sal_uInt16 nItemId
, void* nUserValue
, MenuUserDataReleaseFunction aFunc
)
819 SolarMutexGuard aSolarGuard
;
820 std::unique_lock
aGuard(maMutex
);
822 mpMenu
->SetUserValue(nItemId
, nUserValue
, aFunc
);
825 void* VCLXMenu::getUserValue(sal_uInt16 nItemId
)
827 SolarMutexGuard aSolarGuard
;
828 std::unique_lock
aGuard(maMutex
);
830 return mpMenu
->GetUserValue(nItemId
);
833 VCLXMenuBar::VCLXMenuBar()
835 ImplCreateMenu( false );
838 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( static_cast<Menu
*>(pMenuBar
) )
842 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
843 stardiv_Toolkit_VCLXMenuBar_get_implementation(
844 css::uno::XComponentContext
*,
845 css::uno::Sequence
<css::uno::Any
> const &)
847 return cppu::acquire(new VCLXMenuBar());
850 VCLXPopupMenu::VCLXPopupMenu()
852 ImplCreateMenu( true );
855 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( static_cast<Menu
*>(pPopMenu
) )
860 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
861 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
862 css::uno::XComponentContext
*,
863 css::uno::Sequence
<css::uno::Any
> const &)
865 return cppu::acquire(new VCLXPopupMenu());
868 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */