X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/62f864c32c53356b7228591c85b14abc491c46f0..797e38dde12c5dc2d99070eef25d9b8c2549d621:/src/mac/carbon/icon.cpp diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 956d8f72c3..68e908bf25 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -1,69 +1,78 @@ ///////////////////////////////////////////////////////////////////////////// -// 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 ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "icon.h" -#endif - #include "wx/wxprec.h" #include "wx/icon.h" -IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) +#ifndef WX_PRECOMP + #include "wx/image.h" +#endif -#include "wx/image.h" #include "wx/mac/private.h" -#define M_ICONDATA ((wxIconRefData *)m_refData) +IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) +#define M_ICONDATA ((wxIconRefData *)m_refData) -/* - * Icons - */ wxIcon::wxIcon() { } -wxIcon::wxIcon(const char bits[], int width, int height) +wxIcon::wxIcon( const char bits[], int width, int height ) { - wxBitmap bmp(bits,width,height) ; + wxBitmap bmp( bits, width, height ) ; CopyFromBitmap( bmp ) ; } -wxIcon::wxIcon( const char **bits ) +wxIcon::wxIcon( const char **bits ) { - wxBitmap bmp(bits) ; + wxBitmap bmp( bits ) ; CopyFromBitmap( bmp ) ; } -wxIcon::wxIcon( char **bits ) +wxIcon::wxIcon( char **bits ) { - wxBitmap bmp(bits) ; + wxBitmap bmp( bits ) ; CopyFromBitmap( bmp ) ; } -wxIcon::wxIcon(const wxString& icon_file, int flags, - int desiredWidth, int desiredHeight) +wxIcon::wxIcon( + const wxString& icon_file, int flags, + int desiredWidth, int desiredHeight ) +{ + LoadFile( icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight ); +} + +wxIcon::wxIcon(WXHICON icon, const wxSize& size) + : wxGDIObject() { - LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight); + // as the icon owns that ref, we have to acquire it as well + if (icon) + AcquireIconRef( (IconRef) icon ) ; + + m_refData = new wxIconRefData( icon ) ; + M_ICONDATA->SetWidth( size.x ) ; + M_ICONDATA->SetHeight( size.y ) ; } wxIcon::~wxIcon() { } -WXHICON wxIcon::GetHICON() const +WXHICON wxIcon::GetHICON() const { wxASSERT( Ok() ) ; + return (WXHICON) ((wxIconRefData*)m_refData)->GetHICON() ; } @@ -81,35 +90,38 @@ int wxIcon::GetHeight() const return M_ICONDATA->GetHeight(); } -int wxIcon::GetDepth() const{ - return 32; +int wxIcon::GetDepth() const +{ + return 32; } -void wxIcon::SetDepth(int depth){ - +void wxIcon::SetDepth( int depth ) +{ } -void wxIcon::SetWidth(int width){ - +void wxIcon::SetWidth( int width ) +{ } -void wxIcon::SetHeight(int height){ - +void wxIcon::SetHeight( int height ) +{ } -bool wxIcon::Ok() const +bool wxIcon::IsOk() const { return m_refData != NULL ; } -bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, - int desiredWidth, int desiredHeight) +bool wxIcon::LoadFile( + const wxString& filename, wxBitmapType type, + int desiredWidth, int desiredHeight ) { UnRef(); - + if ( type == wxBITMAP_TYPE_ICON_RESOURCE ) { OSType theId = 0 ; + if ( filename == wxT("wxICON_INFORMATION") ) { theId = kAlertNoteIcon ; @@ -126,51 +138,69 @@ bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, { 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 ) { GetResInfo( resHandle , &theId , &theType , theName ) ; ReleaseResource( resHandle ) ; } - */ +#endif } + if ( theId != 0 ) { IconRef iconRef = NULL ; - verify_noerr(GetIconRef(kOnSystemDisk,kSystemIconsCreator,theId, &iconRef)) ; + verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ; if ( iconRef ) { m_refData = new wxIconRefData( (WXHICON) iconRef ) ; - return TRUE ; + + return true ; } } - return FALSE ; + + return false ; } else { - wxBitmapHandler *handler = wxBitmap::FindHandler(type); + wxBitmapHandler *handler = wxBitmap::FindHandler( type ); if ( handler ) { wxBitmap bmp ; - if ( handler->LoadFile(&bmp , filename, type, desiredWidth, desiredHeight )) + if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight )) { CopyFromBitmap( bmp ) ; + return true ; } + return false ; } else { #if wxUSE_IMAGE - wxImage loadimage(filename, type); - if (loadimage.Ok()) + wxImage loadimage( filename, type ); + if (loadimage.Ok()) { if ( desiredWidth == -1 ) desiredWidth = loadimage.GetWidth() ; @@ -178,8 +208,10 @@ bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, desiredHeight = loadimage.GetHeight() ; if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) loadimage.Rescale( desiredWidth , desiredHeight ) ; + wxBitmap bmp( loadimage ); CopyFromBitmap( bmp ) ; + return true; } #endif @@ -188,13 +220,14 @@ bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, return true ; } -void wxIcon::CopyFromBitmap(const wxBitmap& bmp) +void wxIcon::CopyFromBitmap( const wxBitmap& bmp ) { UnRef() ; - + // as the bitmap owns that ref, we have to acquire it as well IconRef iconRef = bmp.GetBitmapData()->GetIconRef() ; AcquireIconRef( iconRef ) ; + m_refData = new wxIconRefData( (WXHICON) iconRef ) ; M_ICONDATA->SetWidth( bmp.GetWidth() ) ; M_ICONDATA->SetHeight( bmp.GetHeight() ) ; @@ -203,12 +236,13 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp) wxIconRefData::wxIconRefData( WXHICON icon ) { m_iconRef = MAC_WXHICON( icon ) ; - // Std sizes + + // Standard sizes SetWidth( 32 ) ; SetHeight( 32 ) ; } -void wxIconRefData::Init() +void wxIconRefData::Init() { m_iconRef = NULL ; } @@ -224,11 +258,14 @@ void wxIconRefData::Free() IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) -bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight) +bool wxICONResourceHandler::LoadFile( + wxBitmap *bitmap, const wxString& name, long flags, + int desiredWidth, int desiredHeight ) { wxIcon icon ; icon.LoadFile( name , wxBITMAP_TYPE_ICON_RESOURCE , desiredWidth , desiredHeight ) ; bitmap->CopyFromIcon( icon ) ; + return bitmap->Ok() ; } +