1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxmenu.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
35 #include <toolkit/awt/vclxmenu.hxx>
36 #include <toolkit/helper/macros.hxx>
37 #include <toolkit/helper/servicenames.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <toolkit/helper/convert.hxx>
40 #include <cppuhelper/typeprovider.hxx>
41 #include <rtl/memory.h>
44 #include <vcl/menu.hxx>
45 #include <vcl/keycod.hxx>
46 #include <vcl/image.hxx>
47 #include <vcl/mnemonic.hxx>
49 #include <com/sun/star/awt/KeyModifier.hpp>
53 #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
54 if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
55 throw ::com::sun::star::container::NoSuchElementException( \
56 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
57 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item with " ) ) \
58 += ::rtl::OUString::valueOf( sal_Int32( nItemId ) ) \
59 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " as identifier" ) ), \
62 #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
63 if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
64 throw ::com::sun::star::container::NoSuchElementException( \
65 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
66 += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item at position " ) ) \
67 += ::rtl::OUString::valueOf( sal_Int32( nPos ) ), \
71 #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
72 if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
73 throw ::com::sun::star::container::NoSuchElementException();
74 #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
75 if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
76 throw ::com::sun::star::container::NoSuchElementException();
80 // ----------------------------------------------------
82 // ----------------------------------------------------
86 VCLXMenu::VCLXMenu() : maMenuListeners( *this )
88 DBG_CTOR( VCLXMenu
, 0 );
92 VCLXMenu::VCLXMenu( Menu
* pMenu
) : maMenuListeners( *this )
94 DBG_CTOR( VCLXMenu
, 0 );
100 DBG_DTOR( VCLXMenu
, 0 );
101 for ( sal_uInt32 n
= maPopupMenueRefs
.Count(); n
; )
103 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pRef
= maPopupMenueRefs
.GetObject( --n
);
108 mpMenu
->RemoveEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
113 BOOL
VCLXMenu::IsPopupMenu() const
115 return (mpMenu
&& ! mpMenu
->IsMenuBar());
118 void VCLXMenu::ImplCreateMenu( sal_Bool bPopup
)
120 DBG_ASSERT( !mpMenu
, "CreateMenu: Menu exists!" );
123 mpMenu
= new PopupMenu
;
125 mpMenu
= new MenuBar
;
127 mpMenu
->AddEventListener( LINK( this, VCLXMenu
, MenuEventListener
) );
130 IMPL_LINK( VCLXMenu
, MenuEventListener
, VclSimpleEvent
*, pEvent
)
132 DBG_ASSERT( pEvent
&& pEvent
->ISA( VclMenuEvent
), "Unknown Event!" );
133 if ( pEvent
&& pEvent
->ISA( VclMenuEvent
) )
135 DBG_ASSERT( ((VclMenuEvent
*)pEvent
)->GetMenu() && mpMenu
, "Menu???" );
137 VclMenuEvent
* pMenuEvent
= (VclMenuEvent
*)pEvent
;
138 if ( pMenuEvent
->GetMenu() == mpMenu
) // Also called for the root menu
140 switch ( pMenuEvent
->GetId() )
142 case VCLEVENT_MENU_SELECT
:
144 if ( maMenuListeners
.getLength() )
146 ::com::sun::star::awt::MenuEvent aEvent
;
147 aEvent
.Source
= (::cppu::OWeakObject
*)this;
148 aEvent
.MenuId
= mpMenu
->GetCurItemId();
149 maMenuListeners
.select( aEvent
);
153 case VCLEVENT_OBJECT_DYING
:
158 case VCLEVENT_MENU_HIGHLIGHT
:
160 if ( maMenuListeners
.getLength() )
162 ::com::sun::star::awt::MenuEvent aEvent
;
163 aEvent
.Source
= (::cppu::OWeakObject
*)this;
164 aEvent
.MenuId
= mpMenu
->GetCurItemId();
165 maMenuListeners
.highlight( aEvent
);
169 case VCLEVENT_MENU_ACTIVATE
:
171 if ( maMenuListeners
.getLength() )
173 ::com::sun::star::awt::MenuEvent aEvent
;
174 aEvent
.Source
= (::cppu::OWeakObject
*)this;
175 aEvent
.MenuId
= mpMenu
->GetCurItemId();
176 maMenuListeners
.activate( aEvent
);
180 case VCLEVENT_MENU_DEACTIVATE
:
182 if ( maMenuListeners
.getLength() )
184 ::com::sun::star::awt::MenuEvent aEvent
;
185 aEvent
.Source
= (::cppu::OWeakObject
*)this;
186 aEvent
.MenuId
= mpMenu
->GetCurItemId();
187 maMenuListeners
.deactivate( aEvent
);
192 // ignore accessibility events
193 case VCLEVENT_MENU_ENABLE
:
194 case VCLEVENT_MENU_INSERTITEM
:
195 case VCLEVENT_MENU_REMOVEITEM
:
196 case VCLEVENT_MENU_SUBMENUACTIVATE
:
197 case VCLEVENT_MENU_SUBMENUDEACTIVATE
:
198 case VCLEVENT_MENU_SUBMENUCHANGED
:
199 case VCLEVENT_MENU_DEHIGHLIGHT
:
200 case VCLEVENT_MENU_DISABLE
:
201 case VCLEVENT_MENU_ITEMTEXTCHANGED
:
202 case VCLEVENT_MENU_ITEMCHECKED
:
203 case VCLEVENT_MENU_ITEMUNCHECKED
:
204 case VCLEVENT_MENU_SHOW
:
205 case VCLEVENT_MENU_HIDE
:
208 default: DBG_ERROR( "MenuEventListener - Unknown event!" );
216 //=============================================================================
217 //=============================================================================
218 //=============================================================================
221 // ::com::sun::star::lang::XServiceInfo
222 ::rtl::OUString SAL_CALL
VCLXMenu::getImplementationName( )
223 throw (::com::sun::star::uno::RuntimeException
)
225 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
226 const sal_Bool bIsPopupMenu
= IsPopupMenu();
229 ::rtl::OUString
implName( RTL_CONSTASCII_USTRINGPARAM( "stardiv.Toolkit." ) );
231 implName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXPopupMenu" ) );
233 implName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXMenuBar" ) );
239 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
VCLXMenu::getSupportedServiceNames( )
240 throw (::com::sun::star::uno::RuntimeException
)
242 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
243 const sal_Bool bIsPopupMenu
= IsPopupMenu();
246 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aNames( 1 );
248 aNames
[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_PopupMenu
);
250 aNames
[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_MenuBar
);
256 ::sal_Bool SAL_CALL
VCLXMenu::supportsService( const ::rtl::OUString
& rServiceName
)
257 throw (::com::sun::star::uno::RuntimeException
)
259 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aServiceNames( getSupportedServiceNames() );
261 if ( aServiceNames
[ 0 ] == rServiceName
)
268 // ::com::sun::star::uno::XInterface
269 ::com::sun::star::uno::Any
VCLXMenu::queryInterface( const ::com::sun::star::uno::Type
& rType
)
270 throw(::com::sun::star::uno::RuntimeException
)
272 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
273 const sal_Bool bIsPopupMenu
= IsPopupMenu();
276 ::com::sun::star::uno::Any aRet
;
279 aRet
= ::cppu::queryInterface( rType
,
280 SAL_STATIC_CAST( ::com::sun::star::awt::XMenu
*, (::com::sun::star::awt::XMenuBar
*) this ),
281 SAL_STATIC_CAST( ::com::sun::star::awt::XPopupMenu
*, this ),
282 SAL_STATIC_CAST( ::com::sun::star::awt::XPopupMenuExtended
*, this ),
283 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended
*, (::com::sun::star::awt::XPopupMenuExtended
*) this ),
284 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended2
*, (::com::sun::star::awt::XPopupMenuExtended
*) this ),
285 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider
*, this ),
286 SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo
*, this ),
287 SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel
*, this ) );
289 aRet
= ::cppu::queryInterface( rType
,
290 SAL_STATIC_CAST( ::com::sun::star::awt::XMenu
*, (::com::sun::star::awt::XMenuBar
*) this ),
291 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuBar
*, this ),
292 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuBarExtended
*, this ),
293 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended
*, (::com::sun::star::awt::XMenuBarExtended
*) this ),
294 SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended2
*, (::com::sun::star::awt::XMenuBarExtended
*) this ),
295 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider
*, this ),
296 SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo
*, this ),
297 SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel
*, this ) );
299 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
302 // ::com::sun::star::lang::XUnoTunnel
303 IMPL_XUNOTUNNEL( VCLXMenu
)
305 // ::com::sun::star::lang::XTypeProvider
306 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> VCLXMenu::getTypes()
307 throw(::com::sun::star::uno::RuntimeException
)
309 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
310 const sal_Bool bIsPopupMenu
= IsPopupMenu();
313 static ::cppu::OTypeCollection
* pCollectionMenuBar
= NULL
;
314 static ::cppu::OTypeCollection
* pCollectionPopupMenu
= NULL
;
318 if( !pCollectionPopupMenu
)
320 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
321 if( !pCollectionPopupMenu
)
323 static ::cppu::OTypeCollection
collectionPopupMenu(
324 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XTypeProvider
>* ) NULL
),
325 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenu
>* ) NULL
),
326 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
>* ) NULL
),
327 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenuExtended
>* ) NULL
),
328 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended
>* ) NULL
),
329 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended2
>* ) NULL
),
330 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>* ) NULL
) );
331 pCollectionPopupMenu
= &collectionPopupMenu
;
335 return (*pCollectionPopupMenu
).getTypes();
339 if( !pCollectionMenuBar
)
341 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
342 if( !pCollectionMenuBar
)
344 static ::cppu::OTypeCollection
collectionMenuBar(
345 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XTypeProvider
>* ) NULL
),
346 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenu
>* ) NULL
),
347 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuBar
>* ) NULL
),
348 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuBarExtended
>* ) NULL
),
349 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended
>* ) NULL
),
350 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuExtended2
>* ) NULL
),
351 getCppuType( ( ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XServiceInfo
>* ) NULL
) );
352 pCollectionMenuBar
= &collectionMenuBar
;
355 return (*pCollectionMenuBar
).getTypes();
360 ::com::sun::star::uno::Sequence
< sal_Int8
> VCLXMenu::getImplementationId()
361 throw(::com::sun::star::uno::RuntimeException
)
363 ::osl::ResettableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
364 const sal_Bool bIsPopupMenu
= IsPopupMenu();
367 static ::cppu::OImplementationId
* pIdMenuBar
= NULL
;
368 static ::cppu::OImplementationId
* pIdPopupMenu
= NULL
;
374 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
377 static ::cppu::OImplementationId
idPopupMenu( sal_False
);
378 pIdPopupMenu
= &idPopupMenu
;
382 return (*pIdPopupMenu
).getImplementationId();
388 ::osl::Guard
< ::osl::Mutex
> aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
391 static ::cppu::OImplementationId
idMenuBar( sal_False
);
392 pIdMenuBar
= &idMenuBar
;
396 return (*pIdMenuBar
).getImplementationId();
401 //=============================================================================
402 //=============================================================================
403 //=============================================================================
406 void VCLXMenu::addMenuListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
408 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
410 maMenuListeners
.addInterface( rxListener
);
413 void VCLXMenu::removeMenuListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
415 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
417 maMenuListeners
.removeInterface( rxListener
);
420 void VCLXMenu::insertItem( sal_Int16 nItemId
, const ::rtl::OUString
& aText
, sal_Int16 nItemStyle
, sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
422 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
425 mpMenu
->InsertItem( nItemId
, aText
, (MenuItemBits
)nItemStyle
, nPos
);
428 void VCLXMenu::removeItem( sal_Int16 nPos
, sal_Int16 nCount
) throw(::com::sun::star::uno::RuntimeException
)
430 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
432 sal_Int32 nItemCount
= (sal_Int32
)mpMenu
->GetItemCount();
433 if ( mpMenu
&& ( nCount
> 0 ) && ( nPos
>= 0 ) && ( nPos
< nItemCount
) && ( nItemCount
> 0 ))
435 sal_Int16 nP
= sal::static_int_cast
< sal_Int16
>(
436 Min( (int)(nPos
+nCount
), (int)nItemCount
));
438 mpMenu
->RemoveItem( --nP
);
442 sal_Int16
VCLXMenu::getItemCount( ) throw(::com::sun::star::uno::RuntimeException
)
444 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
446 return mpMenu
? mpMenu
->GetItemCount() : 0;
449 sal_Int16
VCLXMenu::getItemId( sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
451 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
453 return mpMenu
? mpMenu
->GetItemId( nPos
) : 0;
456 sal_Int16
VCLXMenu::getItemPos( sal_Int16 nId
) throw(::com::sun::star::uno::RuntimeException
)
458 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
460 return mpMenu
? mpMenu
->GetItemPos( nId
) : 0;
463 void VCLXMenu::enableItem( sal_Int16 nItemId
, sal_Bool bEnable
) throw(::com::sun::star::uno::RuntimeException
)
465 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
468 mpMenu
->EnableItem( nItemId
, bEnable
);
471 sal_Bool
VCLXMenu::isItemEnabled( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
473 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
475 return mpMenu
? mpMenu
->IsItemEnabled( nItemId
) : sal_False
;
478 void VCLXMenu::setItemText( sal_Int16 nItemId
, const ::rtl::OUString
& aText
) throw(::com::sun::star::uno::RuntimeException
)
480 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
483 mpMenu
->SetItemText( nItemId
, aText
);
486 ::rtl::OUString
VCLXMenu::getItemText( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
488 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
490 ::rtl::OUString aItemText
;
492 aItemText
= mpMenu
->GetItemText( nItemId
);
496 void VCLXMenu::setPopupMenu( sal_Int16 nItemId
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
>& rxPopupMenu
) throw(::com::sun::star::uno::RuntimeException
)
498 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
500 VCLXMenu
* pVCLMenu
= VCLXMenu::GetImplementation( rxPopupMenu
);
501 DBG_ASSERT( pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
503 if ( mpMenu
&& pVCLMenu
&& pVCLMenu
->GetMenu() && pVCLMenu
->IsPopupMenu() )
505 // Selbst eine Ref halten!
506 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pNewRef
= new ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> ;
507 *pNewRef
= rxPopupMenu
;
508 maPopupMenueRefs
.Insert( pNewRef
, LIST_APPEND
);
510 mpMenu
->SetPopupMenu( nItemId
, (PopupMenu
*) pVCLMenu
->GetMenu() );
514 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> VCLXMenu::getPopupMenu( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
516 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
518 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> aRef
;
519 Menu
* pMenu
= mpMenu
? mpMenu
->GetPopupMenu( nItemId
) : NULL
;
522 for ( sal_uInt32 n
= maPopupMenueRefs
.Count(); n
; )
524 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pRef
= maPopupMenueRefs
.GetObject( --n
);
525 Menu
* pM
= ((VCLXMenu
*)pRef
->get())->GetMenu();
532 // it seems the popup menu is not insert into maPopupMenueRefs
533 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
536 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> * pNewRef
= new ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPopupMenu
> ;
537 *pNewRef
= new VCLXPopupMenu( (PopupMenu
*)pMenu
);
544 // ::com::sun::star::awt::XPopupMenu
545 void VCLXMenu::insertSeparator( sal_Int16 nPos
) throw(::com::sun::star::uno::RuntimeException
)
547 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
550 mpMenu
->InsertSeparator( nPos
);
553 void VCLXMenu::setDefaultItem( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
555 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
558 mpMenu
->SetDefaultItem( nItemId
);
561 sal_Int16
VCLXMenu::getDefaultItem( ) throw(::com::sun::star::uno::RuntimeException
)
563 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
565 return mpMenu
? mpMenu
->GetDefaultItem() : 0;
568 void VCLXMenu::checkItem( sal_Int16 nItemId
, sal_Bool bCheck
) throw(::com::sun::star::uno::RuntimeException
)
570 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
573 mpMenu
->CheckItem( nItemId
, bCheck
);
576 sal_Bool
VCLXMenu::isItemChecked( sal_Int16 nItemId
) throw(::com::sun::star::uno::RuntimeException
)
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 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
588 if ( mpMenu
&& IsPopupMenu() )
589 nRet
= ((PopupMenu
*)mpMenu
)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer
), VCLRectangle(rArea
), nFlags
| POPUPMENU_NOMOUSEUPCLOSE
);
594 void SAL_CALL
VCLXMenu::setCommand( sal_Int16 nItemId
, const ::rtl::OUString
& aCommand
) throw (::com::sun::star::uno::RuntimeException
)
596 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
599 mpMenu
->SetItemCommand( nItemId
, aCommand
);
602 ::rtl::OUString SAL_CALL
VCLXMenu::getCommand( sal_Int16 nItemId
) throw (::com::sun::star::uno::RuntimeException
)
604 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
606 ::rtl::OUString aItemCommand
;
608 aItemCommand
= mpMenu
->GetItemCommand( nItemId
);
612 void SAL_CALL
VCLXMenu::setHelpCommand( sal_Int16 nItemId
, const ::rtl::OUString
& aHelp
) throw (::com::sun::star::uno::RuntimeException
)
614 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
617 mpMenu
->SetHelpCommand( nItemId
, aHelp
);
620 ::rtl::OUString SAL_CALL
VCLXMenu::getHelpCommand( sal_Int16 nItemId
) throw (::com::sun::star::uno::RuntimeException
)
622 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
624 ::rtl::OUString aHelpCommand
;
626 aHelpCommand
= mpMenu
->GetHelpCommand( nItemId
);
631 // ============================================================================
632 // ============================================================================
633 // ============================================================================
636 // BEGIN ANONYMOUS NAMESPACE
639 namespace css
= ::com::sun::star
;
641 Image
lcl_XGraphic2VCLImage(
642 const css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
,
646 if ( !xGraphic
.is() )
649 aImage
= Image( xGraphic
);
650 const ::Size aCurSize
= aImage
.GetSizePixel();
651 const sal_Int32 nCurWidth
= aCurSize
.Width();
652 const sal_Int32 nCurHeight
= aCurSize
.Height();
653 const sal_Int32
nIdeal( 16 );
655 if ( nCurWidth
> 0 && nCurHeight
> 0 )
657 if ( bResize
&& ( nCurWidth
> nIdeal
|| nCurHeight
> nIdeal
) )
659 sal_Int32 nIdealWidth
= nCurWidth
> nIdeal
? nIdeal
: nCurWidth
;
660 sal_Int32 nIdealHeight
= nCurHeight
> nIdeal
? nIdeal
: nCurHeight
;
662 ::Size
aNewSize( nIdealWidth
, nIdealHeight
);
664 sal_Bool
bModified( sal_False
);
665 BitmapEx aBitmapEx
= aImage
.GetBitmapEx();
666 bModified
= aBitmapEx
.Scale( aNewSize
, BMP_SCALE_INTERPOLATE
);
669 aImage
= Image( aBitmapEx
);
676 As svtools builds after toolkit, we can not include/use
677 svtools/inc/acceleratorexecute.hxx
678 So I just copy here svt::AcceleratorExecute::st_AWTKey2VCLKey
679 and svt::AcceleratorExecute::st_VCLKey2AWTKey
681 css::awt::KeyEvent
lcl_VCLKey2AWTKey(const KeyCode
& aVCLKey
)
683 css::awt::KeyEvent aAWTKey
;
684 aAWTKey
.Modifiers
= 0;
685 aAWTKey
.KeyCode
= (sal_Int16
)aVCLKey
.GetCode();
687 if (aVCLKey
.IsShift())
688 aAWTKey
.Modifiers
|= css::awt::KeyModifier::SHIFT
;
689 if (aVCLKey
.IsMod1())
690 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD1
;
691 if (aVCLKey
.IsMod2())
692 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD2
;
693 if (aVCLKey
.IsMod3())
694 aAWTKey
.Modifiers
|= css::awt::KeyModifier::MOD3
;
699 KeyCode
lcl_AWTKey2VCLKey(const css::awt::KeyEvent
& aAWTKey
)
701 sal_Bool bShift
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::SHIFT
) == css::awt::KeyModifier::SHIFT
);
702 sal_Bool bMod1
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD1
) == css::awt::KeyModifier::MOD1
);
703 sal_Bool bMod2
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD2
) == css::awt::KeyModifier::MOD2
);
704 sal_Bool bMod3
= ((aAWTKey
.Modifiers
& css::awt::KeyModifier::MOD3
) == css::awt::KeyModifier::MOD3
);
705 USHORT nKey
= (USHORT
)aAWTKey
.KeyCode
;
707 return KeyCode(nKey
, bShift
, bMod1
, bMod2
, bMod3
);
710 } // END ANONYMOUS NAMESPACE
713 // ============================================================================
714 // ============================================================================
715 // ============================================================================
718 // XMenuExtended2 Methods
720 ::sal_Bool SAL_CALL
VCLXMenu::isPopupMenu( ) throw (::com::sun::star::uno::RuntimeException
)
722 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
723 return IsPopupMenu();
726 void SAL_CALL
VCLXMenu::clear( ) throw (::com::sun::star::uno::RuntimeException
)
728 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
734 ::com::sun::star::awt::MenuItemType SAL_CALL
VCLXMenu::getItemType( ::sal_Int16 nItemPos
)
735 throw ( ::com::sun::star::container::NoSuchElementException
,
736 ::com::sun::star::uno::RuntimeException
)
738 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
740 ::com::sun::star::awt::MenuItemType aMenuItemType
=
741 ::com::sun::star::awt::MenuItemType_DONTKNOW
;
744 THROW_MENUPOS_NOT_FOUND( "VCLXMenu::getItemType()", nItemPos
)
745 aMenuItemType
= ( (::com::sun::star::awt::MenuItemType
) mpMenu
->GetItemType( nItemPos
) );
748 return aMenuItemType
;
751 void SAL_CALL
VCLXMenu::hideDisabledEntries( ::sal_Bool bHide
)
752 throw (::com::sun::star::uno::RuntimeException
)
754 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
758 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES
);
760 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES
);
765 // ============================================================================
766 // ============================================================================
767 // ============================================================================
770 // XPopupMenuExtended Methods
772 ::sal_Bool SAL_CALL
VCLXMenu::isInExecute( )
773 throw (::com::sun::star::uno::RuntimeException
)
775 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
777 if ( mpMenu
&& IsPopupMenu() )
778 return ( (PopupMenu
*) mpMenu
)->IsInExecute();
784 void SAL_CALL
VCLXMenu::endExecute()
785 throw (::com::sun::star::uno::RuntimeException
)
787 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
789 if ( mpMenu
&& IsPopupMenu() )
790 ( (PopupMenu
*) mpMenu
)->EndExecute();
794 void SAL_CALL
VCLXMenu::setLogo( const ::com::sun::star::awt::MenuLogo
& aMenuLogo
)
795 throw (::com::sun::star::uno::RuntimeException
)
797 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
801 if ( aMenuLogo
.Graphic
.is() )
803 Image aImage
= lcl_XGraphic2VCLImage( aMenuLogo
.Graphic
, sal_False
);
804 MenuLogo aVCLMenuLogo
;
806 aVCLMenuLogo
.aBitmap
= aImage
.GetBitmapEx();
807 aVCLMenuLogo
.aStartColor
= Color( (sal_uInt32
)(aMenuLogo
.StartColor
) );
808 aVCLMenuLogo
.aEndColor
= Color( (sal_uInt32
)(aMenuLogo
.EndColor
) );
810 mpMenu
->SetLogo( aVCLMenuLogo
);
818 ::com::sun::star::awt::MenuLogo SAL_CALL
VCLXMenu::getLogo( )
819 throw (::com::sun::star::uno::RuntimeException
)
821 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
823 ::com::sun::star::awt::MenuLogo aAWTMenuLogo
;
826 if ( mpMenu
->HasLogo() )
828 MenuLogo aVCLMenuLogo
= mpMenu
->GetLogo();
829 aAWTMenuLogo
.Graphic
= Image(aVCLMenuLogo
.aBitmap
).GetXGraphic();
830 aAWTMenuLogo
.StartColor
= aVCLMenuLogo
.aStartColor
.GetColor();
831 aAWTMenuLogo
.EndColor
= aVCLMenuLogo
.aEndColor
.GetColor();
838 void SAL_CALL
VCLXMenu::enableAutoMnemonics( ::sal_Bool bEnable
)
839 throw (::com::sun::star::uno::RuntimeException
)
841 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
845 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
847 mpMenu
->SetMenuFlags( mpMenu
->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS
);
852 void SAL_CALL
VCLXMenu::setAcceleratorKeyEvent( ::sal_Int16 nItemId
,
853 const ::com::sun::star::awt::KeyEvent
& aKeyEvent
)
854 throw ( ::com::sun::star::container::NoSuchElementException
,
855 ::com::sun::star::uno::RuntimeException
)
857 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
859 if ( mpMenu
&& IsPopupMenu() )
861 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setAcceleratorKeyEvent()", nItemId
)
862 KeyCode aVCLKeyCode
= lcl_AWTKey2VCLKey( aKeyEvent
);
863 mpMenu
->SetAccelKey( nItemId
, aVCLKeyCode
);
868 ::com::sun::star::awt::KeyEvent SAL_CALL
VCLXMenu::getAcceleratorKeyEvent( ::sal_Int16 nItemId
)
869 throw ( ::com::sun::star::container::NoSuchElementException
,
870 ::com::sun::star::uno::RuntimeException
)
872 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
874 ::com::sun::star::awt::KeyEvent aKeyEvent
;
875 if ( mpMenu
&& IsPopupMenu() )
877 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getAcceleratorKeyEvent()", nItemId
)
878 KeyCode nKeyCode
= mpMenu
->GetAccelKey( nItemId
);
879 aKeyEvent
= lcl_VCLKey2AWTKey( nKeyCode
);
886 void SAL_CALL
VCLXMenu::setHelpText( ::sal_Int16 nItemId
, const ::rtl::OUString
& sHelpText
)
887 throw ( ::com::sun::star::container::NoSuchElementException
,
888 ::com::sun::star::uno::RuntimeException
)
890 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
892 if ( mpMenu
&& IsPopupMenu() )
894 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setHelpText()", nItemId
)
895 mpMenu
->SetHelpText( nItemId
, sHelpText
);
900 ::rtl::OUString SAL_CALL
VCLXMenu::getHelpText( ::sal_Int16 nItemId
)
901 throw ( ::com::sun::star::container::NoSuchElementException
,
902 ::com::sun::star::uno::RuntimeException
)
904 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
906 rtl::OUString sHelpText
;
907 if ( mpMenu
&& IsPopupMenu() )
909 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getHelpText()", nItemId
)
910 sHelpText
= mpMenu
->GetHelpText( nItemId
);
917 void SAL_CALL
VCLXMenu::setTipHelpText( ::sal_Int16 nItemId
, const ::rtl::OUString
& sTipHelpText
)
918 throw ( ::com::sun::star::container::NoSuchElementException
,
919 ::com::sun::star::uno::RuntimeException
)
921 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
923 if ( mpMenu
&& IsPopupMenu() )
925 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setTipHelpText()", nItemId
)
926 mpMenu
->SetTipHelpText( nItemId
, sTipHelpText
);
931 ::rtl::OUString SAL_CALL
VCLXMenu::getTipHelpText( ::sal_Int16 nItemId
)
932 throw ( ::com::sun::star::container::NoSuchElementException
,
933 ::com::sun::star::uno::RuntimeException
)
935 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
937 rtl::OUString sTipHelpText
;
938 if ( mpMenu
&& IsPopupMenu() )
940 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getTipHelpText()", nItemId
)
941 sTipHelpText
= mpMenu
->GetTipHelpText( nItemId
);
947 void SAL_CALL
VCLXMenu::setItemImage(
949 const ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>& xGraphic
, ::sal_Bool bScale
)
950 throw ( ::com::sun::star::container::NoSuchElementException
,
951 ::com::sun::star::uno::RuntimeException
)
953 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
955 if ( mpMenu
&& IsPopupMenu() )
957 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImage()", nItemId
)
958 Image aImage
= lcl_XGraphic2VCLImage( xGraphic
, bScale
);
959 mpMenu
->SetItemImage( nItemId
, aImage
);
964 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> SAL_CALL
VCLXMenu::getItemImage( ::sal_Int16 nItemId
)
965 throw ( ::com::sun::star::container::NoSuchElementException
,
966 ::com::sun::star::uno::RuntimeException
)
968 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
970 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> rxGraphic
;
972 if ( mpMenu
&& IsPopupMenu() )
974 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImage()", nItemId
)
975 Image aImage
= mpMenu
->GetItemImage( nItemId
);
977 rxGraphic
= aImage
.GetXGraphic();
983 void SAL_CALL
VCLXMenu::setItemImageAngle( ::sal_Int16 nItemId
, ::sal_Int32 nAngle
)
984 throw ( ::com::sun::star::container::NoSuchElementException
,
985 ::com::sun::star::uno::RuntimeException
)
987 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
989 if ( mpMenu
&& IsPopupMenu() )
991 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageAngle()", nItemId
)
992 mpMenu
->SetItemImageAngle( nItemId
, nAngle
);
997 ::sal_Int32 SAL_CALL
VCLXMenu::getItemImageAngle( ::sal_Int16 nItemId
)
998 throw ( ::com::sun::star::container::NoSuchElementException
,
999 ::com::sun::star::uno::RuntimeException
)
1001 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1003 ::sal_Int32
nItemImageAngle( 0 );
1004 if ( mpMenu
&& IsPopupMenu() )
1006 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImageAngle()", nItemId
)
1007 nItemImageAngle
= mpMenu
->GetItemImageAngle( nItemId
);
1009 return nItemImageAngle
;
1013 void SAL_CALL
VCLXMenu::setItemImageMirrorMode( ::sal_Int16 nItemId
, ::sal_Bool bMirror
)
1014 throw ( ::com::sun::star::container::NoSuchElementException
,
1015 ::com::sun::star::uno::RuntimeException
)
1017 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1019 if ( mpMenu
&& IsPopupMenu() )
1021 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageMirrorMode()", nItemId
)
1022 mpMenu
->SetItemImageMirrorMode( nItemId
, bMirror
);
1027 ::sal_Bool SAL_CALL
VCLXMenu::isItemImageInMirrorMode( ::sal_Int16 nItemId
)
1028 throw ( ::com::sun::star::container::NoSuchElementException
,
1029 ::com::sun::star::uno::RuntimeException
)
1031 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1033 sal_Bool
bMirrorMode( sal_False
);
1034 if ( mpMenu
&& IsPopupMenu() )
1036 THROW_MENUITEM_NOT_FOUND( "VCLXMenu::isItemImageInMirrorMode()", nItemId
)
1037 bMirrorMode
= mpMenu
->GetItemImageMirrorMode( nItemId
);
1043 // ----------------------------------------------------
1044 // class VCLXMenuBar
1045 // ----------------------------------------------------
1047 DBG_NAME(VCLXMenuBar
);
1049 VCLXMenuBar::VCLXMenuBar()
1051 DBG_CTOR( VCLXMenuBar
, 0 );
1052 ImplCreateMenu( FALSE
);
1055 VCLXMenuBar::VCLXMenuBar( MenuBar
* pMenuBar
) : VCLXMenu( (Menu
*)pMenuBar
)
1057 DBG_CTOR( VCLXMenuBar
, 0 );
1060 // ----------------------------------------------------
1061 // class VCLXPopupMenu
1062 // ----------------------------------------------------
1064 DBG_NAME(VCLXPopupMenu
);
1066 VCLXPopupMenu::VCLXPopupMenu()
1068 DBG_CTOR( VCLXPopupMenu
, 0 );
1069 ImplCreateMenu( TRUE
);
1072 VCLXPopupMenu::VCLXPopupMenu( PopupMenu
* pPopMenu
) : VCLXMenu( (Menu
*)pPopMenu
)
1074 DBG_CTOR( VCLXPopupMenu
, 0 );