1b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5b0724fc6SAndrew Rist * distributed with this work for additional information 6b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17b0724fc6SAndrew Rist * specific language governing permissions and limitations 18b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20b0724fc6SAndrew Rist *************************************************************/ 21b0724fc6SAndrew Rist 22b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx> 28d026be40SAriel Constenla-Haile #include <toolkit/helper/convert.hxx> 29cdf0e10cSrcweir #include <toolkit/helper/macros.hxx> 30cdf0e10cSrcweir #include <toolkit/helper/servicenames.hxx> 31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 32d026be40SAriel Constenla-Haile 33cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 34cdf0e10cSrcweir #include <rtl/memory.h> 35d026be40SAriel Constenla-Haile #include <rtl/ustrbuf.hxx> 36cdf0e10cSrcweir #include <rtl/uuid.h> 37cdf0e10cSrcweir #include <vcl/image.hxx> 38d026be40SAriel Constenla-Haile #include <vcl/keycod.hxx> 39d026be40SAriel Constenla-Haile #include <vcl/menu.hxx> 40cdf0e10cSrcweir #include <vcl/mnemonic.hxx> 41cdf0e10cSrcweir #include <vcl/svapp.hxx> 42d026be40SAriel Constenla-Haile #include <vos/mutex.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 45cdf0e10cSrcweir 46d026be40SAriel Constenla-Haile using rtl::OUString; 47d026be40SAriel Constenla-Haile using rtl::OUStringBuffer; 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir DBG_NAME(VCLXMenu) 51cdf0e10cSrcweir 52d026be40SAriel Constenla-Haile VCLXMenu::VCLXMenu() 53d026be40SAriel Constenla-Haile : maMenuListeners( *this ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir DBG_CTOR( VCLXMenu, 0 ); 56cdf0e10cSrcweir mpMenu = NULL; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59d026be40SAriel Constenla-Haile VCLXMenu::VCLXMenu( Menu* pMenu ) 60d026be40SAriel Constenla-Haile : maMenuListeners( *this ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir DBG_CTOR( VCLXMenu, 0 ); 63cdf0e10cSrcweir mpMenu = pMenu; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir VCLXMenu::~VCLXMenu() 67cdf0e10cSrcweir { 68cdf0e10cSrcweir DBG_DTOR( VCLXMenu, 0 ); 69cdf0e10cSrcweir for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; ) 70cdf0e10cSrcweir { 71d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n ); 72cdf0e10cSrcweir delete pRef; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir if ( mpMenu ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); 77cdf0e10cSrcweir delete mpMenu; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_Bool VCLXMenu::IsPopupMenu() const 82cdf0e10cSrcweir { 83cdf0e10cSrcweir return (mpMenu && ! mpMenu->IsMenuBar()); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir void VCLXMenu::ImplCreateMenu( sal_Bool bPopup ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir if ( bPopup ) 91cdf0e10cSrcweir mpMenu = new PopupMenu; 92cdf0e10cSrcweir else 93cdf0e10cSrcweir mpMenu = new MenuBar; 94cdf0e10cSrcweir 95cdf0e10cSrcweir mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir IMPL_LINK( VCLXMenu, MenuEventListener, VclSimpleEvent*, pEvent ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir DBG_ASSERT( pEvent && pEvent->ISA( VclMenuEvent ), "Unknown Event!" ); 101cdf0e10cSrcweir if ( pEvent && pEvent->ISA( VclMenuEvent ) ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir DBG_ASSERT( ((VclMenuEvent*)pEvent)->GetMenu() && mpMenu, "Menu???" ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir VclMenuEvent* pMenuEvent = (VclMenuEvent*)pEvent; 106cdf0e10cSrcweir if ( pMenuEvent->GetMenu() == mpMenu ) // Also called for the root menu 107cdf0e10cSrcweir { 108cdf0e10cSrcweir switch ( pMenuEvent->GetId() ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir case VCLEVENT_MENU_SELECT: 111cdf0e10cSrcweir { 112cdf0e10cSrcweir if ( maMenuListeners.getLength() ) 113cdf0e10cSrcweir { 114d026be40SAriel Constenla-Haile css::awt::MenuEvent aEvent; 115cdf0e10cSrcweir aEvent.Source = (::cppu::OWeakObject*)this; 116cdf0e10cSrcweir aEvent.MenuId = mpMenu->GetCurItemId(); 117d026be40SAriel Constenla-Haile maMenuListeners.itemSelected( aEvent ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir break; 121cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING: 122cdf0e10cSrcweir { 123cdf0e10cSrcweir mpMenu = NULL; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir break; 126cdf0e10cSrcweir case VCLEVENT_MENU_HIGHLIGHT: 127cdf0e10cSrcweir { 128cdf0e10cSrcweir if ( maMenuListeners.getLength() ) 129cdf0e10cSrcweir { 130d026be40SAriel Constenla-Haile css::awt::MenuEvent aEvent; 131cdf0e10cSrcweir aEvent.Source = (::cppu::OWeakObject*)this; 132cdf0e10cSrcweir aEvent.MenuId = mpMenu->GetCurItemId(); 133d026be40SAriel Constenla-Haile maMenuListeners.itemHighlighted( aEvent ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir break; 137cdf0e10cSrcweir case VCLEVENT_MENU_ACTIVATE: 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if ( maMenuListeners.getLength() ) 140cdf0e10cSrcweir { 141d026be40SAriel Constenla-Haile css::awt::MenuEvent aEvent; 142cdf0e10cSrcweir aEvent.Source = (::cppu::OWeakObject*)this; 143cdf0e10cSrcweir aEvent.MenuId = mpMenu->GetCurItemId(); 144d026be40SAriel Constenla-Haile maMenuListeners.itemActivated( aEvent ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir break; 148cdf0e10cSrcweir case VCLEVENT_MENU_DEACTIVATE: 149cdf0e10cSrcweir { 150cdf0e10cSrcweir if ( maMenuListeners.getLength() ) 151cdf0e10cSrcweir { 152d026be40SAriel Constenla-Haile css::awt::MenuEvent aEvent; 153cdf0e10cSrcweir aEvent.Source = (::cppu::OWeakObject*)this; 154cdf0e10cSrcweir aEvent.MenuId = mpMenu->GetCurItemId(); 155d026be40SAriel Constenla-Haile maMenuListeners.itemDeactivated( aEvent ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir 160cdf0e10cSrcweir // ignore accessibility events 161cdf0e10cSrcweir case VCLEVENT_MENU_ENABLE: 162cdf0e10cSrcweir case VCLEVENT_MENU_INSERTITEM: 163cdf0e10cSrcweir case VCLEVENT_MENU_REMOVEITEM: 164cdf0e10cSrcweir case VCLEVENT_MENU_SUBMENUACTIVATE: 165cdf0e10cSrcweir case VCLEVENT_MENU_SUBMENUDEACTIVATE: 166cdf0e10cSrcweir case VCLEVENT_MENU_SUBMENUCHANGED: 167cdf0e10cSrcweir case VCLEVENT_MENU_DEHIGHLIGHT: 168cdf0e10cSrcweir case VCLEVENT_MENU_DISABLE: 169cdf0e10cSrcweir case VCLEVENT_MENU_ITEMTEXTCHANGED: 170cdf0e10cSrcweir case VCLEVENT_MENU_ITEMCHECKED: 171cdf0e10cSrcweir case VCLEVENT_MENU_ITEMUNCHECKED: 172cdf0e10cSrcweir case VCLEVENT_MENU_SHOW: 173cdf0e10cSrcweir case VCLEVENT_MENU_HIDE: 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir 176cdf0e10cSrcweir default: DBG_ERROR( "MenuEventListener - Unknown event!" ); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir return 0; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir 184d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getImplementationName( ) 185d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); 188cdf0e10cSrcweir const sal_Bool bIsPopupMenu = IsPopupMenu(); 189cdf0e10cSrcweir aGuard.clear(); 190cdf0e10cSrcweir 191d026be40SAriel Constenla-Haile OUStringBuffer implName; 192d026be40SAriel Constenla-Haile implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "stardiv.Toolkit." ) ); 193cdf0e10cSrcweir if ( bIsPopupMenu ) 194d026be40SAriel Constenla-Haile implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VCLXPopupMenu" ) ); 195cdf0e10cSrcweir else 196d026be40SAriel Constenla-Haile implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VCLXMenuBar" ) ); 197cdf0e10cSrcweir 198d026be40SAriel Constenla-Haile return implName.makeStringAndClear(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir 202d026be40SAriel Constenla-Haile css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( ) 203d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); 206cdf0e10cSrcweir const sal_Bool bIsPopupMenu = IsPopupMenu(); 207cdf0e10cSrcweir aGuard.clear(); 208cdf0e10cSrcweir 209d026be40SAriel Constenla-Haile css::uno::Sequence< OUString > aNames( 1 ); 210cdf0e10cSrcweir if ( bIsPopupMenu ) 211d026be40SAriel Constenla-Haile aNames[ 0 ] = OUString::createFromAscii( szServiceName2_PopupMenu ); 212cdf0e10cSrcweir else 213d026be40SAriel Constenla-Haile aNames[ 0 ] = OUString::createFromAscii( szServiceName2_MenuBar ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir return aNames; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir 219d026be40SAriel Constenla-Haile ::sal_Bool SAL_CALL VCLXMenu::supportsService( 220d026be40SAriel Constenla-Haile const OUString& rServiceName ) 221d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 222cdf0e10cSrcweir { 223d026be40SAriel Constenla-Haile css::uno::Sequence< OUString > aServiceNames( getSupportedServiceNames() ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir if ( aServiceNames[ 0 ] == rServiceName ) 226cdf0e10cSrcweir return sal_True; 227cdf0e10cSrcweir 228cdf0e10cSrcweir return sal_False; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232d026be40SAriel Constenla-Haile css::uno::Any VCLXMenu::queryInterface( 233d026be40SAriel Constenla-Haile const css::uno::Type & rType ) 234d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); 237cdf0e10cSrcweir const sal_Bool bIsPopupMenu = IsPopupMenu(); 238cdf0e10cSrcweir aGuard.clear(); 239cdf0e10cSrcweir 240d026be40SAriel Constenla-Haile css::uno::Any aRet; 241cdf0e10cSrcweir 242cdf0e10cSrcweir if ( bIsPopupMenu ) 243cdf0e10cSrcweir aRet = ::cppu::queryInterface( rType, 244d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::awt::XMenu*, (css::awt::XPopupMenu*) this ), 245d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::awt::XPopupMenu*, this ), 246d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XTypeProvider*, this ), 247d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XServiceInfo*, this ), 248d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XUnoTunnel*, this ) ); 249cdf0e10cSrcweir else 250cdf0e10cSrcweir aRet = ::cppu::queryInterface( rType, 251d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::awt::XMenu*, (css::awt::XMenuBar*) this ), 252d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::awt::XMenuBar*, this ), 253d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XTypeProvider*, this ), 254d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XServiceInfo*, this ), 255d026be40SAriel Constenla-Haile SAL_STATIC_CAST( css::lang::XUnoTunnel*, this ) ); 256cdf0e10cSrcweir 257cdf0e10cSrcweir return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260d026be40SAriel Constenla-Haile 261cdf0e10cSrcweir IMPL_XUNOTUNNEL( VCLXMenu ) 262cdf0e10cSrcweir 263d026be40SAriel Constenla-Haile 264d026be40SAriel Constenla-Haile css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes() 265d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); 268cdf0e10cSrcweir const sal_Bool bIsPopupMenu = IsPopupMenu(); 269cdf0e10cSrcweir aGuard.clear(); 270cdf0e10cSrcweir 271cdf0e10cSrcweir static ::cppu::OTypeCollection* pCollectionMenuBar = NULL; 272cdf0e10cSrcweir static ::cppu::OTypeCollection* pCollectionPopupMenu = NULL; 273cdf0e10cSrcweir 274cdf0e10cSrcweir if ( bIsPopupMenu ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir if( !pCollectionPopupMenu ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); 279cdf0e10cSrcweir if( !pCollectionPopupMenu ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir static ::cppu::OTypeCollection collectionPopupMenu( 282d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::lang::XTypeProvider>* ) NULL ), 283d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::awt::XMenu>* ) NULL ), 284d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::awt::XPopupMenu>* ) NULL ), 285d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::lang::XServiceInfo>* ) NULL ) ); 286cdf0e10cSrcweir pCollectionPopupMenu = &collectionPopupMenu; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir return (*pCollectionPopupMenu).getTypes(); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir else 293cdf0e10cSrcweir { 294cdf0e10cSrcweir if( !pCollectionMenuBar ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); 297cdf0e10cSrcweir if( !pCollectionMenuBar ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir static ::cppu::OTypeCollection collectionMenuBar( 300d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::lang::XTypeProvider>* ) NULL ), 301d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::awt::XMenu>* ) NULL ), 302d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::awt::XMenuBar>* ) NULL ), 303d026be40SAriel Constenla-Haile getCppuType( ( css::uno::Reference< css::lang::XServiceInfo>* ) NULL ) ); 304cdf0e10cSrcweir pCollectionMenuBar = &collectionMenuBar; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir return (*pCollectionMenuBar).getTypes(); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir 312d026be40SAriel Constenla-Haile css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId() 313d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); 316cdf0e10cSrcweir const sal_Bool bIsPopupMenu = IsPopupMenu(); 317cdf0e10cSrcweir aGuard.clear(); 318cdf0e10cSrcweir 319cdf0e10cSrcweir static ::cppu::OImplementationId* pIdMenuBar = NULL; 320cdf0e10cSrcweir static ::cppu::OImplementationId* pIdPopupMenu = NULL; 321cdf0e10cSrcweir 322cdf0e10cSrcweir if ( bIsPopupMenu ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir if( !pIdPopupMenu ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); 327cdf0e10cSrcweir if( !pIdPopupMenu ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir static ::cppu::OImplementationId idPopupMenu( sal_False ); 330cdf0e10cSrcweir pIdPopupMenu = &idPopupMenu; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir return (*pIdPopupMenu).getImplementationId(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir else 337cdf0e10cSrcweir { 338cdf0e10cSrcweir if( !pIdMenuBar ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); 341cdf0e10cSrcweir if( !pIdMenuBar ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir static ::cppu::OImplementationId idMenuBar( sal_False ); 344cdf0e10cSrcweir pIdMenuBar = &idMenuBar; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir return (*pIdMenuBar).getImplementationId(); 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352d026be40SAriel Constenla-Haile void VCLXMenu::addMenuListener( 353d026be40SAriel Constenla-Haile const css::uno::Reference< css::awt::XMenuListener >& rxListener ) 354d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 357cdf0e10cSrcweir 358cdf0e10cSrcweir maMenuListeners.addInterface( rxListener ); 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361d026be40SAriel Constenla-Haile void VCLXMenu::removeMenuListener( 362d026be40SAriel Constenla-Haile const css::uno::Reference< css::awt::XMenuListener >& rxListener ) 363d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 366cdf0e10cSrcweir 367cdf0e10cSrcweir maMenuListeners.removeInterface( rxListener ); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370d026be40SAriel Constenla-Haile void VCLXMenu::insertItem( 371d026be40SAriel Constenla-Haile sal_Int16 nItemId, 372d026be40SAriel Constenla-Haile const OUString& aText, 373d026be40SAriel Constenla-Haile sal_Int16 nItemStyle, 374d026be40SAriel Constenla-Haile sal_Int16 nPos ) 375d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 378cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir if ( mpMenu ) 381cdf0e10cSrcweir mpMenu->InsertItem( nItemId, aText, (MenuItemBits)nItemStyle, nPos ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384d026be40SAriel Constenla-Haile void VCLXMenu::removeItem( 385d026be40SAriel Constenla-Haile sal_Int16 nPos, 386d026be40SAriel Constenla-Haile sal_Int16 nCount ) 387d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 390cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 391cdf0e10cSrcweir 392cdf0e10cSrcweir sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount(); 393cdf0e10cSrcweir if ( mpMenu && ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 )) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir sal_Int16 nP = sal::static_int_cast< sal_Int16 >( 396cdf0e10cSrcweir Min( (int)(nPos+nCount), (int)nItemCount )); 397cdf0e10cSrcweir while( nP-nPos > 0 ) 398cdf0e10cSrcweir mpMenu->RemoveItem( --nP ); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemCount( ) 403d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 406cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 407cdf0e10cSrcweir 408cdf0e10cSrcweir return mpMenu ? mpMenu->GetItemCount() : 0; 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemId( 412d026be40SAriel Constenla-Haile sal_Int16 nPos ) 413d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 416cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 417cdf0e10cSrcweir 418cdf0e10cSrcweir return mpMenu ? mpMenu->GetItemId( nPos ) : 0; 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemPos( 422d026be40SAriel Constenla-Haile sal_Int16 nId ) 423d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 426cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 427cdf0e10cSrcweir 428cdf0e10cSrcweir return mpMenu ? mpMenu->GetItemPos( nId ) : 0; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431d026be40SAriel Constenla-Haile void VCLXMenu::enableItem( 432d026be40SAriel Constenla-Haile sal_Int16 nItemId, 433d026be40SAriel Constenla-Haile sal_Bool bEnable ) 434d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 437cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 438cdf0e10cSrcweir 439cdf0e10cSrcweir if ( mpMenu ) 440cdf0e10cSrcweir mpMenu->EnableItem( nItemId, bEnable ); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443d026be40SAriel Constenla-Haile sal_Bool VCLXMenu::isItemEnabled( 444d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 445d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 448cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir return mpMenu ? mpMenu->IsItemEnabled( nItemId ) : sal_False; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453d026be40SAriel Constenla-Haile void VCLXMenu::setItemText( 454d026be40SAriel Constenla-Haile sal_Int16 nItemId, 455d026be40SAriel Constenla-Haile const OUString& aText ) 456d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 459cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir if ( mpMenu ) 462cdf0e10cSrcweir mpMenu->SetItemText( nItemId, aText ); 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465d026be40SAriel Constenla-Haile OUString VCLXMenu::getItemText( 466d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 467d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 470cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 471cdf0e10cSrcweir 472d026be40SAriel Constenla-Haile OUString aItemText; 473cdf0e10cSrcweir if ( mpMenu ) 474cdf0e10cSrcweir aItemText = mpMenu->GetItemText( nItemId ); 475cdf0e10cSrcweir return aItemText; 476cdf0e10cSrcweir } 477cdf0e10cSrcweir 478d026be40SAriel Constenla-Haile void VCLXMenu::setPopupMenu( 479d026be40SAriel Constenla-Haile sal_Int16 nItemId, 480d026be40SAriel Constenla-Haile const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu ) 481d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 484cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 485cdf0e10cSrcweir 486cdf0e10cSrcweir VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu ); 487cdf0e10cSrcweir DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir // Selbst eine Ref halten! 492d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > * pNewRef = new css::uno::Reference< css::awt::XPopupMenu > ; 493cdf0e10cSrcweir *pNewRef = rxPopupMenu; 494cdf0e10cSrcweir maPopupMenueRefs.Insert( pNewRef, LIST_APPEND ); 495cdf0e10cSrcweir 496cdf0e10cSrcweir mpMenu->SetPopupMenu( nItemId, (PopupMenu*) pVCLMenu->GetMenu() ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu( 501d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 502d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 505cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 506cdf0e10cSrcweir 507d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > aRef; 508cdf0e10cSrcweir Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : NULL; 509cdf0e10cSrcweir if ( pMenu ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; ) 512cdf0e10cSrcweir { 513d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n ); 514cdf0e10cSrcweir Menu* pM = ((VCLXMenu*)pRef->get())->GetMenu(); 515cdf0e10cSrcweir if ( pM == pMenu ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir aRef = *pRef; 518cdf0e10cSrcweir break; 519cdf0e10cSrcweir } 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir return aRef; 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525d026be40SAriel Constenla-Haile // css::awt::XPopupMenu 526d026be40SAriel Constenla-Haile void VCLXMenu::insertSeparator( 527d026be40SAriel Constenla-Haile sal_Int16 nPos ) 528d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 531cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 532cdf0e10cSrcweir 533cdf0e10cSrcweir if ( mpMenu ) 534cdf0e10cSrcweir mpMenu->InsertSeparator( nPos ); 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537d026be40SAriel Constenla-Haile void VCLXMenu::setDefaultItem( 538d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 539d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 542cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 543cdf0e10cSrcweir 544cdf0e10cSrcweir if ( mpMenu ) 545cdf0e10cSrcweir mpMenu->SetDefaultItem( nItemId ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir 548d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getDefaultItem( ) 549d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 552cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 553cdf0e10cSrcweir 554cdf0e10cSrcweir return mpMenu ? mpMenu->GetDefaultItem() : 0; 555cdf0e10cSrcweir } 556cdf0e10cSrcweir 557d026be40SAriel Constenla-Haile void VCLXMenu::checkItem( 558d026be40SAriel Constenla-Haile sal_Int16 nItemId, 559d026be40SAriel Constenla-Haile sal_Bool bCheck ) 560d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 563cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 564cdf0e10cSrcweir 565cdf0e10cSrcweir if ( mpMenu ) 566cdf0e10cSrcweir mpMenu->CheckItem( nItemId, bCheck ); 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569d026be40SAriel Constenla-Haile sal_Bool VCLXMenu::isItemChecked( 570d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 571d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 574cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 575cdf0e10cSrcweir 576cdf0e10cSrcweir return mpMenu ? mpMenu->IsItemChecked( nItemId ) : sal_False; 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::execute( 580d026be40SAriel Constenla-Haile const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer, 581*31d843d7SAriel Constenla-Haile const css::awt::Rectangle& rPos, 582d026be40SAriel Constenla-Haile sal_Int16 nFlags ) 583d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 586cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 587cdf0e10cSrcweir 588cdf0e10cSrcweir sal_Int16 nRet = 0; 589cdf0e10cSrcweir if ( mpMenu && IsPopupMenu() ) 590d026be40SAriel Constenla-Haile { 591d026be40SAriel Constenla-Haile nRet = ((PopupMenu*)mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ), 592*31d843d7SAriel Constenla-Haile VCLRectangle( rPos ), 593d026be40SAriel Constenla-Haile nFlags | POPUPMENU_NOMOUSEUPCLOSE ); 594d026be40SAriel Constenla-Haile } 595cdf0e10cSrcweir return nRet; 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir 599d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setCommand( 600d026be40SAriel Constenla-Haile sal_Int16 nItemId, 601d026be40SAriel Constenla-Haile const OUString& aCommand ) 602d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 605cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 606cdf0e10cSrcweir 607cdf0e10cSrcweir if ( mpMenu ) 608cdf0e10cSrcweir mpMenu->SetItemCommand( nItemId, aCommand ); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getCommand( 612d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 613d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 616cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 617cdf0e10cSrcweir 618d026be40SAriel Constenla-Haile OUString aItemCommand; 619cdf0e10cSrcweir if ( mpMenu ) 620cdf0e10cSrcweir aItemCommand = mpMenu->GetItemCommand( nItemId ); 621cdf0e10cSrcweir return aItemCommand; 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setHelpCommand( 625d026be40SAriel Constenla-Haile sal_Int16 nItemId, 626d026be40SAriel Constenla-Haile const OUString& aHelp ) 627d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 630cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 631cdf0e10cSrcweir 632cdf0e10cSrcweir if ( mpMenu ) 633cdf0e10cSrcweir mpMenu->SetHelpCommand( nItemId, aHelp ); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getHelpCommand( 637d026be40SAriel Constenla-Haile sal_Int16 nItemId ) 638d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 641cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 642cdf0e10cSrcweir 643d026be40SAriel Constenla-Haile OUString aHelpCommand; 644cdf0e10cSrcweir if ( mpMenu ) 645cdf0e10cSrcweir aHelpCommand = mpMenu->GetHelpCommand( nItemId ); 646cdf0e10cSrcweir return aHelpCommand; 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir 650cdf0e10cSrcweir namespace 651cdf0e10cSrcweir { 652d026be40SAriel Constenla-Haile static Image lcl_XGraphic2VCLImage( 653cdf0e10cSrcweir const css::uno::Reference< css::graphic::XGraphic >& xGraphic, 654cdf0e10cSrcweir sal_Bool bResize ) 655cdf0e10cSrcweir { 656cdf0e10cSrcweir Image aImage; 657cdf0e10cSrcweir if ( !xGraphic.is() ) 658cdf0e10cSrcweir return aImage; 659cdf0e10cSrcweir 660cdf0e10cSrcweir aImage = Image( xGraphic ); 661cdf0e10cSrcweir const ::Size aCurSize = aImage.GetSizePixel(); 662cdf0e10cSrcweir const sal_Int32 nCurWidth = aCurSize.Width(); 663cdf0e10cSrcweir const sal_Int32 nCurHeight = aCurSize.Height(); 664cdf0e10cSrcweir const sal_Int32 nIdeal( 16 ); 665cdf0e10cSrcweir 666cdf0e10cSrcweir if ( nCurWidth > 0 && nCurHeight > 0 ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) ) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir sal_Int32 nIdealWidth = nCurWidth > nIdeal ? nIdeal : nCurWidth; 671cdf0e10cSrcweir sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight; 672cdf0e10cSrcweir 673cdf0e10cSrcweir ::Size aNewSize( nIdealWidth, nIdealHeight ); 674cdf0e10cSrcweir 675cdf0e10cSrcweir sal_Bool bModified( sal_False ); 676cdf0e10cSrcweir BitmapEx aBitmapEx = aImage.GetBitmapEx(); 677cdf0e10cSrcweir bModified = aBitmapEx.Scale( aNewSize, BMP_SCALE_INTERPOLATE ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir if ( bModified ) 680cdf0e10cSrcweir aImage = Image( aBitmapEx ); 681cdf0e10cSrcweir } 682cdf0e10cSrcweir } 683cdf0e10cSrcweir return aImage; 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686d026be40SAriel Constenla-Haile /** Copied from svtools/inc/acceleratorexecute.hxx */ 687d026be40SAriel Constenla-Haile static css::awt::KeyEvent lcl_VCLKey2AWTKey( 688d026be40SAriel Constenla-Haile const KeyCode& aVCLKey) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir css::awt::KeyEvent aAWTKey; 691cdf0e10cSrcweir aAWTKey.Modifiers = 0; 692cdf0e10cSrcweir aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode(); 693cdf0e10cSrcweir 694cdf0e10cSrcweir if (aVCLKey.IsShift()) 695cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT; 696cdf0e10cSrcweir if (aVCLKey.IsMod1()) 697cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1; 698cdf0e10cSrcweir if (aVCLKey.IsMod2()) 699cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2; 700cdf0e10cSrcweir if (aVCLKey.IsMod3()) 701cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3; 702cdf0e10cSrcweir 703cdf0e10cSrcweir return aAWTKey; 704cdf0e10cSrcweir } 705cdf0e10cSrcweir 706cdf0e10cSrcweir KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir sal_Bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ); 709cdf0e10cSrcweir sal_Bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ); 710cdf0e10cSrcweir sal_Bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ); 711cdf0e10cSrcweir sal_Bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ); 712cdf0e10cSrcweir sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode; 713cdf0e10cSrcweir 714cdf0e10cSrcweir return KeyCode(nKey, bShift, bMod1, bMod2, bMod3); 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717d026be40SAriel Constenla-Haile } 718cdf0e10cSrcweir 719cdf0e10cSrcweir 720d026be40SAriel Constenla-Haile ::sal_Bool SAL_CALL VCLXMenu::isPopupMenu( ) 721d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 724cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 725cdf0e10cSrcweir return IsPopupMenu(); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir 728d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::clear( ) 729d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 732cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 733cdf0e10cSrcweir if ( mpMenu ) 734cdf0e10cSrcweir mpMenu->Clear(); 735cdf0e10cSrcweir } 736cdf0e10cSrcweir 737cdf0e10cSrcweir 738d026be40SAriel Constenla-Haile css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType( 739d026be40SAriel Constenla-Haile ::sal_Int16 nItemPos ) 740d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 743cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 744cdf0e10cSrcweir 745d026be40SAriel Constenla-Haile css::awt::MenuItemType aMenuItemType = 746d026be40SAriel Constenla-Haile css::awt::MenuItemType_DONTKNOW; 747cdf0e10cSrcweir if ( mpMenu ) 748cdf0e10cSrcweir { 749d026be40SAriel Constenla-Haile aMenuItemType = ( (css::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir return aMenuItemType; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::hideDisabledEntries( 756d026be40SAriel Constenla-Haile ::sal_Bool bHide ) 757d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 760cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 761cdf0e10cSrcweir if ( mpMenu ) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir if ( bHide ) 764cdf0e10cSrcweir mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES ); 765cdf0e10cSrcweir else 766cdf0e10cSrcweir mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES ); 767cdf0e10cSrcweir } 768cdf0e10cSrcweir } 769cdf0e10cSrcweir 770cdf0e10cSrcweir 771cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXMenu::isInExecute( ) 772d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 775cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 776cdf0e10cSrcweir 777cdf0e10cSrcweir if ( mpMenu && IsPopupMenu() ) 778cdf0e10cSrcweir return ( (PopupMenu*) mpMenu )->IsInExecute(); 779cdf0e10cSrcweir else 780cdf0e10cSrcweir return sal_False; 781cdf0e10cSrcweir } 782cdf0e10cSrcweir 783cdf0e10cSrcweir 784cdf0e10cSrcweir void SAL_CALL VCLXMenu::endExecute() 785d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 788cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 789cdf0e10cSrcweir 790cdf0e10cSrcweir if ( mpMenu && IsPopupMenu() ) 791cdf0e10cSrcweir ( (PopupMenu*) mpMenu )->EndExecute(); 792cdf0e10cSrcweir } 793cdf0e10cSrcweir 794cdf0e10cSrcweir 795d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::enableAutoMnemonics( 796d026be40SAriel Constenla-Haile ::sal_Bool bEnable ) 797d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 800cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 801cdf0e10cSrcweir if ( mpMenu ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir if ( !bEnable ) 804cdf0e10cSrcweir mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS ); 805cdf0e10cSrcweir else 806cdf0e10cSrcweir mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS ); 807cdf0e10cSrcweir } 808cdf0e10cSrcweir } 809cdf0e10cSrcweir 810cdf0e10cSrcweir 811d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setAcceleratorKeyEvent( 812d026be40SAriel Constenla-Haile ::sal_Int16 nItemId, 813d026be40SAriel Constenla-Haile const css::awt::KeyEvent& aKeyEvent ) 814d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 817cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 818cdf0e10cSrcweir 819d026be40SAriel Constenla-Haile if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 820cdf0e10cSrcweir { 821cdf0e10cSrcweir KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent ); 822cdf0e10cSrcweir mpMenu->SetAccelKey( nItemId, aVCLKeyCode ); 823cdf0e10cSrcweir } 824cdf0e10cSrcweir } 825cdf0e10cSrcweir 826cdf0e10cSrcweir 827d026be40SAriel Constenla-Haile css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent( 828d026be40SAriel Constenla-Haile ::sal_Int16 nItemId ) 829d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 832cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 833cdf0e10cSrcweir 834d026be40SAriel Constenla-Haile css::awt::KeyEvent aKeyEvent; 835d026be40SAriel Constenla-Haile if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId ); 838cdf0e10cSrcweir aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode ); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir return aKeyEvent; 842cdf0e10cSrcweir } 843cdf0e10cSrcweir 844cdf0e10cSrcweir 845d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setHelpText( 846d026be40SAriel Constenla-Haile ::sal_Int16 nItemId, 847d026be40SAriel Constenla-Haile const OUString& sHelpText ) 848d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 851cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 852cdf0e10cSrcweir 853d026be40SAriel Constenla-Haile if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir mpMenu->SetHelpText( nItemId, sHelpText ); 856cdf0e10cSrcweir } 857cdf0e10cSrcweir } 858cdf0e10cSrcweir 859cdf0e10cSrcweir 860d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getHelpText( 861d026be40SAriel Constenla-Haile ::sal_Int16 nItemId ) 862d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 863cdf0e10cSrcweir { 864cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 865cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 866cdf0e10cSrcweir 867cdf0e10cSrcweir rtl::OUString sHelpText; 868d026be40SAriel Constenla-Haile if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 869cdf0e10cSrcweir { 870cdf0e10cSrcweir sHelpText = mpMenu->GetHelpText( nItemId ); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir return sHelpText; 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir 877d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setTipHelpText( 878d026be40SAriel Constenla-Haile ::sal_Int16 nItemId, 879d026be40SAriel Constenla-Haile const OUString& sTipHelpText ) 880d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 881cdf0e10cSrcweir { 882cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 883cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 884cdf0e10cSrcweir 885d026be40SAriel Constenla-Haile if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir mpMenu->SetTipHelpText( nItemId, sTipHelpText ); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir 892d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getTipHelpText( 893d026be40SAriel Constenla-Haile ::sal_Int16 nItemId ) 894d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 897cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 898cdf0e10cSrcweir 899cdf0e10cSrcweir rtl::OUString sTipHelpText; 900d026be40SAriel Constenla-Haile if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir sTipHelpText = mpMenu->GetTipHelpText( nItemId ); 903cdf0e10cSrcweir } 904cdf0e10cSrcweir return sTipHelpText; 905cdf0e10cSrcweir } 906cdf0e10cSrcweir 907cdf0e10cSrcweir 908cdf0e10cSrcweir void SAL_CALL VCLXMenu::setItemImage( 909cdf0e10cSrcweir ::sal_Int16 nItemId, 910d026be40SAriel Constenla-Haile const css::uno::Reference< css::graphic::XGraphic >& xGraphic, 911d026be40SAriel Constenla-Haile ::sal_Bool bScale ) 912d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 915cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 916cdf0e10cSrcweir 917d026be40SAriel Constenla-Haile if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale ); 920cdf0e10cSrcweir mpMenu->SetItemImage( nItemId, aImage ); 921cdf0e10cSrcweir } 922cdf0e10cSrcweir } 923cdf0e10cSrcweir 924cdf0e10cSrcweir 925d026be40SAriel Constenla-Haile css::uno::Reference< css::graphic::XGraphic > SAL_CALL 926d026be40SAriel Constenla-Haile VCLXMenu::getItemImage( 927d026be40SAriel Constenla-Haile ::sal_Int16 nItemId ) 928d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException) 929cdf0e10cSrcweir { 930cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 931cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); 932cdf0e10cSrcweir 933d026be40SAriel Constenla-Haile css::uno::Reference< css::graphic::XGraphic > rxGraphic; 934cdf0e10cSrcweir 935d026be40SAriel Constenla-Haile if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir Image aImage = mpMenu->GetItemImage( nItemId ); 938cdf0e10cSrcweir if ( !!aImage ) 939cdf0e10cSrcweir rxGraphic = aImage.GetXGraphic(); 940cdf0e10cSrcweir } 941cdf0e10cSrcweir return rxGraphic; 942cdf0e10cSrcweir } 943cdf0e10cSrcweir 944cdf0e10cSrcweir 945cdf0e10cSrcweir 946cdf0e10cSrcweir DBG_NAME(VCLXMenuBar); 947cdf0e10cSrcweir 948cdf0e10cSrcweir VCLXMenuBar::VCLXMenuBar() 949cdf0e10cSrcweir { 950cdf0e10cSrcweir DBG_CTOR( VCLXMenuBar, 0 ); 951cdf0e10cSrcweir ImplCreateMenu( sal_False ); 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( (Menu *)pMenuBar ) 955cdf0e10cSrcweir { 956cdf0e10cSrcweir DBG_CTOR( VCLXMenuBar, 0 ); 957cdf0e10cSrcweir } 958cdf0e10cSrcweir 959cdf0e10cSrcweir 960cdf0e10cSrcweir DBG_NAME(VCLXPopupMenu); 961cdf0e10cSrcweir 962cdf0e10cSrcweir VCLXPopupMenu::VCLXPopupMenu() 963cdf0e10cSrcweir { 964cdf0e10cSrcweir DBG_CTOR( VCLXPopupMenu, 0 ); 965cdf0e10cSrcweir ImplCreateMenu( sal_True ); 966cdf0e10cSrcweir } 967