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