Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / toolkit / source / awt / vclxmenu.cxx
blob8c2598e9f982c729241f53c2c6a01abdbc57526f
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 = nullptr;
47 VCLXMenu::VCLXMenu( Menu* pMenu )
48 : maMenuListeners( *this )
50 mpMenu = pMenu;
53 VCLXMenu::~VCLXMenu()
55 maPopupMenuRefs.clear();
56 if ( mpMenu )
58 mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
59 delete mpMenu;
63 bool VCLXMenu::IsPopupMenu() const
65 return (mpMenu && ! mpMenu->IsMenuBar());
68 void VCLXMenu::ImplCreateMenu( bool bPopup )
70 DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" );
72 if ( bPopup )
73 mpMenu = new PopupMenu;
74 else
75 mpMenu = new MenuBar;
77 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
80 IMPL_LINK_TYPED( VCLXMenu, MenuEventListener, VclMenuEvent&, rMenuEvent, void )
82 DBG_ASSERT( rMenuEvent.GetMenu() && mpMenu, "Menu???" );
84 if ( rMenuEvent.GetMenu() == mpMenu ) // Also called for the root menu
86 switch ( rMenuEvent.GetId() )
88 case VCLEVENT_MENU_SELECT:
90 if ( maMenuListeners.getLength() )
92 css::awt::MenuEvent aEvent;
93 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
94 aEvent.MenuId = mpMenu->GetCurItemId();
95 maMenuListeners.itemSelected( aEvent );
98 break;
99 case VCLEVENT_OBJECT_DYING:
101 mpMenu = nullptr;
103 break;
104 case VCLEVENT_MENU_HIGHLIGHT:
106 if ( maMenuListeners.getLength() )
108 css::awt::MenuEvent aEvent;
109 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
110 aEvent.MenuId = mpMenu->GetCurItemId();
111 maMenuListeners.itemHighlighted( aEvent );
114 break;
115 case VCLEVENT_MENU_ACTIVATE:
117 if ( maMenuListeners.getLength() )
119 css::awt::MenuEvent aEvent;
120 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
121 aEvent.MenuId = mpMenu->GetCurItemId();
122 maMenuListeners.itemActivated( aEvent );
125 break;
126 case VCLEVENT_MENU_DEACTIVATE:
128 if ( maMenuListeners.getLength() )
130 css::awt::MenuEvent aEvent;
131 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
132 aEvent.MenuId = mpMenu->GetCurItemId();
133 maMenuListeners.itemDeactivated( aEvent );
136 break;
138 // ignore accessibility events
139 case VCLEVENT_MENU_ENABLE:
140 case VCLEVENT_MENU_INSERTITEM:
141 case VCLEVENT_MENU_REMOVEITEM:
142 case VCLEVENT_MENU_SUBMENUACTIVATE:
143 case VCLEVENT_MENU_SUBMENUDEACTIVATE:
144 case VCLEVENT_MENU_SUBMENUCHANGED:
145 case VCLEVENT_MENU_DEHIGHLIGHT:
146 case VCLEVENT_MENU_DISABLE:
147 case VCLEVENT_MENU_ITEMTEXTCHANGED:
148 case VCLEVENT_MENU_ITEMCHECKED:
149 case VCLEVENT_MENU_ITEMUNCHECKED:
150 case VCLEVENT_MENU_SHOW:
151 case VCLEVENT_MENU_HIDE:
152 break;
154 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
160 OUString SAL_CALL VCLXMenu::getImplementationName( )
161 throw (css::uno::RuntimeException, std::exception)
163 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
164 const bool bIsPopupMenu = IsPopupMenu();
165 aGuard.clear();
167 OUString implName( "stardiv.Toolkit." );
168 if ( bIsPopupMenu )
169 implName += "VCLXPopupMenu";
170 else
171 implName += "VCLXMenuBar";
173 return implName;
176 css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
177 throw (css::uno::RuntimeException, std::exception)
179 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
180 const bool bIsPopupMenu = IsPopupMenu();
181 aGuard.clear();
183 if ( bIsPopupMenu )
184 return css::uno::Sequence<OUString>{
185 OUString::createFromAscii(szServiceName2_PopupMenu),
186 "stardiv.vcl.PopupMenu"};
187 else
188 return css::uno::Sequence<OUString>{
189 OUString::createFromAscii(szServiceName2_MenuBar),
190 "stardiv.vcl.MenuBar"};
193 sal_Bool SAL_CALL VCLXMenu::supportsService(const OUString& rServiceName )
194 throw (css::uno::RuntimeException, std::exception)
196 return cppu::supportsService(this, rServiceName);
199 css::uno::Any VCLXMenu::queryInterface(
200 const css::uno::Type & rType )
201 throw(css::uno::RuntimeException, std::exception)
203 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
204 const bool bIsPopupMenu = IsPopupMenu();
205 aGuard.clear();
207 css::uno::Any aRet;
209 if ( bIsPopupMenu )
210 aRet = ::cppu::queryInterface( rType,
211 (static_cast< css::awt::XMenu* >(static_cast<css::awt::XMenuBar*>(this)) ),
212 (static_cast< css::awt::XPopupMenu* >(this)),
213 (static_cast< css::lang::XTypeProvider* >(this)),
214 (static_cast< css::lang::XServiceInfo* >(this)),
215 (static_cast< css::lang::XUnoTunnel* >(this)) );
216 else
217 aRet = ::cppu::queryInterface( rType,
218 (static_cast< css::awt::XMenu* >(static_cast<css::awt::XMenuBar*>(this)) ),
219 (static_cast< css::awt::XMenuBar* >(this)),
220 (static_cast< css::lang::XTypeProvider* >(this)),
221 (static_cast< css::lang::XServiceInfo* >(this)),
222 (static_cast< css::lang::XUnoTunnel* >(this)) );
224 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
228 IMPL_XUNOTUNNEL( VCLXMenu )
230 css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes()
231 throw(css::uno::RuntimeException, std::exception)
233 ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
234 const bool bIsPopupMenu = IsPopupMenu();
235 aGuard.clear();
237 static ::cppu::OTypeCollection* pCollectionMenuBar = nullptr;
238 static ::cppu::OTypeCollection* pCollectionPopupMenu = nullptr;
240 if ( bIsPopupMenu )
242 if( !pCollectionPopupMenu )
244 ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
245 if( !pCollectionPopupMenu )
247 static ::cppu::OTypeCollection collectionPopupMenu(
248 cppu::UnoType<css::lang::XTypeProvider>::get(),
249 cppu::UnoType<css::awt::XMenu>::get(),
250 cppu::UnoType<css::awt::XPopupMenu>::get(),
251 cppu::UnoType<css::lang::XServiceInfo>::get());
252 pCollectionPopupMenu = &collectionPopupMenu;
256 return (*pCollectionPopupMenu).getTypes();
258 else
260 if( !pCollectionMenuBar )
262 ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
263 if( !pCollectionMenuBar )
265 static ::cppu::OTypeCollection collectionMenuBar(
266 cppu::UnoType<css::lang::XTypeProvider>::get(),
267 cppu::UnoType<css::awt::XMenu>::get(),
268 cppu::UnoType<css::awt::XMenuBar>::get(),
269 cppu::UnoType<css::lang::XServiceInfo>::get());
270 pCollectionMenuBar = &collectionMenuBar;
273 return (*pCollectionMenuBar).getTypes();
278 css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId()
279 throw(css::uno::RuntimeException, std::exception)
281 return css::uno::Sequence<sal_Int8>();
284 void VCLXMenu::addMenuListener(
285 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
286 throw(css::uno::RuntimeException, std::exception)
288 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
290 maMenuListeners.addInterface( rxListener );
293 void VCLXMenu::removeMenuListener(
294 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
295 throw(css::uno::RuntimeException, std::exception)
297 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
299 maMenuListeners.removeInterface( rxListener );
302 void VCLXMenu::insertItem(
303 sal_Int16 nItemId,
304 const OUString& aText,
305 sal_Int16 nItemStyle,
306 sal_Int16 nPos )
307 throw(css::uno::RuntimeException, std::exception)
309 SolarMutexGuard aSolarGuard;
310 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
312 if ( mpMenu )
313 mpMenu->InsertItem(nItemId, aText, (MenuItemBits)nItemStyle, OString(), nPos);
316 void VCLXMenu::removeItem(
317 sal_Int16 nPos,
318 sal_Int16 nCount )
319 throw(css::uno::RuntimeException, std::exception)
321 SolarMutexGuard aSolarGuard;
322 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
324 if (!mpMenu)
325 return;
327 sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount();
328 if ( ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 ))
330 sal_Int16 nP = sal::static_int_cast< sal_Int16 >(
331 std::min( (int)(nPos+nCount), (int)nItemCount ));
332 while( nP-nPos > 0 )
333 mpMenu->RemoveItem( --nP );
337 sal_Int16 VCLXMenu::getItemCount( )
338 throw(css::uno::RuntimeException, std::exception)
340 SolarMutexGuard aSolarGuard;
341 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
343 return mpMenu ? mpMenu->GetItemCount() : 0;
346 sal_Int16 VCLXMenu::getItemId(
347 sal_Int16 nPos )
348 throw(css::uno::RuntimeException, std::exception)
350 SolarMutexGuard aSolarGuard;
351 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
353 return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
356 sal_Int16 VCLXMenu::getItemPos(
357 sal_Int16 nId )
358 throw(css::uno::RuntimeException, std::exception)
360 SolarMutexGuard aSolarGuard;
361 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
363 return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
366 void VCLXMenu::enableItem(
367 sal_Int16 nItemId,
368 sal_Bool bEnable )
369 throw(css::uno::RuntimeException, std::exception)
371 SolarMutexGuard aSolarGuard;
372 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
374 if ( mpMenu )
375 mpMenu->EnableItem( nItemId, bEnable );
378 sal_Bool VCLXMenu::isItemEnabled(
379 sal_Int16 nItemId )
380 throw(css::uno::RuntimeException, std::exception)
382 SolarMutexGuard aSolarGuard;
383 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
385 return mpMenu && mpMenu->IsItemEnabled( nItemId );
388 void VCLXMenu::setItemText(
389 sal_Int16 nItemId,
390 const OUString& aText )
391 throw(css::uno::RuntimeException, std::exception)
393 SolarMutexGuard aSolarGuard;
394 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
396 if ( mpMenu )
397 mpMenu->SetItemText( nItemId, aText );
400 OUString VCLXMenu::getItemText(
401 sal_Int16 nItemId )
402 throw(css::uno::RuntimeException, std::exception)
404 SolarMutexGuard aSolarGuard;
405 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
407 OUString aItemText;
408 if ( mpMenu )
409 aItemText = mpMenu->GetItemText( nItemId );
410 return aItemText;
413 void VCLXMenu::setPopupMenu(
414 sal_Int16 nItemId,
415 const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu )
416 throw(css::uno::RuntimeException, std::exception)
418 SolarMutexGuard aSolarGuard;
419 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
421 VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu );
422 DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
424 if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() )
426 maPopupMenuRefs.push_back( rxPopupMenu );
428 mpMenu->SetPopupMenu( nItemId, static_cast<PopupMenu*>( pVCLMenu->GetMenu() ) );
432 css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu(
433 sal_Int16 nItemId )
434 throw(css::uno::RuntimeException, std::exception)
436 SolarMutexGuard aSolarGuard;
437 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
439 css::uno::Reference< css::awt::XPopupMenu > aRef;
440 Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : nullptr;
441 if ( pMenu )
443 for ( size_t n = maPopupMenuRefs.size(); n; )
445 css::uno::Reference< css::awt::XPopupMenu >& rRef = maPopupMenuRefs[ --n ];
446 Menu* pM = static_cast<VCLXMenu*>(rRef.get())->GetMenu();
447 if ( pM == pMenu )
449 aRef = rRef;
450 break;
453 // it seems the popup menu is not insert into maPopupMenuRefs
454 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
455 if( !aRef.is() )
457 aRef = new VCLXPopupMenu( static_cast<PopupMenu*>(pMenu) );
460 return aRef;
463 // css::awt::XPopupMenu
464 void VCLXMenu::insertSeparator(
465 sal_Int16 nPos )
466 throw(css::uno::RuntimeException, std::exception)
468 SolarMutexGuard aSolarGuard;
469 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
471 if ( mpMenu )
472 mpMenu->InsertSeparator(OString(), nPos);
475 void VCLXMenu::setDefaultItem(
476 sal_Int16 nItemId )
477 throw(css::uno::RuntimeException, std::exception)
479 SolarMutexGuard aSolarGuard;
480 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
482 if ( mpMenu )
483 mpMenu->SetDefaultItem( nItemId );
486 sal_Int16 VCLXMenu::getDefaultItem( )
487 throw(css::uno::RuntimeException, std::exception)
489 SolarMutexGuard aSolarGuard;
490 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
492 return mpMenu ? mpMenu->GetDefaultItem() : 0;
495 void VCLXMenu::checkItem(
496 sal_Int16 nItemId,
497 sal_Bool bCheck )
498 throw(css::uno::RuntimeException, std::exception)
500 SolarMutexGuard aSolarGuard;
501 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
503 if ( mpMenu )
504 mpMenu->CheckItem( nItemId, bCheck );
507 sal_Bool VCLXMenu::isItemChecked(
508 sal_Int16 nItemId )
509 throw(css::uno::RuntimeException, std::exception)
511 SolarMutexGuard aSolarGuard;
512 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
514 return mpMenu && mpMenu->IsItemChecked( nItemId );
517 sal_Int16 VCLXMenu::execute(
518 const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer,
519 const css::awt::Rectangle& rPos,
520 sal_Int16 nFlags )
521 throw(css::uno::RuntimeException, std::exception)
523 SolarMutexGuard aSolarGuard;
524 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
526 sal_Int16 nRet = 0;
527 if ( mpMenu && IsPopupMenu() )
529 nRet = static_cast<PopupMenu*>(mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ),
530 VCLRectangle( rPos ),
531 static_cast<PopupMenuFlags>(nFlags) | PopupMenuFlags::NoMouseUpClose );
533 return nRet;
537 void SAL_CALL VCLXMenu::setCommand(
538 sal_Int16 nItemId,
539 const OUString& aCommand )
540 throw (css::uno::RuntimeException, std::exception)
542 SolarMutexGuard aSolarGuard;
543 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
545 if ( mpMenu )
546 mpMenu->SetItemCommand( nItemId, aCommand );
549 OUString SAL_CALL VCLXMenu::getCommand(
550 sal_Int16 nItemId )
551 throw (css::uno::RuntimeException, std::exception)
553 SolarMutexGuard aSolarGuard;
554 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
556 OUString aItemCommand;
557 if ( mpMenu )
558 aItemCommand = mpMenu->GetItemCommand( nItemId );
559 return aItemCommand;
562 void SAL_CALL VCLXMenu::setHelpCommand(
563 sal_Int16 nItemId,
564 const OUString& aHelp )
565 throw (css::uno::RuntimeException, std::exception)
567 SolarMutexGuard aSolarGuard;
568 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
570 if ( mpMenu )
571 mpMenu->SetHelpCommand( nItemId, aHelp );
574 OUString SAL_CALL VCLXMenu::getHelpCommand(
575 sal_Int16 nItemId )
576 throw (css::uno::RuntimeException, std::exception)
578 SolarMutexGuard aSolarGuard;
579 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
581 OUString aHelpCommand;
582 if ( mpMenu )
583 aHelpCommand = mpMenu->GetHelpCommand( nItemId );
584 return aHelpCommand;
588 namespace
590 Image lcl_XGraphic2VCLImage(
591 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
592 bool bResize )
594 Image aImage;
595 if ( !xGraphic.is() )
596 return aImage;
598 aImage = Image( xGraphic );
599 const ::Size aCurSize = aImage.GetSizePixel();
600 const sal_Int32 nCurWidth = aCurSize.Width();
601 const sal_Int32 nCurHeight = aCurSize.Height();
602 const sal_Int32 nIdeal( 16 );
604 if ( nCurWidth > 0 && nCurHeight > 0 )
606 if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) )
608 sal_Int32 nIdealWidth = nCurWidth > nIdeal ? nIdeal : nCurWidth;
609 sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight;
611 ::Size aNewSize( nIdealWidth, nIdealHeight );
613 bool bModified( false );
614 BitmapEx aBitmapEx = aImage.GetBitmapEx();
615 bModified = aBitmapEx.Scale( aNewSize, BmpScaleFlag::BestQuality );
617 if ( bModified )
618 aImage = Image( aBitmapEx );
621 return aImage;
624 /** Copied from svtools/inc/acceleratorexecute.hxx */
625 css::awt::KeyEvent lcl_VCLKey2AWTKey(
626 const vcl::KeyCode& aVCLKey)
628 css::awt::KeyEvent aAWTKey;
629 aAWTKey.Modifiers = 0;
630 aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode();
632 if (aVCLKey.IsShift())
633 aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
634 if (aVCLKey.IsMod1())
635 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
636 if (aVCLKey.IsMod2())
637 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
638 if (aVCLKey.IsMod3())
639 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
641 return aAWTKey;
644 vcl::KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
646 bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
647 bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
648 bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
649 bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
650 sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode;
652 return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
658 sal_Bool SAL_CALL VCLXMenu::isPopupMenu( )
659 throw (css::uno::RuntimeException, std::exception)
661 SolarMutexGuard aSolarGuard;
662 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
663 return IsPopupMenu();
666 void SAL_CALL VCLXMenu::clear( )
667 throw (css::uno::RuntimeException, std::exception)
669 SolarMutexGuard aSolarGuard;
670 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
671 if ( mpMenu )
672 mpMenu->Clear();
676 css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType(
677 ::sal_Int16 nItemPos )
678 throw (css::uno::RuntimeException, std::exception)
680 SolarMutexGuard aSolarGuard;
681 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
683 css::awt::MenuItemType aMenuItemType =
684 css::awt::MenuItemType_DONTKNOW;
685 if ( mpMenu )
687 aMenuItemType = ( (css::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) );
690 return aMenuItemType;
693 void SAL_CALL VCLXMenu::hideDisabledEntries(
694 sal_Bool bHide )
695 throw (css::uno::RuntimeException, std::exception)
697 SolarMutexGuard aSolarGuard;
698 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
699 if ( mpMenu )
701 if ( bHide )
702 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries );
703 else
704 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::HideDisabledEntries );
709 sal_Bool SAL_CALL VCLXMenu::isInExecute( )
710 throw (css::uno::RuntimeException, std::exception)
712 SolarMutexGuard aSolarGuard;
713 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
715 if ( mpMenu && IsPopupMenu() )
716 return PopupMenu::IsInExecute();
717 else
718 return false;
722 void SAL_CALL VCLXMenu::endExecute()
723 throw (css::uno::RuntimeException, std::exception)
725 SolarMutexGuard aSolarGuard;
726 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
728 if ( mpMenu && IsPopupMenu() )
729 static_cast<PopupMenu*>( mpMenu )->EndExecute();
733 void SAL_CALL VCLXMenu::enableAutoMnemonics(
734 sal_Bool bEnable )
735 throw (css::uno::RuntimeException, std::exception)
737 SolarMutexGuard aSolarGuard;
738 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
739 if ( mpMenu )
741 if ( !bEnable )
742 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
743 else
744 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics );
749 void SAL_CALL VCLXMenu::setAcceleratorKeyEvent(
750 ::sal_Int16 nItemId,
751 const css::awt::KeyEvent& aKeyEvent )
752 throw (css::uno::RuntimeException, std::exception)
754 SolarMutexGuard aSolarGuard;
755 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
757 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
759 vcl::KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent );
760 mpMenu->SetAccelKey( nItemId, aVCLKeyCode );
765 css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent(
766 ::sal_Int16 nItemId )
767 throw (css::uno::RuntimeException, std::exception)
769 SolarMutexGuard aSolarGuard;
770 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
772 css::awt::KeyEvent aKeyEvent;
773 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
775 vcl::KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId );
776 aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode );
779 return aKeyEvent;
783 void SAL_CALL VCLXMenu::setHelpText(
784 ::sal_Int16 nItemId,
785 const OUString& sHelpText )
786 throw (css::uno::RuntimeException, std::exception)
788 SolarMutexGuard aSolarGuard;
789 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
791 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
793 mpMenu->SetHelpText( nItemId, sHelpText );
798 OUString SAL_CALL VCLXMenu::getHelpText(
799 ::sal_Int16 nItemId )
800 throw (css::uno::RuntimeException, std::exception)
802 SolarMutexGuard aSolarGuard;
803 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
805 OUString sHelpText;
806 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
808 sHelpText = mpMenu->GetHelpText( nItemId );
811 return sHelpText;
815 void SAL_CALL VCLXMenu::setTipHelpText(
816 ::sal_Int16 nItemId,
817 const OUString& sTipHelpText )
818 throw (css::uno::RuntimeException, std::exception)
820 SolarMutexGuard aSolarGuard;
821 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
823 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
825 mpMenu->SetTipHelpText( nItemId, sTipHelpText );
830 OUString SAL_CALL VCLXMenu::getTipHelpText(
831 ::sal_Int16 nItemId )
832 throw (css::uno::RuntimeException, std::exception)
834 SolarMutexGuard aSolarGuard;
835 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
837 OUString sTipHelpText;
838 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
840 sTipHelpText = mpMenu->GetTipHelpText( nItemId );
842 return sTipHelpText;
846 void SAL_CALL VCLXMenu::setItemImage(
847 ::sal_Int16 nItemId,
848 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
849 sal_Bool bScale )
850 throw (css::uno::RuntimeException, std::exception)
852 SolarMutexGuard aSolarGuard;
853 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
855 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
857 Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale );
858 mpMenu->SetItemImage( nItemId, aImage );
863 css::uno::Reference< css::graphic::XGraphic > SAL_CALL
864 VCLXMenu::getItemImage(
865 ::sal_Int16 nItemId )
866 throw (css::uno::RuntimeException, std::exception)
868 SolarMutexGuard aSolarGuard;
869 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
871 css::uno::Reference< css::graphic::XGraphic > rxGraphic;
873 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
875 Image aImage = mpMenu->GetItemImage( nItemId );
876 if ( !!aImage )
877 rxGraphic = aImage.GetXGraphic();
879 return rxGraphic;
882 VCLXMenuBar::VCLXMenuBar()
884 ImplCreateMenu( false );
887 VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( static_cast<Menu *>(pMenuBar) )
891 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
892 stardiv_Toolkit_VCLXMenuBar_get_implementation(
893 css::uno::XComponentContext *,
894 css::uno::Sequence<css::uno::Any> const &)
896 return cppu::acquire(new VCLXMenuBar());
899 VCLXPopupMenu::VCLXPopupMenu()
901 ImplCreateMenu( true );
904 VCLXPopupMenu::VCLXPopupMenu( PopupMenu* pPopMenu ) : VCLXMenu( static_cast<Menu *>(pPopMenu) )
908 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
909 stardiv_Toolkit_VCLXPopupMenu_get_implementation(
910 css::uno::XComponentContext *,
911 css::uno::Sequence<css::uno::Any> const &)
913 return cppu::acquire(new VCLXPopupMenu());
916 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */