Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / awt / vclxmenu.cxx
blobf8c662ae24800885cb0bcebff8b0053ddca55afc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
39 VCLXMenu::VCLXMenu()
40 : maMenuListeners( *this )
41 , mnDefaultItem(0)
43 mpMenu = nullptr;
46 VCLXMenu::VCLXMenu( Menu* pMenu )
47 : maMenuListeners( *this )
48 , mnDefaultItem(0)
50 mpMenu = pMenu;
53 VCLXMenu::~VCLXMenu()
55 maPopupMenuRefs.clear();
56 if ( mpMenu )
58 SolarMutexGuard g;
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!" );
73 if ( bPopup )
74 mpMenu = VclPtr<PopupMenu>::Create();
75 else
76 mpMenu = VclPtr<MenuBar>::Create();
78 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
81 void VCLXMenu::ImplAddListener()
83 assert(mpMenu);
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
92 return;
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 );
106 break;
107 case VclEventId::ObjectDying:
109 mpMenu = nullptr;
111 break;
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 );
122 break;
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 );
133 break;
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 );
144 break;
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:
160 break;
162 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
167 OUString SAL_CALL VCLXMenu::getImplementationName( )
169 std::unique_lock aGuard( maMutex );
170 const bool bIsPopupMenu = IsPopupMenu();
171 aGuard.unlock();
173 OUString implName( "stardiv.Toolkit." );
174 if ( bIsPopupMenu )
175 implName += "VCLXPopupMenu";
176 else
177 implName += "VCLXMenuBar";
179 return implName;
182 css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
184 std::unique_lock aGuard( maMutex );
185 const bool bIsPopupMenu = IsPopupMenu();
186 aGuard.unlock();
188 if ( bIsPopupMenu )
189 return css::uno::Sequence<OUString>{
190 "com.sun.star.awt.PopupMenu",
191 "stardiv.vcl.PopupMenu"};
192 else
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();
208 aGuard.unlock();
210 css::uno::Any aRet;
212 if ( bIsPopupMenu )
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) );
218 else
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();
233 aGuard.unlock();
235 if ( bIsPopupMenu )
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();
243 else
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(
276 sal_Int16 nItemId,
277 const OUString& aText,
278 sal_Int16 nItemStyle,
279 sal_Int16 nPos )
281 SolarMutexGuard aSolarGuard;
282 std::unique_lock aGuard( maMutex );
284 if ( mpMenu )
285 mpMenu->InsertItem(nItemId, aText, static_cast<MenuItemBits>(nItemStyle), {}, nPos);
288 void VCLXMenu::removeItem(
289 sal_Int16 nPos,
290 sal_Int16 nCount )
292 SolarMutexGuard aSolarGuard;
293 std::unique_lock aGuard( maMutex );
295 if (!mpMenu)
296 return;
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) ));
303 while( nP-nPos > 0 )
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(
317 sal_Int16 nPos )
319 SolarMutexGuard aSolarGuard;
320 std::unique_lock aGuard( maMutex );
322 return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
325 sal_Int16 VCLXMenu::getItemPos(
326 sal_Int16 nId )
328 SolarMutexGuard aSolarGuard;
329 std::unique_lock aGuard( maMutex );
331 return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
334 void VCLXMenu::enableItem(
335 sal_Int16 nItemId,
336 sal_Bool bEnable )
338 SolarMutexGuard aSolarGuard;
339 std::unique_lock aGuard( maMutex );
341 if ( mpMenu )
342 mpMenu->EnableItem( nItemId, bEnable );
345 sal_Bool VCLXMenu::isItemEnabled(
346 sal_Int16 nItemId )
348 SolarMutexGuard aSolarGuard;
349 std::unique_lock aGuard( maMutex );
351 return mpMenu && mpMenu->IsItemEnabled( nItemId );
354 void VCLXMenu::setItemText(
355 sal_Int16 nItemId,
356 const OUString& aText )
358 SolarMutexGuard aSolarGuard;
359 std::unique_lock aGuard( maMutex );
361 if ( mpMenu )
362 mpMenu->SetItemText( nItemId, aText );
365 OUString VCLXMenu::getItemText(
366 sal_Int16 nItemId )
368 SolarMutexGuard aSolarGuard;
369 std::unique_lock aGuard( maMutex );
371 OUString aItemText;
372 if ( mpMenu )
373 aItemText = mpMenu->GetItemText( nItemId );
374 return aItemText;
377 void VCLXMenu::setPopupMenu(
378 sal_Int16 nItemId,
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(
396 sal_Int16 nItemId )
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;
403 if ( pMenu )
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();
409 if ( pM == pMenu )
411 aRef = rRef;
412 break;
415 // it seems the popup menu is not insert into maPopupMenuRefs
416 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
417 if( !aRef.is() )
419 aRef = new VCLXPopupMenu( static_cast<PopupMenu*>(pMenu) );
422 return aRef;
425 // css::awt::XPopupMenu
426 void VCLXMenu::insertSeparator(
427 sal_Int16 nPos )
429 SolarMutexGuard aSolarGuard;
430 std::unique_lock aGuard( maMutex );
432 if ( mpMenu )
433 mpMenu->InsertSeparator({}, nPos);
436 void VCLXMenu::setDefaultItem(
437 sal_Int16 nItemId )
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(
452 sal_Int16 nItemId,
453 sal_Bool bCheck )
455 SolarMutexGuard aSolarGuard;
456 std::unique_lock aGuard( maMutex );
458 if ( mpMenu )
459 mpMenu->CheckItem( nItemId, bCheck );
462 sal_Bool VCLXMenu::isItemChecked(
463 sal_Int16 nItemId )
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,
474 sal_Int16 nFlags )
476 SolarMutexGuard aSolarGuard;
477 auto pMenu = mpMenu;
479 std::unique_lock aGuard( maMutex );
480 if ( !mpMenu || !IsPopupMenu() )
481 return 0;
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(
492 sal_Int16 nItemId,
493 const OUString& aCommand )
495 SolarMutexGuard aSolarGuard;
496 std::unique_lock aGuard( maMutex );
498 if ( mpMenu )
499 mpMenu->SetItemCommand( nItemId, aCommand );
502 OUString SAL_CALL VCLXMenu::getCommand(
503 sal_Int16 nItemId )
505 SolarMutexGuard aSolarGuard;
506 std::unique_lock aGuard( maMutex );
508 OUString aItemCommand;
509 if ( mpMenu )
510 aItemCommand = mpMenu->GetItemCommand( nItemId );
511 return aItemCommand;
514 void SAL_CALL VCLXMenu::setHelpCommand(
515 sal_Int16 nItemId,
516 const OUString& aHelp )
518 SolarMutexGuard aSolarGuard;
519 std::unique_lock aGuard( maMutex );
521 if ( mpMenu )
522 mpMenu->SetHelpCommand( nItemId, aHelp );
525 OUString SAL_CALL VCLXMenu::getHelpCommand(
526 sal_Int16 nItemId )
528 SolarMutexGuard aSolarGuard;
529 std::unique_lock aGuard( maMutex );
531 OUString aHelpCommand;
532 if ( mpMenu )
533 aHelpCommand = mpMenu->GetHelpCommand( nItemId );
534 return aHelpCommand;
538 namespace
540 Image lcl_XGraphic2VCLImage(
541 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
542 bool bResize )
544 Image aImage;
545 if ( !xGraphic.is() )
546 return aImage;
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 );
567 if ( bModified )
568 aImage = Image( aBitmapEx );
571 return aImage;
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;
591 return aAWTKey;
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 );
619 if ( mpMenu )
620 mpMenu->Clear();
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;
632 if ( mpMenu )
634 aMenuItemType = static_cast<css::awt::MenuItemType>(mpMenu->GetItemType( nItemPos ));
637 return aMenuItemType;
640 void SAL_CALL VCLXMenu::hideDisabledEntries(
641 sal_Bool bHide )
643 SolarMutexGuard aSolarGuard;
644 std::unique_lock aGuard( maMutex );
645 if ( mpMenu )
647 if ( bHide )
648 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries );
649 else
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();
662 else
663 return false;
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(
678 sal_Bool bEnable )
680 SolarMutexGuard aSolarGuard;
681 std::unique_lock aGuard( maMutex );
682 if ( mpMenu )
684 if ( !bEnable )
685 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
686 else
687 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics );
692 void SAL_CALL VCLXMenu::setAcceleratorKeyEvent(
693 ::sal_Int16 nItemId,
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 );
720 return aKeyEvent;
724 void SAL_CALL VCLXMenu::setHelpText(
725 ::sal_Int16 nItemId,
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 );
744 OUString sHelpText;
745 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
747 sHelpText = mpMenu->GetHelpText( nItemId );
750 return sHelpText;
754 void SAL_CALL VCLXMenu::setTipHelpText(
755 ::sal_Int16 nItemId,
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 );
779 return sTipHelpText;
783 void SAL_CALL VCLXMenu::setItemImage(
784 ::sal_Int16 nItemId,
785 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
786 sal_Bool bScale )
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 );
811 if ( !!aImage )
812 rxGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic();
814 return rxGraphic;
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) )
857 ImplAddListener();
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: */