From 41b9586a0a2c858320676b5a092b01530a3099d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 12 Feb 2011 18:07:20 +0000 Subject: [PATCH] * Let SelectionWindow::MoveCloseToMouse() also take the current workspace into account. This fixes bug #7211. * Also, don't move it that close to the border of the screen (it now keeps an offset of 20 pixels). * Always move the selection window to the mouse position, even if it's already on screen. * Close the window when pressing the escape key. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40464 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/tracker/ContainerWindow.cpp | 7 +++-- src/kits/tracker/SelectionWindow.cpp | 41 ++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index b2692d4e90..2888ca0c10 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -3827,10 +3827,11 @@ BContainerWindow::ShowSelectionWindow() fSelectionWindow = new SelectionWindow(this); fSelectionWindow->Show(); } else if (fSelectionWindow->Lock()) { - if (fSelectionWindow->IsHidden()) { - fSelectionWindow->MoveCloseToMouse(); + // The window is already there, just bring it close + fSelectionWindow->MoveCloseToMouse(); + if (fSelectionWindow->IsHidden()) fSelectionWindow->Show(); - } + fSelectionWindow->Unlock(); } } diff --git a/src/kits/tracker/SelectionWindow.cpp b/src/kits/tracker/SelectionWindow.cpp index 9d85cb65ae..23bd1daa6a 100644 --- a/src/kits/tracker/SelectionWindow.cpp +++ b/src/kits/tracker/SelectionWindow.cpp @@ -32,12 +32,13 @@ names are registered trademarks or trademarks of their respective holders. All rights reserved. */ -#include + #include #include #include #include #include +#include #include "AutoLock.h" #include "ContainerWindow.h" @@ -45,13 +46,14 @@ All rights reserved. #include "Screen.h" #include "SelectionWindow.h" -const int frameThickness = 9; const uint32 kSelectButtonPressed = 'sbpr'; + #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "SelectionWindow" + SelectionWindow::SelectionWindow(BContainerWindow* window) : BWindow(BRect(0, 0, 270, 0), B_TRANSLATE("Select"), B_TITLED_WINDOW, @@ -147,6 +149,32 @@ SelectionWindow::SelectionWindow(BContainerWindow* window) B_TRANSLATE("Name matches wildcard expression:###")); float minWidth = bottomMinWidth > topMinWidth ? bottomMinWidth : topMinWidth; + class EscapeFilter : public BMessageFilter { + public: + EscapeFilter(BWindow* target) + : + BMessageFilter(B_KEY_DOWN), + fTarget(target) + { + } + + virtual filter_result Filter(BMessage* message, BHandler** _target) + { + int8 byte; + if (message->what == B_KEY_DOWN + && message->FindInt8("byte", &byte) == B_OK + && byte == B_ESCAPE) { + fTarget->Hide(); + return B_SKIP_MESSAGE; + } + return B_DISPATCH_MESSAGE; + } + + private: + BWindow* fTarget; + }; + AddCommonFilter(new(std::nothrow) EscapeFilter(this)); + Run(); Lock(); @@ -154,7 +182,7 @@ SelectionWindow::SelectionWindow(BContainerWindow* window) SetSizeLimits(minWidth, 1280, Bounds().bottom, Bounds().bottom); - MoveCloseToMouse(); + MoveCloseToMouse(); Unlock(); } @@ -212,12 +240,13 @@ SelectionWindow::MoveCloseToMouse() // ... unless that's outside of the current screen size: BScreen screen; - windowPosition.x = MAX(0, MIN(screen.Frame().right - Frame().Width(), + windowPosition.x = MAX(20, MIN(screen.Frame().right - 20 - Frame().Width(), windowPosition.x)); - windowPosition.y = MAX(0, MIN(screen.Frame().bottom - Frame().Height(), - windowPosition.y)); + windowPosition.y = MAX(20, + MIN(screen.Frame().bottom - 20 - Frame().Height(), windowPosition.y)); MoveTo(windowPosition); + SetWorkspaces(1UL << current_workspace()); }