コード例 #1
0
bool wxDynamicLibrary::Load(const wxString& libnameOrig, int flags)
{
    wxASSERT_MSG(m_handle == 0, _T("Library already loaded."));

    // add the proper extension for the DLL ourselves unless told not to
    wxString libname = libnameOrig;
    if ( !(flags & wxDL_VERBATIM) )
    {
        // and also check that the libname doesn't already have it
        wxString ext;
        wxFileName::SplitPath(libname, NULL, NULL, &ext);
        if ( ext.empty() )
        {
            libname += GetDllExt();
        }
    }

    // different ways to load a shared library
    //
    // FIXME: should go to the platform-specific files!
#if defined(__WXMAC__) && !defined(__DARWIN__)
    FSSpec      myFSSpec;
    Ptr         myMainAddr;
    Str255      myErrName;

    wxMacFilename2FSSpec( libname , &myFSSpec );

    if( GetDiskFragment( &myFSSpec,
                         0,
                         kCFragGoesToEOF,
                         "\p",
                         kPrivateCFragCopy,
                         &m_handle,
                         &myMainAddr,
                         myErrName ) != noErr )
    {
        wxLogSysError( _("Failed to load shared library '%s' Error '%s'"),
                       libname.c_str(),
                       wxMacMakeStringFromPascal( myErrName ).c_str() );
        m_handle = 0;
    }

#elif defined(__WXPM__) || defined(__EMX__)
    char    err[256] = "";
    DosLoadModule(err, sizeof(err), (PSZ)libname.c_str(), &m_handle);
#else
    m_handle = RawLoad(libname, flags);
#endif

    if ( m_handle == 0 )
    {
#ifdef wxHAVE_DYNLIB_ERROR
        Error();
#else
        wxLogSysError(_("Failed to load shared library '%s'"), libname.c_str());
#endif
    }

    return IsLoaded();
}
コード例 #2
0
static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr)
{
    OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ;
    // return true if this item is invisible or a file

    Boolean visibleFlag;
    Boolean folderFlag;

    visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible);
    folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10);

    // because the semantics of the filter proc are "true means don't show
    // it" we need to invert the result that we return

    if ( !visibleFlag )
        return true ;

    if ( !folderFlag )
    {
        wxString file = wxMacMakeStringFromPascal( myCInfoPBPtr->hFileInfo.ioNamePtr ) ;
        return !CheckFile( file , myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdType , data ) ;
    }

    return false ;
}
コード例 #3
0
ファイル: filedlg.cpp プロジェクト: Duion/Torsion
pascal Boolean CrossPlatformFilterCallback (
    AEDesc *theItem,
    void *info,
    void *callBackUD,
    NavFilterModes filterMode
)
{
    bool display = true;
    OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ;

    if (filterMode == kNavFilteringBrowserList)
    {
        NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ;
        if ( !theInfo->isFolder )
        {
            if (theItem->descriptorType == typeFSS )
            {
                FSSpec    spec;
                memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ;
                wxString file = wxMacMakeStringFromPascal( spec.name ) ;
                display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
            }
            else if ( theItem->descriptorType == typeFSRef )
            {
                FSRef fsref ;
                memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;
                wxString file = wxMacFSRefToPath( &fsref ) ;
                display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
            }
        }
    }

    return display;
}
コード例 #4
0
ファイル: fontenum.cpp プロジェクト: Duion/Torsion
void wxFontEnumeratorHelper::DoEnumerate()
{
    MenuHandle    menu ;

    short         lines ;
    
    menu = NewMenu( 32000 , "\pFont" )  ;
    AppendResMenu( menu , 'FONT' ) ;
    lines = CountMenuItems( menu ) ;

    for ( int i = 1 ; i < lines+1  ; i ++ )
    {
        wxString c_name ;
#if TARGET_API_MAC_CARBON
        CFStringRef menutext ;
        c_name = wxEmptyString ;
        if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr )
        {
            c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding());
        }
#else
        Str255        p_name;
        GetMenuItemText( menu , i , p_name ) ;
        c_name = wxMacMakeStringFromPascal( p_name );
#endif
        /*
          
          if ( m_fixedOnly )
        {
            // check that it's a fixed pitch font (there is *no* error here, the
            // flag name is misleading!)
            if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
            {
                // not a fixed pitch font
                return TRUE;
            }
        }
    
        if ( m_charset != -1 )
        {
            // check that we have the right encoding
            if ( lf->lfCharSet != m_charset )
            {
                return TRUE;
            }
        }
    
        */
        m_fontEnum->OnFacename( c_name ) ;
    }
    DisposeMenu( menu ) ;
}
コード例 #5
0
pascal Boolean CrossPlatformFilterCallback (
    AEDesc *theItem,
    void *info,
    void *callBackUD,
    NavFilterModes filterMode
)
{
    bool display = true;
    OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ;

    if (filterMode == kNavFilteringBrowserList)
    {
        NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ;
        if ( !theInfo->isFolder )
        {
            if (theItem->descriptorType == typeFSS )
            {
                FSSpec    spec;
                memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ;
                wxString file = wxMacMakeStringFromPascal( spec.name ) ;
                display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
            }
#if TARGET_CARBON
            else if ( theItem->descriptorType == typeFSRef )
            {
                FSRef fsref ;
                memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;



                CFURLRef fullURLRef;
                fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref);
#ifdef __UNIX__
                CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
#else
                CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
#endif
                CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
                ::CFRelease( fullURLRef ) ;
                wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding());

                display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
            }
#endif
        }
    }

    return display;
}
コード例 #6
0
void wxFontEnumeratorHelper::DoEnumerate()
{
    MenuHandle    menu ;
    Str255        p_name ;

    short         lines ;

    menu = NewMenu( 32000 , "\pFont" )  ;
    AppendResMenu( menu , 'FONT' ) ;
    lines = CountMenuItems( menu ) ;

    for ( int i = 1 ; i < lines+1  ; i ++ )
    {
        GetMenuItemText( menu , i , p_name ) ;
        wxString c_name = wxMacMakeStringFromPascal(p_name) ;

        /*

          if ( m_fixedOnly )
        {
            // check that it's a fixed pitch font (there is *no* error here, the
            // flag name is misleading!)
            if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
            {
                // not a fixed pitch font
                return TRUE;
            }
        }

        if ( m_charset != -1 )
        {
            // check that we have the right encoding
            if ( lf->lfCharSet != m_charset )
            {
                return TRUE;
            }
        }

        */
        m_fontEnum->OnFacename( c_name ) ;
    }
    DisposeMenu( menu ) ;
}
コード例 #7
0
ファイル: dirmac.cpp プロジェクト: gitrider/wxsj2
bool wxDirData::Read(wxString *filename)
{
    if ( !m_isDir )
        return false ;

    wxString result;

    short err = noErr ;

    while ( err == noErr )
    {
        m_index++ ;
        m_CPB.dirInfo.ioFDirIndex = m_index;
        m_CPB.dirInfo.ioDrDirID = m_dirId;    /* we need to do this every time */
        err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB);
        if ( err != noErr )
            break ;

        // its hidden but we don't want it
        if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) )
            continue ;
#ifdef __DARWIN__
        // under X, names that start with '.' are hidden
        if ( ( m_name[1] == '.' ) && !(m_flags & wxDIR_HIDDEN) )
            continue;
#endif
#if TARGET_CARBON
        // under X thats the way the mounting points look like
        if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) )
            break ;
#endif
        //  we have a directory
        if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) )
            break ;

        // its a file but we don't want it
        if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) )
            continue ;

        wxString file = wxMacMakeStringFromPascal( m_name ) ;
        if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") )
        {
        }
        else if ( m_filespec.Length() > 1 && m_filespec.Left(1) == wxT("*") )
        {
            if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() )
            {
                continue ;
            }
        }
        else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == wxT("*") )
        {
            if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() )
            {
                continue ;
            }
        }
        else if ( file.Upper() != m_filespec.Upper() )
        {
            continue ;
        }

        break ;
    }
    if ( err != noErr )
    {
        return false ;
    }

    *filename = wxMacMakeStringFromPascal( m_name )  ;

    return true;
}
コード例 #8
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
                }
            }
        }
    }
}
コード例 #9
0
ファイル: listbox.cpp プロジェクト: Bluehorn/wxPython
bool wxListBox::Create(wxWindow *parent, wxWindowID id,
                       const wxPoint& pos,
                       const wxSize& size,
                       int n, const wxString choices[],
                       long style,
                       const wxValidator& validator,
                       const wxString& name)
{
    if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) )
        return false;

    m_noItems = 0 ; // this will be increased by our append command
    m_selected = 0;

    Rect bounds ;
    Str255 title ;

    MacPreControlCreate( parent , id ,  wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;

    ListDefSpec listDef;
    listDef.defType = kListDefUserProcType;
    if ( macListDefUPP == NULL )
    {
        macListDefUPP = NewListDefUPP( wxMacListDefinition );
    }
    listDef.u.userProc = macListDefUPP ;

    Str255 fontName ;
    SInt16 fontSize ;
    Style fontStyle ;
#if TARGET_CARBON
    GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
#else
    GetFontName( kFontIDMonaco , fontName ) ;
    fontSize = 9 ;
    fontStyle = normal ;
#endif
    SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) ) ) ;
#if TARGET_CARBON
    Size asize;


    CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, (style & wxLB_HSCROLL), true,
                          kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, (ControlRef *)&m_macControl );

    GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag,
                   sizeof(ListHandle), (Ptr) &m_macList, &asize);

    SetControlReference( (ControlHandle) m_macControl, (long) this);
    SetControlVisibility( (ControlHandle) m_macControl, false, false);

#else

    long    result ;
    wxStAppResource resload ;
    m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
                  (style & wxLB_HSCROLL) ? kwxMacListWithVerticalAndHorizontalScrollbar : kwxMacListWithVerticalScrollbar ,
                  0 , 0, kControlListBoxProc , (long) this ) ;
    ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
               sizeof( ListHandle ) , (char*) &m_macList  , &result ) ;

    HLock( (Handle) m_macList ) ;
    ldefHandle ldef ;
    ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ;
    if (  (**(ListHandle)m_macList).listDefProc != NULL )
    {
      (**ldef).instruction = 0x4EF9;  /* JMP instruction */
      (**ldef).function = (void(*)()) listDef.u.userProc;
      (**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
    }

    Point pt = (**(ListHandle)m_macList).cellSize ;
    pt.v = kwxMacListItemHeight ;
    LCellSize( pt , (ListHandle)m_macList ) ;
    LAddColumn( 1 , 0 , (ListHandle)m_macList ) ;
#endif
    OptionBits  options = 0;
    if ( style & wxLB_MULTIPLE )
    {
        options += lExtendDrag + lUseSense  ;
    }
    else if ( style & wxLB_EXTENDED )
    {
        // default behaviour
    }
    else
    {
        options = (OptionBits) lOnlyOne ;
    }
    SetListSelectionFlags((ListHandle)m_macList, options);

    for ( int i = 0 ; i < n ; i++ )
    {
        Append( choices[i] ) ;
    }

    MacPostControlCreate() ;

    LSetDrawingMode( true , (ListHandle)m_macList ) ;

    return true;
}