xref: /aoo4110/main/svx/inc/svx/sdr/event/eventhandler.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SDR_EVENT_EVENTHANDLER_HXX
25 #define _SDR_EVENT_EVENTHANDLER_HXX
26 
27 #include <sal/types.h>
28 
29 #include <vector>
30 #include <vcl/timer.hxx>
31 
32 //////////////////////////////////////////////////////////////////////////////
33 // predeclarations
34 
35 namespace sdr
36 {
37 	namespace event
38 	{
39 		class BaseEvent;
40 		class EventHandler;
41 
42 		// typedefs for a list of BaseEvents
43 		typedef ::std::vector< BaseEvent* > BaseEventVector;
44 	} // end of namespace event
45 } // end of namespace sdr
46 
47 //////////////////////////////////////////////////////////////////////////////
48 
49 namespace sdr
50 {
51 	namespace event
52 	{
53 		class BaseEvent
54 		{
55 			// the EventHandler this event is registered at
56 			EventHandler&									mrEventHandler;
57 
58 		public:
59 			// basic constructor.
60 			BaseEvent(EventHandler& rEventHandler);
61 
62 			// destructor
63 			virtual ~BaseEvent();
64 
65 			// the called method if the event is triggered
66 			virtual void ExecuteEvent() = 0;
67 		};
68 	} // end of namespace event
69 } // end of namespace sdr
70 
71 //////////////////////////////////////////////////////////////////////////////
72 
73 namespace sdr
74 {
75 	namespace event
76 	{
77 		class EventHandler
78 		{
79 			BaseEventVector									maVector;
80 
81 			// to allow BaseEvents to use the add/remove functionality
82 			friend class BaseEvent;
83 
84 			// methods to add/remove events. These are private since
85 			// they are used from BaseEvent only.
86 			void AddEvent(BaseEvent& rBaseEvent);
87 			void RemoveEvent(BaseEvent& rBaseEvent);
88 
89 			// access to a event, 0L when no more events
90 			BaseEvent* GetEvent();
91 
92 		public:
93 			// basic constructor.
94 			EventHandler();
95 
96 			// destructor
97 			virtual ~EventHandler();
98 
99 			// Trigger and consume the events
100 			virtual void ExecuteEvents();
101 
102 			// for control
103 			sal_Bool IsEmpty() const;
104 		};
105 	} // end of namespace event
106 } // end of namespace sdr
107 
108 //////////////////////////////////////////////////////////////////////////////
109 
110 namespace sdr
111 {
112 	namespace event
113 	{
114 		class TimerEventHandler : public EventHandler, public Timer
115 		{
116 		public:
117 			// basic constructor.
118 			TimerEventHandler(sal_uInt32 nTimeout = 1L);
119 
120 			// destructor
121 			virtual ~TimerEventHandler();
122 
123 			// The timer when it is triggered; from class Timer
124 			virtual void Timeout();
125 
126 			// reset the timer
127 			void Restart();
128 		};
129 	} // end of namespace event
130 } // end of namespace sdr
131 
132 //////////////////////////////////////////////////////////////////////////////
133 
134 #endif //_SDR_EVENT_EVENTHANDLER_HXX
135 
136 // eof
137