1/*
2Open Tracker License
3
4Terms and Conditions
5
6Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of
9this software and associated documentation files (the "Software"), to deal in
10the Software without restriction, including without limitation the rights to
11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12of the Software, and to permit persons to whom the Software is furnished to do
13so, subject to the following conditions:
14
15The above copyright notice and this permission notice applies to all licensees
16and shall be included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25Except as contained in this notice, the name of Be Incorporated shall not be
26used in advertising or otherwise to promote the sale, use or other dealings in
27this Software without prior written authorization from Be Incorporated.
28
29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30trademarks of Be Incorporated in the United States and other countries. Other
31brand product names are registered trademarks or trademarks of their respective
32holders.
33All rights reserved.
34*/
35
36
37#include "StatusViewShelf.h"
38
39#include <stdio.h>
40#include <string.h>
41
42#include <Debug.h>
43#include <InterfaceDefs.h>
44
45#include "StatusView.h"
46
47
48TReplicantShelf::TReplicantShelf(TReplicantTray* parent)
49	: BShelf(parent, false, "DeskbarShelf")
50{
51	fParent = parent;
52	SetAllowsZombies(false);
53}
54
55
56TReplicantShelf::~TReplicantShelf()
57{
58}
59
60
61void
62TReplicantShelf::MessageReceived(BMessage* message)
63{
64	switch (message->what) {
65		case B_DELETE_PROPERTY:
66		{
67			BMessage repspec;
68			int32 index = 0;
69
70			// this should only occur via scripting
71			// since we can't use ReplicantDeleted
72			// catch the message and find the id or name specifier
73			// then delete the rep vi the api,
74
75			// this will fix the problem of realigning the reps
76			// after a remove when done through scripting
77
78			// note: if specified by index its the index not the id!
79
80			while (message->FindMessage("specifiers", index++, &repspec)
81				== B_OK) {
82				const char* str;
83
84				if (repspec.FindString("property", &str) == B_OK) {
85					if (strcmp(str, "Replicant") == 0) {
86						int32 index;
87						if (repspec.FindInt32("index", &index) == B_OK) {
88							int32 id;
89							const char* name;
90							if (fParent->ItemInfo(index, &name, &id) == B_OK)
91								fParent->RemoveIcon(id);
92							break;
93						} else if (repspec.FindString("name", &str) == B_OK) {
94							fParent->RemoveIcon(str);
95							break;
96						}
97					}
98				}
99			}
100			break;
101		}
102
103		default:
104			BShelf::MessageReceived(message);
105			break;
106	}
107}
108
109
110bool
111TReplicantShelf::CanAcceptReplicantView(BRect frame, BView* view,
112	BMessage* message) const
113{
114	if (view->ResizingMode() != B_FOLLOW_NONE)
115		view->SetResizingMode(B_FOLLOW_NONE);
116
117	// determine placement and whether the new replicant will 'fit'
118	return fParent->AcceptAddon(frame, message);
119}
120
121
122BPoint
123TReplicantShelf::AdjustReplicantBy(BRect frame, BMessage* message) const
124{
125	// added in AcceptAddon, from TReplicantTray
126	BPoint point;
127	message->FindPoint("_pjp_loc", &point);
128	message->RemoveName("_pjp_loc");
129
130	return point - frame.LeftTop();
131}
132
133
134// the virtual BShelf::ReplicantDeleted is called before the
135// replicant is actually removed from BShelf's internal list
136// thus, this returns the wrong number of replicants.
137
138void
139TReplicantShelf::ReplicantDeleted(int32, const BMessage*, const BView*)
140{
141}
142