/* libsswf_tags.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::TagSetTabIndex 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;



/////////////////////////////////////////// TagSetTabIndex

/** \class sswf::TagSetTabIndex
 *
 * \brief Set the tab key index for objects
 *
 * This class is used to define the index of each object which can be
 * visited when the tab key is pressed.
 *
 * Objects are specified by depth rather than identifiers.
 *
 * The tab index is a number. Each index should be unique.
 *
 * \sa <a href="../SWFalexref.html#tag_settabindex">SWF Alexis' Reference&mdash;Set Tab Index</a>
 * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
 */


/** \brief Initialize the tab index object
 *
 * This object is initialized to a depth of 1 and an index of 1.
 * This represents the very first object.
 *
 * \param[in] parent The parent object of the TagSetTabIndex tag
 */
TagSetTabIndex::TagSetTabIndex(TagBase *parent)
	: TagBase("settabindex", parent)
{
	f_depth = 1;
	f_index = 1;
}


/** \brief Defines the type of the TagSetTabIndex
 *
 * This function returns SWF_TYPE_DEFINE.
 *
 * \return SWF_TYPE_DEFINE
 */
TagBase::swf_type_t TagSetTabIndex::TypeFlags(void) const
{
	return SWF_TYPE_DEFINE;
}


/** \brief Set the depth of the object
 *
 * This function defines the depth of the object which is
 * assigned the corresponding tab index. This means one can
 * delete and place a new object at that depth and it automatically
 * inherit this index.
 *
 * \param[in] depth The depth of the object to assign this tab index
 *
 * \sa sswf::TagSetTabIndex::GetDepth()
 */
void TagSetTabIndex::SetDepth(int depth)
{
	f_depth = depth;
}


/** \brief Set the tab index for the object
 *
 * This function defines the tab index of the object which is
 * defined at the corresponding depth. Each TagSetTabIndex should
 * specify a different index or the player will have to choose
 * which object is next.
 *
 * The index is limited to a value of 1 to 65535. It is suggested
 * that you keep it small.
 *
 * \param[in] index The tab index for the object at the specified depth
 *
 * \sa sswf::TagSetTabIndex::GetIndex()
 */
void TagSetTabIndex::SetIndex(int index)
{
	f_index = index;
}


/** \brief Get the object depth
 *
 * This function retrieves the depth as set by the SetDepth()
 * function. The depth is expected to be a non zero value.
 *
 * The depth is limited to a value between 1 and 65535. Yet,
 * bit 15 is used for other purposes in the TagPlace and thus
 * the limit is 1 to 32767.
 *
 * \return The depth of the affected object
 *
 * \sa sswf::TagSetTabIndex::SetDepth()
 */
int TagSetTabIndex::GetDepth(void) const
{
	return f_depth;
}


/** \brief Get the object tab index
 *
 * This function retrieves the tab index as set by the SetIndex()
 * function. The tab index is expected to be a non zero value.
 *
 * \return The tab index number
 *
 * \sa sswf::TagSetTabIndex::SetIndex()
 */
int TagSetTabIndex::GetIndex(void) const
{
	return f_index;
}


/** \brief Ensures the minimum version
 *
 * This function requests that the movie be at least of version 7.
 *
 * \return ErrorManager::ERROR_CODE_NONE when no error occured, an error otherwise
 */
ErrorManager::error_code_t TagSetTabIndex::PreSave(void)
{
	MinimumVersion(7);

	return ErrorManager::ERROR_CODE_NONE;
}


/** \brief Saves the tab index and depth
 *
 * This function saves the depth and tab index.
 *
 * \param[in,out] data The Data buffer where the data is saved
 *
 * \return An error if one occurs, or ErrorManager::ERROR_CODE_NONE
 */
ErrorManager::error_code_t TagSetTabIndex::Save(Data& data)
{
	SaveTag(data, SWF_TAG_SET_TAB_INDEX, 4);

	// the default are as defined in the version 7 documentation of SWF
	data.PutShort(f_depth);
	data.PutShort(f_index);

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