libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCtoY2Event.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:       NCtoY2Event.h
00020 
00021    Authors:    Michael Andres <ma@suse.de>
00022                Stefan Hundhammer <sh@suse.de>
00023 
00024 /-*/
00025 
00026 #include "NCtoY2Event.h"
00027 #include "NCWidget.h"
00028 
00029 #define  YUILogComponent "ncurses"
00030 #include <yui/YUILog.h>
00031 
00032 
00033 NCtoY2Event::NCtoY2Event( const NCursesEvent & ncev )
00034         : NCursesEvent( ncev )
00035 {
00036 }
00037 
00038 
00039 NCtoY2Event &
00040 NCtoY2Event::operator=( const NCursesEvent & ncev )
00041 {
00042     if ( ncev.isInternalEvent() )
00043         NCursesEvent::operator=( none );
00044     else
00045         NCursesEvent::operator=( ncev );
00046 
00047     return *this;
00048 }
00049 
00050 
00051 YEvent *
00052 NCtoY2Event::propagate()
00053 {
00054     switch ( type )
00055     {
00056         // Note: libyui assumes ownership of YEvents, so they need to be
00057         // created on the heap with 'new'. libyui takes care of deleting them.
00058 
00059         case button:
00060 
00061             if ( widget && widget->isValid() )
00062                 return new YWidgetEvent( dynamic_cast<YWidget *>( widget ), reason );
00063             else
00064                 return 0;
00065 
00066         case menu:
00067             if ( selection && widget && widget->isValid() )
00068                 return new YMenuEvent( selection );
00069             else
00070                 return 0;
00071 
00072         case cancel:
00073             return new YCancelEvent();
00074 
00075         case timeout:
00076             return new YTimeoutEvent();
00077 
00078         case key:
00079             if ( widget && widget->isValid() )
00080                 return new YKeyEvent( keySymbol, dynamic_cast<YWidget *>( widget ) );
00081             else
00082                 return 0;
00083 
00084         case none:
00085         case handled:
00086             return 0;
00087 
00088             // Intentionally omitting 'default' branch so the compiler can
00089             // detect unhandled enums
00090     }
00091 
00092     // If we get this far, there must be an error.
00093 
00094     yuiMilestone() << "Can't propagate through (EventType*)0" << std::endl;
00095 
00096     yuiDebug() << *this << std::endl;
00097 
00098     return 0;
00099 }
00100 
00101 
00102 std::ostream &
00103 operator<< ( std::ostream & stream, const NCtoY2Event & event )
00104 {
00105     stream << static_cast<const NCursesEvent &>( event );
00106 
00107     if ( ! event.selection )
00108     {
00109         stream << "(-)";
00110     }
00111     else
00112     {
00113         // 'selection' is used in NCMenuButton and NCRichtText (for hyper links)
00114         stream << "(" << event.selection->label() << ")";
00115     }
00116 
00117     return stream << " for " << event.widget;
00118 }
00119 
 All Classes Functions Variables