home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: CItemList.c
- * Created: 7/25/93
- * Desc: A list of CItems that can initialize itself
- * from disk. See CItem for a full description of
- * what items are.
- *
- * In resources, each subtree is stored separately
- *
- * Superclass: CList.
- * Uses: CItem.
- * Original Author: Atul Barve
- * Modifications: W. Wesley Monroe
- *
- * Copyright © 1993 Animas Software Production. All rights reserved.
- */
-
- #include "CItemList.h"
- #include "CItem.h"
-
- void CItemList::IItemList(void)
- {
- inherited::IList();
- }
-
- /*
- * ReadItem()
- *
- * Recursively read an item from a resource.
- */
-
- CItem *CItemList::ReadItem(Handle itemH, short level)
- {
- CItem *theItem;
- CItem *sub;
-
- tItem **h;
-
- char *c, text[256];
- short canExpand, iconID, expanded;
- short j, n, len;
- short numSubs;
-
- theItem = MakeItem();
-
- h = (tItem **) itemH;
- expanded = (**h).expanded;
- canExpand = (**h).canExpand;
- iconID = (**h).iconID;
-
- BlockMove((**h).text, text, (**h).text[0]+1);
-
- theItem->SetExpanded(expanded);
- theItem->SetDisplayText(text);
- theItem->SetCanExpand(canExpand);
- theItem->SetIconID(iconID);
-
- // Move the text pointer past the pascal string to get to
- // the number of subitems...
- c = (**h).text;
- len = text[0];
- len++;
- len = (len % 2 == 1) ? len + 1:len;
- c += len;
-
- *h = (tItem *) c;
- theItem->GetExtraItemData((Handle) h);
-
- c = (char *) *h;
- numSubs = * (short *) c;
-
- c += sizeof(short);
-
- *h = (tItem *) c;
- for(j = 0;j < numSubs; j++) {
- sub = ReadItem((Handle) h,level+1);
- sub->SetParent(theItem);
- theItem->SetLevel(level);
- theItem->SetNthSubItem(sub,100);
- }
-
- return theItem;
- }
-
- /*
- * MakeItem()
- *
- * A Method that subclasses can override to put other
- * types of objects in the list.
- */
-
- CItem *CItemList::MakeItem(void)
- {
- CItem *anItem;
-
- anItem = new CItem;
-
- return anItem;
- }
-
- /*
- * IItemRes()
- *
- * Read the list from resource type 'type' resource.
- */
-
- void CItemList::IItemRes(OSType type)
- {
- CItem *theItem;
-
- Handle hndl;
- char text[256];
- OSType rType;
- short rID,i,n, itemsRead;
-
- n = Count1Resources(type);
-
- for(i = 1; i <= n; i++) {
- hndl = Get1IndResource(type, i);
- FailResError();
- HLock(hndl);
- theItem = ReadItem(hndl, 0);
- HUnlock(hndl);
-
- Append(theItem);
- }
- }
-
- CItemList *CItemList::CopyList(Boolean copySubItems)
- {
- CItemList *copyList;
- CItem *anItem, *copyItem;
-
- long i, n = GetNumItems();
-
- copyList = new CItemList;
- copyList->IList();
-
- for(i = 1; i <= n; i++) {
-
- anItem = (CItem *) NthItem(i);
- copyItem = anItem->CopyItem(copySubItems);
- copyList->Append(copyItem);
- }
-
- return copyList;
- }
-
- /*void CItemList::Dispose(void)*/
- /*{*/
- /* DisposeItems();*/
- /**/
- /* inherited::Dispose();*/
- /*}*/
-
- /*
- * RemoveFromVisTree()
- *
- * Remove an item, and recurrsively its children
- * from the visible list, but do ***not***
- * dispose of the items themselves.
- */
-
- void CItemList::RemoveFromVisTree(CObject *theObject)
- {
- register long i;
- CItem *aItem, *sub;
- short num;
-
- aItem = (CItem *) theObject;
- num = aItem->GetNumSubItems();
- for(i=1;i<=num;i++) {
- sub = aItem->GetNthSubItem(i);
- sub->SetExpanded(0);
- Remove(sub);
- }
-
- aItem->SetExpanded(0);
-
- i = Offset(theObject);
- if (i != BAD_INDEX)
- DeleteItem( i+1);
-
- }
-
- /*
- * RemoveItem()
- *
- * Remove theObject and its recursively, its children
- * from the itemlist.
- * NOTE: The parent still has a reference to theObject
- * in its subitems list.
- */
-
- void CItemList::RemoveItem(CObject *theObject)
- {
- register long i;
- CItem *aItem, *parent;
- short num;
- CItem *sub;
-
- aItem = (CItem *) theObject;
- num = aItem->GetNumSubItems();
- for(i=1;i<=num;i++) {
- sub = aItem->GetNthSubItem(i);
- sub->SetExpanded(0);
- Remove(sub);
- }
-
- aItem->SetExpanded(0);
-
- i = Offset(theObject);
- if (i != BAD_INDEX)
- DeleteItem( i+1);
- }
-
- void CItemList::DeleteItems(void)
- {
- while(numItems) {
- DeleteItem(1);
- }
- }
-