2 * Copyright 2001-2005, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Jeremy Rand (jrand@magma.ca)
13 #include <Messenger.h>
17 #include <InterfaceDefs.h>
22 // ToDo: in case the BDeskbar methods are called from a Deskbar add-on,
23 // they will currently deadlock most of the time (only those that do
24 // not need a reply will work).
25 // That should be fixed in the Deskbar itself, even if the Be API found
26 // a way around that (that doesn't work too well, BTW)
28 // The API in this file should be considered as part of OpenTracker - but
29 // should work with all versions of Tracker available for Haiku.
31 static const char *kDeskbarSignature
= "application/x-vnd.Be-TSKB";
33 static const uint32 kMsgAddView
= 'icon';
34 static const uint32 kMsgAddAddOn
= 'adon';
35 static const uint32 kMsgHasItem
= 'exst';
36 static const uint32 kMsgGetItemInfo
= 'info';
37 static const uint32 kMsgCountItems
= 'cwnt';
38 static const uint32 kMsgRemoveItem
= 'remv';
39 static const uint32 kMsgLocation
= 'gloc';
40 static const uint32 kMsgIsExpanded
= 'gexp';
41 static const uint32 kMsgSetLocation
= 'sloc';
42 static const uint32 kMsgExpand
= 'sexp';
46 get_deskbar_frame(BRect
*frame
)
48 BMessenger
deskbar(kDeskbarSignature
);
52 BMessage
request(B_GET_PROPERTY
);
53 request
.AddSpecifier("Frame");
54 request
.AddSpecifier("Window", "Deskbar");
57 result
= deskbar
.SendMessage(&request
, &reply
);
59 result
= reply
.FindRect("result", frame
);
69 : fMessenger(new BMessenger(kDeskbarSignature
))
81 BDeskbar::IsRunning() const
83 return fMessenger
->IsValid();
88 BDeskbar::Frame() const
90 BRect
frame(0.0, 0.0, 0.0, 0.0);
91 get_deskbar_frame(&frame
);
98 BDeskbar::Location(bool *_isExpanded
) const
100 deskbar_location location
= B_DESKBAR_RIGHT_TOP
;
101 BMessage
request(kMsgLocation
);
107 if (fMessenger
->IsTargetLocal()) {
108 // ToDo: do something about this!
109 // (if we just ask the Deskbar in this case, we would deadlock)
113 if (fMessenger
->SendMessage(&request
, &reply
) == B_OK
) {
115 if (reply
.FindInt32("location", &value
) == B_OK
)
116 location
= static_cast<deskbar_location
>(value
);
119 && reply
.FindBool("expanded", _isExpanded
) != B_OK
)
128 BDeskbar::SetLocation(deskbar_location location
, bool expanded
)
130 BMessage
request(kMsgSetLocation
);
131 request
.AddInt32("location", static_cast<int32
>(location
));
132 request
.AddBool("expand", expanded
);
134 return fMessenger
->SendMessage(&request
);
139 BDeskbar::IsExpanded(void) const
141 BMessage
request(kMsgIsExpanded
);
145 if (fMessenger
->SendMessage(&request
, &reply
) != B_OK
146 || reply
.FindBool("expanded", &isExpanded
) != B_OK
)
154 BDeskbar::Expand(bool expand
)
156 BMessage
request(kMsgExpand
);
157 request
.AddBool("expand", expand
);
159 return fMessenger
->SendMessage(&request
);
164 BDeskbar::GetItemInfo(int32 id
, const char **_name
) const
169 // Note: Be's implementation returns B_BAD_VALUE if *_name was NULL,
170 // not just if _name was NULL. This doesn't make much sense, so we
171 // do not imitate this behaviour.
173 BMessage
request(kMsgGetItemInfo
);
174 request
.AddInt32("id", id
);
177 status_t result
= fMessenger
->SendMessage(&request
, &reply
);
178 if (result
== B_OK
) {
180 result
= reply
.FindString("name", &name
);
181 if (result
== B_OK
) {
182 *_name
= strdup(name
);
184 result
= B_NO_MEMORY
;
192 BDeskbar::GetItemInfo(const char *name
, int32
*_id
) const
197 BMessage
request(kMsgGetItemInfo
);
198 request
.AddString("name", name
);
201 status_t result
= fMessenger
->SendMessage(&request
, &reply
);
203 result
= reply
.FindInt32("id", _id
);
210 BDeskbar::HasItem(int32 id
) const
212 BMessage
request(kMsgHasItem
);
213 request
.AddInt32("id", id
);
216 if (fMessenger
->SendMessage(&request
, &reply
) == B_OK
)
217 return reply
.FindBool("exists");
224 BDeskbar::HasItem(const char *name
) const
226 BMessage
request(kMsgHasItem
);
227 request
.AddString("name", name
);
230 if (fMessenger
->SendMessage(&request
, &reply
) == B_OK
)
231 return reply
.FindBool("exists");
238 BDeskbar::CountItems(void) const
240 BMessage
request(kMsgCountItems
);
243 if (fMessenger
->SendMessage(&request
, &reply
) == B_OK
)
244 return reply
.FindInt32("count");
251 BDeskbar::AddItem(BView
*view
, int32
*_id
)
254 status_t result
= view
->Archive(&archive
);
258 BMessage
request(kMsgAddView
);
259 request
.AddMessage("view", &archive
);
262 result
= fMessenger
->SendMessage(&request
, &reply
);
263 if (result
== B_OK
) {
265 result
= reply
.FindInt32("id", _id
);
267 reply
.FindInt32("error", &result
);
275 BDeskbar::AddItem(entry_ref
*addon
, int32
*_id
)
277 BMessage
request(kMsgAddAddOn
);
278 request
.AddRef("addon", addon
);
281 status_t status
= fMessenger
->SendMessage(&request
, &reply
);
282 if (status
== B_OK
) {
284 status
= reply
.FindInt32("id", _id
);
286 reply
.FindInt32("error", &status
);
294 BDeskbar::RemoveItem(int32 id
)
296 BMessage
request(kMsgRemoveItem
);
297 request
.AddInt32("id", id
);
299 // ToDo: the Deskbar does not reply to this message, so we don't
300 // know if it really succeeded - we can just acknowledge that the
301 // message was sent to the Deskbar
303 return fMessenger
->SendMessage(&request
);
308 BDeskbar::RemoveItem(const char *name
)
310 BMessage
request(kMsgRemoveItem
);
311 request
.AddString("name", name
);
313 // ToDo: the Deskbar does not reply to this message, so we don't
314 // know if it really succeeded - we can just acknowledge that the
315 // message was sent to the Deskbar
317 return fMessenger
->SendMessage(&request
);