Back to index

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

#include <nsDataObj.h>

Collaboration diagram for nsDataObj:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsDataObj (nsIURI *uri=nsnull)
 ~nsDataObj ()
 STDMETHODIMP_ (ULONG) AddRef()
STDMETHODIMP QueryInterface (REFIID, void **)
 STDMETHODIMP_ (ULONG) Release()
void AddDataFlavor (const char *aDataFlavor, LPFORMATETC aFE)
void SetTransferable (nsITransferable *aTransferable)
CLSID GetClassID () const
STDMETHODIMP GetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM)
STDMETHODIMP GetDataHere (LPFORMATETC pFE, LPSTGMEDIUM pSTM)
STDMETHODIMP QueryGetData (LPFORMATETC pFE)
STDMETHODIMP GetCanonicalFormatEtc (LPFORMATETC pFE, LPFORMATETC pCanonFE)
STDMETHODIMP SetData (LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL release)
STDMETHODIMP EnumFormatEtc (DWORD direction, LPENUMFORMATETC *ppEnum)
STDMETHODIMP DAdvise (LPFORMATETC pFE, DWORD flags, LPADVISESINK pAdvise, DWORD *pConn)
STDMETHODIMP DUnadvise (DWORD pConn)
STDMETHODIMP EnumDAdvise (LPENUMSTATDATA *ppEnum)
ULONG GetRefCount () const

Static Public Member Functions

static ULONG GetCumRefCount ()

Protected Member Functions

PRBool IsInternetShortcut ()
virtual HRESULT AddSetFormat (FORMATETC &FE)
virtual HRESULT AddGetFormat (FORMATETC &FE)
virtual HRESULT GetText (const nsACString &aDF, FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetFile (const nsACString &aDF, FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetBitmap (const nsACString &inFlavor, FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT GetDib (const nsACString &inFlavor, FORMATETC &, STGMEDIUM &aSTG)
virtual HRESULT GetMetafilePict (FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT GetUniformResourceLocator (FORMATETC &aFE, STGMEDIUM &aSTG, PRBool aIsUnicode)
virtual HRESULT ExtractUniformResourceLocatorA (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT ExtractUniformResourceLocatorW (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetFileDescriptor (FORMATETC &aFE, STGMEDIUM &aSTG, PRBool aIsUnicode)
virtual HRESULT GetFileContents (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetPreferredDropEffect (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT SetBitmap (FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT SetDib (FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT SetText (FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT SetMetafilePict (FORMATETC &FE, STGMEDIUM &STM)
virtual HRESULT GetFileDescriptorInternetShortcutA (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetFileDescriptorInternetShortcutW (FORMATETC &aFE, STGMEDIUM &aSTG)
virtual HRESULT GetFileContentsInternetShortcut (FORMATETC &aFE, STGMEDIUM &aSTG)
nsresult ExtractShortcutURL (nsString &outURL)
nsresult ExtractShortcutTitle (nsString &outTitle)
nsresult BuildPlatformHTML (const char *inOurHTML, char **outPlatformHTML)
BOOL FormatsMatch (const FORMATETC &source, const FORMATETC &target) const

Protected Attributes

nsCString mSourceURL
nsString mStringData
ULONG m_cRef
nsVoidArraymDataFlavors
nsITransferablemTransferable
CEnumFormatEtc * m_enumFE
nsCOMPtr< nsILocalFilemCachedTempFile

Static Protected Attributes

static ULONG g_cRef = 0

Detailed Description

Definition at line 115 of file nsDataObj.h.


Constructor & Destructor Documentation

Definition at line 102 of file nsDataObj.cpp.

: m_cRef(0), mTransferable(nsnull)
{
  mDataFlavors    = new nsVoidArray();
  m_enumFE        = new CEnumFormatEtc(32);
 
  m_enumFE->AddRef();

  if (uri) {

    // A URI was obtained, so pass this through to the DataObject
    // so it can create a SourceURL for CF_HTML flavour
    uri->GetSpec(mSourceURL);
  }
}

Here is the call graph for this function:

Definition at line 120 of file nsDataObj.cpp.

{
  NS_IF_RELEASE(mTransferable);
  PRInt32 i;
  for (i=0;i<mDataFlavors->Count();i++) {
    nsCAutoString* df = NS_REINTERPRET_CAST(nsCAutoString *, mDataFlavors->ElementAt(i));
    delete df;
  }

  delete mDataFlavors;

  m_cRef = 0;
  m_enumFE->Release();

}

Member Function Documentation

void nsDataObj::AddDataFlavor ( const char *  aDataFlavor,
LPFORMATETC  aFE 
)

Definition at line 1065 of file nsDataObj.cpp.

{
  // These two lists are the mapping to and from data flavors and FEs
  // Later, OLE will tell us it's needs a certain type of FORMATETC (text, unicode, etc)
  // so we will look up data flavor that corresponds to the FE
  // and then ask the transferable for that type of data

  // Add CF_HDROP to the head of the list so that it is returned first
  // when the drop target calls EnumFormatEtc to enumerate through the FE list
  // We use the CF_HDROP format to copy file contents when an image is dragged
  // from Mozilla to a drop target.
#ifndef WINCE
  if (aFE->cfFormat == CF_HDROP) {
    mDataFlavors->InsertElementAt(new nsCAutoString(aDataFlavor), 0);
    m_enumFE->InsertFEAt(aFE, 0);
  }  
  else 
#endif
  {
    mDataFlavors->AppendElement(new nsCAutoString(aDataFlavor));
    m_enumFE->AddFE(aFE);
  }
}

Here is the caller graph for this function:

HRESULT nsDataObj::AddGetFormat ( FORMATETC &  FE) [protected, virtual]

Definition at line 409 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::AddGetFormat\n");
       return ResultFromScode(S_OK);
}
HRESULT nsDataObj::AddSetFormat ( FORMATETC &  FE) [protected, virtual]

Definition at line 402 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::AddSetFormat\n");
       return ResultFromScode(S_OK);
}
nsresult nsDataObj::BuildPlatformHTML ( const char *  inOurHTML,
char **  outPlatformHTML 
) [protected]

Definition at line 1210 of file nsDataObj.cpp.

{
  *outPlatformHTML = nsnull;

  nsDependentCString inHTMLString(inOurHTML);
  const char* const numPlaceholder  = "00000000";
  const char* const startHTMLPrefix = "Version:0.9\r\nStartHTML:";
  const char* const endHTMLPrefix   = "\r\nEndHTML:";
  const char* const startFragPrefix = "\r\nStartFragment:";
  const char* const endFragPrefix   = "\r\nEndFragment:";
  const char* const startSourceURLPrefix = "\r\nSourceURL:";
  const char* const endFragTrailer  = "\r\n";

  // Do we already have mSourceURL from a drag?
  if (mSourceURL.IsEmpty()) {
    nsAutoString url;
    ExtractShortcutURL(url);

    AppendUTF16toUTF8(url, mSourceURL);
  }

  const PRInt32 kSourceURLLength    = mSourceURL.Length();
  const PRInt32 kNumberLength       = strlen(numPlaceholder);

  const PRInt32 kTotalHeaderLen     = strlen(startHTMLPrefix) +
                                      strlen(endHTMLPrefix) +
                                      strlen(startFragPrefix) + 
                                      strlen(endFragPrefix) + 
                                      strlen(endFragTrailer) +
                                      (kSourceURLLength > 0 ? strlen(startSourceURLPrefix) : 0) +
                                      kSourceURLLength +
                                      (4 * kNumberLength);

  NS_NAMED_LITERAL_CSTRING(htmlHeaderString, "<html><body>\r\n");

  NS_NAMED_LITERAL_CSTRING(fragmentHeaderString, "<!--StartFragment-->");

  nsDependentCString trailingString(
      "<!--EndFragment-->\r\n"
      "</body>\r\n"
      "</html>");

  // calculate the offsets
  PRInt32 startHTMLOffset = kTotalHeaderLen;
  PRInt32 startFragOffset = startHTMLOffset
                              + htmlHeaderString.Length()
                           + fragmentHeaderString.Length();

  PRInt32 endFragOffset   = startFragOffset
                              + inHTMLString.Length();

  PRInt32 endHTMLOffset   = endFragOffset
                              + trailingString.Length();

  // now build the final version
  nsCString clipboardString;
  clipboardString.SetCapacity(endHTMLOffset);

  clipboardString.Append(startHTMLPrefix);
  clipboardString.Append(nsPrintfCString("%08u", startHTMLOffset));

  clipboardString.Append(endHTMLPrefix);  
  clipboardString.Append(nsPrintfCString("%08u", endHTMLOffset));

  clipboardString.Append(startFragPrefix);
  clipboardString.Append(nsPrintfCString("%08u", startFragOffset));

  clipboardString.Append(endFragPrefix);
  clipboardString.Append(nsPrintfCString("%08u", endFragOffset));

  if (kSourceURLLength > 0) {
    clipboardString.Append(startSourceURLPrefix);
    clipboardString.Append(mSourceURL);
  }

  clipboardString.Append(endFragTrailer);

  clipboardString.Append(htmlHeaderString);
  clipboardString.Append(fragmentHeaderString);
  clipboardString.Append(inHTMLString);
  clipboardString.Append(trailingString);

  *outPlatformHTML = ToNewCString(clipboardString);
  if (!*outPlatformHTML)
    return NS_ERROR_OUT_OF_MEMORY;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP nsDataObj::DAdvise ( LPFORMATETC  pFE,
DWORD  flags,
LPADVISESINK  pAdvise,
DWORD pConn 
)

Definition at line 363 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::DAdvise\n");
       return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::DUnadvise ( DWORD  pConn)

Definition at line 372 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::DUnadvise\n");
       return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::EnumDAdvise ( LPENUMSTATDATA *  ppEnum)

Definition at line 379 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::EnumDAdvise\n");
       return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::EnumFormatEtc ( DWORD  direction,
LPENUMFORMATETC *  ppEnum 
)

Definition at line 334 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::EnumFormatEtc\n");

  switch (dwDir) {
    case DATADIR_GET: {
       m_enumFE->Clone(ppEnum);
    } break;
    case DATADIR_SET:
        *ppEnum=NULL;
        break;
    default:
        *ppEnum=NULL;
        break;
  } // switch

  // Since a new one has been created, 
  // we will ref count the new clone here 
  // before giving it back
  if (NULL == *ppEnum)
    return ResultFromScode(E_FAIL);
  else
    (*ppEnum)->AddRef();

  return NOERROR;

}
nsresult nsDataObj::ExtractShortcutTitle ( nsString outTitle) [protected]

Definition at line 1168 of file nsDataObj.cpp.

{
  NS_ASSERTION ( mTransferable, "We'd don't have a good transferable" );
  nsresult rv = NS_ERROR_FAILURE;
  
  PRUint32 len = 0;
  nsCOMPtr<nsISupports> genericURL;
  if ( NS_SUCCEEDED(mTransferable->GetTransferData(kURLMime, getter_AddRefs(genericURL), &len)) ) {
    nsCOMPtr<nsISupportsString> urlObject ( do_QueryInterface(genericURL) );
    if ( urlObject ) {
      nsAutoString url;
      urlObject->GetData ( url );

      // find the first linefeed in the data, that's where the url ends. we want
      // everything after that linefeed. FindChar() returns -1 if we can't find
      PRInt32 lineIndex = url.FindChar ( '\n' );
      NS_ASSERTION ( lineIndex != -1, "Format for url flavor is <url> <linefeed> <page title>" );
      if ( lineIndex != -1 ) {
        url.Mid ( outTitle, lineIndex + 1, (len/2) - (lineIndex + 1) );
        rv = NS_OK;    
      }
    }
  } // if found flavor
  
  return rv;

} // ExtractShortcutTitle

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDataObj::ExtractShortcutURL ( nsString outURL) [protected]

Definition at line 1117 of file nsDataObj.cpp.

{
  NS_ASSERTION ( mTransferable, "We don't have a good transferable" );
  nsresult rv = NS_ERROR_FAILURE;
  
  PRUint32 len = 0;
  nsCOMPtr<nsISupports> genericURL;
  if ( NS_SUCCEEDED(mTransferable->GetTransferData(kURLMime, getter_AddRefs(genericURL), &len)) ) {
    nsCOMPtr<nsISupportsString> urlObject ( do_QueryInterface(genericURL) );
    if ( urlObject ) {
      nsAutoString url;
      urlObject->GetData ( url );
      outURL = url;

      // find the first linefeed in the data, that's where the url ends. trunc the 
      // result string at that point.
      PRInt32 lineIndex = outURL.FindChar ( '\n' );
      NS_ASSERTION ( lineIndex > 0, "Format for url flavor is <url> <linefeed> <page title>" );
      if ( lineIndex > 0 ) {
        outURL.Truncate ( lineIndex );
        rv = NS_OK;    
      }
    }
  } else if ( NS_SUCCEEDED(mTransferable->GetTransferData(kURLDataMime, getter_AddRefs(genericURL), &len)) ||
              NS_SUCCEEDED(mTransferable->GetTransferData(kURLPrivateMime, getter_AddRefs(genericURL), &len)) ) {
    nsCOMPtr<nsISupportsString> urlObject ( do_QueryInterface(genericURL) );
    if ( urlObject ) {
      nsAutoString url;
      urlObject->GetData ( url );
      outURL = url;

      rv = NS_OK;    
    }

  }  // if found flavor
  
  return rv;

} // ExtractShortcutURL

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::ExtractUniformResourceLocatorA ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 1315 of file nsDataObj.cpp.

{
  HRESULT result = S_OK;

  nsAutoString url;
  if (NS_FAILED(ExtractShortcutURL(url)))
    return E_OUTOFMEMORY;

  NS_LossyConvertUTF16toASCII asciiUrl(url);
  const int totalLen = asciiUrl.Length() + 1;
  HGLOBAL hGlobalMemory = GlobalAlloc(GMEM_ZEROINIT|GMEM_SHARE, totalLen);
  if (!hGlobalMemory)
    return E_OUTOFMEMORY;

  char* contents = NS_REINTERPRET_CAST(char*, GlobalLock(hGlobalMemory));
  if (!contents) {
    GlobalFree(hGlobalMemory);
    return E_OUTOFMEMORY;
  }

  strcpy(contents, asciiUrl.get());
  GlobalUnlock(hGlobalMemory);
  aSTG.hGlobal = hGlobalMemory;
  aSTG.tymed = TYMED_HGLOBAL;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::ExtractUniformResourceLocatorW ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 1344 of file nsDataObj.cpp.

{
  HRESULT result = S_OK;

  nsAutoString url;
  if (NS_FAILED(ExtractShortcutURL(url)))
    return E_OUTOFMEMORY;

  const int totalLen = (url.Length() + 1) * sizeof(PRUnichar);
  HGLOBAL hGlobalMemory = GlobalAlloc(GMEM_ZEROINIT|GMEM_SHARE, totalLen);
  if (!hGlobalMemory)
    return E_OUTOFMEMORY;

  wchar_t* contents = NS_REINTERPRET_CAST(wchar_t*, GlobalLock(hGlobalMemory));
  if (!contents) {
    GlobalFree(hGlobalMemory);
    return E_OUTOFMEMORY;
  }

  wcscpy(contents, url.get());
  GlobalUnlock(hGlobalMemory);
  aSTG.hGlobal = hGlobalMemory;
  aSTG.tymed = TYMED_HGLOBAL;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsDataObj::FormatsMatch ( const FORMATETC &  source,
const FORMATETC &  target 
) const [protected]

Definition at line 181 of file nsDataObj.cpp.

{
       if ((source.cfFormat == target.cfFormat) &&
               (source.dwAspect  & target.dwAspect)  &&
               (source.tymed     & target.tymed))       {
              return TRUE;
       } else {
              return FALSE;
       }
}

Here is the caller graph for this function:

HRESULT nsDataObj::GetBitmap ( const nsACString &  inFlavor,
FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 417 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::GetBitmap\n");
       return ResultFromScode(E_NOTIMPL);
}
STDMETHODIMP nsDataObj::GetCanonicalFormatEtc ( LPFORMATETC  pFE,
LPFORMATETC  pCanonFE 
)

Definition at line 302 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::GetCanonicalFormatEtc\n");
              return ResultFromScode(E_FAIL);
}
CLSID nsDataObj::GetClassID ( ) const

Definition at line 1057 of file nsDataObj.cpp.

{
       return CLSID_nsDataObj;
}

Definition at line 388 of file nsDataObj.cpp.

{
       return g_cRef;
}
STDMETHODIMP nsDataObj::GetData ( LPFORMATETC  pFE,
LPSTGMEDIUM  pSTM 
)

Definition at line 195 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::GetData\n");
  PRNTDEBUG3("  format: %d  Text: %d\n", pFE->cfFormat, CF_TEXT);
  if ( !mTransferable )
         return ResultFromScode(DATA_E_FORMATETC);

  PRUint32 dfInx = 0;

  static CLIPFORMAT fileDescriptorFlavorA = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORA ); 
  static CLIPFORMAT fileDescriptorFlavorW = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORW ); 
  static CLIPFORMAT uniformResourceLocatorA = ::RegisterClipboardFormat( CFSTR_INETURLA );
  static CLIPFORMAT uniformResourceLocatorW = ::RegisterClipboardFormat( CFSTR_INETURLW );
#ifndef WINCE
  static CLIPFORMAT fileFlavor = ::RegisterClipboardFormat( CFSTR_FILECONTENTS ); 
  static CLIPFORMAT PreferredDropEffect = ::RegisterClipboardFormat( CFSTR_PREFERREDDROPEFFECT );
#endif

  ULONG count;
  FORMATETC fe;
  m_enumFE->Reset();
  while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
    nsCAutoString * df = NS_REINTERPRET_CAST(nsCAutoString*, mDataFlavors->SafeElementAt(dfInx));
    if ( df ) {
      if (FormatsMatch(fe, *pFE)) {
        pSTM->pUnkForRelease = NULL;        // caller is responsible for deleting this data
        CLIPFORMAT format = pFE->cfFormat;
        switch(format) {

        // Someone is asking for plain or unicode text
        case CF_TEXT:
        case CF_UNICODETEXT:
        return GetText(*df, *pFE, *pSTM);
                  
#ifndef WINCE
        case CF_HDROP:
          return GetFile(*df, *pFE, *pSTM);
#endif
        // Someone is asking for an image
        case CF_DIB:
          return GetDib(*df, *pFE, *pSTM);
                                              
        // ... not yet implemented ...
        //case CF_BITMAP:
        //  return GetBitmap(*pFE, *pSTM);
        //case CF_METAFILEPICT:
        //  return GetMetafilePict(*pFE, *pSTM);
            
        default:
          if ( format == fileDescriptorFlavorA )
            return GetFileDescriptor ( *pFE, *pSTM, PR_FALSE );
          if ( format == fileDescriptorFlavorW )
            return GetFileDescriptor ( *pFE, *pSTM, PR_TRUE);
          if ( format == uniformResourceLocatorA )
            return GetUniformResourceLocator( *pFE, *pSTM, PR_FALSE);
          if ( format == uniformResourceLocatorW )
            return GetUniformResourceLocator( *pFE, *pSTM, PR_TRUE);
#ifndef WINCE
          if ( format == fileFlavor )
            return GetFileContents ( *pFE, *pSTM );
          if ( format == PreferredDropEffect )
            return GetPreferredDropEffect( *pFE, *pSTM );
#endif
          PRNTDEBUG2("***** nsDataObj::GetData - Unknown format %u\n", format);
          return GetText(*df, *pFE, *pSTM);
        } //switch
      } // if
    }
    dfInx++;
  } // while

  return ResultFromScode(DATA_E_FORMATETC);
}

Here is the call graph for this function:

STDMETHODIMP nsDataObj::GetDataHere ( LPFORMATETC  pFE,
LPSTGMEDIUM  pSTM 
)

Definition at line 271 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::GetDataHere\n");
              return ResultFromScode(E_FAIL);
}
HRESULT nsDataObj::GetDib ( const nsACString &  inFlavor,
FORMATETC &  ,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 431 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::GetDib\n");
  ULONG result = E_FAIL;
#ifndef WINCE  
  
  PRUint32 len = 0;
  nsCOMPtr<nsISupports> genericDataWrapper;
  mTransferable->GetTransferData(PromiseFlatCString(inFlavor).get(), getter_AddRefs(genericDataWrapper), &len);
  nsCOMPtr<nsIImage> image ( do_QueryInterface(genericDataWrapper) );
  if ( !image ) {
    // In the 0.9.4 timeframe, I had some embedding clients put the nsIImage directly into the
    // transferable. Newer code, however, wraps the nsIImage in a nsISupportsInterfacePointer.
    // We should be backwards compatibile with code already out in the field. If we can't find
    // the image directly out of the transferable,  unwrap the image from its wrapper.
    nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
    if ( ptr )
      ptr->GetData(getter_AddRefs(image));
  }
  
  if ( image ) {
    // use a the helper class to build up a bitmap. We now own the bits,
    // and pass them back to the OS in |aSTG|.
    nsImageToClipboard converter ( image );
    HANDLE bits = nsnull;
    nsresult rv = converter.GetPicture ( &bits );
    if ( NS_SUCCEEDED(rv) && bits ) {
      aSTG.hGlobal = bits;
      aSTG.tymed = TYMED_HGLOBAL;
      result = S_OK;
    }
  } // if we have an image
  else  
    NS_WARNING ( "Definately not an image on clipboard" );

#endif
       return ResultFromScode(result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFile ( const nsACString &  aDF,
FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 940 of file nsDataObj.cpp.

{
  HRESULT res = S_OK;
  if (strcmp(PromiseFlatCString(aDataFlavor).get(), kFilePromiseMime) == 0) {
    // XXX We are copying the file twice below.  Once from the original location to the temporary
    // one (here) and then from the temporary location to the drop location (done by the drop target
    // when this function returns).  If the file being drag-dropped is in the cache, we should be able to
    // just pass back its file name to the drop target and save a copy.  Need help here!
    nsresult rv;
    if (!mCachedTempFile) {
      // Save the file to a temporary location.      
      nsCOMPtr<nsILocalFile> dropDirectory;
      nsCOMPtr<nsIProperties> directoryService = 
        do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
      if (!directoryService || NS_FAILED(rv)) return ResultFromScode(E_FAIL);
      directoryService->Get(NS_OS_TEMP_DIR, 
                            NS_GET_IID(nsIFile), 
                            getter_AddRefs(dropDirectory));
      nsCOMPtr<nsISupports> localFileISupports = do_QueryInterface(dropDirectory);
      rv = mTransferable->SetTransferData(kFilePromiseDirectoryMime, localFileISupports, sizeof(nsILocalFile*));
      if (NS_FAILED(rv)) return ResultFromScode(E_FAIL);
      nsCOMPtr<nsISupports> fileDataPrimitive;
      PRUint32 dataSize = 0;
      rv = mTransferable->GetTransferData(kFilePromiseMime, getter_AddRefs(fileDataPrimitive), &dataSize);
      if (NS_FAILED(rv)) return ResultFromScode(E_FAIL);      
      
      mCachedTempFile = do_QueryInterface(fileDataPrimitive);
      if (!mCachedTempFile) return ResultFromScode(E_FAIL);
    }

    // Pass the file name back to the drop target so that it can copy to the drop location
    nsAutoString path;
    rv = mCachedTempFile->GetPath(path);
    if (NS_FAILED(rv)) return ResultFromScode(E_FAIL);
    // Two null characters are needed to terminate the file name list
    PRUint32 allocLen = path.Length() + 2;
    HGLOBAL hGlobalMemory = NULL;
    aSTG.tymed = TYMED_HGLOBAL;
    aSTG.pUnkForRelease = NULL;
    hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE, sizeof(DROPFILES) + allocLen * sizeof(PRUnichar));
    if (hGlobalMemory) {
      DROPFILES* pDropFile = NS_REINTERPRET_CAST(DROPFILES*, GlobalLock(hGlobalMemory));

      // First, populate drop file structure
      pDropFile->pFiles = sizeof(DROPFILES);   // offset to start of file name char array
      pDropFile->fNC = 0;
      pDropFile->pt.x = 0;
      pDropFile->pt.y = 0;
      pDropFile->fWide = TRUE;

      // Copy the filename right after the DROPFILES structure
      PRUnichar* dest = NS_REINTERPRET_CAST(PRUnichar*, NS_REINTERPRET_CAST(char*, pDropFile) + pDropFile->pFiles);
      memcpy(dest, path.get(), (allocLen - 1) * sizeof(PRUnichar));    // copies the null character in path as well

      // Two null characters are needed at the end of the file name.  
      // Lookup the CF_HDROP shell clipboard format for more info.
      // Add the second null character right after the first one.
      dest[allocLen - 1] = L'\0';

      GlobalUnlock(hGlobalMemory);
    }
    else {
      res = E_OUTOFMEMORY;
    }
    aSTG.hGlobal = hGlobalMemory;
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFileContents ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 499 of file nsDataObj.cpp.

{
  HRESULT res = S_OK;
  
  // How we handle this depends on if we're dealing with an internet
  // shortcut, since those are done under the covers.
  if ( IsInternetShortcut() )  
    res = GetFileContentsInternetShortcut ( aFE, aSTG );
  else
    NS_WARNING ( "Not yet implemented\n" );

       return res;
       
} // GetFileContents

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFileContentsInternetShortcut ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 733 of file nsDataObj.cpp.

{
#ifdef WINCE
  return E_FAIL;
#else
  nsAutoString url;
  if ( NS_FAILED(ExtractShortcutURL(url)) )
    return E_OUTOFMEMORY;

  // will need to change if we ever support iDNS
  nsCAutoString asciiUrl;
  LossyCopyUTF16toASCII(url, asciiUrl);
    
  static const char* shortcutFormatStr = "[InternetShortcut]\r\nURL=%s\r\n";
  static const int formatLen = strlen(shortcutFormatStr) - 2; // don't include %s in the len
  const int totalLen = formatLen + asciiUrl.Length(); // we don't want a null character on the end

  // create a global memory area and build up the file contents w/in it
  HGLOBAL hGlobalMemory = ::GlobalAlloc(GMEM_SHARE, totalLen);
  if ( !hGlobalMemory )
    return E_OUTOFMEMORY;

  char* contents = NS_REINTERPRET_CAST(char*, ::GlobalLock(hGlobalMemory));
  if ( !contents ) {
    ::GlobalFree( hGlobalMemory );
    return E_OUTOFMEMORY;
  }
    
  //NOTE: we intentionally use the Microsoft version of snprintf here because it does NOT null 
  // terminate strings which reach the maximum size of the buffer. Since we know that the 
  // formatted length here is totalLen, this call to _snprintf will format the string into 
  // the buffer without appending the null character.
  _snprintf( contents, totalLen, shortcutFormatStr, asciiUrl.get() );
    
  ::GlobalUnlock(hGlobalMemory);
  aSTG.hGlobal = hGlobalMemory;
  aSTG.tymed = TYMED_HGLOBAL;

  return S_OK;
#endif  
} // GetFileContentsInternetShortcut

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFileDescriptor ( FORMATETC &  aFE,
STGMEDIUM &  aSTG,
PRBool  aIsUnicode 
) [protected, virtual]

Definition at line 477 of file nsDataObj.cpp.

{
  HRESULT res = S_OK;
  
  // How we handle this depends on if we're dealing with an internet
  // shortcut, since those are done under the covers.
  if ( IsInternetShortcut() ) {
    if ( aIsUnicode )
      res = GetFileDescriptorInternetShortcutW ( aFE, aSTG );
    else
      res = GetFileDescriptorInternetShortcutA ( aFE, aSTG );
  } 
  else
    NS_WARNING ( "Not yet implemented\n" );
  
       return res;
       
} // GetFileDescriptor

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFileDescriptorInternetShortcutA ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 634 of file nsDataObj.cpp.

{
#ifdef WINCE
  return E_FAIL;
#else
  // get the title of the shortcut
  nsAutoString title;
  if ( NS_FAILED(ExtractShortcutTitle(title)) )
    return E_OUTOFMEMORY;

  HGLOBAL fileGroupDescHandle = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_SHARE,sizeof(FILEGROUPDESCRIPTORA));
  if (!fileGroupDescHandle)
    return E_OUTOFMEMORY;

  LPFILEGROUPDESCRIPTORA fileGroupDescA = NS_REINTERPRET_CAST(LPFILEGROUPDESCRIPTORA, 
      ::GlobalLock(fileGroupDescHandle));
  if (!fileGroupDescA) {
    ::GlobalFree(fileGroupDescHandle);
    return E_OUTOFMEMORY;
  }

  // get a valid filename in the following order: 1) from the page title, 
  // 2) localized string for an untitled page, 3) just use "Untitled.URL"
  if (!CreateFilenameFromTextA(title, ".URL", 
          fileGroupDescA->fgd[0].cFileName, NS_MAX_FILEDESCRIPTOR)) {
    nsXPIDLString untitled;
    if (!GetLocalizedString(NS_LITERAL_STRING("noPageTitle").get(), untitled) ||
        !CreateFilenameFromTextA(untitled, ".URL", 
            fileGroupDescA->fgd[0].cFileName, NS_MAX_FILEDESCRIPTOR)) {
      strcpy(fileGroupDescA->fgd[0].cFileName, "Untitled.URL");
    }
  }

  // one file in the file block
  fileGroupDescA->cItems = 1;
  fileGroupDescA->fgd[0].dwFlags = FD_LINKUI;

  ::GlobalUnlock( fileGroupDescHandle );
  aSTG.hGlobal = fileGroupDescHandle;
  aSTG.tymed = TYMED_HGLOBAL;

  return S_OK;
#endif
} // GetFileDescriptorInternetShortcutA

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetFileDescriptorInternetShortcutW ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 680 of file nsDataObj.cpp.

{
#ifdef WINCE
  return E_FAIL;
#else
  // get the title of the shortcut
  nsAutoString title;
  if ( NS_FAILED(ExtractShortcutTitle(title)) )
    return E_OUTOFMEMORY;

  HGLOBAL fileGroupDescHandle = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_SHARE,sizeof(FILEGROUPDESCRIPTORW));
  if (!fileGroupDescHandle)
    return E_OUTOFMEMORY;

  LPFILEGROUPDESCRIPTORW fileGroupDescW = NS_REINTERPRET_CAST(LPFILEGROUPDESCRIPTORW, 
      ::GlobalLock(fileGroupDescHandle));
  if (!fileGroupDescW) {
    ::GlobalFree(fileGroupDescHandle);
    return E_OUTOFMEMORY;
  }

  // get a valid filename in the following order: 1) from the page title, 
  // 2) localized string for an untitled page, 3) just use "Untitled.URL"
  if (!CreateFilenameFromTextW(title, NS_LITERAL_STRING(".URL").get(), 
          fileGroupDescW->fgd[0].cFileName, NS_MAX_FILEDESCRIPTOR)) {
    nsXPIDLString untitled;
    if (!GetLocalizedString(NS_LITERAL_STRING("noPageTitle").get(), untitled) ||
        !CreateFilenameFromTextW(untitled, NS_LITERAL_STRING(".URL").get(), 
            fileGroupDescW->fgd[0].cFileName, NS_MAX_FILEDESCRIPTOR)) {
      wcscpy(fileGroupDescW->fgd[0].cFileName, NS_LITERAL_STRING("Untitled.URL").get());
    }
  }

  // one file in the file block
  fileGroupDescW->cItems = 1;
  fileGroupDescW->fgd[0].dwFlags = FD_LINKUI;

  ::GlobalUnlock( fileGroupDescHandle );
  aSTG.hGlobal = fileGroupDescHandle;
  aSTG.tymed = TYMED_HGLOBAL;

  return S_OK;
#endif
} // GetFileDescriptorInternetShortcutW

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetMetafilePict ( FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 1010 of file nsDataObj.cpp.

{
       return ResultFromScode(E_NOTIMPL);
}
HRESULT nsDataObj::GetPreferredDropEffect ( FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 818 of file nsDataObj.cpp.

{
  HRESULT res = S_OK;
  aSTG.tymed = TYMED_HGLOBAL;
  aSTG.pUnkForRelease = NULL;    
  HGLOBAL hGlobalMemory = NULL;
  hGlobalMemory = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(DWORD));
  if (hGlobalMemory) {
    DWORD* pdw = (DWORD*) GlobalLock(hGlobalMemory);
    // The PreferredDropEffect clipboard format is only registered if a drag/drop
    // of an image happens from Mozilla to the desktop.  We want its value
    // to be DROPEFFECT_MOVE in that case so that the file is moved from the
    // temporary location, not copied.
    // This value should, ideally, be set on the data object via SetData() but 
    // our IDataObject implementation doesn't implement SetData.  It adds data
    // to the data object lazily only when the drop target asks for it.
    *pdw = (DWORD) DROPEFFECT_MOVE;
    GlobalUnlock(hGlobalMemory);
  }
  else {
    res = E_OUTOFMEMORY;
  }
  aSTG.hGlobal = hGlobalMemory;
  return res;
}

Here is the caller graph for this function:

Definition at line 394 of file nsDataObj.cpp.

{
       return m_cRef;
}
HRESULT nsDataObj::GetText ( const nsACString &  aDF,
FORMATETC &  aFE,
STGMEDIUM &  aSTG 
) [protected, virtual]

Definition at line 845 of file nsDataObj.cpp.

{
  void* data;
  PRUint32   len;
  
  // if someone asks for text/plain, look up text/unicode instead in the transferable.
  const char* flavorStr;
  const nsPromiseFlatCString& flat = PromiseFlatCString(aDataFlavor);
  if ( aDataFlavor.Equals("text/plain") )
    flavorStr = kUnicodeMime;
  else
    flavorStr = flat.get();

  // NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted
  nsCOMPtr<nsISupports> genericDataWrapper;
  mTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper), &len);
  if ( !len )
    return ResultFromScode(E_FAIL);
  nsPrimitiveHelpers::CreateDataFromPrimitive ( flavorStr, genericDataWrapper, &data, len );
  HGLOBAL     hGlobalMemory = NULL;

  aSTG.tymed          = TYMED_HGLOBAL;
  aSTG.pUnkForRelease = NULL;

  // We play games under the hood and advertise flavors that we know we
  // can support, only they require a bit of conversion or munging of the data.
  // Do that here.
  //
  // The transferable gives us data that is null-terminated, but this isn't reflected in
  // the |len| parameter. Windoze apps expect this null to be there so bump our data buffer
  // by the appropriate size to account for the null (one char for CF_TEXT, one PRUnichar for
  // CF_UNICODETEXT).
  DWORD allocLen = (DWORD)len;
  if ( aFE.cfFormat == CF_TEXT ) {
    // Someone is asking for text/plain; convert the unicode (assuming it's present)
    // to text with the correct platform encoding.
    char* plainTextData = nsnull;
    PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, data);
    PRInt32 plainTextLen = 0;
    nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, len / 2, &plainTextData, &plainTextLen );
   
    // replace the unicode data with our plaintext data. Recall that |plainTextLen| doesn't include
    // the null in the length.
    nsMemory::Free(data);
    if ( plainTextData ) {
      data = plainTextData;
      allocLen = plainTextLen + sizeof(char);
    }
    else {
      NS_WARNING ( "Oh no, couldn't convert unicode to plain text" );
      return ResultFromScode(S_OK);
    }
  }
  else if ( aFE.cfFormat == nsClipboard::CF_HTML ) {
    // Someone is asking for win32's HTML flavor. Convert our html fragment
    // from unicode to UTF-8 then put it into a format specified by msft.
    NS_ConvertUCS2toUTF8 converter ( NS_REINTERPRET_CAST(PRUnichar*, data) );
    char* utf8HTML = nsnull;
    nsresult rv = BuildPlatformHTML ( converter.get(), &utf8HTML );      // null terminates
    
    nsMemory::Free(data);
    if ( NS_SUCCEEDED(rv) && utf8HTML ) {
      // replace the unicode data with our HTML data. Don't forget the null.
      data = utf8HTML;
      allocLen = strlen(utf8HTML) + sizeof(char);
    }
    else {
      NS_WARNING ( "Oh no, couldn't convert to HTML" );
      return ResultFromScode(S_OK);
    }
  }
  else {
    // we assume that any data that isn't caught above is unicode. This may
    // be an erroneous assumption, but is true so far.
    allocLen += sizeof(PRUnichar);
  }

  hGlobalMemory = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, allocLen);

  // Copy text to Global Memory Area
  if ( hGlobalMemory ) {
    char* dest = NS_REINTERPRET_CAST(char*, GlobalLock(hGlobalMemory));
    char* source = NS_REINTERPRET_CAST(char*, data);
    memcpy ( dest, source, allocLen );                         // copies the null as well
    GlobalUnlock(hGlobalMemory);
  }
  aSTG.hGlobal = hGlobalMemory;

  // Now, delete the memory that was created by CreateDataFromPrimitive (or our text/plain data)
  nsMemory::Free(data);

  return ResultFromScode(S_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsDataObj::GetUniformResourceLocator ( FORMATETC &  aFE,
STGMEDIUM &  aSTG,
PRBool  aIsUnicode 
) [protected, virtual]

Definition at line 1300 of file nsDataObj.cpp.

{
  HRESULT res = S_OK;
  if ( IsInternetShortcut() ) {
    if ( aIsUnicode )
      res = ExtractUniformResourceLocatorW( aFE, aSTG );
    else
      res = ExtractUniformResourceLocatorA( aFE, aSTG );
  }
  else
    NS_WARNING ("Not yet implemented\n");
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 784 of file nsDataObj.cpp.

{
  PRBool retval = PR_FALSE;
  
  if ( !mTransferable )
    return PR_FALSE;
  
  // get the list of flavors available in the transferable
  nsCOMPtr<nsISupportsArray> flavorList;
  mTransferable->FlavorsTransferableCanExport ( getter_AddRefs(flavorList) );
  if ( !flavorList )
    return PR_FALSE;
  
  // go spelunking for the url flavor
  PRUint32 cnt;
  flavorList->Count(&cnt);
  for ( PRUint32 i = 0;i < cnt; ++i ) {
    nsCOMPtr<nsISupports> genericFlavor;
    flavorList->GetElementAt (i, getter_AddRefs(genericFlavor));
    nsCOMPtr<nsISupportsCString> currentFlavor (do_QueryInterface(genericFlavor));
    if (currentFlavor) {
      nsCAutoString flavorStr;
      currentFlavor->GetData(flavorStr);
      if ( flavorStr.Equals(kURLMime) ) {
        retval = PR_TRUE;         // found it!
        break;
      }
    }
  } // for each flavor

  return retval;
  
} // IsInternetShortcut

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP nsDataObj::QueryGetData ( LPFORMATETC  pFE)

Definition at line 282 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::QueryGetData  ");
  PRNTDEBUG3("format: %d  Text: %d\n", pFE->cfFormat, CF_TEXT);

  ULONG count;
  FORMATETC fe;
  m_enumFE->Reset();
  while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
    if (fe.cfFormat == pFE->cfFormat) {
      return S_OK;
    }
  }
  
  PRNTDEBUG2("***** nsDataObj::QueryGetData - Unknown format %d\n", pFE->cfFormat);
       return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::QueryInterface ( REFIID  riid,
void **  ppv 
)

Definition at line 140 of file nsDataObj.cpp.

{
       *ppv=NULL;

       if ( (IID_IUnknown == riid) || (IID_IDataObject  == riid) ) {
              *ppv = this;
              AddRef();
              return NOERROR;
       }

       return ResultFromScode(E_NOINTERFACE);
}

Here is the call graph for this function:

HRESULT nsDataObj::SetBitmap ( FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 1016 of file nsDataObj.cpp.

{
       return ResultFromScode(E_NOTIMPL);
}
STDMETHODIMP nsDataObj::SetData ( LPFORMATETC  pFE,
LPSTGMEDIUM  pSTM,
BOOL  release 
)

Definition at line 310 of file nsDataObj.cpp.

{
  PRNTDEBUG("nsDataObj::SetData\n");
#ifndef WINCE
  static CLIPFORMAT PerformedDropEffect = ::RegisterClipboardFormat( CFSTR_PERFORMEDDROPEFFECT );  

  if (pFE && pFE->cfFormat == PerformedDropEffect) {
    // The drop operation has completed.  Delete the temp file if it exists.
    if (mCachedTempFile) {
      mCachedTempFile->Remove(PR_FALSE);
      mCachedTempFile = NULL;
    }
  }
#endif

  if (fRelease) {
    ReleaseStgMedium(pSTM);
  }

  return ResultFromScode(S_OK);
}

Here is the call graph for this function:

HRESULT nsDataObj::SetDib ( FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 1022 of file nsDataObj.cpp.

{
       return ResultFromScode(E_FAIL);
}
HRESULT nsDataObj::SetMetafilePict ( FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 1048 of file nsDataObj.cpp.

{
       return ResultFromScode(E_FAIL);
}
HRESULT nsDataObj::SetText ( FORMATETC &  FE,
STGMEDIUM &  STM 
) [protected, virtual]

Definition at line 1028 of file nsDataObj.cpp.

{
  if (aFE.cfFormat == CF_TEXT && aFE.tymed ==  TYMED_HGLOBAL) {
              HGLOBAL hString = (HGLOBAL)aSTG.hGlobal;
              if(hString == NULL)
                     return(FALSE);

              // get a pointer to the actual bytes
              char *  pString = (char *) GlobalLock(hString);    
              if(!pString)
                     return(FALSE);

              GlobalUnlock(hString);
    nsAutoString str; str.AssignWithConversion(pString);

  }
       return ResultFromScode(E_FAIL);
}

Definition at line 1092 of file nsDataObj.cpp.

{
    NS_IF_RELEASE(mTransferable);

  mTransferable = aTransferable;
  if (nsnull == mTransferable) {
    return;
  }

  NS_ADDREF(mTransferable);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

ULONG nsDataObj::g_cRef = 0 [static, protected]

Definition at line 233 of file nsDataObj.h.

ULONG nsDataObj::m_cRef [protected]

Definition at line 234 of file nsDataObj.h.

CEnumFormatEtc* nsDataObj::m_enumFE [protected]

Definition at line 241 of file nsDataObj.h.

Definition at line 244 of file nsDataObj.h.

Definition at line 236 of file nsDataObj.h.

Definition at line 227 of file nsDataObj.h.

Definition at line 229 of file nsDataObj.h.

Definition at line 238 of file nsDataObj.h.


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