xref: /haiku/src/kits/tracker/PoseList.cpp (revision 56eb8e78cc702792e3b032e3f5f45da9e5dbea9e)
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)
53 				*resultingIndex = index;
54 			return pose;
55 		}
56 	}
57 	return NULL;
58 }
59 
60 BPose *
61 PoseList::FindPose(const entry_ref *entry, int32 *resultingIndex) const
62 {
63 	int32 count = CountItems();
64 	for (int32 index = 0; index < count; index++) {
65 		BPose *pose = ItemAt(index);
66 		ASSERT(pose->TargetModel());
67 		if (*pose->TargetModel()->EntryRef() == *entry) {
68 			if (resultingIndex)
69 				*resultingIndex = index;
70 			return pose;
71 		}
72 	}
73 	return NULL;
74 }
75 
76 BPose *
77 PoseList::FindPose(const Model *model, int32 *resultingIndex) const
78 {
79 	return FindPose(model->NodeRef(), resultingIndex);
80 }
81 
82 BPose *
83 PoseList::DeepFindPose(const node_ref *node, int32 *resultingIndex) const
84 {
85 	int32 count = CountItems();
86 	for (int32 index = 0; index < count; index++) {
87 		BPose *pose = ItemAt(index);
88 		Model *model = pose->TargetModel();
89 		if (*model->NodeRef() == *node) {
90 			if (resultingIndex)
91 				*resultingIndex = index;
92 			return pose;
93 		}
94 		// if model is a symlink, try matching node with the target
95 		// of the link
96 		if (model->IsSymLink()) {
97 			model = model->LinkTo();
98 			if (model && *model->NodeRef() == *node) {
99 				if (resultingIndex)
100 					*resultingIndex = index;
101 				return pose;
102 			}
103 		}
104 	}
105 
106 	return NULL;
107 }
108