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 .
20 #include <svx/sdr/event/eventhandler.hxx>
22 // for SOLARIS compiler include of algorithm part of _STL is necessary to
23 // get access to basic algos like ::std::find
25 #include <tools/debug.hxx>
27 //////////////////////////////////////////////////////////////////////////////
33 BaseEvent::BaseEvent(EventHandler
& rEventHandler
)
34 : mrEventHandler(rEventHandler
)
36 mrEventHandler
.AddEvent(*this);
39 BaseEvent::~BaseEvent()
41 mrEventHandler
.RemoveEvent(*this);
43 } // end of namespace mixer
44 } // end of namespace sdr
46 //////////////////////////////////////////////////////////////////////////////
52 void EventHandler::AddEvent(BaseEvent
& rBaseEvent
)
54 maVector
.push_back(&rBaseEvent
);
57 void EventHandler::RemoveEvent(BaseEvent
& rBaseEvent
)
59 if(maVector
.back() == &rBaseEvent
)
61 // the one to remove is the last, pop
66 const BaseEventVector::iterator aFindResult
= ::std::find(
67 maVector
.begin(), maVector
.end(), &rBaseEvent
);
68 DBG_ASSERT(aFindResult
!= maVector
.end(),
69 "EventHandler::RemoveEvent: Event to be removed not found (!)");
70 maVector
.erase(aFindResult
);
74 BaseEvent
* EventHandler::GetEvent()
78 // get the last event, that one is fastest to be removed
79 return maVector
.back();
87 EventHandler::EventHandler()
91 EventHandler::~EventHandler()
93 while(!maVector
.empty())
99 // Trigger and consume the events
100 void EventHandler::ExecuteEvents()
104 BaseEvent
* pEvent
= GetEvent();
107 pEvent
->ExecuteEvent();
113 bool EventHandler::IsEmpty() const
115 return (0L == maVector
.size());
117 } // end of namespace mixer
118 } // end of namespace sdr
120 //////////////////////////////////////////////////////////////////////////////
126 TimerEventHandler::TimerEventHandler(sal_uInt32 nTimeout
)
128 SetTimeout(nTimeout
);
132 TimerEventHandler::~TimerEventHandler()
137 // The timer when it is triggered; from class Timer
138 void TimerEventHandler::Timeout()
144 void TimerEventHandler::Restart()
148 } // end of namespace mixer
149 } // end of namespace sdr
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */