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