headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / find_view / FindView.cpp
blobf1f83d0a390c04a473867e8449a0828cffa75e39
1 /*
2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
4 */
7 #include <Application.h>
8 #include <Window.h>
9 #include <View.h>
11 #include <stdio.h>
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)
20 SetViewColor(red, green, blue);
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)
31 SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
34 virtual void MouseMoved(BPoint where, uint32 transit,
35 const BMessage* dragMessage)
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");
46 // #pragma mark -
49 int
50 main(int argc, char **argv)
52 BApplication app("application/x-vnd.haiku-find_view");
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);
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);
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);
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();
79 window->Show();
81 app.Run();
82 return 0;