2 * Copyright 2010, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
10 #include "WindowStack.h"
16 #include <ApplicationPrivate.h>
17 #include <MessengerPrivate.h>
19 #include <ServerProtocol.h>
21 #include "StackAndTilePrivate.h"
24 using namespace BPrivate
;
27 BWindowStack::BWindowStack(BWindow
* window
)
29 fLink
= window
->fLink
;
33 BWindowStack::~BWindowStack()
40 BWindowStack::AddWindow(const BWindow
* window
)
42 BMessenger
messenger(window
);
43 return AddWindow(messenger
);
48 BWindowStack::AddWindow(const BMessenger
& window
)
50 return AddWindowAt(window
, -1);
55 BWindowStack::AddWindowAt(const BWindow
* window
, int32 position
)
57 BMessenger
messenger(window
);
58 return AddWindowAt(messenger
, position
);
63 BWindowStack::AddWindowAt(const BMessenger
& window
, int32 position
)
65 _StartMessage(kAddWindowToStack
);
67 _AttachMessenger(window
);
68 fLink
->Attach
<int32
>(position
);
71 if (fLink
->FlushWithReply(code
) != B_OK
)
79 BWindowStack::RemoveWindow(const BWindow
* window
)
81 BMessenger
messenger(window
);
82 return RemoveWindow(messenger
);
87 BWindowStack::RemoveWindow(const BMessenger
& window
)
89 _StartMessage(kRemoveWindowFromStack
);
90 _AttachMessenger(window
);
92 if (fLink
->Flush() != B_OK
)
100 BWindowStack::RemoveWindowAt(int32 position
, BMessenger
* window
)
102 _StartMessage(kRemoveWindowFromStackAt
);
103 fLink
->Attach
<int32
>(position
);
105 int32 code
= B_ERROR
;
106 if (fLink
->FlushWithReply(code
) != B_OK
)
112 return _ReadMessenger(*window
);
117 BWindowStack::CountWindows()
119 _StartMessage(kCountWindowsOnStack
);
121 int32 code
= B_ERROR
;
122 fLink
->FlushWithReply(code
);
127 if (fLink
->Read
<int32
>(&count
) != B_OK
)
135 BWindowStack::WindowAt(int32 position
, BMessenger
& messenger
)
137 _StartMessage(kWindowOnStackAt
);
138 fLink
->Attach
<int32
>(position
);
140 int32 code
= B_ERROR
;
141 fLink
->FlushWithReply(code
);
145 return _ReadMessenger(messenger
);
150 BWindowStack::HasWindow(const BWindow
* window
)
152 BMessenger
messenger(window
);
153 return HasWindow(messenger
);
158 BWindowStack::HasWindow(const BMessenger
& window
)
160 _StartMessage(kStackHasWindow
);
161 _AttachMessenger(window
);
163 int32 code
= B_ERROR
;
164 fLink
->FlushWithReply(code
);
169 if (fLink
->Read
<bool>(&hasWindow
) != B_OK
)
177 BWindowStack::_AttachMessenger(const BMessenger
& window
)
179 BMessenger::Private
messengerPrivate(const_cast<BMessenger
&>(window
));
180 fLink
->Attach
<port_id
>(messengerPrivate
.Port());
181 fLink
->Attach
<int32
>(messengerPrivate
.Token());
182 return fLink
->Attach
<team_id
>(messengerPrivate
.Team());
187 BWindowStack::_ReadMessenger(BMessenger
& window
)
192 fLink
->Read
<port_id
>(&port
);
193 fLink
->Read
<int32
>(&token
);
194 status_t status
= fLink
->Read
<team_id
>(&team
);
197 BMessenger::Private
messengerPrivate(window
);
198 messengerPrivate
.SetTo(team
, port
, token
);
204 BWindowStack::_StartMessage(int32 what
)
206 fLink
->StartMessage(AS_TALK_TO_DESKTOP_LISTENER
);
207 fLink
->Attach
<int32
>(kMagicSATIdentifier
);
208 fLink
->Attach
<int32
>(kStacking
);
209 return fLink
->Attach
<int32
>(what
);