Example #1
0
bool wxDropTarget::CurrentDragHasSupportedFormat()
{
    bool supported = false;

    if ( gTrackingGlobals.m_currentSource != NULL )
    {
        wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject();

        if ( data )
        {
            size_t formatcount = data->GetFormatCount();
            wxDataFormat *array = new wxDataFormat[formatcount];
            data->GetAllFormats( array );
            for (size_t i = 0; !supported && i < formatcount; i++)
            {
                wxDataFormat format = array[i];
                if ( m_dataObject->IsSupported( format ) )
                {
                    supported = true;
                    break;
                }
            }

            delete [] array;
        }
    }

    if ( !supported )
    {
        UInt16 items;
        ItemReference theItem;
        FlavorType theType;
        UInt16 flavors = 0;

        CountDragItems( (DragReference)m_currentDrag, &items );
        for (UInt16 index = 1; index <= items && !supported; ++index)
        {
            flavors = 0;
            GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
            CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors );

            for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
            {
                GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
                {
                    supported = true;
                    break;
                }
            }
        }
    }

    return supported;
}
Example #2
0
pascal OSErr DragReceiveFunc(
	WindowPtr		/*window*/,
	void*			/*theRefCon*/,
	DragReference	drag)
{
	long			i;
	char*			data;
	unsigned short	numFlavors;
	Size			dataSize;
	ItemReference	theItem;
	unsigned short	itemCount;
	FlavorType		flavor;

	if( recieveHiliting )
	{		
		int	oldListEnd=mac_n_files;
		CountDragItems(drag, &itemCount);

		for( i=1; i<=itemCount; i++)
		{
			GetDragItemReferenceNumber(drag, i, &theItem);
			
			if( noErr!=CountDragItemFlavors(drag, theItem, &numFlavors))
						continue;
			if( noErr!=GetFlavorType(drag, theItem, 1, &flavor))
						continue;
			if( noErr!=GetFlavorDataSize(drag, theItem, flavor, &dataSize))
						continue;
			data= (char*)malloc(dataSize);
			if( data==0 ) continue;

			if( noErr!=GetFlavorData(drag, theItem, flavor,
						data, &dataSize, 0))
						continue;
			if(flavor== flavorTypeHFS)
				AddHFS2PlayList((HFSFlavor*)data);
			free(data);
		}
		if( gShuffle ) ShuffleList( oldListEnd, mac_n_files);
	}
	
	return noErr;
}
Example #3
0
static PyObject *DragObj_GetFlavorType(DragObjObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	ItemReference theItemRef;
	UInt16 index;
	FlavorType theType;
#ifndef GetFlavorType
	PyMac_PRECHECK(GetFlavorType);
#endif
	if (!PyArg_ParseTuple(_args, "lH",
	                      &theItemRef,
	                      &index))
		return NULL;
	_err = GetFlavorType(_self->ob_itself,
	                     theItemRef,
	                     index,
	                     &theType);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O&",
	                     PyMac_BuildOSType, theType);
	return _res;
}
Example #4
0
bool wxDropTarget::GetData()
{
    if (!m_dataObject)
        return FALSE;
    
    if ( !CurrentDragHasSupportedFormat() )
        return FALSE ;
    
    bool transferred = false ;   
    if ( gTrackingGlobals.m_currentSource != NULL )
    {
        wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
        
        if ( data )
        {
            size_t formatcount = data->GetFormatCount() ;
            wxDataFormat *array = new wxDataFormat[ formatcount  ];
            data->GetAllFormats( array );
            for (size_t i = 0; !transferred && i < formatcount ; i++)
            {
                wxDataFormat format = array[i] ;
                if ( m_dataObject->IsSupported( format ) ) 
                {
                    int size = data->GetDataSize( format );
                    transferred = true ;
                    
                    if (size == 0) 
                    {
                        m_dataObject->SetData(format , 0 , 0 ) ;
                    }
                    else
                    {
                        char *d = new char[size];
                        data->GetDataHere( format , (void*) d );
                        m_dataObject->SetData( format , size , d ) ;
                        delete[] d ;
                    }
                }
            }
            delete[] array ;
        }
    }
    if ( !transferred )
    {
        UInt16 items ;
        OSErr result;
        bool firstFileAdded = false ;
        CountDragItems((DragReference)m_currentDrag, &items);
        for (UInt16 index = 1; index <= items; ++index) 
        {
            ItemReference theItem;
            FlavorType theType ;
            UInt16 flavors = 0 ;
            GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
            CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
            for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
            {
                result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
                wxDataFormat format(theType) ;
                if ( m_dataObject->IsSupportedFormat( format ) )
                {
                    FlavorFlags theFlags;
                    result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
                    if (result == noErr) 
                    {
                        Size dataSize ;
                        Ptr theData ;
                        GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
                        if ( theType == 'TEXT' )
                        {
                            // this increment is only valid for allocating, on the next GetFlavorData
                            // call it is reset again to the original value
                            dataSize++ ;
                        }
                        theData = new char[dataSize];
                        GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
                        if( theType == 'TEXT' )
                        {
                            theData[dataSize]=0 ; 
                            wxString convert( theData , wxConvLocal ) ;    
                            m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert );
                        }
                        else if ( theType == kDragFlavorTypeHFS )
                        {
                            HFSFlavor* theFile = (HFSFlavor*) theData ;
                            wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ;
                            if (  firstFileAdded )
                                ((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
                            else
                            {
                                ((wxFileDataObject*)m_dataObject)->SetData( 0 , name.c_str() ) ;
                                firstFileAdded = true ;    
                            }
                        }
                        else
                        {
                            m_dataObject->SetData( format, dataSize, theData );
                        }
                        delete[] theData;
                    }
                    break ;
                }
            }
        }
    }
    return TRUE ;   
}
Example #5
0
bool wxDropTarget::GetData()
{
    if (m_dataObject == NULL)
        return false;

    if ( !CurrentDragHasSupportedFormat() )
        return false;

    bool transferred = false;
    if ( gTrackingGlobals.m_currentSource != NULL )
    {
        wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject();

        if (data != NULL)
        {
            size_t formatcount = data->GetFormatCount();
            wxDataFormat *array = new wxDataFormat[formatcount];
            data->GetAllFormats( array );
            for (size_t i = 0; !transferred && i < formatcount; i++)
            {
                wxDataFormat format = array[i];
                if ( m_dataObject->IsSupported( format ) )
                {
                    int size = data->GetDataSize( format );
                    transferred = true;

                    if (size == 0)
                    {
                        m_dataObject->SetData( format, 0, 0 );
                    }
                    else
                    {
                        char *d = new char[size];
                        data->GetDataHere( format, (void*)d );
                        m_dataObject->SetData( format, size, d );
                        delete [] d;
                    }
                }
            }

            delete [] array;
        }
    }

    if ( !transferred )
    {
        UInt16 items;
        OSErr result;
        ItemReference theItem;
        FlavorType theType;
        FlavorFlags theFlags;
        UInt16 flavors;
        wxString filenamesPassed;

        CountDragItems( (DragReference)m_currentDrag, &items );
        for (UInt16 index = 1; index <= items; ++index)
        {
            flavors = 0;
            GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
            CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors );
            wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
            bool hasPreferredFormat = false;

            for (UInt16 flavor = 1; flavor <= flavors; ++flavor)
            {
                result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                wxDataFormat format( theType );
                if (preferredFormat == format)
                {
                    hasPreferredFormat = true;
                    break;
                }
            }

            for (UInt16 flavor = 1; flavor <= flavors; ++flavor)
            {
                result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
                wxDataFormat format( theType );
                if ((hasPreferredFormat && format == preferredFormat)
                    || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
                {
                    result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags );
                    if (result == noErr)
                    {
                        Size dataSize;
                        Ptr theData;

                        GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
                        if (theType == kScrapFlavorTypeText)
                        {
                            // this increment is only valid for allocating:
                            // on the next GetFlavorData call it is reset again to the original value
                            dataSize++;
                        }
                        else if (theType == kScrapFlavorTypeUnicode)
                        {
                            // this increment is only valid for allocating:
                            // on the next GetFlavorData call it is reset again to the original value
                            dataSize++;
                            dataSize++;
                        }

                        if (dataSize > 0)
                            theData = new char[dataSize];
                        else
                            theData = NULL;

                        GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*)theData, &dataSize, 0L );
                        switch (theType)
                        {
                        case kScrapFlavorTypeText:
                            theData[dataSize] = 0;
                            m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize, theData );
                            break;

#if wxUSE_UNICODE
                        case kScrapFlavorTypeUnicode:
                            theData[dataSize + 0] =
                            theData[dataSize + 1] = 0;
                            m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize, theData );
                            break;
#endif

                        case kDragFlavorTypeHFS:
                            if (theData != NULL)
                            {
                                HFSFlavor* theFile = (HFSFlavor*)theData;
#ifndef __LP64__
                                wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );

                                if (!name.empty())
                                    filenamesPassed += name + wxT("\n");
#endif
                            }
                            break;

                        default:
                            m_dataObject->SetData( format, dataSize, theData );
                            break;
                        }

                        delete [] theData;
                    }
                    break;
                }
            }
        }

        if (filenamesPassed.length() > 0)
        {
            wxCharBuffer buf = filenamesPassed.fn_str();
            m_dataObject->SetData( wxDataFormat(wxDF_FILENAME), strlen( buf ), (const char*)buf );
        }
    }

    return true;
}
Example #6
0
bool wxDropTarget::GetData()
{
    if (!m_dataObject)
        return FALSE;
    
    if ( !CurrentDragHasSupportedFormat() )
        return FALSE ;
    
    bool transferred = false ;   
    if ( gTrackingGlobals.m_currentSource != NULL )
    {
        wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
        
        if ( data )
        {
            size_t formatcount = data->GetFormatCount() ;
            wxDataFormat *array = new wxDataFormat[ formatcount  ];
            data->GetAllFormats( array );
            for (size_t i = 0; !transferred && i < formatcount ; i++)
            {
                wxDataFormat format = array[i] ;
                if ( m_dataObject->IsSupported( format ) ) 
                {
                    int size = data->GetDataSize( format );
                    transferred = true ;
                    
                    if (size == 0) 
                    {
                        m_dataObject->SetData(format , 0 , 0 ) ;
                    }
                    else
                    {
                        char *d = new char[size];
                        data->GetDataHere( format , (void*) d );
                        m_dataObject->SetData( format , size , d ) ;
                        delete[] d ;
                    }
                }
            }
            delete[] array ;
        }
    }
    if ( !transferred )
    {
        UInt16 items ;
        OSErr result;
        bool firstFileAdded = false ;
        CountDragItems((DragReference)m_currentDrag, &items);
        for (UInt16 index = 1; index <= items; ++index) 
        {
            ItemReference theItem;
            FlavorType theType ;
            UInt16 flavors = 0 ;
            GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
            CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
            bool hasPreferredFormat = false ;
            wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
            
            for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
            {
                result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
                wxDataFormat format(theType) ;
                if ( preferredFormat == format )
                {
                    hasPreferredFormat = true ;
                    break ;
                }
            }
            
            for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
            {
                result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
                wxDataFormat format(theType) ;
                if ( (hasPreferredFormat && format==preferredFormat) || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
                {
                    FlavorFlags theFlags;
                    result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
                    if (result == noErr) 
                    {
                        Size dataSize ;
                        Ptr theData ;
                        GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
                        if ( theType == kScrapFlavorTypeText )
                        {
                            // this increment is only valid for allocating, on the next GetFlavorData
                            // call it is reset again to the original value
                            dataSize++ ;
                        }
                        else if ( theType == kScrapFlavorTypeUnicode )
                        {
                            // this increment is only valid for allocating, on the next GetFlavorData
                            // call it is reset again to the original value
                            dataSize++ ;
                            dataSize++ ;
                        }
                        theData = new char[dataSize];
                        GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
                        if( theType == kScrapFlavorTypeText )
                        {
                            theData[dataSize]=0 ; 
                            m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
                        }
 #if wxUSE_UNICODE
                        else if ( theType == kScrapFlavorTypeUnicode )
                        {
                            theData[dataSize]=0 ; 
                            theData[dataSize+1]=0 ; 
                            m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData );
                        }
 #endif
                        else if ( theType == kDragFlavorTypeHFS )
                        {
                            HFSFlavor* theFile = (HFSFlavor*) theData ;
                            wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ;
                            if ( !firstFileAdded )
                            {
                                // reset file list
                                ((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
                                firstFileAdded = true ;    
                            }
                            ((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
                        }
                        else
                        {
                            m_dataObject->SetData( format, dataSize, theData );
                        }
                        delete[] theData;
                    }
                    break ;
                }
            }
        }
    }
    return TRUE ;   
}