home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-26 | 13.5 KB | 475 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFx.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
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfx
- #endif
-
- FW_DEFINE_AUTO(CODFxContent)
-
- //========================================================================================
- // CODFxContent class
- //========================================================================================
-
- static FW_CColor *PrivGetInitialColors()
- {
- static FW_CColor colors[9] = {
- FW_kRGBRed, // top left
- FW_kRGBBlack, // top center
- FW_kRGBGreen, // top right
- FW_kRGBYellow, // left center
- FW_kRGBGreen, // center
- FW_kRGBBlue, // right center
- FW_kRGBYellow, // bottom left
- FW_kRGBYellow, // bottom center
- FW_kRGBWhite // bottom right
- };
- return colors;
- }
-
- CODFxContent::ODFXContentStruct::ODFXContentStruct(Boolean initColors)
- : fVisibleGridLines(false),
- fUnused(false),
- fPixPerRow(kMidPixPerRow),
- fNumColors(9)
- {
- if(initColors)
- for (short i = 0; i < 9; i++)
- fColors[i] = PrivGetInitialColors()[i];
- };
-
- //----------------------------------------------------------------------------------------
- // CODFxContent constructor
- //----------------------------------------------------------------------------------------
-
- CODFxContent::CODFxContent(Environment* ev, CODFxPart* part) :
- FW_CContent(ev, part),
- fODFxPart(part),
- fPicture(),
- fPictureValid(false),
- fContentData(true)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent destructor
- //----------------------------------------------------------------------------------------
-
- CODFxContent::~CODFxContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetColorData
- //----------------------------------------------------------------------------------------
-
- const FW_CColor& CODFxContent::GetColorData(short n)
- {
- return fContentData.fColors[n];
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetColorData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::GetColorData(RegionColorArray& colors)
- {
- for(short i = 0; i < 9; i++)
- colors[i] = fContentData.fColors[i];
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetColorData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetColorData(Environment* ev, short n, const FW_CColor& newColor)
- {
- fContentData.fColors[n] = newColor;
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetColorData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetColorData(Environment* ev, const RegionColorArray& colors)
- {
- for(short i = 0; i < 9; i++)
- fContentData.fColors[i] = colors[i];
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetNumColors
- //----------------------------------------------------------------------------------------
-
- short CODFxContent::GetNumColors()
- {
- return fContentData.fNumColors;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetNumColors
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetNumColors(Environment* ev, short numColors)
- {
- if(numColors != fContentData.fNumColors)
- {
- fContentData.fNumColors = numColors;
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetContentData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::GetContentData(ODFXContentStruct& outData)
- {
- outData = fContentData;
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetContentData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetContentData(Environment* ev, const ODFXContentStruct& inData)
- {
- fContentData = inData;
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetShowGridLines
- //----------------------------------------------------------------------------------------
-
- Boolean CODFxContent::GetShowGridLines()
- {
- return fContentData.fVisibleGridLines;
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetShowGridLines
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetShowGridLines(Environment* ev, Boolean show)
- {
- fContentData.fVisibleGridLines = show;
-
- fODFxPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetMaxResolution
- //----------------------------------------------------------------------------------------
-
- short CODFxContent::GetPixPerRow()
- {
- return fContentData.fPixPerRow;
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::SetMaxResolution
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::SetPixPerRow(Environment* ev, short inRes)
- {
- inRes = (inRes / 2) * 2;
-
- if(inRes != fContentData.fPixPerRow)
- {
- fContentData.fPixPerRow = inRes;
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::RotateColors
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::RotateColors(Environment* ev)
- {
- if(GetNumColors() == 4)
- {
- FW_CColor temp = fContentData.fColors[0];
-
- fContentData.fColors[0] = fContentData.fColors[3];
-
- fContentData.fColors[3] = fContentData.fColors[4];
-
- fContentData.fColors[4] = fContentData.fColors[1];
-
- fContentData.fColors[1] = temp;
- }
- else
- {
- FW_CColor temp = fContentData.fColors[0];
-
- fContentData.fColors[0] = fContentData.fColors[3];
-
- fContentData.fColors[3] = fContentData.fColors[6];
-
- fContentData.fColors[6] = fContentData.fColors[7];
-
- fContentData.fColors[7] = fContentData.fColors[8];
-
- fContentData.fColors[8] = fContentData.fColors[5];
-
- fContentData.fColors[5] = fContentData.fColors[2];
-
- fContentData.fColors[2] = fContentData.fColors[1];
-
- fContentData.fColors[1] = temp;
- }
-
- InvalidatePicture(ev);
-
- fODFxPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::ResetColorData
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::ResetColorData(Environment* ev)
- {
- SetContentData(ev, ODFXContentStruct(true));
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
-
- void CODFxContent::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 << fContentData.fNumColors;
- for(short i = 0; i < 9; i++)
- stream << fContentData.fColors[i];
-
- stream << fContentData.fPixPerRow;
- stream << fContentData.fVisibleGridLines;
- }
- else if (kind->IsEqual(ev, 'PICT', kODPlatformDataType))
- {
- FW_PlatformPict platformPict = GetPictureData(ev).GetPlatformPict();
-
- unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
-
- FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
- stream.Write(lockedHandle.GetPointer(), pictSize);
- }
- else if (kind->IsEqual(ev, 'PICT', kODPlatformFileType))
- {
- long myZero = 0;
-
- for(short i = 0; i < (512 / sizeof(myZero)); i++)
- stream << myZero;
-
- FW_PlatformPict platformPict = GetPictureData(ev).GetPlatformPict();
-
- unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
-
- FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
- stream.Write(lockedHandle.GetPointer(), pictSize);
- }
-
- // ----- Clear the end of the focused value -----
- FW_SUDeleteEndOfFocusedValue(ev, storageUnit);
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::InternalizeKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CODFxContent::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))
- {
- FW_PStorageUnitSink suSink(ev, sourceSU, kODPropContents, kind->GetType(ev));
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
-
- const short kOldVersionSize = 56;
- const short kNewVersionSize = sizeof(fContentData);
- Boolean oldVersion = sourceSU->GetSize(ev) == kOldVersionSize;
- Boolean newVersion = sourceSU->GetSize(ev) == kNewVersionSize;
-
- short numColors;
- stream >> numColors;
-
- RegionColorArray colors;
- for(short i = 0; i < 9; i++)
- stream >> colors[i];
-
- if(! oldVersion)
- {
- short pixPerRow;
- stream >> pixPerRow;
-
- FW_Boolean visibleGrid;
- stream >> visibleGrid;
-
- SetPixPerRow(ev, pixPerRow);
- SetShowGridLines(ev, visibleGrid);
- }
-
- SetNumColors(ev, numColors);
- SetColorData(ev, colors);
- }
- else
- {
- FW_DEBUG_MESSAGE("CODFxContent::InternalizeKind - Unknown type");
- }
-
- if (storageKind != FW_kPartStorage)
- fODFxPart->PartChanged(ev);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CODFxContent::GetPictureData
- //----------------------------------------------------------------------------------------
-
- FW_CPicture& CODFxContent::GetPictureData(Environment* ev)
- {
- const short kMaxColor = GetPixPerRow();
-
- if(!fPictureValid)
- {
- FW_gWaitCursor.Select();
-
- // make a kMaxColor pixel tall by kMaxColor pixel wide, 24-bit direct bitmap
- FW_CBitmap bits(kMaxColor, kMaxColor, 24, NULL);
- {
- const short range = GetNumColors() == 9 ? kMaxColor / 2 : kMaxColor;
-
- // top left square if 9 colors, otherwise the whole enchilada
- for(short i = 0; i < range; i++)
- {
- FW_CColor colStart = FW_CColor().Blend(GetColorData((short)0), GetColorData(1), i, range - 1);
- FW_CColor colEnd = FW_CColor().Blend(GetColorData(3), GetColorData(4), i, range - 1);
-
- for(short j = 0; j < range; j++)
- bits.SetPixelColor(i, j, FW_CColor().Blend(colStart, colEnd, j, range - 1));
- }
-
- if(range < kMaxColor)
-
- {
- // top right square
- for(short i = 0; i < range; i++)
- {
- FW_CColor colStart = FW_CColor().Blend(GetColorData(1), GetColorData(2), i, range - 1);
- FW_CColor colEnd = FW_CColor().Blend(GetColorData(4), GetColorData(5), i, range - 1);
-
- for(short j = 0; j < range; j++)
- bits.SetPixelColor(i + range, j, FW_CColor().Blend(colStart, colEnd, j, range - 1));
- }
-
- // bottom left square
- for(short i = 0; i < range; i++)
- {
- FW_CColor colStart = FW_CColor().Blend(GetColorData(3), GetColorData(4), i, range - 1);
- FW_CColor colEnd = FW_CColor().Blend(GetColorData(6), GetColorData(7), i, range - 1);
-
- for(short j = 0; j < range; j++)
- bits.SetPixelColor(i, j + range, FW_CColor().Blend(colStart, colEnd, j, range - 1));
- }
-
- // top right square
- for(short i = 0; i < range; i++)
- {
- FW_CColor colStart = FW_CColor().Blend(GetColorData(4), GetColorData(5), i, range - 1);
- FW_CColor colEnd = FW_CColor().Blend(GetColorData(7), GetColorData(8), i, range - 1);
-
- for(short j = 0; j < range; j++)
- bits.SetPixelColor(i + range, j + range, FW_CColor().Blend(colStart, colEnd, j, range - 1));
- }
- }
- }
-
- {
- FW_CPictureContext picContext(ev, fPicture, FW_IntToFixed(kMaxColor), FW_IntToFixed(kMaxColor));
- FW_CRect pictureBounds(FW_kFixed0, FW_kFixed0, FW_IntToFixed(kMaxColor), FW_IntToFixed(kMaxColor));
- picContext.SetClipRect(pictureBounds);
- FW_CBitmapShape::RenderBitmap(picContext, bits, pictureBounds, ditherCopy);
- }
-
- fPictureValid = true;
-
- FW_gArrowCursor.Select();
- }
-
- return fPicture;
- }
-
-