// Get some data from the clipboard PRBool nsClipboard::GetClipboardData(const char *aFlavor) { ULONG ulFormatID = GetFormatID( aFlavor ); PRBool found = GetClipboardDataByID( ulFormatID, aFlavor ); if (!found) { if (!strcmp( aFlavor, kUnicodeMime )) { found = GetClipboardDataByID( CF_TEXT, aFlavor ); } else if (strstr( aFlavor, "image/" )) { found = GetClipboardDataByID( CF_BITMAP, aFlavor ); } } return found; }
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(const char** aFlavorList, PRUint32 aLength, PRInt32 aWhichClipboard, PRBool *_retval) { *_retval = PR_FALSE; if (aWhichClipboard != kGlobalClipboard || !aFlavorList) return NS_OK; for (PRUint32 i = 0; i < aLength; ++i) { ULONG fmtInfo = 0; ULONG format = GetFormatID(aFlavorList[i]); if (WinQueryClipbrdFmtInfo(0/*hab*/, format, &fmtInfo)) { *_retval = PR_TRUE; break; } // if the client asked for unicode and it wasn't present, check if we have CF_TEXT. if (!strcmp(aFlavorList[i], kUnicodeMime)) { if (WinQueryClipbrdFmtInfo(0/*hab*/, CF_TEXT, &fmtInfo)) { *_retval = PR_TRUE; break; } } // OS2TODO - Support for Images // if the client asked for image/.. and it wasn't present, check if we have CF_BITMAP. if (strstr(aFlavorList[i], "image/")) { if (WinQueryClipbrdFmtInfo (0, CF_BITMAP, &fmtInfo)) { #ifdef DEBUG printf("nsClipboard:: Image present on clipboard; need to add BMP conversion!\n"); #endif // *_retval = PR_TRUE; // break; } } } return NS_OK; }
// Set some data onto the clipboard void nsClipboard::SetClipboardData(const char *aFlavor) { void *pMozData = nsnull; PRUint32 NumOfBytes = 0; // Get the data from the transferable nsCOMPtr<nsISupports> genericDataWrapper; #ifdef DEBUG nsresult errCode = #endif mTransferable->GetTransferData( aFlavor, getter_AddRefs(genericDataWrapper), &NumOfBytes ); #ifdef DEBUG if (NS_FAILED(errCode)) printf( "nsClipboard:: Error getting data from transferable\n" ); #endif if (NumOfBytes == 0) return; nsPrimitiveHelpers::CreateDataFromPrimitive( aFlavor, genericDataWrapper, &pMozData, NumOfBytes ); /* If creating the data failed, just return */ if (!pMozData) { return; } ULONG ulFormatID = GetFormatID( aFlavor ); if (strstr( aFlavor, "text/" )) // All text/.. flavors are null-terminated { if (ulFormatID == CF_TEXT) // CF_TEXT is one byte character set { char* pByteMem = nsnull; if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pByteMem), nsnull, NumOfBytes + sizeof(char), PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) { memcpy( pByteMem, pMozData, NumOfBytes ); // Copy text string pByteMem[NumOfBytes] = '\0'; // Append terminator // With Warp4 copying more than 64K to the clipboard works well, but // legacy apps cannot always handle it. So output an alarm to alert the // user that there might be a problem. if (strlen(pByteMem) > 0xFFFF) { WinAlarm(HWND_DESKTOP, WA_ERROR); } WinSetClipbrdData(0, reinterpret_cast<ULONG>(pByteMem), ulFormatID, CFI_POINTER); } } else // All other text/.. flavors are in unicode { UniChar* pUnicodeMem = nsnull; PRUint32 NumOfChars = NumOfBytes / sizeof(UniChar); if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pUnicodeMem), nsnull, NumOfBytes + sizeof(UniChar), PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) { memcpy( pUnicodeMem, pMozData, NumOfBytes ); // Copy text string pUnicodeMem[NumOfChars] = L'\0'; // Append terminator WinSetClipbrdData( 0, reinterpret_cast<ULONG>(pUnicodeMem), ulFormatID, CFI_POINTER ); } // If the flavor is unicode, we also put it on the clipboard as CF_TEXT // after conversion to locale charset. if (!strcmp( aFlavor, kUnicodeMime )) { char* pByteMem = nsnull; if (DosAllocSharedMem(reinterpret_cast<PPVOID>(&pByteMem), nsnull, NumOfBytes + 1, PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) { PRUnichar* uchtemp = (PRUnichar*)pMozData; for (PRUint32 i=0;i<NumOfChars;i++) { switch (uchtemp[i]) { case 0x2018: case 0x2019: uchtemp[i] = 0x0027; break; case 0x201C: case 0x201D: uchtemp[i] = 0x0022; break; case 0x2014: uchtemp[i] = 0x002D; break; } } nsAutoCharBuffer buffer; PRInt32 bufLength; WideCharToMultiByte(0, static_cast<PRUnichar*>(pMozData), NumOfBytes, buffer, bufLength); memcpy(pByteMem, buffer.Elements(), NumOfBytes); // With Warp4 copying more than 64K to the clipboard works well, but // legacy apps cannot always handle it. So output an alarm to alert the // user that there might be a problem. if (strlen(pByteMem) > 0xFFFF) { WinAlarm(HWND_DESKTOP, WA_ERROR); } WinSetClipbrdData(0, reinterpret_cast<ULONG>(pByteMem), CF_TEXT, CFI_POINTER); } } } } else // Assume rest of flavors are binary data { PBYTE pBinaryMem = nsnull; if (DosAllocSharedMem( reinterpret_cast<PPVOID>(&pBinaryMem), nsnull, NumOfBytes + sizeof(PRUint32), PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == NO_ERROR) { *(reinterpret_cast<PRUint32*>(pBinaryMem)) = NumOfBytes; // First DWORD contains data length memcpy( pBinaryMem + sizeof(PRUint32), pMozData, NumOfBytes ); // Copy binary data WinSetClipbrdData( 0, reinterpret_cast<ULONG>(pBinaryMem), ulFormatID, CFI_POINTER ); } // If the flavor is image, we also put it on clipboard as CF_BITMAP // after conversion to OS2 bitmap if (strstr (aFlavor, "image/")) { // XXX OS2TODO Convert jpg, gif, png to bitmap #ifdef DEBUG printf( "nsClipboard:: Putting image on clipboard; should also convert to BMP\n" ); #endif } } nsMemory::Free(pMozData); }
QString Format::GetFileExtension () const { return GetFormatID (); }
//##ModelId=474D307602FF bool CClip_ImportExport::ImportFromSqliteV1(CppSQLite3DB &db, CppSQLite3Query &qMain) { try { //Load the Main Table m_Desc = qMain.getStringField(_T("mText")); long lID = qMain.getIntField(_T("lID")); //Load the data Table CClipFormat cf; HGLOBAL hGlobal = 0; m_Formats.RemoveAll(); CString csSQL; csSQL.Format( _T("SELECT Data.* FROM Data ") _T("INNER JOIN Main ON Main.lID = Data.lParentID ") _T("WHERE Main.lID = %d ORDER BY Data.lID desc"), lID); CppSQLite3Query qData = db.execQuery(csSQL); while(qData.eof() == false) { cf.m_cfType = GetFormatID(qData.getStringField(_T("strClipBoardFormat"))); long lOriginalSize = qData.getIntField(_T("lOriginalSize")); int nDataLen = 0; const unsigned char *cData = qData.getBlobField(_T("ooData"), nDataLen); if(cData != NULL) { Bytef *pUnZippedData = new Bytef[lOriginalSize]; if(pUnZippedData) { //the data in the exported file is compressed so uncompress it now int nRet = uncompress(pUnZippedData, (uLongf *)&lOriginalSize, (Bytef *)cData, nDataLen); if(nRet == Z_OK) { cf.m_hgData = NewGlobalP(pUnZippedData, lOriginalSize); if(cf.m_hgData) { m_Formats.Add(cf); cf.m_hgData = NULL; //m_format owns m_hgData now } else { Log(StrF(_T("Error allocating NewGlobalP size = %d"), lOriginalSize)); ASSERT(FALSE); } } else { Log(_T("Error uncompressing data from zlib")); ASSERT(FALSE); } delete []pUnZippedData; pUnZippedData = NULL; } else { Log(StrF(_T("Error allocating memory to unzip size = %d"), lOriginalSize)); ASSERT(FALSE); } } qData.nextRow(); } } CATCH_SQLITE_EXCEPTION_AND_RETURN(false) return m_Formats.GetSize() > 0; }