libyui
YEvent.h
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: YEvent.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YEvent_h
26 #define YEvent_h
27 
28 
29 #include <string>
30 #include <iosfwd>
31 #include "YDialog.h"
32 #include "YSimpleEventHandler.h"
33 
34 class YWidget;
35 class YItem;
36 class YDialog;
37 
38 
43 class YEvent
44 {
45 public:
46 
47  enum EventType
48  {
49  NoEvent = 0,
50  UnknownEvent,
51  WidgetEvent,
52  MenuEvent,
53  KeyEvent,
54  CancelEvent,
55  TimeoutEvent,
56  DebugEvent,
57  InvalidEvent = 0x4242
58  };
59 
60 
61  enum EventReason
62  {
63  UnknownReason = 0,
64  Activated,
65  SelectionChanged,
66  ValueChanged,
67  ContextMenuActivated
68  };
69 
70 
74  YEvent( EventType eventType = UnknownEvent );
75 
79  EventType eventType() const { return _eventType; }
80 
85  unsigned long serial() const { return _serial; }
86 
93  virtual YWidget * widget() const { return 0; }
94 
101  virtual YItem * item() const { return 0; }
102 
106  YDialog * dialog() const { return _dialog; }
107 
111  bool isValid() const;
112 
116  static const char * toString( EventType eventType );
117 
121  static const char * toString( EventReason reason );
122 
123 
124 protected:
125 
129  void setDialog( YDialog * dia ) { _dialog = dia; }
130 
139  virtual ~YEvent();
140 
144  void invalidate();
145 
146 private:
147 
148  friend void YDialog::deleteEvent( YEvent * event );
149  friend void YSimpleEventHandler::deleteEvent( YEvent * event );
150 
151 
152  //
153  // Data members
154  //
155 
156  EventType _eventType;
157  unsigned long _serial;
158  YDialog * _dialog;
159 
160  static unsigned long _nextSerial;
161 };
162 
163 
164 
165 class YWidgetEvent: public YEvent
166 {
167 public:
168 
172  YWidgetEvent( YWidget * widget = 0,
173  EventReason reason = Activated,
174  EventType eventType = WidgetEvent );
175 
180  virtual YWidget * widget() const { return _widget; }
181 
185  EventReason reason() const { return _reason; }
186 
187 protected:
188 
194  virtual ~YWidgetEvent() {}
195 
196 
197  //
198  // Data members
199  //
200 
201  YWidget * _widget;
202  EventReason _reason;
203 };
204 
205 
206 class YKeyEvent: public YEvent
207 {
208 public:
209 
217  YKeyEvent( const std::string & keySymbol,
218  YWidget * focusWidget = 0 );
219 
224  std::string keySymbol() const { return _keySymbol; }
225 
232  YWidget * focusWidget() const { return _focusWidget; }
233 
234 protected:
235 
241  virtual ~YKeyEvent() {}
242 
243 
244  //
245  // Data members
246  //
247 
248  std::string _keySymbol;
249  YWidget * _focusWidget;
250 };
251 
252 
256 class YMenuEvent: public YEvent
257 {
258 public:
259 
260  YMenuEvent( YItem * item )
261  : YEvent( MenuEvent )
262  , _item( item )
263  {}
264 
265  YMenuEvent( const char * id ) : YEvent( MenuEvent ), _item(0), _id( id ) {}
266  YMenuEvent( const std::string & id ) : YEvent( MenuEvent ), _item(0), _id( id ) {}
267 
274  virtual YItem * item() const { return _item; }
275 
280  std::string id() const { return _id; }
281 
282 protected:
283 
289  virtual ~YMenuEvent() {}
290 
291 
292  //
293  // Data members
294  //
295 
296  YItem * _item;
297  std::string _id;
298 };
299 
300 
305 class YCancelEvent: public YEvent
306 {
307 public:
308 
309  YCancelEvent() : YEvent( CancelEvent ) {}
310 
311 
312 protected:
318  virtual ~YCancelEvent() {}
319 };
320 
321 
326 class YDebugEvent: public YEvent
327 {
328 public:
329 
330  YDebugEvent() : YEvent( DebugEvent ) {}
331 
332 protected:
338  virtual ~YDebugEvent() {}
339 };
340 
341 
346 class YTimeoutEvent: public YEvent
347 {
348 public:
349 
350  YTimeoutEvent() : YEvent( TimeoutEvent ) {}
351 
352 protected:
358  virtual ~YTimeoutEvent() {}
359 };
360 
361 
362 std::ostream & operator<<( std::ostream & stream, const YEvent * event );
363 
364 
365 #endif // YEvent_h
virtual ~YKeyEvent()
Definition: YEvent.h:241
void deleteEvent(YEvent *event)
Definition: YDialog.cc:516
Definition: YEvent.h:206
std::string keySymbol() const
Definition: YEvent.h:224
bool isValid() const
Definition: YEvent.cc:55
void setDialog(YDialog *dia)
Definition: YEvent.h:129
Definition: YEvent.h:256
virtual ~YEvent()
Definition: YEvent.cc:48
Definition: YEvent.h:43
virtual ~YTimeoutEvent()
Definition: YEvent.h:358
YWidgetEvent(YWidget *widget=0, EventReason reason=Activated, EventType eventType=WidgetEvent)
Definition: YEvent.cc:112
virtual ~YWidgetEvent()
Definition: YEvent.h:194
EventType eventType() const
Definition: YEvent.h:79
virtual YItem * item() const
Definition: YEvent.h:274
YKeyEvent(const std::string &keySymbol, YWidget *focusWidget=0)
Definition: YEvent.cc:125
YWidget * focusWidget() const
Definition: YEvent.h:232
virtual ~YMenuEvent()
Definition: YEvent.h:289
void invalidate()
Definition: YEvent.cc:62
Definition: YItem.h:55
virtual ~YDebugEvent()
Definition: YEvent.h:338
void deleteEvent(YEvent *event)
Definition: YSimpleEventHandler.cc:156
EventReason reason() const
Definition: YEvent.h:185
unsigned long serial() const
Definition: YEvent.h:85
Definition: YEvent.h:165
virtual YItem * item() const
Definition: YEvent.h:101
YDialog * dialog() const
Definition: YEvent.h:106
std::string id() const
Definition: YEvent.h:280
YEvent(EventType eventType=UnknownEvent)
Definition: YEvent.cc:40
Definition: YEvent.h:346
Definition: YDialog.h:47
virtual YWidget * widget() const
Definition: YEvent.h:93
Definition: YWidget.h:54
static const char * toString(EventType eventType)
Definition: YEvent.cc:69
virtual ~YCancelEvent()
Definition: YEvent.h:318
virtual YWidget * widget() const
Definition: YEvent.h:180
Definition: YEvent.h:305
Definition: YEvent.h:326