No real changes, just rearrange wxCursor::InitFromImage() in wxGTK.
Make it more clear that the function deals with two cases by using if/else instead of if+return. Also use smart wxGtkObject pointer instead of calling g_object_unref() manually. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "wx/gtk/private/object.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxCursorRefData
|
||||
@@ -231,30 +232,33 @@ void wxCursor::InitFromImage( const wxImage & image )
|
||||
bitmap.GetPixbuf(),
|
||||
hotSpotX, hotSpotY
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
else // no colour cursor support
|
||||
{
|
||||
unsigned long keyMaskColor = 0;
|
||||
GdkPixmap* mask;
|
||||
GdkPixmap *maskRaw;
|
||||
if (bHasMask)
|
||||
{
|
||||
keyMaskColor = wxImageHistogram::MakeKey(
|
||||
image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
|
||||
// get mask before image is modified
|
||||
wxBitmap bitmap(image, 1);
|
||||
mask = bitmap.GetMask()->GetBitmap();
|
||||
g_object_ref(mask);
|
||||
maskRaw = bitmap.GetMask()->GetBitmap();
|
||||
g_object_ref(maskRaw);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int size = ((w + 7) / 8) * h;
|
||||
char* bits = new char[size];
|
||||
memset(bits, 0xff, size);
|
||||
mask = gdk_bitmap_create_from_data(
|
||||
maskRaw = gdk_bitmap_create_from_data(
|
||||
wxGetRootWindow()->window, bits, w, h);
|
||||
delete[] bits;
|
||||
}
|
||||
|
||||
// assign the raw pointer to wxGtkObject to ensure it is unref'd later
|
||||
wxGtkObject<GdkPixmap> mask(maskRaw);
|
||||
|
||||
// modify image so wxBitmap can be used to convert to pixmap
|
||||
image_copy.SetMask(false);
|
||||
wxByte* data = image_copy.GetData();
|
||||
@@ -329,8 +333,7 @@ void wxCursor::InitFromImage( const wxImage & image )
|
||||
fg.GetColor(), bg.GetColor(),
|
||||
hotSpotX, hotSpotY
|
||||
);
|
||||
|
||||
g_object_unref (mask);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
Reference in New Issue
Block a user