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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir #include <tools/list.hxx> 31*cdf0e10cSrcweir #include <tools/table.hxx> 32*cdf0e10cSrcweir #include <tools/debug.hxx> 33*cdf0e10cSrcweir #include <tools/rc.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <vcl/svapp.hxx> 36*cdf0e10cSrcweir #include <accel.h> 37*cdf0e10cSrcweir #include <vcl/accel.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // ======================================================================= 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir DECLARE_TABLE( ImplAccelTable, ImplAccelEntry* ) 44*cdf0e10cSrcweir DECLARE_LIST( ImplAccelList, ImplAccelEntry* ) 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #define ACCELENTRY_NOTFOUND ((sal_uInt16)0xFFFF) 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ======================================================================= 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir class ImplAccelData 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir public: 53*cdf0e10cSrcweir ImplAccelTable maKeyTable; // Fuer KeyCodes, die mit einem Code erzeugt wurden 54*cdf0e10cSrcweir ImplAccelList maIdList; // Id-List 55*cdf0e10cSrcweir }; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // ======================================================================= 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir DBG_NAME( Accelerator ) 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // ======================================================================= 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir sal_uInt16 ImplAccelEntryGetIndex( ImplAccelList* pList, sal_uInt16 nId, 64*cdf0e10cSrcweir sal_uInt16* pIndex = NULL ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir sal_uLong nLow; 67*cdf0e10cSrcweir sal_uLong nHigh; 68*cdf0e10cSrcweir sal_uLong nMid; 69*cdf0e10cSrcweir sal_uLong nCount = pList->Count(); 70*cdf0e10cSrcweir sal_uInt16 nCompareId; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // Abpruefen, ob der erste Key groesser als der Vergleichskey ist 73*cdf0e10cSrcweir if ( !nCount || (nId < pList->GetObject( 0 )->mnId) ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir if ( pIndex ) 76*cdf0e10cSrcweir *pIndex = 0; 77*cdf0e10cSrcweir return ACCELENTRY_NOTFOUND; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // Binaeres Suchen 81*cdf0e10cSrcweir nLow = 0; 82*cdf0e10cSrcweir nHigh = nCount-1; 83*cdf0e10cSrcweir do 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir nMid = (nLow + nHigh) / 2; 86*cdf0e10cSrcweir nCompareId = pList->GetObject( nMid )->mnId; 87*cdf0e10cSrcweir if ( nId < nCompareId ) 88*cdf0e10cSrcweir nHigh = nMid-1; 89*cdf0e10cSrcweir else 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if ( nId > nCompareId ) 92*cdf0e10cSrcweir nLow = nMid + 1; 93*cdf0e10cSrcweir else 94*cdf0e10cSrcweir return (sal_uInt16)nMid; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir while ( nLow <= nHigh ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if ( pIndex ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if ( nId > nCompareId ) 102*cdf0e10cSrcweir *pIndex = (sal_uInt16)(nMid+1); 103*cdf0e10cSrcweir else 104*cdf0e10cSrcweir *pIndex = (sal_uInt16)nMid; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir return ACCELENTRY_NOTFOUND; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // ----------------------------------------------------------------------- 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir static void ImplAccelEntryInsert( ImplAccelList* pList, ImplAccelEntry* pEntry ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir sal_uInt16 nInsIndex; 115*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetIndex( pList, pEntry->mnId, &nInsIndex ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir do 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir nIndex++; 122*cdf0e10cSrcweir ImplAccelEntry* pTempEntry = pList->GetObject( nIndex ); 123*cdf0e10cSrcweir if ( !pTempEntry || (pTempEntry->mnId != pEntry->mnId) ) 124*cdf0e10cSrcweir break; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir while ( nIndex < pList->Count() ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir pList->Insert( pEntry, (sal_uLong)nIndex ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else 131*cdf0e10cSrcweir pList->Insert( pEntry, (sal_uLong)nInsIndex ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // ----------------------------------------------------------------------- 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir static sal_uInt16 ImplAccelEntryGetFirstPos( ImplAccelList* pList, sal_uInt16 nId ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetIndex( pList, nId ); 139*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir while ( nIndex ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir nIndex--; 144*cdf0e10cSrcweir if ( pList->GetObject( nIndex )->mnId != nId ) 145*cdf0e10cSrcweir break; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir if ( pList->GetObject( nIndex )->mnId != nId ) 149*cdf0e10cSrcweir nIndex++; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir return nIndex; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // ======================================================================= 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void Accelerator::ImplInit() 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir mnCurId = 0; 160*cdf0e10cSrcweir mnCurRepeat = 0; 161*cdf0e10cSrcweir mbIsCancel = sal_False; 162*cdf0e10cSrcweir mpDel = NULL; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // ----------------------------------------------------------------------- 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir ImplAccelEntry* Accelerator::ImplGetAccelData( const KeyCode& rKeyCode ) const 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir return mpData->maKeyTable.Get( rKeyCode.GetFullKeyCode() ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // ----------------------------------------------------------------------- 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void Accelerator::ImplCopyData( ImplAccelData& rAccelData ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // Tabellen kopieren 177*cdf0e10cSrcweir ImplAccelEntry* pEntry = rAccelData.maIdList.First(); 178*cdf0e10cSrcweir while ( pEntry ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir pEntry = new ImplAccelEntry( *pEntry ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir // Folge-Accelerator, dann auch kopieren 183*cdf0e10cSrcweir if ( pEntry->mpAccel ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir pEntry->mpAccel = new Accelerator( *(pEntry->mpAccel) ); 186*cdf0e10cSrcweir pEntry->mpAutoAccel = pEntry->mpAccel; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir else 189*cdf0e10cSrcweir pEntry->mpAutoAccel = NULL; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir mpData->maKeyTable.Insert( (sal_uLong)pEntry->maKeyCode.GetFullKeyCode(), pEntry ); 192*cdf0e10cSrcweir mpData->maIdList.Insert( pEntry, LIST_APPEND ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir pEntry = rAccelData.maIdList.Next(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // ----------------------------------------------------------------------- 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir void Accelerator::ImplDeleteData() 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // Accelerator-Eintraege ueber die Id-Tabelle loeschen 203*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.First(); 204*cdf0e10cSrcweir while ( pEntry ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir // AutoResAccel zerstoeren 207*cdf0e10cSrcweir if ( pEntry->mpAutoAccel ) 208*cdf0e10cSrcweir delete pEntry->mpAutoAccel; 209*cdf0e10cSrcweir delete pEntry; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir pEntry = mpData->maIdList.Next(); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // ----------------------------------------------------------------------- 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir void Accelerator::ImplInsertAccel( sal_uInt16 nItemId, const KeyCode& rKeyCode, 218*cdf0e10cSrcweir sal_Bool bEnable, Accelerator* pAutoAccel ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 221*cdf0e10cSrcweir DBG_ASSERT( nItemId, "Accelerator::InsertItem(): ItemId == 0" ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir if ( rKeyCode.IsFunction() ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir sal_uInt16 nCode1; 226*cdf0e10cSrcweir sal_uInt16 nCode2; 227*cdf0e10cSrcweir sal_uInt16 nCode3; 228*cdf0e10cSrcweir sal_uInt16 nCode4; 229*cdf0e10cSrcweir ImplGetKeyCode( rKeyCode.GetFunction(), nCode1, nCode2, nCode3, nCode4 ); 230*cdf0e10cSrcweir if ( nCode1 ) 231*cdf0e10cSrcweir ImplInsertAccel( nItemId, KeyCode( nCode1, nCode1 ), bEnable, pAutoAccel ); 232*cdf0e10cSrcweir if ( nCode2 ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir if ( pAutoAccel ) 235*cdf0e10cSrcweir pAutoAccel = new Accelerator( *pAutoAccel ); 236*cdf0e10cSrcweir ImplInsertAccel( nItemId, KeyCode( nCode2, nCode2 ), bEnable, pAutoAccel ); 237*cdf0e10cSrcweir if ( nCode3 ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir if ( pAutoAccel ) 240*cdf0e10cSrcweir pAutoAccel = new Accelerator( *pAutoAccel ); 241*cdf0e10cSrcweir ImplInsertAccel( nItemId, KeyCode( nCode3, nCode3 ), bEnable, pAutoAccel ); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir return; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // Neuen Eintrag holen und fuellen 248*cdf0e10cSrcweir ImplAccelEntry* pEntry = new ImplAccelEntry; 249*cdf0e10cSrcweir pEntry->mnId = nItemId; 250*cdf0e10cSrcweir pEntry->maKeyCode = rKeyCode; 251*cdf0e10cSrcweir pEntry->mpAccel = pAutoAccel; 252*cdf0e10cSrcweir pEntry->mpAutoAccel = pAutoAccel; 253*cdf0e10cSrcweir pEntry->mbEnabled = bEnable; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir // Ab in die Tabellen 256*cdf0e10cSrcweir sal_uLong nCode = rKeyCode.GetFullKeyCode(); 257*cdf0e10cSrcweir if ( !nCode ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir DBG_ERROR( "Accelerator::InsertItem(): KeyCode with KeyCode 0 not allowed" ); 260*cdf0e10cSrcweir delete pEntry; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir else if ( !mpData->maKeyTable.Insert( nCode, pEntry ) ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir DBG_ERROR1( "Accelerator::InsertItem(): KeyCode (Key: %lx) already exists", nCode ); 265*cdf0e10cSrcweir delete pEntry; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir else 268*cdf0e10cSrcweir ImplAccelEntryInsert( &(mpData->maIdList), pEntry ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // ----------------------------------------------------------------------- 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir Accelerator::Accelerator() 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir DBG_CTOR( Accelerator, NULL ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir ImplInit(); 278*cdf0e10cSrcweir mpData = new ImplAccelData; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // ----------------------------------------------------------------------- 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir Accelerator::Accelerator( const Accelerator& rAccel ) : 284*cdf0e10cSrcweir Resource(), 285*cdf0e10cSrcweir maHelpStr( rAccel.maHelpStr ), 286*cdf0e10cSrcweir maCurKeyCode( rAccel.maCurKeyCode ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir DBG_CTOR( Accelerator, NULL ); 289*cdf0e10cSrcweir DBG_CHKOBJ( &rAccel, Accelerator, NULL ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir ImplInit(); 292*cdf0e10cSrcweir mpData = new ImplAccelData; 293*cdf0e10cSrcweir ImplCopyData( *((ImplAccelData*)(rAccel.mpData)) ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir // ----------------------------------------------------------------------- 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir Accelerator::Accelerator( const ResId& rResId ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir DBG_CTOR( Accelerator, NULL ); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir ImplInit(); 303*cdf0e10cSrcweir mpData = new ImplAccelData; 304*cdf0e10cSrcweir rResId.SetRT( RSC_ACCEL ); 305*cdf0e10cSrcweir ImplLoadRes( rResId ); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir // ----------------------------------------------------------------------- 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir void Accelerator::ImplLoadRes( const ResId& rResId ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir GetRes( rResId ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir maHelpStr = ReadStringRes(); 315*cdf0e10cSrcweir sal_uLong nObjFollows = ReadLongRes(); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir for( sal_uLong i = 0; i < nObjFollows; i++ ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir InsertItem( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 320*cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir // ----------------------------------------------------------------------- 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir Accelerator::~Accelerator() 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir DBG_DTOR( Accelerator, NULL ); 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir // AccelManager benachrichtigen, das Accelrator geloescht wurde 331*cdf0e10cSrcweir if ( mpDel ) 332*cdf0e10cSrcweir *mpDel = sal_True; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir ImplDeleteData(); 335*cdf0e10cSrcweir delete mpData; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir // ----------------------------------------------------------------------- 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir void Accelerator::Activate() 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir maActivateHdl.Call( this ); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir // ----------------------------------------------------------------------- 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir void Accelerator::Deactivate() 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir maDeactivateHdl.Call( this ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // ----------------------------------------------------------------------- 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir void Accelerator::Select() 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir maSelectHdl.Call( this ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir // ----------------------------------------------------------------------- 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir void Accelerator::InsertItem( sal_uInt16 nItemId, const KeyCode& rKeyCode ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir ImplInsertAccel( nItemId, rKeyCode, sal_True, NULL ); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // ----------------------------------------------------------------------- 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir void Accelerator::InsertItem( const ResId& rResId ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir sal_uLong nObjMask; 373*cdf0e10cSrcweir sal_uInt16 nAccelKeyId; 374*cdf0e10cSrcweir sal_uInt16 bDisable; 375*cdf0e10cSrcweir KeyCode aKeyCode; 376*cdf0e10cSrcweir Accelerator* pAutoAccel = NULL; 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir GetRes( rResId.SetRT( RSC_ACCELITEM ) ); 379*cdf0e10cSrcweir nObjMask = ReadLongRes(); 380*cdf0e10cSrcweir nAccelKeyId = sal::static_int_cast<sal_uInt16>(ReadLongRes()); 381*cdf0e10cSrcweir bDisable = ReadShortRes(); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir if ( nObjMask & ACCELITEM_KEY ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir // es wird ein neuer Kontext aufgespannt 386*cdf0e10cSrcweir RSHEADER_TYPE * pKeyCodeRes = (RSHEADER_TYPE *)GetClassRes(); 387*cdf0e10cSrcweir ResId aResId( pKeyCodeRes, *rResId.GetResMgr()); 388*cdf0e10cSrcweir aKeyCode = KeyCode( aResId ); 389*cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir if ( nObjMask & ACCELITEM_ACCEL ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir pAutoAccel = new Accelerator( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 395*cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir ImplInsertAccel( nAccelKeyId, aKeyCode, !bDisable, pAutoAccel ); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // ----------------------------------------------------------------------- 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir void Accelerator::RemoveItem( sal_uInt16 nItemId ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir // Aus der Id-Liste entfernen 408*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetFirstPos( &(mpData->maIdList), nItemId ); 409*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir sal_uInt16 nItemCount = GetItemCount(); 412*cdf0e10cSrcweir do 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.GetObject( (sal_uLong)nIndex ); 415*cdf0e10cSrcweir if ( pEntry && pEntry->mnId == nItemId ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir mpData->maKeyTable.Remove( pEntry->maKeyCode.GetFullKeyCode() ); 418*cdf0e10cSrcweir mpData->maIdList.Remove( (sal_uLong)nIndex ); 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir // AutoResAccel zerstoeren 421*cdf0e10cSrcweir if ( pEntry->mpAutoAccel ) 422*cdf0e10cSrcweir delete pEntry->mpAutoAccel; 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir delete pEntry; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir else 427*cdf0e10cSrcweir break; 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir while ( nIndex < nItemCount ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir // ----------------------------------------------------------------------- 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir void Accelerator::RemoveItem( const KeyCode rKeyCode ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 440*cdf0e10cSrcweir if ( pEntry ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir // Aus der Id-Liste entfernen 443*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetFirstPos( &(mpData->maIdList), pEntry->mnId ); 444*cdf0e10cSrcweir sal_uInt16 nItemCount = GetItemCount(); 445*cdf0e10cSrcweir do 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir if ( mpData->maIdList.GetObject( (sal_uLong)nIndex ) == pEntry ) 448*cdf0e10cSrcweir break; 449*cdf0e10cSrcweir nIndex++; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir while ( nIndex < nItemCount ); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir mpData->maKeyTable.Remove( rKeyCode.GetFullKeyCode() ); 454*cdf0e10cSrcweir mpData->maIdList.Remove( (sal_uLong)nIndex ); 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir // AutoResAccel zerstoeren 457*cdf0e10cSrcweir if ( pEntry->mpAutoAccel ) 458*cdf0e10cSrcweir delete pEntry->mpAutoAccel; 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir delete pEntry; 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir // ----------------------------------------------------------------------- 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir void Accelerator::Clear() 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir ImplDeleteData(); 471*cdf0e10cSrcweir mpData->maKeyTable.Clear(); 472*cdf0e10cSrcweir mpData->maIdList.Clear(); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir // ----------------------------------------------------------------------- 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir sal_uInt16 Accelerator::GetItemCount() const 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir return (sal_uInt16)mpData->maIdList.Count(); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // ----------------------------------------------------------------------- 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir sal_uInt16 Accelerator::GetItemId( sal_uInt16 nPos ) const 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.GetObject( (sal_uLong)nPos ); 491*cdf0e10cSrcweir if ( pEntry ) 492*cdf0e10cSrcweir return pEntry->mnId; 493*cdf0e10cSrcweir else 494*cdf0e10cSrcweir return 0; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir // ----------------------------------------------------------------------- 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir KeyCode Accelerator::GetItemKeyCode( sal_uInt16 nPos ) const 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.GetObject( (sal_uLong)nPos ); 504*cdf0e10cSrcweir if ( pEntry ) 505*cdf0e10cSrcweir return pEntry->maKeyCode; 506*cdf0e10cSrcweir else 507*cdf0e10cSrcweir return KeyCode(); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // ----------------------------------------------------------------------- 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir sal_uInt16 Accelerator::GetItemId( const KeyCode& rKeyCode ) const 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 517*cdf0e10cSrcweir if ( pEntry ) 518*cdf0e10cSrcweir return pEntry->mnId; 519*cdf0e10cSrcweir else 520*cdf0e10cSrcweir return 0; 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir // ----------------------------------------------------------------------- 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir KeyCode Accelerator::GetKeyCode( sal_uInt16 nItemId ) const 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetFirstPos( &(mpData->maIdList), nItemId ); 530*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 531*cdf0e10cSrcweir return mpData->maIdList.GetObject( (sal_uLong)nIndex )->maKeyCode; 532*cdf0e10cSrcweir else 533*cdf0e10cSrcweir return KeyCode(); 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir // ----------------------------------------------------------------------- 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir sal_Bool Accelerator::IsIdValid( sal_uInt16 nItemId ) const 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetIndex( &(mpData->maIdList), nItemId ); 543*cdf0e10cSrcweir return (nIndex != ACCELENTRY_NOTFOUND); 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir // ----------------------------------------------------------------------- 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir sal_Bool Accelerator::IsKeyCodeValid( const KeyCode rKeyCode ) const 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 553*cdf0e10cSrcweir return (pEntry != NULL); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir // ----------------------------------------------------------------------- 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir sal_Bool Accelerator::Call( const KeyCode& rKeyCode, sal_uInt16 nRepeat ) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 563*cdf0e10cSrcweir if ( pEntry ) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir if ( pEntry->mbEnabled ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir sal_Bool bDel = sal_False; 568*cdf0e10cSrcweir mnCurId = pEntry->mnId; 569*cdf0e10cSrcweir maCurKeyCode = rKeyCode; 570*cdf0e10cSrcweir mnCurRepeat = nRepeat; 571*cdf0e10cSrcweir mpDel = &bDel; 572*cdf0e10cSrcweir Select(); 573*cdf0e10cSrcweir if ( !bDel ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir mnCurId = 0; 576*cdf0e10cSrcweir maCurKeyCode = KeyCode(); 577*cdf0e10cSrcweir mnCurRepeat = 0; 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir return sal_True; 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir return sal_False; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir // ----------------------------------------------------------------------- 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir void Accelerator::SetAccel( sal_uInt16 nItemId, Accelerator* pAccel ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetFirstPos( &(mpData->maIdList), nItemId ); 594*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir sal_uInt16 nItemCount = GetItemCount(); 597*cdf0e10cSrcweir do 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.GetObject( (sal_uLong)nIndex ); 600*cdf0e10cSrcweir if ( pEntry->mnId != nItemId ) 601*cdf0e10cSrcweir break; 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir pEntry->mpAccel = pAccel; 604*cdf0e10cSrcweir nIndex++; 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir while ( nIndex < nItemCount ); 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir // ----------------------------------------------------------------------- 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir Accelerator* Accelerator::GetAccel( sal_uInt16 nItemId ) const 613*cdf0e10cSrcweir { 614*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetIndex( &(mpData->maIdList), nItemId ); 617*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 618*cdf0e10cSrcweir return mpData->maIdList.GetObject( (sal_uLong)nIndex )->mpAccel; 619*cdf0e10cSrcweir else 620*cdf0e10cSrcweir return NULL; 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir // ----------------------------------------------------------------------- 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir void Accelerator::SetAccel( const KeyCode rKeyCode, Accelerator* pAccel ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 630*cdf0e10cSrcweir if ( pEntry ) 631*cdf0e10cSrcweir pEntry->mpAccel = pAccel; 632*cdf0e10cSrcweir } 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir // ----------------------------------------------------------------------- 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir Accelerator* Accelerator::GetAccel( const KeyCode rKeyCode ) const 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 641*cdf0e10cSrcweir if ( pEntry ) 642*cdf0e10cSrcweir return pEntry->mpAccel; 643*cdf0e10cSrcweir else 644*cdf0e10cSrcweir return sal_False; 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir // ----------------------------------------------------------------------- 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir void Accelerator::EnableItem( sal_uInt16 nItemId, sal_Bool bEnable ) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetFirstPos( &(mpData->maIdList), nItemId ); 654*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir sal_uInt16 nItemCount = GetItemCount(); 657*cdf0e10cSrcweir do 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir ImplAccelEntry* pEntry = mpData->maIdList.GetObject( (sal_uLong)nIndex ); 660*cdf0e10cSrcweir if ( pEntry->mnId != nItemId ) 661*cdf0e10cSrcweir break; 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir pEntry->mbEnabled = bEnable; 664*cdf0e10cSrcweir nIndex++; 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir while ( nIndex < nItemCount ); 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir // ----------------------------------------------------------------------- 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir sal_Bool Accelerator::IsItemEnabled( sal_uInt16 nItemId ) const 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir sal_uInt16 nIndex = ImplAccelEntryGetIndex( &(mpData->maIdList), nItemId ); 677*cdf0e10cSrcweir if ( nIndex != ACCELENTRY_NOTFOUND ) 678*cdf0e10cSrcweir return mpData->maIdList.GetObject( (sal_uLong)nIndex )->mbEnabled; 679*cdf0e10cSrcweir else 680*cdf0e10cSrcweir return sal_False; 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir // ----------------------------------------------------------------------- 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir void Accelerator::EnableItem( const KeyCode rKeyCode, sal_Bool bEnable ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 690*cdf0e10cSrcweir if ( pEntry ) 691*cdf0e10cSrcweir pEntry->mbEnabled = bEnable; 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir // ----------------------------------------------------------------------- 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir sal_Bool Accelerator::IsItemEnabled( const KeyCode rKeyCode ) const 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir ImplAccelEntry* pEntry = ImplGetAccelData( rKeyCode ); 701*cdf0e10cSrcweir if ( pEntry ) 702*cdf0e10cSrcweir return pEntry->mbEnabled; 703*cdf0e10cSrcweir else 704*cdf0e10cSrcweir return sal_False; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir // ----------------------------------------------------------------------- 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir Accelerator& Accelerator::operator=( const Accelerator& rAccel ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir DBG_CHKTHIS( Accelerator, NULL ); 712*cdf0e10cSrcweir DBG_CHKOBJ( &rAccel, Accelerator, NULL ); 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir // Neue Daten zuweisen 715*cdf0e10cSrcweir maHelpStr = rAccel.maHelpStr; 716*cdf0e10cSrcweir maCurKeyCode = KeyCode(); 717*cdf0e10cSrcweir mnCurId = 0; 718*cdf0e10cSrcweir mnCurRepeat = 0; 719*cdf0e10cSrcweir mbIsCancel = sal_False; 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir // Tabellen loeschen und kopieren 722*cdf0e10cSrcweir ImplDeleteData(); 723*cdf0e10cSrcweir mpData->maKeyTable.Clear(); 724*cdf0e10cSrcweir mpData->maIdList.Clear(); 725*cdf0e10cSrcweir ImplCopyData( *((ImplAccelData*)(rAccel.mpData)) ); 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir return *this; 728*cdf0e10cSrcweir } 729