xref: /haiku/src/tests/kits/interface/GetMouseTest.cpp (revision 9f3bdf3d039430b5172c424def20ce5d9f7367d4)
1 #include <Application.h>
2 #include <View.h>
3 #include <Window.h>
4 
5 #include <stdio.h>
6 
7 class view : public BView {
8 public:
9 	view(BRect rect)
10 	: BView(rect, "test view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
11 	{
12 	}
13 
14 	virtual void
15 	MouseDown(BPoint where)
16 	{
17 		printf("Mouse DOWN !!! %" B_PRIdBIGTIME "\n", system_time());
18 
19 		BPoint mouseWhere;
20 		uint32 buttons;
21 		do {
22 			GetMouse(&mouseWhere, &buttons);
23 			snooze(10000);
24 		} while (buttons != 0);
25 
26 		printf("Mouse UP !!! %" B_PRIdBIGTIME "\n", system_time());
27 	}
28 };
29 
30 
31 class window : public BWindow {
32 public:
33 	window() :
34 		BWindow(BRect(100, 100, 400, 300), "test window", B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
35 	{
36 		AddChild(new view(Bounds()));
37 	}
38 
39 	virtual void
40 	DispatchMessage(BMessage *message, BHandler *handler)
41 	{
42 		bigtime_t when;
43 		message->FindInt64("when", &when);
44 		switch (message->what) {
45 			case B_MOUSE_MOVED:
46 				printf("B_MOUSE_MOVED: %" B_PRIdBIGTIME "\n", when);
47 				break;
48 			case B_MOUSE_UP:
49 				printf("B_MOUSE_UP: %" B_PRIdBIGTIME "\n", when);
50 				break;
51 			case B_MOUSE_DOWN:
52 				printf("B_MOUSE_DOWN: %" B_PRIdBIGTIME "\n", when);
53 				break;
54 			default:
55 				break;
56 		}
57 		BWindow::DispatchMessage(message, handler);
58 	}
59 };
60 
61 int
62 main()
63 {
64 	BApplication app("application/x-vnd.getmousetest");
65 
66 	(new window())->Show();
67 
68 	app.Run();
69 }
70