libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YEvent.cc
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:         YEvent.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 
00027 #define YUILogComponent "ui-events"
00028 #include "YUILog.h"
00029 
00030 #include "YWidget.h"
00031 #include "YEvent.h"
00032 #include "YDialog.h"
00033 
00034 
00035 unsigned long YEvent::_nextSerial = 0;
00036 
00037 
00038 YEvent::YEvent( EventType eventType )
00039     : _eventType( eventType )
00040 {
00041     _dialog = YDialog::currentDialog( false ); // don't throw
00042     _serial = _nextSerial++;
00043 }
00044 
00045 
00046 YEvent::~YEvent()
00047 {
00048     invalidate();
00049 }
00050 
00051 
00052 bool
00053 YEvent::isValid() const
00054 {
00055     return _eventType != InvalidEvent;
00056 }
00057 
00058 
00059 void
00060 YEvent::invalidate()
00061 {
00062     _eventType = InvalidEvent;
00063 }
00064 
00065 
00066 const char *
00067 YEvent::toString( EventType eventType )
00068 {
00069     switch ( eventType )
00070     {
00071         case NoEvent:                   return "NoEvent";
00072         case UnknownEvent:              return "UnknownEvent";
00073         case WidgetEvent:               return "WidgetEvent";
00074         case MenuEvent:                 return "MenuEvent";
00075         case KeyEvent:                  return "KeyEvent";
00076         case CancelEvent:               return "CancelEvent";
00077         case TimeoutEvent:              return "TimeoutEvent";
00078         case DebugEvent:                return "DebugEvent";
00079         case InvalidEvent:              return "InvalidEvent";
00080 
00081         // Intentionally omitting "default" branch so the compiler can
00082         // detect unhandled enums
00083     }
00084 
00085     return "<Unknown event type - internal error>";
00086 }
00087 
00088 
00089 const char *
00090 YEvent::toString( EventReason reason )
00091 {
00092     switch ( reason )
00093     {
00094         case UnknownReason:             return "Unknown";
00095         case Activated:                 return "Activated";
00096         case SelectionChanged:          return "SelectionChanged";
00097         case ValueChanged:              return "ValueChanged";
00098         case ContextMenuActivated:      return "ContextMenuActivated";
00099 
00100         // Intentionally omitting "default" branch so the compiler can
00101         // detect unhandled enums
00102     }
00103 
00104     return "<Unknown event reason - internal error>";
00105 }
00106 
00107 
00108 
00109 
00110 YWidgetEvent::YWidgetEvent( YWidget *   widget,
00111                             EventReason reason,
00112                             EventType   eventType )
00113     : YEvent( eventType )
00114     , _widget( widget )
00115     , _reason( reason )
00116 {
00117     if ( widget )
00118         setDialog( widget->findDialog() );
00119 }
00120 
00121 
00122 
00123 YKeyEvent::YKeyEvent( const std::string &       keySymbol,
00124                       YWidget *                 focusWidget )
00125     : YEvent( KeyEvent )
00126     , _keySymbol( keySymbol )
00127     , _focusWidget( focusWidget )
00128 {
00129 }
00130 
00131 
00132 
00133 std::ostream &
00134 operator<<( std::ostream & stream, const YEvent * event )
00135 {
00136     if ( event )
00137     {
00138         stream << YEvent::toString( event->eventType() )
00139                << " at " << std::hex << (void *) event << std::dec;
00140     }
00141     else
00142     {
00143         stream << "<NULL event>";
00144     }
00145 
00146     return stream;
00147 }
 All Classes Functions Variables Enumerations Friends