WgWidget * WgTablePanel::FindWidget( const WgCoord& ofs, WgSearchMode mode )
{
	// Check cell content

	int	xOfs;
	int yOfs;
	WgTableRow* pRow;

	int col = _getMarkedColumn( ofs.x, xOfs );
	int	row = _getMarkedRow( ofs.y, pRow, yOfs );

	WgWidget * pWidget = 0;

	if( col != -1 && row != -1 && pRow->GetHook(col)->IsVisible() )
	{
		if( xOfs < m_cellPadding.left || xOfs >= m_pColumns[col].m_realWidth - m_cellPadding.right ||
			yOfs < m_cellPadding.top || yOfs >= pRow->Height() - m_cellPadding.bottom )
		{
			pWidget = pRow->GetWidget(col);
			if( mode == WG_SEARCH_GEOMETRY || pWidget->MarkTest( WgCoord( xOfs-m_cellPadding.left, yOfs-m_cellPadding.top) )  )
				return pWidget;
		}
	}

	// Check ourselves

	if( mode == WG_SEARCH_GEOMETRY || MarkTest( ofs ) )
		return this;
	else
		return 0;
}
WgWidget *  WgPopupLayer::_findWidget( const WgCoord& ofs, WgSearchMode mode )
{
	// MenuPanel has its own _findWidget() method since we need special treatment of
	// searchmode ACTION_TARGET when a menu is open.

	if( mode == WG_SEARCH_ACTION_TARGET && !m_popupHooks.IsEmpty() )
	{
		// In search mode ACTION_TARGET we limit our target to us, our menu-branches and the menu-opener if a menu is open.

		WgPopupHook * pHook = m_popupHooks.Last();
		WgWidget * pResult = 0;

		while( pHook && !pResult )
		{
			if( pHook->m_geo.Contains( ofs ) )
			{
				if( pHook->_widget()->IsContainer() )
					pResult = static_cast<WgContainer*>(pHook->_widget())->_findWidget( ofs - pHook->m_geo.Pos(), mode );
				else if( pHook->_widget()->MarkTest( ofs - pHook->m_geo.Pos() ) )
					pResult = pHook->_widget();
			}
			pHook = pHook->_prev();
		}

		if( pResult == 0 )
		{
			// Check the first opener
			
			WgPopupHook * pHook = m_popupHooks.First();
			if( pHook && pHook->m_pOpener )
			{
				WgWidget * pOpener = pHook->m_pOpener.RawPtr();

				WgCoord absPos 		= ofs + GlobalPos();
				WgRect	openerGeo 	= pOpener->GlobalGeo();

				if( openerGeo.Contains(absPos) && pOpener->MarkTest( absPos - openerGeo.Pos() ) )
					pResult = pOpener;
			}
			
			// Fall back to us.
			
			if( pResult == 0 )
				pResult = this;
		}
		return pResult;
	}
	else
	{
		// For the rest of the modes we can rely on the default method.

		return WgContainer::_findWidget( ofs, mode );
	}
}