예제 #1
0
///////////////////////////////////////////////////////////////////////////////
// Provides support for multiple clipboard formats.
// 
bool ClipboardDataObject::SetData( const wxDataFormat& format, size_t len, const void* buf )
{
    bool result = false;

    if ( format == GetFormat() )
    {
        // Editor clipboard format
        result = wxCustomDataObject::SetData( format, len, buf );
    }
    else if ( format.IsStandard() && format.GetFormatId() == wxDF_FILENAME )
    {
        // File name list format.  Convert to our own type of filename list.
        wxFileDataObject fileData;
        fileData.SetData( len, buf );

        if ( fileData.GetFilenames().size() > 0 )
        {
            ClipboardFileListPtr fileList = new ClipboardFileList();

            wxArrayString::const_iterator fileItr = fileData.GetFilenames().begin();
            wxArrayString::const_iterator fileEnd = fileData.GetFilenames().end();
            for ( ; fileItr != fileEnd; ++fileItr )
            {
                const wxChar* file = fileItr->c_str();
                fileList->AddFilePath( file );
            }

            result = ToBuffer( fileList );
        }
    }

    return result;
}
예제 #2
0
bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat)
{
   wxDataFormat::NativeFormat cf = dataFormat.GetFormatId();

    if ( ::IsClipboardFormatAvailable(cf) )
    {
        // ok from the first try
        return true;
    }

    // for several standard formats, we can convert from some other ones too
    switch ( cf )
    {
        // for bitmaps, DIBs will also do
        case CF_BITMAP:
            return ::IsClipboardFormatAvailable(CF_DIB) != 0;

#if wxUSE_ENH_METAFILE && !defined(__WXWINCE__)
        case CF_METAFILEPICT:
            return ::IsClipboardFormatAvailable(CF_ENHMETAFILE) != 0;
#endif // wxUSE_ENH_METAFILE

        default:
            return false;
    }
}
예제 #3
0
파일: drawdnd.cpp 프로젝트: wds315/szarp
size_t SetInfoDataObject::GetDataSize(const wxDataFormat& format) const {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		assert(false);

	wxString url = GetUrl();

	size_t ret = url.length();

	if (format.GetType() == wxDF_FILENAME)
		ret += 1;

	return ret;
}
예제 #4
0
void wxClipboard::GTKOnSelectionReceived(const GtkSelectionData& sel)
{
    wxCHECK_RET( m_receivedData, wxT("should be inside GetData()") );

    const wxDataFormat format(gtk_selection_data_get_target(const_cast<GtkSelectionData*>(&sel)));
    wxLogTrace(TRACE_CLIPBOARD, wxT("Received selection %s"),
               format.GetId().c_str());

    if ( !m_receivedData->IsSupportedFormat(format, wxDataObject::Set) )
        return;

    m_receivedData->SetData(format,
        gtk_selection_data_get_length(const_cast<GtkSelectionData*>(&sel)),
        gtk_selection_data_get_data(const_cast<GtkSelectionData*>(&sel)));
    m_formatSupported = true;
}
예제 #5
0
size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
{
    if ( format.GetFormatId() == CF_DIB )
    {
        // create the DIB
        ScreenHDC hdc;

        // shouldn't be selected into a DC or GetDIBits() would fail
        wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
                      wxT("can't copy bitmap selected into wxMemoryDC") );

        // first get the info
        BITMAPINFO bi;
        if ( !GetDIBits(hdc, (HBITMAP)m_bitmap.GetHBITMAP(), 0, 0,
                        NULL, &bi, DIB_RGB_COLORS) )
        {
            wxLogLastError(wxT("GetDIBits(NULL)"));

            return 0;
        }

        return sizeof(BITMAPINFO) + bi.bmiHeader.biSizeImage;
    }
    else // CF_BITMAP
    {
        // no data to copy - we don't pass HBITMAP via global memory
        return 0;
    }
}
예제 #6
0
bool wxDataFormat::operator==(const wxDataFormat& format) const
{
    if (IsStandard() || format.IsStandard())
        return ( format.m_type == m_type );
    else
        return ( UTTypeConformsTo( (CFStringRef) m_format , (CFStringRef) format.m_format ) );
}
예제 #7
0
bool wxGetClipboardFormatName(const wxDataFormat& dataFormat, char *formatName,
                              int maxCount)
{
    wxStrlcpy( formatName, dataFormat.GetId().c_str(), maxCount );

    return true;
}
예제 #8
0
bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
{
    wxLogTrace(TRACE_CLIPBOARD, wxT("Checking if format %s is available"),
               dataFormat.GetId().c_str());

    if ( m_data )
        return m_data->IsSupported( dataFormat );
    return wxDataObject::IsFormatInPasteboard( m_pasteboard, dataFormat );
}
예제 #9
0
파일: drawdnd.cpp 프로젝트: wds315/szarp
bool SetInfoDataObject::GetDataHere(const wxDataFormat& format, void *pbuf) const {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		return false;

	wxString url = GetUrl();

	char *curl = strdup((char*)SC::S2U(url).c_str());
	size_t len = strlen(curl);
	if (format.GetType() == wxDF_FILENAME)
		len += 1;

	memcpy(pbuf, curl, len);
	free(curl);

	return true;
}
예제 #10
0
void CIDataObject::SetData (
  const wxDataFormat&               rFormat
, char*                             pzBuffer
)
{
    ULONG                           ulSize = 0;

    switch (rFormat.GetType())
    {
        case wxDF_TEXT:
        case wxDF_OEMTEXT:
        case wxDF_FILENAME:
        case wxDF_HTML:
            ulSize = strlen((const char *)pzBuffer);
            break;

#if wxUSE_UNICODE
        case wxDF_UNICODETEXT:
             ulSize = ::wcslen((const wchar_t *)pzBuffer);
             break;
#endif

        case wxDF_BITMAP:
        case wxDF_METAFILE:
        case wxDF_ENHMETAFILE:
        case wxDF_TIFF:
        case wxDF_DIB:
            ulSize = 0; // pass via a handle
            break;


        case wxDF_SYLK:
        case wxDF_DIF:
        case wxDF_PALETTE:
        case wxDF_PENDATA:
        case wxDF_RIFF:
        case wxDF_WAVE:
        case wxDF_LOCALE:
            //PUNT
            break;

        case wxDF_PRIVATE:
            size_t*                 p = (size_t *)pzBuffer;

            ulSize = *p++;
            pzBuffer = (char*)p;
            break;
    }
    m_pDataObject->SetData( rFormat
                           ,ulSize
                           ,(void*)pzBuffer
                          );
} // end of CIDataObject::SetData
예제 #11
0
파일: drawdnd.cpp 프로젝트: wds315/szarp
bool SetInfoDataObject::SetData(const wxDataFormat& format, size_t len, const void *buf) {
	if (format.GetType() != wxDF_TEXT 
			&& format.GetType() != wxDF_FILENAME
//			&& format.GetType() != wxDF_OEMTEXT
			&& format.GetType() != wxDF_UNICODETEXT)
		return false;

	unsigned char *escaped = (unsigned char*)malloc(len + 1);
	memcpy(escaped, buf, len);
	escaped[len] = '\0';
	wxString url = decode_string(escaped);
	free(escaped);

	url.Trim(true);
	url.Trim(false);

	if (!decode_url(url, m_prefix, m_set, m_period, m_time, m_selected_draw))
		return false;

	return true;
}
예제 #12
0
bool CIDataObject::GetData ( const wxDataFormat& rFormat,
                             char* pzBuffer,
                             ULONG ulLen )
{
    QueryGetData(rFormat);
    if (rFormat.GetType() == wxDF_INVALID)
        return false;

    ULONG                           ulSize = m_pDataObject->GetDataSize(rFormat);

    if (ulSize == 0)
    {
        //
        // It probably means that the method is just not implemented
        //
        return false;
    }
    if (rFormat.GetType() == wxDF_PRIVATE)
    {
        //
        // For custom formats, put the size with the data - alloc the
        // space for it
        //
        ulSize += sizeof(ULONG);
    }

    if (ulSize > ulLen) // not enough room to copy
        return false;

    //
    // Copy the data
    //
    GetDataHere( rFormat
                ,pzBuffer
                ,ulSize
               );
    return true;
} // end of CIDataObject::GetData
예제 #13
0
bool wxDataObject::IsFormatInPasteboard( void * pb, const wxDataFormat &dataFormat )
{
    PasteboardRef pasteboard = (PasteboardRef) pb;
    bool hasData = false;
    OSStatus err = noErr;
    ItemCount itemCount;

    // we synchronize here once again, so we don't mind which flags get returned
    PasteboardSynchronize( pasteboard );

    err = PasteboardGetItemCount( pasteboard, &itemCount );
    if ( err == noErr )
    {
        for( UInt32 itemIndex = 1; itemIndex <= itemCount && hasData == false ; itemIndex++ )
        {
            PasteboardItemID    itemID;
            CFArrayRef          flavorTypeArray;
            CFIndex             flavorCount;
     
            err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID );
            if ( err != noErr )
                continue;
     
            err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray );
            if ( err != noErr )
                continue;
     
            flavorCount = CFArrayGetCount( flavorTypeArray );
     
            for( CFIndex flavorIndex = 0; flavorIndex < flavorCount && hasData == false ; flavorIndex++ )
            {
                CFStringRef             flavorType;
     
                flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray,
                                                                     flavorIndex );
                     
                wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType );
                if ( dataFormat == flavorFormat )
                    hasData = true;
                else if (  dataFormat.GetType() == wxDF_UNICODETEXT && flavorFormat.GetType() == wxDF_TEXT )
                    hasData = true;
            }
            CFRelease (flavorTypeArray);
        }
    }

    return hasData;
}
예제 #14
0
bool wxClipboard::IsSupported( const wxDataFormat& format )
{
    /* reentrance problems */
    if (m_waiting) return FALSE;

    /* store requested format to be asked for by callbacks */
    m_targetRequested = format;

    wxLogTrace( TRACE_CLIPBOARD,
                wxT("wxClipboard:IsSupported: requested format: %s"),
                format.GetId().c_str() );

    wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );

    m_formatSupported = FALSE;

    /* perform query. this will set m_formatSupported to
       TRUE if m_targetRequested is supported.
       also, we have to wait for the "answer" from the
       clipboard owner which is an asynchronous process.
       therefore we set m_waiting = TRUE here and wait
       until the callback "targets_selection_received"
       sets it to FALSE */

    m_waiting = TRUE;

    gtk_selection_convert( m_targetsWidget,
                           m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                                        : g_clipboardAtom,
                           g_targetsAtom,
                           (guint32) GDK_CURRENT_TIME );

    while (m_waiting) gtk_main_iteration();

#if defined(__WXGTK20__) && wxUSE_UNICODE
    if (!m_formatSupported && format == wxDataFormat(wxDF_UNICODETEXT))
    {
        // Another try with plain STRING format
        extern GdkAtom g_altTextAtom;
        return IsSupported(g_altTextAtom);
    }
#endif

    return m_formatSupported;
}
예제 #15
0
bool wxBitmapDataObject::SetData(const wxDataFormat& format,
                                 size_t size, const void *pBuf)
{
    HBITMAP hbmp;
    if ( format.GetFormatId() == CF_DIB )
    {
        // here we get BITMAPINFO struct followed by the actual bitmap bits and
        // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
        ScreenHDC hdc;

        BITMAPINFO *pbmi = (BITMAPINFO *)pBuf;
        BITMAPINFOHEADER *pbmih = &pbmi->bmiHeader;
        hbmp = CreateDIBitmap(hdc, pbmih, CBM_INIT,
                              pbmi + 1, pbmi, DIB_RGB_COLORS);
        if ( !hbmp )
        {
            wxLogLastError(wxT("CreateDIBitmap"));
        }

        m_bitmap.SetWidth(pbmih->biWidth);
        m_bitmap.SetHeight(pbmih->biHeight);
    }
    else // CF_BITMAP
    {
        // it's easy with bitmaps: we pass them by handle
        hbmp = *(HBITMAP *)pBuf;

        BITMAP bmp;
        if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) )
        {
            wxLogLastError(wxT("GetObject(HBITMAP)"));
        }

        m_bitmap.SetWidth(bmp.bmWidth);
        m_bitmap.SetHeight(bmp.bmHeight);
        m_bitmap.SetDepth(bmp.bmPlanes);
    }

    m_bitmap.SetHBITMAP((WXHBITMAP)hbmp);

    wxASSERT_MSG( m_bitmap.IsOk(), wxT("pasting invalid bitmap") );

    return true;
}
예제 #16
0
bool wxClipboard::IsSupported(const wxDataFormat& format)
{
    Display* xdisplay = wxGlobalDisplay();
    Window xwindow = XtWindow( (Widget)wxTheApp->GetTopLevelRealizedWidget() );
    bool isSupported = false;
    int retval, count;
    unsigned long  max_name_length;
    wxString id = format.GetId();

    while( ( retval = XmClipboardLock( xdisplay, xwindow ) )
            == XmClipboardLocked );
    if( retval != XmClipboardSuccess )
        return false;

    if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length )
            == XmClipboardSuccess )
    {
        wxCharBuffer buf( max_name_length + 1 );
        unsigned long copied;

        for( int i = 0; i < count; ++i )
        {
            if( XmClipboardInquireFormat( xdisplay, xwindow, i + 1,
                                          (XtPointer)buf.data(),
                                          max_name_length, &copied )
                    != XmClipboardSuccess )
                continue;

            buf.data()[copied] = '\0';

            if( buf == id )
            {
                isSupported = true;
                break;
            }
        }
    }

    XmClipboardUnlock( xdisplay, xwindow, False );

    return isSupported;
}
예제 #17
0
bool wxClipboard::IsSupported( const wxDataFormat& format )
{
    /* reentrance problems */
    if (m_waiting) return false;

    /* store requested format to be asked for by callbacks */
    m_targetRequested = format;

#if 0
    wxLogTrace( TRACE_CLIPBOARD,
                wxT("wxClipboard:IsSupported: requested format: %s"),
                format.GetId().c_str() );
#endif

    wxCHECK_MSG( m_targetRequested, false, wxT("invalid clipboard format") );

    m_formatSupported = false;

    /* perform query. this will set m_formatSupported to
       true if m_targetRequested is supported.
       also, we have to wait for the "answer" from the
       clipboard owner which is an asynchronous process.
       therefore we set m_waiting = true here and wait
       until the callback "targets_selection_received"
       sets it to false */

    m_waiting = true;

#if 0
    gtk_selection_convert( m_targetsWidget,
                           m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                                        : g_clipboardAtom,
                           g_targetsAtom,
                           (guint32) GDK_CURRENT_TIME );

    while (m_waiting) gtk_main_iteration();
#endif

    if (!m_formatSupported) return false;

    return true;
}
예제 #18
0
bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format,
                                     void *pBuf) const
{
    wxASSERT_MSG( m_bitmap.IsOk(), wxT("copying invalid bitmap") );

    HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP();
    if ( format.GetFormatId() == CF_DIB )
    {
        // create the DIB
        ScreenHDC hdc;

        // shouldn't be selected into a DC or GetDIBits() would fail
        wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
                      wxT("can't copy bitmap selected into wxMemoryDC") );

        // first get the info
        BITMAPINFO *pbi = (BITMAPINFO *)pBuf;
        if ( !GetDIBits(hdc, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) )
        {
            wxLogLastError(wxT("GetDIBits(NULL)"));

            return 0;
        }

        // and now copy the bits
        if ( !GetDIBits(hdc, hbmp, 0, pbi->bmiHeader.biHeight, pbi + 1,
                        pbi, DIB_RGB_COLORS) )
        {
            wxLogLastError(wxT("GetDIBits"));

            return false;
        }
    }
    else // CF_BITMAP
    {
        // we put a bitmap handle into pBuf
        *(HBITMAP *)pBuf = hbmp;
    }

    return true;
}
예제 #19
0
bool wxClipboard::DoIsSupported(const wxDataFormat& format)
{
    wxCHECK_MSG( format, false, wxT("invalid clipboard format") );

    wxLogTrace(TRACE_CLIPBOARD, wxT("Checking if format %s is available"),
               format.GetId().c_str());

    // these variables will be used by our GTKOnTargetReceived()
    m_targetRequested = format;
    m_formatSupported = false;

    // block until m_formatSupported is set from targets_selection_received
    // callback
    {
        wxClipboardSync sync(*this);

        gtk_selection_convert( m_targetsWidget,
                               GTKGetClipboardAtom(),
                               g_targetsAtom,
                               (guint32) GDK_CURRENT_TIME );
    }

    return m_formatSupported;
}