2 * Copyright 2005-2007, Haiku Inc.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include <Application.h>
11 #include <MessageRunner.h>
18 static const uint32 kMsgUpdate
= 'updt';
21 class View
: public BView
{
26 virtual void AttachedToWindow();
27 virtual void DetachedFromWindow();
28 virtual void Draw(BRect updateRect
);
29 virtual void KeyDown(const char* bytes
, int32 numBytes
);
30 virtual void KeyUp(const char* bytes
, int32 numBytes
);
31 virtual void MessageReceived(BMessage
* message
);
32 virtual void MouseDown(BPoint where
);
37 BMessageRunner
* fRunner
;
43 class Window
: public BWindow
{
45 Window(int32 offset
= 0);
48 virtual bool QuitRequested();
51 class Application
: public BApplication
{
55 virtual void ReadyToRun();
59 View::View(BRect rect
)
60 : BView(rect
, "lock focus", B_FOLLOW_ALL
, B_WILL_DRAW
),
75 View::AttachedToWindow()
79 BMessage
update(kMsgUpdate
);
80 fRunner
= new BMessageRunner(this, &update
, 16667);
89 View::DetachedFromWindow()
97 View::MouseDown(BPoint where
)
99 SetMouseEventMask(0, B_LOCK_WINDOW_FOCUS
| B_SUSPEND_VIEW_FOCUS
100 | B_NO_POINTER_HISTORY
);
102 ::Window
* window
= new ::Window(100);
108 View::MessageReceived(BMessage
* message
)
110 switch (message
->what
) {
115 BView::MessageReceived(message
);
127 if (fLastColor
< 255) {
135 View::KeyUp(const char* bytes
, int32 numBytes
)
142 View::KeyDown(const char* bytes
, int32 numBytes
)
152 View::Draw(BRect updateRect
)
154 SetHighColor(fLastColor
, fLastColor
, fLastColor
);
155 DrawString(&fLastKey
, 1, BPoint(20, 70));
162 Window::Window(int32 offset
)
163 : BWindow(BRect(100 + offset
, 100 + offset
, 400 + offset
, 400 + offset
),
164 "LockFocus-Test", B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS
)
166 BView
*view
= new View(Bounds());
177 Window::QuitRequested()
179 be_app
->PostMessage(B_QUIT_REQUESTED
);
187 Application::Application()
188 : BApplication("application/x-vnd.haiku-lock_focus")
194 Application::ReadyToRun(void)
196 Window
* window
= new Window();
205 main(int argc
, char** argv
)