Exemple #1
0
bool
ResourcesContainer::IsModified() const
{
	bool isModified = fIsModified;
	int32 count = CountResources();
	for (int32 i = 0; !isModified && i < count; i++)
		isModified |= ResourceAt(i)->IsModified();
	return isModified;
}
Exemple #2
0
void
ResourcesContainer::SetModified(bool modified)
{
	fIsModified = modified;
	// If unmodified, set the resource item's modified flag as well.
	if (!modified) {
		int32 count = CountResources();
		for (int32 i = 0; i < count; i++)
			ResourceAt(i)->SetModified(false);
	}
}
Exemple #3
0
int32
ResourcesContainer::IndexOf(type_code type, int32 id) const
{
	int32 index = -1;
	int32 count = CountResources();
	for (int32 i = 0; index == -1 && i < count; i++) {
		ResourceItem *item = ResourceAt(i);
		if (item->Type() == type && item->ID() == id)
			index = i;
	}
	return index;
}
Exemple #4
0
int32
ResourcesContainer::IndexOf(const void *data) const
{
	int32 index = -1;
	if (data) {
		int32 count = CountResources();
		for (int32 i = 0; index == -1 && i < count; i++) {
			if (ResourceAt(i)->Data() == data)
				index = i;
		}
	}
	return index;
}
Exemple #5
0
int32
ResourcesContainer::IndexOfType(type_code type, int32 typeIndex) const
{
	int32 index = -1;
	int32 count = CountResources();
	for (int32 i = 0; index == -1 && i < count; i++) {
		ResourceItem *item = ResourceAt(i);
		if (item->Type() == type) {
			if (typeIndex == 0)
				index = i;
			typeIndex--;
		}
	}
	return index;
}
Exemple #6
0
//! Returns false, if item is NULL or memory is insufficient, true otherwise.
bool
ResourcesContainer::AddResource(ResourceItem *item, int32 index, bool replace)
{
	bool result = false;
	if (item) {
		// replace an item with the same type and id
		if (replace)
			delete RemoveResource(IndexOf(item->Type(), item->ID()));
		int32 count = CountResources();
		if (index < 0 || index > count)
			index = count;
		result = fResources.AddItem(item, count);
		SetModified(true);
	}
	return result;
}
// IndexOf
int32
ResourcesContainer::IndexOf(type_code type, const char *name) const
{
	int32 index = -1;
	int32 count = CountResources();
	for (int32 i = 0; index == -1 && i < count; i++) {
		ResourceItem *item = ResourceAt(i);
		const char *itemName = item->Name();
		if (item->Type() == type && (name == NULL && itemName == NULL
									 || name != NULL && itemName != NULL
										&& !strcmp(name, itemName))) {
			index = i;
		}
	}
	return index;
}
Exemple #8
0
static PyObject *Res_CountResources(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short _rv;
    ResType theType;
#ifndef CountResources
    PyMac_PRECHECK(CountResources);
#endif
    if (!PyArg_ParseTuple(_args, "O&",
                          PyMac_GetOSType, &theType))
        return NULL;
    _rv = CountResources(theType);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("h",
                         _rv);
    return _res;
}
Exemple #9
0
/**
Marks the end of resource count checking.

The function takes the current resource count by
calling CSession2::CountResources(), and compares it with the resource count
value saved when CSession2::ResourceCountMarkStart() was called.
If the resource counts differ, then the client thread is panicked (CSession 2)".

The client/server framework does not call this function (nor does it call 
CSession2::ResourceCountMarkStart()), but the function is available for
servers to use, if appropriate.

@param aMessage Represents the details of the client request that is requesting
                this resource check.

@see CSession2::CountResources()
@see CSession2::ResourceCountMarkStart()
*/
EXPORT_C void CSession2::ResourceCountMarkEnd(const RMessage2& aMessage)
	{
	if (iResourceCountMark!=CountResources())
		aMessage.Panic(KSessionPanicCategory,ESesFoundResCountHeaven);
	}
Exemple #10
0
/**
Marks the start of resource count checking.

It sets up a starting value for resource count checking.

The function sets up a starting value for resource count checking by using
the value returned by a call to CSession2::CountResources(), and is the value
that will be used for comparison if CSession2::ResourceCountMarkEnd() is called
at some later time.

The client/server framework does not call this function (nor
does it call CSession2::ResourceCountMarkEnd()), but is available for servers
to use, if appropriate.

@see CSession2::CountResources()
@see CSession2::ResourceCountMarkEnd()
*/
EXPORT_C void CSession2::ResourceCountMarkStart()
	{
	iResourceCountMark=CountResources();
	}
long iniMacros(void)
{
#ifndef MACINTOSH
	int        i;

	for (i = 0; macros[i].name; i++)
	{
		if (!installMacro(macros[i].text, macros[i].name,
						  strlen(macros[i].text)))
		{
			goto errorExit;
		}
	}
#else /*MACINTOSH*/
	Integer          id = IDBASE, id1;
	Integer          i, count = CountResources(MACROTYPE);
	char            *prefix = NAMEPREFIX;
	Integer          prefixLength = strlen(prefix);
	Str255           resName;
	char            *name = (char *) resName;
	ResType          type;
    unsigned char  **text;
	
	/*
	   examine all resources of the wanted type
	   If the name starts with prefix, install it as long as it is not
	   the name of the dummy last macro
	*/
	for(i=1; i<= count; i++)
	{
		text = (unsigned char **) GetIndResource(MACROTYPE, i);
		if (ResError() != noErr)
		{
			break;
		}
		GetResInfo((Handle) text, &id1, &type, resName);
		if (ResError() != noErr)
		{
			goto errorExit;
		}
		PtoCstr((unsigned char *) name);
		if (strncmp(prefix, name, prefixLength) == 0 &&
			strcmp(name + prefixLength, ENDNAME) != 0)
		{
			HLock((Handle) text);
		/* first two characters of *text give number of characters */
			if (!installMacro((char *) (*text) + 2, name + prefixLength,
							  (*text)[0] * 256 + (*text)[1]))
			{
				goto errorExit;
			}
			HUnlock((Handle) text);
		}
		ReleaseResource((Handle) text);
	} /*while(1)*/
#endif /*MACINTOSH*/
	return (1);

  errorExit:
	return (0);
} /*iniMacros()*/