]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/ole/dataobj.cpp
Honour window min and max sizes in wxWindow::GetBestSize().
[wxWidgets.git] / src / msw / ole / dataobj.cpp
index bd369ee4e113e645ad9694ac982825d2c62db84d..ad02bc6be353dd972682f684af490816862d64da 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        msw/ole/dataobj.cpp
+// Name:        src/msw/ole/dataobj.cpp
 // Purpose:     implementation of wx[I]DataObject class
 // Author:      Vadim Zeitlin
 // Modified by:
     #define GetTymedName(tymed) wxEmptyString
 #endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
 
+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;
+}
+
 // ----------------------------------------------------------------------------
 // wxIEnumFORMATETC interface implementation
 // ----------------------------------------------------------------------------
@@ -139,7 +154,7 @@ private:
 
 void wxDataFormat::SetId(const wxString& format)
 {
-    m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.wx_str());
+    m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.t_str());
     if ( !m_format )
     {
         wxLogError(_("Couldn't register clipboard format '%s'."), format);
@@ -183,7 +198,10 @@ wxIEnumFORMATETC::wxIEnumFORMATETC(const wxDataFormat *formats, ULONG nCount)
     m_nCount = nCount;
     m_formats = new CLIPFORMAT[nCount];
     for ( ULONG n = 0; n < nCount; n++ ) {
-        m_formats[n] = formats[n].GetFormatId();
+        if (formats[n].GetFormatId() != wxDF_HTML)
+            m_formats[n] = formats[n].GetFormatId();
+        else
+            m_formats[n] = ::RegisterClipboardFormat(wxT("HTML Format"));
     }
 }
 
@@ -290,6 +308,7 @@ STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
     // for the bitmaps and metafiles we use the handles instead of global memory
     // to pass the data
     wxDataFormat format = (wxDataFormat::NativeFormat)pformatetcIn->cfFormat;
+    format = HtmlFormatFixup(format);
 
     switch ( format )
     {
@@ -432,6 +451,8 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
             {
                 wxDataFormat format = pformatetc->cfFormat;
 
+                format = HtmlFormatFixup(format);
+
                 // this is quite weird, but for file drag and drop, explorer
                 // calls our SetData() with the formats we do *not* support!
                 //
@@ -459,14 +480,14 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
                 size_t size;
                 switch ( format )
                 {
+                    case wxDF_HTML:
                     case CF_TEXT:
                     case CF_OEMTEXT:
                         size = strlen((const char *)pBuf);
                         break;
 #if !(defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
                     case CF_UNICODETEXT:
-#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
-    || ( defined(__MWERKS__) && defined(__WXMSW__) )
+#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) )
                         size = std::wcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
 #else
                         size = wxWcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
@@ -568,6 +589,8 @@ STDMETHODIMP wxIDataObject::QueryGetData(FORMATETC *pformatetc)
 
     // and now check the type of data requested
     wxDataFormat format = pformatetc->cfFormat;
+    format = HtmlFormatFixup(format);
+
     if ( m_pDataObject->IsSupportedFormat(format) ) {
         wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::QueryGetData: %s ok"),
                    wxGetFormatName(format));
@@ -852,7 +875,7 @@ bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf)
     wxBitmap bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes);
     bitmap.SetHBITMAP((WXHBITMAP)hbmp);
 
-    if ( !bitmap.Ok() ) {
+    if ( !bitmap.IsOk() ) {
         wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
 
         return false;
@@ -898,7 +921,7 @@ size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
 bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format,
                                      void *pBuf) const
 {
-    wxASSERT_MSG( m_bitmap.Ok(), wxT("copying invalid bitmap") );
+    wxASSERT_MSG( m_bitmap.IsOk(), wxT("copying invalid bitmap") );
 
     HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP();
     if ( format.GetFormatId() == CF_DIB )
@@ -977,7 +1000,7 @@ bool wxBitmapDataObject::SetData(const wxDataFormat& format,
 
     m_bitmap.SetHBITMAP((WXHBITMAP)hbmp);
 
-    wxASSERT_MSG( m_bitmap.Ok(), wxT("pasting invalid bitmap") );
+    wxASSERT_MSG( m_bitmap.IsOk(), wxT("pasting invalid bitmap") );
 
     return true;
 }
@@ -1129,7 +1152,7 @@ bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const
 #endif // wxUSE_UNICODE_MSLU
         {
             len = m_filenames[i].length();
-            memcpy(pbuf, m_filenames[i].wx_str(), len*sizeOfChar);
+            memcpy(pbuf, m_filenames[i].t_str(), len*sizeOfChar);
         }
 
         pbuf += len*sizeOfChar;
@@ -1182,23 +1205,6 @@ public:
         return buffer;
     }
 
-#if wxUSE_UNICODE
-    virtual bool GetDataHere( void* buffer ) const
-    {
-        // CFSTR_SHELLURL is _always_ ANSI!
-        wxCharBuffer char_buffer( GetDataSize() );
-        wxCustomDataObject::GetDataHere( (void*)char_buffer.data() );
-        wxString unicode_buffer( char_buffer, wxConvLibc );
-        memcpy( buffer, unicode_buffer.c_str(),
-                ( unicode_buffer.length() + 1 ) * sizeof(wxChar) );
-
-        return true;
-    }
-    virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
-                             void *buf) const
-        { return GetDataHere(buf); }
-#endif
-
     wxDECLARE_NO_COPY_CLASS(CFSTR_SHELLURLDataObject);
 };
 
@@ -1236,9 +1242,28 @@ wxString wxURLDataObject::GetURL() const
     wxString url;
     wxCHECK_MSG( m_dataObjectLast, url, wxT("no data in wxURLDataObject") );
 
-    size_t len = m_dataObjectLast->GetDataSize();
+    if ( m_dataObjectLast->GetPreferredFormat() == CFSTR_SHELLURL )
+    {
+        const size_t len = m_dataObjectLast->GetDataSize();
+        if ( !len )
+            return wxString();
 
-    m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
+        // CFSTR_SHELLURL is always ANSI so we need to convert it from it in
+        // Unicode build
+#if wxUSE_UNICODE
+        wxCharBuffer buf(len);
+
+        if ( m_dataObjectLast->GetDataHere(buf.data()) )
+            url = buf;
+#else // !wxUSE_UNICODE
+        // in ANSI build no conversion is necessary
+        m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+    }
+    else // must be wxTextDataObject
+    {
+        url = static_cast<wxTextDataObject *>(m_dataObjectLast)->GetText();
+    }
 
     return url;
 }