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

Generated by: LCOV version 1.10