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