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 trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All 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 44BPose* 45PoseList::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 55 return pose; 56 } 57 } 58 return NULL; 59} 60 61 62BPose* 63PoseList::FindPose(const entry_ref* entry, int32* resultingIndex) const 64{ 65 int32 count = CountItems(); 66 for (int32 index = 0; index < count; index++) { 67 BPose* pose = ItemAt(index); 68 ASSERT(pose->TargetModel()); 69 if (*pose->TargetModel()->EntryRef() == *entry) { 70 if (resultingIndex) 71 *resultingIndex = index; 72 73 return pose; 74 } 75 } 76 return NULL; 77} 78 79 80BPose* 81PoseList::FindPose(const Model* model, int32* resultingIndex) const 82{ 83 return FindPose(model->NodeRef(), resultingIndex); 84} 85 86 87BPose* 88PoseList::DeepFindPose(const node_ref* node, int32* resultingIndex) const 89{ 90 int32 count = CountItems(); 91 for (int32 index = 0; index < count; index++) { 92 BPose* pose = ItemAt(index); 93 Model* model = pose->TargetModel(); 94 if (*model->NodeRef() == *node) { 95 if (resultingIndex) 96 *resultingIndex = index; 97 98 return pose; 99 } 100 // if model is a symlink, try matching node with the target 101 // of the link 102 if (model->IsSymLink()) { 103 model = model->LinkTo(); 104 if (model && *model->NodeRef() == *node) { 105 if (resultingIndex) 106 *resultingIndex = index; 107 108 return pose; 109 } 110 } 111 } 112 113 return NULL; 114} 115 116 117PoseList* 118PoseList::FindAllPoses(const node_ref* node) const 119{ 120 int32 count = CountItems(); 121 PoseList *result = new PoseList(5, false); 122 for (int32 index = 0; index < count; index++) { 123 BPose *pose = ItemAt(index); 124 Model *model = pose->TargetModel(); 125 if (*model->NodeRef() == *node) { 126 result->AddItem(pose, 0); 127 continue; 128 } 129 130 if (!model->IsSymLink()) 131 continue; 132 133 model = model->LinkTo(); 134 if (model != NULL && *model->NodeRef() == *node) { 135 result->AddItem(pose); 136 continue; 137 } 138 139 if (model == NULL) { 140 Model model(pose->TargetModel()->EntryRef(), true); 141 if (*model.NodeRef() == *node) 142 result->AddItem(pose); 143 } 144 } 145 return result; 146} 147