Esempio n. 1
0
//-----------------------------------------------------------------------------
// wxDockTaskBarIcon::SetIcon
//
// Sets the icon for the dock CGImage functions and SetApplicationDockTileImage
//-----------------------------------------------------------------------------
bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& WXUNUSED(tooltip))
{
    // convert the wxIcon into a wxBitmap so we can perform some
    // wxBitmap operations with it
    wxBitmap bmp( icon );
    wxASSERT( bmp.Ok() );

    // get the CGImageRef for the wxBitmap:
    // OSX builds only, but then the dock only exists in OSX
    CGImageRef pImage = (CGImageRef) bmp.CreateCGImage();
    wxASSERT( pImage != NULL );

    // actually set the dock image
    OSStatus err = SetApplicationDockTileImage( pImage );
    verify_noerr( err );

    // free the CGImage, now that it's referenced by the dock
    if (pImage != NULL)
        CGImageRelease( pImage );

    bool success = (err == noErr);
    m_iconAdded = success;

    return success;
}
Esempio n. 2
0
// Operations:
bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
{
    wxBitmap bmp( icon ) ;
    OSStatus err = noErr ;

    CGImageRef pImage;
    
#if 0 // is always available under OSX now -- crashes on 10.2 in CFRetain() - RN
    pImage = (CGImageRef) bmp.CGImageCreate() ;
#else
    WXHBITMAP iconport ;
    WXHBITMAP maskport ;
    iconport = bmp.GetHBITMAP( &maskport ) ;

    if (!maskport)
    {
        // Make a mask with no transparent pixels
        wxBitmap   mbmp(icon.GetWidth(), icon.GetHeight());
        wxMemoryDC dc;
        dc.SelectObject(mbmp);
        dc.SetBackground(*wxBLACK_BRUSH);
        dc.Clear();
        dc.SelectObject(wxNullBitmap);
        bmp.SetMask( new wxMask(mbmp, *wxWHITE) ) ;
        iconport = bmp.GetHBITMAP( &maskport ) ;
    } 
    
    //create the icon from the bitmap and mask bitmap contained within
    err = CreateCGImageFromPixMaps(
                                            GetGWorldPixMap(MAC_WXHBITMAP(iconport)),
                                            GetGWorldPixMap(MAC_WXHBITMAP(maskport)),
                                            &pImage
                                            );    
    wxASSERT(err == 0);
#endif
    wxASSERT(pImage != NULL );
    err = SetApplicationDockTileImage(pImage);
    
    wxASSERT(err == 0);
    
    if (pImage != NULL)
        CGImageRelease(pImage);
    
    return m_iconAdded = err == noErr;
}