X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f1ae4143271ae63a17e052a1a471d16e9cd8c44..a8680e3e0e5066d35a8f4fd43294ba4bfcaf4ba7:/src/mac/carbon/icon.cpp diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 4ec1f1b5e9..bd1937bc2a 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -1,12 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// // 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__ @@ -19,110 +19,114 @@ IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) #endif +#include "wx/mac/private.h" + + /* * Icons */ - -wxIconRefData::wxIconRefData() -{ - m_ok = FALSE; - m_width = 0; - m_height = 0; - m_depth = 0; - m_quality = 0; - m_numColors = 0; - m_bitmapMask = NULL; - m_hBitmap = NULL ; - m_hIcon = NULL ; -} - -wxIconRefData::~wxIconRefData() -{ - if ( m_hIcon ) - { - DisposeCIcon( m_hIcon ) ; - m_hIcon = NULL ; - } - - if (m_bitmapMask) - { - delete m_bitmapMask; - m_bitmapMask = NULL; - } -} - wxIcon::wxIcon() { } -wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height)) +wxIcon::wxIcon(const char bits[], int width, int height) : + wxBitmap(bits, width, height) { + } -wxIcon::wxIcon( const char **bits, int width, int height ) +wxIcon::wxIcon( const char **bits ) : + wxBitmap(bits) { } -wxIcon::wxIcon( char **bits, int width, int height ) +wxIcon::wxIcon( char **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 wxIconRefData; - - wxBitmapHandler *handler = FindHandler(type); + UnRef(); + + m_refData = new wxBitmapRefData; + + wxBitmapHandler *handler = FindHandler((wxBitmapType)type); + + if ( handler ) + return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); + else + return FALSE; +} - if ( handler ) - return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); - else - return FALSE; +void wxIcon::CopyFromBitmap(const wxBitmap& bmp) +{ + wxIcon *icon = (wxIcon*)(&bmp); + *this = *icon; } IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight) + int desiredWidth, int desiredHeight) { - Str255 theName ; - short theId ; - OSType theType ; - strcpy( (char*) theName , name ) ; - c2pstr( (char*) theName ) ; - - Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - if ( resHandle != 0L ) - { - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; - - CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; - if ( theIcon ) - { - M_ICONHANDLERDATA->m_hIcon = theIcon ; - M_ICONHANDLERDATA->m_width = 32 ; - M_ICONHANDLERDATA->m_height = 32 ; - - M_ICONHANDLERDATA->m_depth = 8 ; - M_ICONHANDLERDATA->m_ok = true ; - M_ICONHANDLERDATA->m_numColors = 256 ; - return TRUE ; - } - } - return FALSE ; -} \ No newline at end of file + short theId = -1 ; + if ( name == wxT("wxICON_INFORMATION") ) + { + theId = kNoteIcon ; + } + else if ( name == wxT("wxICON_QUESTION") ) + { + theId = kCautionIcon ; + } + else if ( name == wxT("wxICON_WARNING") ) + { + theId = kCautionIcon ; + } + else if ( name == wxT("wxICON_ERROR") ) + { + theId = kStopIcon ; + } + else + { + 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 ; + } + } + return FALSE ; +}