Accounting Software
Small Business Software Estimating Software
Inventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareConstruction Management SoftwareProject Management SoftwareBusiness Management Software

Picture Data (Source Code)

Link to: header | other data directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

DB_Picture

a persistent object which stores a picture-- e.g. the picture pasted into a
Cost Item or Assembly.

This class manages pictures for the Goldenseal job cost accounting software,
project management software, construction estimating software
and construction project estimating software.

The picture object stores a graphic handle, and the actual data record then
stores the ID of the picture object. It reduces the size of the data object,
and also meshes well with the icon display in accounts.

Note that graphics pasted into a layout are handled differently-- those are
stored in the layout itself.

SUPERCLASS = DB_PersistentObject

****************

DB_IconSuite

a persistent object which stores an icon suite-- e.g. for an account

SUPERCLASS = DB_Picture

Constructor

/*********************************************************************************
constructor TCS 6/28/02
*********************************************************************************/
DB_Picture::DB_Picture()
{
mGraphicHandle = nil;
mEndSafetyTag = tag_endsafetytag;
}
/*********************************************************************************
destructor TCS 6/28/02
*********************************************************************************/
DB_Picture::~DB_Picture()
{
TCS_ForgetHandle(&mGraphicHandle);
}

Source Code

/*********************************************************************************

GetFileLength TCS 6/30/02

return the file length used by this object

*********************************************************************************/
NeoSize DB_Picture::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
HANDLE_FILE_SIZE(mGraphicHandle) +
cFileLength;
}
/*********************************************************************************

CopyFrom TCS 6/30/02

copy the data members from the passed object. This is used to implement
duplicate. source should be an object of the same class as this object

*********************************************************************************/
void DB_Picture::CopyFrom(DB_PersistentObject *source, const UInt8 /*copyFlags*/)
{
DB_Picture *src = TCS_SAFE_CAST(source, DB_Picture);
TCS_FailNILMsg(src, TCS_GetErrString(errID_BadRecord));

mGraphicHandle = TCS_CopyHandle(src->mGraphicHandle);
}
/*********************************************************************************

ReadObject TCS 6/30/02

read the persistent object's data in from a stream
*********************************************************************************/
void DB_Picture::ReadObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));

CNeoDebugImport checker(aStream, this);

THE_SUPERCLASS::ReadObject(aStream, aTag);

if (!IsIOValid())
return;

if (!mGraphicHandle)
{
// allocate an empty handle, if we don't have one already.
// We do not use TCS_GetNewHandle since we don't want a
// record save or purge now.
mGraphicHandle = TCS_NewHandle();
TCS_FailNILMsg(mGraphicHandle, TCS_GetErrString(errID_BadStream));
}

ReadHandleFromStream(aStream, mGraphicHandle, cHasSafetyTag);

mEndSafetyTag = aStream->ReadEndSafetyTag(this); // mfs_sa rev 20feb2k3

// --End: Binary Compatibility Changes

if (!IsValidEndTag(mEndSafetyTag))
ReportDamagedObject(GetDBClassID(), GetDBID());
}/*********************************************************************************

WriteObject TCS 6/30/02

write the persistent object's data to a stream
*********************************************************************************/
void DB_Picture::WriteObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));

if (!IsValidEndTag(mEndSafetyTag))
{
ReportDamagedObject(GetDBClassID(), GetDBID());
mEndSafetyTag = tag_endsafetytag; // rev TCS 11/26/02
}

CNeoDebugExport checker(aStream, this);

THE_SUPERCLASS::WriteObject(aStream, aTag);

WriteHandleToStream(aStream, mGraphicHandle, cHasSafetyTag);

aStream->WriteEndSafetyTag(mEndSafetyTag, this); // mfs_sa rev 20feb2k3
}
#if CAN_USE_MARK
#pragma mark -
#endif/*********************************************************************************

GetGraphic

set the given graphic to the data referenced by this graphic blob. Note
that this gives the graphic a copy of the blob data, so the graphic
owns it

*********************************************************************************/
void DB_Picture::GetGraphic(CGraphic *graphic)
{
graphic->SetGraphicHandle(GetGraphicHandle());
}
/*********************************************************************************

GetGraphicHandle

return a copy of the graphic data referenced by this object. This function
returns a copy of the graphic handle, which the caller is responsible for
disposing when done with it.

*********************************************************************************/
TCS_Handle DB_Picture::GetGraphicHandle()
{
return TCS_CopyHandle(mGraphicHandle);
}
/*********************************************************************************

SetGraphic

set the Graphic data referenced by this object.

*********************************************************************************/
void DB_Picture::SetGraphic(CGraphic &aGraphic)
{
// load in the graphic's handle
TCS_Handle graphicH = aGraphic.LoadGraphic();
TCS_FailNILMsg(graphicH, TCS_GetErrString(errID_BadGraphic));

SetGraphicHandle(graphicH);
aGraphic.UnloadGraphic();
}
/*********************************************************************************

SetGraphicHandle

return a copy of the graphic data referenced by this object. This function
returns a copy of the graphic handle, which the caller is responsible for
disposing when done with it.

*********************************************************************************/
void DB_Picture::SetGraphicHandle(const TCS_Handle inHandle)
{
// we should not be in the database while this happens, since the file
// length may change
TCS_ASSERTMsg(!IsInDatabase(), TCS_GetErrString(errID_BadLengthChange));

// get rid of our existing layout
TCS_ForgetHandle(&mGraphicHandle);

mGraphicHandle = TCS_CopyHandle(inHandle);

MakeDirty();
}
/*********************************************************************************

FillDataReport TCS 9/7/02

fill in a diagnostic table that shows data field values.

*********************************************************************************/
void DB_Picture::FillDataReport(CTCS_Table *table, CNeoStream *stream) const
{
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
TCS_FailNILMsg(stream, TCS_GetErrString(errID_BadStream));

THE_SUPERCLASS::FillDataReport(table, stream);
FillEndSafetyTag(table, stream, cHandleValidationTag);

SInt32 handleSize = TCS_GetHandleSize(mGraphicHandle);
FillFieldTableRow(table, stream, "graphic size", cLongSize, handleSize);
FillFieldTableRow(table, stream, "mGraphicHandle", handleSize, cTwoDashString);

FillEndSafetyTag(table, stream, mEndSafetyTag);
}#pragma mark -
#if TCS_CANUSE_QUICKTIME //TCS_FOR_MAC mfs_kk 15jul2k2 replaced TCS_FOR_MAC with TCS_CANUSE_QUICKTIME
const SInt32 numIconTypes = 6,
gIconTypes[numIconTypes] = {
kLarge1BitMask,
kLarge4BitData,
kLarge8BitData,
kSmall1BitMask,
kSmall4BitData,
kSmall8BitData
};
#elif TCS_FOR_WINDOWS
// Windows has three icon types: Monochrome, CGA, and EGA/VGA
// %%% Not sure yet how to pull out a single icon type, so init
// the array with zeros
const SInt32 numIconTypes = 3,
gIconTypes [numIconTypes] = { 0, 0, 0 };
#endif

#undef THE_SUPERCLASS
#define THE_SUPERCLASS DB_Picture
/*********************************************************************************

TCS_IconSuiteFromHandle

set the given graphic to the data referenced by this graphic handle. Note
that this gives the graphic a copy of the data, so the graphic
owns it

*********************************************************************************/
static TCS_Handle TCS_IconSuiteFromHandle(TCS_Handle iconData)
{
#if TCS_CANUSE_QUICKTIME //TCS_FOR_MAC mfs_kk 15jul2k2 replaced TCS_FOR_MAC with TCS_CANUSE_QUICKTIME
// the buffer object is created with iconData for
// the buffer data. The buffer will dispose of iconData
// at the end of this scope
CTCS_HandleContainer buffer(iconData);
CInputStream stream(&buffer);
SInt32 iconType,
dataSize;
TCS_Handle iconSuiteH,
dataH;

TCS_FailOSErr(TCS_NewIconSuite(&iconSuiteH)); // mfs_kk 15jul2k2 called wrapper instead of direct call
TCS_FailNILMsg(iconSuiteH, TCS_GetErrString(errID_BadIcon));

while (!buffer.AtEnd())
{
stream.ReadLong(iconType);
stream.ReadLong(dataSize);
dataH = TCS_GetNewHandle(dataSize);
TCS_FailNILMsg(dataH, TCS_GetErrString(errID_BadIcon));

stream.ReadHandleBlock(dataH);
TCS_FailOSErr(TCS_AddIconToSuite(dataH, iconSuiteH, iconType)); // mfs_kk 15jul2k2 called wrapper instead of direct call
}
return iconSuiteH;

#elif TCS_FOR_WINDOWS
#pragma unused(iconData)
SIGNAL_Debug("Not Yet Implemented!");
return nil;
#endif
}
/*********************************************************************************

TCS_ResolveIconSuite

set the Graphic data referenced by this object.

********************************* ************************************************/
static TCS_Handle TCS_ResolveIconSuite(TCS_Handle iconSuiteH)
{
#if TCS_CANUSE_QUICKTIME //TCS_FOR_MAC mfs_kk 15jul2k2 replaced TCS_FOR_MAC with TCS_CANUSE_QUICKTIME
SInt32 i,
handleSize;
TCS_Handle iconH;
CTCS_HandleContainer buffer(cDoesntOwnData);
COutputStream stream(&buffer);

// we want the buffer to resize only as much as
// necessary to hold the icon data
buffer.SetBlockSize(0);
for (i = 0; i < numIconTypes; i++)
{
if (TCS_GetIconFromSuite(&iconH, iconSuiteH, gIconTypes[i]) == noErr) // mfs_kk 15jul2k2 called wrapper instead of direct call
{
handleSize = TCS_GetHandleSize(iconH);
if (handleSize)
{
// the icon type exists, write it to the stream
stream.WriteLong(gIconTypes[i]);
stream.WriteLong(handleSize);
stream.WriteHandleBlock(iconH);
}
}
}
return TCS_Handle(buffer);
#else if TCS_FOR_WINDOWS
#pragma unused(iconSuiteH)
SIGNAL_Debug("Not Yet Implemented!");
return nil;
#endif
}
/*********************************************************************************

GetGraphicHandle TCS rev 7/2/02

get a copy of the graphic handle. We convert it to an icon suite

********************************* ************************************************/
TCS_Handle DB_IconSuite::GetGraphicHandle()
{
TCS_Handle graphicH = THE_SUPERCLASS::GetGraphicHandle();

TCS_FailNILMsg(graphicH, TCS_GetErrString(errID_BadObject));

// get the system-compatible graphic handle from
// the blob data. Note that TCS_IconSuiteFromData
// will dispose of the blob
return TCS_IconSuiteFromHandle(graphicH);
}

/*********************************************************************************

SetGraphic

set the graphic

********************************* ************************************************/
void DB_IconSuite::SetGraphic(CGraphic &aGraphic)
{
// load in the graphic's handle
TCS_Handle graphicH = aGraphic.LoadGraphic();
TCS_FailNILMsg(graphicH, TCS_GetErrString(errID_BadGraphic));

TCS_Handle iconH = TCS_ResolveIconSuite(graphicH);
TCS_FailNILMsg(iconH, TCS_GetErrString(errID_BadIcon));

SetGraphicHandle(iconH); // rev TCS 7/2/02

TCS_ForgetHandle(&iconH);
aGraphic.UnloadGraphic();
}