* 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
This commit is contained in:
Axel Dörfler 2011-02-12 18:07:20 +00:00
parent fd44ef4211
commit 41b9586a0a
2 changed files with 39 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -32,12 +32,13 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#include <BeBuild.h>
#include <Alert.h>
#include <Box.h>
#include <Catalog.h>
#include <Locale.h>
#include <MenuItem.h>
#include <MessageFilter.h>
#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());
}