]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "icon.h"
16 #include "wx/wxprec.h"
20 #if !USE_SHARED_LIBRARIES
21 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
25 #include "wx/mac/private.h"
36 wxIcon::wxIcon(const char bits
[], int width
, int height
) :
37 wxBitmap(bits
, width
, height
)
42 wxIcon::wxIcon( const char **bits
) :
47 wxIcon::wxIcon( char **bits
) :
52 wxIcon::wxIcon(const wxString
& icon_file
, int flags
,
53 int desiredWidth
, int desiredHeight
)
55 LoadFile(icon_file
, (wxBitmapType
) flags
, desiredWidth
, desiredHeight
);
62 bool wxIcon::LoadFile(const wxString
& filename
, wxBitmapType type
,
63 int desiredWidth
, int desiredHeight
)
67 wxBitmapHandler
*handler
= FindHandler(type
);
71 m_refData
= new wxBitmapRefData
;
72 return handler
->LoadFile(this, filename
, type
, desiredWidth
, desiredHeight
);
76 wxImage
loadimage(filename
, type
);
79 if ( desiredWidth
== -1 )
80 desiredWidth
= loadimage
.GetWidth() ;
81 if ( desiredHeight
== -1 )
82 desiredHeight
= loadimage
.GetHeight() ;
83 if ( desiredWidth
!= loadimage
.GetWidth() || desiredHeight
!= loadimage
.GetHeight() )
84 loadimage
.Rescale( desiredWidth
, desiredHeight
) ;
85 wxBitmap
bmp( loadimage
);
86 wxIcon
*icon
= (wxIcon
*)(&bmp
);
94 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
96 wxIcon
*icon
= (wxIcon
*)(&bmp
);
100 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler
, wxBitmapHandler
)
102 bool wxICONResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
103 int desiredWidth
, int desiredHeight
)
106 if ( name
== wxT("wxICON_INFORMATION") )
110 else if ( name
== wxT("wxICON_QUESTION") )
112 theId
= kCautionIcon
;
114 else if ( name
== wxT("wxICON_WARNING") )
116 theId
= kCautionIcon
;
118 else if ( name
== wxT("wxICON_ERROR") )
126 wxMacStringToPascal( name
, theName
) ;
128 Handle resHandle
= GetNamedResource( 'cicn' , theName
) ;
129 if ( resHandle
!= 0L )
131 GetResInfo( resHandle
, &theId
, &theType
, theName
) ;
132 ReleaseResource( resHandle
) ;
137 CIconHandle theIcon
= (CIconHandle
) GetCIcon( theId
) ;
140 M_BITMAPHANDLERDATA
->m_hIcon
= theIcon
;
141 M_BITMAPHANDLERDATA
->m_width
= 32 ;
142 M_BITMAPHANDLERDATA
->m_height
= 32 ;
144 M_BITMAPHANDLERDATA
->m_depth
= 8 ;
145 M_BITMAPHANDLERDATA
->m_ok
= true ;
146 M_BITMAPHANDLERDATA
->m_numColors
= 256 ;
147 M_BITMAPHANDLERDATA
->m_bitmapType
= kMacBitmapTypeIcon
;