]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/icon.cpp
FixMath fix
[wxWidgets.git] / src / mac / carbon / icon.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: icon.cpp
3// Purpose: wxIcon class
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "icon.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
e9576ca5
SC
18#include "wx/icon.h"
19
2f1ae414 20#if !USE_SHARED_LIBRARIES
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
2f1ae414 22#endif
e9576ca5 23
1996c23f 24#include "wx/image.h"
76a5e5d2
SC
25#include "wx/mac/private.h"
26
27
e9576ca5
SC
28/*
29 * Icons
30 */
31
e9576ca5
SC
32wxIcon::wxIcon()
33{
34}
35
3dec57ad 36wxIcon::wxIcon(const char bits[], int width, int height) :
d84afea9 37 wxBitmap(bits, width, height)
e9576ca5 38{
3dec57ad 39
e9576ca5
SC
40}
41
3dec57ad 42wxIcon::wxIcon( const char **bits ) :
d84afea9 43 wxBitmap(bits)
2f1ae414
SC
44{
45}
46
3dec57ad 47wxIcon::wxIcon( char **bits ) :
d84afea9 48 wxBitmap(bits)
2f1ae414
SC
49{
50}
51
76a5e5d2 52wxIcon::wxIcon(const wxString& icon_file, int flags,
e9576ca5 53 int desiredWidth, int desiredHeight)
e9576ca5 54{
76a5e5d2 55 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
e9576ca5
SC
56}
57
58wxIcon::~wxIcon()
59{
60}
61
76a5e5d2 62bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
e9576ca5
SC
63 int desiredWidth, int desiredHeight)
64{
e40298d5
JS
65 UnRef();
66
1996c23f
SC
67 wxBitmapHandler *handler = FindHandler(type);
68
e40298d5 69 if ( handler )
1996c23f
SC
70 {
71 m_refData = new wxBitmapRefData;
72 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight );
73 }
e40298d5 74 else
1996c23f
SC
75 {
76 wxImage loadimage(filename, type);
77 if (loadimage.Ok())
78 {
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);
87 *this = *icon;
88 return true;
89 }
90 }
91 return false ;
e9576ca5
SC
92}
93
d062e17f
GD
94void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
95{
96 wxIcon *icon = (wxIcon*)(&bmp);
97 *this = *icon;
98}
99
519cb848
SC
100IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
101
102bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
e40298d5 103 int desiredWidth, int desiredHeight)
519cb848 104{
e40298d5 105 short theId = -1 ;
427ff662 106 if ( name == wxT("wxICON_INFORMATION") )
3dec57ad
SC
107 {
108 theId = kNoteIcon ;
109 }
427ff662 110 else if ( name == wxT("wxICON_QUESTION") )
3dec57ad
SC
111 {
112 theId = kCautionIcon ;
113 }
427ff662 114 else if ( name == wxT("wxICON_WARNING") )
3dec57ad 115 {
e40298d5
JS
116 theId = kCautionIcon ;
117 }
427ff662 118 else if ( name == wxT("wxICON_ERROR") )
3dec57ad
SC
119 {
120 theId = kStopIcon ;
121 }
122 else
123 {
e40298d5
JS
124 Str255 theName ;
125 OSType theType ;
427ff662 126 wxMacStringToPascal( name , theName ) ;
e40298d5
JS
127
128 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
129 if ( resHandle != 0L )
130 {
131 GetResInfo( resHandle , &theId , &theType , theName ) ;
132 ReleaseResource( resHandle ) ;
133 }
134 }
135 if ( theId != -1 )
136 {
137 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
138 if ( theIcon )
139 {
140 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
141 M_BITMAPHANDLERDATA->m_width = 32 ;
142 M_BITMAPHANDLERDATA->m_height = 32 ;
143
144 M_BITMAPHANDLERDATA->m_depth = 8 ;
145 M_BITMAPHANDLERDATA->m_ok = true ;
146 M_BITMAPHANDLERDATA->m_numColors = 256 ;
147 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
148 return TRUE ;
149 }
3dec57ad 150 }
e40298d5 151 return FALSE ;
03e11df5 152}