fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / event / eventhandler.cxx
blob9dab9cb7b9218daae4edd90bb24f275f581fe52a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
24 #include <algorithm>
25 #include <tools/debug.hxx>
27 //////////////////////////////////////////////////////////////////////////////
29 namespace sdr
31 namespace event
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 //////////////////////////////////////////////////////////////////////////////
48 namespace sdr
50 namespace event
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
62 maVector.pop_back();
64 else
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()
76 if(!maVector.empty())
78 // get the last event, that one is fastest to be removed
79 return maVector.back();
81 else
83 return 0L;
87 EventHandler::EventHandler()
91 EventHandler::~EventHandler()
93 while(!maVector.empty())
95 delete GetEvent();
99 // Trigger and consume the events
100 void EventHandler::ExecuteEvents()
102 for(;;)
104 BaseEvent* pEvent = GetEvent();
105 if(pEvent == NULL)
106 break;
107 pEvent->ExecuteEvent();
108 delete pEvent;
112 // for control
113 bool EventHandler::IsEmpty() const
115 return (0L == maVector.size());
117 } // end of namespace mixer
118 } // end of namespace sdr
120 //////////////////////////////////////////////////////////////////////////////
122 namespace sdr
124 namespace event
126 TimerEventHandler::TimerEventHandler(sal_uInt32 nTimeout)
128 SetTimeout(nTimeout);
129 Stop();
132 TimerEventHandler::~TimerEventHandler()
134 Stop();
137 // The timer when it is triggered; from class Timer
138 void TimerEventHandler::Timeout()
140 ExecuteEvents();
143 // reset the timer
144 void TimerEventHandler::Restart()
146 Start();
148 } // end of namespace mixer
149 } // end of namespace sdr
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */