From f9bbab8848383da363df67ea3e712c222d3708f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 24 Feb 2008 11:18:52 +0000 Subject: [PATCH] * First steps towards a more flexible workspaces view handling: the workspaces view can now be any view in the hierarchy. * Added private view flag kWorkspacesViewFlag that identifies such a view - note though, that you must not remove a view before closing or hiding its window for now (and that you still need to set the kWorkspacesWindowFlag, too). * Fixed Workspaces check for valid screen coordinates; after a crash, it managed to open its window offscreen for me. * Added a ViewLayer method FindView() that finds a view with the specified flags set. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24090 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/ViewPrivate.h | 9 ++++--- src/apps/workspaces/Workspaces.cpp | 32 +++++++++++++++++++------ src/servers/app/Desktop.cpp | 12 ++++++---- src/servers/app/ServerWindow.cpp | 10 ++++---- src/servers/app/ViewLayer.cpp | 16 +++++++++++++ src/servers/app/ViewLayer.h | 1 + src/servers/app/WorkspacesLayer.cpp | 26 +++++++++++++------- 7 files changed, 79 insertions(+), 27 deletions(-) diff --git a/headers/private/interface/ViewPrivate.h b/headers/private/interface/ViewPrivate.h index e86682f7a0..79e520786c 100644 --- a/headers/private/interface/ViewPrivate.h +++ b/headers/private/interface/ViewPrivate.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006, Haiku. + * Copyright 2003-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -10,8 +10,6 @@ #define VIEW_PRIVATE_H -#include - #include #include #include @@ -20,6 +18,9 @@ const static uint32 kDeleteReplicant = 'JAHA'; +const static uint32 kWorkspacesViewFlag = 0x40000000UL; + // was/is _B_RESERVED1_ in View.h + enum { B_VIEW_FONT_BIT = 0x00000001, B_VIEW_HIGH_COLOR_BIT = 0x00000002, @@ -48,6 +49,8 @@ enum { namespace BPrivate { +class PortLink; + class ViewState { public: ViewState(); diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index e2ff554857..80f49d9243 100644 --- a/src/apps/workspaces/Workspaces.cpp +++ b/src/apps/workspaces/Workspaces.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Haiku, Inc. + * Copyright 2002-2008, Haiku, Inc. * Copyright 2002, François Revol, revol@free.fr. * This file is distributed under the terms of the MIT License. * @@ -32,7 +32,9 @@ #include #include -#include "WindowPrivate.h" +#include +#include + static const char *kWorkspacesSignature = "application/x-vnd.Be-WORK"; static const char *kWorkspacesSettingFile = "Workspace_data"; @@ -63,6 +65,7 @@ class WorkspacesView : public BView { virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); + virtual void MouseDown(BPoint where); }; class WorkspacesWindow : public BWindow { @@ -126,9 +129,10 @@ WorkspacesPreferences::WorkspacesPreferences() } // check if loaded values are valid - if (screen.Frame().right >= fWindowFrame.right - && screen.Frame().bottom >= fWindowFrame.bottom - && fWindowFrame.right > 0 && fWindowFrame.bottom > 0) + if (screen.Frame().right + 5 >= fWindowFrame.right + && screen.Frame().bottom + 5 >= fWindowFrame.bottom + && screen.Frame().left - 5 <= fWindowFrame.left + && screen.Frame().top - 5 <= fWindowFrame.top) settingsValid = true; } } @@ -200,7 +204,7 @@ WorkspacesPreferences::SetWindowFrame(BRect frame) WorkspacesView::WorkspacesView(BRect frame) - : BView(frame, "workspaces", 0, B_FOLLOW_NONE) + : BView(frame, "workspaces", B_FOLLOW_NONE, kWorkspacesViewFlag) { } @@ -231,6 +235,20 @@ WorkspacesView::MouseMoved(BPoint where, uint32 transit, } +void +WorkspacesView::MouseDown(BPoint where) +{ + int32 buttons = 0; + if (Window() != NULL && Window()->CurrentMessage() != NULL) + Window()->CurrentMessage()->FindInt32("buttons", &buttons); + + if ((buttons & B_SECONDARY_MOUSE_BUTTON) == 0) + return; + + // TODO: open menu +} + + // #pragma mark - @@ -241,7 +259,7 @@ WorkspacesWindow::WorkspacesWindow(WorkspacesPreferences *preferences) B_ALL_WORKSPACES), fPreferences(preferences) { - AddChild(new WorkspacesView(BRect(-10, -10, -5, -5))); + AddChild(new WorkspacesView(Bounds())); fPreviousFrame = Frame(); } diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 1c4941e6eb..d7452a655f 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -29,6 +29,7 @@ #include "Workspace.h" #include "WorkspacesLayer.h" +#include #include #include @@ -1598,8 +1599,11 @@ Desktop::ShowWindow(WindowLayer* window) return; } - if (WorkspacesLayer* layer = dynamic_cast(window->TopLayer())) - fWorkspacesLayer = layer; + if ((window->Flags() & kWorkspacesWindowFlag) != 0) { + // find workspaces layer in view hierarchy + fWorkspacesLayer = dynamic_cast( + window->TopLayer()->FindView(kWorkspacesViewFlag)); + } UnlockAllWindows(); @@ -1637,7 +1641,7 @@ Desktop::HideWindow(WindowLayer* window) if (fWorkspacesLayer != NULL) fWorkspacesLayer->WindowRemoved(window); - if (dynamic_cast(window->TopLayer()) != NULL) + if ((window->Flags() & kWorkspacesWindowFlag) != 0) fWorkspacesLayer = NULL; UnlockAllWindows(); diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 1ae957aa4c..49c9360d79 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -561,9 +562,10 @@ ServerWindow::_CreateLayerTree(BPrivate::LinkReceiver &link, ViewLayer **_parent ViewLayer* newLayer; - if (link.Code() == AS_LAYER_CREATE_ROOT - && (fWindowLayer->Flags() & kWorkspacesWindowFlag) != 0) { - // this is a workspaces window! + if ((fWindowLayer->Flags() & kWorkspacesWindowFlag) != 0 + && (flags & kWorkspacesViewFlag) != 0) { + // TODO: there can currently only be one of these views per desktop! + // TODO: get rid of the kWorkspacesWindowFlag newLayer = new (nothrow) WorkspacesLayer(frame, scrollingOffset, name, token, resizeMask, flags); } else { diff --git a/src/servers/app/ViewLayer.cpp b/src/servers/app/ViewLayer.cpp index 62be70cf54..00ff62b90a 100644 --- a/src/servers/app/ViewLayer.cpp +++ b/src/servers/app/ViewLayer.cpp @@ -376,6 +376,22 @@ ViewLayer::MarkAt(DrawingEngine* engine, const BPoint& where, int32 level) #endif +ViewLayer* +ViewLayer::FindView(uint32 flags) +{ + if ((Flags() & flags) == flags) + return this; + + for (ViewLayer* child = FirstChild(); child; child = child->NextSibling()) { + ViewLayer* layer = child->FindView(flags); + if (layer != NULL) + return layer; + } + + return NULL; +} + + ViewLayer* ViewLayer::ViewAt(const BPoint& where) { diff --git a/src/servers/app/ViewLayer.h b/src/servers/app/ViewLayer.h index fdf37d2442..5505ab784e 100644 --- a/src/servers/app/ViewLayer.h +++ b/src/servers/app/ViewLayer.h @@ -100,6 +100,7 @@ class ViewLayer { uint32 CountChildren(bool deep = false) const; void CollectTokensForChildren(BList* tokenMap) const; + ViewLayer* FindView(uint32 flags); ViewLayer* ViewAt(const BPoint& where); diff --git a/src/servers/app/WorkspacesLayer.cpp b/src/servers/app/WorkspacesLayer.cpp index 85a8fdc79b..2d82cc00e4 100644 --- a/src/servers/app/WorkspacesLayer.cpp +++ b/src/servers/app/WorkspacesLayer.cpp @@ -33,6 +33,7 @@ WorkspacesLayer::WorkspacesLayer(BRect frame, BPoint scrollingOffset, WorkspacesLayer::~WorkspacesLayer() { + // TODO: we actually need to tell the Desktop that we're gone } @@ -74,21 +75,25 @@ WorkspacesLayer::_WorkspaceAt(int32 i) int32 columns, rows; _GetGrid(columns, rows); - int32 width = Frame().IntegerWidth() / columns; - int32 height = Frame().IntegerHeight() / rows; + BRect frame = Bounds(); + ConvertToScreen(&frame); + + int32 width = frame.IntegerWidth() / columns; + int32 height = frame.IntegerHeight() / rows; int32 column = i % columns; int32 row = i / columns; - BRect rect(column * width, row * height, (column + 1) * width, (row + 1) * height); + BRect rect(column * width, row * height, (column + 1) * width, + (row + 1) * height); - rect.OffsetBy(Frame().LeftTop()); + rect.OffsetBy(frame.LeftTop()); // make sure there is no gap anywhere if (column == columns - 1) - rect.right = Frame().right; + rect.right = frame.right; if (row == rows - 1) - rect.bottom = Frame().bottom; + rect.bottom = frame.bottom; return rect; } @@ -288,7 +293,10 @@ WorkspacesLayer::_DarkenColor(rgb_color& color) const void WorkspacesLayer::_Invalidate() const { - BRegion region((BRect)Frame()); + BRect frame = Bounds(); + ConvertToScreen(&frame); + + BRegion region(frame); Window()->MarkContentDirty(region); } @@ -314,8 +322,8 @@ WorkspacesLayer::Draw(DrawingEngine* drawingEngine, BRegion* effectiveClipping, gridRegion.Exclude(activeRect); drawingEngine->ConstrainClippingRegion(&gridRegion); - BRect frame = Frame(); - // top ViewLayer frame is in screen coordinates + BRect frame = Bounds(); + ConvertToScreen(&frame); // horizontal lines