1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accmgr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/list.hxx>
34 #include <tools/debug.hxx>
35 #include <vcl/accel.h>
36 #include <vcl/accel.hxx>
37 #include <vcl/accmgr.hxx>
41 // =======================================================================
43 DECLARE_LIST( ImplAccelList
, Accelerator
* )
45 // =======================================================================
47 DBG_NAMEEX( Accelerator
)
49 // =======================================================================
51 ImplAccelManager::~ImplAccelManager()
56 delete mpSequenceList
;
59 // -----------------------------------------------------------------------
61 BOOL
ImplAccelManager::InsertAccel( Accelerator
* pAccel
)
64 mpAccelList
= new ImplAccelList
;
68 if ( mpAccelList
->GetPos( pAccel
) != LIST_ENTRY_NOTFOUND
)
72 // Am Anfang der Liste einfuegen
73 mpAccelList
->Insert( pAccel
, (ULONG
)0 );
78 // -----------------------------------------------------------------------
80 void ImplAccelManager::RemoveAccel( Accelerator
* pAccel
)
82 // Haben wir ueberhaupt eine Liste ?
87 mpAccelList
->Remove( pAccel
);
90 // -----------------------------------------------------------------------
92 void ImplAccelManager::EndSequence( BOOL bCancel
)
94 // Sind wir ueberhaupt in einer Sequenz ?
95 if ( !mpSequenceList
)
98 // Alle Deactivate-Handler der Acceleratoren in der Sequenz rufen
99 Accelerator
* pTempAccel
= mpSequenceList
->First();
103 pTempAccel
->mbIsCancel
= bCancel
;
104 pTempAccel
->mpDel
= &bDel
;
105 pTempAccel
->Deactivate();
108 pTempAccel
->mbIsCancel
= FALSE
;
109 pTempAccel
->mpDel
= NULL
;
112 pTempAccel
= mpSequenceList
->Next();
115 // Sequenz-Liste loeschen
116 delete mpSequenceList
;
117 mpSequenceList
= NULL
;
120 // -----------------------------------------------------------------------
122 BOOL
ImplAccelManager::IsAccelKey( const KeyCode
& rKeyCode
, USHORT nRepeat
)
126 // Haben wir ueberhaupt Acceleratoren ??
129 if ( !mpAccelList
->Count() )
132 // Sind wir in einer Sequenz ?
133 if ( mpSequenceList
)
135 pAccel
= mpSequenceList
->GetObject( 0 );
136 DBG_CHKOBJ( pAccel
, Accelerator
, NULL
);
146 // Ist der Eintrag da drin ?
147 ImplAccelEntry
* pEntry
= pAccel
->ImplGetAccelData( rKeyCode
);
150 Accelerator
* pNextAccel
= pEntry
->mpAccel
;
152 // Ist da ein Accelerator hinter ?
155 DBG_CHKOBJ( pNextAccel
, Accelerator
, NULL
);
157 mpSequenceList
->Insert( pNextAccel
, (ULONG
)0 );
159 // Activate-Handler vom Neuen rufen
160 pNextAccel
->Activate();
166 if ( pEntry
->mbEnabled
)
168 // Sequence beenden (Deactivate-Handler vorher rufen)
171 // Dem Accelerator das aktuelle Item setzen
174 pAccel
->maCurKeyCode
= rKeyCode
;
175 pAccel
->mnCurId
= pEntry
->mnId
;
176 pAccel
->mnCurRepeat
= nRepeat
;
177 pAccel
->mpDel
= &bDel
;
180 // Hat Accel den Aufruf ueberlebt
183 DBG_CHKOBJ( pAccel
, Accelerator
, NULL
);
184 pAccel
->maCurKeyCode
= KeyCode();
186 pAccel
->mnCurRepeat
= 0;
187 pAccel
->mpDel
= NULL
;
194 // Sequenz abbrechen, weil Acceleraor disabled
195 // Taste wird weitergeleitet (ans System)
203 // Sequenz abbrechen wegen falscher Taste
209 // Durch die Liste der Acceleratoren wuehlen
210 pAccel
= mpAccelList
->First();
213 DBG_CHKOBJ( pAccel
, Accelerator
, NULL
);
215 // Ist der Eintrag da drin ?
216 ImplAccelEntry
* pEntry
= pAccel
->ImplGetAccelData( rKeyCode
);
219 Accelerator
* pNextAccel
= pEntry
->mpAccel
;
221 // Ist da ein Accelerator hinter ?
224 DBG_CHKOBJ( pNextAccel
, Accelerator
, NULL
);
226 // Sequenz-Liste erzeugen
227 mpSequenceList
= new ImplAccelList
;
228 mpSequenceList
->Insert( pAccel
, (ULONG
)0 );
229 mpSequenceList
->Insert( pNextAccel
, (ULONG
)0 );
231 // Activate-Handler vom Neuen rufen
232 pNextAccel
->Activate();
239 if ( pEntry
->mbEnabled
)
241 // Activate/Deactivate-Handler vorher rufen
243 pAccel
->Deactivate();
245 // Dem Accelerator das aktuelle Item setzen
248 pAccel
->maCurKeyCode
= rKeyCode
;
249 pAccel
->mnCurId
= pEntry
->mnId
;
250 pAccel
->mnCurRepeat
= nRepeat
;
251 pAccel
->mpDel
= &bDel
;
254 // Hat Accel den Aufruf ueberlebt
257 DBG_CHKOBJ( pAccel
, Accelerator
, NULL
);
258 pAccel
->maCurKeyCode
= KeyCode();
260 pAccel
->mnCurRepeat
= 0;
261 pAccel
->mpDel
= NULL
;
271 // Nicht gefunden, vielleicht im naechsten Accelerator
272 pAccel
= mpAccelList
->Next();