Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsNativeDragTarget Class Reference

#include <nsNativeDragTarget.h>

Collaboration diagram for nsNativeDragTarget:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsNativeDragTarget (nsIWidget *aWnd)
 ~nsNativeDragTarget ()
STDMETHODIMP QueryInterface (REFIID, void **)
 STDMETHODIMP_ (ULONG) AddRef()
 STDMETHODIMP_ (ULONG) Release()
STDMETHODIMP DragEnter (LPDATAOBJECT pSource, DWORD grfKeyState, POINTL point, DWORD *pEffect)
STDMETHODIMP DragOver (DWORD grfKeyState, POINTL point, DWORD *pEffect)
STDMETHODIMP DragLeave ()
STDMETHODIMP Drop (LPDATAOBJECT pSource, DWORD grfKeyState, POINTL point, DWORD *pEffect)

Protected Member Functions

void GetGeckoDragAction (LPDATAOBJECT pData, DWORD grfKeyState, LPDWORD pdwEffect, PRUint32 *aGeckoAction)
void ProcessDrag (LPDATAOBJECT pData, PRUint32 aEventType, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
void DispatchDragDropEvent (PRUint32 aType, POINTL pt)

Protected Attributes

ULONG m_cRef
HWND mHWnd
PRBool mCanMove
nsIWidgetmWindow
nsIDragServicemDragService

Detailed Description

Definition at line 55 of file nsNativeDragTarget.h.


Constructor & Destructor Documentation

Definition at line 77 of file nsNativeDragTarget.cpp.

  : m_cRef(0), mWindow(aWnd), mCanMove(PR_TRUE)
{
  mHWnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WINDOW);

  /*
   * Create/Get the DragService that we have implemented
   */
  CallGetService(kCDragServiceCID, &mDragService);
}

Here is the call graph for this function:

Definition at line 92 of file nsNativeDragTarget.cpp.


Member Function Documentation

void nsNativeDragTarget::DispatchDragDropEvent ( PRUint32  aType,
POINTL  pt 
) [protected]

Definition at line 184 of file nsNativeDragTarget.cpp.

{
  nsEventStatus status;
  nsMouseEvent event(PR_TRUE, aEventType, mWindow, nsMouseEvent::eReal);

  nsWindow * win = NS_STATIC_CAST(nsWindow *, mWindow);
  win->InitEvent(event);
  POINT cpos;

  cpos.x = aPT.x;
  cpos.y = aPT.y;

  if (mHWnd != NULL) {
    ::ScreenToClient(mHWnd, &cpos);
    event.point.x = cpos.x;
    event.point.y = cpos.y;
  } else {
    event.point.x = 0;
    event.point.y = 0;
  }

  event.isShift   = IsKeyDown(NS_VK_SHIFT);
  event.isControl = IsKeyDown(NS_VK_CONTROL);
  event.isMeta    = PR_FALSE;
  event.isAlt     = IsKeyDown(NS_VK_ALT);

  mWindow->DispatchEvent(&event, status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP nsNativeDragTarget::DragEnter ( LPDATAOBJECT  pSource,
DWORD  grfKeyState,
POINTL  point,
DWORD pEffect 
)

Definition at line 256 of file nsNativeDragTarget.cpp.

{
  if (DRAG_DEBUG) printf("DragEnter\n");

       if (!mDragService) {
              return ResultFromScode(E_FAIL);
  }

  // tell the drag service about this drag (it may have come from an
  // outside app).
  mDragService->StartDragSession();

  // Remember if this operation allows a move.
  mCanMove = (*pdwEffect) & DROPEFFECT_MOVE;

  // Set the native data object into drag service
  //
  // This cast is ok because in the constructor we created a
  // the actual implementation we wanted, so we know this is
  // a nsDragService. It should be a private interface, though.
  nsDragService * winDragService =
    NS_STATIC_CAST(nsDragService *, mDragService);
  winDragService->SetIDataObject(pIDataSource);

  // Now process the native drag state and then dispatch the event
  ProcessDrag(pIDataSource, NS_DRAGDROP_ENTER, grfKeyState, pt, pdwEffect);

  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP nsNativeDragTarget::DragLeave ( void  )

Definition at line 309 of file nsNativeDragTarget.cpp.

{
  if (DRAG_DEBUG) printf("DragLeave\n");

       if (!mDragService) {
              return ResultFromScode(E_FAIL);
  }

  // dispatch the event into Gecko
  DispatchDragDropEvent(NS_DRAGDROP_EXIT, gDragLastPoint);

  nsCOMPtr<nsIDragSession> currentDragSession;
  mDragService->GetCurrentSession(getter_AddRefs(currentDragSession));

  if (currentDragSession) {
    nsCOMPtr<nsIDOMNode> sourceNode;
    currentDragSession->GetSourceNode(getter_AddRefs(sourceNode));

    if (!sourceNode) {
      // We're leaving a window while doing a drag that was
      // initiated in a different app. End the drag session, since
      // we're done with it for now (until the user drags back into
      // mozilla).
      mDragService->EndDragSession();
    }
  }

  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP nsNativeDragTarget::DragOver ( DWORD  grfKeyState,
POINTL  point,
DWORD pEffect 
)

Definition at line 292 of file nsNativeDragTarget.cpp.

{
  if (DRAG_DEBUG) printf("DragOver\n");
       if (!mDragService) {
              return ResultFromScode(E_FAIL);
  }

  // Now process the native drag state and then dispatch the event
  ProcessDrag(nsnull, NS_DRAGDROP_OVER, grfKeyState, pt, pdwEffect);
  return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP nsNativeDragTarget::Drop ( LPDATAOBJECT  pSource,
DWORD  grfKeyState,
POINTL  point,
DWORD pEffect 
)

Definition at line 342 of file nsNativeDragTarget.cpp.

{
       if (!mDragService) {
              return ResultFromScode(E_FAIL);
  }

  // Set the native data object into the drag service
  //
  // This cast is ok because in the constructor we created a
  // the actual implementation we wanted, so we know this is
  // a nsDragService (but it should still be a private interface)
  nsDragService * winDragService =
    NS_STATIC_CAST(nsDragService *, mDragService);
  winDragService->SetIDataObject(pData);

  // Note: Calling ProcessDrag can destroy us; don't touch members after that.
  nsCOMPtr<nsIDragService> serv = mDragService;

  // Now process the native drag state and then dispatch the event
  ProcessDrag(pData, NS_DRAGDROP_DROP, grfKeyState, aPT, pdwEffect);

  // tell the drag service we're done with the session
  serv->EndDragSession();
  return S_OK;
}

Here is the call graph for this function:

void nsNativeDragTarget::GetGeckoDragAction ( LPDATAOBJECT  pData,
DWORD  grfKeyState,
LPDWORD  pdwEffect,
PRUint32 aGeckoAction 
) [protected]

Definition at line 141 of file nsNativeDragTarget.cpp.

{
  // Check if we can link from this data object as well.
  PRBool canLink = PR_FALSE;
  if (pData)
    canLink = (S_OK == ::OleQueryLinkFromData(pData) ? PR_TRUE : PR_FALSE);

  // Default is move if we can, in fact drop here,
  // and if the drop source supports a move operation.
  if (mCanMove) {
    *pdwEffect    = DROPEFFECT_MOVE;
    *aGeckoAction = nsIDragService::DRAGDROP_ACTION_MOVE;
  } else {
    *aGeckoAction = nsIDragService::DRAGDROP_ACTION_COPY;
    *pdwEffect    = DROPEFFECT_COPY;
  }

  // Given the key modifiers figure out what state we are in for both
  // the native system and Gecko
  if (grfKeyState & MK_CONTROL) {
    if (canLink && (grfKeyState & MK_SHIFT)) {
      *aGeckoAction = nsIDragService::DRAGDROP_ACTION_LINK;
      *pdwEffect    = DROPEFFECT_LINK;
    } else {
      *aGeckoAction = nsIDragService::DRAGDROP_ACTION_COPY;
      *pdwEffect    = DROPEFFECT_COPY;
    }
  }
}

Here is the caller graph for this function:

void nsNativeDragTarget::ProcessDrag ( LPDATAOBJECT  pData,
PRUint32  aEventType,
DWORD  grfKeyState,
POINTL  pt,
DWORD pdwEffect 
) [protected]

Definition at line 215 of file nsNativeDragTarget.cpp.

{
  // Before dispatching the event make sure we have the correct drop action set
  PRUint32 geckoAction;
  GetGeckoDragAction(pData, grfKeyState, pdwEffect, &geckoAction);

  // Set the current action into the Gecko specific type
  nsCOMPtr<nsIDragSession> currSession;
  mDragService->GetCurrentSession(getter_AddRefs(currSession));
  if (!currSession) {
    return;
  }

  currSession->SetDragAction(geckoAction);

  // Dispatch the event into Gecko
  DispatchDragDropEvent(aEventType, pt);

  // Now get the cached Drag effect from the drag service
  // the data memeber should have been set by who ever handled the
  // nsGUIEvent or nsIDOMEvent
  PRBool canDrop;
  currSession->GetCanDrop(&canDrop);
  if (!canDrop)
    *pdwEffect = DROPEFFECT_NONE;

  // Clear the cached value
  currSession->SetCanDrop(PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP nsNativeDragTarget::QueryInterface ( REFIID  riid,
void **  ppv 
)

Definition at line 101 of file nsNativeDragTarget.cpp.

{
  *ppv=NULL;

  if (IID_IUnknown == riid || IID_IDropTarget == riid)
    *ppv=this;

  if (NULL!=*ppv) {
    ((LPUNKNOWN)*ppv)->AddRef();
    return NOERROR;
  }

  return ResultFromScode(E_NOINTERFACE);
}

Member Data Documentation

Definition at line 102 of file nsNativeDragTarget.h.

Definition at line 104 of file nsNativeDragTarget.h.

Definition at line 108 of file nsNativeDragTarget.h.

Definition at line 103 of file nsNativeDragTarget.h.

Definition at line 107 of file nsNativeDragTarget.h.


The documentation for this class was generated from the following files: