]> git.saurik.com Git - wxWidgets.git/blame - src/mac/icon.cpp
1. added wxAssertIsEqual() function to be used in wxASSERT()
[wxWidgets.git] / src / mac / icon.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: icon.cpp
3// Purpose: wxIcon class
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "icon.h"
14#endif
15
16#include "wx/icon.h"
17
2f1ae414 18#if !USE_SHARED_LIBRARIES
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
2f1ae414 20#endif
e9576ca5
SC
21
22/*
23 * Icons
24 */
25
e9576ca5
SC
26wxIcon::wxIcon()
27{
28}
29
3dec57ad
SC
30wxIcon::wxIcon(const char bits[], int width, int height) :
31 wxBitmap(bits,width,height )
e9576ca5 32{
3dec57ad 33
e9576ca5
SC
34}
35
3dec57ad
SC
36wxIcon::wxIcon( const char **bits ) :
37 wxBitmap(bits )
2f1ae414
SC
38{
39}
40
3dec57ad
SC
41wxIcon::wxIcon( char **bits ) :
42 wxBitmap(bits )
2f1ae414
SC
43{
44}
45
e9576ca5
SC
46wxIcon::wxIcon(const wxString& icon_file, long flags,
47 int desiredWidth, int desiredHeight)
48
49{
50 LoadFile(icon_file, flags, desiredWidth, desiredHeight);
51}
52
53wxIcon::~wxIcon()
54{
55}
56
57bool wxIcon::LoadFile(const wxString& filename, long type,
58 int desiredWidth, int desiredHeight)
59{
60 UnRef();
61
3dec57ad 62 m_refData = new wxBitmapRefData;
e9576ca5
SC
63
64 wxBitmapHandler *handler = FindHandler(type);
65
66 if ( handler )
67 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
68 else
69 return FALSE;
70}
71
519cb848
SC
72IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
73
74bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
75 int desiredWidth, int desiredHeight)
76{
3dec57ad
SC
77 short theId = -1 ;
78 if ( name == "wxICON_INFO" )
79 {
80 theId = kNoteIcon ;
81 }
82 else if ( name == "wxICON_QUESTION" )
83 {
84 theId = kCautionIcon ;
85 }
86 else if ( name == "wxICON_WARNING" )
87 {
88 theId = kCautionIcon ;
89 }
90 else if ( name == "wxICON_ERROR" )
91 {
92 theId = kStopIcon ;
93 }
94 else
95 {
96 Str255 theName ;
97 OSType theType ;
98
99 #if TARGET_CARBON
100 c2pstrcpy( (StringPtr) theName , name ) ;
101 #else
102 strcpy( (char *) theName , name ) ;
103 c2pstr( (char *) theName ) ;
104 #endif
105
106 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
107 if ( resHandle != 0L )
108 {
109 GetResInfo( resHandle , &theId , &theType , theName ) ;
110 ReleaseResource( resHandle ) ;
111 }
112 }
113 if ( theId != -1 )
519cb848 114 {
2f1ae414
SC
115 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
116 if ( theIcon )
117 {
3dec57ad
SC
118 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
119 M_BITMAPHANDLERDATA->m_width = 32 ;
120 M_BITMAPHANDLERDATA->m_height = 32 ;
2f1ae414 121
3dec57ad
SC
122 M_BITMAPHANDLERDATA->m_depth = 8 ;
123 M_BITMAPHANDLERDATA->m_ok = true ;
124 M_BITMAPHANDLERDATA->m_numColors = 256 ;
125 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
2f1ae414
SC
126 return TRUE ;
127 }
519cb848
SC
128 }
129 return FALSE ;
03e11df5 130}