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