LCOV - code coverage report
Current view: top level - svtools/source/control - toolbarmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 756 0.0 %
Date: 2012-08-25 Functions: 0 80 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 824 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      30                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      31                 :            : #include <comphelper/processfactory.hxx>
      32                 :            : 
      33                 :            : #include <vcl/dockwin.hxx>
      34                 :            : #include <vcl/decoview.hxx>
      35                 :            : #include <vcl/image.hxx>
      36                 :            : #include <vcl/taskpanelist.hxx>
      37                 :            : #include <vcl/toolbox.hxx>
      38                 :            : 
      39                 :            : #include "svtools/valueset.hxx"
      40                 :            : #include "svtools/toolbarmenu.hxx"
      41                 :            : #include "toolbarmenuimp.hxx"
      42                 :            : 
      43                 :            : using ::rtl::OUString;
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using namespace ::com::sun::star::lang;
      46                 :            : using namespace ::com::sun::star::frame;
      47                 :            : using namespace ::com::sun::star::accessibility;
      48                 :            : 
      49                 :            : namespace svtools {
      50                 :            : 
      51                 :            : // --------------------------------------------------------------------
      52                 :            : 
      53                 :          0 : static Window* GetTopMostParentSystemWindow( Window* pWindow )
      54                 :            : {
      55                 :            :     OSL_ASSERT( pWindow );
      56         [ #  # ]:          0 :     if ( pWindow )
      57                 :            :     {
      58                 :            :         // ->manually search topmost system window
      59                 :            :         // required because their might be another system window between this and the top window
      60                 :          0 :         pWindow = pWindow->GetParent();
      61                 :          0 :         SystemWindow* pTopMostSysWin = NULL;
      62         [ #  # ]:          0 :         while ( pWindow )
      63                 :            :         {
      64         [ #  # ]:          0 :             if ( pWindow->IsSystemWindow() )
      65                 :          0 :                 pTopMostSysWin = (SystemWindow*)pWindow;
      66                 :          0 :             pWindow = pWindow->GetParent();
      67                 :            :         }
      68                 :          0 :         pWindow = pTopMostSysWin;
      69                 :            :         OSL_ASSERT( pWindow );
      70                 :          0 :         return pWindow;
      71                 :            :     }
      72                 :            : 
      73                 :          0 :     return NULL;
      74                 :            : }
      75                 :            : 
      76                 :            : // --------------------------------------------------------------------
      77                 :            : 
      78                 :          0 : void ToolbarMenuEntry::init( int nEntryId, MenuItemBits nBits )
      79                 :            : {
      80                 :          0 :     mnEntryId = nEntryId;
      81                 :          0 :     mnBits = nBits;
      82                 :            : 
      83                 :          0 :     mbHasText = false;
      84                 :          0 :     mbHasImage = false;
      85                 :          0 :     mbChecked = false;
      86                 :          0 :     mbEnabled = true;
      87                 :            : 
      88                 :          0 :     mpControl = NULL;
      89                 :          0 : }
      90                 :            : 
      91                 :            : // --------------------------------------------------------------------
      92                 :            : 
      93                 :          0 : ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const String& rText, MenuItemBits nBits )
      94 [ #  # ][ #  # ]:          0 : : mrMenu( rMenu )
      95                 :            : {
      96                 :          0 :     init( nEntryId, nBits );
      97                 :            : 
      98         [ #  # ]:          0 :     maText = rText;
      99                 :          0 :     mbHasText = true;
     100                 :          0 : }
     101                 :            : 
     102                 :            : // --------------------------------------------------------------------
     103                 :            : 
     104                 :          0 : ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const Image& rImage, const String& rText, MenuItemBits nBits )
     105 [ #  # ][ #  # ]:          0 : : mrMenu( rMenu )
     106                 :            : {
     107                 :          0 :     init( nEntryId, nBits );
     108                 :            : 
     109         [ #  # ]:          0 :     maText = rText;
     110                 :          0 :     mbHasText = true;
     111                 :            : 
     112         [ #  # ]:          0 :     maImage = rImage;
     113                 :          0 :     mbHasImage = true;
     114                 :          0 : }
     115                 :            : 
     116                 :            : // --------------------------------------------------------------------
     117                 :            : 
     118                 :          0 : ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, Control* pControl, MenuItemBits nBits )
     119 [ #  # ][ #  # ]:          0 : : mrMenu( rMenu )
     120                 :            : {
     121                 :          0 :     init( nEntryId, nBits );
     122                 :            : 
     123         [ #  # ]:          0 :     if( pControl )
     124                 :            :     {
     125                 :          0 :         mpControl = pControl;
     126         [ #  # ]:          0 :         mpControl->Show();
     127                 :            :     }
     128                 :          0 : }
     129                 :            : 
     130                 :            : // --------------------------------------------------------------------
     131                 :            : 
     132         [ #  # ]:          0 : ToolbarMenuEntry::~ToolbarMenuEntry()
     133                 :            : {
     134         [ #  # ]:          0 :     if( mxAccContext.is() )
     135                 :            :     {
     136         [ #  # ]:          0 :         Reference< XComponent > xComponent( mxAccContext, UNO_QUERY );
     137         [ #  # ]:          0 :         if( xComponent.is() )
     138 [ #  # ][ #  # ]:          0 :             xComponent->dispose();
     139                 :          0 :         mxAccContext.clear();
     140                 :            :     }
     141 [ #  # ][ #  # ]:          0 :     delete mpControl;
     142                 :          0 : }
     143                 :            : 
     144                 :            : // --------------------------------------------------------------------
     145                 :            : 
     146                 :          0 : const Reference< XAccessibleContext >& ToolbarMenuEntry::GetAccessible( bool bCreate /* = false */ )
     147                 :            : {
     148 [ #  # ][ #  # ]:          0 :     if( !mxAccContext.is() && bCreate )
                 [ #  # ]
     149                 :            :     {
     150         [ #  # ]:          0 :         if( mpControl )
     151                 :            :         {
     152 [ #  # ][ #  # ]:          0 :             mxAccContext = Reference< XAccessibleContext >( mpControl->GetAccessible( sal_True ), UNO_QUERY );
     153                 :            :         }
     154                 :            :         else
     155                 :            :         {
     156 [ #  # ][ #  # ]:          0 :             mxAccContext = Reference< XAccessibleContext >( new ToolbarMenuEntryAcc( this ) );
                 [ #  # ]
     157                 :            :         }
     158                 :            :     }
     159                 :            : 
     160                 :          0 :     return mxAccContext;
     161                 :            : }
     162                 :            : 
     163                 :            : // --------------------------------------------------------------------
     164                 :            : 
     165                 :          0 : sal_Int32 ToolbarMenuEntry::getAccessibleChildCount() throw (RuntimeException)
     166                 :            : {
     167         [ #  # ]:          0 :     if( mpControl )
     168                 :            :     {
     169                 :          0 :         const Reference< XAccessibleContext >& xContext = GetAccessible( true );
     170         [ #  # ]:          0 :         if( xContext.is() )
     171                 :            :         {
     172                 :          0 :             return xContext->getAccessibleChildCount();
     173                 :            :         }
     174                 :            :     }
     175                 :          0 :     return 1;
     176                 :            : }
     177                 :            : 
     178                 :            : // --------------------------------------------------------------------
     179                 :            : 
     180                 :          0 : Reference< XAccessible > ToolbarMenuEntry::getAccessibleChild( sal_Int32 index ) throw (IndexOutOfBoundsException, RuntimeException)
     181                 :            : {
     182                 :          0 :     const Reference< XAccessibleContext >& xContext = GetAccessible( true );
     183         [ #  # ]:          0 :     if( mpControl )
     184                 :            :     {
     185         [ #  # ]:          0 :         if( xContext.is() )
     186                 :            :         {
     187                 :          0 :             return xContext->getAccessibleChild(index);
     188                 :            :         }
     189                 :            :     }
     190         [ #  # ]:          0 :     else if( index == 0 )
     191                 :            :     {
     192         [ #  # ]:          0 :         Reference< XAccessible > xRet( xContext, UNO_QUERY );
     193         [ #  # ]:          0 :         if( xRet.is() )
     194         [ #  # ]:          0 :             return xRet;
     195                 :            :     }
     196                 :            : 
     197         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     198                 :            : }
     199                 :            : 
     200                 :            : // --------------------------------------------------------------------
     201                 :            : 
     202                 :          0 : ToolbarMenu_Impl::ToolbarMenu_Impl( ToolbarMenu& rMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame )
     203                 :            : : mrMenu( rMenu )
     204                 :            : , mxFrame( xFrame )
     205                 :            : , mxServiceManager( ::comphelper::getProcessServiceFactory() )
     206                 :            : , mnCheckPos(0)
     207                 :            : , mnImagePos(0)
     208                 :            : , mnTextPos(0)
     209                 :            : , mnHighlightedEntry(-1)
     210                 :            : , mnSelectedEntry(-1)
     211 [ #  # ][ #  # ]:          0 : , mnLastColumn(0)
                 [ #  # ]
     212                 :            : {
     213                 :          0 : }
     214                 :            : 
     215                 :            : // --------------------------------------------------------------------
     216                 :            : 
     217                 :          0 : ToolbarMenu_Impl::~ToolbarMenu_Impl()
     218                 :            : {
     219         [ #  # ]:          0 :     setAccessible( 0 );
     220                 :          0 : }
     221                 :            : 
     222                 :            : // --------------------------------------------------------------------
     223                 :            : 
     224                 :          0 : void ToolbarMenu_Impl::setAccessible( ToolbarMenuAcc* pAccessible )
     225                 :            : {
     226         [ #  # ]:          0 :     if( mxAccessible.get() != pAccessible )
     227                 :            :     {
     228         [ #  # ]:          0 :         if( mxAccessible.is() )
     229                 :          0 :             mxAccessible->dispose();
     230                 :            : 
     231                 :          0 :         mxAccessible.set( pAccessible );
     232                 :            :     }
     233                 :          0 : }
     234                 :            : 
     235                 :            : // -----------------------------------------------------------------------
     236                 :            : 
     237                 :          0 : void ToolbarMenu_Impl::fireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
     238                 :            : {
     239         [ #  # ]:          0 :     if( mxAccessible.is() )
     240                 :          0 :         mxAccessible->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
     241                 :          0 : }
     242                 :            : 
     243                 :            : // -----------------------------------------------------------------------
     244                 :            : 
     245                 :          0 : bool ToolbarMenu_Impl::hasAccessibleListeners()
     246                 :            : {
     247 [ #  # ][ #  # ]:          0 :     return( mxAccessible.is() && mxAccessible->HasAccessibleListeners() );
     248                 :            : }
     249                 :            : 
     250                 :            : // --------------------------------------------------------------------
     251                 :            : 
     252                 :          0 : sal_Int32 ToolbarMenu_Impl::getAccessibleChildCount() throw (RuntimeException)
     253                 :            : {
     254                 :          0 :     sal_Int32 nCount = 0;
     255                 :          0 :     const int nEntryCount = maEntryVector.size();
     256         [ #  # ]:          0 :     for( int nEntry = 0; nEntry < nEntryCount; nEntry++ )
     257                 :            :     {
     258                 :          0 :         ToolbarMenuEntry* pEntry = maEntryVector[nEntry];
     259         [ #  # ]:          0 :         if( pEntry )
     260                 :            :         {
     261         [ #  # ]:          0 :             if( pEntry->mpControl )
     262                 :            :             {
     263                 :          0 :                 nCount += pEntry->getAccessibleChildCount();
     264                 :            :             }
     265                 :            :             else
     266                 :            :             {
     267                 :          0 :                 nCount += 1;
     268                 :            :             }
     269                 :            :         }
     270                 :            :     }
     271                 :            : 
     272                 :          0 :     return nCount;
     273                 :            : }
     274                 :            : 
     275                 :            : // --------------------------------------------------------------------
     276                 :            : 
     277                 :          0 : Reference< XAccessible > ToolbarMenu_Impl::getAccessibleChild( sal_Int32 index ) throw (IndexOutOfBoundsException, RuntimeException)
     278                 :            : {
     279                 :          0 :     const int nEntryCount = maEntryVector.size();
     280         [ #  # ]:          0 :     for( int nEntry = 0; nEntry < nEntryCount; nEntry++ )
     281                 :            :     {
     282                 :          0 :         ToolbarMenuEntry* pEntry = maEntryVector[nEntry];
     283         [ #  # ]:          0 :         if( pEntry )
     284                 :            :         {
     285                 :          0 :             const sal_Int32 nCount = pEntry->getAccessibleChildCount();
     286         [ #  # ]:          0 :             if( index < nCount )
     287                 :            :             {
     288                 :          0 :                 return pEntry->getAccessibleChild( index );
     289                 :            :             }
     290                 :          0 :             index -= nCount;
     291                 :            :         }
     292                 :            :     }
     293                 :            : 
     294         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     295                 :            : }
     296                 :            : 
     297                 :            : // --------------------------------------------------------------------
     298                 :            : 
     299                 :          0 : Reference< XAccessible > ToolbarMenu_Impl::getAccessibleChild( Control* pControl, sal_Int32 childIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     300                 :            : {
     301                 :          0 :     const int nEntryCount = maEntryVector.size();
     302         [ #  # ]:          0 :     for( int nEntry = 0; nEntry < nEntryCount; nEntry++ )
     303                 :            :     {
     304                 :          0 :         ToolbarMenuEntry* pEntry = maEntryVector[nEntry];
     305 [ #  # ][ #  # ]:          0 :         if( pEntry && (pEntry->mpControl == pControl) )
     306                 :            :         {
     307                 :          0 :             return pEntry->getAccessibleChild( childIndex );
     308                 :            :         }
     309                 :            :     }
     310                 :            : 
     311         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     312                 :            : }
     313                 :            : 
     314                 :            : // --------------------------------------------------------------------
     315                 :            : 
     316                 :          0 : void ToolbarMenu_Impl::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     317                 :            : {
     318                 :          0 :     const int nEntryCount = maEntryVector.size();
     319         [ #  # ]:          0 :     for( int nEntry = 0; nEntry < nEntryCount; nEntry++ )
     320                 :            :     {
     321                 :          0 :         ToolbarMenuEntry* pEntry = maEntryVector[nEntry];
     322         [ #  # ]:          0 :         if( pEntry )
     323                 :            :         {
     324                 :          0 :             const sal_Int32 nCount = pEntry->getAccessibleChildCount();
     325         [ #  # ]:          0 :             if( nChildIndex < nCount )
     326                 :            :             {
     327         [ #  # ]:          0 :                 if( pEntry->mpControl )
     328                 :            :                 {
     329 [ #  # ][ #  # ]:          0 :                     Reference< XAccessibleSelection > xSel( pEntry->GetAccessible(true), UNO_QUERY_THROW );
     330 [ #  # ][ #  # ]:          0 :                     xSel->selectAccessibleChild(nChildIndex);
     331                 :            :                 }
     332         [ #  # ]:          0 :                 else if( pEntry->mnEntryId != TITLE_ID )
     333                 :            :                 {
     334                 :          0 :                     mrMenu.implSelectEntry( nEntry );
     335                 :            :                 }
     336                 :          0 :                 return;
     337                 :            :             }
     338                 :          0 :             nChildIndex -= nCount;
     339                 :            :         }
     340                 :            :     }
     341                 :            : 
     342         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     343                 :            : }
     344                 :            : 
     345                 :            : // --------------------------------------------------------------------
     346                 :            : 
     347                 :          0 : sal_Bool ToolbarMenu_Impl::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     348                 :            : {
     349                 :          0 :     const int nEntryCount = maEntryVector.size();
     350         [ #  # ]:          0 :     for( int nEntry = 0; nEntry < nEntryCount; nEntry++ )
     351                 :            :     {
     352                 :          0 :         ToolbarMenuEntry* pEntry = maEntryVector[nEntry];
     353         [ #  # ]:          0 :         if( pEntry )
     354                 :            :         {
     355                 :          0 :             const sal_Int32 nCount = pEntry->getAccessibleChildCount();
     356         [ #  # ]:          0 :             if( nChildIndex < nCount )
     357                 :            :             {
     358         [ #  # ]:          0 :                 if( mnHighlightedEntry == nEntry )
     359                 :            :                 {
     360         [ #  # ]:          0 :                     if( pEntry->mpControl )
     361                 :            :                     {
     362 [ #  # ][ #  # ]:          0 :                         Reference< XAccessibleSelection > xSel( pEntry->GetAccessible(true), UNO_QUERY_THROW );
     363 [ #  # ][ #  # ]:          0 :                         xSel->isAccessibleChildSelected(nChildIndex);
     364                 :            :                     }
     365                 :          0 :                     return true;
     366                 :            :                 }
     367                 :            :                 else
     368                 :            :                 {
     369                 :          0 :                     return false;
     370                 :            :                 }
     371                 :            :             }
     372                 :          0 :             nChildIndex -= nCount;
     373                 :            :         }
     374                 :            :     }
     375                 :            : 
     376         [ #  # ]:          0 :     throw IndexOutOfBoundsException();
     377                 :            : }
     378                 :            : 
     379                 :            : // --------------------------------------------------------------------
     380                 :            : 
     381                 :          0 : void ToolbarMenu_Impl::clearAccessibleSelection()
     382                 :            : {
     383         [ #  # ]:          0 :     if( mnHighlightedEntry != -1 )
     384                 :            :     {
     385                 :          0 :         mrMenu.implHighlightEntry( mnHighlightedEntry, false );
     386                 :          0 :         mnHighlightedEntry = -1;
     387                 :            :     }
     388                 :          0 : }
     389                 :            : 
     390                 :            : 
     391                 :            : // --------------------------------------------------------------------
     392                 :            : 
     393                 :          0 : void ToolbarMenu_Impl::notifyHighlightedEntry()
     394                 :            : {
     395         [ #  # ]:          0 :     if( hasAccessibleListeners() )
     396                 :            :     {
     397                 :          0 :         ToolbarMenuEntry* pEntry = implGetEntry( mnHighlightedEntry );
     398 [ #  # ][ #  # ]:          0 :         if( pEntry && pEntry->mbEnabled && (pEntry->mnEntryId != TITLE_ID) )
                 [ #  # ]
     399                 :            :         {
     400                 :          0 :             Any aNew;
     401         [ #  # ]:          0 :             Any aOld( mxOldSelection );
     402         [ #  # ]:          0 :             if( pEntry->mpControl )
     403                 :            :             {
     404                 :          0 :                 sal_Int32 nChildIndex = 0;
     405                 :            :                 // todo: if other controls than ValueSet are allowed, addapt this code
     406         [ #  # ]:          0 :                 ValueSet* pValueSet = dynamic_cast< ValueSet* >( pEntry->mpControl );
     407         [ #  # ]:          0 :                 if( pValueSet )
     408         [ #  # ]:          0 :                     nChildIndex = static_cast< sal_Int32 >( pValueSet->GetItemPos( pValueSet->GetSelectItemId() ) );
     409                 :            : 
     410 [ #  # ][ #  # ]:          0 :                 if( nChildIndex >= pEntry->getAccessibleChildCount() )
     411                 :          0 :                     return;
     412                 :            : 
     413 [ #  # ][ #  # ]:          0 :                 aNew <<= getAccessibleChild( pEntry->mpControl, nChildIndex );
     414                 :            :             }
     415                 :            :             else
     416                 :            :             {
     417 [ #  # ][ #  # ]:          0 :                 aNew <<= pEntry->GetAccessible(true);
     418                 :            :             }
     419                 :            : 
     420         [ #  # ]:          0 :             fireAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOld, aNew );
     421         [ #  # ]:          0 :             fireAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOld, aNew );
     422 [ #  # ][ #  # ]:          0 :             fireAccessibleEvent( AccessibleEventId::STATE_CHANGED, Any(), Any( AccessibleStateType::FOCUSED ) );
     423 [ #  # ][ #  # ]:          0 :             aNew >>= mxOldSelection;
                 [ #  # ]
     424                 :            :         }
     425                 :            :     }
     426                 :            : }
     427                 :            : 
     428                 :            : // --------------------------------------------------------------------
     429                 :            : 
     430                 :          0 : ToolbarMenuEntry* ToolbarMenu_Impl::implGetEntry( int nEntry ) const
     431                 :            : {
     432 [ #  # ][ #  # ]:          0 :     if( (nEntry < 0) || (nEntry >= (int)maEntryVector.size() ) )
                 [ #  # ]
     433                 :          0 :         return NULL;
     434                 :            : 
     435                 :          0 :     return maEntryVector[nEntry];
     436                 :            : }
     437                 :            : 
     438                 :            : 
     439                 :            : // --------------------------------------------------------------------
     440                 :            : 
     441                 :          0 : IMPL_LINK( ToolbarMenu, HighlightHdl, Control *, pControl )
     442                 :            : {
     443                 :            :     (void)pControl;
     444                 :          0 :     mpImpl->notifyHighlightedEntry();
     445                 :          0 :     return 0;
     446                 :            : }
     447                 :            : 
     448                 :            : // ====================================================================
     449                 :            : 
     450                 :          0 : ToolbarMenu::ToolbarMenu( const Reference< XFrame >& rFrame, Window* pParentWindow, WinBits nBits )
     451                 :          0 : : DockingWindow(pParentWindow, nBits)
     452                 :            : {
     453         [ #  # ]:          0 :     implInit(rFrame);
     454                 :          0 : }
     455                 :            : 
     456                 :            : // --------------------------------------------------------------------
     457                 :            : 
     458                 :          0 : ToolbarMenu::ToolbarMenu( const Reference< XFrame >& rFrame, Window* pParentWindow, const ResId& rResId )
     459                 :          0 : : DockingWindow(pParentWindow, rResId)
     460                 :            : {
     461         [ #  # ]:          0 :     implInit(rFrame);
     462                 :          0 : }
     463                 :            : 
     464                 :            : // --------------------------------------------------------------------
     465                 :            : 
     466                 :          0 : void ToolbarMenu::implInit(const Reference< XFrame >& rFrame)
     467                 :            : {
     468         [ #  # ]:          0 :     mpImpl = new ToolbarMenu_Impl( *this, rFrame );
     469                 :            : 
     470                 :          0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     471                 :          0 :     SetControlBackground( rStyleSettings.GetMenuColor() );
     472                 :            : 
     473                 :          0 :     initWindow();
     474                 :            : 
     475                 :          0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
     476         [ #  # ]:          0 :     if ( pWindow )
     477                 :          0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
     478                 :          0 : }
     479                 :            : 
     480                 :            : // --------------------------------------------------------------------
     481                 :            : 
     482                 :          0 : ToolbarMenu::~ToolbarMenu()
     483                 :            : {
     484         [ #  # ]:          0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
     485         [ #  # ]:          0 :     if ( pWindow )
     486 [ #  # ][ #  # ]:          0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
     487                 :            : 
     488         [ #  # ]:          0 :     if ( mpImpl->mxStatusListener.is() )
     489                 :            :     {
     490         [ #  # ]:          0 :         mpImpl->mxStatusListener->dispose();
     491                 :          0 :         mpImpl->mxStatusListener.clear();
     492                 :            :     }
     493                 :            : 
     494                 :            :     // delete all menu entries
     495                 :          0 :     const int nEntryCount = mpImpl->maEntryVector.size();
     496                 :            :     int nEntry;
     497         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     498                 :            :     {
     499 [ #  # ][ #  # ]:          0 :         delete mpImpl->maEntryVector[nEntry];
     500                 :            :     }
     501                 :            : 
     502 [ #  # ][ #  # ]:          0 :     delete mpImpl;
     503         [ #  # ]:          0 : }
     504                 :            : 
     505                 :            : // --------------------------------------------------------------------
     506                 :            : 
     507                 :          0 : int ToolbarMenu::getSelectedEntryId() const
     508                 :            : {
     509                 :          0 :     ToolbarMenuEntry* pEntry = implGetEntry( mpImpl->mnSelectedEntry );
     510         [ #  # ]:          0 :     return pEntry ? pEntry->mnEntryId : -1;
     511                 :            : }
     512                 :            : 
     513                 :            : // --------------------------------------------------------------------
     514                 :            : 
     515                 :          0 : int ToolbarMenu::getHighlightedEntryId() const
     516                 :            : {
     517                 :          0 :     ToolbarMenuEntry* pEntry = implGetEntry( mpImpl->mnHighlightedEntry );
     518         [ #  # ]:          0 :     return pEntry ? pEntry->mnEntryId : -1;
     519                 :            : }
     520                 :            : 
     521                 :            : // --------------------------------------------------------------------
     522                 :            : 
     523                 :          0 : void ToolbarMenu::checkEntry( int nEntryId, bool bChecked )
     524                 :            : {
     525                 :          0 :     ToolbarMenuEntry* pEntry = implSearchEntry( nEntryId );
     526 [ #  # ][ #  # ]:          0 :     if( pEntry && pEntry->mbChecked != bChecked )
     527                 :            :     {
     528                 :          0 :         pEntry->mbChecked = bChecked;
     529                 :          0 :         Invalidate();
     530                 :            :     }
     531                 :          0 : }
     532                 :            : 
     533                 :            : // --------------------------------------------------------------------
     534                 :            : 
     535                 :          0 : void ToolbarMenu::enableEntry( int nEntryId, bool bEnable )
     536                 :            : {
     537                 :          0 :     ToolbarMenuEntry* pEntry = implSearchEntry( nEntryId );
     538 [ #  # ][ #  # ]:          0 :     if( pEntry && pEntry->mbEnabled != bEnable )
     539                 :            :     {
     540                 :          0 :         pEntry->mbEnabled = bEnable;
     541         [ #  # ]:          0 :         if( pEntry->mpControl )
     542                 :            :         {
     543                 :          0 :             pEntry->mpControl->Enable( bEnable );
     544                 :            : 
     545                 :            :             // hack for the valueset to make it paint itself anew
     546                 :          0 :             pEntry->mpControl->Resize();
     547                 :            :         }
     548                 :          0 :         Invalidate();
     549                 :            :     }
     550                 :          0 : }
     551                 :            : 
     552                 :            : // --------------------------------------------------------------------
     553                 :            : 
     554                 :          0 : void ToolbarMenu::setEntryText( int nEntryId, const String& rStr )
     555                 :            : {
     556                 :          0 :     ToolbarMenuEntry* pEntry = implSearchEntry( nEntryId );
     557 [ #  # ][ #  # ]:          0 :     if( pEntry && pEntry->maText != rStr )
                 [ #  # ]
     558                 :            :     {
     559                 :          0 :         pEntry->maText = rStr;
     560                 :          0 :         mpImpl->maSize = implCalcSize();
     561         [ #  # ]:          0 :         if( IsVisible() )
     562                 :          0 :             Invalidate();
     563                 :            :     }
     564                 :          0 : }
     565                 :            : 
     566                 :            : // --------------------------------------------------------------------
     567                 :            : 
     568                 :          0 : void ToolbarMenu::setEntryImage( int nEntryId, const Image& rImage )
     569                 :            : {
     570                 :          0 :     ToolbarMenuEntry* pEntry = implSearchEntry( nEntryId );
     571 [ #  # ][ #  # ]:          0 :     if( pEntry && pEntry->maImage != rImage )
                 [ #  # ]
     572                 :            :     {
     573                 :          0 :         pEntry->maImage = rImage;
     574                 :          0 :         mpImpl->maSize = implCalcSize();
     575         [ #  # ]:          0 :         if( IsVisible() )
     576                 :          0 :             Invalidate();
     577                 :            :     }
     578                 :          0 : }
     579                 :            : 
     580                 :            : // --------------------------------------------------------------------
     581                 :            : 
     582                 :          0 : void ToolbarMenu::initWindow()
     583                 :            : {
     584                 :          0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     585                 :            : 
     586                 :          0 :     SetPointFont( rStyleSettings.GetMenuFont() );
     587 [ #  # ][ #  # ]:          0 :     SetBackground( Wallpaper( GetControlBackground() ) );
                 [ #  # ]
     588                 :          0 :     SetTextColor( rStyleSettings.GetMenuTextColor() );
     589                 :          0 :     SetTextFillColor();
     590                 :          0 :     SetLineColor();
     591                 :            : 
     592                 :          0 :     mpImpl->maSize = implCalcSize();
     593                 :          0 : }
     594                 :            : 
     595                 :            : // --------------------------------------------------------------------
     596                 :            : 
     597                 :          0 : static long ImplGetNativeCheckAndRadioSize( Window* pWin, long& rCheckHeight, long& rRadioHeight, long &rMaxWidth )
     598                 :            : {
     599                 :          0 :     rMaxWidth = rCheckHeight = rRadioHeight = 0;
     600                 :            : 
     601                 :          0 :     ImplControlValue aVal;
     602         [ #  # ]:          0 :     Rectangle aNativeBounds;
     603         [ #  # ]:          0 :     Rectangle aNativeContent;
     604                 :          0 :     Point tmp( 0, 0 );
     605         [ #  # ]:          0 :     Rectangle aCtrlRegion( tmp, Size( 100, 15 ) );
     606 [ #  # ][ #  # ]:          0 :     if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM_CHECK_MARK ) )
     607                 :            :     {
     608         [ #  # ]:          0 :         if( pWin->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP),
     609                 :            :                                           ControlPart(PART_MENU_ITEM_CHECK_MARK),
     610                 :            :                                           aCtrlRegion,
     611                 :            :                                           ControlState(CTRL_STATE_ENABLED),
     612                 :            :                                           aVal,
     613                 :            :                                           OUString(),
     614                 :            :                                           aNativeBounds,
     615         [ #  # ]:          0 :                                           aNativeContent )
     616                 :            :         )
     617                 :            :         {
     618         [ #  # ]:          0 :             rCheckHeight = aNativeBounds.GetHeight();
     619         [ #  # ]:          0 :             rMaxWidth = aNativeContent.GetWidth();
     620                 :            :         }
     621                 :            :     }
     622 [ #  # ][ #  # ]:          0 :     if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM_RADIO_MARK ) )
     623                 :            :     {
     624         [ #  # ]:          0 :         if( pWin->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP),
     625                 :            :                                           ControlPart(PART_MENU_ITEM_RADIO_MARK),
     626                 :            :                                           aCtrlRegion,
     627                 :            :                                           ControlState(CTRL_STATE_ENABLED),
     628                 :            :                                           aVal,
     629                 :            :                                           OUString(),
     630                 :            :                                           aNativeBounds,
     631         [ #  # ]:          0 :                                           aNativeContent )
     632                 :            :         )
     633                 :            :         {
     634         [ #  # ]:          0 :             rRadioHeight = aNativeBounds.GetHeight();
     635         [ #  # ]:          0 :             rMaxWidth = Max (rMaxWidth, aNativeContent.GetWidth());
     636                 :            :         }
     637                 :            :     }
     638 [ #  # ][ #  # ]:          0 :     return (rCheckHeight > rRadioHeight) ? rCheckHeight : rRadioHeight;
     639                 :            : }
     640                 :            : 
     641                 :            : #define gfxExtra 7
     642                 :            : 
     643                 :          0 : Size ToolbarMenu::implCalcSize()
     644                 :            : {
     645         [ #  # ]:          0 :     const long nFontHeight = GetTextHeight();
     646                 :          0 :     long nExtra = nFontHeight/4;
     647                 :            : 
     648                 :          0 :     Size aSz;
     649                 :          0 :     Size aMaxImgSz;
     650                 :          0 :     long nMaxTextWidth = 0;
     651                 :          0 :     long nMinMenuItemHeight = nFontHeight+2;
     652                 :          0 :     sal_Bool bCheckable = sal_False;
     653                 :            : 
     654                 :          0 :     const int nEntryCount = mpImpl->maEntryVector.size();
     655                 :            :     int nEntry;
     656                 :            : 
     657                 :          0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
     658         [ #  # ]:          0 :     const bool bUseImages = rSettings.GetUseImagesInMenus();
     659                 :            : 
     660                 :            :     // get maximum image size
     661         [ #  # ]:          0 :     if( bUseImages )
     662                 :            :     {
     663         [ #  # ]:          0 :         for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     664                 :            :         {
     665                 :          0 :             ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
     666 [ #  # ][ #  # ]:          0 :             if( pEntry && pEntry->mbHasImage )
     667                 :            :             {
     668         [ #  # ]:          0 :                 Size aImgSz( pEntry->maImage.GetSizePixel() );
     669         [ #  # ]:          0 :                 nMinMenuItemHeight = std::max( nMinMenuItemHeight, aImgSz.Height() + 6 );
     670         [ #  # ]:          0 :                 aMaxImgSz.Width() = std::max( aMaxImgSz.Width(), aImgSz.Width() );
     671                 :            :             }
     672                 :            :         }
     673                 :            :     }
     674                 :            : 
     675                 :          0 :     mpImpl->mnCheckPos = nExtra;
     676                 :          0 :     mpImpl->mnImagePos = nExtra;
     677                 :          0 :     mpImpl->mnTextPos = mpImpl->mnImagePos + aMaxImgSz.Width();
     678                 :            : 
     679         [ #  # ]:          0 :     if ( aMaxImgSz.Width() )
     680         [ #  # ]:          0 :         mpImpl->mnTextPos += std::max( nExtra, 7L );
     681         [ #  # ]:          0 :     if ( bCheckable )
     682                 :          0 :         mpImpl->mnTextPos += 16;
     683                 :            : 
     684                 :            :     // set heights, calc maximum width
     685         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     686                 :            :     {
     687                 :          0 :         ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
     688                 :            : 
     689         [ #  # ]:          0 :         if( pEntry )
     690                 :            :         {
     691         [ #  # ]:          0 :             if ( ( pEntry->mnBits ) & ( MIB_RADIOCHECK | MIB_CHECKABLE ) )
     692                 :          0 :                 bCheckable = sal_True;
     693                 :            : 
     694                 :            :             // Text:
     695 [ #  # ][ #  # ]:          0 :             if( pEntry->mbHasText || pEntry->mbHasImage )
     696                 :            :             {
     697                 :          0 :                 pEntry->maSize.Height() = nMinMenuItemHeight;
     698                 :            : 
     699         [ #  # ]:          0 :                 if( pEntry->mbHasText )
     700                 :            :                 {
     701         [ #  # ]:          0 :                     long nTextWidth = GetCtrlTextWidth( pEntry->maText ) + mpImpl->mnTextPos + nExtra;
     702         [ #  # ]:          0 :                     nMaxTextWidth = std::max( nTextWidth, nMaxTextWidth );
     703                 :          0 :                 }
     704                 :            :             }
     705                 :            :             // Control:
     706         [ #  # ]:          0 :             else if( pEntry->mpControl )
     707                 :            :             {
     708                 :          0 :                 Size aControlSize( pEntry->mpControl->GetOutputSizePixel() );
     709                 :            : 
     710         [ #  # ]:          0 :                 nMaxTextWidth = std::max( aControlSize.Width(), nMaxTextWidth );
     711                 :          0 :                 pEntry->maSize.Height() = aControlSize.Height() + 1;
     712                 :            :             }
     713                 :            : 
     714 [ #  # ][ #  # ]:          0 :             if( pEntry->HasCheck() && !pEntry->mbHasImage )
                 [ #  # ]
     715                 :            :             {
     716         [ #  # ]:          0 :                 if( this->IsNativeControlSupported( CTRL_MENU_POPUP,
     717                 :            :                                                      (pEntry->mnBits & MIB_RADIOCHECK)
     718                 :            :                                                      ? PART_MENU_ITEM_CHECK_MARK
     719 [ #  # ][ #  # ]:          0 :                                                      : PART_MENU_ITEM_RADIO_MARK ) )
     720                 :            :                 {
     721                 :          0 :                     long nCheckHeight = 0, nRadioHeight = 0, nMaxCheckWidth = 0;
     722         [ #  # ]:          0 :                     ImplGetNativeCheckAndRadioSize( this, nCheckHeight, nRadioHeight, nMaxCheckWidth );
     723                 :            : 
     724         [ #  # ]:          0 :                     long nCtrlHeight = (pEntry->mnBits & MIB_RADIOCHECK) ? nCheckHeight : nRadioHeight;
     725                 :          0 :                     nMaxTextWidth += nCtrlHeight + gfxExtra;
     726                 :            :                 }
     727         [ #  # ]:          0 :                 else if( pEntry->mbChecked )
     728                 :            :                 {
     729                 :          0 :                     long nSymbolWidth = (nFontHeight*25)/40;
     730         [ #  # ]:          0 :                     if ( pEntry->mnBits & MIB_RADIOCHECK )
     731                 :          0 :                         nSymbolWidth = nFontHeight/2;
     732                 :            : 
     733                 :          0 :                     nMaxTextWidth += nSymbolWidth;
     734                 :            :                 }
     735                 :            :             }
     736                 :            :         }
     737                 :            :     }
     738                 :            : 
     739                 :          0 :     aSz.Width() = nMaxTextWidth + (BORDER_X<<1);
     740                 :            : 
     741                 :            :     // positionate controls
     742                 :          0 :     int nY = BORDER_Y;
     743         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     744                 :            :     {
     745                 :          0 :         ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
     746                 :            : 
     747         [ #  # ]:          0 :         if( pEntry )
     748                 :            :         {
     749                 :          0 :             pEntry->maSize.Width() = nMaxTextWidth;
     750                 :            : 
     751         [ #  # ]:          0 :             if( pEntry->mpControl )
     752                 :            :             {
     753                 :          0 :                 Size aControlSize( pEntry->mpControl->GetOutputSizePixel() );
     754                 :          0 :                 Point aControlPos( (aSz.Width() - aControlSize.Width())>>1, nY);
     755                 :            : 
     756         [ #  # ]:          0 :                 pEntry->mpControl->SetPosPixel( aControlPos );
     757                 :            : 
     758         [ #  # ]:          0 :                 pEntry->maRect = Rectangle( aControlPos, aControlSize );
     759                 :            :             }
     760                 :            :             else
     761                 :            :             {
     762         [ #  # ]:          0 :                 pEntry->maRect = Rectangle( Point( 0, nY ), pEntry->maSize );
     763                 :            :             }
     764                 :            : 
     765                 :          0 :             nY += pEntry->maSize.Height();
     766                 :            :         }
     767                 :            :         else
     768                 :            :         {
     769                 :          0 :             nY += SEPARATOR_HEIGHT;
     770                 :            :         }
     771                 :            :     }
     772                 :            : 
     773                 :          0 :     aSz.Height() += nY + BORDER_Y;
     774                 :            : 
     775                 :          0 :     return aSz;
     776                 :            : }
     777                 :            : 
     778                 :            : // --------------------------------------------------------------------
     779                 :            : 
     780                 :          0 : void ToolbarMenu::highlightFirstEntry()
     781                 :            : {
     782                 :          0 :     implChangeHighlightEntry( 0 );
     783                 :          0 : }
     784                 :            : 
     785                 :            : // --------------------------------------------------------------------
     786                 :            : 
     787                 :          0 : void ToolbarMenu::GetFocus()
     788                 :            : {
     789         [ #  # ]:          0 :     if( mpImpl->mnHighlightedEntry == -1 )
     790                 :          0 :         implChangeHighlightEntry( 0 );
     791                 :            : 
     792                 :          0 :     DockingWindow::GetFocus();
     793                 :          0 : }
     794                 :            : 
     795                 :            : // --------------------------------------------------------------------
     796                 :            : 
     797                 :          0 : void ToolbarMenu::LoseFocus()
     798                 :            : {
     799         [ #  # ]:          0 :     if( mpImpl->mnHighlightedEntry != -1 )
     800                 :          0 :         implChangeHighlightEntry( -1 );
     801                 :            : 
     802                 :          0 :     DockingWindow::LoseFocus();
     803                 :          0 : }
     804                 :            : 
     805                 :            : // --------------------------------------------------------------------
     806                 :            : 
     807                 :          0 : void ToolbarMenu::appendEntry( int nEntryId, const String& rStr, MenuItemBits nItemBits )
     808                 :            : {
     809         [ #  # ]:          0 :     appendEntry( new ToolbarMenuEntry( *this, nEntryId, rStr, nItemBits ) );
     810                 :          0 : }
     811                 :            : 
     812                 :            : // --------------------------------------------------------------------
     813                 :            : 
     814                 :          0 : void ToolbarMenu::appendEntry( int nEntryId, const String& rStr, const Image& rImage, MenuItemBits nItemBits )
     815                 :            : {
     816         [ #  # ]:          0 :     appendEntry( new ToolbarMenuEntry( *this, nEntryId, rImage, rStr, nItemBits ) );
     817                 :          0 : }
     818                 :            : 
     819                 :            : // --------------------------------------------------------------------
     820                 :            : 
     821                 :          0 : void ToolbarMenu::appendEntry( int nEntryId, Control* pControl, MenuItemBits nItemBits )
     822                 :            : {
     823         [ #  # ]:          0 :     appendEntry( new ToolbarMenuEntry( *this, nEntryId, pControl, nItemBits ) );
     824                 :          0 : }
     825                 :            : 
     826                 :            : // --------------------------------------------------------------------
     827                 :            : 
     828                 :          0 : void ToolbarMenu::appendEntry( ToolbarMenuEntry* pEntry )
     829                 :            : {
     830                 :          0 :     mpImpl->maEntryVector.push_back( pEntry );
     831                 :          0 :     mpImpl->maSize = implCalcSize();
     832         [ #  # ]:          0 :     if( IsVisible() )
     833                 :          0 :         Invalidate();
     834                 :          0 : }
     835                 :            : 
     836                 :            : // --------------------------------------------------------------------
     837                 :            : 
     838                 :          0 : void ToolbarMenu::appendSeparator()
     839                 :            : {
     840                 :          0 :     appendEntry( 0 );
     841                 :          0 : }
     842                 :            : 
     843                 :            : // --------------------------------------------------------------------
     844                 :            : 
     845                 :            : /** creates an empty ValueSet that is initialized and can be inserted with appendEntry. */
     846                 :          0 : ValueSet* ToolbarMenu::createEmptyValueSetControl()
     847                 :            : {
     848         [ #  # ]:          0 :     ValueSet* pSet = new ValueSet( this, WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT );
     849                 :          0 :     pSet->EnableFullItemMode( sal_False );
     850         [ #  # ]:          0 :     pSet->SetColor( GetControlBackground() );
     851         [ #  # ]:          0 :     pSet->SetHighlightHdl( LINK( this, ToolbarMenu, HighlightHdl ) );
     852                 :          0 :     return pSet;
     853                 :            : }
     854                 :            : 
     855                 :            : // --------------------------------------------------------------------
     856                 :            : 
     857                 :          0 : ToolbarMenuEntry* ToolbarMenu::implGetEntry( int nEntry ) const
     858                 :            : {
     859                 :          0 :     return mpImpl->implGetEntry( nEntry );
     860                 :            : }
     861                 :            : 
     862                 :            : // --------------------------------------------------------------------
     863                 :            : 
     864                 :          0 : ToolbarMenuEntry* ToolbarMenu::implSearchEntry( int nEntryId ) const
     865                 :            : {
     866                 :          0 :     const int nEntryCount = mpImpl->maEntryVector.size();
     867                 :            :     int nEntry;
     868         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     869                 :            :     {
     870                 :          0 :         ToolbarMenuEntry* p = mpImpl->maEntryVector[nEntry];
     871 [ #  # ][ #  # ]:          0 :         if( p && p->mnEntryId == nEntryId )
     872                 :            :         {
     873                 :          0 :             return p;
     874                 :            :         }
     875                 :            :     }
     876                 :            : 
     877                 :          0 :     return NULL;
     878                 :            : }
     879                 :            : 
     880                 :            : // --------------------------------------------------------------------
     881                 :            : 
     882                 :          0 : void ToolbarMenu::implHighlightEntry( int nHighlightEntry, bool bHighlight )
     883                 :            : {
     884         [ #  # ]:          0 :     Size    aSz( GetOutputSizePixel() );
     885                 :          0 :     long    nX = 0, nY = 0;
     886                 :            : 
     887                 :          0 :     const int nEntryCount = mpImpl->maEntryVector.size();
     888                 :            :     int nEntry;
     889         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
     890                 :            :     {
     891                 :          0 :         ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
     892 [ #  # ][ #  # ]:          0 :         if( pEntry && (nEntry == nHighlightEntry) )
     893                 :            :         {
     894                 :            :             // no highlights for controls only items
     895         [ #  # ]:          0 :             if( pEntry->mpControl )
     896                 :            :             {
     897         [ #  # ]:          0 :                 if( !bHighlight )
     898                 :            :                 {
     899         [ #  # ]:          0 :                     ValueSet* pValueSet = dynamic_cast< ValueSet* >( pEntry->mpControl );
     900         [ #  # ]:          0 :                     if( pValueSet )
     901                 :            :                     {
     902         [ #  # ]:          0 :                         pValueSet->SetNoSelection();
     903                 :            :                     }
     904                 :            :                 }
     905                 :            :                 break;
     906                 :            :             }
     907                 :            : 
     908                 :          0 :             bool bRestoreLineColor = false;
     909                 :          0 :             Color oldLineColor;
     910                 :          0 :             bool bDrawItemRect = true;
     911                 :            : 
     912         [ #  # ]:          0 :             Rectangle aItemRect( Point( nX, nY ), Size( aSz.Width(), pEntry->maSize.Height() ) );
     913         [ #  # ]:          0 :             if ( pEntry->mnBits & MIB_POPUPSELECT )
     914                 :            :             {
     915         [ #  # ]:          0 :                 long nFontHeight = GetTextHeight();
     916                 :          0 :                 aItemRect.Right() -= nFontHeight + nFontHeight/4;
     917                 :            :             }
     918                 :            : 
     919 [ #  # ][ #  # ]:          0 :             if( IsNativeControlSupported( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL ) )
     920                 :            :             {
     921         [ #  # ]:          0 :                 Size aPxSize( GetOutputSizePixel() );
     922         [ #  # ]:          0 :                 Push( PUSH_CLIPREGION );
     923 [ #  # ][ #  # ]:          0 :                 IntersectClipRegion( Rectangle( Point( nX, nY ), Size( aSz.Width(), pEntry->maSize.Height() ) ) );
     924         [ #  # ]:          0 :                 Rectangle aCtrlRect( Point( nX, 0 ), Size( aPxSize.Width()-nX, aPxSize.Height() ) );
     925                 :            :                 DrawNativeControl( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL,
     926                 :            :                                    aCtrlRect,
     927                 :            :                                    CTRL_STATE_ENABLED,
     928                 :            :                                    ImplControlValue(),
     929 [ #  # ][ #  # ]:          0 :                                    OUString() );
     930 [ #  # ][ #  # ]:          0 :                 if( bHighlight && IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM ) )
         [ #  # ][ #  # ]
     931                 :            :                 {
     932                 :          0 :                     bDrawItemRect = false;
     933         [ #  # ]:          0 :                     if( sal_False == DrawNativeControl( CTRL_MENU_POPUP, PART_MENU_ITEM,
     934                 :            :                                                     aItemRect,
     935                 :            :                                                     CTRL_STATE_SELECTED | ( pEntry->mbEnabled? CTRL_STATE_ENABLED: 0 ),
     936                 :            :                                                     ImplControlValue(),
     937 [ #  # ][ #  # ]:          0 :                                                     OUString() ) )
                 [ #  # ]
     938                 :            :                     {
     939                 :          0 :                         bDrawItemRect = bHighlight;
     940                 :            :                     }
     941                 :            :                 }
     942                 :            :                 else
     943                 :          0 :                     bDrawItemRect = bHighlight;
     944         [ #  # ]:          0 :                 Pop();
     945                 :            :             }
     946         [ #  # ]:          0 :             if( bDrawItemRect )
     947                 :            :             {
     948         [ #  # ]:          0 :                 if ( bHighlight )
     949                 :            :                 {
     950         [ #  # ]:          0 :                     if( pEntry->mbEnabled )
     951         [ #  # ]:          0 :                         SetFillColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
     952                 :            :                     else
     953                 :            :                     {
     954         [ #  # ]:          0 :                         SetFillColor();
     955                 :          0 :                         oldLineColor = GetLineColor();
     956         [ #  # ]:          0 :                         SetLineColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
     957                 :          0 :                         bRestoreLineColor = true;
     958                 :            :                     }
     959                 :            :                 }
     960                 :            :                 else
     961         [ #  # ]:          0 :                     SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
     962                 :            : 
     963         [ #  # ]:          0 :                 DrawRect( aItemRect );
     964                 :            :             }
     965         [ #  # ]:          0 :             implPaint( pEntry, bHighlight );
     966         [ #  # ]:          0 :             if( bRestoreLineColor )
     967         [ #  # ]:          0 :                 SetLineColor( oldLineColor );
     968                 :            :             break;
     969                 :            :         }
     970                 :            : 
     971         [ #  # ]:          0 :         nY += pEntry ? pEntry->maSize.Height() : SEPARATOR_HEIGHT;
     972                 :            :     }
     973                 :          0 : }
     974                 :            : 
     975                 :            : // --------------------------------------------------------------------
     976                 :            : 
     977                 :          0 : void ToolbarMenu::implSelectEntry( int nSelectedEntry )
     978                 :            : {
     979                 :          0 :     mpImpl->mnSelectedEntry = nSelectedEntry;
     980                 :            : 
     981                 :          0 :     ToolbarMenuEntry* pEntry = NULL;
     982         [ #  # ]:          0 :     if( nSelectedEntry != -1 )
     983                 :          0 :         pEntry = mpImpl->maEntryVector[ nSelectedEntry ];
     984                 :            : 
     985         [ #  # ]:          0 :     if( pEntry )
     986                 :          0 :         mpImpl->maSelectHdl.Call( this );
     987                 :          0 : }
     988                 :            : 
     989                 :            : // --------------------------------------------------------------------
     990                 :            : 
     991                 :          0 : void ToolbarMenu::MouseButtonDown( const MouseEvent& rMEvt )
     992                 :            : {
     993                 :          0 :     implHighlightEntry( rMEvt, true );
     994                 :            : 
     995                 :          0 :     implSelectEntry( mpImpl->mnHighlightedEntry );
     996                 :          0 : }
     997                 :            : 
     998                 :            : // --------------------------------------------------------------------
     999                 :            : 
    1000                 :          0 : void ToolbarMenu::MouseButtonUp( const MouseEvent& )
    1001                 :            : {
    1002                 :          0 : }
    1003                 :            : 
    1004                 :            : // --------------------------------------------------------------------
    1005                 :            : 
    1006                 :          0 : void ToolbarMenu::MouseMove( const MouseEvent& rMEvt )
    1007                 :            : {
    1008         [ #  # ]:          0 :     if ( !IsVisible() )
    1009                 :          0 :         return;
    1010                 :            : 
    1011                 :          0 :     implHighlightEntry( rMEvt, false );
    1012                 :            : }
    1013                 :            : 
    1014                 :            : // --------------------------------------------------------------------
    1015                 :            : 
    1016                 :          0 : void ToolbarMenu::implHighlightEntry( const MouseEvent& rMEvt, bool /*bMBDown*/ )
    1017                 :            : {
    1018                 :          0 :     long nY = 0;
    1019                 :          0 :     long nMouseY = rMEvt.GetPosPixel().Y();
    1020         [ #  # ]:          0 :     Size aOutSz = GetOutputSizePixel();
    1021 [ #  # ][ #  # ]:          0 :     if ( ( nMouseY >= 0 ) && ( nMouseY < aOutSz.Height() ) )
                 [ #  # ]
    1022                 :            :     {
    1023                 :          0 :         bool bHighlighted = sal_False;
    1024                 :            : 
    1025                 :          0 :         const int nEntryCount = mpImpl->maEntryVector.size();
    1026                 :            :         int nEntry;
    1027         [ #  # ]:          0 :         for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
    1028                 :            :         {
    1029                 :          0 :             ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
    1030         [ #  # ]:          0 :             if( pEntry )
    1031                 :            :             {
    1032                 :          0 :                 long nOldY = nY;
    1033                 :          0 :                 nY += pEntry->maSize.Height();
    1034                 :            : 
    1035         [ #  # ]:          0 :                 if( pEntry->mnEntryId != TITLE_ID )
    1036                 :            :                 {
    1037 [ #  # ][ #  # ]:          0 :                     if ( ( nOldY <= nMouseY ) && ( nY > nMouseY ) )
    1038                 :            :                     {
    1039         [ #  # ]:          0 :                         if( nEntry != mpImpl->mnHighlightedEntry )
    1040                 :            :                         {
    1041         [ #  # ]:          0 :                             implChangeHighlightEntry( nEntry );
    1042                 :            :                         }
    1043                 :          0 :                         bHighlighted = true;
    1044                 :            :                     }
    1045                 :            :                 }
    1046                 :            :             }
    1047                 :            :             else
    1048                 :            :             {
    1049                 :          0 :                 nY += SEPARATOR_HEIGHT;
    1050                 :            :             }
    1051                 :            :         }
    1052         [ #  # ]:          0 :         if ( !bHighlighted )
    1053         [ #  # ]:          0 :             implChangeHighlightEntry( -1 );
    1054                 :            :     }
    1055                 :            :     else
    1056                 :            :     {
    1057         [ #  # ]:          0 :         implChangeHighlightEntry( -1 );
    1058                 :            :     }
    1059                 :          0 : }
    1060                 :            : 
    1061                 :            : // --------------------------------------------------------------------
    1062                 :            : 
    1063                 :          0 : void ToolbarMenu::implChangeHighlightEntry( int nEntry )
    1064                 :            : {
    1065         [ #  # ]:          0 :     if( mpImpl->mnHighlightedEntry != -1 )
    1066                 :            :     {
    1067                 :          0 :         implHighlightEntry( mpImpl->mnHighlightedEntry, false );
    1068                 :            :     }
    1069                 :            : 
    1070                 :          0 :     mpImpl->mnHighlightedEntry = nEntry;
    1071                 :          0 :     Invalidate();
    1072                 :            : 
    1073         [ #  # ]:          0 :     if( mpImpl->mnHighlightedEntry != -1 )
    1074                 :            :     {
    1075                 :          0 :         implHighlightEntry( mpImpl->mnHighlightedEntry, true );
    1076                 :            :     }
    1077                 :            : 
    1078                 :          0 :     mpImpl->notifyHighlightedEntry();
    1079                 :          0 : }
    1080                 :            : 
    1081                 :            : // --------------------------------------------------------------------
    1082                 :            : 
    1083                 :          0 : static bool implCheckSubControlCursorMove( Control* pControl, bool bUp, int& nLastColumn )
    1084                 :            : {
    1085         [ #  # ]:          0 :     ValueSet* pValueSet = dynamic_cast< ValueSet* >( pControl );
    1086         [ #  # ]:          0 :     if( pValueSet )
    1087                 :            :     {
    1088                 :          0 :         sal_uInt16 nItemPos = pValueSet->GetItemPos( pValueSet->GetSelectItemId() );
    1089         [ #  # ]:          0 :         if( nItemPos != VALUESET_ITEM_NOTFOUND )
    1090                 :            :         {
    1091                 :          0 :             const sal_uInt16 nColCount = pValueSet->GetColCount();
    1092                 :          0 :             const sal_uInt16 nLine = nItemPos / nColCount;
    1093                 :            : 
    1094                 :          0 :             nLastColumn = nItemPos - (nLine * nColCount);
    1095                 :            : 
    1096         [ #  # ]:          0 :             if( bUp )
    1097                 :            :             {
    1098                 :          0 :                 return nLine > 0;
    1099                 :            :             }
    1100                 :            :             else
    1101                 :            :             {
    1102                 :          0 :                 const sal_uInt16 nLineCount = (pValueSet->GetItemCount() + nColCount - 1) / nColCount;
    1103                 :          0 :                 return (nLine+1) < nLineCount;
    1104                 :            :             }
    1105                 :            :         }
    1106                 :            :     }
    1107                 :            : 
    1108                 :          0 :     return false;
    1109                 :            : }
    1110                 :            : 
    1111                 :            : // --------------------------------------------------------------------
    1112                 :            : 
    1113                 :          0 : ToolbarMenuEntry* ToolbarMenu::implCursorUpDown( bool bUp, bool bHomeEnd )
    1114                 :            : {
    1115                 :          0 :     int n = 0, nLoop = 0;
    1116         [ #  # ]:          0 :     if( !bHomeEnd )
    1117                 :            :     {
    1118                 :          0 :         n = mpImpl->mnHighlightedEntry;
    1119         [ #  # ]:          0 :         if( n == -1 )
    1120                 :            :         {
    1121         [ #  # ]:          0 :             if( bUp )
    1122                 :          0 :                 n = 0;
    1123                 :            :             else
    1124                 :          0 :                 n = mpImpl->maEntryVector.size()-1;
    1125                 :            :         }
    1126                 :            :         else
    1127                 :            :         {
    1128                 :            :             // if we have a currently selected entry and
    1129                 :            :             // cursor keys are used than check if this entry
    1130                 :            :             // has a control that can use those cursor keys
    1131                 :          0 :             ToolbarMenuEntry* pData = mpImpl->maEntryVector[n];
    1132 [ #  # ][ #  # ]:          0 :             if( pData && pData->mpControl && !pData->mbHasText )
                 [ #  # ]
    1133                 :            :             {
    1134         [ #  # ]:          0 :                 if( implCheckSubControlCursorMove( pData->mpControl, bUp, mpImpl->mnLastColumn ) )
    1135                 :          0 :                     return pData;
    1136                 :            :             }
    1137                 :            :         }
    1138                 :          0 :         nLoop = n;
    1139                 :            :     }
    1140                 :            :     else
    1141                 :            :     {
    1142                 :            :         // absolute positioning
    1143         [ #  # ]:          0 :         if( bUp )
    1144                 :            :         {
    1145                 :          0 :             n = mpImpl->maEntryVector.size();
    1146                 :          0 :             nLoop = n-1;
    1147                 :            :         }
    1148                 :            :         else
    1149                 :            :         {
    1150                 :          0 :             n = -1;
    1151                 :          0 :             nLoop = mpImpl->maEntryVector.size()-1;
    1152                 :            :         }
    1153                 :            :     }
    1154                 :            : 
    1155         [ #  # ]:          0 :     do
    1156                 :            :     {
    1157         [ #  # ]:          0 :         if( bUp )
    1158                 :            :         {
    1159         [ #  # ]:          0 :             if ( n )
    1160                 :          0 :                 n--;
    1161                 :            :             else
    1162         [ #  # ]:          0 :                 if( mpImpl->mnHighlightedEntry == -1 )
    1163                 :          0 :                     n = mpImpl->maEntryVector.size()-1;
    1164                 :            :                 else
    1165                 :          0 :                     break;
    1166                 :            :         }
    1167                 :            :         else
    1168                 :            :         {
    1169         [ #  # ]:          0 :             if( n < ((int)mpImpl->maEntryVector.size()-1) )
    1170                 :          0 :                 n++;
    1171                 :            :             else
    1172         [ #  # ]:          0 :                 if( mpImpl->mnHighlightedEntry == -1 )
    1173                 :          0 :                     n = 0;
    1174                 :            :                 else
    1175                 :          0 :                     break;
    1176                 :            :         }
    1177                 :            : 
    1178                 :          0 :         ToolbarMenuEntry* pData = mpImpl->maEntryVector[n];
    1179 [ #  # ][ #  # ]:          0 :         if( pData && (pData->mnEntryId != TITLE_ID) )
    1180                 :            :         {
    1181                 :          0 :             implChangeHighlightEntry( n );
    1182                 :          0 :             return pData;
    1183                 :            :         }
    1184                 :            :     } while ( n != nLoop );
    1185                 :            : 
    1186                 :          0 :     return 0;
    1187                 :            : }
    1188                 :            : 
    1189                 :            : // --------------------------------------------------------------------
    1190                 :            : 
    1191                 :          0 : void ToolbarMenu_Impl::implHighlightControl( sal_uInt16 nCode, Control* pControl )
    1192                 :            : {
    1193         [ #  # ]:          0 :     ValueSet* pValueSet = dynamic_cast< ValueSet* >( pControl );
    1194         [ #  # ]:          0 :     if( pValueSet )
    1195                 :            :     {
    1196                 :          0 :         const sal_uInt16 nItemCount = pValueSet->GetItemCount();
    1197                 :          0 :         sal_uInt16 nItemPos = VALUESET_ITEM_NOTFOUND;
    1198   [ #  #  #  #  :          0 :         switch( nCode )
                      # ]
    1199                 :            :         {
    1200                 :            :         case KEY_UP:
    1201                 :            :         {
    1202                 :          0 :             const sal_uInt16 nColCount = pValueSet->GetColCount();
    1203                 :          0 :             const sal_uInt16 nLastLine = nItemCount / nColCount;
    1204         [ #  # ]:          0 :             nItemPos = std::min( ((nLastLine-1) * nColCount) + mnLastColumn, nItemCount-1 );
    1205                 :          0 :             break;
    1206                 :            :         }
    1207                 :            :         case KEY_DOWN:
    1208         [ #  # ]:          0 :             nItemPos = std::min( mnLastColumn, nItemCount-1 );
    1209                 :          0 :             break;
    1210                 :            :         case KEY_END:
    1211                 :          0 :             nItemPos = nItemCount -1;
    1212                 :          0 :             break;
    1213                 :            :         case KEY_HOME:
    1214                 :          0 :             nItemPos = 0;
    1215                 :          0 :             break;
    1216                 :            :         }
    1217                 :          0 :         pValueSet->SelectItem( pValueSet->GetItemId( nItemPos ) );
    1218                 :          0 :         notifyHighlightedEntry();
    1219                 :            :     }
    1220                 :          0 : }
    1221                 :            : 
    1222                 :            : // --------------------------------------------------------------------
    1223                 :            : 
    1224                 :          0 : void ToolbarMenu::KeyInput( const KeyEvent& rKEvent )
    1225                 :            : {
    1226                 :          0 :     Control* pForwardControl = 0;
    1227                 :          0 :     sal_uInt16 nCode = rKEvent.GetKeyCode().GetCode();
    1228   [ #  #  #  #  :          0 :     switch ( nCode )
                      # ]
    1229                 :            :     {
    1230                 :            :         case KEY_UP:
    1231                 :            :         case KEY_DOWN:
    1232                 :            :         {
    1233                 :          0 :             int nOldEntry = mpImpl->mnHighlightedEntry;
    1234                 :          0 :             ToolbarMenuEntry*p = implCursorUpDown( nCode == KEY_UP, false );
    1235 [ #  # ][ #  # ]:          0 :             if( p && p->mpControl )
    1236                 :            :             {
    1237         [ #  # ]:          0 :                 if( nOldEntry != mpImpl->mnHighlightedEntry )
    1238                 :            :                 {
    1239                 :          0 :                     mpImpl->implHighlightControl( nCode, p->mpControl );
    1240                 :            :                 }
    1241                 :            :                 else
    1242                 :            :                 {
    1243                 :            :                     // in case we are in a system floating window, GrabFocus does not work :-/
    1244                 :          0 :                     pForwardControl = p->mpControl;
    1245                 :            :                 }
    1246                 :            :             }
    1247                 :            :         }
    1248                 :          0 :         break;
    1249                 :            :         case KEY_END:
    1250                 :            :         case KEY_HOME:
    1251                 :            :         {
    1252                 :          0 :             ToolbarMenuEntry* p = implCursorUpDown( nCode == KEY_END, true );
    1253 [ #  # ][ #  # ]:          0 :             if( p && p->mpControl )
    1254                 :            :             {
    1255                 :          0 :                 mpImpl->implHighlightControl( nCode, p->mpControl );
    1256                 :            :             }
    1257                 :            :         }
    1258                 :          0 :         break;
    1259                 :            :         case KEY_F6:
    1260                 :            :         case KEY_ESCAPE:
    1261                 :            :         {
    1262                 :            :             // Ctrl-F6 acts like ESC here, the menu bar however will then put the focus in the document
    1263 [ #  # ][ #  # ]:          0 :             if( nCode == KEY_F6 && !rKEvent.GetKeyCode().IsMod1() )
                 [ #  # ]
    1264                 :          0 :                 break;
    1265                 :            : 
    1266                 :          0 :             implSelectEntry( -1 );
    1267                 :            :         }
    1268                 :          0 :         break;
    1269                 :            : 
    1270                 :            :         case KEY_RETURN:
    1271                 :            :         {
    1272                 :          0 :             ToolbarMenuEntry* pEntry = implGetEntry( mpImpl->mnHighlightedEntry );
    1273 [ #  # ][ #  # ]:          0 :             if ( pEntry && pEntry->mbEnabled && (pEntry->mnEntryId != TITLE_ID) )
                 [ #  # ]
    1274                 :            :             {
    1275         [ #  # ]:          0 :                 if( pEntry->mpControl )
    1276                 :            :                 {
    1277                 :          0 :                     pForwardControl = pEntry->mpControl;
    1278                 :            :                 }
    1279                 :            :                 else
    1280                 :            :                 {
    1281                 :          0 :                     implSelectEntry( mpImpl->mnHighlightedEntry );
    1282                 :            :                 }
    1283                 :            :             }
    1284                 :            :         }
    1285                 :          0 :         break;
    1286                 :            :         default:
    1287                 :            :         {
    1288                 :          0 :             ToolbarMenuEntry* pEntry = implGetEntry( mpImpl->mnHighlightedEntry );
    1289 [ #  # ][ #  # ]:          0 :             if ( pEntry && pEntry->mbEnabled && pEntry->mpControl && !pEntry->mbHasText )
         [ #  # ][ #  # ]
    1290                 :            :             {
    1291                 :          0 :                 pForwardControl = pEntry->mpControl;
    1292                 :            :             }
    1293                 :            :         }
    1294                 :            : 
    1295                 :            :     }
    1296         [ #  # ]:          0 :     if( pForwardControl )
    1297                 :          0 :         pForwardControl->KeyInput( rKEvent );
    1298                 :            : 
    1299                 :          0 : }
    1300                 :            : 
    1301                 :            : // --------------------------------------------------------------------
    1302                 :          0 : static void ImplPaintCheckBackground( Window* i_pWindow, const Rectangle& i_rRect, bool i_bHighlight )
    1303                 :            : {
    1304                 :          0 :     sal_Bool bNativeOk = sal_False;
    1305         [ #  # ]:          0 :     if( i_pWindow->IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
    1306                 :            :     {
    1307                 :          0 :         ImplControlValue    aControlValue;
    1308                 :          0 :         ControlState        nState = CTRL_STATE_PRESSED | CTRL_STATE_ENABLED;
    1309                 :            : 
    1310                 :          0 :         aControlValue.setTristateVal( BUTTONVALUE_ON );
    1311                 :            : 
    1312                 :            :         bNativeOk = i_pWindow->DrawNativeControl( CTRL_TOOLBAR, PART_BUTTON,
    1313                 :            :                                                   i_rRect, nState, aControlValue,
    1314 [ #  # ][ #  # ]:          0 :                                                   rtl::OUString() );
    1315                 :            :     }
    1316                 :            : 
    1317         [ #  # ]:          0 :     if( ! bNativeOk )
    1318                 :            :     {
    1319                 :          0 :         const StyleSettings& rSettings = i_pWindow->GetSettings().GetStyleSettings();
    1320         [ #  # ]:          0 :         Color aColor( i_bHighlight ? rSettings.GetMenuHighlightTextColor() : rSettings.GetHighlightColor() );
    1321         [ #  # ]:          0 :         i_pWindow->DrawSelectionBackground( i_rRect, 0, i_bHighlight, sal_True, sal_False, 2, NULL, &aColor );
    1322                 :            :     }
    1323                 :          0 : }
    1324                 :            : 
    1325                 :          0 : void ToolbarMenu::implPaint( ToolbarMenuEntry* pThisOnly, bool bHighlighted )
    1326                 :            : {
    1327                 :          0 :     sal_uInt16 nBorder = 0; long nStartY = 0; // from Menu implementations, needed when we support native menu background & scrollable menu
    1328                 :            : 
    1329         [ #  # ]:          0 :     long nFontHeight = GetTextHeight();
    1330                 :            : //    long nExtra = nFontHeight/4;
    1331                 :            : 
    1332                 :          0 :     long nCheckHeight = 0, nRadioHeight = 0, nMaxCheckWidth = 0;
    1333         [ #  # ]:          0 :     ImplGetNativeCheckAndRadioSize( this, nCheckHeight, nRadioHeight, nMaxCheckWidth );
    1334                 :            : 
    1335                 :          0 :     DecorationView aDecoView( this );
    1336                 :          0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
    1337         [ #  # ]:          0 :     const bool bUseImages = rSettings.GetUseImagesInMenus();
    1338                 :            : 
    1339                 :          0 :     int nOuterSpace = 0; // ImplGetSVData()->maNWFData.mnMenuFormatExtraBorder;
    1340                 :          0 :     Point aTopLeft( nOuterSpace, nOuterSpace ), aTmpPos;
    1341                 :            : 
    1342         [ #  # ]:          0 :     Size aOutSz( GetOutputSizePixel() );
    1343                 :          0 :     const int nEntryCount = mpImpl->maEntryVector.size();
    1344                 :            :     int nEntry;
    1345         [ #  # ]:          0 :     for( nEntry = 0; nEntry < nEntryCount; nEntry++ )
    1346                 :            :     {
    1347                 :          0 :         ToolbarMenuEntry* pEntry = mpImpl->maEntryVector[nEntry];
    1348                 :            : 
    1349                 :          0 :         Point aPos( aTopLeft );
    1350                 :          0 :         aPos.Y() += nBorder;
    1351                 :          0 :         aPos.Y() += nStartY;
    1352                 :            : 
    1353                 :            : 
    1354 [ #  # ][ #  # ]:          0 :         if( (pEntry == 0) && !pThisOnly )
    1355                 :            :         {
    1356                 :            :             // Separator
    1357                 :          0 :             aTmpPos.Y() = aPos.Y() + ((SEPARATOR_HEIGHT-2)/2);
    1358                 :          0 :             aTmpPos.X() = aPos.X() + 2 + nOuterSpace;
    1359         [ #  # ]:          0 :             SetLineColor( rSettings.GetShadowColor() );
    1360         [ #  # ]:          0 :             DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpace, aTmpPos.Y() ) );
    1361                 :          0 :             aTmpPos.Y()++;
    1362         [ #  # ]:          0 :             SetLineColor( rSettings.GetLightColor() );
    1363         [ #  # ]:          0 :             DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpace, aTmpPos.Y() ) );
    1364         [ #  # ]:          0 :             SetLineColor();
    1365                 :            :         }
    1366 [ #  # ][ #  # ]:          0 :         else if( !pThisOnly || ( pEntry == pThisOnly ) )
    1367                 :            :         {
    1368                 :          0 :             const bool bTitle = pEntry->mnEntryId == TITLE_ID;
    1369                 :            : 
    1370 [ #  # ][ #  # ]:          0 :             if ( pThisOnly && bHighlighted )
    1371         [ #  # ]:          0 :                 SetTextColor( rSettings.GetMenuHighlightTextColor() );
    1372                 :            : 
    1373         [ #  # ]:          0 :             if( aPos.Y() >= 0 )
    1374                 :            :             {
    1375                 :          0 :                 long nTextOffsetY = ((pEntry->maSize.Height()-nFontHeight)/2);
    1376                 :            : 
    1377                 :          0 :                 sal_uInt16  nTextStyle   = 0;
    1378                 :          0 :                 sal_uInt16  nSymbolStyle = 0;
    1379                 :          0 :                 sal_uInt16  nImageStyle  = 0;
    1380                 :            : 
    1381         [ #  # ]:          0 :                 if( !pEntry->mbEnabled )
    1382                 :            :                 {
    1383                 :          0 :                     nTextStyle   |= TEXT_DRAW_DISABLE;
    1384                 :          0 :                     nSymbolStyle |= SYMBOL_DRAW_DISABLE;
    1385                 :          0 :                     nImageStyle  |= IMAGE_DRAW_DISABLE;
    1386                 :            :                 }
    1387                 :            : 
    1388         [ #  # ]:          0 :                 Rectangle aOuterCheckRect( Point( aPos.X()+mpImpl->mnCheckPos, aPos.Y() ), Size( pEntry->maSize.Height(), pEntry->maSize.Height() ) );
    1389                 :          0 :                 aOuterCheckRect.Left()      += 1;
    1390                 :          0 :                 aOuterCheckRect.Right()     -= 1;
    1391                 :          0 :                 aOuterCheckRect.Top()       += 1;
    1392                 :          0 :                 aOuterCheckRect.Bottom()    -= 1;
    1393                 :            : 
    1394         [ #  # ]:          0 :                 if( bTitle )
    1395                 :            :                 {
    1396                 :            :                     // fill the background
    1397         [ #  # ]:          0 :                     Rectangle aRect( aTopLeft, Size( aOutSz.Width(), pEntry->maSize.Height() ) );
    1398         [ #  # ]:          0 :                     SetFillColor(rSettings.GetDialogColor());
    1399         [ #  # ]:          0 :                     SetLineColor();
    1400         [ #  # ]:          0 :                     DrawRect(aRect);
    1401         [ #  # ]:          0 :                     SetLineColor( rSettings.GetLightColor() );
    1402 [ #  # ][ #  # ]:          0 :                     DrawLine( aRect.TopLeft(), aRect.TopRight() );
    1403         [ #  # ]:          0 :                     SetLineColor( rSettings.GetShadowColor() );
    1404 [ #  # ][ #  # ]:          0 :                     DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
                 [ #  # ]
    1405                 :            :                 }
    1406                 :            : 
    1407                 :            :                 // CheckMark
    1408         [ #  # ]:          0 :                 if ( pEntry->HasCheck() )
    1409                 :            :                 {
    1410                 :            :                     // draw selection transparent marker if checked
    1411                 :            :                     // onto that either a checkmark or the item image
    1412                 :            :                     // will be painted
    1413                 :            :                     // however do not do this if native checks will be painted since
    1414                 :            :                     // the selection color too often does not fit the theme's check and/or radio
    1415                 :            : 
    1416         [ #  # ]:          0 :                     if( !pEntry->mbHasImage )
    1417                 :            :                     {
    1418         [ #  # ]:          0 :                         if( this->IsNativeControlSupported( CTRL_MENU_POPUP,
    1419                 :            :                                                              (pEntry->mnBits & MIB_RADIOCHECK)
    1420                 :            :                                                              ? PART_MENU_ITEM_CHECK_MARK
    1421 [ #  # ][ #  # ]:          0 :                                                              : PART_MENU_ITEM_RADIO_MARK ) )
    1422                 :            :                         {
    1423                 :            :                             ControlPart nPart = ((pEntry->mnBits & MIB_RADIOCHECK)
    1424                 :            :                                                  ? PART_MENU_ITEM_RADIO_MARK
    1425         [ #  # ]:          0 :                                                  : PART_MENU_ITEM_CHECK_MARK);
    1426                 :            : 
    1427                 :          0 :                             ControlState nState = 0;
    1428                 :            : 
    1429         [ #  # ]:          0 :                             if ( pEntry->mbChecked )
    1430                 :          0 :                                 nState |= CTRL_STATE_PRESSED;
    1431                 :            : 
    1432         [ #  # ]:          0 :                             if ( pEntry->mbEnabled )
    1433                 :          0 :                                 nState |= CTRL_STATE_ENABLED;
    1434                 :            : 
    1435         [ #  # ]:          0 :                             if ( bHighlighted )
    1436                 :          0 :                                 nState |= CTRL_STATE_SELECTED;
    1437                 :            : 
    1438         [ #  # ]:          0 :                             long nCtrlHeight = (pEntry->mnBits & MIB_RADIOCHECK) ? nCheckHeight : nRadioHeight;
    1439         [ #  # ]:          0 :                             aTmpPos.X() = aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - nCtrlHeight)/2;
    1440         [ #  # ]:          0 :                             aTmpPos.Y() = aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - nCtrlHeight)/2;
    1441                 :            : 
    1442         [ #  # ]:          0 :                             Rectangle aCheckRect( aTmpPos, Size( nCtrlHeight, nCtrlHeight ) );
    1443 [ #  # ][ #  # ]:          0 :                             DrawNativeControl( CTRL_MENU_POPUP, nPart, aCheckRect, nState, ImplControlValue(), OUString() );
    1444                 :          0 :                             aPos.setX( aPos.getX() + nCtrlHeight + gfxExtra );
    1445                 :            :                         }
    1446         [ #  # ]:          0 :                         else if ( pEntry->mbChecked ) // by default do nothing for unchecked items
    1447                 :            :                         {
    1448 [ #  # ][ #  # ]:          0 :                             ImplPaintCheckBackground( this, aOuterCheckRect, pThisOnly && bHighlighted );
                 [ #  # ]
    1449                 :            : 
    1450                 :            :                             SymbolType eSymbol;
    1451                 :          0 :                             Size aSymbolSize;
    1452         [ #  # ]:          0 :                             if ( pEntry->mnBits & MIB_RADIOCHECK )
    1453                 :            :                             {
    1454                 :          0 :                                 eSymbol = SYMBOL_RADIOCHECKMARK;
    1455                 :          0 :                                 aSymbolSize = Size( nFontHeight/2, nFontHeight/2 );
    1456                 :            :                             }
    1457                 :            :                             else
    1458                 :            :                             {
    1459                 :          0 :                                 eSymbol = SYMBOL_CHECKMARK;
    1460                 :          0 :                                 aSymbolSize = Size( (nFontHeight*25)/40, nFontHeight/2 );
    1461                 :            :                             }
    1462         [ #  # ]:          0 :                             aTmpPos.X() = aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - aSymbolSize.Width())/2;
    1463         [ #  # ]:          0 :                             aTmpPos.Y() = aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - aSymbolSize.Height())/2;
    1464         [ #  # ]:          0 :                             Rectangle aRect( aTmpPos, aSymbolSize );
    1465         [ #  # ]:          0 :                             aDecoView.DrawSymbol( aRect, eSymbol, GetTextColor(), nSymbolStyle );
    1466                 :          0 :                             aPos.setX( aPos.getX() + aSymbolSize.getWidth( ) + gfxExtra );
    1467                 :            :                         }
    1468                 :            :                     }
    1469                 :            :                 }
    1470                 :            : 
    1471                 :            :                 // Image:
    1472 [ #  # ][ #  # ]:          0 :                 if( pEntry->mbHasImage && bUseImages )
    1473                 :            :                 {
    1474         [ #  # ]:          0 :                     if( pEntry->mbChecked )
    1475 [ #  # ][ #  # ]:          0 :                         ImplPaintCheckBackground( this, aOuterCheckRect, pThisOnly && bHighlighted );
                 [ #  # ]
    1476                 :          0 :                     aTmpPos = aOuterCheckRect.TopLeft();
    1477 [ #  # ][ #  # ]:          0 :                     aTmpPos.X() += (aOuterCheckRect.GetWidth()-pEntry->maImage.GetSizePixel().Width())/2;
    1478 [ #  # ][ #  # ]:          0 :                     aTmpPos.Y() += (aOuterCheckRect.GetHeight()-pEntry->maImage.GetSizePixel().Height())/2;
    1479         [ #  # ]:          0 :                     DrawImage( aTmpPos, pEntry->maImage, nImageStyle );
    1480                 :            :                 }
    1481                 :            : 
    1482                 :            :                 // Text:
    1483         [ #  # ]:          0 :                 if( pEntry->mbHasText )
    1484                 :            :                 {
    1485         [ #  # ]:          0 :                     aTmpPos.X() = aPos.X() + (bTitle ? 4 : mpImpl->mnTextPos);
    1486                 :          0 :                     aTmpPos.Y() = aPos.Y();
    1487                 :          0 :                     aTmpPos.Y() += nTextOffsetY;
    1488                 :          0 :                     sal_uInt16 nStyle = nTextStyle|TEXT_DRAW_MNEMONIC;
    1489                 :            : 
    1490         [ #  # ]:          0 :                     DrawCtrlText( aTmpPos, pEntry->maText, 0, pEntry->maText.Len(), nStyle, NULL, NULL ); // pVector, pDisplayText );
    1491                 :            :                 }
    1492                 :            : 
    1493 [ #  # ][ #  # ]:          0 :                 if ( pThisOnly && bHighlighted )
    1494                 :            :                 {
    1495                 :            :                     // This restores the normal menu or menu bar text
    1496                 :            :                     // color for when it is no longer highlighted.
    1497         [ #  # ]:          0 :                     SetTextColor( rSettings.GetMenuTextColor() );
    1498                 :            :                  }
    1499                 :            :             }
    1500                 :            :         }
    1501                 :            : 
    1502         [ #  # ]:          0 :         aTopLeft.Y() += pEntry ? pEntry->maSize.Height() : SEPARATOR_HEIGHT;
    1503                 :            :     }
    1504                 :          0 : }
    1505                 :            : 
    1506                 :            : // --------------------------------------------------------------------
    1507                 :            : 
    1508                 :          0 : void ToolbarMenu::Paint( const Rectangle& )
    1509                 :            : {
    1510                 :          0 :     SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
    1511                 :            : 
    1512                 :          0 :     implPaint();
    1513                 :            : 
    1514         [ #  # ]:          0 :     if( mpImpl->mnHighlightedEntry != -1 )
    1515                 :          0 :         implHighlightEntry( mpImpl->mnHighlightedEntry, true );
    1516                 :          0 : }
    1517                 :            : 
    1518                 :            : // --------------------------------------------------------------------
    1519                 :            : 
    1520                 :          0 : void ToolbarMenu::RequestHelp( const HelpEvent& rHEvt )
    1521                 :            : {
    1522                 :          0 :     DockingWindow::RequestHelp( rHEvt );
    1523                 :          0 : }
    1524                 :            : 
    1525                 :            : // --------------------------------------------------------------------
    1526                 :            : 
    1527                 :          0 : void ToolbarMenu::StateChanged( StateChangedType nType )
    1528                 :            : {
    1529                 :          0 :     DockingWindow::StateChanged( nType );
    1530                 :            : 
    1531 [ #  # ][ #  # ]:          0 :     if ( ( nType == STATE_CHANGE_CONTROLFOREGROUND ) || ( nType == STATE_CHANGE_CONTROLBACKGROUND ) )
    1532                 :            :     {
    1533                 :          0 :         initWindow();
    1534                 :          0 :         Invalidate();
    1535                 :            :     }
    1536                 :          0 : }
    1537                 :            : 
    1538                 :            : // --------------------------------------------------------------------
    1539                 :            : 
    1540                 :          0 : void ToolbarMenu::DataChanged( const DataChangedEvent& rDCEvt )
    1541                 :            : {
    1542                 :          0 :     DockingWindow::DataChanged( rDCEvt );
    1543                 :            : 
    1544 [ #  # ][ #  #  :          0 :     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
          #  #  #  #  #  
                      # ]
    1545                 :          0 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
    1546                 :          0 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    1547                 :          0 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
    1548                 :            :     {
    1549                 :          0 :         initWindow();
    1550                 :          0 :         Invalidate();
    1551                 :            :     }
    1552                 :          0 : }
    1553                 :            : 
    1554                 :            : // --------------------------------------------------------------------
    1555                 :            : 
    1556                 :          0 : void ToolbarMenu::Command( const CommandEvent& rCEvt )
    1557                 :            : {
    1558         [ #  # ]:          0 :     if ( rCEvt.GetCommand() == COMMAND_WHEEL )
    1559                 :            :     {
    1560                 :          0 :         const CommandWheelData* pData = rCEvt.GetWheelData();
    1561 [ #  # ][ #  # ]:          0 :         if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) )
                 [ #  # ]
    1562                 :            :         {
    1563                 :          0 :             implCursorUpDown( pData->GetDelta() > 0L, false );
    1564                 :            :         }
    1565                 :            :     }
    1566                 :          0 : }
    1567                 :            : 
    1568                 :            : // --------------------------------------------------------------------
    1569                 :            : 
    1570                 :          0 : Reference< ::com::sun::star::accessibility::XAccessible > ToolbarMenu::CreateAccessible()
    1571                 :            : {
    1572         [ #  # ]:          0 :     mpImpl->setAccessible( new ToolbarMenuAcc( *mpImpl ) );
    1573         [ #  # ]:          0 :     return Reference< XAccessible >( mpImpl->mxAccessible.get() );
    1574                 :            : }
    1575                 :            : 
    1576                 :            : // --------------------------------------------------------------------
    1577                 :            : 
    1578                 :            : // todo: move to new base class that will replace SfxPopupWindo
    1579                 :          0 : void ToolbarMenu::AddStatusListener( const rtl::OUString& rCommandURL )
    1580                 :            : {
    1581                 :          0 :     initStatusListener();
    1582                 :          0 :     mpImpl->mxStatusListener->addStatusListener( rCommandURL );
    1583                 :          0 : }
    1584                 :            : 
    1585                 :            : // --------------------------------------------------------------------
    1586                 :            : 
    1587                 :            : // XStatusListener (subclasses must override this one to get the status updates
    1588                 :          0 : void SAL_CALL ToolbarMenu::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& /*Event*/ ) throw ( ::com::sun::star::uno::RuntimeException )
    1589                 :            : {
    1590                 :          0 : }
    1591                 :            : 
    1592                 :            : // --------------------------------------------------------------------
    1593                 :            : 
    1594         [ #  # ]:          0 : class ToolbarMenuStatusListener : public svt::FrameStatusListener
    1595                 :            : {
    1596                 :            : public:
    1597                 :            :     ToolbarMenuStatusListener( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager,
    1598                 :            :                                const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
    1599                 :            :                                ToolbarMenu& rToolbarMenu );
    1600                 :            : 
    1601                 :            :     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
    1602                 :            :     virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
    1603                 :            : 
    1604                 :            :     ToolbarMenu* mpMenu;
    1605                 :            : };
    1606                 :            : 
    1607                 :            : // --------------------------------------------------------------------
    1608                 :            : 
    1609                 :          0 : ToolbarMenuStatusListener::ToolbarMenuStatusListener(
    1610                 :            :     const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager,
    1611                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
    1612                 :            :     ToolbarMenu& rToolbarMenu )
    1613                 :            : : svt::FrameStatusListener( xServiceManager, xFrame )
    1614                 :          0 : , mpMenu( &rToolbarMenu )
    1615                 :            : {
    1616                 :          0 : }
    1617                 :            : 
    1618                 :            : // --------------------------------------------------------------------
    1619                 :            : 
    1620                 :          0 : void SAL_CALL ToolbarMenuStatusListener::dispose() throw (::com::sun::star::uno::RuntimeException)
    1621                 :            : {
    1622                 :          0 :     mpMenu = 0;
    1623                 :          0 :     svt::FrameStatusListener::dispose();
    1624                 :          0 : }
    1625                 :            : 
    1626                 :            : // --------------------------------------------------------------------
    1627                 :            : 
    1628                 :          0 : void SAL_CALL ToolbarMenuStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
    1629                 :            : {
    1630         [ #  # ]:          0 :     if( mpMenu )
    1631                 :          0 :         mpMenu->statusChanged( Event );
    1632                 :          0 : }
    1633                 :            : 
    1634                 :            : // --------------------------------------------------------------------
    1635                 :            : 
    1636                 :          0 : void ToolbarMenu::initStatusListener()
    1637                 :            : {
    1638         [ #  # ]:          0 :     if( !mpImpl->mxStatusListener.is() )
    1639         [ #  # ]:          0 :         mpImpl->mxStatusListener.set( new ToolbarMenuStatusListener( mpImpl->mxServiceManager, mpImpl->mxFrame, *this ) );
    1640                 :          0 : }
    1641                 :            : 
    1642                 :            : // --------------------------------------------------------------------
    1643                 :            : 
    1644                 :          0 : bool ToolbarMenu::IsInPopupMode()
    1645                 :            : {
    1646                 :          0 :     return GetDockingManager()->IsInPopupMode(this);
    1647                 :            : }
    1648                 :            : 
    1649                 :            : // --------------------------------------------------------------------
    1650                 :            : 
    1651                 :          0 : void ToolbarMenu::EndPopupMode()
    1652                 :            : {
    1653                 :          0 :     GetDockingManager()->EndPopupMode(this);
    1654                 :          0 : }
    1655                 :            : 
    1656                 :            : // --------------------------------------------------------------------
    1657                 :            : 
    1658                 :          0 : const Size& ToolbarMenu::getMenuSize() const
    1659                 :            : {
    1660                 :          0 :     return mpImpl->maSize;
    1661                 :            : }
    1662                 :            : 
    1663                 :            : // --------------------------------------------------------------------
    1664                 :            : 
    1665                 :          0 : void ToolbarMenu::SetSelectHdl( const Link& rLink )
    1666                 :            : {
    1667                 :          0 :     mpImpl->maSelectHdl = rLink;
    1668                 :          0 : }
    1669                 :            : 
    1670                 :            : // --------------------------------------------------------------------
    1671                 :            : 
    1672                 :            : }
    1673                 :            : 
    1674                 :            : 
    1675                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10