libyui  3.4.2
YSimpleEventHandler.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YSimpleEventHandler.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YSimpleEventHandler_h
26 #define YSimpleEventHandler_h
27 
28 
29 class YEvent;
30 class YWidget;
31 
32 
33 /**
34  * Simple event handler suitable for most UIs.
35  *
36  * This event handler keeps track of one single event that gets overwritten
37  * when a new one arrives.
38  **/
40 {
41 public:
42 
43  /**
44  * Constructor.
45  **/
47 
48  /**
49  * Destructor.
50  *
51  * If there is a pending event, it is deleted here.
52  **/
53  virtual ~YSimpleEventHandler();
54 
55  /**
56  * Widget event handlers call this when an event occured that
57  * should be the answer to a UserInput() / PollInput() (etc.) call.
58  *
59  * The UI assumes ownership of the event object that 'event' points to, so
60  * the event MUST be created with new(). The UI is to take care to delete
61  * the event after it has been processed.
62  *
63  * If events are blocked (see blockEvents() ), the event sent with this
64  * function will be ignored (but safely deleted - no memory leak).
65  *
66  * It is an error to pass 0 for 'event'.
67  **/
68  void sendEvent( YEvent * event_disown );
69 
70  /**
71  * Returns 'true' if there is any event pending for the specified widget.
72  **/
73  bool eventPendingFor( YWidget * widget ) const;
74 
75  /**
76  * Returns the last event that isn't processed yet or 0 if there is none.
77  *
78  * This event handler keeps track of only one single (the last one) event.
79  **/
80  YEvent * pendingEvent() const { return _pendingEvent; }
81 
82  /**
83  * Consumes the pending event. Sets the internal pending event to 0.
84  * Does NOT delete the internal consuming event.
85  *
86  * The caller assumes ownership of the object this pending event points
87  * to. In particular, he has to take care to delete that object when he is
88  * done processing it.
89  *
90  * Returns the pending event or 0 if there is none.
91  **/
93 
94  /**
95  * Delete any pending events for the specified widget. This is useful
96  * mostly if the widget is about to be destroyed.
97  **/
98  void deletePendingEventsFor( YWidget * widget );
99 
100  /**
101  * Clears any pending event (deletes the corresponding object).
102  **/
103  void clear();
104 
105  /**
106  * Block (or unblock) events. If events are blocked, any event sent with
107  * sendEvent() from now on is ignored (and will get lost) until events are
108  * unblocked again.
109  **/
110  void blockEvents( bool block = true );
111 
112  /**
113  * Unblock events previously blocked. This is just an alias for
114  * blockEvents( false) for better readability.
115  **/
116  void unblockEvents() { blockEvents( false ); }
117 
118  /**
119  * Returns 'true' if events are currently blocked.
120  **/
121  bool eventsBlocked() const { return _eventsBlocked; }
122 
123  /**
124  * Delete an event. Don't call this from the outside; this is public only
125  * because of limitations of C++ .
126  **/
127  void deleteEvent( YEvent * event );
128 
129 
130 protected:
131 
132  // Data members
133 
134  YEvent * _pendingEvent;
135  bool _eventsBlocked;
136 };
137 
138 
139 
140 
141 #endif // YSimpleEventHandler_h
virtual ~YSimpleEventHandler()
Destructor.
YEvent * consumePendingEvent()
Consumes the pending event.
Simple event handler suitable for most UIs.
bool eventPendingFor(YWidget *widget) const
Returns &#39;true&#39; if there is any event pending for the specified widget.
Abstract base class for events to be returned upon UI::UserInput() and related functions.
Definition: YEvent.h:43
void sendEvent(YEvent *event_disown)
Widget event handlers call this when an event occured that should be the answer to a UserInput() / Po...
bool eventsBlocked() const
Returns &#39;true&#39; if events are currently blocked.
void clear()
Clears any pending event (deletes the corresponding object).
void deleteEvent(YEvent *event)
Delete an event.
void blockEvents(bool block=true)
Block (or unblock) events.
void unblockEvents()
Unblock events previously blocked.
YSimpleEventHandler()
Constructor.
YEvent * pendingEvent() const
Returns the last event that isn&#39;t processed yet or 0 if there is none.
void deletePendingEventsFor(YWidget *widget)
Delete any pending events for the specified widget.
Abstract base class of all UI widgets.
Definition: YWidget.h:54