libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YSimpleEventHandler.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YSimpleEventHandler.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YSimpleEventHandler_h
00026 #define YSimpleEventHandler_h
00027 
00028 
00029 class YEvent;
00030 class YWidget;
00031 
00032 
00033 /**
00034  * Simple event handler suitable for most UIs.
00035  *
00036  * This event handler keeps track of one single event that gets overwritten
00037  * when a new one arrives.
00038  **/
00039 class YSimpleEventHandler
00040 {
00041 public:
00042 
00043     /**
00044      * Constructor.
00045      **/
00046     YSimpleEventHandler();
00047 
00048     /**
00049      * Destructor.
00050      *
00051      * If there is a pending event, it is deleted here.
00052      **/
00053     virtual ~YSimpleEventHandler();
00054 
00055     /**
00056      * Widget event handlers call this when an event occured that
00057      * should be the answer to a UserInput() / PollInput() (etc.) call.
00058      *
00059      * The UI assumes ownership of the event object that 'event' points to, so
00060      * the event MUST be created with new(). The UI is to take care to delete
00061      * the event after it has been processed.
00062      *
00063      * If events are blocked (see blockEvents() ), the event sent with this
00064      * function will be ignored (but safely deleted - no memory leak).
00065      *
00066      * It is an error to pass 0 for 'event'.
00067      **/
00068     void sendEvent( YEvent * event_disown );
00069 
00070     /**
00071      * Returns 'true' if there is any event pending for the specified widget.
00072      **/
00073     bool eventPendingFor( YWidget * widget ) const;
00074 
00075     /**
00076      * Returns the last event that isn't processed yet or 0 if there is none.
00077      *
00078      * This event handler keeps track of only one single (the last one) event.
00079      **/
00080     YEvent * pendingEvent() const { return _pendingEvent; }
00081 
00082     /**
00083      * Consumes the pending event. Sets the internal pending event to 0.
00084      * Does NOT delete the internal consuming event.
00085      *
00086      * The caller assumes ownership of the object this pending event points
00087      * to. In particular, he has to take care to delete that object when he is
00088      * done processing it.
00089      *
00090      * Returns the pending event or 0 if there is none.
00091      **/
00092     YEvent * consumePendingEvent();
00093 
00094     /**
00095      * Delete any pending events for the specified widget. This is useful
00096      * mostly if the widget is about to be destroyed.
00097      **/
00098     void deletePendingEventsFor( YWidget * widget );
00099 
00100     /**
00101      * Clears any pending event (deletes the corresponding object).
00102      **/
00103     void clear();
00104 
00105     /**
00106      * Block (or unblock) events. If events are blocked, any event sent with
00107      * sendEvent() from now on is ignored (and will get lost) until events are
00108      * unblocked again.
00109      **/
00110     void blockEvents( bool block = true );
00111 
00112     /**
00113      * Unblock events previously blocked. This is just an alias for
00114      * blockEvents( false) for better readability.
00115      **/
00116     void unblockEvents() { blockEvents( false ); }
00117 
00118     /**
00119      * Returns 'true' if events are currently blocked.
00120      **/
00121     bool eventsBlocked() const { return _eventsBlocked; }
00122 
00123     /**
00124      * Delete an event. Don't call this from the outside; this is public only
00125      * because of limitations of C++ .
00126      **/
00127     void deleteEvent( YEvent * event );
00128 
00129 
00130 protected:
00131 
00132     // Data members
00133 
00134     YEvent *    _pendingEvent;
00135     bool        _eventsBlocked;
00136 };
00137 
00138 
00139 
00140 
00141 #endif // YSimpleEventHandler_h
 All Classes Functions Variables Enumerations Friends