home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
odtlktv4.zip
/
ODTLKT
/
TOOLKIT
/
SAMPLES
/
OPENDOC
/
PARTS
/
COOKBOOK
/
CKBKUTL.CPP
next >
Wrap
Text File
|
1995-12-15
|
11KB
|
396 lines
//----------------------------------------------------------------------------
// File: ckbkutl.cpp
//
// Contains: CookbookPart utility functions & classes source file
//
// Modified by: Lynda Salvetti
// Written by: Steve Smith (original)
//
// Copyright: ⌐ 1994 by Apple Computer, Inc., all rights reserved.
// Copyright: 1995 by IBM, Inc., all rights reserved.
//
//----------------------------------------------------------------------------
// --- OpenDoc Includes ---
#ifndef _ODTYPES_
#include <ODTypes.h>
#endif
#ifndef SOM_ODPart_xh
#include <Part.xh>
#endif
#ifndef SOM_Module_OpenDoc_StdProps_defined
#include <StdProps.xh>
#endif
#ifndef SOM_Module_OpenDoc_StdTypes_defined
#include <StdTypes.xh>
#endif
#ifndef SOM_ODFrame_xh
#include <Frame.xh>
#endif
#ifndef SOM_ODDraft_xh
#include <Draft.xh>
#endif
#ifndef SOM_ODFrameFacetIterator_xh
#include <Frfaitr.xh>
#endif
#ifndef SOM_ODCanvas_xh
#include <Canvas.xh>
#endif
#ifndef SOM_ODTransform_xh
#include <Trnsform.xh>
#endif
#ifndef SOM_ODStorageUnit_xh
#include <StorageU.xh>
#endif
// --- CookbookPart Includes ---
#ifndef _COOKBOOKPARTUTILS_
#include "ckbkutl.hpp"
#endif
#ifndef SOM_CookbookPart_xih
#include "cookbook.xih"
#endif
#ifndef _COOKBOOKDEFS_
#include "cookbook.hpp"
#endif
//====================================================================
// Utility Functions
//====================================================================
//--------------------------------------------------------------------
// CountFacets
//--------------------------------------------------------------------
ODUShort CountFramesFacets(Environment* ev, ODFrame* frame)
{
ODUShort facetCount = 0;
ODFacet* facet;
ODFrameFacetIterator* ffiter;
ffiter = frame->CreateFacetIterator(ev);
facet = ffiter->First(ev);
while ( ffiter->IsNotComplete(ev) )
{
facetCount++;
facet = ffiter->Next(ev);
}
delete ffiter;
return facetCount;
}
//====================================================================
// CLinkedList
//====================================================================
CLinkedList::CLinkedList():CLink()
{
}
CLinkedList::~CLinkedList()
{
// Delete all links:
while (fNext != this)
delete fNext;
}
void CLinkedList::Add(ODPtr content)
{
// The new link has already hooked itself into my chain so
// I don't need to remember it elsewhere.
new CLink(content,this);
}
void CLinkedList::Remove(ODPtr content)
{
CLink *link;
for (link=this->First(); link->Content(); link=link->Next())
if (link->Content() == content)
{
delete link;
return;
}
}
ODBoolean CLinkedList::Contains(ODPtr content)
{
CLink *link;
for (link=this->First(); link->Content(); link=link->Next())
if (link->Content() == content)
return kODTrue;
return kODFalse;
}
ODUShort CLinkedList::Count()
{
ODUShort count = 0;
CLink *link;
for (link=this->First(); link->Content(); link=link->Next())
count++;
return count;
}
//====================================================================
// CLink
//====================================================================
CLink::CLink()
:fContent(kODNULL),
fPrev(this),
fNext(this)
{
}
CLink::CLink(ODPtr content, CLinkedList* list)
:fContent(content),
fPrev(list),
fNext(list->fNext)
{
list->fNext = this;
fNext->fPrev = this;
}
CLink::~CLink()
{
if (fPrev)
fPrev->fNext = fNext;
if (fNext)
fNext->fPrev = fPrev;
}
//=========================================================================
// CFrameInfo
//=========================================================================
//-------------------------------------------------------------------------
// CFrameInfo::CFrameInfo
//-------------------------------------------------------------------------
CFrameInfo::CFrameInfo()
{
fFrameActive = kODFalse;
fFrameReactivate = kODFalse;
fActiveFacet = kODNULL;
fSourceFrame = kODNULL;
fAttachedFrames = kODNULL;
fPartWindow = kODNULL;
}
//-------------------------------------------------------------------------
// CFrameInfo::~CFrameInfo
//-------------------------------------------------------------------------
CFrameInfo::~CFrameInfo()
{
if ( fAttachedFrames )
delete fAttachedFrames;
}
//-------------------------------------------------------------------------
// CFrameInfo::Externalize
//-------------------------------------------------------------------------
void CFrameInfo::Externalize(Environment* ev,
ODStorageUnitView* storageUnitView)
{
// This method assumes that OpenDoc has passed us a storageUnitView
// that is focused to a property, but no particular value.
ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
this->ExternalizeFrameInfo(ev, storageUnit, 0, kODNULL);
}
//-------------------------------------------------------------------------
// CFrameInfo::ExternalizeFrameInfo
//-------------------------------------------------------------------------
void CFrameInfo::ExternalizeFrameInfo(Environment* ev,
ODStorageUnit* storageUnit,
ODDraftKey key, ODFrame* scopeFrame)
{
if ( storageUnit->Exists(ev, kODNULL, kCookbookPartInfo, 0) )
{
// Persistent object references are stored in a side table, rather
// than in the property/value stream. Thus, deleting the contents of
// a value will not "delete" the references previously written to
// that value. To completely "delete" all references written to the
// value, we must remove the value and add it back.
storageUnit->Focus(ev, kODNULL, kODPosSame, kCookbookPartInfo,
0, kODPosUndefined);
storageUnit->Remove(ev);
}
if ( fSourceFrame )
{
ODStorageUnitRef weakRef;
ODID frameID = fSourceFrame->GetID(ev);
ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : 0 );
ODDraft* fromDraft = fSourceFrame->GetStorageUnit(ev)->GetDraft(ev);
storageUnit->AddValue(ev, kCookbookPartInfo);
// If a draft key exists, then we are being cloned to another draft.
// We must "weak" clone our display frame and reference the cloned
// frame. The part re-uses the frameID variable so there aren't two
// different GetWeakStorageUnitRef calls.
if ( key )
frameID = fromDraft->WeakClone(ev, key, frameID, 0, scopeFrameID);
// Write out weak references to each of the part's display frames.
storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
(ODPtr)&weakRef);
}
}
//-------------------------------------------------------------------------
// CFrameInfo::CloneInto
//-------------------------------------------------------------------------
void CFrameInfo::CloneInto(Environment *ev, ODDraftKey key,
ODStorageUnitView* storageUnitView, ODFrame* scopeFrame)
{
// This method assumes that OpenDoc has passed us a storageUnitView
// that is focused to a property, but no particular value.
ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
if ( storageUnit->Exists(ev, kODNULL, kCookbookPartInfo, 0) == kODFalse )
{
this->ExternalizeFrameInfo(ev, storageUnit, key, scopeFrame);
}
}
//-------------------------------------------------------------------------
// CFrameInfo::InitFromStorage
//------------------------------------------------------------------------------
void CFrameInfo::InitFromStorage(Environment* ev,
ODStorageUnitView* storageUnitView)
{
// This method assumes that OpenDoc has passed us a storageUnitView
// that is focused to a property, but no particular value.
ODStorageUnit* storageUnit = storageUnitView->GetStorageUnit(ev);
if ( storageUnit->Exists(ev, kODNULL, kCookbookPartInfo, 0) )
{
storageUnit->Focus(ev, kODNULL, kODPosSame,
kCookbookPartInfo, 0 , kODPosUndefined);
ODULong size = storageUnit->GetSize(ev);
// If the frame does not have a source frame, make sure the value
// is empty.
if ( size > 0 )
{
ODStorageUnitRef weakRef;
StorageUnitGetValue(storageUnit, ev, sizeof(ODStorageUnitRef),
(ODPtr)&weakRef);
if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
{
ODID sourceID = storageUnit->GetIDFromStorageUnitRef(ev,
weakRef);
ODFrame* frame = storageUnit->GetDraft(ev)->AcquireFrame(ev,
sourceID);
fSourceFrame = frame;
frame->Release(ev);
}
else
{
fSourceFrame = kODNULL;
}
}
}
}
//-------------------------------------------------------------------------
// CFrameInfo::SetSourceFrame
//-------------------------------------------------------------------------
void CFrameInfo::SetSourceFrame(Environment* ev, ODFrame* sourceFrame)
{
if ( sourceFrame != kODNULL )
{
fSourceFrame = sourceFrame;
fSourceFrame->Acquire(ev);
}
}
//-------------------------------------------------------------------------
// CFrameInfo::ReleaseSourceFrame
//-------------------------------------------------------------------------
void CFrameInfo::ReleaseSourceFrame(Environment* ev)
{
if ( fSourceFrame != kODNULL )
{
fSourceFrame->Release(ev);
fSourceFrame = kODNULL;
}
}
//-------------------------------------------------------------------------
// CFrameInfo::AttachFrame
//-------------------------------------------------------------------------
void CFrameInfo::AttachFrame(Environment* ev, ODFrame* frame)
{
if ( fAttachedFrames == kODNULL )
fAttachedFrames = new CLinkedList;
if ( !fAttachedFrames->Contains((ODPtr)frame) )
{
frame->Acquire(ev);
fAttachedFrames->Add((ODPtr)frame);
}
}
//-------------------------------------------------------------------------
// CFrameInfo::DetachFrame
//-------------------------------------------------------------------------
void CFrameInfo::DetachFrame(Environment* ev, ODFrame* frame)
{
if ( fAttachedFrames->Contains((ODPtr)frame) )
{
fAttachedFrames->Remove((ODPtr)frame);
frame->Release(ev);
}
if ( fAttachedFrames->Count() == 0 )
{
delete fAttachedFrames;
fAttachedFrames = kODNULL;
}
}