LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/toolkit/source/awt - vclxmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 102 439 23.2 %
Date: 2013-07-09 Functions: 25 64 39.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10