//
// Taken from http://wxwidgets.org/docs/technote/install.htm
//
wxString PlatformCompatibility::GetExecutablePath()
{
    static bool found = false;
    static wxString path;

    if (found)
        return path;
    else
    {
#ifdef __WXMSW__

        wxChar buf[512];
        *buf = '\0';
        GetModuleFileName(NULL, buf, 511);
        path = buf;

#elif defined(__WXMAC__)

        ProcessInfoRec processinfo;
        ProcessSerialNumber procno ;
        FSSpec fsSpec;

        procno.highLongOfPSN = 0 ;
        procno.lowLongOfPSN = kCurrentProcess ;
        processinfo.processInfoLength = sizeof(ProcessInfoRec);
        processinfo.processName = NULL;
        processinfo.processAppSpec = &fsSpec;

        GetProcessInformation( &procno , &processinfo ) ;
        path = wxMacFSSpec2MacFilename(&fsSpec);
#else
        wxString argv0 = wxGetApp().argv[0];

        if (wxIsAbsolutePath(argv0))
            path = argv0;
        else
        {
            wxPathList pathlist;
            pathlist.AddEnvList(wxT("PATH"));
            path = pathlist.FindAbsoluteValidPath(argv0);
        }

        wxFileName filename(path);
        filename.Normalize();
        path = filename.GetFullPath();
#endif
        found = true;
        return path;
    }
}
Esempio n. 2
0
// TODO: implement this using real CoreFoundation API instead of Carbon API
wxString wxStandardPathsCF::GetExecutablePath() const
{
#ifdef __WXMAC__
    ProcessInfoRec processinfo;
    ProcessSerialNumber procno ;
    FSSpec fsSpec;

    procno.highLongOfPSN = 0 ;
    procno.lowLongOfPSN = kCurrentProcess ;
    processinfo.processInfoLength = sizeof(ProcessInfoRec);
    processinfo.processName = NULL;
    processinfo.processAppSpec = &fsSpec;

    GetProcessInformation( &procno , &processinfo ) ;
    return wxMacFSSpec2MacFilename(&fsSpec);
#else
    return wxStandardPathsBase::GetExecutablePath();
#endif
}
Esempio n. 3
0
wxString wxStandardPathsCF::GetExecutablePath() const
{
#ifdef __WXMAC__
#if 1
    return GetFromFunc(CFBundleCopyBundleURL);
#else
    // TODO remove if cf implementation ok
    ProcessInfoRec processinfo;
    ProcessSerialNumber procno ;
#ifdef __LP64__
    FSRef  fsRef;
#else
    FSSpec fsSpec;
#endif
    
    procno.highLongOfPSN = 0 ;
    procno.lowLongOfPSN = kCurrentProcess ;
    processinfo.processInfoLength = sizeof(ProcessInfoRec);
    processinfo.processName = NULL;
#ifdef __LP64__
    processinfo.processAppRef = &fsRef;
#else
    processinfo.processAppSpec = &fsSpec;
#endif
    
    GetProcessInformation( &procno , &processinfo ) ;
#ifdef __LP64__
    return wxMacFSRefToPath(&fsRef);
#else
    return wxMacFSSpec2MacFilename(&fsSpec);
#endif
#endif
    
#else
    return wxStandardPathsBase::GetExecutablePath();
#endif
}
Esempio n. 4
0
int wxDirDialog::ShowModal()
{
    NavDialogOptions        mNavOptions;
    NavObjectFilterUPP        mNavFilterUPP = NULL;
    NavPreviewUPP            mNavPreviewUPP = NULL ;
    NavReplyRecord            mNavReply;
    AEDesc*                    mDefaultLocation = NULL ;
    bool                    mSelectDefault = false ;

    ::NavGetDefaultDialogOptions(&mNavOptions);

    mNavFilterUPP    = nil;
    mNavPreviewUPP    = nil;
    mSelectDefault    = false;
    mNavReply.validRecord                = false;
    mNavReply.replacing                    = false;
    mNavReply.isStationery                = false;
    mNavReply.translationNeeded            = false;
    mNavReply.selection.descriptorType = typeNull;
    mNavReply.selection.dataHandle        = nil;
    mNavReply.keyScript                    = smSystemScript;
    mNavReply.fileTranslation            = nil;

    // Set default location, the location
    //   that's displayed when the dialog
    //   first appears

    if ( mDefaultLocation ) {

        if (mSelectDefault) {
            mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
        } else {
            mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
        }
    }

    OSErr err = ::NavChooseFolder(
                        mDefaultLocation,
                        &mNavReply,
                        &mNavOptions,
                        NULL,
                        mNavFilterUPP,
                        0L);                            // User Data

    if ( (err != noErr) && (err != userCanceledErr) ) {
        m_path = wxEmptyString ;
        return wxID_CANCEL ;
    }

    if (mNavReply.validRecord) {        // User chose a folder

        FSSpec    folderInfo;
        FSSpec  outFileSpec ;
        AEDesc specDesc ;

        OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
        if ( err != noErr ) {
            m_path = wxEmptyString ;
            return wxID_CANCEL ;
        }
        folderInfo = **(FSSpec**) specDesc.dataHandle;
        if (specDesc.dataHandle != nil) {
            ::AEDisposeDesc(&specDesc);
        }

//            mNavReply.GetFileSpec(folderInfo);

            // The FSSpec from NavChooseFolder is NOT the file spec
            // for the folder. The parID field is actually the DirID
            // of the folder itself, not the folder's parent, and
            // the name field is empty. We must call PBGetCatInfo
            // to get the parent DirID and folder name

        Str255        name;
        CInfoPBRec    thePB;            // Directory Info Parameter Block
        thePB.dirInfo.ioCompletion    = nil;
        thePB.dirInfo.ioVRefNum        = folderInfo.vRefNum;    // Volume is right
        thePB.dirInfo.ioDrDirID        = folderInfo.parID;        // Folder's DirID
        thePB.dirInfo.ioNamePtr        = name;
        thePB.dirInfo.ioFDirIndex    = -1;    // Lookup using Volume and DirID

        err = ::PBGetCatInfoSync(&thePB);
        if ( err != noErr ) {
            m_path = wxEmptyString;
            return wxID_CANCEL ;
        }
                                            // Create cannonical FSSpec
        ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
                       name, &outFileSpec);

        // outFolderDirID = thePB.dirInfo.ioDrDirID;
        m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
        return wxID_OK ;
    }
    return wxID_CANCEL;
}
Esempio n. 5
0
int wxFileDialog::ShowModal()
{
#if TARGET_CARBON
    OSErr err;
    NavDialogCreationOptions dialogCreateOptions;
    // set default options
    ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions);

    // this was always unset in the old code
    dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation;

    wxMacCFStringHolder message(m_message, m_font.GetEncoding());
    dialogCreateOptions.windowTitle = message;

    wxMacCFStringHolder defaultFileName(m_fileName, m_font.GetEncoding());
    dialogCreateOptions.saveFileName = defaultFileName;


    NavDialogRef dialog;
    NavObjectFilterUPP navFilterUPP = NULL;
    CFArrayRef cfArray = NULL; // for popupExtension
    OpenUserDataRec myData;
    myData.defaultLocation = m_dir;

    if (m_dialogStyle & wxSAVE)
    {
        dialogCreateOptions.optionFlags |= kNavNoTypePopup;
        dialogCreateOptions.optionFlags |= kNavDontAutoTranslate;
        dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems;

        // The extension is important
        dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension;

        err = ::NavCreatePutFileDialog(&dialogCreateOptions,
                                       'TEXT',
                                       'TEXT',
                                       sStandardNavEventFilter,
                                       &myData, // for defaultLocation
                                       &dialog);
    }
    else
    {
        MakeUserDataRec(&myData , m_wildCard);
        size_t numfilters = myData.extensions.GetCount();
        if (numfilters > 0)
        {
            CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault ,
                                      numfilters , &kCFTypeArrayCallBacks ) ;
            dialogCreateOptions.popupExtension = popup ;
            myData.menuitems = dialogCreateOptions.popupExtension ;
            for ( size_t i = 0 ; i < numfilters ; ++i )
            {
                CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ;
            }
        }

        navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback);
        err = ::NavCreateGetFileDialog(&dialogCreateOptions,
                                       NULL, // NavTypeListHandle
                                       sStandardNavEventFilter,
                                       NULL, // NavPreviewUPP
                                       navFilterUPP,
                                       (void *) &myData, // inClientData
                                       &dialog);
    }

    if (err == noErr)
        err = ::NavDialogRun(dialog);

    // clean up filter related data, etc.
    if (navFilterUPP)
        ::DisposeNavObjectFilterUPP(navFilterUPP);
    if (cfArray)
        ::CFRelease(cfArray);

    if (err != noErr)
        return wxID_CANCEL;

    NavReplyRecord navReply;
    err = ::NavDialogGetReply(dialog, &navReply);
    if (err == noErr && navReply.validRecord)
    {
        AEKeyword   theKeyword;
        DescType    actualType;
        Size        actualSize;
        FSRef       theFSRef;
        wxString thePath ;
        long count;
        ::AECountItems(&navReply.selection , &count);
        for (long i = 1; i <= count; ++i)
        {
            err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType,
                                &theFSRef, sizeof(theFSRef), &actualSize);
            if (err != noErr)
                break;

            CFURLRef fullURLRef;
            if (m_dialogStyle & wxSAVE)
            {
                CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);

                if (parentURLRef)
                {
                    fullURLRef =
                        ::CFURLCreateCopyAppendingPathComponent(NULL,
                                parentURLRef,
                                navReply.saveFileName,
                                false);
                    ::CFRelease(parentURLRef);
                }
            }
            else
            {
                fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
            }
#ifdef __UNIX__
            CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
#else
            CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
#endif
            CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
            thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding());
            if (!thePath)
            {
                ::NavDisposeReply(&navReply);
                return wxID_CANCEL;
            }
            m_path = thePath;
            m_paths.Add(m_path);
            m_fileName = wxFileNameFromPath(m_path);
            m_fileNames.Add(m_fileName);
        }
        // set these to the first hit
        m_path = m_paths[0];
        m_fileName = wxFileNameFromPath(m_path);
        m_dir = wxPathOnly(m_path);
    }
    ::NavDisposeReply(&navReply);

    return (err == noErr) ? wxID_OK : wxID_CANCEL;
#else // TARGET_CARBON

    NavDialogOptions           mNavOptions;
    NavObjectFilterUPP           mNavFilterUPP = NULL;
    NavPreviewUPP           mNavPreviewUPP = NULL ;
    NavReplyRecord           mNavReply;
    AEDesc               mDefaultLocation ;
    bool               mSelectDefault = false ;
    OSStatus            err = noErr ;
    // setup dialog

    mNavFilterUPP    = nil;
    mNavPreviewUPP    = nil;
    mSelectDefault    = false;
    mDefaultLocation.descriptorType = typeNull;
    mDefaultLocation.dataHandle     = nil;

    NavGetDefaultDialogOptions(&mNavOptions);
    wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ;
    wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ;

    // Set default location, the location
    //   that's displayed when the dialog
    //   first appears

    FSSpec location ;
    wxMacFilename2FSSpec( m_dir , &location ) ;

    err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation );

    if ( mDefaultLocation.dataHandle )
    {
        if (mSelectDefault)
        {
            mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
        } else {
            mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
        }
    }

    memset( &mNavReply , 0 , sizeof( mNavReply ) ) ;
    mNavReply.validRecord = false;
    mNavReply.replacing = false;
    mNavReply.isStationery = false;
    mNavReply.translationNeeded = false;
    mNavReply.selection.descriptorType = typeNull;
    mNavReply.selection.dataHandle = nil;
    mNavReply.keyScript = smSystemScript;
    mNavReply.fileTranslation = nil;
    mNavReply.version = kNavReplyRecordVersion ;

    // zero all data

    m_path = wxEmptyString ;
    m_fileName = wxEmptyString ;
    m_paths.Empty();
    m_fileNames.Empty();

    OpenUserDataRec            myData;
    MakeUserDataRec( &myData , m_wildCard ) ;
    myData.currentfilter = m_filterIndex ;
    if ( myData.extensions.GetCount() > 0 )
    {
        mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ;
        myData.menuitems = mNavOptions.popupExtension ;
        for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i )
        {
            (*mNavOptions.popupExtension)[i].version     = kNavMenuItemSpecVersion ;
            (*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ;
            // TODO : according to the new docs  -1 to 10 are reserved for the OS
            (*mNavOptions.popupExtension)[i].menuType    = i ;
            wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ;
        }
    }
    if ( m_dialogStyle & wxSAVE )
    {
        myData.saveMode = true ;

        mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ;
        mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ;

        err = ::NavPutFile(
                  &mDefaultLocation,
                  &mNavReply,
                  &mNavOptions,
                  sStandardNavEventFilter ,
                  NULL,
                  kNavGenericSignature,
                  &myData);                    // User Data
        m_filterIndex = myData.currentfilter ;
    }
    else
    {
        myData.saveMode = false ;

        mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ;
        if ( m_dialogStyle & wxMULTIPLE )
            mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ;
        else
            mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ;

        err = ::NavGetFile(
                  &mDefaultLocation,
                  &mNavReply,
                  &mNavOptions,
                  sStandardNavEventFilter ,
                  mNavPreviewUPP,
                  mNavFilterUPP,
                  NULL ,
                  &myData);
        m_filterIndex = myData.currentfilter ;
    }

    DisposeNavObjectFilterUPP(mNavFilterUPP);
    if ( mDefaultLocation.dataHandle != nil )
    {
        ::AEDisposeDesc(&mDefaultLocation);
    }

    if ( (err != noErr) && (err != userCanceledErr) ) {
        return wxID_CANCEL ;
    }

    if (mNavReply.validRecord)
    {
        FSSpec  outFileSpec ;
        AEDesc specDesc ;
        AEKeyword keyWord ;

        long count ;
        ::AECountItems( &mNavReply.selection , &count ) ;
        for ( long i = 1 ; i <= count ; ++i )
        {
            OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc);
            if ( err != noErr )
            {
                m_path = wxT("") ;
                return wxID_CANCEL ;
            }
            outFileSpec = **(FSSpec**) specDesc.dataHandle;
            if (specDesc.dataHandle != nil) {
                ::AEDisposeDesc(&specDesc);
            }
            m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;

            m_paths.Add( m_path ) ;
            m_fileName = wxFileNameFromPath(m_path);
            m_fileNames.Add(m_fileName);
        }
        // set these to the first hit
        m_path = m_paths[ 0 ] ;
        m_fileName = wxFileNameFromPath(m_path);
        m_dir = wxPathOnly(m_path);
        NavDisposeReply( &mNavReply ) ;
        return wxID_OK ;
    }
    return wxID_CANCEL;
#endif // TARGET_CARBON
}
Esempio n. 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 ) ;
            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 ;   
}
Esempio n. 7
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;
}
Esempio n. 8
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 ;   
}