xref: /haiku/src/tests/servers/app/find_view/FindView.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*
2  * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <Application.h>
8 #include <Window.h>
9 #include <View.h>
10 
11 #include <stdio.h>
12 
13 
14 class View : public BView {
15 public:
16 	View(BRect rect, const char* name, uint32 followMode,
17 			uint8 red, uint8 green, uint8 blue)
18 		: BView(rect, name, followMode, 0)
19 	{
20 		SetViewColor(red, green, blue);
21 	}
22 };
23 
24 
25 class TestView : public View {
26 public:
27 	TestView(BRect rect, const char* name, uint32 followMode,
28 			uint8 red, uint8 green, uint8 blue)
29 		: View(rect, name, followMode, red, green, blue)
30 	{
31 		SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
32 	}
33 
34 	virtual	void MouseMoved(BPoint where, uint32 transit,
35 			const BMessage* dragMessage)
36 	{
37 		ConvertToScreen(&where);
38 		where -= Window()->Frame().LeftTop();
39 		BView* view = Window()->FindView(where);
40 		printf("View at (%.1f, %.1f): %s\n", where.x, where.y,
41 			view ? view->Name() : "NULL");
42 	}
43 };
44 
45 
46 //	#pragma mark -
47 
48 
49 int
50 main(int argc, char **argv)
51 {
52 	BApplication app("application/x-vnd.haiku-find_view");
53 
54 	BWindow* window = new BWindow(BRect(100, 100, 400, 400),
55 		"ViewTransit-Test", B_TITLED_WINDOW,
56 		B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
57 
58 	// TestView
59 	BRect frame = window->Bounds();
60 	View* testView = new TestView(frame, "Test View", B_FOLLOW_ALL, 255, 0, 0);
61 	window->AddChild(testView);
62 
63 	// View 1
64 	frame.InsetBy(20, 20);
65 	frame.right /= 2;
66 	View* view1 = new View(frame, "View 1",
67 		B_FOLLOW_TOP_BOTTOM | B_FOLLOW_RIGHT, 0, 255, 0);
68 	testView->AddChild(view1);
69 
70 	// View 2
71 	frame.left = frame.right + 1;
72 	frame.right = window->Bounds().right - 20;
73 	View* view2 = new View(frame, "View 2",
74 		B_FOLLOW_TOP_BOTTOM | B_FOLLOW_RIGHT, 0, 0, 255);
75 	testView->AddChild(view2);
76 	view2->Hide();
77 
78 
79 	window->Show();
80 
81 	app.Run();
82 	return 0;
83 }
84