Example #1
0
GUIComponent *GUIComponent::get_previous_component_in_tree()
{
	if (impl->prev_sibling)
	{
		// return last grand-child of sibling.
		if (impl->prev_sibling->has_child_components())
		{
			GUIComponent *last = impl->prev_sibling->impl->last_child;
			while (last->has_child_components())
			{
				last = last->get_last_child();
			}
			return last;
		}
		else
		{
			// sibling has no children, return sibling.
			return impl->prev_sibling;
		}
	}

	// no previous sibling, return parent.
	if (impl->parent)
		return impl->parent;

	// No parent, must be top-level component. Find last child.
	GUIComponent *last = impl->last_child;

    // No child, must be a lonely top-level component.
    if(last == 0)
        return this;

	while (last->has_child_components())
	{
		last = last->get_last_child();
	}
	return last;
}