vfs: check userland buffers before reading them.
[haiku.git] / src / apps / deskbar / StatusViewShelf.cpp
blob4cd15bb7a6dcea89ced96047f43184179f489e4f
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
30 trademarks of Be Incorporated in the United States and other countries. Other
31 brand product names are registered trademarks or trademarks of their respective
32 holders.
33 All rights reserved.
37 #include "StatusViewShelf.h"
39 #include <stdio.h>
40 #include <string.h>
42 #include <Debug.h>
43 #include <InterfaceDefs.h>
45 #include "StatusView.h"
48 TReplicantShelf::TReplicantShelf(TReplicantTray* parent)
49 : BShelf(parent, false, "DeskbarShelf")
51 fParent = parent;
52 SetAllowsZombies(false);
56 TReplicantShelf::~TReplicantShelf()
61 void
62 TReplicantShelf::MessageReceived(BMessage* message)
64 switch (message->what) {
65 case B_DELETE_PROPERTY:
67 BMessage repspec;
68 int32 index = 0;
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,
75 // this will fix the problem of realigning the reps
76 // after a remove when done through scripting
78 // note: if specified by index its the index not the id!
80 while (message->FindMessage("specifiers", index++, &repspec)
81 == B_OK) {
82 const char* str;
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;
100 break;
103 default:
104 BShelf::MessageReceived(message);
105 break;
110 bool
111 TReplicantShelf::CanAcceptReplicantView(BRect frame, BView* view,
112 BMessage* message) const
114 if (view->ResizingMode() != B_FOLLOW_NONE)
115 view->SetResizingMode(B_FOLLOW_NONE);
117 // determine placement and whether the new replicant will 'fit'
118 return fParent->AcceptAddon(frame, message);
122 BPoint
123 TReplicantShelf::AdjustReplicantBy(BRect frame, BMessage* message) const
125 // added in AcceptAddon, from TReplicantTray
126 BPoint point;
127 message->FindPoint("_pjp_loc", &point);
128 message->RemoveName("_pjp_loc");
130 return point - frame.LeftTop();
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.
138 void
139 TReplicantShelf::ReplicantDeleted(int32, const BMessage*, const BView*)