diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 96d3a98ee5..6e81f0b65e 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -137,6 +137,7 @@ HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : haiku_app_server } # if $(TARGET_PLATFORM) = libbe_test +SubInclude HAIKU_TOP src tests servers app avoid_focus ; SubInclude HAIKU_TOP src tests servers app bitmap_drawing ; SubInclude HAIKU_TOP src tests servers app code_to_name ; SubInclude HAIKU_TOP src tests servers app copy_bits ; diff --git a/src/tests/servers/app/avoid_focus/AvoidFocus.cpp b/src/tests/servers/app/avoid_focus/AvoidFocus.cpp new file mode 100644 index 0000000000..c9fc90d1d3 --- /dev/null +++ b/src/tests/servers/app/avoid_focus/AvoidFocus.cpp @@ -0,0 +1,207 @@ +/* + * Copyright 2005, Haiku Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ + + +#include +#include +#include + +#include +#include +#include + + +bool gAvoid = true; + + +class View : public BView { + public: + View(BRect rect); + virtual ~View(); + + virtual void AttachedToWindow(); + + virtual void KeyDown(const char* bytes, int32 numBytes); + virtual void KeyUp(const char* bytes, int32 numBytes); + + virtual void MouseDown(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); + + virtual void Draw(BRect updateRect); + virtual void Pulse(); + + private: + BString fChar; + bool fPressed; +}; + + +View::View(BRect rect) + : BView(rect, "desktop view", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED) +{ + SetViewColor(255, 255, 255); + SetHighColor(0, 0, 0); + SetLowColor(ViewColor()); +} + + +View::~View() +{ +} + + +void +View::AttachedToWindow() +{ + MakeFocus(true); + KeyDown("<>", 2); + fPressed = false; +} + + +void +View::KeyDown(const char* bytes, int32 numBytes) +{ + fChar = bytes; + fPressed = true; + SetHighColor(0, 0, 0); + Window()->SetPulseRate(200000); + Invalidate(); +} + + +void +View::KeyUp(const char* bytes, int32 numBytes) +{ + fPressed = false; + Invalidate(); +} + + +void +View::MouseDown(BPoint where) +{ + SetHighColor(0, 250, 0); + Invalidate(); + Window()->SetPulseRate(150000); +} + + +void +View::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) +{ + SetHighColor(0, 0, 150); + Invalidate(); + Window()->SetPulseRate(10000); +} + + +void +View::Draw(BRect updateRect) +{ + BFont font; + font.SetSize(200); + + font_height fontHeight; + font.GetHeight(&fontHeight); + + SetFont(&font); + MovePenTo(20, ceilf(20 + fontHeight.ascent)); + + DrawString(fChar.String()); +} + + +void +View::Pulse() +{ + if (fPressed) + return; + + rgb_color color = HighColor(); + SetHighColor(tint_color(color, B_LIGHTEN_2_TINT)); + Invalidate(); + + if (color.red > 253) + Window()->SetPulseRate(0); +} + + +// #pragma mark - + + +class Window : public BWindow { + public: + Window(); + virtual ~Window(); + + virtual bool QuitRequested(); +}; + + +Window::Window() + : BWindow(BRect(100, 100, 400, 400), "AvoidFocus-Test", + B_TITLED_WINDOW, (gAvoid ? B_AVOID_FOCUS : 0) | 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 - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(); +}; + + +Application::Application() + : BApplication("application/x-vnd.haiku-avoid_focus") +{ +} + + +void +Application::ReadyToRun() +{ + Window *window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char **argv) +{ + if (argc > 1 && (!strcmp(argv[1], "false") || (isdigit(argv[1][0]) && atoi(argv[1]) == 0))) + gAvoid = false; + + Application app; + + app.Run(); + return 0; +} diff --git a/src/tests/servers/app/avoid_focus/Jamfile b/src/tests/servers/app/avoid_focus/Jamfile new file mode 100644 index 0000000000..7e1620b3e7 --- /dev/null +++ b/src/tests/servers/app/avoid_focus/Jamfile @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src tests servers app avoid_focus ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +Application AvoidFocus : + AvoidFocus.cpp + : be +; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : AvoidFocus + : tests!apps ; +} +