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/macros.hxx>
23 #include <toolkit/helper/servicenames.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/queryinterface.hxx>
29 #include <cppuhelper/typeprovider.hxx>
31 #include <osl/mutex.hxx>
32 #include <tools/debug.hxx>
33 #include <vcl/graph.hxx>
34 #include <vcl/menu.hxx>
35 #include <vcl/keycod.hxx>
36 #include <vcl/image.hxx>
37 #include <vcl/mnemonic.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/window.hxx>
41 #include <com/sun/star/awt/KeyModifier.hpp>
44 : maMenuListeners( *this )
50 VCLXMenu::VCLXMenu( Menu
* pMenu
)
51 : maMenuListeners( *this )
59 maPopupMenuRefs
.clear();
62 mpMenu
->RemoveEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
63 mpMenu
.disposeAndClear();
67 bool VCLXMenu::IsPopupMenu() const
69 return (mpMenu
&& ! mpMenu
->IsMenuBar());
72 void VCLXMenu::ImplCreateMenu( bool bPopup
)
74 DBG_ASSERT( !mpMenu
, "CreateMenu: Menu exists!" );
77 mpMenu
= VclPtr
<PopupMenu
>::Create();
79 mpMenu
= VclPtr
<MenuBar
>::Create();
81 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
84 void VCLXMenu::ImplAddListener()
87 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
90 IMPL_LINK( VCLXMenu
, MenuEventListener
, VclMenuEvent
&, rMenuEvent
, void )
92 DBG_ASSERT( rMenuEvent
.GetMenu() && mpMenu
, "Menu???" );
94 if ( rMenuEvent
.GetMenu() == mpMenu
) // Also called for the root menu
96 switch ( rMenuEvent
.GetId() )
98 case VclEventId::MenuSelect
:
100 if ( maMenuListeners
.getLength() )
102 css::awt::MenuEvent aEvent
;
103 aEvent
.Source
= static_cast<cppu::OWeakObject
*>(this);
104 aEvent
.MenuId
= mpMenu
->GetCurItemId();
105 maMenuListeners
.itemSelected( aEvent
);
109 case VclEventId::ObjectDying
:
114 case VclEventId::MenuHighlight
:
116 if ( maMenuListeners
.getLength() )
118 css::awt::MenuEvent aEvent
;
119 aEvent
.Source
= static_cast<cppu::OWeakObject
*>(this);
120 aEvent
.MenuId
= mpMenu
->GetCurItemId();
121 maMenuListeners
.itemHighlighted( aEvent
);
125 case VclEventId::MenuActivate
:
127 if ( maMenuListeners
.getLength() )
129 css::awt::MenuEvent aEvent
;
130 aEvent
.Source
= static_cast<cppu::OWeakObject
*>(this);
131 aEvent
.MenuId
= mpMenu
->GetCurItemId();
132 maMenuListeners
.itemActivated( aEvent
);
136 case VclEventId::MenuDeactivate
:
138 if ( maMenuListeners
.getLength() )
140 css::awt::MenuEvent aEvent
;
141 aEvent
.Source
= static_cast<cppu::OWeakObject
*>(this);
142 aEvent
.MenuId
= mpMenu
->GetCurItemId();
143 maMenuListeners
.itemDeactivated( aEvent
);
148 // ignore accessibility events
149 case VclEventId::MenuEnable
:
150 case VclEventId::MenuInsertItem
:
151 case VclEventId::MenuRemoveItem
:
152 case VclEventId::MenuSubmenuActivate
:
153 case VclEventId::MenuSubmenuDeactivate
:
154 case VclEventId::MenuSubmenuChanged
:
155 case VclEventId::MenuDehighlight
:
156 case VclEventId::MenuDisable
:
157 case VclEventId::MenuItemTextChanged
:
158 case VclEventId::MenuItemChecked
:
159 case VclEventId::MenuItemUnchecked
:
160 case VclEventId::MenuShow
:
161 case VclEventId::MenuHide
:
164 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
170 OUString SAL_CALL
VCLXMenu::getImplementationName( )
172 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
173 const bool bIsPopupMenu
= IsPopupMenu();
176 OUString
implName( "stardiv.Toolkit." );
178 implName
+= "VCLXPopupMenu";
180 implName
+= "VCLXMenuBar";
185 css::uno::Sequence
< OUString
> SAL_CALL
VCLXMenu::getSupportedServiceNames( )
187 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
188 const bool bIsPopupMenu
= IsPopupMenu();
192 return css::uno::Sequence
<OUString
>{
193 OUString::createFromAscii(szServiceName2_PopupMenu
),
194 "stardiv.vcl.PopupMenu"};
196 return css::uno::Sequence
<OUString
>{
197 OUString::createFromAscii(szServiceName2_MenuBar
),
198 "stardiv.vcl.MenuBar"};
201 sal_Bool SAL_CALL
VCLXMenu::supportsService(const OUString
& rServiceName
)
203 return cppu::supportsService(this, rServiceName
);
206 css::uno::Any
VCLXMenu::queryInterface(
207 const css::uno::Type
& rType
)
209 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
210 const bool bIsPopupMenu
= IsPopupMenu();
216 aRet
= ::cppu::queryInterface( rType
,
217 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
218 static_cast< css::awt::XPopupMenu
* >(this),
219 static_cast< css::lang::XTypeProvider
* >(this),
220 static_cast< css::lang::XServiceInfo
* >(this),
221 static_cast< css::lang::XUnoTunnel
* >(this) );
223 aRet
= ::cppu::queryInterface( rType
,
224 static_cast< css::awt::XMenu
* >(static_cast<css::awt::XMenuBar
*>(this)),
225 static_cast< css::awt::XMenuBar
* >(this),
226 static_cast< css::lang::XTypeProvider
* >(this),
227 static_cast< css::lang::XServiceInfo
* >(this),
228 static_cast< css::lang::XUnoTunnel
* >(this) );
230 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
234 IMPL_XUNOTUNNEL( VCLXMenu
)
236 css::uno::Sequence
< css::uno::Type
> VCLXMenu::getTypes()
238 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
239 const bool bIsPopupMenu
= IsPopupMenu();
244 static cppu::OTypeCollection
collectionPopupMenu(
245 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
246 cppu::UnoType
<css::awt::XPopupMenu
>::get(),
247 cppu::UnoType
<css::lang::XServiceInfo
>::get());
248 return collectionPopupMenu
.getTypes();
252 static cppu::OTypeCollection
collectionMenuBar(
253 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<css::awt::XMenu
>::get(),
254 cppu::UnoType
<css::awt::XMenuBar
>::get(),
255 cppu::UnoType
<css::lang::XServiceInfo
>::get());
256 return collectionMenuBar
.getTypes();
261 css::uno::Sequence
< sal_Int8
> VCLXMenu::getImplementationId()
263 return css::uno::Sequence
<sal_Int8
>();
266 void VCLXMenu::addMenuListener(
267 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
269 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
271 maMenuListeners
.addInterface( rxListener
);
274 void VCLXMenu::removeMenuListener(
275 const css::uno::Reference
< css::awt::XMenuListener
>& rxListener
)
277 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
279 maMenuListeners
.removeInterface( rxListener
);
282 void VCLXMenu::insertItem(
284 const OUString
& aText
,
285 sal_Int16 nItemStyle
,
288 SolarMutexGuard aSolarGuard
;
289 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
292 mpMenu
->InsertItem(nItemId
, aText
, static_cast<MenuItemBits
>(nItemStyle
), OString(), nPos
);
295 void VCLXMenu::removeItem(
299 SolarMutexGuard aSolarGuard
;
300 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
305 sal_Int32 nItemCount
= static_cast<sal_Int32
>(mpMenu
->GetItemCount());
306 if ((nCount
> 0) && (nPos
>= 0) && (nPos
< nItemCount
))
308 sal_Int16 nP
= sal::static_int_cast
< sal_Int16
>(
309 std::min( static_cast<int>(nPos
+nCount
), static_cast<int>(nItemCount
) ));
311 mpMenu
->RemoveItem( --nP
);
315 sal_Int16
VCLXMenu::getItemCount( )
317 SolarMutexGuard aSolarGuard
;
318 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
320 return mpMenu
? mpMenu
->GetItemCount() : 0;
323 sal_Int16
VCLXMenu::getItemId(
326 SolarMutexGuard aSolarGuard
;
327 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
329 return mpMenu
? mpMenu
->GetItemId( nPos
) : 0;
332 sal_Int16
VCLXMenu::getItemPos(
335 SolarMutexGuard aSolarGuard
;
336 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
338 return mpMenu
? mpMenu
->GetItemPos( nId
) : 0;
341 void VCLXMenu::enableItem(
345 SolarMutexGuard aSolarGuard
;
346 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
349 mpMenu
->EnableItem( nItemId
, bEnable
);
352 sal_Bool
VCLXMenu::isItemEnabled(
355 SolarMutexGuard aSolarGuard
;
356 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
358 return mpMenu
&& mpMenu
->IsItemEnabled( nItemId
);
361 void VCLXMenu::setItemText(
363 const OUString
& aText
)
365 SolarMutexGuard aSolarGuard
;
366 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
369 mpMenu
->SetItemText( nItemId
, aText
);
372 OUString
VCLXMenu::getItemText(
375 SolarMutexGuard aSolarGuard
;
376 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
380 aItemText
= mpMenu
->GetItemText( nItemId
);
384 void VCLXMenu::setPopupMenu(
386 const css::uno::Reference
< css::awt::XPopupMenu
>& rxPopupMenu
)
388 SolarMutexGuard aSolarGuard
;
389 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
391 VCLXMenu
* pVCLMenu
= VCLXMenu::GetImplementation( rxPopupMenu
);
392 DBG_ASSERT( pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
394 if ( mpMenu
&& pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu() )
396 maPopupMenuRefs
.push_back( rxPopupMenu
);
398 mpMenu
->SetPopupMenu( nItemId
, static_cast<PopupMenu
*>( pVCLMenu
->GetMenu() ) );
402 css::uno::Reference
< css::awt::XPopupMenu
> VCLXMenu::getPopupMenu(
405 SolarMutexGuard aSolarGuard
;
406 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
408 css::uno::Reference
< css::awt::XPopupMenu
> aRef
;
409 Menu
* pMenu
= mpMenu
? mpMenu
->GetPopupMenu( nItemId
) : nullptr;
412 for ( size_t n
= maPopupMenuRefs
.size(); n
; )
414 css::uno::Reference
< css::awt::XPopupMenu
>& rRef
= maPopupMenuRefs
[ --n
];
415 Menu
* pM
= static_cast<VCLXMenu
*>(rRef
.get())->GetMenu();
422 // it seems the popup menu is not insert into maPopupMenuRefs
423 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
426 aRef
= new VCLXPopupMenu( static_cast<PopupMenu
*>(pMenu
) );
432 // css::awt::XPopupMenu
433 void VCLXMenu::insertSeparator(
436 SolarMutexGuard aSolarGuard
;
437 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
440 mpMenu
->InsertSeparator(OString(), nPos
);
443 void VCLXMenu::setDefaultItem(
446 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
448 mnDefaultItem
= nItemId
;
451 sal_Int16
VCLXMenu::getDefaultItem( )
453 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
455 return mnDefaultItem
;
458 void VCLXMenu::checkItem(
462 SolarMutexGuard aSolarGuard
;
463 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
466 mpMenu
->CheckItem( nItemId
, bCheck
);
469 sal_Bool
VCLXMenu::isItemChecked(
472 SolarMutexGuard aSolarGuard
;
473 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
475 return mpMenu
&& mpMenu
->IsItemChecked( nItemId
);
478 sal_Int16
VCLXMenu::execute(
479 const css::uno::Reference
< css::awt::XWindowPeer
>& rxWindowPeer
,
480 const css::awt::Rectangle
& rPos
,
483 SolarMutexGuard aSolarGuard
;
484 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
487 if ( mpMenu
&& IsPopupMenu() )
489 nRet
= static_cast<PopupMenu
*>(mpMenu
.get())->Execute( VCLUnoHelper::GetWindow( rxWindowPeer
),
490 VCLRectangle( rPos
),
491 static_cast<PopupMenuFlags
>(nFlags
) | PopupMenuFlags::NoMouseUpClose
);
497 void SAL_CALL
VCLXMenu::setCommand(
499 const OUString
& aCommand
)
501 SolarMutexGuard aSolarGuard
;
502 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
505 mpMenu
->SetItemCommand( nItemId
, aCommand
);
508 OUString SAL_CALL
VCLXMenu::getCommand(
511 SolarMutexGuard aSolarGuard
;
512 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
514 OUString aItemCommand
;
516 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
520 void SAL_CALL
VCLXMenu::setHelpCommand(
522 const OUString
& aHelp
)
524 SolarMutexGuard aSolarGuard
;
525 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
528 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
531 OUString SAL_CALL
VCLXMenu::getHelpCommand(
534 SolarMutexGuard aSolarGuard
;
535 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
537 OUString aHelpCommand
;
539 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
546 Image
lcl_XGraphic2VCLImage(
547 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
551 if ( !xGraphic
.is() )
554 aImage
= Image( xGraphic
);
555 const ::Size aCurSize
= aImage
.GetSizePixel();
556 const sal_Int32 nCurWidth
= aCurSize
.Width();
557 const sal_Int32 nCurHeight
= aCurSize
.Height();
558 const sal_Int32
nIdeal( 16 );
560 if ( nCurWidth
> 0 && nCurHeight
> 0 )
562 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
564 sal_Int32 nIdealWidth
= std::min(nCurWidth
, nIdeal
);
565 sal_Int32 nIdealHeight
= std::min(nCurHeight
, nIdeal
);
567 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
569 bool bModified( false );
570 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
571 bModified
= aBitmapEx
.Scale( aNewSize
, BmpScaleFlag::BestQuality
);
574 aImage
= Image( aBitmapEx
);
580 /** Copied from svtools/inc/acceleratorexecute.hxx */
581 css::awt::KeyEvent
lcl_VCLKey2AWTKey(
582 const vcl::KeyCode
& aVCLKey
)
584 css::awt::KeyEvent aAWTKey
;
585 aAWTKey
.Modifiers
= 0;
586 aAWTKey
.KeyCode
= static_cast<sal_Int16
>(aVCLKey
.GetCode());
588 if (aVCLKey
.IsShift())
589 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
590 if (aVCLKey
.IsMod1())
591 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
592 if (aVCLKey
.IsMod2())
593 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
594 if (aVCLKey
.IsMod3())
595 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
600 vcl::KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
602 bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
603 bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
604 bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
605 bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
606 sal_uInt16 nKey
= static_cast<sal_uInt16
>(aAWTKey
.KeyCode
);
608 return vcl::KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
614 sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( )
616 SolarMutexGuard aSolarGuard
;
617 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
618 return IsPopupMenu();
621 void SAL_CALL
VCLXMenu::clear( )
623 SolarMutexGuard aSolarGuard
;
624 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
630 css::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType(
631 ::sal_Int16 nItemPos
)
633 SolarMutexGuard aSolarGuard
;
634 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
636 css::awt::MenuItemType aMenuItemType
=
637 css::awt::MenuItemType_DONTKNOW
;
640 aMenuItemType
= static_cast<css::awt::MenuItemType
>(mpMenu
->GetItemType( nItemPos
));
643 return aMenuItemType
;
646 void SAL_CALL
VCLXMenu::hideDisabledEntries(
649 SolarMutexGuard aSolarGuard
;
650 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
654 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::HideDisabledEntries
);
656 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::HideDisabledEntries
);
661 sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
663 SolarMutexGuard aSolarGuard
;
664 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
666 if ( mpMenu
&& IsPopupMenu() )
667 return PopupMenu::IsInExecute();
673 void SAL_CALL
VCLXMenu::endExecute()
675 SolarMutexGuard aSolarGuard
;
676 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
678 if ( mpMenu
&& IsPopupMenu() )
679 static_cast<PopupMenu
*>( mpMenu
.get() )->EndExecute();
683 void SAL_CALL
VCLXMenu::enableAutoMnemonics(
686 SolarMutexGuard aSolarGuard
;
687 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
691 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MenuFlags::NoAutoMnemonics
);
693 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics
);
698 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent(
700 const css::awt::KeyEvent
& aKeyEvent
)
702 SolarMutexGuard aSolarGuard
;
703 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
705 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
707 vcl::KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
708 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
713 css::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent(
714 ::sal_Int16 nItemId
)
716 SolarMutexGuard aSolarGuard
;
717 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
719 css::awt::KeyEvent aKeyEvent
;
720 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
722 vcl::KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
723 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
730 void SAL_CALL
VCLXMenu::setHelpText(
732 const OUString
& sHelpText
)
734 SolarMutexGuard aSolarGuard
;
735 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
737 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
739 mpMenu
->SetHelpText( nItemId
, sHelpText
);
744 OUString SAL_CALL
VCLXMenu::getHelpText(
745 ::sal_Int16 nItemId
)
747 SolarMutexGuard aSolarGuard
;
748 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
751 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
753 sHelpText
= mpMenu
->GetHelpText( nItemId
);
760 void SAL_CALL
VCLXMenu::setTipHelpText(
762 const OUString
& sTipHelpText
)
764 SolarMutexGuard aSolarGuard
;
765 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
767 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
769 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
774 OUString SAL_CALL
VCLXMenu::getTipHelpText(
775 ::sal_Int16 nItemId
)
777 SolarMutexGuard aSolarGuard
;
778 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
780 OUString sTipHelpText
;
781 if ( mpMenu
&& MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
783 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
789 void SAL_CALL
VCLXMenu::setItemImage(
791 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
794 SolarMutexGuard aSolarGuard
;
795 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
797 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
799 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
800 mpMenu
->SetItemImage( nItemId
, aImage
);
805 css::uno::Reference
< css::graphic::XGraphic
> SAL_CALL
806 VCLXMenu::getItemImage(
807 ::sal_Int16 nItemId
)
809 SolarMutexGuard aSolarGuard
;
810 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
812 css::uno::Reference
< css::graphic::XGraphic
> rxGraphic
;
814 if ( mpMenu
&& IsPopupMenu() && MENU_ITEM_NOTFOUND
!= mpMenu
->GetItemPos( nItemId
) )
816 Image aImage
= mpMenu
->GetItemImage( nItemId
);
818 rxGraphic
= Graphic(aImage
.GetBitmapEx()).GetXGraphic();
823 VCLXMenuBar::VCLXMenuBar()
825 ImplCreateMenu( false );
828 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( static_cast<Menu
*>(pMenuBar
) )
832 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
833 stardiv_Toolkit_VCLXMenuBar_get_implementation(
834 css::uno::XComponentContext
*,
835 css::uno::Sequence
<css::uno::Any
> const &)
837 return cppu::acquire(new VCLXMenuBar());
840 VCLXPopupMenu::VCLXPopupMenu()
842 ImplCreateMenu( true );
845 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( static_cast<Menu
*>(pPopMenu
) )
850 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
851 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
852 css::uno::XComponentContext
*,
853 css::uno::Sequence
<css::uno::Any
> const &)
855 return cppu::acquire(new VCLXPopupMenu());
858 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */