xref: /haiku/src/kits/tracker/PoseList.cpp (revision 22440f4105cafc95cc1d49f9bc65bb395c527d86)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
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:
14 
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.
17 
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.
24 
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.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 //	Icon cache is used for drawing node icons; it caches icons
36 //	and reuses them for successive draws
37 
38 #include <Debug.h>
39 
40 #include "PoseList.h"
41 #include "Pose.h"
42 
43 
44 BPose*
45 PoseList::FindPose(const node_ref* node, int32* resultingIndex) const
46 {
47 	int32 count = CountItems();
48 	for (int32 index = 0; index < count; index++) {
49 		BPose* pose = ItemAt(index);
50 		ASSERT(pose->TargetModel());
51 		if (*pose->TargetModel()->NodeRef() == *node) {
52 			if (resultingIndex != NULL)
53 				*resultingIndex = index;
54 
55 			return pose;
56 		}
57 	}
58 
59 	return NULL;
60 }
61 
62 
63 BPose*
64 PoseList::FindPose(const entry_ref* entry, int32* resultingIndex) const
65 {
66 	int32 count = CountItems();
67 	for (int32 index = 0; index < count; index++) {
68 		BPose* pose = ItemAt(index);
69 		ASSERT(pose->TargetModel());
70 		if (*pose->TargetModel()->EntryRef() == *entry) {
71 			if (resultingIndex != NULL)
72 				*resultingIndex = index;
73 
74 			return pose;
75 		}
76 	}
77 	return NULL;
78 }
79 
80 
81 BPose*
82 PoseList::FindPose(const Model* model, int32* resultingIndex) const
83 {
84 	return FindPose(model->NodeRef(), resultingIndex);
85 }
86 
87 
88 BPose*
89 PoseList::DeepFindPose(const node_ref* node, int32* resultingIndex) const
90 {
91 	int32 count = CountItems();
92 	for (int32 index = 0; index < count; index++) {
93 		BPose* pose = ItemAt(index);
94 		Model* model = pose->TargetModel();
95 		if (*model->NodeRef() == *node) {
96 			if (resultingIndex != NULL)
97 				*resultingIndex = index;
98 
99 			return pose;
100 		}
101 		// if model is a symlink, try matching node with the target
102 		// of the link
103 		if (model->IsSymLink()) {
104 			model = model->LinkTo();
105 			if (model != NULL && *model->NodeRef() == *node) {
106 				if (resultingIndex != NULL)
107 					*resultingIndex = index;
108 
109 				return pose;
110 			}
111 		}
112 	}
113 
114 	return NULL;
115 }
116 
117 
118 PoseList*
119 PoseList::FindAllPoses(const node_ref* node) const
120 {
121 	int32 count = CountItems();
122 	PoseList *result = new PoseList(5, false);
123 	for (int32 index = 0; index < count; index++) {
124 		BPose *pose = ItemAt(index);
125 		Model *model = pose->TargetModel();
126 		if (*model->NodeRef() == *node) {
127 			result->AddItem(pose, 0);
128 			continue;
129 		}
130 
131 		if (!model->IsSymLink())
132 			continue;
133 
134 		model = model->LinkTo();
135 		if (model != NULL && *model->NodeRef() == *node) {
136 			result->AddItem(pose);
137 			continue;
138 		}
139 
140 		if (model == NULL) {
141 			Model model(pose->TargetModel()->EntryRef(), true);
142 			if (*model.NodeRef() == *node)
143 				result->AddItem(pose);
144 		}
145 	}
146 
147 	return result;
148 }
149 
150 
151 BPose*
152 PoseList::FindPoseByFileName(const char* name, int32* _index) const
153 {
154 	int32 count = CountItems();
155 	for (int32 index = 0; index < count; index++) {
156 		BPose* pose = ItemAt(index);
157 		ASSERT(pose->TargetModel());
158 		if (strcmp(pose->TargetModel()->EntryRef()->name, name) == 0) {
159 			if (_index != NULL)
160 				*_index = index;
161 
162 			return pose;
163 		}
164 	}
165 
166 	return NULL;
167 }
168