Ejemplo n.º 1
0
// Replaces a bitmap, optionally passing a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
bool wxImageList::Replace(int index,
                          const wxBitmap& bitmap,
                          const wxBitmap& mask)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));

    if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
    {
        wxLogLastError(wxT("ImageList_Replace()"));
        return false;
    }

    return true;
}
Ejemplo n.º 2
0
// Adds a bitmap, using the specified colour to create the mask bitmap
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap'.
int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in overloaded Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    int index = ImageList_AddMasked(GetHImageList(),
                                    hbmp,
                                    wxColourToRGB(maskColour));
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Ejemplo n.º 3
0
// Adds a bitmap, and optionally a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
{
    HBITMAP hbmp;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // wxBitmap normally stores alpha in pre-multiplied format but
    // ImageList_Draw() does pre-multiplication internally so we need to undo
    // the pre-multiplication here. Converting back and forth like this is, of
    // course, very inefficient but it's better than wrong appearance so we do
    // this for now until a better way can be found.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        hbmp = wxDIB(bitmap.ConvertToImage(),
                     wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
        hbmp = GetHbitmapOf(bitmap);

    // Use mask only if we don't have alpha, the bitmap isn't drawn correctly
    // if we use both.
    AutoHBITMAP hbmpMask;
    if ( !bitmap.HasAlpha() )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Ejemplo n.º 4
0
// Adds a bitmap, and optionally a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
{
    HBITMAP hbmp;
    bool useMask;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // wxBitmap normally stores alpha in pre-multiplied format but
    // ImageList_Draw() does pre-multiplication internally so we need to undo
    // the pre-multiplication here. Converting back and forth like this is, of
    // course, very inefficient but it's better than wrong appearance so we do
    // this for now until a better way can be found.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        wxImage img = bitmap.ConvertToImage();

        // For comctl32.dll < 6 remove alpha channel from image
        // to prevent possible interferences with the mask.
        if ( wxApp::GetComCtl32Version() < 600 )
        {
            img.ClearAlpha();
            useMask = true;
        }
        else
        {
            useMask = false;
        }

        hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
    {
        hbmp = GetHbitmapOf(bitmap);
        useMask = true;
    }

    // Use mask only if we don't have alpha, the bitmap isn't drawn correctly
    // if we use both.
    AutoHBITMAP hbmpMask;
    if ( useMask )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
    if ( index == -1 )
    {
        wxLogError(_("Couldn't add an image to the image list."));
    }

    return index;
}
Ejemplo n.º 5
0
// Replaces a bitmap, optionally passing a mask bitmap.
// Note that wxImageList creates new bitmaps, so you may delete
// 'bitmap' and 'mask'.
bool wxImageList::Replace(int index,
                          const wxBitmap& bitmap,
                          const wxBitmap& mask)
{
    HBITMAP hbmp;
    bool useMask;

#if wxUSE_WXDIB && wxUSE_IMAGE
    // See the comment in Add() above.
    AutoHBITMAP hbmpRelease;
    if ( bitmap.HasAlpha() )
    {
        wxImage img = bitmap.ConvertToImage();

        if ( wxApp::GetComCtl32Version() < 600 )
        {
            img.ClearAlpha();
            useMask = true;
        }
        else
        {
            useMask = false;
        }

        hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
        hbmpRelease.Init(hbmp);
    }
    else
#endif // wxUSE_WXDIB && wxUSE_IMAGE
    {
        hbmp = GetHbitmapOf(bitmap);
        useMask = true;
    }

    AutoHBITMAP hbmpMask;
    if ( useMask )
        hbmpMask.Init(GetMaskForImage(bitmap, mask));

    if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
    {
        wxLogLastError(wxT("ImageList_Replace()"));
        return false;
    }

    return true;
}
Ejemplo n.º 6
0
void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
{
    Free();
    InvalidateBestSize();

    m_isIcon = image->IsKindOf( wxCLASSINFO(wxIcon) );
    // the image has already been copied
    m_image = image;

    int x, y;
    int w, h;
    GetPosition(&x, &y);
    GetSize(&w, &h);

    // Normally we just use the handle of provided image but in some cases we
    // create our own temporary bitmap, so the actual handle may end up being
    // different from the original one.
    const HANDLE handleOrig = (HANDLE)m_image->GetHandle();
    HANDLE handle = handleOrig;

#if wxUSE_WXDIB
    if ( !m_isIcon )
    {
        // wxBitmap normally stores alpha in pre-multiplied format but
        // apparently STM_SETIMAGE message handler does pre-multiplication
        // internally so we need to undo the pre-multiplication here for a
        // while (this is similar to what we do in ImageList::Add()).
        const wxBitmap& bmp = static_cast<wxBitmap&>(*image);
        if ( bmp.HasAlpha() )
        {
            // For bitmap with alpha channel create temporary DIB with
            // not-premultiplied alpha values.
            handle = wxDIB(bmp.ConvertToImage(),
                           wxDIB::PixelFormat_NotPreMultiplied).Detach();
        }
    }
#endif // wxUSE_WXDIB
    LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
    ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
                     ( m_isIcon ? SS_ICON : SS_BITMAP ) );

    MSWReplaceImageHandle((WXLPARAM)handle);

    DeleteCurrentHandleIfNeeded();

    m_currentHandle = (WXHANDLE)handle;
    m_ownsCurrentHandle = handle != handleOrig;

    if ( ImageIsOk() )
    {
        int width = image->GetWidth(),
            height = image->GetHeight();
        if ( width && height )
        {
            w = width;
            h = height;

            ::MoveWindow(GetHwnd(), x, y, width, height, FALSE);
        }
    }

    RECT rect;
    rect.left   = x;
    rect.top    = y;
    rect.right  = x + w;
    rect.bottom = y + h;
    ::InvalidateRect(GetHwndOf(GetParent()), &rect, TRUE);
}