]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/icon.cpp
added wxID_ANY default value for the id parameter of Create() for consistency with...
[wxWidgets.git] / src / mac / classic / icon.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
923d28da 2// Name: src/mac/classic/icon.cpp
2646f485
SC
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
923d28da 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
923d28da
WS
12#include "wx/wxprec.h"
13
2646f485
SC
14#include "wx/icon.h"
15
2646f485 16IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
2646f485
SC
17
18#include "wx/mac/private.h"
19
20
21/*
22 * Icons
23 */
24
25wxIcon::wxIcon()
26{
27}
28
923d28da
WS
29wxIcon::wxIcon(const char bits[], int width, int height)
30 :wxBitmap(bits, width, height)
2646f485 31{
2646f485
SC
32}
33
34wxIcon::wxIcon( const char **bits ) :
35 wxBitmap(bits)
36{
37}
38
39wxIcon::wxIcon( char **bits ) :
40 wxBitmap(bits)
41{
42}
43
44wxIcon::wxIcon(const wxString& icon_file, int flags,
45 int desiredWidth, int desiredHeight)
46{
47 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
48}
49
50wxIcon::~wxIcon()
51{
52}
53
54bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
55 int desiredWidth, int desiredHeight)
56{
57 UnRef();
923d28da 58
2646f485 59 m_refData = new wxBitmapRefData;
923d28da 60
2646f485 61 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
923d28da 62
2646f485
SC
63 if ( handler )
64 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
65 else
923d28da 66 return false;
2646f485
SC
67}
68
69void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
70{
71 wxIcon *icon = (wxIcon*)(&bmp);
72 *this = *icon;
73}
74
75IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
76
77bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
78 int desiredWidth, int desiredHeight)
79{
80 short theId = -1 ;
81 if ( name == wxT("wxICON_INFORMATION") )
82 {
83 theId = kNoteIcon ;
84 }
85 else if ( name == wxT("wxICON_QUESTION") )
86 {
87 theId = kCautionIcon ;
88 }
89 else if ( name == wxT("wxICON_WARNING") )
90 {
91 theId = kCautionIcon ;
92 }
93 else if ( name == wxT("wxICON_ERROR") )
94 {
95 theId = kStopIcon ;
96 }
97 else
98 {
99 Str255 theName ;
100 OSType theType ;
101 wxMacStringToPascal( name , theName ) ;
923d28da 102
2646f485
SC
103 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
104 if ( resHandle != 0L )
105 {
106 GetResInfo( resHandle , &theId , &theType , theName ) ;
107 ReleaseResource( resHandle ) ;
108 }
109 }
110 if ( theId != -1 )
111 {
112 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
113 if ( theIcon )
114 {
115 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
116 M_BITMAPHANDLERDATA->m_width = 32 ;
117 M_BITMAPHANDLERDATA->m_height = 32 ;
923d28da 118
2646f485
SC
119 M_BITMAPHANDLERDATA->m_depth = 8 ;
120 M_BITMAPHANDLERDATA->m_ok = true ;
121 M_BITMAPHANDLERDATA->m_numColors = 256 ;
122 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
923d28da 123 return true;
2646f485
SC
124 }
125 }
923d28da 126 return false;
2646f485 127}