}
}
+wxBitmap::wxBitmap(const char* const* bits)
+{
+ wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
+
+ GdkBitmap* mask = NULL;
+ SetPixmap(gdk_pixmap_create_from_xpm_d(wxGetRootWindow()->window, &mask, NULL, wx_const_cast(char**, bits)));
+
+ if (M_BMPDATA->m_pixmap != NULL && mask != NULL)
+ {
+ M_BMPDATA->m_mask = new wxMask;
+ M_BMPDATA->m_mask->m_bitmap = mask;
+ }
+}
+
wxBitmap::~wxBitmap()
{
}
return Ok();
}
-bool wxBitmap::CreateFromXpm(const char* const* bits)
-{
- UnRef();
-
- wxCHECK_MSG( bits != NULL, false, wxT("invalid bitmap data") );
-
- GdkBitmap *mask = (GdkBitmap*) NULL;
- SetPixmap(gdk_pixmap_create_from_xpm_d(wxGetRootWindow()->window, &mask, NULL, wx_const_cast(char**, bits)));
-
- wxCHECK_MSG( M_BMPDATA->m_pixmap, false, wxT("couldn't create pixmap") );
-
- if (mask)
- {
- M_BMPDATA->m_mask = new wxMask;
- M_BMPDATA->m_mask->m_bitmap = mask;
- }
-
- return true;
-}
-
wxBitmap wxBitmap::Rescale(int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy) const
{
wxBitmap bmp;
return image;
}
-bool wxBitmap::operator == ( const wxBitmap& bmp ) const
-{
- return m_refData == bmp.m_refData;
-}
-
-bool wxBitmap::Ok() const
+bool wxBitmap::IsOk() const
{
return (m_refData != NULL) &&
(
{
wxCHECK_RET( Ok(), wxT("invalid bitmap") );
+ AllocExclusive();
delete M_BMPDATA->m_mask;
M_BMPDATA->m_mask = mask;
}
void wxBitmap::SetHeight( int height )
{
- if (!m_refData)
- m_refData = new wxBitmapRefData;
-
+ AllocExclusive();
M_BMPDATA->m_height = height;
}
void wxBitmap::SetWidth( int width )
{
- if (!m_refData)
- m_refData = new wxBitmapRefData;
-
+ AllocExclusive();
M_BMPDATA->m_width = width;
}
void wxBitmap::SetDepth( int depth )
{
- if (!m_refData)
- m_refData = new wxBitmapRefData;
-
+ AllocExclusive();
M_BMPDATA->m_bpp = depth;
}
if (!m_refData)
m_refData = new wxBitmapRefData;
+ // AllocExclusive should not be needed for this internal function
+ wxASSERT(m_refData->GetRefCount() == 1);
wxASSERT(M_BMPDATA->m_pixmap == NULL);
M_BMPDATA->m_pixmap = pixmap;
gdk_drawable_get_size(pixmap, &M_BMPDATA->m_width, &M_BMPDATA->m_height);
if (!m_refData)
m_refData = new wxBitmapRefData;
+ // AllocExclusive should not be needed for this internal function
+ wxASSERT(m_refData->GetRefCount() == 1);
wxASSERT(M_BMPDATA->m_pixbuf == NULL);
M_BMPDATA->m_pixbuf = pixbuf;
M_BMPDATA->m_width = gdk_pixbuf_get_width(pixbuf);
if (!gdk_pixbuf_get_has_alpha(pixbuf))
{
M_BMPDATA->m_pixbuf = NULL;
- SetPixbuf(gdk_pixbuf_add_alpha(pixbuf, false, 0, 0, 0));
+ AllocExclusive();
+ M_BMPDATA->m_pixbuf = gdk_pixbuf_add_alpha(pixbuf, false, 0, 0, 0);
g_object_unref(pixbuf);
}
}
-//-----------------------------------------------------------------------------
-// wxBitmapHandler
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler,wxBitmapHandlerBase)
-
-wxBitmapHandler::~wxBitmapHandler()
+wxObjectRefData* wxBitmap::CreateRefData() const
{
+ return new wxBitmapRefData;
}
-bool wxBitmapHandler::Create(wxBitmap * WXUNUSED(bitmap),
- void * WXUNUSED(data),
- long WXUNUSED(type),
- int WXUNUSED(width),
- int WXUNUSED(height),
- int WXUNUSED(depth))
-{
- wxFAIL_MSG( _T("not implemented") );
-
- return false;
-}
-
-bool wxBitmapHandler::LoadFile(wxBitmap * WXUNUSED(bitmap),
- const wxString& WXUNUSED(name),
- long WXUNUSED(flags),
- int WXUNUSED(desiredWidth),
- int WXUNUSED(desiredHeight))
+wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const
{
- wxFAIL_MSG( _T("not implemented") );
+ const wxBitmapRefData* oldRef = wx_static_cast(const wxBitmapRefData*, data);
+ wxBitmapRefData* newRef = new wxBitmapRefData;
+ newRef->m_width = oldRef->m_width;
+ newRef->m_height = oldRef->m_height;
+ newRef->m_bpp = oldRef->m_bpp;
+ if (oldRef->m_pixmap != NULL)
+ {
+ newRef->m_pixmap = gdk_pixmap_new(
+ oldRef->m_pixmap, oldRef->m_width, oldRef->m_height,
+ // use pixmap depth, m_bpp may not match
+ gdk_drawable_get_depth(oldRef->m_pixmap));
+ GdkGC* gc = gdk_gc_new(newRef->m_pixmap);
+ gdk_draw_drawable(
+ newRef->m_pixmap, gc, oldRef->m_pixmap, 0, 0, 0, 0, -1, -1);
+ g_object_unref(gc);
+ }
+ if (oldRef->m_pixbuf != NULL)
+ {
+ newRef->m_pixbuf = gdk_pixbuf_copy(oldRef->m_pixbuf);
+ }
+ if (oldRef->m_mask != NULL)
+ {
+ newRef->m_mask = new wxMask;
+ newRef->m_mask->m_bitmap = gdk_pixmap_new(
+ oldRef->m_mask->m_bitmap, oldRef->m_width, oldRef->m_height, 1);
+ GdkGC* gc = gdk_gc_new(newRef->m_mask->m_bitmap);
+ gdk_draw_drawable(newRef->m_mask->m_bitmap,
+ gc, oldRef->m_mask->m_bitmap, 0, 0, 0, 0, -1, -1);
+ g_object_unref(gc);
+ }
+#if wxUSE_PALETTE
+ // implement this if SetPalette is ever implemented
+ wxASSERT(oldRef->m_palette == NULL);
+#endif
- return false;
+ return newRef;
}
-bool wxBitmapHandler::SaveFile(const wxBitmap * WXUNUSED(bitmap),
- const wxString& WXUNUSED(name),
- int WXUNUSED(type),
- const wxPalette * WXUNUSED(palette))
-{
- wxFAIL_MSG( _T("not implemented") );
+//-----------------------------------------------------------------------------
+// wxBitmapHandler
+//-----------------------------------------------------------------------------
- return false;
-}
+IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxBitmapHandlerBase)
/* static */ void wxBitmap::InitStandardHandlers()
{