2005-07-01 10:53:07 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Haiku Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
2005-11-04 18:54:16 +03:00
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
2005-07-01 10:53:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
#include "WorkspacesLayer.h"
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "AppServer.h"
|
2005-12-08 15:41:19 +03:00
|
|
|
#include "Desktop.h"
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "DrawingEngine.h"
|
2005-11-24 20:45:26 +03:00
|
|
|
#include "WindowLayer.h"
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "Workspace.h"
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
#include <ColorSet.h>
|
|
|
|
#include <WindowPrivate.h>
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
WorkspacesLayer::WorkspacesLayer(BRect frame, const char* name,
|
2005-12-08 15:41:19 +03:00
|
|
|
int32 token, uint32 resizeMode, uint32 flags)
|
|
|
|
: ViewLayer(frame, name, token, resizeMode, flags)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
2005-12-01 14:43:04 +03:00
|
|
|
fDrawState->SetLowColor(RGBColor(255, 255, 255));
|
|
|
|
fDrawState->SetHighColor(RGBColor(0, 0, 0));
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorkspacesLayer::~WorkspacesLayer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkspacesLayer::_GetGrid(int32& columns, int32& rows)
|
|
|
|
{
|
2005-11-30 18:47:01 +03:00
|
|
|
DesktopSettings settings(Window()->Desktop());
|
|
|
|
int32 count = settings.WorkspacesCount();
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
rows = 1;
|
|
|
|
for (int32 i = 2; i < count; i++) {
|
|
|
|
if (count % i == 0)
|
|
|
|
rows = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
columns = count / rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRect
|
|
|
|
WorkspacesLayer::_WorkspaceAt(int32 i)
|
|
|
|
{
|
|
|
|
int32 columns, rows;
|
|
|
|
_GetGrid(columns, rows);
|
|
|
|
|
2005-11-08 20:38:07 +03:00
|
|
|
int32 width = Frame().IntegerWidth() / columns;
|
|
|
|
int32 height = Frame().IntegerHeight() / rows;
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
int32 column = i % columns;
|
|
|
|
int32 row = i / columns;
|
|
|
|
|
|
|
|
BRect rect(column * width, row * height, (column + 1) * width, (row + 1) * height);
|
|
|
|
|
2005-12-09 19:19:18 +03:00
|
|
|
rect.OffsetBy(Frame().LeftTop());
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
// make sure there is no gap anywhere
|
|
|
|
if (column == columns - 1)
|
2005-11-08 20:38:07 +03:00
|
|
|
rect.right = Frame().right;
|
2005-07-01 10:53:07 +04:00
|
|
|
if (row == rows - 1)
|
2005-11-08 20:38:07 +03:00
|
|
|
rect.bottom = Frame().bottom;
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRect
|
|
|
|
WorkspacesLayer::_WindowFrame(const BRect& workspaceFrame,
|
2005-11-30 22:56:44 +03:00
|
|
|
const BRect& screenFrame, const BRect& windowFrame,
|
|
|
|
BPoint windowPosition)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
|
|
|
BRect frame = windowFrame;
|
2005-11-30 22:56:44 +03:00
|
|
|
frame.OffsetTo(windowPosition);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
float factor = workspaceFrame.Width() / screenFrame.Width();
|
2005-07-01 11:58:22 +04:00
|
|
|
frame.left = rintf(frame.left * factor);
|
|
|
|
frame.right = rintf(frame.right * factor);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
factor = workspaceFrame.Height() / screenFrame.Height();
|
2005-07-01 11:58:22 +04:00
|
|
|
frame.top = rintf(frame.top * factor);
|
|
|
|
frame.bottom = rintf(frame.bottom * factor);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
frame.OffsetBy(workspaceFrame.LeftTop());
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-12-08 15:41:19 +03:00
|
|
|
WorkspacesLayer::_DrawWindow(DrawingEngine* drawingEngine, const BRect& workspaceFrame,
|
2005-11-30 22:56:44 +03:00
|
|
|
const BRect& screenFrame, WindowLayer* window, BPoint windowPosition,
|
2005-07-21 15:43:11 +04:00
|
|
|
BRegion& backgroundRegion, bool active)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
2005-12-09 19:19:18 +03:00
|
|
|
if (window->Feel() == kDesktopWindowFeel || window->IsHidden())
|
2005-07-08 04:38:52 +04:00
|
|
|
return;
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
BPoint offset = window->Frame().LeftTop() - windowPosition;
|
|
|
|
BRect frame = _WindowFrame(workspaceFrame, screenFrame, window->Frame(),
|
|
|
|
windowPosition);
|
2006-02-18 12:38:42 +03:00
|
|
|
Decorator *decorator = window->Decorator();
|
|
|
|
BRect tabFrame(0, 0, 0, 0);
|
|
|
|
if (decorator != NULL)
|
|
|
|
tabFrame = decorator->TabRect();
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
tabFrame = _WindowFrame(workspaceFrame, screenFrame,
|
|
|
|
tabFrame, tabFrame.LeftTop() - offset);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
// ToDo: let decorator do this!
|
2006-02-18 12:38:42 +03:00
|
|
|
RGBColor yellow;
|
|
|
|
if (decorator != NULL)
|
|
|
|
yellow = decorator->Colors().window_tab;
|
2005-07-21 15:43:11 +04:00
|
|
|
RGBColor gray(180, 180, 180);
|
|
|
|
RGBColor white(255, 255, 255);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
_DarkenColor(yellow);
|
|
|
|
_DarkenColor(gray);
|
|
|
|
_DarkenColor(white);
|
|
|
|
}
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-07-01 11:58:22 +04:00
|
|
|
if (tabFrame.left < frame.left)
|
|
|
|
tabFrame.left = frame.left;
|
|
|
|
if (tabFrame.right >= frame.right)
|
|
|
|
tabFrame.right = frame.right - 1;
|
|
|
|
|
|
|
|
tabFrame.top = frame.top - 1;
|
|
|
|
tabFrame.bottom = frame.top - 1;
|
|
|
|
|
|
|
|
backgroundRegion.Exclude(tabFrame);
|
|
|
|
backgroundRegion.Exclude(frame);
|
|
|
|
|
2006-02-18 12:38:42 +03:00
|
|
|
if (decorator != NULL)
|
|
|
|
drawingEngine->StrokeLine(tabFrame.LeftTop(), tabFrame.RightBottom(), yellow);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeRect(frame, gray);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
|
|
|
frame.InsetBy(1, 1);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->FillRect(frame, white);
|
2005-12-01 14:43:04 +03:00
|
|
|
|
|
|
|
// draw title
|
|
|
|
|
|
|
|
// TODO: disabled because it's much too slow this way - the mini-window
|
|
|
|
// functionality should probably be moved into the WindowLayer class,
|
|
|
|
// so that it has only to be recalculated on demand. With double buffered
|
|
|
|
// windows, this would also open up the door to have a more detailed
|
|
|
|
// preview.
|
|
|
|
#if 0
|
|
|
|
BString title = window->Name();
|
|
|
|
|
|
|
|
ServerFont font = fDrawState->Font();
|
|
|
|
font.SetSize(7);
|
|
|
|
fDrawState->SetFont(font);
|
|
|
|
|
|
|
|
fDrawState->Font().TruncateString(&title, B_TRUNCATE_END, frame.Width() - 4);
|
|
|
|
float width = GetDrawingEngine()->StringWidth(title.String(), title.Length(),
|
|
|
|
fDrawState, NULL);
|
|
|
|
float height = GetDrawingEngine()->StringHeight(title.String(), title.Length(),
|
|
|
|
fDrawState);
|
|
|
|
|
|
|
|
GetDrawingEngine()->DrawString(title.String(), title.Length(),
|
|
|
|
BPoint(frame.left + (frame.Width() - width) / 2,
|
|
|
|
frame.top + (frame.Height() + height) / 2),
|
|
|
|
fDrawState, NULL);
|
|
|
|
#endif
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-12-09 18:39:20 +03:00
|
|
|
WorkspacesLayer::_DrawWorkspace(DrawingEngine* drawingEngine,
|
|
|
|
BRegion& redraw, int32 index)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
|
|
|
BRect rect = _WorkspaceAt(index);
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
Workspace workspace(*Window()->Desktop(), index);
|
|
|
|
bool active = workspace.IsCurrent();
|
2005-07-21 15:43:11 +04:00
|
|
|
if (active) {
|
2005-07-01 10:53:07 +04:00
|
|
|
// draw active frame
|
|
|
|
RGBColor black(0, 0, 0);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeRect(rect, black);
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rect.InsetBy(1, 1);
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
RGBColor color = workspace.Color();
|
|
|
|
if (!active)
|
2005-07-21 15:43:11 +04:00
|
|
|
_DarkenColor(color);
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
// draw windows
|
|
|
|
|
2005-12-09 18:39:20 +03:00
|
|
|
BRegion backgroundRegion = redraw;
|
2005-11-07 22:01:12 +03:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
// ToDo: would be nice to get the real update region here
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
uint16 width, height;
|
|
|
|
uint32 colorSpace;
|
|
|
|
float frequency;
|
|
|
|
Window()->Desktop()->ScreenAt(0)->GetMode(width, height,
|
|
|
|
colorSpace, frequency);
|
|
|
|
BRect screenFrame(0, 0, width - 1, height - 1);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
BRegion workspaceRegion(rect);
|
|
|
|
backgroundRegion.IntersectWith(&workspaceRegion);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->ConstrainClippingRegion(&backgroundRegion);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
WindowLayer* window;
|
|
|
|
BPoint leftTop;
|
|
|
|
while (workspace.GetNextWindow(window, leftTop) == B_OK) {
|
2005-12-08 15:41:19 +03:00
|
|
|
_DrawWindow(drawingEngine, rect, screenFrame, window,
|
|
|
|
leftTop, backgroundRegion, active);
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
2005-07-01 11:58:22 +04:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
// draw background
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->ConstrainClippingRegion(&backgroundRegion);
|
|
|
|
drawingEngine->FillRect(rect, color);
|
2005-07-02 14:37:53 +04:00
|
|
|
|
2005-12-09 18:39:20 +03:00
|
|
|
drawingEngine->ConstrainClippingRegion(&redraw);
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-21 15:43:11 +04:00
|
|
|
void
|
|
|
|
WorkspacesLayer::_DarkenColor(RGBColor& color) const
|
|
|
|
{
|
|
|
|
color = tint_color(color.GetColor32(), B_DARKEN_2_TINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
void
|
2005-12-08 15:41:19 +03:00
|
|
|
WorkspacesLayer::Draw(DrawingEngine* drawingEngine, BRegion* effectiveClipping,
|
|
|
|
BRegion* windowContentClipping, bool deep)
|
2005-07-01 10:53:07 +04:00
|
|
|
{
|
2005-12-09 18:39:20 +03:00
|
|
|
// we can only draw within our own area
|
|
|
|
BRegion redraw(ScreenClipping(windowContentClipping));
|
|
|
|
// add the current clipping
|
|
|
|
redraw.IntersectWith(effectiveClipping);
|
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
int32 columns, rows;
|
|
|
|
_GetGrid(columns, rows);
|
|
|
|
|
|
|
|
// draw grid
|
2005-12-01 13:41:01 +03:00
|
|
|
|
|
|
|
// make sure the grid around the active workspace is not drawn
|
|
|
|
// to reduce flicker
|
|
|
|
BRect activeRect = _WorkspaceAt(Window()->Desktop()->CurrentWorkspace());
|
2005-12-09 18:39:20 +03:00
|
|
|
BRegion gridRegion(redraw);
|
2005-12-01 13:41:01 +03:00
|
|
|
gridRegion.Exclude(activeRect);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->ConstrainClippingRegion(&gridRegion);
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-08 20:38:07 +03:00
|
|
|
BRect frame = Frame();
|
2005-12-09 18:39:20 +03:00
|
|
|
// top ViewLayer frame is in screen coordinates
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-12-01 13:41:01 +03:00
|
|
|
// horizontal lines
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeLine(BPoint(frame.left, frame.top),
|
2005-07-01 10:53:07 +04:00
|
|
|
BPoint(frame.right, frame.top), ViewColor());
|
|
|
|
|
|
|
|
for (int32 row = 0; row < rows; row++) {
|
|
|
|
BRect rect = _WorkspaceAt(row * columns);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeLine(BPoint(frame.left, rect.bottom),
|
2005-07-01 10:53:07 +04:00
|
|
|
BPoint(frame.right, rect.bottom), ViewColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
// vertical lines
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeLine(BPoint(frame.left, frame.top),
|
2005-07-01 10:53:07 +04:00
|
|
|
BPoint(frame.left, frame.bottom), ViewColor());
|
|
|
|
|
|
|
|
for (int32 column = 0; column < columns; column++) {
|
|
|
|
BRect rect = _WorkspaceAt(column);
|
2005-12-08 15:41:19 +03:00
|
|
|
drawingEngine->StrokeLine(BPoint(rect.right, frame.top),
|
2005-07-01 10:53:07 +04:00
|
|
|
BPoint(rect.right, frame.bottom), ViewColor());
|
|
|
|
}
|
|
|
|
|
2005-12-09 18:39:20 +03:00
|
|
|
drawingEngine->ConstrainClippingRegion(&redraw);
|
2005-12-01 13:41:01 +03:00
|
|
|
|
2005-07-01 10:53:07 +04:00
|
|
|
// draw workspaces
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
for (int32 i = rows * columns; i-- > 0;) {
|
2005-12-09 18:39:20 +03:00
|
|
|
_DrawWorkspace(drawingEngine, redraw, i);
|
2005-11-30 18:47:01 +03:00
|
|
|
}
|
2005-11-30 22:56:44 +03:00
|
|
|
}
|
2005-07-01 10:53:07 +04:00
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
|
|
|
|
void
|
2005-12-09 20:25:32 +03:00
|
|
|
WorkspacesLayer::MouseDown(BMessage* message, BPoint where)
|
2005-11-30 22:56:44 +03:00
|
|
|
{
|
|
|
|
int32 columns, rows;
|
|
|
|
_GetGrid(columns, rows);
|
|
|
|
|
|
|
|
for (int32 i = columns * rows; i-- > 0;) {
|
|
|
|
BRect rect = _WorkspaceAt(i);
|
|
|
|
|
|
|
|
if (rect.Contains(where)) {
|
|
|
|
Window()->Desktop()->SetWorkspace(i);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
2005-11-30 22:56:44 +03:00
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
//ViewLayer::MouseDown(message, where, _viewToken);
|
2005-07-01 10:53:07 +04:00
|
|
|
}
|
|
|
|
|
2005-11-30 22:56:44 +03:00
|
|
|
|
2005-12-09 19:19:18 +03:00
|
|
|
void
|
|
|
|
WorkspacesLayer::WindowChanged(WindowLayer* window)
|
|
|
|
{
|
|
|
|
// TODO: be smarter about this!
|
|
|
|
BRegion region(Frame());
|
|
|
|
Window()->MarkContentDirty(region);
|
|
|
|
}
|
|
|
|
|