update dev300-m58
[ooovba.git] / vcl / source / window / accmgr.cxx
blob77c4d1552d7af4a95af187de7462ef6bd321b196
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accmgr.cxx,v $
10 * $Revision: 1.9 $
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()
53 if ( mpAccelList )
54 delete mpAccelList;
55 if ( mpSequenceList )
56 delete mpSequenceList;
59 // -----------------------------------------------------------------------
61 BOOL ImplAccelManager::InsertAccel( Accelerator* pAccel )
63 if ( !mpAccelList )
64 mpAccelList = new ImplAccelList;
65 else
67 // Gibts den schon ?
68 if ( mpAccelList->GetPos( pAccel ) != LIST_ENTRY_NOTFOUND )
69 return FALSE;
72 // Am Anfang der Liste einfuegen
73 mpAccelList->Insert( pAccel, (ULONG)0 );
75 return TRUE;
78 // -----------------------------------------------------------------------
80 void ImplAccelManager::RemoveAccel( Accelerator* pAccel )
82 // Haben wir ueberhaupt eine Liste ?
83 if ( !mpAccelList )
84 return;
86 // Raus damit
87 mpAccelList->Remove( pAccel );
90 // -----------------------------------------------------------------------
92 void ImplAccelManager::EndSequence( BOOL bCancel )
94 // Sind wir ueberhaupt in einer Sequenz ?
95 if ( !mpSequenceList )
96 return;
98 // Alle Deactivate-Handler der Acceleratoren in der Sequenz rufen
99 Accelerator* pTempAccel = mpSequenceList->First();
100 while( pTempAccel )
102 BOOL bDel = FALSE;
103 pTempAccel->mbIsCancel = bCancel;
104 pTempAccel->mpDel = &bDel;
105 pTempAccel->Deactivate();
106 if ( !bDel )
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 )
124 Accelerator* pAccel;
126 // Haben wir ueberhaupt Acceleratoren ??
127 if ( !mpAccelList )
128 return FALSE;
129 if ( !mpAccelList->Count() )
130 return FALSE;
132 // Sind wir in einer Sequenz ?
133 if ( mpSequenceList )
135 pAccel = mpSequenceList->GetObject( 0 );
136 DBG_CHKOBJ( pAccel, Accelerator, NULL );
138 // Nicht Gefunden ?
139 if ( !pAccel )
141 // Sequenz abbrechen
142 FlushAccel();
143 return FALSE;
146 // Ist der Eintrag da drin ?
147 ImplAccelEntry* pEntry = pAccel->ImplGetAccelData( rKeyCode );
148 if ( pEntry )
150 Accelerator* pNextAccel = pEntry->mpAccel;
152 // Ist da ein Accelerator hinter ?
153 if ( pNextAccel )
155 DBG_CHKOBJ( pNextAccel, Accelerator, NULL );
157 mpSequenceList->Insert( pNextAccel, (ULONG)0 );
159 // Activate-Handler vom Neuen rufen
160 pNextAccel->Activate();
161 return TRUE;
163 else
165 // Hat ihn schon !
166 if ( pEntry->mbEnabled )
168 // Sequence beenden (Deactivate-Handler vorher rufen)
169 EndSequence();
171 // Dem Accelerator das aktuelle Item setzen
172 // und Handler rufen
173 BOOL bDel = FALSE;
174 pAccel->maCurKeyCode = rKeyCode;
175 pAccel->mnCurId = pEntry->mnId;
176 pAccel->mnCurRepeat = nRepeat;
177 pAccel->mpDel = &bDel;
178 pAccel->Select();
180 // Hat Accel den Aufruf ueberlebt
181 if ( !bDel )
183 DBG_CHKOBJ( pAccel, Accelerator, NULL );
184 pAccel->maCurKeyCode = KeyCode();
185 pAccel->mnCurId = 0;
186 pAccel->mnCurRepeat = 0;
187 pAccel->mpDel = NULL;
190 return TRUE;
192 else
194 // Sequenz abbrechen, weil Acceleraor disabled
195 // Taste wird weitergeleitet (ans System)
196 FlushAccel();
197 return FALSE;
201 else
203 // Sequenz abbrechen wegen falscher Taste
204 FlushAccel();
205 return FALSE;
209 // Durch die Liste der Acceleratoren wuehlen
210 pAccel = mpAccelList->First();
211 while ( pAccel )
213 DBG_CHKOBJ( pAccel, Accelerator, NULL );
215 // Ist der Eintrag da drin ?
216 ImplAccelEntry* pEntry = pAccel->ImplGetAccelData( rKeyCode );
217 if ( pEntry )
219 Accelerator* pNextAccel = pEntry->mpAccel;
221 // Ist da ein Accelerator hinter ?
222 if ( pNextAccel )
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();
234 return TRUE;
236 else
238 // Hat ihn schon !
239 if ( pEntry->mbEnabled )
241 // Activate/Deactivate-Handler vorher rufen
242 pAccel->Activate();
243 pAccel->Deactivate();
245 // Dem Accelerator das aktuelle Item setzen
246 // und Handler rufen
247 BOOL bDel = FALSE;
248 pAccel->maCurKeyCode = rKeyCode;
249 pAccel->mnCurId = pEntry->mnId;
250 pAccel->mnCurRepeat = nRepeat;
251 pAccel->mpDel = &bDel;
252 pAccel->Select();
254 // Hat Accel den Aufruf ueberlebt
255 if ( !bDel )
257 DBG_CHKOBJ( pAccel, Accelerator, NULL );
258 pAccel->maCurKeyCode = KeyCode();
259 pAccel->mnCurId = 0;
260 pAccel->mnCurRepeat = 0;
261 pAccel->mpDel = NULL;
264 return TRUE;
266 else
267 return FALSE;
271 // Nicht gefunden, vielleicht im naechsten Accelerator
272 pAccel = mpAccelList->Next();
275 return FALSE;