diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 9a4a750943..7121b2cc82 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -168,6 +168,7 @@ SubInclude HAIKU_TOP src tests servers app desktop_window ; SubInclude HAIKU_TOP src tests servers app event_mask ; SubInclude HAIKU_TOP src tests servers app following ; SubInclude HAIKU_TOP src tests servers app idle_test ; +SubInclude HAIKU_TOP src tests servers app lock_focus ; SubInclude HAIKU_TOP src tests servers app look_and_feel ; SubInclude HAIKU_TOP src tests servers app menu_crash ; SubInclude HAIKU_TOP src tests servers app no_pointer_history ; diff --git a/src/tests/servers/app/lock_focus/Jamfile b/src/tests/servers/app/lock_focus/Jamfile new file mode 100644 index 0000000000..49a3e884f2 --- /dev/null +++ b/src/tests/servers/app/lock_focus/Jamfile @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src tests servers app lock_focus ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +Application LockFocusTest : + LockFocusTest.cpp + : be +; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : LockFocusTest + : tests!apps ; +} diff --git a/src/tests/servers/app/lock_focus/LockFocusTest.cpp b/src/tests/servers/app/lock_focus/LockFocusTest.cpp new file mode 100644 index 0000000000..097b8235ad --- /dev/null +++ b/src/tests/servers/app/lock_focus/LockFocusTest.cpp @@ -0,0 +1,211 @@ +/* + * Copyright 2005-2007, Haiku Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ + + +#include +#include +#include +#include + +#include + + +static const uint32 kMsgUpdate = 'updt'; + + +class View : public BView { + public: + View(BRect rect); + virtual ~View(); + + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void Draw(BRect updateRect); + virtual void KeyDown(const char* bytes, int32 numBytes); + virtual void KeyUp(const char* bytes, int32 numBytes); + virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint where); + + private: + void _Update(); + + BMessageRunner* fRunner; + char fLastKey; + bool fPressed; + uint8 fLastColor; +}; + +class Window : public BWindow { + public: + Window(int32 offset = 0); + virtual ~Window(); + + virtual bool QuitRequested(); +}; + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(); +}; + + +View::View(BRect rect) + : BView(rect, "lock focus", B_FOLLOW_ALL, B_WILL_DRAW), + fRunner(NULL), + fLastKey('\0'), + fPressed(false), + fLastColor(255) +{ +} + + +View::~View() +{ +} + + +void +View::AttachedToWindow() +{ + MakeFocus(this); + + BMessage update(kMsgUpdate); + fRunner = new BMessageRunner(this, &update, 16667); + + BFont font; + font.SetSize(72); + SetFont(&font); +} + + +void +View::DetachedFromWindow() +{ + delete fRunner; + fRunner = NULL; +} + + +void +View::MouseDown(BPoint where) +{ + SetMouseEventMask(0, B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS + | B_NO_POINTER_HISTORY); + + ::Window* window = new ::Window(100); + window->Show(); +} + + +void +View::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgUpdate: + _Update(); + break; + default: + BView::MessageReceived(message); + break; + } +} + + +void +View::_Update() +{ + if (fPressed) + return; + + if (fLastColor < 255) { + fLastColor += 15; + Invalidate(); + } +} + + +void +View::KeyUp(const char* bytes, int32 numBytes) +{ + fPressed = false; +} + + +void +View::KeyDown(const char* bytes, int32 numBytes) +{ + fLastKey = bytes[0]; + fLastColor = 0; + fPressed = true; + Invalidate(); +} + + +void +View::Draw(BRect updateRect) +{ + SetHighColor(fLastColor, fLastColor, fLastColor); + DrawString(&fLastKey, 1, BPoint(20, 70)); +} + + +// #pragma mark - + + +Window::Window(int32 offset) + : BWindow(BRect(100 + offset, 100 + offset, 400 + offset, 400 + offset), + "LockFocus-Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BView *view = new View(Bounds()); + AddChild(view); +} + + +Window::~Window() +{ +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +// #pragma mark - + + +Application::Application() + : BApplication("application/x-vnd.haiku-lock_focus") +{ +} + + +void +Application::ReadyToRun(void) +{ + Window* window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char** argv) +{ + Application app; + + app.Run(); + return 0; +}