Ejemplo n.º 1
0
void wxMessageOutputDebug::Printf(const wxChar* format, ...)
{
    wxString out;

    va_list args;
    va_start(args, format);

    out.PrintfV(format, args);
    va_end(args);

#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
    out.Replace(wxT("\t"), wxT("        "));
    out.Replace(wxT("\n"), wxT("\r\n"));
    ::OutputDebugString(out);
#elif defined(__WXMAC__) && !defined(__DARWIN__)
    if ( wxIsDebuggerRunning() )
    {
        Str255 pstr;
        wxString output = out + wxT(";g") ;
        wxMacStringToPascal(output.c_str(), pstr);

        #ifdef __powerc
            DebugStr(pstr);
        #else
            SysBreakStr(pstr);
        #endif
    }
#else
    wxFputs( out , stderr ) ;
    if ( out.Right(1) != wxT("\n") )
        wxFputs( wxT("\n") , stderr ) ;
    fflush( stderr ) ;
#endif // platform
}
Ejemplo n.º 2
0
bool wxSound::Create(const wxString& fileName, bool isResource)
{
    Stop();

    if (isResource)
    {
#ifdef __WXMAC__
        m_type = wxSound_RESOURCE;

        Str255 lpSnd ;

        wxMacStringToPascal( fileName , lpSnd ) ;

        m_sndname = fileName;
        m_hSnd = (char*) GetNamedResource('snd ', (const unsigned char *) lpSnd);
#else
        return false;
#endif
    }
    else
    {
        m_type = wxSound_FILE;
        m_sndname = fileName;
    }

    return true;
}
Ejemplo n.º 3
0
static pascal void
NavEventProc(
    NavEventCallbackMessage        inSelector,
    NavCBRecPtr                    ioParams,
    NavCallBackUserData    ioUserData    )
{
    OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ;
    if (inSelector == kNavCBEvent) {
    }
    else if ( inSelector == kNavCBStart )
    {
        if (data && !(data->defaultLocation).IsEmpty())
        {
            // Set default location for the modern Navigation APIs
            // Apple Technical Q&A 1151
            FSSpec theFSSpec;
            wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec);
            AEDesc theLocation = {typeNull, NULL};
            if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
                ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
        }

        NavMenuItemSpec  menuItem;
        menuItem.version = kNavMenuItemSpecVersion;
        menuItem.menuCreator = 'WXNG';
        menuItem.menuType = data->currentfilter;
        wxMacStringToPascal( data->name[data->currentfilter] , (StringPtr)(menuItem.menuItemName) ) ;
        ::NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &menuItem);
    }
    else if ( inSelector == kNavCBPopupMenuSelect )
    {
        NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ;
        const size_t numFilters = data->extensions.GetCount();

        if ( menu->menuType < numFilters )
        {
            data->currentfilter = menu->menuType ;
            if ( data->saveMode )
            {
                int i = menu->menuType ;
                wxString extension =  data->extensions[i].AfterLast('.') ;
                extension.MakeLower() ;
                wxString sfilename ;

                wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false  );
                sfilename = cfString.AsString() ;

                int pos = sfilename.Find('.', true) ;
                if ( pos != wxNOT_FOUND )
                {
                    sfilename = sfilename.Left(pos+1)+extension ;
                    cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ;
                    NavDialogSetSaveFileName( ioParams->context , cfString ) ;
                }
            }
        }
    }
}
Ejemplo n.º 4
0
int wxListBox::FindString(const wxString& s, bool bCase) const
{
    if ( s.Right(1) == wxT("*") )
    {
        wxString search = s.Left( s.length() - 1 ) ;
        int len = search.length() ;
        Str255 s1 , s2 ;
        wxMacStringToPascal( search , s2 ) ;

        for ( unsigned int i = 0 ; i < m_noItems ; ++ i )
        {
            wxMacStringToPascal( m_stringArray[i].Left( len ) , s1 ) ;

            if ( EqualString( s1 , s2 , bCase , false ) )
                return (int)i ;
        }
        if ( s.Left(1) == wxT("*") && s.length() > 1 )
        {
            wxString st = s ;
            st.MakeLower() ;
            for ( unsigned int i = 0 ; i < m_noItems ; ++i )
            {
                if (GetString(i).Lower().Matches(st))
                    return (int)i ;
            }
        }

    }
    else
    {
        Str255 s1 , s2 ;

        wxMacStringToPascal( s , s2 ) ;

        for ( unsigned int i = 0 ; i < m_noItems ; ++ i )
        {
            wxMacStringToPascal( m_stringArray[i] , s1 ) ;

            if ( EqualString( s1 , s2 , bCase , false ) )
                return (int)i ;
        }
    }

    return wxNOT_FOUND;
}
Ejemplo n.º 5
0
wxOSXSoundManagerSoundData::wxOSXSoundManagerSoundData(const wxString& fileName) :
    m_pSndChannel(NULL)
{
    Str255 lpSnd ;

    wxMacStringToPascal( fileName , lpSnd ) ;

    m_hSnd = (SndListHandle) GetNamedResource('snd ', (const unsigned char *) lpSnd);
}
Ejemplo n.º 6
0
void UMASetMenuItemText(  MenuRef menu,  MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
{
    wxString str = wxStripMenuCodes( title ) ;
#if TARGET_CARBON
    SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
#else
    Str255 ptitle ;
    wxMacStringToPascal( str , ptitle ) ;
    SetMenuItemText( menu , item , ptitle ) ;
#endif
}
Ejemplo n.º 7
0
MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
{
    wxString str = wxStripMenuCodes( title ) ;
    MenuRef menu ;
#if TARGET_CARBON
    CreateNewMenu( id , 0 , &menu ) ;
    SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
#else
    Str255 ptitle ;
    wxMacStringToPascal( str , ptitle ) ;
    menu = ::NewMenu( id , ptitle ) ;
#endif
    return menu ;
}
Ejemplo n.º 8
0
wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
{
    m_refData = new wxCursorRefData;
    if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
    {
        Str255 theName ;
        wxMacStringToPascal( cursor_file , theName ) ;

        wxStAppResource resload ;
        Handle resHandle = ::GetNamedResource( 'crsr' , theName ) ;
        if ( resHandle )
        {
            short theId = -1 ;
            OSType theType ;
            GetResInfo( resHandle , &theId , &theType , theName ) ;
            ReleaseResource( resHandle ) ;
            M_CURSORDATA->m_hCursor = GetCCursor( theId ) ;
            if ( M_CURSORDATA->m_hCursor )
                M_CURSORDATA->m_isColorCursor = true ;
        }
        else
        {
            Handle resHandle = ::GetNamedResource( 'CURS' , theName ) ;
            if ( resHandle )
            {
                short theId = -1 ;
                OSType theType ;
                GetResInfo( resHandle , &theId , &theType , theName ) ;
                ReleaseResource( resHandle ) ;
                 M_CURSORDATA->m_hCursor = GetCursor( theId ) ;
                if ( M_CURSORDATA->m_hCursor )
                    M_CURSORDATA->m_releaseHandle = true ;
            }
        }
    }
    else
    {
        wxImage image ;
        image.LoadFile( cursor_file , flags ) ;
        if( image.Ok() )
        {
            image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,hotSpotX ) ;
            image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,hotSpotY ) ;
            delete m_refData ;
            CreateFromImage(image) ;
        }
    }
}
Ejemplo n.º 9
0
//don't know what to do with looped, wth
bool wxSound::DoPlay(unsigned flags) const
{
    bool ret = false;

    if (m_isResource)
    {
    	Str255 snd ;
    	wxMacStringToPascal( m_sndname , snd ) ;
      	SndListHandle hSnd;

      	hSnd = (SndListHandle) GetNamedResource('snd ', snd);

      	if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, (flags & wxSOUND_ASYNC)) == noErr))
        	ret = true;
    }

    return ret;
}
Ejemplo n.º 10
0
void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , 
             const wxPoint& pos,
             const wxSize& size, long style,
             const wxValidator& validator,
             const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) 
{
    m_label = label ;

    // These sizes will be adjusted in MacPostControlCreate
    m_width = size.x ;
    m_height = size.y ;
    m_x = pos.x ;
    m_y = pos.y ;
        
    ((Rect*)outBounds)->top = -10;
    ((Rect*)outBounds)->left = -10;
    ((Rect*)outBounds)->bottom = 0;
    ((Rect*)outBounds)->right = 0;

    wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
}
Ejemplo n.º 11
0
int wxMessageDialog::ShowModal()
{
    int resultbutton = wxID_CANCEL ;

    short result ;

    const long style = GetMessageDialogStyle();

    wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;

    AlertType alertType = kAlertPlainAlert ;
    if (style & wxICON_EXCLAMATION)
        alertType = kAlertNoteAlert ;
    else if (style & wxICON_HAND)
        alertType = kAlertStopAlert ;
    else if (style & wxICON_INFORMATION)
        alertType = kAlertNoteAlert ;
    else if (style & wxICON_QUESTION)
        alertType = kAlertCautionAlert ;

#if TARGET_CARBON
    if ( UMAGetSystemVersion() >= 0x1000 )
    {
        AlertStdCFStringAlertParamRec param ;
        wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
        wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;

        wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
        wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());

        param.movable = true;
        param.flags = 0 ;

        bool skipDialog = false ;

        if (style & wxYES_NO)
        {
            if (style & wxCANCEL)
            {
                param.defaultText     = cfYesString ;
                param.cancelText     = (CFStringRef) kAlertDefaultCancelText;
                param.otherText     = cfNoString ;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = kAlertStdAlertCancelButton;
            }
            else
            {
                param.defaultText     = cfYesString ;
                param.cancelText     = NULL;
                param.otherText     = cfNoString ;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
        }
        // the msw implementation even shows an ok button if it is not specified, we'll do the same
        else
        {
            if (style & wxCANCEL)
            {
                // thats a cancel missing
                param.defaultText     = (CFStringRef) kAlertDefaultOKText ;
                param.cancelText     = (CFStringRef) kAlertDefaultCancelText ;
                param.otherText     = NULL;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
            else
            {
                param.defaultText     = (CFStringRef) kAlertDefaultOKText ;
                param.cancelText     = NULL;
                param.otherText     = NULL;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
        }
        /*
        else
        {
            skipDialog = true ;
        }
        */

        param.position = kWindowDefaultPosition;
        if ( !skipDialog )
        {
            DialogRef alertRef ;
            CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
            RunStandardAlert( alertRef , NULL , &result ) ;
        }
        if ( skipDialog )
            return wxID_CANCEL ;
    }
    else
#endif
    {
        AlertStdAlertParamRec    param;

        Str255 yesPString ;
        Str255 noPString ;

        Str255 pascalTitle ;
        Str255 pascalText ;
        wxMacStringToPascal( m_caption , pascalTitle ) ;
        wxMacStringToPascal( _("Yes") , yesPString ) ;
        wxMacStringToPascal(  _("No") , noPString ) ;
        wxMacStringToPascal( m_message , pascalText ) ;

        param.movable         = true;
        param.filterProc     = NULL ;
        if (style & wxYES_NO)
        {
            if (style & wxCANCEL)
            {
                param.defaultText     = yesPString ;
                param.cancelText     = (StringPtr) kAlertDefaultCancelText;
                param.otherText     = noPString ;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = kAlertStdAlertCancelButton;
            }
            else
            {
                param.defaultText     = yesPString ;
                param.cancelText     = NULL;
                param.otherText     = noPString ;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
        }
        else if (style & wxOK)
        {
            if (style & wxCANCEL)
            {
                param.defaultText     = (StringPtr) kAlertDefaultOKText ;
                param.cancelText     = (StringPtr) kAlertDefaultCancelText ;
                param.otherText     = NULL;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
            else
            {
                param.defaultText     = (StringPtr) kAlertDefaultOKText ;
                param.cancelText     = NULL;
                param.otherText     = NULL;
                param.helpButton     = false ;
                param.defaultButton = kAlertStdAlertOKButton;
                param.cancelButton     = 0;
            }
        }
        else
        {
            return resultbutton ;
        }

        param.position         = 0;

        StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
    }

    if (style & wxOK)
    {
        if (style & wxCANCEL)
        {
            //TODO add Cancelbutton
            switch( result )
            {
            case 1 :
                resultbutton = wxID_OK ;
                break ;
            case 2 :
                break ;
            case 3 :
                break ;
            }
        }
        else
        {
            switch( result )
            {
            case 1 :
                resultbutton = wxID_OK ;
                break ;
            case 2 :
                break ;
            case 3 :
                break ;
            }
        }
    }
    else if (style & wxYES_NO)
    {
        if (style & wxCANCEL)
        {
            switch( result )
            {
            case 1 :
                resultbutton = wxID_YES ;
                break ;
            case 2 :
                resultbutton = wxID_CANCEL ;
                break ;
            case 3 :
                resultbutton = wxID_NO ;
                break ;
            }
        }
        else
        {
            switch( result )
            {
            case 1 :
                resultbutton = wxID_YES ;
                break ;
            case 2 :
                break ;
            case 3 :
                resultbutton = wxID_NO ;
                break ;
            }
        }
    }

    return resultbutton ;
}
Ejemplo n.º 12
0
static pascal void
NavEventProc(
    NavEventCallbackMessage        inSelector,
    NavCBRecPtr                    ioParams,
    NavCallBackUserData    ioUserData    )
{
    OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ;
    if (inSelector == kNavCBEvent) {
#if TARGET_CARBON
#else
        wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event);
#endif
    }
    else if ( inSelector == kNavCBStart )
    {
#if TARGET_CARBON
        if (data && !(data->defaultLocation).IsEmpty())
        {
            // Set default location for the modern Navigation APIs
            // Apple Technical Q&A 1151
            FSSpec theFSSpec;
            wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec);
            AEDesc theLocation = {typeNull, NULL};
            if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
                ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
        }
#else
        if ( data->menuitems )
            NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &(*data->menuitems)[data->currentfilter]);
#endif
    }
    else if ( inSelector == kNavCBPopupMenuSelect )
    {
        NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ;
#if TARGET_CARBON
#else
        if ( menu->menuCreator == 'WXNG' )
#endif
        {
            data->currentfilter = menu->menuType ;
            if ( data->saveMode )
            {
                int i = menu->menuType ;
                wxString extension =  data->extensions[i].AfterLast('.') ;
                extension.MakeLower() ;
                wxString sfilename ;

#if TARGET_CARBON
                wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false  );
                sfilename = cfString.AsString() ;
#else
                Str255 filename ;
                // get the current filename
                NavCustomControl(ioParams->context, kNavCtlGetEditFileName, &filename);
                sfilename = wxMacMakeStringFromPascal( filename ) ;
#endif

                int pos = sfilename.Find('.', true) ;
                if ( pos != wxNOT_FOUND )
                {
                    sfilename = sfilename.Left(pos+1)+extension ;
#if TARGET_CARBON
                    cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ;
                    NavDialogSetSaveFileName( ioParams->context , cfString ) ;
#else
                    wxMacStringToPascal( sfilename , filename ) ;
                    NavCustomControl(ioParams->context, kNavCtlSetEditFileName, &filename);
#endif
                }
            }
        }
    }
}
Ejemplo n.º 13
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
}
Ejemplo n.º 14
0
bool wxIcon::LoadFile(
    const wxString& filename, wxBitmapType type,
    int desiredWidth, int desiredHeight )
{
    UnRef();

    if ( type == wxBITMAP_TYPE_ICON_RESOURCE )
    {
        OSType theId = 0 ;

        if ( filename == wxT("wxICON_INFORMATION") )
        {
            theId = kAlertNoteIcon ;
        }
        else if ( filename == wxT("wxICON_QUESTION") )
        {
            theId = kAlertCautionIcon ;
        }
        else if ( filename == wxT("wxICON_WARNING") )
        {
            theId = kAlertCautionIcon ;
        }
        else if ( filename == wxT("wxICON_ERROR") )
        {
            theId = kAlertStopIcon ;
        }
        else
        {
#if 0
            Str255 theName ;
            OSType theType ;
            wxMacStringToPascal( name , theName ) ;

            Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
            if ( resHandle != 0L )
            {
                GetResInfo( resHandle , &theId , &theType , theName ) ;
                ReleaseResource( resHandle ) ;
            }
#endif
        }

        if ( theId != 0 )
        {
            IconRef iconRef = NULL ;
            verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ;
            if ( iconRef )
            {
                m_refData = new wxIconRefData( (WXHICON) iconRef ) ;

                return true ;
            }
        }

        return false ;
    }
    else
    {
        wxBitmapHandler *handler = wxBitmap::FindHandler( type );

        if ( handler )
        {
            wxBitmap bmp ;
            if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight ))
            {
                CopyFromBitmap( bmp ) ;

                return true ;
            }

            return false ;
        }
        else
        {
#if wxUSE_IMAGE
            wxImage loadimage( filename, type );
            if (loadimage.Ok())
            {
                if ( desiredWidth == -1 )
                    desiredWidth = loadimage.GetWidth() ;
                if ( desiredHeight == -1 )
                    desiredHeight = loadimage.GetHeight() ;
                if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
                    loadimage.Rescale( desiredWidth , desiredHeight ) ;

                wxBitmap bmp( loadimage );
                CopyFromBitmap( bmp ) ;

                return true;
            }
#endif
        }
    }
    return true ;
}