home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / DU Folder / DU Selection FW / Sources / DUListPrt.cpp < prev    next >
Encoding:
Text File  |  1995-10-26  |  4.9 KB  |  191 lines  |  [TEXT/MPS ]

  1. //    Copyright © 1995 Apple Computer, Inc. All rights reserved.
  2. //    Release Version:    $ 1.0 d11 $
  3.  
  4. //================================================================================
  5.  
  6. // --- DU FW ---------------------
  7. #ifndef DULISTPART_H
  8. #include "DUListPart.h"        // DU_CListPart
  9. #endif
  10.  
  11. #ifndef DUSELECTABLE_H
  12. #include "DUSelectable.h"    // DU_MSelectable
  13. #endif
  14.  
  15. #ifndef DULIST_H
  16. #include "DUList.h"            // DU_CList
  17. #endif
  18.  
  19.  
  20. // ----- Framework Layer -----
  21. #ifndef FWPRESEN_H
  22. #include "FWPresen.h"        // FW_CPresentation
  23. #endif
  24.  
  25. // ----- OS Layer -----
  26. #ifndef FWSUSINK_H
  27. #include "FWSUSink.h"        // FW_CStorageUnitSink
  28. #endif
  29.  
  30. // ----- Foundation Layer -----
  31. #ifndef FWSTREAM_H
  32. #include <FWStream.h>        // FW_InitializeArchiving
  33. #endif
  34.  
  35. #include "FWARDyna.h"
  36.  
  37. // ----- OpenDoc Includes --------------
  38. #ifndef SOM_Module_OpenDoc_StdProps_defined
  39. #include <StdProps.xh>        // kODPropContents
  40. #endif
  41.  
  42. //==============================================================================
  43. DU_CListPart::DU_CListPart(    ODPart* odPart, 
  44.                                 ODValueType partKind, 
  45.                                 ODValueType partUserName,
  46.                                 FW_Instance partInstance, 
  47.                                 FW_ResourceId iconID)
  48.   :    FW_CPart(odPart, partKind, partUserName, partInstance, iconID),
  49.       fPartKind(partKind),
  50.     fNumItems(0),
  51.     fItemList(NULL)
  52. {
  53. }
  54.  
  55. //--------------------------------------------------------------------------------
  56. void 
  57. DU_CListPart::Initialize(Environment* ev)    // Override
  58. {
  59.     FW_CPart::Initialize(ev);
  60.     fItemList = new DU_CList;
  61. }
  62.  
  63. //--------------------------------------------------------------------------------
  64. DU_CListPart::~DU_CListPart()
  65. {
  66.     DU_MSelectable* item = NULL;
  67.     while ((item = fItemList->FirstItem()) != NULL) {
  68.         fItemList->Remove(item);
  69.         delete item;
  70.         }
  71.     delete fItemList;
  72. }
  73.  
  74. //--------------------------------------------------------------------------------
  75. FW_Boolean 
  76. DU_CListPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  77.                                      FW_Boolean hasMenuFocus,
  78.                                      FW_Boolean isRoot)    // Override
  79. {
  80.     if (hasMenuFocus) {    
  81.         menuBar->EnableCommand(ev, kODCommandSelectAll, GetNumItems() > 0);
  82.     }
  83.     return FALSE;
  84. }
  85.  
  86. //--------------------------------------------------------------------------------
  87. void 
  88. DU_CListPart::ExternalizeContent(Environment* ev,
  89.                                     ODStorageUnit* storageUnit,
  90.                                     FW_CCloneInfo* cloneInfo)    // Override
  91. {
  92.     FW_UNUSED(cloneInfo);
  93.  
  94.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fPartKind, 0, kODPosUndefined);
  95.     storageUnit->Remove(ev);
  96.     storageUnit->AddValue(ev, fPartKind);
  97.  
  98.     FW_CStorageUnitSink suSink(storageUnit, kODPropContents, fPartKind);
  99.     FW_CWritableStream stream(&suSink);
  100.  
  101.     // write number
  102.     stream << fNumItems;
  103.     
  104.     // write each item
  105.     DU_CListIterator iter(fItemList);
  106.     DU_MSelectable*    item;
  107.     for (item = iter.First(); iter.IsNotComplete(); item = iter.Next())
  108.         FW_WRITE_DYNAMIC_OBJECT(stream, item, DU_MSelectable);
  109.         
  110. }
  111.  
  112. //--------------------------------------------------------------------------------
  113. void 
  114. DU_CListPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, 
  115.                                 FW_CCloneInfo* cloneInfo)    // Override
  116. {
  117.     FW_UNUSED(cloneInfo);
  118.     ODValueType contentPropertyValueType = this->GetPartKind(ev);
  119.  
  120.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, 
  121.                         contentPropertyValueType, 0, kODPosUndefined);
  122.  
  123.     if (storageUnit->GetSize(ev) != 0) {
  124.         FW_CStorageUnitSink sink(storageUnit, kODPropContents, 
  125.                                             contentPropertyValueType);
  126.         FW_CReadableStream stream(&sink);
  127.         
  128.         // read number
  129.         stream >> fNumItems;
  130.  
  131.         // read items; make list
  132.         DU_MSelectable* item = NULL;
  133.         for (long count=0; count < fNumItems; count++) {
  134.             FW_READ_DYNAMIC_OBJECT(stream, &item, DU_MSelectable);
  135.             fItemList->AddLast(item);
  136.             }
  137.     }    // if
  138. }
  139.  
  140. //--------------------------------------------------------------------------------
  141. DU_CList* 
  142. DU_CListPart::GetItemList()
  143. {
  144.     return fItemList;
  145. }
  146.  
  147. //--------------------------------------------------------------------------------
  148. ODSShort 
  149. DU_CListPart::GetNumItems()
  150. {
  151.     return fNumItems;
  152. }
  153.  
  154. //--------------------------------------------------------------------------------
  155. DU_MSelectable* 
  156. DU_CListPart::FrontItemHit(Environment *ev, FW_CPoint &pt)
  157. {
  158.     DU_MSelectable* item = NULL;
  159.     
  160.     // Look first for a hit within a selected item
  161.     DU_CListIterator iter(fItemList);
  162.     for (item = iter.Last(); iter.IsNotComplete(); item = iter.Previous()) {
  163.         if (item->IsSelected() && item->Hit(ev, pt))
  164.             return item;
  165.     }
  166.     
  167.     // Look next for a hit within any item
  168.     for (item = iter.Last(); iter.IsNotComplete(); item = iter.Previous()) {
  169.         if (item->Hit(ev, pt))
  170.             return item;
  171.     }
  172.     return NULL;
  173. }
  174.  
  175. //--------------------------------------------------------------------------------
  176. void 
  177. DU_CListPart::AddItem(Environment* ev, DU_MSelectable* item)
  178. {
  179.     fItemList->AddLast(item);
  180.     fNumItems++;
  181. }
  182.  
  183. //--------------------------------------------------------------------------------
  184. void 
  185. DU_CListPart::RemoveItem(Environment* ev, DU_MSelectable* item)
  186. {
  187.     fItemList->Remove(item);
  188.     fNumItems--;
  189. }
  190.  
  191.