2009-12-01 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / eventargs.h
blobeae1a1f36205f2e31bf6c4b1d47e137e5a89509a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * eventargs.h
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __EVENTARGS_H__
12 #define __EVENTARGS_H__
14 #include <glib.h>
16 #include <cairo.h>
17 #include <gdk/gdkevents.h>
18 #include "dependencyobject.h"
19 #include "keyboard.h"
20 #include "enums.h"
21 #include "error.h"
23 class StylusInfo;
24 class StylusPointCollection;
25 class UIElement;
28 * EventArgs needs to be ref counted since js can keep objects around until
29 * after the event has been emitted.
32 /* @Namespace=None */
33 class EventArgs : public DependencyObject {
34 public:
35 EventArgs ();
37 protected:
38 virtual ~EventArgs ();
39 EventArgs (Type::Kind type);
42 /* @Namespace=None */
43 class PropertyChangedEventArgs : public EventArgs {
44 public:
45 PropertyChangedEventArgs (DependencyProperty *p, int pid, Value *ov, Value *nv) : obj (p), id (pid), old_value(ov), new_value (nv) { }
47 /* @GenerateCBinding,GeneratePInvoke */
48 DependencyProperty *GetProperty () { return obj; }
49 /* @GenerateCBinding,GeneratePInvoke */
50 int GetId () { return id; }
51 /* @GenerateCBinding,GeneratePInvoke */
52 Value* GetOldValue () { return old_value; }
53 /* @GenerateCBinding,GeneratePInvoke */
54 Value* GetNewValue () { return new_value; }
56 private:
57 DependencyProperty *obj;
58 int id;
60 Value *old_value;
61 Value *new_value;
64 /* @Namespace=None */
65 class RenderingEventArgs : public EventArgs {
66 public:
67 RenderingEventArgs (TimeSpan renderingTime);
69 /* @GenerateCBinding,GeneratePInvoke */
70 TimeSpan GetRenderingTime ();
72 protected:
73 virtual ~RenderingEventArgs ();
75 private:
77 TimeSpan renderingTime;
80 enum CollectionChangedAction {
81 CollectionChangedActionAdd,
82 CollectionChangedActionRemove,
83 CollectionChangedActionReplace,
84 CollectionChangedActionClearing,
85 CollectionChangedActionCleared,
88 /* @Namespace=None */
89 class CollectionChangedEventArgs : public EventArgs {
90 public:
91 /* @GenerateCBinding,GeneratePInvoke */
92 CollectionChangedEventArgs ();
94 CollectionChangedEventArgs (CollectionChangedAction action, Value *new_value, Value *old_value, int index);
96 /* @GenerateCBinding,GeneratePInvoke */
97 void SetChangedAction (CollectionChangedAction action);
99 /* @GenerateCBinding,GeneratePInvoke */
100 CollectionChangedAction GetChangedAction ();
102 /* @GenerateCBinding,GeneratePInvoke */
103 void SetNewItem (Value *item);
105 /* @GenerateCBinding,GeneratePInvoke */
106 Value *GetNewItem ();
108 /* @GenerateCBinding,GeneratePInvoke */
109 void SetOldItem (Value *item);
111 /* @GenerateCBinding,GeneratePInvoke */
112 Value *GetOldItem ();
114 /* @GenerateCBinding,GeneratePInvoke */
115 void SetIndex (int index);
117 /* @GenerateCBinding,GeneratePInvoke */
118 int GetIndex ();
120 protected:
121 virtual ~CollectionChangedEventArgs ();
124 private:
125 CollectionChangedAction action;
126 Value *old_item;
127 Value *new_item;
128 int index;
131 /* @Namespace=None */
132 class CollectionItemChangedEventArgs : public EventArgs {
133 public:
134 CollectionItemChangedEventArgs (DependencyObject *collectionItem,
135 DependencyProperty *property,
136 Value *oldValue,
137 Value *newValue)
139 this->collectionItem = collectionItem;
140 this->property = property;
141 this->oldValue = oldValue;
142 this->newValue = newValue;
145 DependencyObject* GetCollectionItem() { return collectionItem; }
146 DependencyProperty* GetProperty() { return property; }
147 Value* GetOldValue () { return oldValue; }
148 Value* GetNewValue () { return newValue; }
150 private:
151 DependencyObject *collectionItem;
152 DependencyProperty *property;
153 Value *oldValue;
154 Value *newValue;
157 /* @Namespace=None */
158 class DownloadProgressEventArgs : public EventArgs {
159 private:
160 double progress;
162 protected:
163 virtual ~DownloadProgressEventArgs ();
165 public:
166 DownloadProgressEventArgs ();
167 DownloadProgressEventArgs (double progress);
169 void SetProgress (double progress);
171 /* @GenerateCBinding,GeneratePInvoke */
172 double GetProgress ();
175 /* @Namespace=None */
176 class RoutedEventArgs : public EventArgs {
177 public:
178 /* @GenerateCBinding,GeneratePInvoke */
179 RoutedEventArgs ();
181 RoutedEventArgs (DependencyObject *source);
183 /* @GenerateCBinding,GeneratePInvoke */
184 DependencyObject *GetSource ();
186 /* @GenerateCBinding,GeneratePInvoke */
187 void SetSource(DependencyObject *el);
189 /* @GenerateCBinding,GeneratePInvoke */
190 void SetHandled (bool handled);
192 /* @GenerateCBinding,GeneratePInvoke */
193 bool GetHandled ();
195 protected:
196 virtual ~RoutedEventArgs ();
197 RoutedEventArgs (DependencyObject *source, Type::Kind kind);
198 RoutedEventArgs (Type::Kind kind);
200 private:
201 DependencyObject *source;
202 bool handled;
205 /* @Namespace=None */
206 class KeyEventArgs : public RoutedEventArgs {
207 public:
208 /* @GenerateCBinding,GeneratePInvoke */
209 KeyEventArgs ();
210 KeyEventArgs (GdkEventKey *event);
212 /* @GenerateCBinding,GeneratePInvoke */
213 int GetKey ();
215 /* @GenerateCBinding,GeneratePInvoke */
216 int GetPlatformKeyCode ();
218 // accessors for the native GdkEventKey
219 GdkEventKey *GetEvent ();
220 GdkModifierType GetModifiers ();
221 gunichar GetUnicode ();
222 guint GetKeyVal ();
223 bool IsModifier ();
225 protected:
226 virtual ~KeyEventArgs ();
228 private:
229 GdkEventKey *event;
232 /* @Namespace=None */
233 class MouseEventArgs : public RoutedEventArgs {
234 public:
235 /* @GenerateCBinding,GeneratePInvoke */
236 MouseEventArgs ();
237 MouseEventArgs (GdkEvent *event);
239 GdkEvent *GetEvent () { return event; }
241 int GetState ();
243 /* @GenerateCBinding,GeneratePInvoke */
244 void GetPosition (UIElement *relative_to, double *x, double *y);
246 /* @GenerateCBinding,GeneratePInvoke */
247 StylusInfo *GetStylusInfo ();
249 /* @GenerateCBinding,GeneratePInvoke */
250 StylusPointCollection *GetStylusPoints (UIElement *ink_presenter);
252 protected:
253 virtual ~MouseEventArgs ();
254 MouseEventArgs (Type::Kind kind, GdkEvent *event);
256 GdkEvent *event;
259 /* @Namespace=None */
260 class LogReadyRoutedEventArgs : public RoutedEventArgs {
261 public:
262 /* @GenerateCBinding,GeneratePInvoke */
263 LogReadyRoutedEventArgs ();
265 const char *GetLog () { return log; }
266 LogSource GetLogSource () { return log_source; }
268 private:
269 const char *log;
270 LogSource log_source;
273 /* @Namespace=None */
274 class MouseButtonEventArgs : public MouseEventArgs {
275 public:
276 /* @GenerateCBinding,GeneratePInvoke */
277 MouseButtonEventArgs ();
278 MouseButtonEventArgs (GdkEvent *event);
280 int GetButton ();
281 int GetClickCount ();
283 protected:
284 virtual ~MouseButtonEventArgs ();
287 /* @Namespace=None */
288 class MouseWheelEventArgs : public MouseEventArgs {
289 public:
290 /* @GenerateCBinding,GeneratePInvoke */
291 MouseWheelEventArgs ();
292 MouseWheelEventArgs (GdkEvent *event);
294 /* @GenerateCBinding,GeneratePInvoke */
295 int GetWheelDelta ();
297 protected:
298 virtual ~MouseWheelEventArgs ();
302 /* @Namespace=None,ManagedDependencyProperties=None */
303 class ErrorEventArgs : public EventArgs {
304 private:
305 MoonError *error;
306 void Initialize (Type::Kind kind, ErrorEventArgsType type, const MoonError &error, int extended_error_code, const char *extended_msg);
307 int extended_code;
308 char *extended_message;
309 ErrorEventArgsType error_type;
311 protected:
312 virtual ~ErrorEventArgs ();
313 ErrorEventArgs (Type::Kind kind, ErrorEventArgsType type, const MoonError error);
315 public:
316 ErrorEventArgs (ErrorEventArgsType type, MoonError error);
317 ErrorEventArgs (ErrorEventArgsType type, MoonError error, int extended_code, const char *extended_msg);
319 /* @GenerateCBinding,GeneratePInvoke */
320 gpointer GetMoonError () { return error; }
322 /* @GenerateCBinding,GeneratePInvoke */
323 const char *GetErrorMessage () { return error->message; }
324 /* @GenerateCBinding,GeneratePInvoke */
325 int GetErrorCode () { return error->code; }
326 /* @GenerateCBinding,GeneratePInvoke */
327 int GetErrorType () { return error_type; }
329 // To match SL behaviour we need to match SL error messages, which aren't all that helpful
330 // This is here to keep extra error information we have,
331 // but don't want to report to the user.
332 // extended_code:
333 // 3 (MEDIA_UNKNOWN_CODEC): used by playlist to determine if we should raise a MediaFailed event or just continue to play the next entry.
334 int GetExtendedCode () { return extended_code; }
335 const char *GetExtendedMessage () { return extended_message; }
338 /* @Namespace=None,ManagedDependencyProperties=None */
339 class ImageErrorEventArgs : public ErrorEventArgs {
340 public:
341 ImageErrorEventArgs (MoonError error);
343 protected:
344 virtual ~ImageErrorEventArgs ();
348 /* @Namespace=None,ManagedDependencyProperties=None */
349 class ParserErrorEventArgs : public ErrorEventArgs {
350 protected:
351 virtual ~ParserErrorEventArgs ();
353 public:
354 ParserErrorEventArgs (const char *msg, const char *file,
355 int line, int column, int error_code,
356 const char *element, const char *attribute);
358 int char_position;
359 int line_number;
360 char *xaml_file;
361 char *xml_element;
362 char *xml_attribute;
365 /* @Namespace=None */
366 class TimelineMarkerRoutedEventArgs : public RoutedEventArgs {
367 TimelineMarker *marker;
369 protected:
370 virtual ~TimelineMarkerRoutedEventArgs ();
372 public:
373 /* @GenerateCBinding,GeneratePInvoke */
374 TimelineMarkerRoutedEventArgs (TimelineMarker *marker);
376 /* @GenerateCBinding,GeneratePInvoke */
377 TimelineMarker *GetMarker () { return marker; }
380 #endif /* __EVENTARGS_H__ */