Exemplo n.º 1
0
void WgTablist::_onEvent( const WgEventPtr& _pEvent, WgEventHandler * pHandler )
{
	WgWidget::_onEvent(_pEvent,pHandler);

	switch( _pEvent->Type() )
	{
		case WG_EVENT_TICK:
		{
			WgTickEventPtr pEvent = WgTickEvent::Cast(_pEvent);

			m_alertModeCnt -= pEvent->Millisec();
			if( m_alertModeCnt <= 0 )
			{
				m_bAlertOn = !m_bAlertOn;
				m_alertModeCnt = m_alertRate;		// This is right, we want it to stay in the new mode at least one frame.

				// Check if we have to render something...

				WgTab * pTab = m_tabs.First();
				while( pTab )
				{
					if( pTab->m_bAlert && pTab->m_bVisible )
					{
						_requestRender();			// Somewhat stupid to render all tabs though...
						break;
					}
					pTab = pTab->Next();
				}
			}
			break;
		}

		case WG_EVENT_MOUSE_PRESS:
		{
			WgMouseButtonEventPtr pEvent = WgMouseButtonEvent::Cast(_pEvent);

			WgCoord pos = pEvent->PointerPos();

			WgTab * pTab = _pos2Tab( pos.x, pos.y );
			if( pTab && pTab != m_pTabSelected )
			{
				if( pEvent->Button() == WG_BUTTON_LEFT )
					SelectTab(pTab->m_id);

				pHandler->QueueEvent( new WgItemMousePressEvent(this, pTab->m_id, WgObjectPtr(), pEvent->Button()) );
			}
		}
		break;

		case WG_EVENT_MOUSE_ENTER:
		case WG_EVENT_MOUSE_MOVE:
		{
			WgCoord pos = _pEvent->PointerPos();

			WgTab * pTab = _pos2Tab( pos.x, pos.y );
			if( pTab != m_pTabMarked )
			{
				m_pTabMarked = pTab;
				_requestRender();
			}
		}
		break;

		case WG_EVENT_MOUSE_LEAVE:
			if( m_pTabMarked )
			{
				m_pTabMarked = 0;
				_requestRender();
			}
		break;

        default:
            break;
	}

	// Swallow event depending on rules.

	if( _pEvent->IsMouseButtonEvent() && WgMouseButtonEvent::Cast(_pEvent)->Button() == WG_BUTTON_LEFT )
		pHandler->SwallowEvent(_pEvent);
}
Exemplo n.º 2
0
void WgPopupLayer::_onEvent( const WgEventPtr& _pEvent, WgEventHandler * pHandler )
{
	WgLayer::_onEvent(_pEvent,pHandler);

	WgWidget * pOpener = 0;

	// Try to find an opener

	WgWidget * pOrigin = _pEvent->Widget();
	if( pOrigin && pOrigin != this )
	{
		WgPopupHook * pHook = m_popupHooks.First();
		while( pHook && pHook->_widget() != pOrigin )
			pHook = pHook->_next();
			
		if( pHook && pHook->m_pOpener )
			pOpener = pHook->m_pOpener.RawPtr();
	}
	
	// First we try to forward event to opener (if any)

	if( pOpener )
	{
		pHandler->ForwardEvent( _pEvent, pOpener );
		return;
	}	

	// Secondly we take care of event ourselves if it is addressed to one of our menus or us.

	switch( _pEvent->Type() )
	{
/*
		case WG_EVENT_MOUSE_POSITION:

			if( !m_popupHooks.IsEmpty() )							// Process only if we have at least one open menu.
			{
				WgCoord ofs = _pEvent->PointerPos();
				WgWidget * p = _findWidget( ofs, WG_SEARCH_ACTION_TARGET );
				if( p != this )
				{
					while( p->Parent() != this )
						p = p->Parent();
						
					if( p != m_popupHooks.	
				}	
			}
		break;
*/		
		case WG_EVENT_MOUSE_RELEASE:
		case WG_EVENT_MOUSE_PRESS:
		{
			WgMouseButtonEventPtr pEvent = WgMouseButtonEvent::Cast(_pEvent);

			WgCoord ofs = pEvent->PointerPos();
			WgWidget * p = _findWidget( ofs, WG_SEARCH_ACTION_TARGET );
			if( p == this )
			{
				CloseAllPopups();
				pHandler->SwallowEvent( _pEvent );
				return;
			}
		}
		break;

		case WG_EVENT_KEY_PRESS:
		case WG_EVENT_KEY_REPEAT:
		{
			WgKeyEventPtr pEvent = WgKeyEvent::Cast(_pEvent);

			if( pEvent->TranslatedKeyCode() == WG_KEY_ESCAPE )
			{
				if( !m_popupHooks.IsEmpty() )
				{
					ClosePopup( m_popupHooks.Last()->_widget() );
					pHandler->SwallowEvent( _pEvent );
					return;
				}
			}

		}
		break;
	}
}