/* libsswf_tag_remove.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2008 */

/*

Copyright (c) 2002-2008 Made to Order Software Corp.

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

/** \file
 *
 * \brief The implementation of the sswf::TagRemove class
 *
 * This file declares the body of the functions which are not
 * inline. It is part of the SSWF library.
 */

#include	"sswf/libsswf.h"

using namespace sswf;





/////////////////////////////////////////// TagRemove

/** \class sswf::TagRemove
 *
 * \brief Remove an object from the display list
 *
 * A Flash animation is composed of a set of characters (shapes)
 * and a display list. You insert shapes in the display list using
 * the sswf::TagPlace and you remove shapes using the sswf::TagRemove
 * tag.
 *
 * Since version 3 of SWF, it is possible to remove objects from
 * the list using sswf::TagPlace only.
 *
 * \sa sswf::TagPlace
 * \sa sswf::TagPlace::Replace
 * \sa <a href="../SWFalexref.html#tag_removeobject">SWF Alexis' Reference&mdash;Remove Object</a>
 * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
 */


/** \fn void sswf::TagRemove::SetDepth(int depth)
 *
 * \brief Set the depth at which an object is removed
 *
 * This function can be used to remove an object at the specified
 * depth.
 *
 * It is possible to only define the depth in which case the last
 * object added at this depth is removed from the display list.
 *
 * \note
 * Defining the depth is mandatory.
 *
 * Since version 3 of SWF, it is possible to use the replace flag
 * of the sswf::TagPlace instead of removing an object with an
 * sswf::TagRemove.
 *
 * \param depth The depth where an object is removed
 *
 * \sa void sswf::TagRemove::SetObjectID(sswf_id_t id)
 * \sa void sswf::TagPlace::Replace(void)
 */


/** \fn void sswf::TagRemove::SetObjectID(sswf_id_t id)
 *
 * \brief Set the identifier of the object to be removed
 *
 * The identification of the object to be removed.
 *
 * The TagRemove can be used with an object identification
 * in which case only an object with the given identification
 * is removed from the list. If no such object exists, nothing
 * happens.
 *
 * \note
 * Since version 3 of SWF, it is possible to use the replace flag
 * of the sswf::TagPlace instead of removing an object with an
 * sswf::TagRemove.
 *
 * \sa void sswf::TagRemove::SetDepth(int depth)
 * \sa void sswf::TagPlace::Replace(void)
 */


/** \brief Initialize the TagRemove with defaults
 *
 * By default, a TagRemove tag is set to 'no depth' and 'no identifier'.
 *
 * You can specify one or both of these parameters.
 *
 * \param parent A object of type sswf::TagHeader or sswf::TagSprite
 *
 * \sa void sswf::TagRemove::SetDepth
 * \sa void sswf::TagRemove::SetObjectID
 * \sa sswf::TagPlace
 * \sa void sswf::TagPlace::Replace(void)
 */
TagRemove::TagRemove(TagBase *parent)
	: TagBase("remove", parent)
{
	f_depth = -1;
	f_id = SSWF_ID_NONE;
}


/** \brief Return the type flags of the TagRemove tag
 *
 * A TagRemove is a CONTROL tag: it is used to change the
 * display list.
 *
 * A TagRemove has a REFERENCE to another object.
 *
 * \sa TagBase::swf_type_t sswf::TagBase::TypeFlags(void) const
 */
TagBase::swf_type_t TagRemove::TypeFlags(void) const
{
	return SWF_TYPE_CONTROL | SWF_TYPE_REFERENCE;
}


/** \brief Prepare the movie to save a Remove tag
 *
 * A TagRemove requests at least a version 3 movie when an
 * object identification was specified.
 *
 * \return Zero when no error occurs; non-zero otherwise
 */
ErrorManager::error_code_t TagRemove::PreSave(void)
{
	if(f_id == SSWF_ID_NONE) {
		MinimumVersion(3);
	}

	return ErrorManager::ERROR_CODE_NONE;
}


/** \brief Save the TagRemove in the specified Data buffer
 *
 * This function saves the TagRemove information--the depth
 * and eventual object identifier--in the Data buffer.
 *
 * \param data The Data buffer where the tag is saved
 *
 * \return Zero when no errors occur, non-zero otherwise
 */
ErrorManager::error_code_t TagRemove::Save(Data& data)
{
	assert((unsigned int) f_depth <= 65535, "invalid depth parameter for a remove object");

	if(f_id == SSWF_ID_NONE) {		// RemoveObject2
		SaveTag(data, SWF_TAG_REMOVE_OBJECT2, 2);
		data.PutShort(f_depth);
	}
	else {					// RemoveObject
		SaveTag(data, SWF_TAG_REMOVE_OBJECT, 4);
		data.PutShort(f_id);
		data.PutShort(f_depth);
	}

	return ErrorManager::ERROR_CODE_NONE;
}







/* The following options fold the documentation; use 'zi' to turn on and off
 *
 * vim: foldexpr=getline(v\:lnum)!~'^/\\*\\*'&&getline(v\:lnum)!~'^\ \\*'?0\:1 foldcolumn=2 foldmethod=expr
 */
