* 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
This commit is contained in:
@@ -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 <PortLink.h>
|
||||
|
||||
#include <Font.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Point.h>
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007, Haiku, Inc.
|
||||
* Copyright 2002-2008, Haiku, Inc.
|
||||
* Copyright 2002, François Revol, [email protected].
|
||||
* This file is distributed under the terms of the MIT License.
|
||||
*
|
||||
@@ -32,7 +32,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "WindowPrivate.h"
|
||||
#include <ViewPrivate.h>
|
||||
#include <WindowPrivate.h>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <ViewPrivate.h>
|
||||
#include <WindowInfo.h>
|
||||
#include <ServerProtocol.h>
|
||||
|
||||
@@ -1598,8 +1599,11 @@ Desktop::ShowWindow(WindowLayer* window)
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorkspacesLayer* layer = dynamic_cast<WorkspacesLayer*>(window->TopLayer()))
|
||||
fWorkspacesLayer = layer;
|
||||
if ((window->Flags() & kWorkspacesWindowFlag) != 0) {
|
||||
// find workspaces layer in view hierarchy
|
||||
fWorkspacesLayer = dynamic_cast<WorkspacesLayer*>(
|
||||
window->TopLayer()->FindView(kWorkspacesViewFlag));
|
||||
}
|
||||
|
||||
UnlockAllWindows();
|
||||
|
||||
@@ -1637,7 +1641,7 @@ Desktop::HideWindow(WindowLayer* window)
|
||||
if (fWorkspacesLayer != NULL)
|
||||
fWorkspacesLayer->WindowRemoved(window);
|
||||
|
||||
if (dynamic_cast<WorkspacesLayer*>(window->TopLayer()) != NULL)
|
||||
if ((window->Flags() & kWorkspacesWindowFlag) != 0)
|
||||
fWorkspacesLayer = NULL;
|
||||
|
||||
UnlockAllWindows();
|
||||
|
||||
@@ -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 <DirectWindowPrivate.h>
|
||||
#include <MessagePrivate.h>
|
||||
#include <PortLink.h>
|
||||
#include <ViewPrivate.h>
|
||||
#include <WindowInfo.h>
|
||||
#include <WindowPrivate.h>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user