X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03ab016d6692ccceafb0f324a063bbf8f334f020..2e1a688e3e9c6c265620e4f05d579077367e9fdb:/src/msw/bitmap.cpp?ds=sidebyside diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index ff62b50293..9498c65e43 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -9,42 +9,60 @@ // 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 -#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 + + #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; @@ -57,35 +75,56 @@ wxBitmapRefData::wxBitmapRefData(void) 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); @@ -96,12 +135,9 @@ bool wxBitmap::FreeResource(bool WXUNUSED(force)) 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); @@ -208,7 +244,7 @@ bool wxBitmap::LoadFile(const wxString& filename, long type) 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; } @@ -225,7 +261,7 @@ bool wxBitmap::Create(void *data, long type, int width, int height, int depth) 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; } @@ -238,7 +274,7 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal 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; } @@ -305,9 +341,10 @@ void wxBitmap::SetMask(wxMask *mask) 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) @@ -435,7 +472,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const * wxMask */ -wxMask::wxMask(void) +wxMask::wxMask() { m_maskBitmap = 0; } @@ -463,7 +500,7 @@ wxMask::wxMask(const wxBitmap& bitmap) Create(bitmap); } -wxMask::~wxMask(void) +wxMask::~wxMask() { if ( m_maskBitmap ) ::DeleteObject((HBITMAP) m_maskBitmap); @@ -601,7 +638,7 @@ class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler) public: - inline wxBMPResourceHandler(void) + inline wxBMPResourceHandler() { m_name = "Windows bitmap resource"; m_extension = ""; @@ -620,17 +657,22 @@ bool wxBMPResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long M_BITMAPHANDLERDATA->m_hBitmap = (WXHBITMAP) ::LoadBitmap(wxGetInstance(), name); if (M_BITMAPHANDLERDATA->m_hBitmap) { - M_BITMAPHANDLERDATA->m_ok = TRUE; - BITMAP bm; - GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(BITMAP), (LPSTR) &bm); - M_BITMAPHANDLERDATA->m_width = bm.bmWidth; - M_BITMAPHANDLERDATA->m_height = bm.bmHeight; - M_BITMAPHANDLERDATA->m_depth = bm.bmBitsPixel; - return TRUE; + M_BITMAPHANDLERDATA->m_ok = TRUE; + BITMAP bm; + GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(BITMAP), (LPSTR) &bm); + M_BITMAPHANDLERDATA->m_width = bm.bmWidth; + M_BITMAPHANDLERDATA->m_height = bm.bmHeight; + M_BITMAPHANDLERDATA->m_depth = bm.bmBitsPixel; + + if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) + { + } + + return TRUE; } // 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; } @@ -639,7 +681,7 @@ class WXDLLEXPORT wxBMPFileHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxBMPFileHandler) public: - inline wxBMPFileHandler(void) + inline wxBMPFileHandler() { m_name = "Windows bitmap file"; m_extension = "bmp"; @@ -670,7 +712,10 @@ bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long WXU palette = NULL; } if (palette) - M_BITMAPHANDLERDATA->m_bitmapPalette = *palette; + { + M_BITMAPHANDLERDATA->m_bitmapPalette = *palette; + delete palette; + } return success; #else return FALSE; @@ -689,7 +734,7 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int WXUN #endif } -void wxBitmap::CleanUpHandlers(void) +void wxBitmap::CleanUpHandlers() { wxNode *node = sm_handlers.First(); while ( node ) @@ -702,7 +747,7 @@ void wxBitmap::CleanUpHandlers(void) } } -void wxBitmap::InitStandardHandlers(void) +void wxBitmap::InitStandardHandlers() { AddHandler(new wxBMPResourceHandler); AddHandler(new wxBMPFileHandler);