usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / servers / app / WindowList.cpp
blob33c91d2ebf70fd4c2a688e3b42c4c50917e18ba6
1 /*
2 * Copyright (c) 2005-2008, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include "DesktopSettings.h"
11 #include "Window.h"
14 const BPoint kInvalidWindowPosition = BPoint(INFINITY, INFINITY);
17 window_anchor::window_anchor()
19 next(NULL),
20 previous(NULL),
21 position(kInvalidWindowPosition)
26 // #pragma mark -
29 WindowList::WindowList(int32 index)
31 fIndex(index),
32 fFirstWindow(NULL),
33 fLastWindow(NULL)
38 WindowList::~WindowList()
43 void
44 WindowList::SetIndex(int32 index)
46 fIndex = index;
50 /*!
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.
54 void
55 WindowList::AddWindow(Window* window, Window* before)
57 window_anchor& windowAnchor = window->Anchor(fIndex);
59 if (before != NULL) {
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;
71 } else {
72 // add view to the end of the list
73 if (fLastWindow != NULL) {
74 fLastWindow->Anchor(fIndex).next = window;
75 windowAnchor.previous = fLastWindow;
76 } else {
77 fFirstWindow = window;
78 windowAnchor.previous = NULL;
81 windowAnchor.next = NULL;
82 fLastWindow = window;
85 if (fIndex < kMaxWorkspaces)
86 window->SetWorkspaces(window->Workspaces() | (1UL << fIndex));
90 void
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;
98 } else {
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;
106 } else {
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;
119 bool
120 WindowList::HasWindow(Window* window) const
122 if (window == NULL)
123 return false;
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).
136 bool
137 WindowList::ValidateWindow(Window* validateWindow) const
139 for (Window *window = FirstWindow(); window != NULL;
140 window = window->NextWindow(fIndex)) {
141 if (window == validateWindow)
142 return true;
145 return false;
149 int32
150 WindowList::Count() const
152 int32 count = 0;
154 for (Window *window = FirstWindow(); window != NULL;
155 window = window->NextWindow(fIndex)) {
156 count++;
159 return count;