/// Sets the page offset to render elements at based on displaced positioning
/// \param xOff - x offset 
/// \param yOff - y offset 
void CGUIPage::SetPageOffset(int xOff, int yOff)
{
	m_iPageOffsetX = xOff;
	m_iPageOffsetY = yOff;

	IGUIElement *guiElement;
	OBJECTLIST::iterator olIter = m_ObjectList.begin();
	while(olIter != m_ObjectList.end())
	{
		guiElement = dynamic_cast<IGUIElement*>((*olIter));
		if(guiElement == NULL)
		{
			m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
			m_ToolBox->Log(LOGERROR, _T("Could not cast to IGUIElement: %s"), (*olIter)->GetName());
		}
		/*
		POSITIONDATA pos;
		IHashString *guiName;
		guiName = guiElement->GetName();
		static DWORD msgHash_GetPosition = CHashString(_T("GetPosition")).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_GetPosition, sizeof(POSITIONDATA), &pos, guiName, NULL);
		pos.m_fXPos += (float) xOff;
		pos.m_fYPos += (float) yOff;
		static DWORD msgHash_SetPosition = CHashString(_T("SetPosition")).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_SetPosition, sizeof(POSITIONDATA), &pos, guiName, NULL);
		*/		
		guiElement->SetPageOffset(m_iPageOffsetX, m_iPageOffsetY);
		olIter++;
	}
}
// add a gui element to the page list
DWORD CGUIPage::OnAddGUIElementToPage(DWORD size, void *params)
{
	OBJECTLIST::iterator olIter;
	GUIPAGEMESSAGE *gpm;
	IObject *guiObject;
	static CHashString managerName(_T("CGUIManager"));
	CGUIManager *manager;

	// make sure message is valid
	VERIFY_MESSAGE_SIZE(size, sizeof(GUIPAGEMESSAGE));

	// downcast parameters to struct we expect
	gpm = (GUIPAGEMESSAGE *)params;

	// ask gui manager for the object to add
	manager = dynamic_cast<CGUIManager*>(EngineGetToolBox()->GetComponent( &managerName ));
	if (!manager)
	{
		EngineGetToolBox()->SetErrorValue(ERR_NULL_POINTER);
		EngineGetToolBox()->Log(LOGERROR, _T("could not cast IComponent from EngineToolBox to CGUIManager\n")); 
		return MSG_ERROR;
	}
	guiObject = manager->GetObject(gpm->name, gpm->compType);
	if(guiObject == NULL)
	{
		EngineGetToolBox()->SetErrorValue(ERR_NULL_POINTER);
		EngineGetToolBox()->Log(LOGERROR, _T("could not get the gui object from the gui manager: %s object not found\n"), gpm->name);
		return MSG_ERROR;
	}

	// check if object is already on list
	for(olIter = m_ObjectList.begin(); olIter != m_ObjectList.end(); olIter++)
	{
		if ( (*olIter)->GetName()->GetUniqueID() == guiObject->GetName()->GetUniqueID() )
		{
			// object is already on page
			return MSG_NOT_HANDLED;
		}
	}
	// now add object to list
	m_ObjectList.push_back(guiObject);
	m_SortedMap.clear();
	IGUIElement *guiElement = dynamic_cast<IGUIElement*>(guiObject);
	guiElement->SetWidthRatio(m_fWidthRatio);
	guiElement->SetHeightRatio(m_fHeightRatio);
	guiElement->SetZoomFactor(m_fZoomFactor);
	guiElement->SetPageOffset(m_iPageOffsetX, m_iPageOffsetY);
	return MSG_HANDLED_STOP;
}