~ubuntu-branches/ubuntu/trusty/moon/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * eventargs.h
 *
 * Copyright 2007 Novell, Inc. (http://www.novell.com)
 *
 * See the LICENSE file included with the distribution for details.
 * 
 */

#ifndef __EVENTARGS_H__
#define __EVENTARGS_H__

#include <glib.h>

#include <cairo.h>
#include <gdk/gdkevents.h>
#include "dependencyobject.h"
#include "enums.h"

class StylusInfo;
class StylusPointCollection;
class UIElement;

/*
 * EventArgs needs to be ref counted since js can keep objects around until
 * after the event has been emitted.
 */

/* @Namespace=None */
class EventArgs : public DependencyObject {
 protected:
	virtual ~EventArgs () {}
	
 public:
	EventArgs () {}
	virtual Type::Kind GetObjectType () { return Type::EVENTARGS; }
};

enum CollectionChangedAction {
	CollectionChangedActionAdd,
	CollectionChangedActionRemove,
	CollectionChangedActionReplace,
	CollectionChangedActionClearing,
	CollectionChangedActionCleared,
};

/* @Namespace=None */
class CollectionChangedEventArgs : public EventArgs {
 protected:
	virtual ~CollectionChangedEventArgs () {}
	
 public:
	CollectionChangedAction action;
	Value *old_value;
	Value *new_value;
	int index;
	
	/* @GenerateCBinding,GeneratePInvoke */
	CollectionChangedEventArgs ()
	{
		action = CollectionChangedActionAdd;
		old_value = NULL;
		new_value = NULL;
		index = -1;
	}
	
	CollectionChangedEventArgs (CollectionChangedAction action, Value *new_value, Value *old_value, int index)
	{
		this->action = action;
		this->new_value = new_value;
		this->old_value = old_value;
		this->index = index;
	}
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetChangedAction (CollectionChangedAction action) { this->action = action; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	CollectionChangedAction GetChangedAction () { return action; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetNewItem (Value *item) { new_value = item; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	Value *GetNewItem () { return new_value; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetOldItem (Value *item) { old_value = item; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	Value *GetOldItem () { return old_value; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetIndex (int index) { this->index = index; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	int GetIndex () { return index; }
};

/* @Namespace=None */
class RoutedEventArgs : public EventArgs {
	DependencyObject *source;
	bool handled;
	
 protected:
	virtual ~RoutedEventArgs ();
	
 public:
 	/* @GenerateCBinding,GeneratePInvoke */
	RoutedEventArgs ();

	virtual Type::Kind GetObjectType () { return Type::ROUTEDEVENTARGS; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	DependencyObject* GetSource() { return source; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetSource(DependencyObject *el);
	
	/* @GenerateCBinding,GeneratePInvoke */
	void SetHandled (bool handled) { this->handled = handled; }
	
	/* @GenerateCBinding,GeneratePInvoke */
	bool GetHandled () { return handled; }
};

/* @Namespace=None */
class KeyEventArgs : public RoutedEventArgs {
	GdkEventKey *event;
	
 protected:
	virtual ~KeyEventArgs ();
	
 public:
 	/* @GenerateCBinding,GeneratePInvoke */
	KeyEventArgs ();
	KeyEventArgs (GdkEventKey *event);
	virtual Type::Kind GetObjectType () { return Type::KEYEVENTARGS; };
	
	int GetState ();

	/* @GenerateCBinding,GeneratePInvoke */
	int GetKey ();
	
	/* @GenerateCBinding,GeneratePInvoke */
	int GetPlatformKeyCode ();

	static int gdk_keyval_to_key (guint keyval);
};

/* @Namespace=None */
class MouseEventArgs : public RoutedEventArgs {
	GdkEvent *event;
	
 protected:
	virtual ~MouseEventArgs ();
	
 public:
 	/* @GenerateCBinding,GeneratePInvoke */
	MouseEventArgs ();
	MouseEventArgs (GdkEvent *event);
	virtual Type::Kind GetObjectType () { return Type::MOUSEEVENTARGS; };
	
	int GetState ();
	
	/* @GenerateCBinding,GeneratePInvoke */
	void GetPosition (UIElement *relative_to, double *x, double *y);
	
	StylusInfo *GetStylusInfo ();
	
	/* @GenerateCBinding,GeneratePInvoke */
	StylusPointCollection *GetStylusPoints (UIElement *ink_presenter);
};

class Keyboard {
	static ModifierKeys modifiers;
	static GHashTable* pressedKeys;

 public:
	/* @GenerateCBinding,GeneratePInvoke */
	static ModifierKeys GetModifiers ();

	static void SetModifiers (ModifierKeys m);

	static void OnKeyPress (Key key);
	static void OnKeyRelease (Key key);

	static bool IsKeyPressed (Key key);

	static Key MapKeyValToKey (guint keyval);
};

#endif /* __EVENTARGS_H__ */