libyui-ncurses  2.50.1
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 ( widget && widget->isValid() ) {
68  if (selection)
69  return new YMenuEvent( selection );
70  else
71  return new YMenuEvent( result );
72  }
73  else
74  return 0;
75 
76  case cancel:
77  return new YCancelEvent();
78 
79  case timeout:
80  return new YTimeoutEvent();
81 
82  case key:
83  if ( widget && widget->isValid() )
84  return new YKeyEvent( keySymbol, dynamic_cast<YWidget *>( widget ) );
85  else
86  return 0;
87 
88  case none:
89  case handled:
90  return 0;
91 
92  // Intentionally omitting 'default' branch so the compiler can
93  // detect unhandled enums
94  }
95 
96  // If we get this far, there must be an error.
97 
98  yuiMilestone() << "Can't propagate through (EventType*)0" << std::endl;
99 
100  yuiDebug() << *this << std::endl;
101 
102  return 0;
103 }
104 
105 
106 std::ostream &
107 operator<< ( std::ostream & stream, const NCtoY2Event & event )
108 {
109  stream << static_cast<const NCursesEvent &>( event );
110 
111  if ( ! event.selection )
112  {
113  stream << "(-)";
114  }
115  else
116  {
117  // 'selection' is used in NCMenuButton and NCRichtText (for hyper links)
118  stream << "(" << event.selection->label() << ")";
119  }
120 
121  return stream << " for " << event.widget;
122 }
123 
NCtoY2Event & operator=(const NCursesEvent &ncev)
Assignment operator.
Definition: NCtoY2Event.cc:40
Helper class for translating an NCurses event to a YEvent.
Definition: NCtoY2Event.h:36
NCtoY2Event()
Default constructor.
Definition: NCtoY2Event.h:46
YEvent * propagate()
The reason of existence of this class: Translate the NCursesEvent to a YEvent.
Definition: NCtoY2Event.cc:52