1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <toolkit/awt/vclxmenu.hxx>
21 #include <toolkit/helper/macros.hxx>
22 #include <toolkit/helper/servicenames.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <toolkit/helper/convert.hxx>
25 #include <cppuhelper/typeprovider.hxx>
27 #include <osl/mutex.hxx>
29 #include <vcl/menu.hxx>
30 #include <vcl/keycod.hxx>
31 #include <vcl/image.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include <vcl/svapp.hxx>
35 #include <com/sun/star/awt/KeyModifier.hpp>
39 #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
40 if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
41 throw ::com::sun::star::container::NoSuchElementException( \
42 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
43 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item with " ) ) \
44 += ::rtl::OUString::valueOf( sal_Int32( nItemId ) ) \
45 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " as identifier" ) ), \
48 #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
49 if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
50 throw ::com::sun::star::container::NoSuchElementException( \
51 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
52 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item at position " ) ) \
53 += ::rtl::OUString::valueOf( sal_Int32( nPos ) ), \
57 #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
58 if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
59 throw ::com::sun::star::container::NoSuchElementException();
60 #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
61 if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
62 throw ::com::sun::star::container::NoSuchElementException();
66 // ----------------------------------------------------
68 // ----------------------------------------------------
72 VCLXMenu::VCLXMenu() : maMenuListeners( *this )
74 DBG_CTOR( VCLXMenu
, 0 );
78 VCLXMenu::VCLXMenu( Menu
* pMenu
) : maMenuListeners( *this )
80 DBG_CTOR( VCLXMenu
, 0 );
86 DBG_DTOR( VCLXMenu
, 0 );
87 for ( size_t n
= maPopupMenueRefs
.size(); n
; ) {
88 delete maPopupMenueRefs
[ --n
];
92 mpMenu
->RemoveEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
97 sal_Bool
VCLXMenu::IsPopupMenu() const
99 return (mpMenu
&& ! mpMenu
->IsMenuBar());
102 void VCLXMenu::ImplCreateMenu( sal_Bool bPopup
)
104 DBG_ASSERT( !mpMenu
, "CreateMenu: Menu exists!" );
107 mpMenu
= new PopupMenu
;
109 mpMenu
= new MenuBar
;
111 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
114 IMPL_LINK( VCLXMenu
, MenuEventListener
, VclSimpleEvent
*, pEvent
)
116 DBG_ASSERT( pEvent
&& pEvent
->ISA( VclMenuEvent
), "Unknown Event!" );
117 if ( pEvent
&& pEvent
->ISA( VclMenuEvent
) )
119 DBG_ASSERT( ((VclMenuEvent
*)pEvent
)->GetMenu() && mpMenu
, "Menu???" );
121 VclMenuEvent
* pMenuEvent
= (VclMenuEvent
*)pEvent
;
122 if ( pMenuEvent
->GetMenu() == mpMenu
) // Also called for the root menu
124 switch ( pMenuEvent
->GetId() )
126 case VCLEVENT_MENU_SELECT
:
128 if ( maMenuListeners
.getLength() )
130 ::com::sun::star::awt::MenuEvent aEvent
;
131 aEvent
.Source
= (::cppu::OWeakObject
*)this;
132 aEvent
.MenuId
= mpMenu
->GetCurItemId();
133 maMenuListeners
.select( aEvent
);
137 case VCLEVENT_OBJECT_DYING
:
142 case VCLEVENT_MENU_HIGHLIGHT
:
144 if ( maMenuListeners
.getLength() )
146 ::com::sun::star::awt::MenuEvent aEvent
;
147 aEvent
.Source
= (::cppu::OWeakObject
*)this;
148 aEvent
.MenuId
= mpMenu
->GetCurItemId();
149 maMenuListeners
.highlight( aEvent
);
153 case VCLEVENT_MENU_ACTIVATE
:
155 if ( maMenuListeners
.getLength() )
157 ::com::sun::star::awt::MenuEvent aEvent
;
158 aEvent
.Source
= (::cppu::OWeakObject
*)this;
159 aEvent
.MenuId
= mpMenu
->GetCurItemId();
160 maMenuListeners
.activate( aEvent
);
164 case VCLEVENT_MENU_DEACTIVATE
:
166 if ( maMenuListeners
.getLength() )
168 ::com::sun::star::awt::MenuEvent aEvent
;
169 aEvent
.Source
= (::cppu::OWeakObject
*)this;
170 aEvent
.MenuId
= mpMenu
->GetCurItemId();
171 maMenuListeners
.deactivate( aEvent
);
176 // ignore accessibility events
177 case VCLEVENT_MENU_ENABLE
:
178 case VCLEVENT_MENU_INSERTITEM
:
179 case VCLEVENT_MENU_REMOVEITEM
:
180 case VCLEVENT_MENU_SUBMENUACTIVATE
:
181 case VCLEVENT_MENU_SUBMENUDEACTIVATE
:
182 case VCLEVENT_MENU_SUBMENUCHANGED
:
183 case VCLEVENT_MENU_DEHIGHLIGHT
:
184 case VCLEVENT_MENU_DISABLE
:
185 case VCLEVENT_MENU_ITEMTEXTCHANGED
:
186 case VCLEVENT_MENU_ITEMCHECKED
:
187 case VCLEVENT_MENU_ITEMUNCHECKED
:
188 case VCLEVENT_MENU_SHOW
:
189 case VCLEVENT_MENU_HIDE
:
192 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
200 //=============================================================================
201 //=============================================================================
202 //=============================================================================
205 // ::com::sun::star::lang::XServiceInfo
206 ::rtl::OUString SAL_CALL
VCLXMenu::getImplementationName( )
207 throw (::com::sun::star::uno::RuntimeException
)
209 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
210 const sal_Bool bIsPopupMenu
= IsPopupMenu();
213 ::rtl::OUString
implName( RTL_CONSTASCII_USTRINGPARAM( "stardiv.Toolkit." ) );
215 implName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXPopupMenu" ) );
217 implName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXMenuBar" ) );
223 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
VCLXMenu::getSupportedServiceNames( )
224 throw (::com::sun::star::uno::RuntimeException
)
226 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
227 const sal_Bool bIsPopupMenu
= IsPopupMenu();
230 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aNames( 1 );
232 aNames
[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_PopupMenu
);
234 aNames
[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_MenuBar
);
240 ::sal_Bool SAL_CALL
VCLXMenu::supportsService( const ::rtl::OUString
& rServiceName
)
241 throw (::com::sun::star::uno::RuntimeException
)
243 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aServiceNames( getSupportedServiceNames() );
245 if ( aServiceNames
[ 0 ] == rServiceName
)
252 // ::com::sun::star::uno::XInterface
253 ::com::sun::star::uno::Any
VCLXMenu::queryInterface( const ::com::sun::star::uno::Type
& rType
)
254 throw(::com::sun::star::uno::RuntimeException
)
256 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
257 const sal_Bool bIsPopupMenu
= IsPopupMenu();
260 ::com::sun::star::uno::Any aRet
;
263 aRet
= ::cppu::queryInterface( rType
,
264 (static_cast< ::com::sun::star::awt::XMenu
* >((::com::sun::star::awt::XMenuBar
*) this) ),
265 (static_cast< ::com::sun::star::awt::XPopupMenu
* >(this)),
266 (static_cast< ::com::sun::star::awt::XPopupMenuExtended
* >(this)),
267 (static_cast< ::com::sun::star::awt::XMenuExtended
* >((::com::sun::star::awt::XPopupMenuExtended
*) this) ),
268 (static_cast< ::com::sun::star::awt::XMenuExtended2
* >((::com::sun::star::awt::XPopupMenuExtended
*) this) ),
269 (static_cast< ::com::sun::star::lang::XTypeProvider
* >(this)),
270 (static_cast< ::com::sun::star::lang::XServiceInfo
* >(this)),
271 (static_cast< ::com::sun::star::lang::XUnoTunnel
* >(this)) );
273 aRet
= ::cppu::queryInterface( rType
,
274 (static_cast< ::com::sun::star::awt::XMenu
* >((::com::sun::star::awt::XMenuBar
*) this) ),
275 (static_cast< ::com::sun::star::awt::XMenuBar
* >(this)),
276 (static_cast< ::com::sun::star::awt::XMenuBarExtended
* >(this)),
277 (static_cast< ::com::sun::star::awt::XMenuExtended
* >((::com::sun::star::awt::XMenuBarExtended
*) this) ),
278 (static_cast< ::com::sun::star::awt::XMenuExtended2
* >((::com::sun::star::awt::XMenuBarExtended
*) this) ),
279 (static_cast< ::com::sun::star::lang::XTypeProvider
* >(this)),
280 (static_cast< ::com::sun::star::lang::XServiceInfo
* >(this)),
281 (static_cast< ::com::sun::star::lang::XUnoTunnel
* >(this)) );
283 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
286 // ::com::sun::star::lang::XUnoTunnel
287 IMPL_XUNOTUNNEL( VCLXMenu
)
289 // ::com::sun::star::lang::XTypeProvider
290 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> VCLXMenu::getTypes()
291 throw(::com::sun::star::uno::RuntimeException
)
293 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
294 const sal_Bool bIsPopupMenu
= IsPopupMenu();
297 static ::cppu::OTypeCollection
* pCollectionMenuBar
= NULL
;
298 static ::cppu::OTypeCollection
* pCollectionPopupMenu
= NULL
;
302 if( !pCollectionPopupMenu
)
304 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
305 if( !pCollectionPopupMenu
)
307 static ::cppu::OTypeCollection
collectionPopupMenu(
308 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XTypeProvider
>* ) NULL
),
309 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenu
>* ) NULL
),
310 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
>* ) NULL
),
311 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenuExtended
>* ) NULL
),
312 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended
>* ) NULL
),
313 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended2
>* ) NULL
),
314 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>* ) NULL
) );
315 pCollectionPopupMenu
= &collectionPopupMenu
;
319 return (*pCollectionPopupMenu
).getTypes();
323 if( !pCollectionMenuBar
)
325 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
326 if( !pCollectionMenuBar
)
328 static ::cppu::OTypeCollection
collectionMenuBar(
329 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XTypeProvider
>* ) NULL
),
330 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenu
>* ) NULL
),
331 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuBar
>* ) NULL
),
332 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuBarExtended
>* ) NULL
),
333 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended
>* ) NULL
),
334 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended2
>* ) NULL
),
335 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>* ) NULL
) );
336 pCollectionMenuBar
= &collectionMenuBar
;
339 return (*pCollectionMenuBar
).getTypes();
344 ::com::sun::star::uno::Sequence
< sal_Int8
> VCLXMenu::getImplementationId()
345 throw(::com::sun::star::uno::RuntimeException
)
347 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
348 const sal_Bool bIsPopupMenu
= IsPopupMenu();
351 static ::cppu::OImplementationId
* pIdMenuBar
= NULL
;
352 static ::cppu::OImplementationId
* pIdPopupMenu
= NULL
;
358 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
361 static ::cppu::OImplementationId
idPopupMenu( sal_False
);
362 pIdPopupMenu
= &idPopupMenu
;
366 return (*pIdPopupMenu
).getImplementationId();
372 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
375 static ::cppu::OImplementationId
idMenuBar( sal_False
);
376 pIdMenuBar
= &idMenuBar
;
380 return (*pIdMenuBar
).getImplementationId();
385 //=============================================================================
386 //=============================================================================
387 //=============================================================================
390 void VCLXMenu::addMenuListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
392 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
394 maMenuListeners
.addInterface( rxListener
);
397 void VCLXMenu::removeMenuListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
399 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
401 maMenuListeners
.removeInterface( rxListener
);
404 void VCLXMenu::insertItem( sal_Int16 nItemId
, const ::rtl::OUString
& aText
, sal_Int16 nItemStyle
, sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
406 SolarMutexGuard aSolarGuard
;
407 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
410 mpMenu
->InsertItem( nItemId
, aText
, (MenuItemBits
)nItemStyle
, nPos
);
413 void VCLXMenu::removeItem( sal_Int16 nPos
, sal_Int16 nCount
) throw(::com::sun::star::uno::RuntimeException
)
415 SolarMutexGuard aSolarGuard
;
416 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
418 sal_Int32 nItemCount
= (sal_Int32
)mpMenu
->GetItemCount();
419 if ( mpMenu
&& ( nCount
> 0 ) && ( nPos
>= 0 ) && ( nPos
< nItemCount
) && ( nItemCount
> 0 ))
421 sal_Int16 nP
= sal::static_int_cast
< sal_Int16
>(
422 Min( (int)(nPos
+nCount
), (int)nItemCount
));
424 mpMenu
->RemoveItem( --nP
);
428 sal_Int16
VCLXMenu::getItemCount( ) throw(::com::sun::star::uno::RuntimeException
)
430 SolarMutexGuard aSolarGuard
;
431 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
433 return mpMenu
? mpMenu
->GetItemCount() : 0;
436 sal_Int16
VCLXMenu::getItemId( sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
438 SolarMutexGuard aSolarGuard
;
439 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
441 return mpMenu
? mpMenu
->GetItemId( nPos
) : 0;
444 sal_Int16
VCLXMenu::getItemPos( sal_Int16 nId
) throw(::com::sun::star::uno::RuntimeException
)
446 SolarMutexGuard aSolarGuard
;
447 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
449 return mpMenu
? mpMenu
->GetItemPos( nId
) : 0;
452 void VCLXMenu::enableItem( sal_Int16 nItemId
, sal_Bool bEnable
) throw(::com::sun::star::uno::RuntimeException
)
454 SolarMutexGuard aSolarGuard
;
455 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
458 mpMenu
->EnableItem( nItemId
, bEnable
);
461 sal_Bool
VCLXMenu::isItemEnabled( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
463 SolarMutexGuard aSolarGuard
;
464 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
466 return mpMenu
? mpMenu
->IsItemEnabled( nItemId
) : sal_False
;
469 void VCLXMenu::setItemText( sal_Int16 nItemId
, const ::rtl::OUString
& aText
) throw(::com::sun::star::uno::RuntimeException
)
471 SolarMutexGuard aSolarGuard
;
472 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
475 mpMenu
->SetItemText( nItemId
, aText
);
478 ::rtl::OUString
VCLXMenu::getItemText( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
480 SolarMutexGuard aSolarGuard
;
481 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
483 ::rtl::OUString aItemText
;
485 aItemText
= mpMenu
->GetItemText( nItemId
);
489 void VCLXMenu::setPopupMenu( sal_Int16 nItemId
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
>& rxPopupMenu
) throw(::com::sun::star::uno::RuntimeException
)
491 SolarMutexGuard aSolarGuard
;
492 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
494 VCLXMenu
* pVCLMenu
= VCLXMenu::GetImplementation( rxPopupMenu
);
495 DBG_ASSERT( pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
497 if ( mpMenu
&& pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu() )
499 // Selbst eine Ref halten!
500 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pNewRef
= new ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> ;
501 *pNewRef
= rxPopupMenu
;
502 maPopupMenueRefs
.push_back( pNewRef
);
504 mpMenu
->SetPopupMenu( nItemId
, (PopupMenu
*) pVCLMenu
->GetMenu() );
508 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> VCLXMenu::getPopupMenu( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
510 SolarMutexGuard aSolarGuard
;
511 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
513 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> aRef
;
514 Menu
* pMenu
= mpMenu
? mpMenu
->GetPopupMenu( nItemId
) : NULL
;
517 for ( size_t n
= maPopupMenueRefs
.size(); n
; )
519 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pRef
= maPopupMenueRefs
[ --n
];
520 Menu
* pM
= ((VCLXMenu
*)pRef
->get())->GetMenu();
527 // it seems the popup menu is not insert into maPopupMenueRefs
528 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
531 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pNewRef
= new ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> ;
532 *pNewRef
= new VCLXPopupMenu( (PopupMenu
*)pMenu
);
539 // ::com::sun::star::awt::XPopupMenu
540 void VCLXMenu::insertSeparator( sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
542 SolarMutexGuard aSolarGuard
;
543 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
546 mpMenu
->InsertSeparator( nPos
);
549 void VCLXMenu::setDefaultItem( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
551 SolarMutexGuard aSolarGuard
;
552 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
555 mpMenu
->SetDefaultItem( nItemId
);
558 sal_Int16
VCLXMenu::getDefaultItem( ) throw(::com::sun::star::uno::RuntimeException
)
560 SolarMutexGuard aSolarGuard
;
561 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
563 return mpMenu
? mpMenu
->GetDefaultItem() : 0;
566 void VCLXMenu::checkItem( sal_Int16 nItemId
, sal_Bool bCheck
) throw(::com::sun::star::uno::RuntimeException
)
568 SolarMutexGuard aSolarGuard
;
569 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
572 mpMenu
->CheckItem( nItemId
, bCheck
);
575 sal_Bool
VCLXMenu::isItemChecked( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
577 SolarMutexGuard aSolarGuard
;
578 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
580 return mpMenu
? mpMenu
->IsItemChecked( nItemId
) : sal_False
;
583 sal_Int16
VCLXMenu::execute( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& rxWindowPeer
, const ::com::sun::star::awt::Rectangle
& rArea
, sal_Int16 nFlags
) throw(::com::sun::star::uno::RuntimeException
)
585 SolarMutexGuard aSolarGuard
;
586 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
589 if ( mpMenu
&& IsPopupMenu() )
590 nRet
= ((PopupMenu
*)mpMenu
)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer
), VCLRectangle(rArea
), nFlags
| POPUPMENU_NOMOUSEUPCLOSE
);
595 void SAL_CALL
VCLXMenu::setCommand( sal_Int16 nItemId
, const ::rtl::OUString
& aCommand
) throw (::com::sun::star::uno::RuntimeException
)
597 SolarMutexGuard aSolarGuard
;
598 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
601 mpMenu
->SetItemCommand( nItemId
, aCommand
);
604 ::rtl::OUString SAL_CALL
VCLXMenu::getCommand( sal_Int16 nItemId
) throw (::com::sun::star::uno::RuntimeException
)
606 SolarMutexGuard aSolarGuard
;
607 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
609 ::rtl::OUString aItemCommand
;
611 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
615 void SAL_CALL
VCLXMenu::setHelpCommand( sal_Int16 nItemId
, const ::rtl::OUString
& aHelp
) throw (::com::sun::star::uno::RuntimeException
)
617 SolarMutexGuard aSolarGuard
;
618 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
621 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
624 ::rtl::OUString SAL_CALL
VCLXMenu::getHelpCommand( sal_Int16 nItemId
) throw (::com::sun::star::uno::RuntimeException
)
626 SolarMutexGuard aSolarGuard
;
627 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
629 ::rtl::OUString aHelpCommand
;
631 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
636 // ============================================================================
637 // ============================================================================
638 // ============================================================================
641 // BEGIN ANONYMOUS NAMESPACE
644 Image
lcl_XGraphic2VCLImage(
645 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
649 if ( !xGraphic
.is() )
652 aImage
= Image( xGraphic
);
653 const ::Size aCurSize
= aImage
.GetSizePixel();
654 const sal_Int32 nCurWidth
= aCurSize
.Width();
655 const sal_Int32 nCurHeight
= aCurSize
.Height();
656 const sal_Int32
nIdeal( 16 );
658 if ( nCurWidth
> 0 && nCurHeight
> 0 )
660 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
662 sal_Int32 nIdealWidth
= nCurWidth
> nIdeal
? nIdeal
: nCurWidth
;
663 sal_Int32 nIdealHeight
= nCurHeight
> nIdeal
? nIdeal
: nCurHeight
;
665 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
667 sal_Bool
bModified( sal_False
);
668 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
669 bModified
= aBitmapEx
.Scale( aNewSize
, BMP_SCALE_BEST
);
672 aImage
= Image( aBitmapEx
);
679 As svtools builds after toolkit, we can not include/use
680 svtools/inc/acceleratorexecute.hxx
681 So I just copy here svt::AcceleratorExecute::st_AWTKey2VCLKey
682 and svt::AcceleratorExecute::st_VCLKey2AWTKey
684 css::awt::KeyEvent
lcl_VCLKey2AWTKey(const KeyCode
& aVCLKey
)
686 css::awt::KeyEvent aAWTKey
;
687 aAWTKey
.Modifiers
= 0;
688 aAWTKey
.KeyCode
= (sal_Int16
)aVCLKey
.GetCode();
690 if (aVCLKey
.IsShift())
691 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
692 if (aVCLKey
.IsMod1())
693 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
694 if (aVCLKey
.IsMod2())
695 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
696 if (aVCLKey
.IsMod3())
697 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
702 KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
704 sal_Bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
705 sal_Bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
706 sal_Bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
707 sal_Bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
708 sal_uInt16 nKey
= (sal_uInt16
)aAWTKey
.KeyCode
;
710 return KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
713 } // END ANONYMOUS NAMESPACE
716 // ============================================================================
717 // ============================================================================
718 // ============================================================================
721 // XMenuExtended2 Methods
723 ::sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( ) throw (::com::sun::star::uno::RuntimeException
)
725 SolarMutexGuard aSolarGuard
;
726 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
727 return IsPopupMenu();
730 void SAL_CALL
VCLXMenu::clear( ) throw (::com::sun::star::uno::RuntimeException
)
732 SolarMutexGuard aSolarGuard
;
733 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
739 ::com::sun::star::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType( ::sal_Int16 nItemPos
)
740 throw ( ::com::sun::star::container::NoSuchElementException
,
741 ::com::sun::star::uno::RuntimeException
)
743 SolarMutexGuard aSolarGuard
;
744 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
746 ::com::sun::star::awt::MenuItemType aMenuItemType
=
747 ::com::sun::star::awt::MenuItemType_DONTKNOW
;
750 THROW_MENUPOS_NOT_FOUND( "VCLXMenu::getItemType()", nItemPos
)
751 aMenuItemType
= ( (::com::sun::star::awt::MenuItemType
) mpMenu
->GetItemType( nItemPos
) );
754 return aMenuItemType
;
757 void SAL_CALL
VCLXMenu::hideDisabledEntries( ::sal_Bool bHide
)
758 throw (::com::sun::star::uno::RuntimeException
)
760 SolarMutexGuard aSolarGuard
;
761 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
765 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES
);
767 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES
);
772 // ============================================================================
773 // ============================================================================
774 // ============================================================================
777 // XPopupMenuExtended Methods
779 ::sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
780 throw (::com::sun::star::uno::RuntimeException
)
782 SolarMutexGuard aSolarGuard
;
783 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
785 if ( mpMenu
&& IsPopupMenu() )
786 return ( (PopupMenu
*) mpMenu
)->IsInExecute();
792 void SAL_CALL
VCLXMenu::endExecute()
793 throw (::com::sun::star::uno::RuntimeException
)
795 SolarMutexGuard aSolarGuard
;
796 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
798 if ( mpMenu
&& IsPopupMenu() )
799 ( (PopupMenu
*) mpMenu
)->EndExecute();
803 void SAL_CALL
VCLXMenu::setLogo( const ::com::sun::star::awt::MenuLogo
& aMenuLogo
)
804 throw (::com::sun::star::uno::RuntimeException
)
806 SolarMutexGuard aSolarGuard
;
807 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
811 if ( aMenuLogo
.Graphic
.is() )
813 Image aImage
= lcl_XGraphic2VCLImage( aMenuLogo
.Graphic
, sal_False
);
814 MenuLogo aVCLMenuLogo
;
816 aVCLMenuLogo
.aBitmap
= aImage
.GetBitmapEx();
817 aVCLMenuLogo
.aStartColor
= Color( (sal_uInt32
)(aMenuLogo
.StartColor
) );
818 aVCLMenuLogo
.aEndColor
= Color( (sal_uInt32
)(aMenuLogo
.EndColor
) );
820 mpMenu
->SetLogo( aVCLMenuLogo
);
828 ::com::sun::star::awt::MenuLogo SAL_CALL
VCLXMenu::getLogo( )
829 throw (::com::sun::star::uno::RuntimeException
)
831 SolarMutexGuard aSolarGuard
;
832 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
834 ::com::sun::star::awt::MenuLogo aAWTMenuLogo
;
837 if ( mpMenu
->HasLogo() )
839 MenuLogo aVCLMenuLogo
= mpMenu
->GetLogo();
840 aAWTMenuLogo
.Graphic
= Image(aVCLMenuLogo
.aBitmap
).GetXGraphic();
841 aAWTMenuLogo
.StartColor
= aVCLMenuLogo
.aStartColor
.GetColor();
842 aAWTMenuLogo
.EndColor
= aVCLMenuLogo
.aEndColor
.GetColor();
849 void SAL_CALL
VCLXMenu::enableAutoMnemonics( ::sal_Bool bEnable
)
850 throw (::com::sun::star::uno::RuntimeException
)
852 SolarMutexGuard aSolarGuard
;
853 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
857 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
859 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS
);
864 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent( ::sal_Int16 nItemId
,
865 const ::com::sun::star::awt::KeyEvent
& aKeyEvent
)
866 throw ( ::com::sun::star::container::NoSuchElementException
,
867 ::com::sun::star::uno::RuntimeException
)
869 SolarMutexGuard aSolarGuard
;
870 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
872 if ( mpMenu
&& IsPopupMenu() )
874 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setAcceleratorKeyEvent()", nItemId
)
875 KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
876 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
881 ::com::sun::star::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent( ::sal_Int16 nItemId
)
882 throw ( ::com::sun::star::container::NoSuchElementException
,
883 ::com::sun::star::uno::RuntimeException
)
885 SolarMutexGuard aSolarGuard
;
886 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
888 ::com::sun::star::awt::KeyEvent aKeyEvent
;
889 if ( mpMenu
&& IsPopupMenu() )
891 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getAcceleratorKeyEvent()", nItemId
)
892 KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
893 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
900 void SAL_CALL
VCLXMenu::setHelpText( ::sal_Int16 nItemId
, const ::rtl::OUString
& sHelpText
)
901 throw ( ::com::sun::star::container::NoSuchElementException
,
902 ::com::sun::star::uno::RuntimeException
)
904 SolarMutexGuard aSolarGuard
;
905 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
907 if ( mpMenu
&& IsPopupMenu() )
909 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setHelpText()", nItemId
)
910 mpMenu
->SetHelpText( nItemId
, sHelpText
);
915 ::rtl::OUString SAL_CALL
VCLXMenu::getHelpText( ::sal_Int16 nItemId
)
916 throw ( ::com::sun::star::container::NoSuchElementException
,
917 ::com::sun::star::uno::RuntimeException
)
919 SolarMutexGuard aSolarGuard
;
920 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
922 rtl::OUString sHelpText
;
923 if ( mpMenu
&& IsPopupMenu() )
925 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getHelpText()", nItemId
)
926 sHelpText
= mpMenu
->GetHelpText( nItemId
);
933 void SAL_CALL
VCLXMenu::setTipHelpText( ::sal_Int16 nItemId
, const ::rtl::OUString
& sTipHelpText
)
934 throw ( ::com::sun::star::container::NoSuchElementException
,
935 ::com::sun::star::uno::RuntimeException
)
937 SolarMutexGuard aSolarGuard
;
938 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
940 if ( mpMenu
&& IsPopupMenu() )
942 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setTipHelpText()", nItemId
)
943 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
948 ::rtl::OUString SAL_CALL
VCLXMenu::getTipHelpText( ::sal_Int16 nItemId
)
949 throw ( ::com::sun::star::container::NoSuchElementException
,
950 ::com::sun::star::uno::RuntimeException
)
952 SolarMutexGuard aSolarGuard
;
953 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
955 rtl::OUString sTipHelpText
;
956 if ( mpMenu
&& IsPopupMenu() )
958 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getTipHelpText()", nItemId
)
959 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
965 void SAL_CALL
VCLXMenu::setItemImage(
967 const ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>& xGraphic
, ::sal_Bool bScale
)
968 throw ( ::com::sun::star::container::NoSuchElementException
,
969 ::com::sun::star::uno::RuntimeException
)
971 SolarMutexGuard aSolarGuard
;
972 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
974 if ( mpMenu
&& IsPopupMenu() )
976 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImage()", nItemId
)
977 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
978 mpMenu
->SetItemImage( nItemId
, aImage
);
983 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> SAL_CALL
VCLXMenu::getItemImage( ::sal_Int16 nItemId
)
984 throw ( ::com::sun::star::container::NoSuchElementException
,
985 ::com::sun::star::uno::RuntimeException
)
987 SolarMutexGuard aSolarGuard
;
988 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
990 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> rxGraphic
;
992 if ( mpMenu
&& IsPopupMenu() )
994 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImage()", nItemId
)
995 Image aImage
= mpMenu
->GetItemImage( nItemId
);
997 rxGraphic
= aImage
.GetXGraphic();
1003 void SAL_CALL
VCLXMenu::setItemImageAngle( ::sal_Int16 nItemId
, ::sal_Int32 nAngle
)
1004 throw ( ::com::sun::star::container::NoSuchElementException
,
1005 ::com::sun::star::uno::RuntimeException
)
1007 SolarMutexGuard aSolarGuard
;
1008 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1010 if ( mpMenu
&& IsPopupMenu() )
1012 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageAngle()", nItemId
)
1013 mpMenu
->SetItemImageAngle( nItemId
, nAngle
);
1018 ::sal_Int32 SAL_CALL
VCLXMenu::getItemImageAngle( ::sal_Int16 nItemId
)
1019 throw ( ::com::sun::star::container::NoSuchElementException
,
1020 ::com::sun::star::uno::RuntimeException
)
1022 SolarMutexGuard aSolarGuard
;
1023 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1025 ::sal_Int32
nItemImageAngle( 0 );
1026 if ( mpMenu
&& IsPopupMenu() )
1028 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImageAngle()", nItemId
)
1029 nItemImageAngle
= mpMenu
->GetItemImageAngle( nItemId
);
1031 return nItemImageAngle
;
1035 void SAL_CALL
VCLXMenu::setItemImageMirrorMode( ::sal_Int16 nItemId
, ::sal_Bool bMirror
)
1036 throw ( ::com::sun::star::container::NoSuchElementException
,
1037 ::com::sun::star::uno::RuntimeException
)
1039 SolarMutexGuard aSolarGuard
;
1040 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1042 if ( mpMenu
&& IsPopupMenu() )
1044 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageMirrorMode()", nItemId
)
1045 mpMenu
->SetItemImageMirrorMode( nItemId
, bMirror
);
1050 ::sal_Bool SAL_CALL
VCLXMenu::isItemImageInMirrorMode( ::sal_Int16 nItemId
)
1051 throw ( ::com::sun::star::container::NoSuchElementException
,
1052 ::com::sun::star::uno::RuntimeException
)
1054 SolarMutexGuard aSolarGuard
;
1055 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1057 sal_Bool
bMirrorMode( sal_False
);
1058 if ( mpMenu
&& IsPopupMenu() )
1060 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::isItemImageInMirrorMode()", nItemId
)
1061 bMirrorMode
= mpMenu
->GetItemImageMirrorMode( nItemId
);
1067 // ----------------------------------------------------
1068 // class VCLXMenuBar
1069 // ----------------------------------------------------
1071 DBG_NAME(VCLXMenuBar
);
1073 VCLXMenuBar::VCLXMenuBar()
1075 DBG_CTOR( VCLXMenuBar
, 0 );
1076 ImplCreateMenu( sal_False
);
1079 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( (Menu
*)pMenuBar
)
1081 DBG_CTOR( VCLXMenuBar
, 0 );
1084 // ----------------------------------------------------
1085 // class VCLXPopupMenu
1086 // ----------------------------------------------------
1088 DBG_NAME(VCLXPopupMenu
);
1090 VCLXPopupMenu::VCLXPopupMenu()
1092 DBG_CTOR( VCLXPopupMenu
, 0 );
1093 ImplCreateMenu( sal_True
);
1096 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( (Menu
*)pPopMenu
)
1098 DBG_CTOR( VCLXPopupMenu
, 0 );
1101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */