/* libsswf_tag_end.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::TagEnd 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;


/////////////////////////////////////////// TagEnd

/** \class sswf::TagEnd
 *
 * \brief Mark the end of a list of tags.
 *
 * This tag is used to mark the end of the list of tags in the main
 * movie and in a TagSprite control list.
 *
 * It seems that a TagEnd is not mandatory, but it can help to have
 * it so the movie can be considered 100% valid. For this reason,
 * the SSWF library will automatically add an sswf::TagEnd whenever
 * none are present. Also, if the control list does not end with
 * a sswf::TagShowFrame, that tag is also added.
 *
 * \code
 *	if not(control list ends with TagEnd) then
 *		if not(control list ends with TagShowFrame) then
 *			add TagShowFrame to control list
 *		end if
 *		add TagEnd to control list
 *	end if
 * \endcode
 *
 * \sa sswf::TagShowFrame
 * \sa sswf::TagSprite
 * \sa sswf::TagHeader
 * \sa <a href="../SWFalexref.html#tag_end">SWF Alexis' Reference&mdash;End</a>
 * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
 */


/** \brief Initialize the TagEnd
 *
 * A TagEnd is empty. The only initialization is the parent of the
 * tag.
 *
 * \param parent The parent tag of this tag
 */
TagEnd::TagEnd(TagBase *parent)
	: TagBase("end", parent)
{
}



/** \brief Returns the type flags of the TagEnd
 *
 * The TagEnd is a CONTROL tag.
 *
 * \return The type flags of this tag
 */
TagBase::swf_type_t TagEnd::TypeFlags(void) const
{
	return SWF_TYPE_CONTROL;
}


/** \brief Save the TagEnd in the specified Data buffer
 *
 * This function saves the TagEnd which is saving a 16 bits
 * zero in the Data buffer.
 *
 * \param data The Data buffer where the TagEnd is saved
 *
 * \return The function returns zero when no errors; non-zero otherwise
 */
ErrorManager::error_code_t TagEnd::Save(Data& data)
{
	SaveTag(data, SWF_TAG_END, 0);

	// If the End tag is not preceeded by a ShowFrame, then
	// we call ShowFrame() on our parent since we are very
	// much like a frame!
	TagBase *previous = Previous();
	if(previous != 0) {
		if(strcmp(previous->Name(), "showframe") != 0) {
			Parent()->ShowFrame();
		}
	}

	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
 */
