X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5a7d70fe8922a56407a5b02b95a53fb16e787f70..31c1cbc7bc2cff4db5f1bf1c7765ceb23e2b3a59:/src/mac/carbon/icon.cpp diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 3473bf72ba..3457355e0c 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -1,18 +1,22 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: icon.cpp +// Name: src/mac/carbon/icon.cpp // Purpose: wxIcon class // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" #include "wx/icon.h" -#include "wx/image.h" + +#ifndef WX_PRECOMP + #include "wx/image.h" +#endif + #include "wx/mac/private.h" IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) @@ -49,6 +53,21 @@ wxIcon::wxIcon( LoadFile( icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight ); } +wxIcon::wxIcon(WXHICON icon, const wxSize& size) + : wxGDIObject() +{ + // as the icon owns that ref, we have to acquire it as well + if (icon) + AcquireIconRef( (IconRef) icon ) ; + + m_refData = new wxIconRefData( icon ) ; + if ( (size.x != -1) && (size.y != -1) ) + { + M_ICONDATA->SetWidth( size.x ) ; + M_ICONDATA->SetHeight( size.y ) ; + } +} + wxIcon::~wxIcon() { } @@ -79,19 +98,19 @@ int wxIcon::GetDepth() const return 32; } -void wxIcon::SetDepth( int depth ) +void wxIcon::SetDepth( int WXUNUSED(depth) ) { } -void wxIcon::SetWidth( int width ) +void wxIcon::SetWidth( int WXUNUSED(width) ) { } -void wxIcon::SetHeight( int height ) +void wxIcon::SetHeight( int WXUNUSED(height) ) { } -bool wxIcon::Ok() const +bool wxIcon::IsOk() const { return m_refData != NULL ; } @@ -122,20 +141,48 @@ bool wxIcon::LoadFile( { theId = kAlertStopIcon ; } + else if ( filename == wxT("wxICON_FOLDER") ) + { + theId = kGenericFolderIcon ; + } + else if ( filename == wxT("wxICON_FOLDER_OPEN") ) + { + theId = kOpenFolderIcon ; + } + else if ( filename == wxT("wxICON_NORMAL_FILE") ) + { + theId = kGenericDocumentIcon ; + } else { -#if 0 - Str255 theName ; - OSType theType ; - wxMacStringToPascal( name , theName ) ; - - Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - if ( resHandle != 0L ) + IconRef iconRef = NULL ; + + // first look in the resource fork + if ( iconRef == NULL ) + { + Str255 theName ; + + wxMacStringToPascal( filename , theName ) ; + Handle resHandle = GetNamedResource( 'icns' , theName ) ; + if ( resHandle != 0L ) + { + IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ; + HLock((Handle) iconFamily); + OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef ); + HUnlock((Handle) iconFamily); + wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") ); + ReleaseResource( resHandle ) ; + } + } + if ( iconRef == NULL ) { - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; + // TODO add other attempts to load it from files etc here } -#endif + if ( iconRef ) + { + m_refData = new wxIconRefData( (WXHICON) iconRef ) ; + return true ; + } } if ( theId != 0 ) @@ -180,7 +227,7 @@ bool wxIcon::LoadFile( desiredHeight = loadimage.GetHeight() ; if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) loadimage.Rescale( desiredWidth , desiredHeight ) ; - + wxBitmap bmp( loadimage ); CopyFromBitmap( bmp ) ; @@ -231,7 +278,7 @@ void wxIconRefData::Free() IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) bool wxICONResourceHandler::LoadFile( - wxBitmap *bitmap, const wxString& name, long flags, + wxBitmap *bitmap, const wxString& name, long WXUNUSED(flags), int desiredWidth, int desiredHeight ) { wxIcon icon ;