HRESULT DropTargetWin::DragEnter(IDataObject* data_object,
                                  DWORD key_state,
                                  POINTL cursor_position,
                                  DWORD* effect) {
  if (!callback_)
    return E_UNEXPECTED;

  HRESULT hr;
  IDropTargetHelper* drop_helper = DropHelper();
  if (drop_helper) {
	  hr = drop_helper->DragEnter(hWnd_, data_object,
		  reinterpret_cast<POINT*>(&cursor_position), *effect);
  }

  CefRefPtr<CefDragData> drag_data = current_drag_data_;
  if (!drag_data) {
    drag_data = DataObjectToDragData(data_object);
  }

  CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
  CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
  mask = callback_->OnDragEnter(drag_data, ev, mask);
  *effect = DragOperationToDropEffect(mask);
  return S_OK;
}
HRESULT DropTargetWin::DragOver(DWORD key_state,
                                POINTL cursor_position,
                                DWORD* effect) {
  if (!callback_)
    return E_UNEXPECTED;
  CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
  CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
  mask = callback_->OnDragOver(ev, mask);
  *effect = DragOperationToDropEffect(mask);
  return S_OK;
}
HRESULT DropTargetWin::DragEnter(IDataObject* data_object,
                                  DWORD key_state,
                                  POINTL cursor_position,
                                  DWORD* effect) {
  if (!callback_)
    return E_UNEXPECTED;

  CefRefPtr<CefDragData> drag_data = current_drag_data_;
  if (!drag_data) {
    drag_data = DataObjectToDragData(data_object);
  }
  CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
  CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
  mask = callback_->OnDragEnter(drag_data, ev, mask);
  *effect = DragOperationToDropEffect(mask);
  return S_OK;
}
HRESULT DropTargetWin::DragOver(DWORD key_state,
                                POINTL cursor_position,
                                DWORD* effect) {
  if (!callback_)
    return E_UNEXPECTED;

  // Tell the helper that we moved over it so it can update the drag image.
  IDropTargetHelper* drop_helper = DropHelper();
  if (drop_helper)
	  drop_helper->DragOver(reinterpret_cast<POINT*>(&cursor_position), *effect);

  CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
  CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
  mask = callback_->OnDragOver(ev, mask);
  *effect = DragOperationToDropEffect(mask);
  return S_OK;
}
    bool CCoherentInputEventListener::OnInputEvent( const SInputEvent& event )
    {
        // Process special keys that toggle a function
        if ( event.deviceId == eDI_Keyboard && ( event.state & eIS_Released ) )
        {
            switch ( event.keyId )
            {
                case eKI_NP_0:
                    m_PlayerInputEnabled = !m_PlayerInputEnabled;
                    if (gEnv->pGame && gEnv->pGame->GetIGameFramework())
                    {
                        gEnv->pGame->GetIGameFramework()->GetIActionMapManager()->EnableActionMap( "player", m_PlayerInputEnabled );
                    }
                    return false;

                    // NP_1 starts raycasting so don't use it
                case eKI_NP_2:
                    m_DrawCoherentUI = !m_DrawCoherentUI;
                    return false;

                case eKI_NP_3:
                    m_DrawCursor = !m_DrawCursor;
                    ::ShowCursor( m_DrawCursor );

                    if ( gEnv && gEnv->pSystem && gEnv->pSystem->GetIHardwareMouse() )
                    {
                        if ( m_DrawCursor )
                        {
                            gEnv->pSystem->GetIHardwareMouse()->IncrementCounter();
                        }

                        else
                        {
                            gEnv->pSystem->GetIHardwareMouse()->DecrementCounter();
                        }
                    }

                    return false;

                case eKI_NP_4:
                    {
                        EntityId id = gEnv->pGame->GetIGameFramework()->GetClientActor()->GetGameObject()->GetWorldQuery()->GetLookAtEntityId();
                        IEntity* pEntityInFront = gEnv->pEntitySystem->GetEntity( id );

                        if ( pEntityInFront )
                        {
                            OutputDebugString( pEntityInFront->GetName() );
                        }
                    }

                    return false;

                case eKI_NP_5:
                    {
                        CCamera& cam = gEnv->pSystem->GetViewCamera();
                        int vpWidth = gEnv->pRenderer->GetWidth();
                        int vpHeight = gEnv->pRenderer->GetHeight();
                        float proj22 = 1.0f / cry_tanf( cam.GetFov() / 2.0f );
                        float proj11 = proj22 / cam.GetProjRatio();
                        float viewX = ( ( ( 2.0f * ( float )GetMouseX() ) / vpWidth ) - 1.0f ) / proj11;
                        float viewY = ( ( ( -2.0f * ( float )GetMouseY() ) / vpHeight ) + 1.0f ) / proj22;
                        Matrix34 invView = cam.GetMatrix();
                        Vec3 dir = invView.TransformVector( Vec3( viewX, 1.0f, viewY ) ); // Z is up
                        dir.Normalize();
                        dir *= 1000.0f;

                        Vec3 origin = cam.GetPosition();

                        ray_hit hit;
                        IPhysicalEntity* pSkipEnt = nullptr;
                        int hitCount = gEnv->pPhysicalWorld->RayWorldIntersection( origin, dir,
                                       ent_sleeping_rigid | ent_rigid,
                                       rwi_stop_at_pierceable | rwi_colltype_any, &hit, 1, pSkipEnt );

                        if ( hitCount > 0 )
                        {
                            IEntity* pEntity = gEnv->pEntitySystem->GetEntityFromPhysics( hit.pCollider );
                            OutputDebugString( pEntity->GetName() );
                        }
                    }

                    return false;

                case eKI_NP_6:
                    {
                        int dummyx, dummyy;
                        CCoherentViewListener* pViewListener;
                        TraceMouse( dummyx, dummyy, pViewListener );
                    }

                    return false;
            }
        }


        // Send input to Coherent UI only when the player input is disabled
        if ( m_PlayerInputEnabled )
        {
            return false;
        }

        if ( event.deviceId == eDI_Keyboard )
        {
            if ( !m_pLastFocusedViewListener || !m_pLastFocusedViewListener->GetView() )
            {
                return false;
            }

            Coherent::UI::KeyEventData keyEvent;

            if ( ToKeyEventData( event, keyEvent ) )
            {
                // Enter needs to be sent as KeyDown to work
                if ( keyEvent.KeyCode == 13 )
                {
                    keyEvent.Type = Coherent::UI::KeyEventData::KeyDown;
                    m_pLastFocusedViewListener->GetView()->KeyEvent( keyEvent );
                    keyEvent.Type = Coherent::UI::KeyEventData::Char;
                }

                m_pLastFocusedViewListener->GetView()->KeyEvent( keyEvent );
            }
        }

        else if ( event.deviceId == eDI_Mouse )
        {
            Coherent::UI::MouseEventData mouseEvent;
            int mouseX, mouseY;

            if ( ToMouseEvent( event, mouseEvent ) && TraceMouse( mouseX, mouseY, m_pLastFocusedViewListener ) )
            {
                mouseEvent.X = mouseX;
                mouseEvent.Y = mouseY;

                if ( m_pLastFocusedViewListener->GetView() )
                {
                    m_pLastFocusedViewListener->GetView()->MouseEvent( mouseEvent );
                }
            }
        }

        return false;
    }