2005-12-08 15:41:19 +03:00
|
|
|
/*
|
2008-03-08 15:45:54 +03:00
|
|
|
* Copyright (c) 2005-2008, Haiku, Inc.
|
2005-12-08 15:41:19 +03:00
|
|
|
* Distributed under the terms of the MIT license.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-12-09 16:17:43 +03:00
|
|
|
#include "DesktopSettings.h"
|
2008-03-08 15:45:54 +03:00
|
|
|
#include "Window.h"
|
2005-12-08 15:41:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
const BPoint kInvalidWindowPosition = BPoint(INFINITY, INFINITY);
|
|
|
|
|
|
|
|
|
|
|
|
window_anchor::window_anchor()
|
|
|
|
:
|
|
|
|
next(NULL),
|
|
|
|
previous(NULL),
|
|
|
|
position(kInvalidWindowPosition)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
WindowList::WindowList(int32 index)
|
|
|
|
:
|
|
|
|
fIndex(index),
|
|
|
|
fFirstWindow(NULL),
|
|
|
|
fLastWindow(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WindowList::~WindowList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
WindowList::SetIndex(int32 index)
|
|
|
|
{
|
|
|
|
fIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-16 00:33:12 +03:00
|
|
|
/*!
|
|
|
|
Adds the \a window to the end of the list. If \a before is
|
|
|
|
given, it will be inserted right before that window.
|
|
|
|
*/
|
2005-12-08 15:41:19 +03:00
|
|
|
void
|
2008-03-08 15:45:54 +03:00
|
|
|
WindowList::AddWindow(Window* window, Window* before)
|
2005-12-08 15:41:19 +03:00
|
|
|
{
|
|
|
|
window_anchor& windowAnchor = window->Anchor(fIndex);
|
|
|
|
|
|
|
|
if (before != NULL) {
|
|
|
|
window_anchor& beforeAnchor = before->Anchor(fIndex);
|
|
|
|
|
|
|
|
// add view before this one
|
|
|
|
windowAnchor.next = before;
|
|
|
|
windowAnchor.previous = beforeAnchor.previous;
|
|
|
|
if (windowAnchor.previous != NULL)
|
|
|
|
windowAnchor.previous->Anchor(fIndex).next = window;
|
|
|
|
|
|
|
|
beforeAnchor.previous = window;
|
|
|
|
if (fFirstWindow == before)
|
|
|
|
fFirstWindow = window;
|
|
|
|
} else {
|
|
|
|
// add view to the end of the list
|
|
|
|
if (fLastWindow != NULL) {
|
|
|
|
fLastWindow->Anchor(fIndex).next = window;
|
|
|
|
windowAnchor.previous = fLastWindow;
|
|
|
|
} else {
|
|
|
|
fFirstWindow = window;
|
|
|
|
windowAnchor.previous = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
windowAnchor.next = NULL;
|
|
|
|
fLastWindow = window;
|
|
|
|
}
|
2005-12-09 16:17:43 +03:00
|
|
|
|
|
|
|
if (fIndex < kMaxWorkspaces)
|
|
|
|
window->SetWorkspaces(window->Workspaces() | (1UL << fIndex));
|
2005-12-08 15:41:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2008-03-08 15:45:54 +03:00
|
|
|
WindowList::RemoveWindow(Window* window)
|
2005-12-08 15:41:19 +03:00
|
|
|
{
|
|
|
|
window_anchor& windowAnchor = window->Anchor(fIndex);
|
|
|
|
|
|
|
|
if (fFirstWindow == window) {
|
|
|
|
// it's the first child
|
|
|
|
fFirstWindow = windowAnchor.next;
|
|
|
|
} else {
|
2005-12-08 16:32:54 +03:00
|
|
|
// it must have a previous sibling, then
|
|
|
|
windowAnchor.previous->Anchor(fIndex).next = windowAnchor.next;
|
2005-12-08 15:41:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fLastWindow == window) {
|
|
|
|
// it's the last child
|
|
|
|
fLastWindow = windowAnchor.previous;
|
|
|
|
} else {
|
2005-12-08 16:32:54 +03:00
|
|
|
// then it must have a next sibling
|
|
|
|
windowAnchor.next->Anchor(fIndex).previous = windowAnchor.previous;
|
2005-12-08 15:41:19 +03:00
|
|
|
}
|
|
|
|
|
2005-12-09 16:17:43 +03:00
|
|
|
if (fIndex < kMaxWorkspaces)
|
|
|
|
window->SetWorkspaces(window->Workspaces() & ~(1UL << fIndex));
|
|
|
|
|
2005-12-08 15:41:19 +03:00
|
|
|
windowAnchor.previous = NULL;
|
|
|
|
windowAnchor.next = NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-09 16:17:43 +03:00
|
|
|
|
|
|
|
bool
|
2008-03-08 15:45:54 +03:00
|
|
|
WindowList::HasWindow(Window* window) const
|
2005-12-09 16:17:43 +03:00
|
|
|
{
|
|
|
|
if (window == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return window->Anchor(fIndex).next != NULL
|
|
|
|
|| window->Anchor(fIndex).previous != NULL
|
|
|
|
|| fFirstWindow == window
|
|
|
|
|| fLastWindow == window;
|
|
|
|
}
|
|
|
|
|
2008-08-13 13:00:36 +04:00
|
|
|
|
|
|
|
/*! Unlike HasWindow(), this will not reference the window pointer. You
|
|
|
|
can use this method to check whether or not a window is still part
|
|
|
|
of a list (when it's possible that the window is already gone).
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
WindowList::ValidateWindow(Window* validateWindow) const
|
|
|
|
{
|
|
|
|
for (Window *window = FirstWindow(); window != NULL;
|
|
|
|
window = window->NextWindow(fIndex)) {
|
|
|
|
if (window == validateWindow)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
WindowList::Count() const
|
|
|
|
{
|
|
|
|
int32 count = 0;
|
|
|
|
|
|
|
|
for (Window *window = FirstWindow(); window != NULL;
|
|
|
|
window = window->NextWindow(fIndex)) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|