2 * Copyright 2005, Haiku Inc.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include <Application.h>
14 #include <TextControl.h>
20 static const uint32 kMsgPointerEvents
= 'pevt';
21 static const rgb_color kPermanentColor
= { 130, 130, 220};
22 static const rgb_color kPressedColor
= { 220, 120, 120};
25 class PositionView
: public BBox
{
27 PositionView(BRect rect
, uint32 options
);
28 virtual ~PositionView();
30 void SetPermanent(bool permanent
);
32 virtual void Draw(BRect updateRect
);
33 virtual void MouseDown(BPoint where
);
34 virtual void MouseUp(BPoint where
);
35 virtual void MouseMoved(BPoint where
, uint32 transit
, const BMessage
* dragMessage
);
44 PositionView::PositionView(BRect rect
, uint32 options
)
45 : BBox(rect
, "event mask", B_FOLLOW_ALL
, B_WILL_DRAW
),
53 PositionView::~PositionView()
59 PositionView::SetPermanent(bool permanent
)
62 SetEventMask(B_POINTER_EVENTS
, 0);
63 SetViewColor(kPermanentColor
);
66 SetViewColor(Parent()->ViewColor());
69 fPermanent
= permanent
;
71 SetLowColor(ViewColor());
77 PositionView::Draw(BRect updateRect
)
79 BBox::Draw(updateRect
);
82 if (fOptions
& B_SUSPEND_VIEW_FOCUS
) {
84 if (fOptions
& ~B_SUSPEND_VIEW_FOCUS
)
87 if (fOptions
& B_LOCK_WINDOW_FOCUS
)
92 DrawString(type
.String(), BPoint(6, 14));
96 position
<< (int32
)fPosition
.x
;
102 if (fPosition
.y
>= 0)
103 position
<< (int32
)fPosition
.y
;
107 DrawString(position
.String(), BPoint(6, 28));
112 PositionView::MouseDown(BPoint where
)
115 SetMouseEventMask(B_POINTER_EVENTS
, fOptions
);
117 SetViewColor(kPressedColor
);
118 SetLowColor(ViewColor());
125 PositionView::MouseUp(BPoint where
)
128 SetViewColor(kPermanentColor
);
130 SetViewColor(Parent()->ViewColor());
133 SetLowColor(ViewColor());
140 PositionView::MouseMoved(BPoint where
, uint32 transit
, const BMessage
* dragMessage
)
144 BRect rect
= Bounds().InsetByCopy(5, 5);
153 class Window
: public BWindow
{
158 virtual bool QuitRequested();
159 virtual void MessageReceived(BMessage
* message
);
162 PositionView
* fViews
[4];
167 : BWindow(BRect(100, 100, 590, 260), "EventMask-Test",
168 B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS
| B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
)
170 BView
* view
= new BView(Bounds(), NULL
, B_FOLLOW_ALL
, B_WILL_DRAW
);
171 view
->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
174 BTextControl
* textControl
= new BTextControl(BRect(10, 10, 290, 30),
175 "text", "Type to test focus suspending:", "", NULL
, B_FOLLOW_LEFT_RIGHT
);
176 textControl
->SetDivider(textControl
->StringWidth(textControl
->Label()) + 8);
177 view
->AddChild(textControl
);
179 textControl
= new BTextControl(BRect(300, 10, 420, 30),
180 "all", "All keys:", "", NULL
, B_FOLLOW_LEFT_RIGHT
);
181 textControl
->SetDivider(textControl
->StringWidth(textControl
->Label()) + 8);
182 view
->AddChild(textControl
);
183 textControl
->TextView()->SetEventMask(B_KEYBOARD_EVENTS
, 0);
185 BRect
rect(10, 40, 120, 120);
186 for (int32 i
= 0; i
< 4; i
++) {
190 options
= B_SUSPEND_VIEW_FOCUS
;
193 options
= B_LOCK_WINDOW_FOCUS
;
196 options
= B_SUSPEND_VIEW_FOCUS
| B_LOCK_WINDOW_FOCUS
;
200 fViews
[i
] = new PositionView(rect
, options
);
201 view
->AddChild(fViews
[i
]);
203 rect
.OffsetBy(120, 0);
206 BCheckBox
* checkBox
= new BCheckBox(BRect(10, 130, 200, 160), "permanent", "Get all pointer events", new BMessage(kMsgPointerEvents
));
207 view
->AddChild(checkBox
);
217 Window::QuitRequested()
219 be_app
->PostMessage(B_QUIT_REQUESTED
);
225 Window::MessageReceived(BMessage
* message
)
227 switch (message
->what
) {
228 case kMsgPointerEvents
:
230 bool selected
= message
->FindInt32("be:value") != 0;
232 for (int32 i
= 0; i
< 4; i
++) {
233 fViews
[i
]->SetPermanent(selected
);
239 BWindow::MessageReceived(message
);
248 class Application
: public BApplication
{
252 virtual void ReadyToRun(void);
256 Application::Application()
257 : BApplication("application/x-vnd.haiku-view_state")
263 Application::ReadyToRun(void)
265 Window
*window
= new Window();
274 main(int argc
, char **argv
)
276 Application app
;// app;