1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
26 ImplAccelManager::~ImplAccelManager()
30 bool ImplAccelManager::InsertAccel( Accelerator
* pAccel
)
33 mxAccelList
.emplace();
35 for (Accelerator
* i
: *mxAccelList
) {
42 mxAccelList
->insert( mxAccelList
->begin(), pAccel
);
46 void ImplAccelManager::RemoveAccel( Accelerator
const * pAccel
)
48 // do we have a list ?
52 //e.g. #i90599#. Someone starts typing a sequence in a dialog, but doesn't
53 //end it, and then closes the dialog, deleting the accelerators. So if
54 //we're removing an accelerator that a sub-accelerator which is in the
55 //sequence list, throw away the entire sequence
56 if ( mxSequenceList
) {
57 for (sal_uInt16 i
= 0; i
< pAccel
->GetItemCount(); ++i
) {
58 Accelerator
* pSubAccel
= pAccel
->GetAccel( pAccel
->GetItemId(i
) );
59 for (Accelerator
* j
: *mxSequenceList
) {
60 if ( j
== pSubAccel
) {
62 i
= pAccel
->GetItemCount();
70 auto it
= std::find(mxAccelList
->begin(), mxAccelList
->end(), pAccel
);
71 if (it
!= mxAccelList
->end())
72 mxAccelList
->erase( it
);
75 void ImplAccelManager::EndSequence()
78 if ( !mxSequenceList
)
81 for (Accelerator
* pTempAccel
: *mxSequenceList
)
83 pTempAccel
->mpDel
= nullptr;
86 // delete sequence-list
87 mxSequenceList
.reset();
90 bool ImplAccelManager::IsAccelKey( const vcl::KeyCode
& rKeyCode
)
94 // do we have accelerators ??
97 if ( mxAccelList
->empty() )
100 // are we in a sequence ?
101 if ( mxSequenceList
)
103 pAccel
= mxSequenceList
->empty() ? nullptr : (*mxSequenceList
)[ 0 ];
113 // can the entry be found ?
114 ImplAccelEntry
* pEntry
= pAccel
->ImplGetAccelData( rKeyCode
);
117 Accelerator
* pNextAccel
= pEntry
->mpAccel
;
119 // is an accelerator coupled ?
123 mxSequenceList
->insert( mxSequenceList
->begin(), pNextAccel
);
125 // call Activate-Handler of the new one
126 pNextAccel
->Activate();
131 // it is there already !
132 if ( pEntry
->mbEnabled
)
134 // stop sequence (first call deactivate-handler)
137 // set accelerator of the actual item
138 // and call the handler
140 pAccel
->mnCurId
= pEntry
->mnId
;
141 pAccel
->mpDel
= &bDel
;
144 // did the accelerator survive the call
148 pAccel
->mpDel
= nullptr;
155 // stop sequence as the accelerator was disabled
156 // transfer the key (to the system)
164 // wrong key => stop sequence
170 // step through the list of accelerators
171 for (Accelerator
* i
: *mxAccelList
)
175 // is the entry contained ?
176 ImplAccelEntry
* pEntry
= pAccel
->ImplGetAccelData( rKeyCode
);
179 Accelerator
* pNextAccel
= pEntry
->mpAccel
;
181 // is an accelerator assigned ?
185 // create sequence list
186 mxSequenceList
.emplace();
187 mxSequenceList
->insert( mxSequenceList
->begin(), pAccel
);
188 mxSequenceList
->insert( mxSequenceList
->begin(), pNextAccel
);
190 // call activate-Handler of the new one
191 pNextAccel
->Activate();
197 // already assigned !
198 if ( pEntry
->mbEnabled
)
200 // first call activate/deactivate-Handler
203 // define accelerator of the actual item
204 // and call the handler
206 pAccel
->mnCurId
= pEntry
->mnId
;
207 pAccel
->mpDel
= &bDel
;
210 // if the accelerator did survive the call
214 pAccel
->mpDel
= nullptr;
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */