libyui-ncurses  2.44.1
 All Classes Functions Variables
NCtoY2Event.cc
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: NCtoY2Event.h
20 
21  Authors: Michael Andres <ma@suse.de>
22  Stefan Hundhammer <sh@suse.de>
23 
24 /-*/
25 
26 #include "NCtoY2Event.h"
27 #include "NCWidget.h"
28 
29 #define YUILogComponent "ncurses"
30 #include <yui/YUILog.h>
31 
32 
34  : NCursesEvent( ncev )
35 {
36 }
37 
38 
41 {
42  if ( ncev.isInternalEvent() )
43  NCursesEvent::operator=( none );
44  else
45  NCursesEvent::operator=( ncev );
46 
47  return *this;
48 }
49 
50 
51 YEvent *
53 {
54  switch ( type )
55  {
56  // Note: libyui assumes ownership of YEvents, so they need to be
57  // created on the heap with 'new'. libyui takes care of deleting them.
58 
59  case button:
60 
61  if ( widget && widget->isValid() )
62  return new YWidgetEvent( dynamic_cast<YWidget *>( widget ), reason );
63  else
64  return 0;
65 
66  case menu:
67  if ( selection && widget && widget->isValid() )
68  return new YMenuEvent( selection );
69  else
70  return 0;
71 
72  case cancel:
73  return new YCancelEvent();
74 
75  case timeout:
76  return new YTimeoutEvent();
77 
78  case key:
79  if ( widget && widget->isValid() )
80  return new YKeyEvent( keySymbol, dynamic_cast<YWidget *>( widget ) );
81  else
82  return 0;
83 
84  case none:
85  case handled:
86  return 0;
87 
88  // Intentionally omitting 'default' branch so the compiler can
89  // detect unhandled enums
90  }
91 
92  // If we get this far, there must be an error.
93 
94  yuiMilestone() << "Can't propagate through (EventType*)0" << std::endl;
95 
96  yuiDebug() << *this << std::endl;
97 
98  return 0;
99 }
100 
101 
102 std::ostream &
103 operator<< ( std::ostream & stream, const NCtoY2Event & event )
104 {
105  stream << static_cast<const NCursesEvent &>( event );
106 
107  if ( ! event.selection )
108  {
109  stream << "(-)";
110  }
111  else
112  {
113  // 'selection' is used in NCMenuButton and NCRichtText (for hyper links)
114  stream << "(" << event.selection->label() << ")";
115  }
116 
117  return stream << " for " << event.widget;
118 }
119 
NCtoY2Event & operator=(const NCursesEvent &ncev)
Definition: NCtoY2Event.cc:40
YEvent * propagate()
Definition: NCtoY2Event.cc:52