bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / vclxmenu.cxx
blob716eec4a01051a2b52d4866dd02c3b2702a8b7b8
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/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>
30 #include <rtl/uuid.h>
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>
43 VCLXMenu::VCLXMenu()
44 : maMenuListeners( *this )
45 , mnDefaultItem(0)
47 mpMenu = nullptr;
50 VCLXMenu::VCLXMenu( Menu* pMenu )
51 : maMenuListeners( *this )
52 , mnDefaultItem(0)
54 mpMenu = pMenu;
57 VCLXMenu::~VCLXMenu()
59 maPopupMenuRefs.clear();
60 if ( mpMenu )
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!" );
76 if ( bPopup )
77 mpMenu = VclPtr<PopupMenu>::Create();
78 else
79 mpMenu = VclPtr<MenuBar>::Create();
81 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
84 void VCLXMenu::ImplAddListener()
86 assert(mpMenu);
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 );
108 break;
109 case VclEventId::ObjectDying:
111 mpMenu = nullptr;
113 break;
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 );
124 break;
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 );
135 break;
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 );
146 break;
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:
162 break;
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();
174 aGuard.clear();
176 OUString implName( "stardiv.Toolkit." );
177 if ( bIsPopupMenu )
178 implName += "VCLXPopupMenu";
179 else
180 implName += "VCLXMenuBar";
182 return implName;
185 css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
187 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
188 const bool bIsPopupMenu = IsPopupMenu();
189 aGuard.clear();
191 if ( bIsPopupMenu )
192 return css::uno::Sequence<OUString>{
193 OUString::createFromAscii(szServiceName2_PopupMenu),
194 "stardiv.vcl.PopupMenu"};
195 else
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();
211 aGuard.clear();
213 css::uno::Any aRet;
215 if ( bIsPopupMenu )
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) );
222 else
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();
240 aGuard.clear();
242 if ( bIsPopupMenu )
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();
250 else
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(
283 sal_Int16 nItemId,
284 const OUString& aText,
285 sal_Int16 nItemStyle,
286 sal_Int16 nPos )
288 SolarMutexGuard aSolarGuard;
289 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
291 if ( mpMenu )
292 mpMenu->InsertItem(nItemId, aText, static_cast<MenuItemBits>(nItemStyle), OString(), nPos);
295 void VCLXMenu::removeItem(
296 sal_Int16 nPos,
297 sal_Int16 nCount )
299 SolarMutexGuard aSolarGuard;
300 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
302 if (!mpMenu)
303 return;
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) ));
310 while( nP-nPos > 0 )
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(
324 sal_Int16 nPos )
326 SolarMutexGuard aSolarGuard;
327 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
329 return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
332 sal_Int16 VCLXMenu::getItemPos(
333 sal_Int16 nId )
335 SolarMutexGuard aSolarGuard;
336 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
338 return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
341 void VCLXMenu::enableItem(
342 sal_Int16 nItemId,
343 sal_Bool bEnable )
345 SolarMutexGuard aSolarGuard;
346 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
348 if ( mpMenu )
349 mpMenu->EnableItem( nItemId, bEnable );
352 sal_Bool VCLXMenu::isItemEnabled(
353 sal_Int16 nItemId )
355 SolarMutexGuard aSolarGuard;
356 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
358 return mpMenu && mpMenu->IsItemEnabled( nItemId );
361 void VCLXMenu::setItemText(
362 sal_Int16 nItemId,
363 const OUString& aText )
365 SolarMutexGuard aSolarGuard;
366 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
368 if ( mpMenu )
369 mpMenu->SetItemText( nItemId, aText );
372 OUString VCLXMenu::getItemText(
373 sal_Int16 nItemId )
375 SolarMutexGuard aSolarGuard;
376 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
378 OUString aItemText;
379 if ( mpMenu )
380 aItemText = mpMenu->GetItemText( nItemId );
381 return aItemText;
384 void VCLXMenu::setPopupMenu(
385 sal_Int16 nItemId,
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(
403 sal_Int16 nItemId )
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;
410 if ( pMenu )
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();
416 if ( pM == pMenu )
418 aRef = rRef;
419 break;
422 // it seems the popup menu is not insert into maPopupMenuRefs
423 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
424 if( !aRef.is() )
426 aRef = new VCLXPopupMenu( static_cast<PopupMenu*>(pMenu) );
429 return aRef;
432 // css::awt::XPopupMenu
433 void VCLXMenu::insertSeparator(
434 sal_Int16 nPos )
436 SolarMutexGuard aSolarGuard;
437 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
439 if ( mpMenu )
440 mpMenu->InsertSeparator(OString(), nPos);
443 void VCLXMenu::setDefaultItem(
444 sal_Int16 nItemId )
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(
459 sal_Int16 nItemId,
460 sal_Bool bCheck )
462 SolarMutexGuard aSolarGuard;
463 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
465 if ( mpMenu )
466 mpMenu->CheckItem( nItemId, bCheck );
469 sal_Bool VCLXMenu::isItemChecked(
470 sal_Int16 nItemId )
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,
481 sal_Int16 nFlags )
483 SolarMutexGuard aSolarGuard;
484 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
486 sal_Int16 nRet = 0;
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 );
493 return nRet;
497 void SAL_CALL VCLXMenu::setCommand(
498 sal_Int16 nItemId,
499 const OUString& aCommand )
501 SolarMutexGuard aSolarGuard;
502 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
504 if ( mpMenu )
505 mpMenu->SetItemCommand( nItemId, aCommand );
508 OUString SAL_CALL VCLXMenu::getCommand(
509 sal_Int16 nItemId )
511 SolarMutexGuard aSolarGuard;
512 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
514 OUString aItemCommand;
515 if ( mpMenu )
516 aItemCommand = mpMenu->GetItemCommand( nItemId );
517 return aItemCommand;
520 void SAL_CALL VCLXMenu::setHelpCommand(
521 sal_Int16 nItemId,
522 const OUString& aHelp )
524 SolarMutexGuard aSolarGuard;
525 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
527 if ( mpMenu )
528 mpMenu->SetHelpCommand( nItemId, aHelp );
531 OUString SAL_CALL VCLXMenu::getHelpCommand(
532 sal_Int16 nItemId )
534 SolarMutexGuard aSolarGuard;
535 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
537 OUString aHelpCommand;
538 if ( mpMenu )
539 aHelpCommand = mpMenu->GetHelpCommand( nItemId );
540 return aHelpCommand;
544 namespace
546 Image lcl_XGraphic2VCLImage(
547 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
548 bool bResize )
550 Image aImage;
551 if ( !xGraphic.is() )
552 return aImage;
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 );
573 if ( bModified )
574 aImage = Image( aBitmapEx );
577 return aImage;
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;
597 return aAWTKey;
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() );
625 if ( mpMenu )
626 mpMenu->Clear();
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;
638 if ( mpMenu )
640 aMenuItemType = static_cast<css::awt::MenuItemType>(mpMenu->GetItemType( nItemPos ));
643 return aMenuItemType;
646 void SAL_CALL VCLXMenu::hideDisabledEntries(
647 sal_Bool bHide )
649 SolarMutexGuard aSolarGuard;
650 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
651 if ( mpMenu )
653 if ( bHide )
654 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries );
655 else
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();
668 else
669 return false;
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(
684 sal_Bool bEnable )
686 SolarMutexGuard aSolarGuard;
687 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
688 if ( mpMenu )
690 if ( !bEnable )
691 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
692 else
693 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics );
698 void SAL_CALL VCLXMenu::setAcceleratorKeyEvent(
699 ::sal_Int16 nItemId,
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 );
726 return aKeyEvent;
730 void SAL_CALL VCLXMenu::setHelpText(
731 ::sal_Int16 nItemId,
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() );
750 OUString sHelpText;
751 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
753 sHelpText = mpMenu->GetHelpText( nItemId );
756 return sHelpText;
760 void SAL_CALL VCLXMenu::setTipHelpText(
761 ::sal_Int16 nItemId,
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 );
785 return sTipHelpText;
789 void SAL_CALL VCLXMenu::setItemImage(
790 ::sal_Int16 nItemId,
791 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
792 sal_Bool bScale )
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 );
817 if ( !!aImage )
818 rxGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic();
820 return rxGraphic;
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) )
847 ImplAddListener();
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: */