2 * Copyright (c) 2005-2008, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include "DesktopSettings.h"
14 const BPoint kInvalidWindowPosition
= BPoint(INFINITY
, INFINITY
);
17 window_anchor::window_anchor()
21 position(kInvalidWindowPosition
)
29 WindowList::WindowList(int32 index
)
38 WindowList::~WindowList()
44 WindowList::SetIndex(int32 index
)
51 Adds the \a window to the end of the list. If \a before is
52 given, it will be inserted right before that window.
55 WindowList::AddWindow(Window
* window
, Window
* before
)
57 window_anchor
& windowAnchor
= window
->Anchor(fIndex
);
60 window_anchor
& beforeAnchor
= before
->Anchor(fIndex
);
62 // add view before this one
63 windowAnchor
.next
= before
;
64 windowAnchor
.previous
= beforeAnchor
.previous
;
65 if (windowAnchor
.previous
!= NULL
)
66 windowAnchor
.previous
->Anchor(fIndex
).next
= window
;
68 beforeAnchor
.previous
= window
;
69 if (fFirstWindow
== before
)
70 fFirstWindow
= window
;
72 // add view to the end of the list
73 if (fLastWindow
!= NULL
) {
74 fLastWindow
->Anchor(fIndex
).next
= window
;
75 windowAnchor
.previous
= fLastWindow
;
77 fFirstWindow
= window
;
78 windowAnchor
.previous
= NULL
;
81 windowAnchor
.next
= NULL
;
85 if (fIndex
< kMaxWorkspaces
)
86 window
->SetWorkspaces(window
->Workspaces() | (1UL << fIndex
));
91 WindowList::RemoveWindow(Window
* window
)
93 window_anchor
& windowAnchor
= window
->Anchor(fIndex
);
95 if (fFirstWindow
== window
) {
96 // it's the first child
97 fFirstWindow
= windowAnchor
.next
;
99 // it must have a previous sibling, then
100 windowAnchor
.previous
->Anchor(fIndex
).next
= windowAnchor
.next
;
103 if (fLastWindow
== window
) {
104 // it's the last child
105 fLastWindow
= windowAnchor
.previous
;
107 // then it must have a next sibling
108 windowAnchor
.next
->Anchor(fIndex
).previous
= windowAnchor
.previous
;
111 if (fIndex
< kMaxWorkspaces
)
112 window
->SetWorkspaces(window
->Workspaces() & ~(1UL << fIndex
));
114 windowAnchor
.previous
= NULL
;
115 windowAnchor
.next
= NULL
;
120 WindowList::HasWindow(Window
* window
) const
125 return window
->Anchor(fIndex
).next
!= NULL
126 || window
->Anchor(fIndex
).previous
!= NULL
127 || fFirstWindow
== window
128 || fLastWindow
== window
;
132 /*! Unlike HasWindow(), this will not reference the window pointer. You
133 can use this method to check whether or not a window is still part
134 of a list (when it's possible that the window is already gone).
137 WindowList::ValidateWindow(Window
* validateWindow
) const
139 for (Window
*window
= FirstWindow(); window
!= NULL
;
140 window
= window
->NextWindow(fIndex
)) {
141 if (window
== validateWindow
)
150 WindowList::Count() const
154 for (Window
*window
= FirstWindow(); window
!= NULL
;
155 window
= window
->NextWindow(fIndex
)) {