libyui

/data/gitorious.org/libyui/libyui-master/src/YEvent.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YEvent.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YEvent_h
00041 #define YEvent_h
00042 
00043 
00044 #include <string>
00045 #include <iosfwd>
00046 #include "YDialog.h"
00047 #include "YSimpleEventHandler.h"
00048 
00049 using std::string;
00050 class YWidget;
00051 class YItem;
00052 class YDialog;
00053 
00054 
00059 class YEvent
00060 {
00061 public:
00062 
00063     enum EventType
00064     {
00065         NoEvent = 0,
00066         UnknownEvent,
00067         WidgetEvent,
00068         MenuEvent,
00069         KeyEvent,
00070         CancelEvent,
00071         TimeoutEvent,
00072         DebugEvent,
00073         InvalidEvent = 0x4242
00074     };
00075 
00076 
00077     enum EventReason
00078     {
00079         UnknownReason = 0,
00080         Activated,
00081         SelectionChanged,
00082         ValueChanged,
00083         ContextMenuActivated
00084     };
00085 
00086 
00090     YEvent( EventType eventType = UnknownEvent );
00091 
00095     EventType eventType() const { return _eventType; }
00096 
00101     unsigned long serial() const { return _serial; }
00102 
00109     virtual YWidget * widget() const { return 0; }
00110 
00117     virtual YItem * item() const { return 0; }
00118 
00122     YDialog * dialog() const { return _dialog; }
00123 
00127     bool isValid() const;
00128 
00132     static const char * toString( EventType eventType );
00133 
00137     static const char * toString( EventReason reason );
00138 
00139 
00140 protected:
00141     
00145     void setDialog( YDialog * dia ) { _dialog = dia; }
00146 
00155     virtual ~YEvent();
00156 
00160     void invalidate();
00161 
00162 private:
00163     
00164     friend void YDialog::deleteEvent( YEvent * event );
00165     friend void YSimpleEventHandler::deleteEvent( YEvent * event );
00166 
00167 
00168     //
00169     // Data members
00170     //
00171 
00172     EventType                   _eventType;
00173     unsigned long               _serial;
00174     YDialog *                   _dialog;
00175 
00176     static unsigned long        _nextSerial;
00177 };
00178 
00179 
00180 
00181 class YWidgetEvent: public YEvent
00182 {
00183 public:
00184 
00188     YWidgetEvent( YWidget *     widget          = 0,
00189                   EventReason   reason          = Activated,
00190                   EventType     eventType       = WidgetEvent );
00191 
00196     virtual YWidget * widget() const { return _widget; }
00197 
00201     EventReason reason() const { return _reason; }
00202 
00203 protected:
00204 
00210     virtual ~YWidgetEvent() {}
00211 
00212     
00213     //
00214     // Data members
00215     //
00216     
00217     YWidget *   _widget;
00218     EventReason _reason;
00219 };
00220 
00221 
00222 class YKeyEvent: public YEvent
00223 {
00224 public:
00225 
00233     YKeyEvent( const string &   keySymbol,
00234                YWidget *        focusWidget = 0 );
00235 
00240     string keySymbol() const { return _keySymbol; }
00241 
00248     YWidget * focusWidget() const { return _focusWidget; }
00249 
00250 protected:
00251     
00257     virtual ~YKeyEvent() {}
00258 
00259     
00260     //
00261     // Data members
00262     //
00263 
00264     string      _keySymbol;
00265     YWidget *   _focusWidget;
00266 };
00267 
00268 
00272 class YMenuEvent: public YEvent
00273 {
00274 public:
00275 
00276     YMenuEvent( YItem * item )
00277         : YEvent( MenuEvent )
00278         , _item( item )
00279         {}
00280 
00281     YMenuEvent( const char *     id )   : YEvent( MenuEvent ), _item(0), _id( id ) {}
00282     YMenuEvent( const string &   id )   : YEvent( MenuEvent ), _item(0), _id( id ) {}
00283 
00290     virtual YItem * item() const { return _item; }
00291 
00296     string id() const { return _id; }
00297 
00298 protected:
00299     
00305     virtual ~YMenuEvent() {}
00306 
00307     
00308     //
00309     // Data members
00310     //
00311 
00312     YItem * _item;
00313     string  _id;
00314 };
00315 
00316 
00321 class YCancelEvent: public YEvent
00322 {
00323 public:
00324 
00325     YCancelEvent() : YEvent( CancelEvent ) {}
00326 
00327     
00328 protected:
00334     virtual ~YCancelEvent() {}
00335 };
00336 
00337 
00342 class YDebugEvent: public YEvent
00343 {
00344 public:
00345 
00346     YDebugEvent() : YEvent( DebugEvent ) {}
00347     
00348 protected:
00354     virtual ~YDebugEvent() {}
00355 };
00356 
00357 
00362 class YTimeoutEvent: public YEvent
00363 {
00364 public:
00365 
00366     YTimeoutEvent() : YEvent( TimeoutEvent ) {}
00367     
00368 protected:
00374     virtual ~YTimeoutEvent() {}
00375 };
00376 
00377 
00378 std::ostream & operator<<( std::ostream & stream, const YEvent * event );
00379 
00380 
00381 #endif // YEvent_h
 All Classes Functions Variables Enumerations Friends