bump product version to 5.0.4.1
[LibreOffice.git] / toolkit / source / awt / vclxmenu.cxx
blob76469d7ca2b68ac7e4305d0fdc8f7da63d3cedea
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>
33 #include <vcl/menu.hxx>
34 #include <vcl/keycod.hxx>
35 #include <vcl/image.hxx>
36 #include <vcl/mnemonic.hxx>
37 #include <vcl/svapp.hxx>
39 #include <com/sun/star/awt/KeyModifier.hpp>
41 VCLXMenu::VCLXMenu()
42 : maMenuListeners( *this )
44 mpMenu = NULL;
47 VCLXMenu::VCLXMenu( Menu* pMenu )
48 : maMenuListeners( *this )
50 mpMenu = pMenu;
53 VCLXMenu::~VCLXMenu()
55 for ( size_t n = maPopupMenuRefs.size(); n; ) {
56 delete maPopupMenuRefs[ --n ];
58 if ( mpMenu )
60 mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
61 delete mpMenu;
65 bool VCLXMenu::IsPopupMenu() const
67 return (mpMenu && ! mpMenu->IsMenuBar());
70 void VCLXMenu::ImplCreateMenu( bool bPopup )
72 DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" );
74 if ( bPopup )
75 mpMenu = new PopupMenu;
76 else
77 mpMenu = new MenuBar;
79 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
82 IMPL_LINK( VCLXMenu, MenuEventListener, VclSimpleEvent*, pEvent )
84 DBG_ASSERT( pEvent && pEvent->ISA( VclMenuEvent ), "Unknown Event!" );
85 if ( pEvent && pEvent->ISA( VclMenuEvent ) )
87 DBG_ASSERT( static_cast<VclMenuEvent*>(pEvent)->GetMenu() && mpMenu, "Menu???" );
89 VclMenuEvent* pMenuEvent = static_cast<VclMenuEvent*>(pEvent);
90 if ( pMenuEvent->GetMenu() == mpMenu ) // Also called for the root menu
92 switch ( pMenuEvent->GetId() )
94 case VCLEVENT_MENU_SELECT:
96 if ( maMenuListeners.getLength() )
98 css::awt::MenuEvent aEvent;
99 aEvent.Source = (::cppu::OWeakObject*)this;
100 aEvent.MenuId = mpMenu->GetCurItemId();
101 maMenuListeners.itemSelected( aEvent );
104 break;
105 case VCLEVENT_OBJECT_DYING:
107 mpMenu = NULL;
109 break;
110 case VCLEVENT_MENU_HIGHLIGHT:
112 if ( maMenuListeners.getLength() )
114 css::awt::MenuEvent aEvent;
115 aEvent.Source = (::cppu::OWeakObject*)this;
116 aEvent.MenuId = mpMenu->GetCurItemId();
117 maMenuListeners.itemHighlighted( aEvent );
120 break;
121 case VCLEVENT_MENU_ACTIVATE:
123 if ( maMenuListeners.getLength() )
125 css::awt::MenuEvent aEvent;
126 aEvent.Source = (::cppu::OWeakObject*)this;
127 aEvent.MenuId = mpMenu->GetCurItemId();
128 maMenuListeners.itemActivated( aEvent );
131 break;
132 case VCLEVENT_MENU_DEACTIVATE:
134 if ( maMenuListeners.getLength() )
136 css::awt::MenuEvent aEvent;
137 aEvent.Source = (::cppu::OWeakObject*)this;
138 aEvent.MenuId = mpMenu->GetCurItemId();
139 maMenuListeners.itemDeactivated( aEvent );
142 break;
144 // ignore accessibility events
145 case VCLEVENT_MENU_ENABLE:
146 case VCLEVENT_MENU_INSERTITEM:
147 case VCLEVENT_MENU_REMOVEITEM:
148 case VCLEVENT_MENU_SUBMENUACTIVATE:
149 case VCLEVENT_MENU_SUBMENUDEACTIVATE:
150 case VCLEVENT_MENU_SUBMENUCHANGED:
151 case VCLEVENT_MENU_DEHIGHLIGHT:
152 case VCLEVENT_MENU_DISABLE:
153 case VCLEVENT_MENU_ITEMTEXTCHANGED:
154 case VCLEVENT_MENU_ITEMCHECKED:
155 case VCLEVENT_MENU_ITEMUNCHECKED:
156 case VCLEVENT_MENU_SHOW:
157 case VCLEVENT_MENU_HIDE:
158 break;
160 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
164 return 0;
168 OUString SAL_CALL VCLXMenu::getImplementationName( )
169 throw (css::uno::RuntimeException, std::exception)
171 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
172 const bool bIsPopupMenu = IsPopupMenu();
173 aGuard.clear();
175 OUString implName( "stardiv.Toolkit." );
176 if ( bIsPopupMenu )
177 implName += "VCLXPopupMenu";
178 else
179 implName += "VCLXMenuBar";
181 return implName;
184 css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
185 throw (css::uno::RuntimeException, std::exception)
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 )
202 throw (css::uno::RuntimeException, std::exception)
204 return cppu::supportsService(this, rServiceName);
207 css::uno::Any VCLXMenu::queryInterface(
208 const css::uno::Type & rType )
209 throw(css::uno::RuntimeException, std::exception)
211 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
212 const bool bIsPopupMenu = IsPopupMenu();
213 aGuard.clear();
215 css::uno::Any aRet;
217 if ( bIsPopupMenu )
218 aRet = ::cppu::queryInterface( rType,
219 (static_cast< css::awt::XMenu* >((css::awt::XMenuBar*) this) ),
220 (static_cast< css::awt::XPopupMenu* >(this)),
221 (static_cast< css::lang::XTypeProvider* >(this)),
222 (static_cast< css::lang::XServiceInfo* >(this)),
223 (static_cast< css::lang::XUnoTunnel* >(this)) );
224 else
225 aRet = ::cppu::queryInterface( rType,
226 (static_cast< css::awt::XMenu* >((css::awt::XMenuBar*) this) ),
227 (static_cast< css::awt::XMenuBar* >(this)),
228 (static_cast< css::lang::XTypeProvider* >(this)),
229 (static_cast< css::lang::XServiceInfo* >(this)),
230 (static_cast< css::lang::XUnoTunnel* >(this)) );
232 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
236 IMPL_XUNOTUNNEL( VCLXMenu )
238 css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes()
239 throw(css::uno::RuntimeException, std::exception)
241 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
242 const bool bIsPopupMenu = IsPopupMenu();
243 aGuard.clear();
245 static ::cppu::OTypeCollection* pCollectionMenuBar = NULL;
246 static ::cppu::OTypeCollection* pCollectionPopupMenu = NULL;
248 if ( bIsPopupMenu )
250 if( !pCollectionPopupMenu )
252 ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
253 if( !pCollectionPopupMenu )
255 static ::cppu::OTypeCollection collectionPopupMenu(
256 cppu::UnoType<css::lang::XTypeProvider>::get(),
257 cppu::UnoType<css::awt::XMenu>::get(),
258 cppu::UnoType<css::awt::XPopupMenu>::get(),
259 cppu::UnoType<css::lang::XServiceInfo>::get());
260 pCollectionPopupMenu = &collectionPopupMenu;
264 return (*pCollectionPopupMenu).getTypes();
266 else
268 if( !pCollectionMenuBar )
270 ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
271 if( !pCollectionMenuBar )
273 static ::cppu::OTypeCollection collectionMenuBar(
274 cppu::UnoType<css::lang::XTypeProvider>::get(),
275 cppu::UnoType<css::awt::XMenu>::get(),
276 cppu::UnoType<css::awt::XMenuBar>::get(),
277 cppu::UnoType<css::lang::XServiceInfo>::get());
278 pCollectionMenuBar = &collectionMenuBar;
281 return (*pCollectionMenuBar).getTypes();
286 css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId()
287 throw(css::uno::RuntimeException, std::exception)
289 return css::uno::Sequence<sal_Int8>();
292 void VCLXMenu::addMenuListener(
293 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
294 throw(css::uno::RuntimeException, std::exception)
296 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
298 maMenuListeners.addInterface( rxListener );
301 void VCLXMenu::removeMenuListener(
302 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
303 throw(css::uno::RuntimeException, std::exception)
305 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
307 maMenuListeners.removeInterface( rxListener );
310 void VCLXMenu::insertItem(
311 sal_Int16 nItemId,
312 const OUString& aText,
313 sal_Int16 nItemStyle,
314 sal_Int16 nPos )
315 throw(css::uno::RuntimeException, std::exception)
317 SolarMutexGuard aSolarGuard;
318 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
320 if ( mpMenu )
321 mpMenu->InsertItem(nItemId, aText, (MenuItemBits)nItemStyle, OString(), nPos);
324 void VCLXMenu::removeItem(
325 sal_Int16 nPos,
326 sal_Int16 nCount )
327 throw(css::uno::RuntimeException, std::exception)
329 SolarMutexGuard aSolarGuard;
330 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
332 if (!mpMenu)
333 return;
335 sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount();
336 if ( ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 ))
338 sal_Int16 nP = sal::static_int_cast< sal_Int16 >(
339 std::min( (int)(nPos+nCount), (int)nItemCount ));
340 while( nP-nPos > 0 )
341 mpMenu->RemoveItem( --nP );
345 sal_Int16 VCLXMenu::getItemCount( )
346 throw(css::uno::RuntimeException, std::exception)
348 SolarMutexGuard aSolarGuard;
349 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
351 return mpMenu ? mpMenu->GetItemCount() : 0;
354 sal_Int16 VCLXMenu::getItemId(
355 sal_Int16 nPos )
356 throw(css::uno::RuntimeException, std::exception)
358 SolarMutexGuard aSolarGuard;
359 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
361 return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
364 sal_Int16 VCLXMenu::getItemPos(
365 sal_Int16 nId )
366 throw(css::uno::RuntimeException, std::exception)
368 SolarMutexGuard aSolarGuard;
369 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
371 return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
374 void VCLXMenu::enableItem(
375 sal_Int16 nItemId,
376 sal_Bool bEnable )
377 throw(css::uno::RuntimeException, std::exception)
379 SolarMutexGuard aSolarGuard;
380 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
382 if ( mpMenu )
383 mpMenu->EnableItem( nItemId, bEnable );
386 sal_Bool VCLXMenu::isItemEnabled(
387 sal_Int16 nItemId )
388 throw(css::uno::RuntimeException, std::exception)
390 SolarMutexGuard aSolarGuard;
391 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
393 return mpMenu ? mpMenu->IsItemEnabled( nItemId ) : sal_False;
396 void VCLXMenu::setItemText(
397 sal_Int16 nItemId,
398 const OUString& aText )
399 throw(css::uno::RuntimeException, std::exception)
401 SolarMutexGuard aSolarGuard;
402 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
404 if ( mpMenu )
405 mpMenu->SetItemText( nItemId, aText );
408 OUString VCLXMenu::getItemText(
409 sal_Int16 nItemId )
410 throw(css::uno::RuntimeException, std::exception)
412 SolarMutexGuard aSolarGuard;
413 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
415 OUString aItemText;
416 if ( mpMenu )
417 aItemText = mpMenu->GetItemText( nItemId );
418 return aItemText;
421 void VCLXMenu::setPopupMenu(
422 sal_Int16 nItemId,
423 const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu )
424 throw(css::uno::RuntimeException, std::exception)
426 SolarMutexGuard aSolarGuard;
427 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
429 VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu );
430 DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
432 if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() )
434 // Selbst eine Ref halten!
435 css::uno::Reference< css::awt::XPopupMenu > * pNewRef = new css::uno::Reference< css::awt::XPopupMenu > ;
436 *pNewRef = rxPopupMenu;
437 maPopupMenuRefs.push_back( pNewRef );
439 mpMenu->SetPopupMenu( nItemId, static_cast<PopupMenu*>( pVCLMenu->GetMenu() ) );
443 css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu(
444 sal_Int16 nItemId )
445 throw(css::uno::RuntimeException, std::exception)
447 SolarMutexGuard aSolarGuard;
448 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
450 css::uno::Reference< css::awt::XPopupMenu > aRef;
451 Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : NULL;
452 if ( pMenu )
454 for ( size_t n = maPopupMenuRefs.size(); n; )
456 css::uno::Reference< css::awt::XPopupMenu > * pRef = maPopupMenuRefs[ --n ];
457 Menu* pM = static_cast<VCLXMenu*>(pRef->get())->GetMenu();
458 if ( pM == pMenu )
460 aRef = *pRef;
461 break;
464 // it seems the popup menu is not insert into maPopupMenuRefs
465 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
466 if( !aRef.is() )
468 aRef = new VCLXPopupMenu( static_cast<PopupMenu*>(pMenu) );
471 return aRef;
474 // css::awt::XPopupMenu
475 void VCLXMenu::insertSeparator(
476 sal_Int16 nPos )
477 throw(css::uno::RuntimeException, std::exception)
479 SolarMutexGuard aSolarGuard;
480 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
482 if ( mpMenu )
483 mpMenu->InsertSeparator(OString(), nPos);
486 void VCLXMenu::setDefaultItem(
487 sal_Int16 nItemId )
488 throw(css::uno::RuntimeException, std::exception)
490 SolarMutexGuard aSolarGuard;
491 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
493 if ( mpMenu )
494 mpMenu->SetDefaultItem( nItemId );
497 sal_Int16 VCLXMenu::getDefaultItem( )
498 throw(css::uno::RuntimeException, std::exception)
500 SolarMutexGuard aSolarGuard;
501 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
503 return mpMenu ? mpMenu->GetDefaultItem() : 0;
506 void VCLXMenu::checkItem(
507 sal_Int16 nItemId,
508 sal_Bool bCheck )
509 throw(css::uno::RuntimeException, std::exception)
511 SolarMutexGuard aSolarGuard;
512 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
514 if ( mpMenu )
515 mpMenu->CheckItem( nItemId, bCheck );
518 sal_Bool VCLXMenu::isItemChecked(
519 sal_Int16 nItemId )
520 throw(css::uno::RuntimeException, std::exception)
522 SolarMutexGuard aSolarGuard;
523 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
525 return mpMenu ? mpMenu->IsItemChecked( nItemId ) : sal_False;
528 sal_Int16 VCLXMenu::execute(
529 const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer,
530 const css::awt::Rectangle& rPos,
531 sal_Int16 nFlags )
532 throw(css::uno::RuntimeException, std::exception)
534 SolarMutexGuard aSolarGuard;
535 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
537 sal_Int16 nRet = 0;
538 if ( mpMenu && IsPopupMenu() )
540 nRet = static_cast<PopupMenu*>(mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ),
541 VCLRectangle( rPos ),
542 static_cast<PopupMenuFlags>(nFlags) | PopupMenuFlags::NoMouseUpClose );
544 return nRet;
548 void SAL_CALL VCLXMenu::setCommand(
549 sal_Int16 nItemId,
550 const OUString& aCommand )
551 throw (css::uno::RuntimeException, std::exception)
553 SolarMutexGuard aSolarGuard;
554 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
556 if ( mpMenu )
557 mpMenu->SetItemCommand( nItemId, aCommand );
560 OUString SAL_CALL VCLXMenu::getCommand(
561 sal_Int16 nItemId )
562 throw (css::uno::RuntimeException, std::exception)
564 SolarMutexGuard aSolarGuard;
565 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
567 OUString aItemCommand;
568 if ( mpMenu )
569 aItemCommand = mpMenu->GetItemCommand( nItemId );
570 return aItemCommand;
573 void SAL_CALL VCLXMenu::setHelpCommand(
574 sal_Int16 nItemId,
575 const OUString& aHelp )
576 throw (css::uno::RuntimeException, std::exception)
578 SolarMutexGuard aSolarGuard;
579 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
581 if ( mpMenu )
582 mpMenu->SetHelpCommand( nItemId, aHelp );
585 OUString SAL_CALL VCLXMenu::getHelpCommand(
586 sal_Int16 nItemId )
587 throw (css::uno::RuntimeException, std::exception)
589 SolarMutexGuard aSolarGuard;
590 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
592 OUString aHelpCommand;
593 if ( mpMenu )
594 aHelpCommand = mpMenu->GetHelpCommand( nItemId );
595 return aHelpCommand;
599 namespace
601 static Image lcl_XGraphic2VCLImage(
602 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
603 bool bResize )
605 Image aImage;
606 if ( !xGraphic.is() )
607 return aImage;
609 aImage = Image( xGraphic );
610 const ::Size aCurSize = aImage.GetSizePixel();
611 const sal_Int32 nCurWidth = aCurSize.Width();
612 const sal_Int32 nCurHeight = aCurSize.Height();
613 const sal_Int32 nIdeal( 16 );
615 if ( nCurWidth > 0 && nCurHeight > 0 )
617 if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) )
619 sal_Int32 nIdealWidth = nCurWidth > nIdeal ? nIdeal : nCurWidth;
620 sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight;
622 ::Size aNewSize( nIdealWidth, nIdealHeight );
624 bool bModified( false );
625 BitmapEx aBitmapEx = aImage.GetBitmapEx();
626 bModified = aBitmapEx.Scale( aNewSize, BmpScaleFlag::BestQuality );
628 if ( bModified )
629 aImage = Image( aBitmapEx );
632 return aImage;
635 /** Copied from svtools/inc/acceleratorexecute.hxx */
636 static css::awt::KeyEvent lcl_VCLKey2AWTKey(
637 const vcl::KeyCode& aVCLKey)
639 css::awt::KeyEvent aAWTKey;
640 aAWTKey.Modifiers = 0;
641 aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode();
643 if (aVCLKey.IsShift())
644 aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
645 if (aVCLKey.IsMod1())
646 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
647 if (aVCLKey.IsMod2())
648 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
649 if (aVCLKey.IsMod3())
650 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
652 return aAWTKey;
655 vcl::KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
657 bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
658 bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
659 bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
660 bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
661 sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode;
663 return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
669 sal_Bool SAL_CALL VCLXMenu::isPopupMenu( )
670 throw (css::uno::RuntimeException, std::exception)
672 SolarMutexGuard aSolarGuard;
673 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
674 return IsPopupMenu();
677 void SAL_CALL VCLXMenu::clear( )
678 throw (css::uno::RuntimeException, std::exception)
680 SolarMutexGuard aSolarGuard;
681 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
682 if ( mpMenu )
683 mpMenu->Clear();
687 css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType(
688 ::sal_Int16 nItemPos )
689 throw (css::uno::RuntimeException, std::exception)
691 SolarMutexGuard aSolarGuard;
692 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
694 css::awt::MenuItemType aMenuItemType =
695 css::awt::MenuItemType_DONTKNOW;
696 if ( mpMenu )
698 aMenuItemType = ( (css::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) );
701 return aMenuItemType;
704 void SAL_CALL VCLXMenu::hideDisabledEntries(
705 sal_Bool bHide )
706 throw (css::uno::RuntimeException, std::exception)
708 SolarMutexGuard aSolarGuard;
709 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
710 if ( mpMenu )
712 if ( bHide )
713 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries );
714 else
715 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::HideDisabledEntries );
720 sal_Bool SAL_CALL VCLXMenu::isInExecute( )
721 throw (css::uno::RuntimeException, std::exception)
723 SolarMutexGuard aSolarGuard;
724 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
726 if ( mpMenu && IsPopupMenu() )
727 return PopupMenu::IsInExecute();
728 else
729 return sal_False;
733 void SAL_CALL VCLXMenu::endExecute()
734 throw (css::uno::RuntimeException, std::exception)
736 SolarMutexGuard aSolarGuard;
737 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
739 if ( mpMenu && IsPopupMenu() )
740 static_cast<PopupMenu*>( mpMenu )->EndExecute();
744 void SAL_CALL VCLXMenu::enableAutoMnemonics(
745 sal_Bool bEnable )
746 throw (css::uno::RuntimeException, std::exception)
748 SolarMutexGuard aSolarGuard;
749 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
750 if ( mpMenu )
752 if ( !bEnable )
753 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
754 else
755 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics );
760 void SAL_CALL VCLXMenu::setAcceleratorKeyEvent(
761 ::sal_Int16 nItemId,
762 const css::awt::KeyEvent& aKeyEvent )
763 throw (css::uno::RuntimeException, std::exception)
765 SolarMutexGuard aSolarGuard;
766 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
768 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
770 vcl::KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent );
771 mpMenu->SetAccelKey( nItemId, aVCLKeyCode );
776 css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent(
777 ::sal_Int16 nItemId )
778 throw (css::uno::RuntimeException, std::exception)
780 SolarMutexGuard aSolarGuard;
781 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
783 css::awt::KeyEvent aKeyEvent;
784 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
786 vcl::KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId );
787 aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode );
790 return aKeyEvent;
794 void SAL_CALL VCLXMenu::setHelpText(
795 ::sal_Int16 nItemId,
796 const OUString& sHelpText )
797 throw (css::uno::RuntimeException, std::exception)
799 SolarMutexGuard aSolarGuard;
800 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
802 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
804 mpMenu->SetHelpText( nItemId, sHelpText );
809 OUString SAL_CALL VCLXMenu::getHelpText(
810 ::sal_Int16 nItemId )
811 throw (css::uno::RuntimeException, std::exception)
813 SolarMutexGuard aSolarGuard;
814 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
816 OUString sHelpText;
817 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
819 sHelpText = mpMenu->GetHelpText( nItemId );
822 return sHelpText;
826 void SAL_CALL VCLXMenu::setTipHelpText(
827 ::sal_Int16 nItemId,
828 const OUString& sTipHelpText )
829 throw (css::uno::RuntimeException, std::exception)
831 SolarMutexGuard aSolarGuard;
832 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
834 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
836 mpMenu->SetTipHelpText( nItemId, sTipHelpText );
841 OUString SAL_CALL VCLXMenu::getTipHelpText(
842 ::sal_Int16 nItemId )
843 throw (css::uno::RuntimeException, std::exception)
845 SolarMutexGuard aSolarGuard;
846 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
848 OUString sTipHelpText;
849 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
851 sTipHelpText = mpMenu->GetTipHelpText( nItemId );
853 return sTipHelpText;
857 void SAL_CALL VCLXMenu::setItemImage(
858 ::sal_Int16 nItemId,
859 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
860 sal_Bool bScale )
861 throw (css::uno::RuntimeException, std::exception)
863 SolarMutexGuard aSolarGuard;
864 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
866 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
868 Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale );
869 mpMenu->SetItemImage( nItemId, aImage );
874 css::uno::Reference< css::graphic::XGraphic > SAL_CALL
875 VCLXMenu::getItemImage(
876 ::sal_Int16 nItemId )
877 throw (css::uno::RuntimeException, std::exception)
879 SolarMutexGuard aSolarGuard;
880 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
882 css::uno::Reference< css::graphic::XGraphic > rxGraphic;
884 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
886 Image aImage = mpMenu->GetItemImage( nItemId );
887 if ( !!aImage )
888 rxGraphic = aImage.GetXGraphic();
890 return rxGraphic;
893 VCLXMenuBar::VCLXMenuBar()
895 ImplCreateMenu( false );
898 VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( (Menu *)pMenuBar )
902 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
903 stardiv_Toolkit_VCLXMenuBar_get_implementation(
904 css::uno::XComponentContext *,
905 css::uno::Sequence<css::uno::Any> const &)
907 return cppu::acquire(new VCLXMenuBar());
910 VCLXPopupMenu::VCLXPopupMenu()
912 ImplCreateMenu( true );
915 VCLXPopupMenu::VCLXPopupMenu( PopupMenu* pPopMenu ) : VCLXMenu( (Menu *)pPopMenu )
919 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
920 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
921 css::uno::XComponentContext *,
922 css::uno::Sequence<css::uno::Any> const &)
924 return cppu::acquire(new VCLXPopupMenu());
927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */