X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4b7f2165565bb33b149baf1272e28f9a61d579d3..cf31a1d7b60feddf23cc30259c6d909d4736ca56:/src/msw/imaglist.cpp diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index c80c8b8e7a..5140135aeb 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -35,6 +35,7 @@ #include "wx/icon.h" #include "wx/dc.h" #include "wx/string.h" + #include "wx/dcmemory.h" #include #endif @@ -45,7 +46,7 @@ #include "wx/msw/imaglist.h" #include "wx/msw/private.h" -#if !defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) +#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) #include #endif @@ -63,7 +64,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) // returns the mask if it's valid, otherwise the bitmap mask and, if it's not // valid neither, a "solid" mask (no transparent zones at all) -static wxBitmap GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask); +static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask); // ============================================================================ // implementation @@ -81,7 +82,16 @@ wxImageList::wxImageList() // Creates an image list bool wxImageList::Create(int width, int height, bool mask, int initial) { - UINT flags = 0; // TODO shouldallow to specify ILC_COLORxxx here + UINT flags = 0; + + // set appropriate color depth + int dd = wxDisplayDepth(); + if (dd <= 4) flags |= ILC_COLOR; // 16 color + else if (dd <= 8) flags |= ILC_COLOR8; // 256 color + else if (dd <= 16) flags |= ILC_COLOR16; // 64k hi-color + else if (dd <= 24) flags |= ILC_COLOR24; // 16m truecolor + else if (dd <= 32) flags |= ILC_COLOR32; // 16m truecolor + if ( mask ) flags |= ILC_MASK; @@ -90,7 +100,7 @@ bool wxImageList::Create(int width, int height, bool mask, int initial) initial, 1); if ( !m_hImageList ) { - wxLogLastError("ImageList_Create()"); + wxLogLastError(wxT("ImageList_Create()")); } return m_hImageList != 0; @@ -117,6 +127,14 @@ int wxImageList::GetImageCount() const return ImageList_GetImageCount(GetHImageList()); } +// Returns the size (same for all images) of the images in the list +bool wxImageList::GetSize(int WXUNUSED(index), int &width, int &height) const +{ + wxASSERT_MSG( m_hImageList, _T("invalid image list") ); + + return ImageList_GetIconSize(GetHImageList(), &width, &height) != 0; +} + // ---------------------------------------------------------------------------- // wxImageList operations // ---------------------------------------------------------------------------- @@ -126,8 +144,7 @@ int wxImageList::GetImageCount() const // 'bitmap' and 'mask'. int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) { - wxBitmap bmpMask = GetMaskForImage(bitmap, mask); - HBITMAP hbmpMask = wxInvertMask(GetHbitmapOf(bmpMask)); + HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); int index = ImageList_Add(GetHImageList(), GetHbitmapOf(bitmap), hbmpMask); if ( index == -1 ) @@ -183,14 +200,13 @@ bool wxImageList::Replace(int index, wxFAIL_MSG(_T("ImageList_Replace not implemented in TWIN32")); return FALSE; #else - wxBitmap bmpMask = GetMaskForImage(bitmap, mask); - HBITMAP hbmpMask = wxInvertMask(GetHbitmapOf(bmpMask)); + HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); bool ok = ImageList_Replace(GetHImageList(), index, GetHbitmapOf(bitmap), hbmpMask) != 0; if ( !ok ) { - wxLogLastError("ImageList_Add()"); + wxLogLastError(wxT("ImageList_Add()")); } ::DeleteObject(hbmpMask); @@ -205,7 +221,7 @@ bool wxImageList::Replace(int i, const wxIcon& icon) bool ok = ImageList_ReplaceIcon(GetHImageList(), i, GetHiconOf(icon)) != 0; if ( !ok ) { - wxLogLastError("ImageList_ReplaceIcon()"); + wxLogLastError(wxT("ImageList_ReplaceIcon()")); } return ok; @@ -221,7 +237,7 @@ bool wxImageList::Remove(int index) bool ok = ImageList_Remove(GetHImageList(), index) != 0; if ( !ok ) { - wxLogLastError("ImageList_Remove()"); + wxLogLastError(wxT("ImageList_Remove()")); } return ok; @@ -231,13 +247,16 @@ bool wxImageList::Remove(int index) // Remove all images bool wxImageList::RemoveAll() { - bool ok = ImageList_RemoveAll(GetHImageList()) != 0; - if ( !ok ) + // don't use ImageList_RemoveAll() because mingw32 headers don't have it + int count = ImageList_GetImageCount(GetHImageList()); + for ( int i = 0; i < count; i++ ) { - wxLogLastError("ImageList_RemoveAll()"); + // the image indexes are shifted, so we should always remove the first + // one + (void)Remove(0); } - return ok; + return TRUE; } // Draws the given image on a dc at the specified position. @@ -282,7 +301,7 @@ bool wxImageList::Draw(int index, bool ok = ImageList_Draw(GetHImageList(), index, hDC, x, y, style) != 0; if ( !ok ) { - wxLogLastError("ImageList_Draw()"); + wxLogLastError(wxT("ImageList_Draw()")); } return ok; @@ -293,36 +312,42 @@ bool wxImageList::Draw(int index, // helpers // ---------------------------------------------------------------------------- -static wxBitmap GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask) +static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask) { - wxBitmap bmpMask; + HBITMAP hbmpMask; + wxBitmap *bmpMask = NULL; if ( mask.Ok() ) { - bmpMask = mask; + hbmpMask = GetHbitmapOf(mask); } else { wxMask *pMask = bitmap.GetMask(); if ( pMask ) { - bmpMask.SetHBITMAP(pMask->GetMaskBitmap()); + hbmpMask = (HBITMAP)pMask->GetMaskBitmap(); } - } + else + { + // create a non transparent mask - apparently, this is needed under + // Win9x (it doesn't behave correctly if it's passed 0 mask) + bmpMask = new wxBitmap(bitmap.GetWidth(), bitmap.GetHeight(), 1); - if ( !bmpMask.Ok() ) - { - // create a non transparent mask - apparently, this is needed under - // Win9x (it doesn't behave correctly if it's passed 0 mask) - bmpMask.Create(bitmap.GetWidth(), bitmap.GetHeight(), 1); - - wxMemoryDC dcMem; - dcMem.SelectObject(bmpMask); - dcMem.Clear(); - dcMem.SelectObject(wxNullBitmap); + wxMemoryDC dcMem; + dcMem.SelectObject(*bmpMask); + dcMem.Clear(); + dcMem.SelectObject(wxNullBitmap); + + hbmpMask = GetHbitmapOf(*bmpMask); + } } - return bmpMask; + // windows mask convention is opposite to the wxWindows one + HBITMAP hbmpMaskInv = wxInvertMask(hbmpMask); + delete bmpMask; + + return hbmpMaskInv; } #endif // Win95