home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.6 KB | 236 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Hello.hpp"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWSUUTIL_H
- #include "FWSUUtil.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWBUFSIN_H
- #include "FWBufSin.h"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfhello
- #endif
-
- FW_DEFINE_AUTO(CHelloContent)
-
- //========================================================================================
- // CHelloContent class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CHelloContent constructor
- //----------------------------------------------------------------------------------------
-
- CHelloContent::CHelloContent(Environment* ev, CHelloPart* part) :
- FW_CContent(ev, part),
- fTextData(""),
- fCentered(FALSE),
- fHelloPart(part)
- {
- // ----- Initialize the text data strings -----
- FW_PSharedLibraryResourceFile resFile(ev);
-
- FW_CString32 platformString;
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, FW_kMultiStringRes, kFirstString, fTextData);
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, FW_kMultiStringRes, kPlatformString, platformString);
- fTextData += platformString;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent destructor
- //----------------------------------------------------------------------------------------
-
- CHelloContent::~CHelloContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::GetTextData
- //----------------------------------------------------------------------------------------
-
- const FW_CString& CHelloContent::GetTextData()
- {
- return fTextData;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::SetTextData
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::SetTextData(Environment* ev, const FW_CString& newText)
- {
- fTextData = newText;
- fHelloPart->PartChanged(ev, true); // invalidateOnly = true
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::ClearTextData
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::ClearTextData(Environment* ev)
- {
- FW_CString newString;
- FW_PSharedLibraryResourceFile resFile(ev);
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, FW_kMultiStringRes, kBlankString, newString);
-
- fTextData = newString;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
- FW_UNUSED(storageKind);
- FW_UNUSED(promise);
-
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_CWritableStream stream(suSink);
-
- if (kind->IsPartKind(ev))
- {
- stream << fCentered;
- stream << fTextData;
- }
- else if (kind->IsEqual(ev, 'TEXT', kODPlatformDataType))
- {
- stream.Write(fTextData.RevealBuffer(), fTextData.GetByteLength());
- }
- else if (kind->IsEqual(ev, 'TEXT', kODPlatformFileType))
- {
- FW_DEBUG_MESSAGE("Should never externalize TEXT file");
- }
-
- // ----- Clear the end of the focused value -----
- FW_SUDeleteEndOfFocusedValue(ev, storageUnit);
- }
-
- //----------------------------------------------------------------------------------------
- // ReadStringFromStream
- //----------------------------------------------------------------------------------------
-
- static void ReadStringFromStream(Environment* ev, FW_CString& string, FW_CReadableStream& stream, unsigned long textSize)
- {
- FW_UNUSED(ev);
- FW_CAcquireTemporaryMemory tempMemory(textSize + 1);
- char* buffer = (char*)tempMemory.GetPointer();
-
- stream.Read(buffer, textSize);
-
- buffer[textSize] = 0;
- string = "";
- string.Append((const FW_Char*)buffer, textSize);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::InternalizeKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloContent::InternalizeKind(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- unsigned long size = sourceSU->GetSize(ev);
-
- if (kind->IsPartKind(ev) || kind->IsEqual(ev, 'TEXT', kODPlatformDataType))
- {
- FW_PStorageUnitSink suSink(ev, sourceSU, kODPropContents, kind->GetType(ev));
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
-
- if (kind->IsPartKind(ev))
- {
- stream >> fCentered;
- stream >> fTextData;
- }
- else
- ReadStringFromStream(ev, fTextData, stream, sink->GetLength(ev) /*size*/);
- }
- else if (kind->IsEqual(ev, 'TEXT', kODPlatformFileType))
- {
- FW_PFileValueSink sink(ev, sourceSU);
- FW_CReadableStream stream(sink);
- ReadStringFromStream(ev, fTextData, stream, sink->GetLength(ev));
- }
- else
- {
- FW_DEBUG_MESSAGE("CHelloContent::InternalizeKind - Unknown type");
- }
-
- if (storageKind != FW_kPartStorage)
- fHelloPart->PartChanged(ev, true); // invalidateOnly = true
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::CenterText
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::CenterText(Environment* ev, FW_Boolean state)
- {
- if (state != fCentered)
- {
- fCentered = state;
- fHelloPart->PartChanged(ev, false); // invalidateOnly = false
- }
- }
-
-