X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dabeb02181178d15b6914992a34eb223a98aaa0a..90f9b8ef0c83c09f80c2f60ad65407ba16f11a3c:/src/msw/icon.cpp diff --git a/src/msw/icon.cpp b/src/msw/icon.cpp index 93293f2814..ebf8f49d98 100644 --- a/src/msw/icon.cpp +++ b/src/msw/icon.cpp @@ -1,187 +1,158 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: icon.cpp +// Name: src/msw/icon.cpp // Purpose: wxIcon class // Author: Julian Smart -// Modified by: +// Modified by: 20.11.99 (VZ): don't derive from wxBitmap any more // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "icon.h" -#endif +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- // 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/icon.h" + #include "wx/list.h" + #include "wx/utils.h" + #include "wx/app.h" + #include "wx/icon.h" + #include "wx/bitmap.h" + #include "wx/log.h" #endif #include "wx/msw/private.h" -#include "assert.h" -#if USE_XPM_IN_MSW -#define FOR_MSW 1 -#include "..\..\contrib\wxxpm\libxpm.34b\lib\xpm34.h" -#endif +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- -#if USE_RESOURCE_LOADING_IN_MSW -#include "wx/msw/curico.h" -#include "wx/msw/curicop.h" -#endif +IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) -IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler) -IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler) -#endif +// ============================================================================ +// implementation +// ============================================================================ -/* - * Icons - */ +// ---------------------------------------------------------------------------- +// wxIconRefData +// ---------------------------------------------------------------------------- - -wxIconRefData::wxIconRefData(void) +void wxIconRefData::Free() { - m_hIcon = (WXHICON) NULL ; -} + if ( m_hIcon ) + { +#ifndef __WXMICROWIN__ + ::DestroyIcon((HICON) m_hIcon); +#endif -wxIconRefData::~wxIconRefData(void) -{ - if ( m_hIcon ) - ::DestroyIcon((HICON) m_hIcon); + m_hIcon = 0; + } } -wxIcon::wxIcon(void) -{ -} +// ---------------------------------------------------------------------------- +// wxIcon +// ---------------------------------------------------------------------------- -wxIcon::wxIcon(const char WXUNUSED(bits)[], const int WXUNUSED(width), const int WXUNUSED(height)) +wxIcon::wxIcon(const char bits[], int width, int height) { + wxBitmap bmp(bits, width, height); + CopyFromBitmap(bmp); } -wxIcon::wxIcon(const wxString& icon_file, const long flags, - int desiredWidth, int desiredHeight) +wxIcon::wxIcon(const wxString& iconfile, + long flags, + int desiredWidth, + int desiredHeight) { - LoadFile(icon_file, flags, desiredWidth, desiredHeight); + LoadFile(iconfile, flags, desiredWidth, desiredHeight); } -wxIcon::~wxIcon(void) +wxIcon::wxIcon(const wxIconLocation& loc) { + // wxICOFileHandler accepts names in the format "filename;index" + wxString fullname = loc.GetFileName(); + if ( loc.GetIndex() ) + { + fullname << _T(';') << loc.GetIndex(); + } + //else: 0 is default + + LoadFile(fullname, wxBITMAP_TYPE_ICO); } -bool wxIcon::FreeResource(bool force) +wxIcon::~wxIcon() { - if (M_ICONDATA && M_ICONDATA->m_hIcon) - { - DestroyIcon((HICON) M_ICONDATA->m_hIcon); - M_ICONDATA->m_hIcon = (WXHICON) NULL; - } - return TRUE; } -bool wxIcon::LoadFile(const wxString& filename, const long type, - int desiredWidth, int desiredHeight) +wxObjectRefData *wxIcon::CloneRefData(const wxObjectRefData *dataOrig) const { - UnRef(); - - m_refData = new wxIconRefData; - - wxBitmapHandler *handler = FindHandler(type); - - if ( handler ) - return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); - else - return FALSE; + const wxIconRefData * + data = wx_static_cast(const wxIconRefData *, dataOrig); + if ( !data ) + return NULL; + + // we don't have to copy m_hIcon because we're only called from SetHICON() + // which overwrites m_hIcon anyhow currently + // + // and if we're called from SetWidth/Height/Depth(), it doesn't make sense + // to copy it neither as the handle would be inconsistent with the new size + return new wxIconRefData(*data); } -void wxIcon::SetHICON(WXHICON ico) +void wxIcon::CopyFromBitmap(const wxBitmap& bmp) { - if ( !M_ICONDATA ) - m_refData = new wxIconRefData; - - M_ICONDATA->m_hIcon = ico; +#ifndef __WXMICROWIN__ + HICON hicon = wxBitmapToHICON(bmp); + if ( !hicon ) + { + wxLogLastError(wxT("CreateIconIndirect")); + } + else + { + SetHICON((WXHICON)hicon); + SetSize(bmp.GetWidth(), bmp.GetHeight()); + } +#endif // __WXMICROWIN__ } -bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, const long flags, - int desiredWidth, int desiredHeight) +void wxIcon::CreateIconFromXpm(const char **data) { -#if USE_RESOURCE_LOADING_IN_MSW - if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) - { - wxIcon *icon = (wxIcon *)bitmap; - int width, height; - WXHICON hIcon = (WXHICON) ReadIconFile((char *)(const char *)name, wxGetInstance(), &width, &height); - - ((wxIconRefData *)icon->GetRefData())->m_hIcon = hIcon; - ((wxIconRefData *)icon->GetRefData())->m_ok = (((wxIconRefData *)icon->GetRefData())->m_hIcon != 0); - return ((wxIconRefData *)icon->GetRefData())->m_ok; - } - else - return FALSE; -#else - return FALSE; -#endif + wxBitmap bmp(data); + CopyFromBitmap(bmp); } -bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, const long flags, - int desiredWidth, int desiredHeight) +bool wxIcon::LoadFile(const wxString& filename, + long type, + int desiredWidth, int desiredHeight) { - if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) - { -#if defined(__WIN32__) - if (desiredWidth > -1 && desiredHeight > -1) - { - M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR); - } - else -#endif + UnRef(); + + wxGDIImageHandler *handler = FindHandler(type); + + if ( !handler ) { - M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name); + // load via wxBitmap which, in turn, uses wxImage allowing us to + // support more formats + wxBitmap bmp; + if ( !bmp.LoadFile(filename, type) ) + return false; + + CopyFromBitmap(bmp); + return true; } -#ifdef __WIN32__ - // Win32s doesn't have GetIconInfo function... - if (M_ICONHANDLERDATA->m_hIcon && wxGetOsVersion()!=wxWIN32S) - { - ICONINFO info ; - if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info)) - { - HBITMAP ms_bitmap = info.hbmMask ; - if (ms_bitmap) - { - BITMAP bm; - ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm); - M_ICONHANDLERDATA->m_width = bm.bmWidth; - M_ICONHANDLERDATA->m_height = bm.bmHeight; - } - if (info.hbmMask) - ::DeleteObject(info.hbmMask) ; - if (info.hbmColor) - ::DeleteObject(info.hbmColor) ; - } - } -#else - M_ICONHANDLERDATA->m_width = 32; - M_ICONHANDLERDATA->m_height = 32; -#endif - M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0); - return M_ICONHANDLERDATA->m_ok; - } - else - return FALSE; + return handler->Load(this, filename, type, desiredWidth, desiredHeight); } -