Ticket #1415: TestMouse.cc

File TestMouse.cc, 2.0 KB (added by tangobravo, 17 years ago)

Small test application

Line 
1#include <TextView.h>
2#include <Application.h>
3#include <Window.h>
4#include <iostream>
5using namespace std;
6
7class MouseView : public BTextView
8{
9 public:
10 MouseView(BRect frame);
11 virtual void KeyDown(const char *bytes, int32 numBytes);
12 virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
13 virtual void MouseDown(BPoint point);
14 virtual void MouseUp(BPoint point);
15};
16
17MouseView::MouseView(BRect frame)
18 : BTextView(frame, "MouseView", frame, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
19{
20 this->SetViewColor(255, 255, 200);
21 this->SetLowColor(255, 255, 200);
22}
23
24void MouseView::KeyDown(const char *bytes, int32 numBytes)
25{
26 cout << "Started KeyDown" << endl;
27 snooze(1000000);
28 for(int i = 0; i < numBytes; i++)
29 cout << bytes[i];
30 cout << endl;
31 BTextView::KeyDown(bytes, numBytes);
32 snooze(1000000);
33 cout << "Finished KeyDown" << endl << endl;
34}
35
36void MouseView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
37{
38 cout << "Started MouseMoved" << endl;
39 snooze(1000000);
40 point.PrintToStream();
41 BTextView::MouseMoved(point, transit, message);
42 snooze(1000000);
43 cout << "Finished MouseMoved" << endl << endl;
44}
45
46void MouseView::MouseDown(BPoint point)
47{
48 cout << "Started MouseDown" << endl;
49 snooze(1000000);
50 point.PrintToStream();
51 BTextView::MouseDown(point);
52 snooze(1000000);
53 cout << "Finished MouseDown" << endl << endl;
54}
55
56void MouseView::MouseUp(BPoint point)
57{
58 cout << "Started MouseUp" << endl;
59 snooze(1000000);
60 point.PrintToStream();
61 BTextView::MouseDown(point);
62 snooze(1000000);
63 cout << "Finished MouseUp" << endl << endl;
64}
65
66int main(int argc, char** argv)
67{
68 BApplication app("application/x-vnd.Simon-TestMouse");
69
70 BWindow* wnd = new BWindow(BRect(100, 100, 400, 400), "Window", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
71 MouseView* mv = new MouseView(BRect(10, 10, 290, 290));
72 wnd->AddChild(mv);
73 wnd->Show();
74 if(wnd->LockLooper())
75 {
76 mv->MakeFocus();
77 mv->SetEventMask(0, B_NO_POINTER_HISTORY);
78 wnd->UnlockLooper();
79 }
80
81 app.Run();
82
83 return 0;
84}
85