diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 0cae1ec5d4..fb458c3c04 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -947,7 +947,8 @@ Desktop::_SetWorkspace(int32 index) bool movedMouseEventWindow = false; display_mode previousMode, newMode; fVirtualScreen.ScreenAt(0)->GetMode(&previousMode); - fVirtualScreen.RestoreConfiguration(*this, fSettings->WorkspacesMessage(index)); + fVirtualScreen.RestoreConfiguration(*this, + fSettings->WorkspacesMessage(index)); fVirtualScreen.ScreenAt(0)->GetMode(&newMode); // We only need to invalidate the entire desktop if we changed display modes if (memcmp(&previousMode, &newMode, sizeof(display_mode))) @@ -964,7 +965,8 @@ Desktop::_SetWorkspace(int32 index) _Windows(index).AddWindow(fMouseEventWindow); _Windows(previousIndex).RemoveWindow(fMouseEventWindow); - _UpdateSubsetWorkspaces(fMouseEventWindow, previousIndex, index); + _UpdateSubsetWorkspaces(fMouseEventWindow, previousIndex, + index); movedMouseEventWindow = true; // send B_WORKSPACES_CHANGED message @@ -974,11 +976,13 @@ Desktop::_SetWorkspace(int32 index) // make sure it's frontmost _Windows(index).RemoveWindow(fMouseEventWindow); _Windows(index).AddWindow(fMouseEventWindow, - fMouseEventWindow->Frontmost(_Windows(index).FirstWindow(), index)); + fMouseEventWindow->Frontmost(_Windows(index).FirstWindow(), + index)); } } - fMouseEventWindow->Anchor(index).position = fMouseEventWindow->Frame().LeftTop(); + fMouseEventWindow->Anchor(index).position + = fMouseEventWindow->Frame().LeftTop(); } // build region of windows that are no longer visible in the new workspace @@ -1832,8 +1836,14 @@ Desktop::HideWindow(Window* window) window->SetHidden(true); fFocusList.RemoveWindow(window); - if (fMouseEventWindow == window) + if (fMouseEventWindow == window) { + // Make its decorator lose the current mouse action + BMessage message; + int32 viewToken; + window->MouseUp(&message, fLastMousePosition, &viewToken); + fMouseEventWindow = NULL; + } if (window->InWorkspace(fCurrentWorkspace)) { _UpdateSubsetWorkspaces(window); @@ -2235,7 +2245,8 @@ Desktop::AddWindowToSubset(Window* subset, Window* window) if (!subset->AddToSubset(window)) return false; - _ChangeWindowWorkspaces(subset, subset->Workspaces(), subset->SubsetWorkspaces()); + _ChangeWindowWorkspaces(subset, subset->Workspaces(), + subset->SubsetWorkspaces()); return true; } @@ -2244,7 +2255,8 @@ void Desktop::RemoveWindowFromSubset(Window* subset, Window* window) { subset->RemoveFromSubset(window); - _ChangeWindowWorkspaces(subset, subset->Workspaces(), subset->SubsetWorkspaces()); + _ChangeWindowWorkspaces(subset, subset->Workspaces(), + subset->SubsetWorkspaces()); } diff --git a/src/servers/app/Window.h b/src/servers/app/Window.h index 6071193480..94ee30d957 100644 --- a/src/servers/app/Window.h +++ b/src/servers/app/Window.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2008, Haiku, Inc. + * Copyright (c) 2001-2009, Haiku, Inc. * Distributed under the terms of the MIT license. * * Authors: @@ -62,7 +62,8 @@ public: ::Desktop* Desktop() const { return fDesktop; } ::Decorator* Decorator() const { return fDecorator; } ::ServerWindow* ServerWindow() const { return fWindow; } - ::EventTarget& EventTarget() const { return fWindow->EventTarget(); } + ::EventTarget& EventTarget() const + { return fWindow->EventTarget(); } // setting and getting the "hard" clipping, you need to have // WriteLock()ed the clipping! @@ -78,7 +79,8 @@ public: void GetContentRegion(BRegion* region); void MoveBy(int32 x, int32 y); - void ResizeBy(int32 x, int32 y, BRegion* dirtyRegion); + void ResizeBy(int32 x, int32 y, + BRegion* dirtyRegion); void ScrollViewBy(View* view, int32 dx, int32 dy); @@ -88,7 +90,8 @@ public: virtual bool IsOffscreenWindow() const { return false; } - void GetEffectiveDrawingRegion(View* view, BRegion& region); + void GetEffectiveDrawingRegion(View* view, + BRegion& region); bool DrawingRegionChanged(View* view) const; // generic version, used by the Desktop @@ -131,15 +134,18 @@ public: void CopyContents(BRegion* region, int32 xOffset, int32 yOffset); - void MouseDown(BMessage* message, BPoint where, int32* _viewToken); - void MouseUp(BMessage* message, BPoint where, int32* _viewToken); - void MouseMoved(BMessage* message, BPoint where, int32* _viewToken, - bool isLatestMouseMoved); + void MouseDown(BMessage* message, BPoint where, + int32* _viewToken); + void MouseUp(BMessage* message, BPoint where, + int32* _viewToken); + void MouseMoved(BMessage* message, BPoint where, + int32* _viewToken, bool isLatestMouseMoved); // some hooks to inform the client window // TODO: move this to ServerWindow maybe? void WorkspaceActivated(int32 index, bool active); - void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); + void WorkspacesChanged(uint32 oldWorkspaces, + uint32 newWorkspaces); void Activated(bool active); // changing some properties @@ -179,7 +185,8 @@ public: void FontsChanged(BRegion* updateRegion); - void SetLook(window_look look, BRegion* updateRegion); + void SetLook(window_look look, + BRegion* updateRegion); void SetFeel(window_feel feel); void SetFlags(uint32 flags, BRegion* updateRegion); @@ -243,12 +250,13 @@ protected: void _DrawBorder(); // handling update sessions - void _TransferToUpdateSession(BRegion* contentDirtyRegion); + void _TransferToUpdateSession( + BRegion* contentDirtyRegion); void _SendUpdateMessage(); void _UpdateContentRegion(); - click_type _ActionFor(const BMessage* msg) const; + click_type _ActionFor(const BMessage* message) const; void _ObeySizeLimits(); void _PropagatePosition(); diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index 23817c880d..fc7151fbca 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -175,6 +175,7 @@ SubInclude HAIKU_TOP src tests servers app drawing_modes ; SubInclude HAIKU_TOP src tests servers app event_mask ; SubInclude HAIKU_TOP src tests servers app find_view ; SubInclude HAIKU_TOP src tests servers app following ; +SubInclude HAIKU_TOP src tests servers app hide_and_show ; SubInclude HAIKU_TOP src tests servers app idle_test ; SubInclude HAIKU_TOP src tests servers app lagging_get_mouse ; SubInclude HAIKU_TOP src tests servers app lock_focus ; diff --git a/src/tests/servers/app/hide_and_show/HideAndShow.cpp b/src/tests/servers/app/hide_and_show/HideAndShow.cpp new file mode 100644 index 0000000000..be87b66761 --- /dev/null +++ b/src/tests/servers/app/hide_and_show/HideAndShow.cpp @@ -0,0 +1,138 @@ +/* + * Copyright 2005-2009, 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 kMsgToggleShow = 'tgsh'; + +class Window : public BWindow { +public: + Window(); + virtual ~Window(); + + virtual void MessageReceived(BMessage* message); + virtual void FrameResized(float width, float height); + virtual bool QuitRequested(); + +private: + BMessageRunner* fRunner; +}; + + +Window::Window() + : BWindow(BRect(100, 100, 400, 400), "HideAndShow-Test", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BRect rect(Bounds()); + rect.left += 20; + rect.right -= 20; + rect.top = 100; + rect.bottom = 200; + BTextView* view = new BTextView(Bounds(), "", rect, B_FOLLOW_ALL, + B_FRAME_EVENTS | B_WILL_DRAW); + view->MakeEditable(false); + view->SetAlignment(B_ALIGN_CENTER); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + view->SetText("The window will be hidden and shown every 2 seconds."); + AddChild(view); + + BMessage showAndHide(kMsgToggleShow); + fRunner = new BMessageRunner(this, &showAndHide, 2000000); +} + +Window::~Window() +{ + delete fRunner; +} + + +void +Window::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgToggleShow: + if (IsHidden()) + Show(); + else + Hide(); + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + + +void +Window::FrameResized(float width, float height) +{ + BTextView* view = dynamic_cast(ChildAt(0)); + if (view == NULL) + return; + + BRect rect = Bounds(); + rect.left += 20; + rect.right -= 20; + rect.top = 100; + rect.bottom = 200; + view->SetTextRect(rect); +} + + +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-hide_and_show") +{ +} + + +void +Application::ReadyToRun(void) +{ + Window* window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char** argv) +{ + Application app; + + app.Run(); + return 0; +} diff --git a/src/tests/servers/app/hide_and_show/Jamfile b/src/tests/servers/app/hide_and_show/Jamfile new file mode 100644 index 0000000000..054a325ca2 --- /dev/null +++ b/src/tests/servers/app/hide_and_show/Jamfile @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src tests servers app hide_and_show ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +Application HideAndShow : + HideAndShow.cpp + : be +; + +if $(TARGET_PLATFORM) = libbe_test { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : ViewState + : tests!apps ; +} +