From fc505229371054798da3d607d645e331b44aac9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 17 Nov 2005 11:01:42 +0000 Subject: [PATCH] Added a small test application to see how event masks are working. Notice the doubled key events in case the upper right BTextControl with B_KEYBOARD_EVENTS has focus in BeOS... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14982 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/servers/app/Jamfile | 1 + .../servers/app/event_mask/EventMask.cpp | 280 ++++++++++++++++++ src/tests/servers/app/event_mask/Jamfile | 18 ++ 3 files changed, 299 insertions(+) create mode 100644 src/tests/servers/app/event_mask/EventMask.cpp create mode 100644 src/tests/servers/app/event_mask/Jamfile diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 12ccfb52b6..6c4ffacbd6 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 SubInclude HAIKU_TOP src tests servers app bitmap_drawing ; SubInclude HAIKU_TOP src tests servers app copy_bits ; +SubInclude HAIKU_TOP src tests servers app event_mask ; SubInclude HAIKU_TOP src tests servers app painter ; SubInclude HAIKU_TOP src tests servers app playground ; SubInclude HAIKU_TOP src tests servers app resize_limits ; diff --git a/src/tests/servers/app/event_mask/EventMask.cpp b/src/tests/servers/app/event_mask/EventMask.cpp new file mode 100644 index 0000000000..e1da8b076a --- /dev/null +++ b/src/tests/servers/app/event_mask/EventMask.cpp @@ -0,0 +1,280 @@ +/* + * 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 + +#include + + +static const uint32 kMsgPointerEvents = 'pevt'; +static const rgb_color kPermanentColor = { 130, 130, 220}; +static const rgb_color kPressedColor = { 220, 120, 120}; + + +class PositionView : public BBox { + public: + PositionView(BRect rect, uint32 options); + virtual ~PositionView(); + + void SetPermanent(bool permanent); + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); + + private: + bool fPermanent; + uint32 fOptions; + BPoint fPosition; +}; + + +PositionView::PositionView(BRect rect, uint32 options) + : BBox(rect, "event mask", B_FOLLOW_ALL, B_WILL_DRAW), + fPermanent(false), + fOptions(options), + fPosition(-1, -1) +{ +} + + +PositionView::~PositionView() +{ +} + + +void +PositionView::SetPermanent(bool permanent) +{ + if (permanent) { + SetEventMask(B_POINTER_EVENTS, 0); + SetViewColor(kPermanentColor); + } else { + SetEventMask(0, 0); + SetViewColor(Parent()->ViewColor()); + } + + fPermanent = permanent; + + SetLowColor(ViewColor()); + Invalidate(); +} + + +void +PositionView::Draw(BRect updateRect) +{ + BBox::Draw(updateRect); + + BString type; + if (fOptions & B_SUSPEND_VIEW_FOCUS) { + type << "suspend"; + if (fOptions & ~B_SUSPEND_VIEW_FOCUS) + type << " & "; + } + if (fOptions & B_LOCK_WINDOW_FOCUS) + type << "lock"; + if (fOptions == 0) + type << "none"; + + DrawString(type.String(), BPoint(6, 14)); + + BString position; + if (fPosition.x >= 0) + position << (int32)fPosition.x; + else + position << "-"; + + position << " : "; + + if (fPosition.y >= 0) + position << (int32)fPosition.y; + else + position << "-"; + + DrawString(position.String(), BPoint(6, 28)); +} + + +void +PositionView::MouseDown(BPoint where) +{ + if (fOptions != 0) + SetMouseEventMask(B_POINTER_EVENTS, fOptions); + + SetViewColor(kPressedColor); + SetLowColor(ViewColor()); + fPosition = where; + Invalidate(); +} + + +void +PositionView::MouseUp(BPoint where) +{ + if (fPermanent) { + SetViewColor(kPermanentColor); + } else { + SetViewColor(Parent()->ViewColor()); + } + + SetLowColor(ViewColor()); + fPosition = where; + Invalidate(); +} + + +void +PositionView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) +{ + fPosition = where; + + BRect rect = Bounds().InsetByCopy(5, 5); + rect.bottom = 33; + Invalidate(rect); +} + + +// #pragma mark - + + +class Window : public BWindow { + public: + Window(); + virtual ~Window(); + + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage* message); + + private: + PositionView* fViews[4]; +}; + + +Window::Window() + : BWindow(BRect(100, 100, 590, 260), "EventMask-Test", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +{ + BView* view = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); + + BTextControl* textControl = new BTextControl(BRect(10, 10, 290, 30), + "text", "Type to test focus suspending:", "", NULL, B_FOLLOW_LEFT_RIGHT); + textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 8); + view->AddChild(textControl); + + textControl = new BTextControl(BRect(300, 10, 420, 30), + "all", "All keys:", "", NULL, B_FOLLOW_LEFT_RIGHT); + textControl->SetDivider(textControl->StringWidth(textControl->Label()) + 8); + view->AddChild(textControl); + textControl->TextView()->SetEventMask(B_KEYBOARD_EVENTS, 0); + + BRect rect(10, 40, 120, 120); + for (int32 i = 0; i < 4; i++) { + uint32 options = 0; + switch (i) { + case 1: + options = B_SUSPEND_VIEW_FOCUS; + break; + case 2: + options = B_LOCK_WINDOW_FOCUS; + break; + case 3: + options = B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS; + break; + } + + fViews[i] = new PositionView(rect, options); + view->AddChild(fViews[i]); + + rect.OffsetBy(120, 0); + } + + BCheckBox* checkBox = new BCheckBox(BRect(10, 130, 200, 160), "permanent", "Get all pointer events", new BMessage(kMsgPointerEvents)); + view->AddChild(checkBox); +} + + +Window::~Window() +{ +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +void +Window::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgPointerEvents: + { + bool selected = message->FindInt32("be:value") != 0; + + for (int32 i = 0; i < 4; i++) { + fViews[i]->SetPermanent(selected); + } + break; + } + + default: + BWindow::MessageReceived(message); + break; + } +} + + +// #pragma mark - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(void); +}; + + +Application::Application() + : BApplication("application/x-vnd.haiku-view_state") +{ +} + + +void +Application::ReadyToRun(void) +{ + Window *window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char **argv) +{ + Application app;// app; + + app.Run(); + return 0; +} diff --git a/src/tests/servers/app/event_mask/Jamfile b/src/tests/servers/app/event_mask/Jamfile new file mode 100644 index 0000000000..438067f73d --- /dev/null +++ b/src/tests/servers/app/event_mask/Jamfile @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src tests servers app event_mask ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +Application EventMask : + EventMask.cpp + : be +; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : EventMask + : tests!apps ; +} +