2013-06-15 00:55:05 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/thread.h>
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
DEFINE_EVENT_BEGIN(MouseMotion)
|
2013-06-15 00:55:05 +04:00
|
|
|
int x;
|
|
|
|
int y;
|
2013-06-15 21:32:13 +04:00
|
|
|
DEFINE_EVENT_END(MouseMotion)
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
DEFINE_EVENT_BEGIN(MouseButton)
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int flags;
|
|
|
|
int button;
|
|
|
|
DEFINE_EVENT_END(MouseButton)
|
2013-06-15 00:55:05 +04:00
|
|
|
|
|
|
|
void MouseMotionEventHandler(void* context, MouseMotionEventArgs* e)
|
|
|
|
{
|
|
|
|
printf("MouseMotionEvent: x: %d y: %d\n", e->x, e->y);
|
|
|
|
}
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
void MouseButtonEventHandler(void* context, MouseButtonEventArgs* e)
|
2013-06-15 00:55:05 +04:00
|
|
|
{
|
2013-06-15 21:32:13 +04:00
|
|
|
printf("MouseButtonEvent: x: %d y: %d flags: %d button: %d\n", e->x, e->y, e->flags, e->button);
|
|
|
|
}
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
static wEvent Node_Events[] =
|
2013-06-15 00:55:05 +04:00
|
|
|
{
|
2013-06-15 21:32:13 +04:00
|
|
|
DEFINE_EVENT_ENTRY(MouseMotion)
|
|
|
|
DEFINE_EVENT_ENTRY(MouseButton)
|
2013-06-15 00:55:05 +04:00
|
|
|
};
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
#define NODE_EVENT_COUNT (sizeof(Node_Events) / sizeof(wEvent))
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
/* strongly-typed wrappers could be automatically defined using a macro */
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
static INLINE int PubSub_SubscribeMouseMotion(wPubSub* pubSub, pMouseMotionEventHandler MouseMotionEventHandler)
|
2013-06-15 00:55:05 +04:00
|
|
|
{
|
2013-06-15 21:32:13 +04:00
|
|
|
return PubSub_Subscribe(pubSub, "MouseMotion", (pEventHandler) MouseMotionEventHandler);
|
2013-06-15 00:55:05 +04:00
|
|
|
}
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
static INLINE int PubSub_OnMouseMotion(wPubSub* pubSub, void* context, MouseMotionEventArgs* e)
|
2013-06-15 00:55:05 +04:00
|
|
|
{
|
2013-06-15 21:32:13 +04:00
|
|
|
return PubSub_OnEvent(pubSub, "MouseMotion", context, (wEventArgs*) e);
|
2013-06-15 00:55:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int TestPubSub(int argc, char* argv[])
|
|
|
|
{
|
2013-06-15 21:32:13 +04:00
|
|
|
wPubSub* node;
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
node = PubSub_New(TRUE);
|
2013-06-15 00:55:05 +04:00
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
PubSub_Publish(node, Node_Events, NODE_EVENT_COUNT);
|
2013-06-15 00:55:05 +04:00
|
|
|
|
|
|
|
/* Register Event Handler */
|
2013-06-15 21:32:13 +04:00
|
|
|
|
|
|
|
PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler);
|
|
|
|
PubSub_Subscribe(node, "MouseButton", (pEventHandler) MouseButtonEventHandler);
|
2013-06-15 00:55:05 +04:00
|
|
|
|
|
|
|
/* Call Event Handler */
|
|
|
|
{
|
|
|
|
MouseMotionEventArgs e;
|
|
|
|
|
|
|
|
e.x = 64;
|
|
|
|
e.y = 128;
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
PubSub_OnMouseMotion(node, NULL, &e);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MouseButtonEventArgs e;
|
|
|
|
|
|
|
|
e.x = 23;
|
|
|
|
e.y = 56;
|
|
|
|
e.flags = 7;
|
|
|
|
e.button = 1;
|
|
|
|
|
|
|
|
PubSub_OnEvent(node, "MouseButton", NULL, (wEventArgs*) &e);
|
2013-06-15 00:55:05 +04:00
|
|
|
}
|
|
|
|
|
2013-06-15 21:32:13 +04:00
|
|
|
PubSub_Free(node);
|
2013-06-15 00:55:05 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|