+namespace
+{
+
+wxDataFormat HtmlFormatFixup(wxDataFormat format)
+{
+ // Since the HTML format is dynamically registered, the wxDF_HTML
+ // format does not match the native constant in the way other formats do,
+ // so for the format checks below to work, we must change the native
+ // id to the wxDF_HTML constant.
+ wxChar s_szBuf[256];
+ if (::GetClipboardFormatName(format, s_szBuf, WXSIZEOF(s_szBuf)))
+ {
+ if (s_szBuf == wxString("HTML Format"))
+ format = wxDF_HTML;
+ }
+ return format;
+}
+
+// helper function for wxCopyStgMedium()
+HGLOBAL wxGlobalClone(HGLOBAL hglobIn)
+{
+ HGLOBAL hglobOut = NULL;
+
+ LPVOID pvIn = GlobalLock(hglobIn);
+ if (pvIn)
+ {
+ SIZE_T cb = GlobalSize(hglobIn);
+ hglobOut = GlobalAlloc(GMEM_FIXED, cb);
+ if (hglobOut)
+ {
+ CopyMemory(hglobOut, pvIn, cb);
+ }
+ GlobalUnlock(hglobIn);
+ }
+
+ return hglobOut;
+}
+
+// Copies the given STGMEDIUM structure.
+//
+// This is an local implementation of the function with the same name in
+// urlmon.lib but to use that function would require linking with urlmon.lib
+// and we don't want to require it, so simple reimplement it here.
+HRESULT wxCopyStgMedium(const STGMEDIUM *pmediumIn, STGMEDIUM *pmediumOut)
+{
+ HRESULT hres = S_OK;
+ STGMEDIUM stgmOut = *pmediumIn;
+
+ if (pmediumIn->pUnkForRelease == NULL &&
+ !(pmediumIn->tymed & (TYMED_ISTREAM | TYMED_ISTORAGE)))
+ {
+ // Object needs to be cloned.
+ if (pmediumIn->tymed == TYMED_HGLOBAL)
+ {
+ stgmOut.hGlobal = wxGlobalClone(pmediumIn->hGlobal);
+ if (!stgmOut.hGlobal)
+ {
+ hres = E_OUTOFMEMORY;
+ }
+ }
+ else
+ {
+ hres = DV_E_TYMED; // Don't know how to clone GDI objects.
+ }
+ }
+
+ if ( SUCCEEDED(hres) )
+ {
+ switch ( stgmOut.tymed )
+ {
+ case TYMED_ISTREAM:
+ stgmOut.pstm->AddRef();
+ break;
+
+ case TYMED_ISTORAGE:
+ stgmOut.pstg->AddRef();
+ break;
+ }
+
+ if ( stgmOut.pUnkForRelease )
+ stgmOut.pUnkForRelease->AddRef();
+
+ *pmediumOut = stgmOut;
+ }
+
+ return hres;
+}
+
+} // anonymous namespace