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
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include "wx/gtk/private/object.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxCursorRefData
|
// wxCursorRefData
|
||||||
@@ -231,30 +232,33 @@ void wxCursor::InitFromImage( const wxImage & image )
|
|||||||
bitmap.GetPixbuf(),
|
bitmap.GetPixbuf(),
|
||||||
hotSpotX, hotSpotY
|
hotSpotX, hotSpotY
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else // no colour cursor support
|
||||||
|
{
|
||||||
unsigned long keyMaskColor = 0;
|
unsigned long keyMaskColor = 0;
|
||||||
GdkPixmap* mask;
|
GdkPixmap *maskRaw;
|
||||||
if (bHasMask)
|
if (bHasMask)
|
||||||
{
|
{
|
||||||
keyMaskColor = wxImageHistogram::MakeKey(
|
keyMaskColor = wxImageHistogram::MakeKey(
|
||||||
image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
|
image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
|
||||||
// get mask before image is modified
|
// get mask before image is modified
|
||||||
wxBitmap bitmap(image, 1);
|
wxBitmap bitmap(image, 1);
|
||||||
mask = bitmap.GetMask()->GetBitmap();
|
maskRaw = bitmap.GetMask()->GetBitmap();
|
||||||
g_object_ref(mask);
|
g_object_ref(maskRaw);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int size = ((w + 7) / 8) * h;
|
const int size = ((w + 7) / 8) * h;
|
||||||
char* bits = new char[size];
|
char* bits = new char[size];
|
||||||
memset(bits, 0xff, size);
|
memset(bits, 0xff, size);
|
||||||
mask = gdk_bitmap_create_from_data(
|
maskRaw = gdk_bitmap_create_from_data(
|
||||||
wxGetRootWindow()->window, bits, w, h);
|
wxGetRootWindow()->window, bits, w, h);
|
||||||
delete[] bits;
|
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
|
// modify image so wxBitmap can be used to convert to pixmap
|
||||||
image_copy.SetMask(false);
|
image_copy.SetMask(false);
|
||||||
wxByte* data = image_copy.GetData();
|
wxByte* data = image_copy.GetData();
|
||||||
@@ -329,8 +333,7 @@ void wxCursor::InitFromImage( const wxImage & image )
|
|||||||
fg.GetColor(), bg.GetColor(),
|
fg.GetColor(), bg.GetColor(),
|
||||||
hotSpotX, hotSpotY
|
hotSpotX, hotSpotY
|
||||||
);
|
);
|
||||||
|
}
|
||||||
g_object_unref (mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_IMAGE
|
#endif // wxUSE_IMAGE
|
||||||
|
Reference in New Issue
Block a user