// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
#ifdef __GNUG__
-#pragma implementation "bitmap.h"
+ #pragma implementation "bitmap.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
#ifndef WX_PRECOMP
-#include <stdio.h>
-#include "wx/setup.h"
-#include "wx/list.h"
-#include "wx/utils.h"
-#include "wx/app.h"
-#include "wx/palette.h"
-#include "wx/dcmemory.h"
-#include "wx/bitmap.h"
-#include "wx/icon.h"
+ #include <stdio.h>
+
+ #include "wx/list.h"
+ #include "wx/utils.h"
+ #include "wx/app.h"
+ #include "wx/palette.h"
+ #include "wx/dcmemory.h"
+ #include "wx/bitmap.h"
+ #include "wx/icon.h"
#endif
#include "wx/msw/private.h"
#include "wx/log.h"
-#include "assert.h"
-
#include "wx/msw/dib.h"
+// ----------------------------------------------------------------------------
+// macros
+// ----------------------------------------------------------------------------
+
#if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
-IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
+ IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
+ IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
#endif
-wxBitmapRefData::wxBitmapRefData(void)
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxBitmapRefData
+// ----------------------------------------------------------------------------
+
+wxBitmapRefData::wxBitmapRefData()
{
m_ok = FALSE;
m_width = 0;
m_bitmapMask = NULL;
}
-wxBitmapRefData::~wxBitmapRefData(void)
+wxBitmapRefData::~wxBitmapRefData()
{
- if (m_selectedInto)
- {
- char buf[200];
- sprintf(buf, "Bitmap was deleted without selecting out of wxMemoryDC %X.", (unsigned int) m_selectedInto);
- wxFatalError(buf);
- }
- if (m_hBitmap)
- {
- DeleteObject((HBITMAP) m_hBitmap);
- }
- m_hBitmap = 0 ;
+ wxASSERT_MSG( !m_selectedInto,
+ wxT("deleting bitmap still selected into wxMemoryDC") );
- if (m_bitmapMask)
- delete m_bitmapMask;
- m_bitmapMask = NULL;
+ if ( m_hBitmap)
+ DeleteObject((HBITMAP) m_hBitmap);
+ if ( m_bitmapMask )
+ delete m_bitmapMask;
}
+// ----------------------------------------------------------------------------
+// wxBitmap
+// ----------------------------------------------------------------------------
+
wxList wxBitmap::sm_handlers;
-wxBitmap::wxBitmap(void)
+wxBitmap::wxBitmap()
{
if ( wxTheBitmapList )
wxTheBitmapList->AddBitmap(this);
}
-wxBitmap::~wxBitmap(void)
+wxBitmap::wxBitmap(const wxBitmap& bitmap)
+{
+ wxIcon *icon = wxDynamicCast(&bitmap, wxIcon);
+ if ( icon )
+ {
+ HDC hdc = ::CreateCompatibleDC(NULL); // screen DC
+ HBITMAP hbitmap = ::CreateCompatibleBitmap(hdc,
+ icon->GetWidth(),
+ icon->GetHeight());
+ ::SelectObject(hdc, hbitmap);
+ ::DrawIcon(hdc, 0, 0, (HICON)icon->GetHICON());
+
+ ::DeleteDC(hdc);
+
+ SetHBITMAP((WXHBITMAP)hbitmap);
+ }
+ else
+ {
+ Ref(bitmap);
+ }
+
+ if ( wxTheBitmapList )
+ wxTheBitmapList->AddBitmap(this);
+}
+
+wxBitmap::~wxBitmap()
{
if (wxTheBitmapList)
wxTheBitmapList->DeleteObject(this);
if ( !M_BITMAPDATA )
return FALSE;
- if (M_BITMAPDATA->m_selectedInto)
- {
- char buf[200];
- sprintf(buf, "Bitmap %X was deleted without selecting out of wxMemoryDC %X.", (unsigned int) this, (unsigned int) M_BITMAPDATA->m_selectedInto);
- wxFatalError(buf);
- }
+ wxASSERT_MSG( !M_BITMAPDATA->m_selectedInto,
+ wxT("freeing bitmap still selected into wxMemoryDC") );
+
if (M_BITMAPDATA->m_hBitmap)
{
DeleteObject((HBITMAP) M_BITMAPDATA->m_hBitmap);
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL ) {
- wxLogWarning("no bitmap handler for type %d defined.", type);
+ wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
return FALSE;
}
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL ) {
- wxLogWarning("no bitmap handler for type %d defined.", type);
+ wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
return FALSE;
}
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL ) {
- wxLogWarning("no bitmap handler for type %d defined.", type);
+ wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
return FALSE;
}
void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
{
if (!M_BITMAPDATA)
- m_refData = new wxBitmapRefData;
+ m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_hBitmap = bmp;
+ M_BITMAPDATA->m_ok = bmp != 0;
}
void wxBitmap::AddHandler(wxBitmapHandler *handler)
* wxMask
*/
-wxMask::wxMask(void)
+wxMask::wxMask()
{
m_maskBitmap = 0;
}
Create(bitmap);
}
-wxMask::~wxMask(void)
+wxMask::~wxMask()
{
if ( m_maskBitmap )
::DeleteObject((HBITMAP) m_maskBitmap);
{
DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
public:
- inline wxBMPResourceHandler(void)
+ inline wxBMPResourceHandler()
{
m_name = "Windows bitmap resource";
m_extension = "";
}
// it's probably not found
- wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name.c_str());
+ wxLogError(wxT("Can't load bitmap '%s' from resources! Check .rc file."), name.c_str());
return FALSE;
}
{
DECLARE_DYNAMIC_CLASS(wxBMPFileHandler)
public:
- inline wxBMPFileHandler(void)
+ inline wxBMPFileHandler()
{
m_name = "Windows bitmap file";
m_extension = "bmp";
#endif
}
-void wxBitmap::CleanUpHandlers(void)
+void wxBitmap::CleanUpHandlers()
{
wxNode *node = sm_handlers.First();
while ( node )
}
}
-void wxBitmap::InitStandardHandlers(void)
+void wxBitmap::InitStandardHandlers()
{
AddHandler(new wxBMPResourceHandler);
AddHandler(new wxBMPFileHandler);