X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d062e17fca1a1fc0b82b269da4a7ad271075ba2b..900a87655f9a8533817c82fdac7deaedf345b246:/src/mac/carbon/icon.cpp diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 0133e45534..25543c1e95 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -1,24 +1,30 @@ ///////////////////////////////////////////////////////////////////////////// // Name: icon.cpp // Purpose: wxIcon class -// Author: AUTHOR +// Author: Stefan Csomor // Modified by: -// Created: ??/??/98 +// Created: 1998-01-01 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "icon.h" #endif +#include "wx/wxprec.h" + #include "wx/icon.h" #if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) #endif +#include "wx/image.h" +#include "wx/mac/private.h" + + /* * Icons */ @@ -28,45 +34,61 @@ wxIcon::wxIcon() } wxIcon::wxIcon(const char bits[], int width, int height) : - wxBitmap(bits,width,height ) + wxBitmap(bits, width, height) { } wxIcon::wxIcon( const char **bits ) : - wxBitmap(bits ) + wxBitmap(bits) { } wxIcon::wxIcon( char **bits ) : - wxBitmap(bits ) + wxBitmap(bits) { } -wxIcon::wxIcon(const wxString& icon_file, long flags, +wxIcon::wxIcon(const wxString& icon_file, int flags, int desiredWidth, int desiredHeight) - { - LoadFile(icon_file, flags, desiredWidth, desiredHeight); + LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight); } wxIcon::~wxIcon() { } -bool wxIcon::LoadFile(const wxString& filename, long type, +bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight) { - UnRef(); - - m_refData = new wxBitmapRefData; - - wxBitmapHandler *handler = FindHandler((wxBitmapType)type); + UnRef(); + + wxBitmapHandler *handler = FindHandler(type); - if ( handler ) - return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); - else - return FALSE; + if ( handler ) + { + m_refData = new wxBitmapRefData; + return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight ); + } + else + { + wxImage loadimage(filename, type); + if (loadimage.Ok()) + { + if ( desiredWidth == -1 ) + desiredWidth = loadimage.GetWidth() ; + if ( desiredHeight == -1 ) + desiredHeight = loadimage.GetHeight() ; + if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) + loadimage.Rescale( desiredWidth , desiredHeight ) ; + wxBitmap bmp( loadimage ); + wxIcon *icon = (wxIcon*)(&bmp); + *this = *icon; + return true; + } + } + return false ; } void wxIcon::CopyFromBitmap(const wxBitmap& bmp) @@ -78,59 +100,53 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp) IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight) + int desiredWidth, int desiredHeight) { - short theId = -1 ; - if ( name == "wxICON_INFO" ) + short theId = -1 ; + if ( name == wxT("wxICON_INFORMATION") ) { theId = kNoteIcon ; } - else if ( name == "wxICON_QUESTION" ) + else if ( name == wxT("wxICON_QUESTION") ) { theId = kCautionIcon ; } - else if ( name == "wxICON_WARNING" ) + else if ( name == wxT("wxICON_WARNING") ) { - theId = kCautionIcon ; - } - else if ( name == "wxICON_ERROR" ) + theId = kCautionIcon ; + } + else if ( name == wxT("wxICON_ERROR") ) { theId = kStopIcon ; } else { - Str255 theName ; - OSType theType ; - - #if TARGET_CARBON - c2pstrcpy( (StringPtr) theName , name ) ; - #else - strcpy( (char *) theName , name ) ; - c2pstr( (char *) theName ) ; - #endif - - Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - if ( resHandle != 0L ) - { - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; - } + Str255 theName ; + OSType theType ; + wxMacStringToPascal( name , theName ) ; + + Handle resHandle = GetNamedResource( 'cicn' , theName ) ; + if ( resHandle != 0L ) + { + GetResInfo( resHandle , &theId , &theType , theName ) ; + ReleaseResource( resHandle ) ; + } + } + if ( theId != -1 ) + { + CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; + if ( theIcon ) + { + M_BITMAPHANDLERDATA->m_hIcon = theIcon ; + M_BITMAPHANDLERDATA->m_width = 32 ; + M_BITMAPHANDLERDATA->m_height = 32 ; + + M_BITMAPHANDLERDATA->m_depth = 8 ; + M_BITMAPHANDLERDATA->m_ok = true ; + M_BITMAPHANDLERDATA->m_numColors = 256 ; + M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ; + return TRUE ; + } } - if ( theId != -1 ) - { - CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; - if ( theIcon ) - { - M_BITMAPHANDLERDATA->m_hIcon = theIcon ; - M_BITMAPHANDLERDATA->m_width = 32 ; - M_BITMAPHANDLERDATA->m_height = 32 ; - - M_BITMAPHANDLERDATA->m_depth = 8 ; - M_BITMAPHANDLERDATA->m_ok = true ; - M_BITMAPHANDLERDATA->m_numColors = 256 ; - M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ; - return TRUE ; - } - } - return FALSE ; + return FALSE ; }