예제 #1
0
//-----------------------------------------------------------------------------
// Purpose: Calculate the new key focus
//-----------------------------------------------------------------------------
VPanel *CInputWin32::CalculateNewKeyFocus()
{
	InputContext_t *pContext = GetInputContext(m_hContext);

	// get the top-order panel
	VPanel *top = NULL;
	VPanel *wantedKeyFocus = NULL;

	if (!pContext->_rootPanel)
	{
		if (surface()->GetPopupCount() > 0)
		{
			// find the highest-level window that is both visible and a popup
			int index = surface()->GetPopupCount();
			
			while (index)
			{
				
				top = (VPanel *)surface()->GetPopup(--index);

				// traverse the heirachy and check if the popup really is visible
				if (top->IsPopup() && top->IsVisible() && top->IsKeyBoardInputEnabled() && !surface()->IsMinimized((VPANEL)top))
				{
					bool IsVisible = top->IsVisible();
					VPanel *p = top->GetParent();
					// drill down the heirachy checking that everything is visible
					while(p && IsVisible)
					{
						if( p->IsVisible()==false)
						{
							IsVisible=false;
							break;
						}
						p=p->GetParent();
					}

					if (IsVisible && !surface()->IsMinimized((VPANEL)top) )
					{
						break;
					}
				}
				
				top = NULL;
			} 
		}
	}
	else
	{
		top = (VPanel *)pContext->_rootPanel;
	}

	if (top)
	{
		// ask the top-level panel for what it considers to be the current focus
		wantedKeyFocus = (VPanel *)top->Client()->GetCurrentKeyFocus();
		if (!wantedKeyFocus)
		{
			wantedKeyFocus = top;

		}
	}

	// check to see if any of this surfaces panels have the focus
	if (!surface()->HasFocus())
	{
		wantedKeyFocus=NULL;
	}

	// check if we are in modal state, 
	// and if we are make sure this panel is a child of us.
	if (!IsChildOfModalPanel((VPANEL)wantedKeyFocus))
	{	
		wantedKeyFocus=NULL;
	}

	return wantedKeyFocus;
}
예제 #2
0
//-----------------------------------------------------------------------------
// Purpose: Sets the new mouse focus
//			won't override _mouseCapture settings
// Input  : newMouseFocus - 
//-----------------------------------------------------------------------------
void CInputWin32::SetMouseFocus(VPANEL newMouseFocus)
{
	// check if we are in modal state, 
	// and if we are make sure this panel is a child of us.
	if (!IsChildOfModalPanel(newMouseFocus))
	{	
		return;	
	}

	bool wantsMouse, isPopup; // =  popup->GetMouseInput();
	VPanel *panel = (VPanel *)newMouseFocus;

	InputContext_t *pContext = GetInputContext( m_hContext );

	
	if ( newMouseFocus )
	{
		do 
		{
			wantsMouse = panel->IsMouseInputEnabled();
			isPopup = panel->IsPopup();
			panel = panel->GetParent();
		}
		while ( wantsMouse && !isPopup && panel && panel->GetParent() ); // only consider panels that want mouse input
	}

	// if this panel doesn't want mouse input don't let it get focus
	if (newMouseFocus && !wantsMouse) 
	{
		return;
	}

	if ((VPANEL)pContext->_mouseOver != newMouseFocus || (!pContext->_mouseCapture && (VPANEL)pContext->_mouseFocus != newMouseFocus) )
	{
		pContext->_oldMouseFocus = pContext->_mouseOver;
		pContext->_mouseOver = (VPanel *)newMouseFocus;

		//tell the old panel with the mouseFocus that the cursor exited
		if (pContext->_oldMouseFocus != NULL)
		{
			// only notify of entry if the mouse is not captured or we're a child of the captured panel
			if ( !pContext->_mouseCapture || pContext->_oldMouseFocus->HasParent(pContext->_mouseCapture) )
			{
				ivgui()->PostMessage((VPANEL)pContext->_oldMouseFocus, new KeyValues("CursorExited"), NULL);
			}
		}

		//tell the new panel with the mouseFocus that the cursor entered
		if (pContext->_mouseOver != NULL)
		{
			// only notify of entry if the mouse is not captured or we're a child of the captured panel
			if ( !pContext->_mouseCapture || pContext->_mouseOver->HasParent(pContext->_mouseCapture) )
			{
				ivgui()->PostMessage((VPANEL)pContext->_mouseOver, new KeyValues("CursorEntered"), NULL);
			}
		}

		// set where the mouse is currently over
		// mouse capture overrides destination
		if ( pContext->_mouseCapture )
		{
			pContext->_mouseFocus = pContext->_mouseCapture;
		}
		else
		{
			pContext->_mouseFocus = pContext->_mouseOver;
		}
	}
}
예제 #3
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CInputWin32::RunFrame()
{
	InputContext_t *pContext = GetInputContext(m_hContext);

	if (m_hContext == DEFAULT_INPUT_CONTEXT)
	{
		_updateToggleButtonState = true;

	/*	FIXME: add the set cursor call?
		// make sure the cursor looks like it is supposed to
		if (pContext->_mouseFocus)
		{
			pContext->_mouseFocus->Client()->InternalSetCursor();
		}*/
	}


	// tick whoever has the focus
	if (pContext->_keyFocus)
	{
		// when modal dialogs are up messages only get sent to the dialogs children.
		if (IsChildOfModalPanel((VPANEL)pContext->_keyFocus))
		{	
			ivgui()->PostMessage((VPANEL)pContext->_keyFocus, new KeyValues("KeyFocusTicked"), NULL);
		}
	}

	// tick whoever has the focus
	if (pContext->_mouseFocus)
	{
		// when modal dialogs are up messages only get sent to the dialogs children.
		if (IsChildOfModalPanel((VPANEL)pContext->_mouseFocus))
		{	
			ivgui()->PostMessage((VPANEL)pContext->_mouseFocus, new KeyValues("MouseFocusTicked"), NULL);
		}
	}

	//clear mouse and key states
	for (int i = 0; i < MOUSE_LAST; i++)
	{
		pContext->_mousePressed[i] = 0;
		pContext->_mouseDoublePressed[i] = 0;
		pContext->_mouseReleased[i] = 0;
	}
	for (i = 0; i < KEY_LAST; i++)
	{
		pContext->_keyPressed[i] = 0;
		pContext->_keyTyped[i] = 0;
		pContext->_keyReleased[i] = 0;
	}

	VPanel *wantedKeyFocus = CalculateNewKeyFocus();

	// make sure old and new focus get painted
	if (pContext->_keyFocus != wantedKeyFocus)
	{
		if (pContext->_keyFocus != NULL)
		{
			pContext->_keyFocus->Client()->InternalFocusChanged(true);

			// send a message to the window saying that it's losing focus
			ivgui()->PostMessage((VPANEL)pContext->_keyFocus, new KeyValues("KillFocus"), NULL);

			pContext->_keyFocus->Client()->Repaint();

			// repaint the nearest popup as well, since it will need to redraw after losing focus
			VPanel *dlg = pContext->_keyFocus;
			while (dlg && !dlg->IsPopup())
			{
				dlg = dlg->GetParent();
			}
			if (dlg)
			{
				dlg->Client()->Repaint();
			}
		}
		if (wantedKeyFocus != NULL)
		{
			wantedKeyFocus->Client()->InternalFocusChanged(false);

			// send a message to the window saying that it's gaining focus
			ivgui()->PostMessage((VPANEL)wantedKeyFocus, new KeyValues("SetFocus"), NULL);
			wantedKeyFocus->Client()->Repaint();

			// repaint the nearest popup as well, since it will need to redraw after gaining focus
			VPanel *dlg = wantedKeyFocus;
			while (dlg && !dlg->IsPopup())
			{
				dlg = dlg->GetParent();
			}
			if (dlg)
			{
				dlg->Client()->Repaint();
			}
		}

		// accept the focus request
		pContext->_keyFocus = wantedKeyFocus;
		if (pContext->_keyFocus)
		{
			pContext->_keyFocus->MoveToFront();
		}
	}
}