]> git.saurik.com Git - wxWidgets.git/blame - src/mac/icon.cpp
bugfix for SetString in a wxCheckListBox
[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 21
76a5e5d2
SC
22#include "wx/mac/private.h"
23
24
e9576ca5
SC
25/*
26 * Icons
27 */
28
e9576ca5
SC
29wxIcon::wxIcon()
30{
31}
32
3dec57ad
SC
33wxIcon::wxIcon(const char bits[], int width, int height) :
34 wxBitmap(bits,width,height )
e9576ca5 35{
3dec57ad 36
e9576ca5
SC
37}
38
3dec57ad
SC
39wxIcon::wxIcon( const char **bits ) :
40 wxBitmap(bits )
2f1ae414
SC
41{
42}
43
3dec57ad
SC
44wxIcon::wxIcon( char **bits ) :
45 wxBitmap(bits )
2f1ae414
SC
46{
47}
48
76a5e5d2 49wxIcon::wxIcon(const wxString& icon_file, int flags,
e9576ca5
SC
50 int desiredWidth, int desiredHeight)
51
52{
76a5e5d2 53 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
e9576ca5
SC
54}
55
56wxIcon::~wxIcon()
57{
58}
59
76a5e5d2 60bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
e9576ca5
SC
61 int desiredWidth, int desiredHeight)
62{
63 UnRef();
64
3dec57ad 65 m_refData = new wxBitmapRefData;
e9576ca5 66
90b959ae 67 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
e9576ca5
SC
68
69 if ( handler )
70 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
71 else
72 return FALSE;
73}
74
d062e17f
GD
75void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
76{
77 wxIcon *icon = (wxIcon*)(&bmp);
78 *this = *icon;
79}
80
519cb848
SC
81IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
82
83bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
84 int desiredWidth, int desiredHeight)
85{
3dec57ad
SC
86 short theId = -1 ;
87 if ( name == "wxICON_INFO" )
88 {
89 theId = kNoteIcon ;
90 }
91 else if ( name == "wxICON_QUESTION" )
92 {
93 theId = kCautionIcon ;
94 }
95 else if ( name == "wxICON_WARNING" )
96 {
97 theId = kCautionIcon ;
98 }
99 else if ( name == "wxICON_ERROR" )
100 {
101 theId = kStopIcon ;
102 }
103 else
104 {
105 Str255 theName ;
106 OSType theType ;
107
108 #if TARGET_CARBON
109 c2pstrcpy( (StringPtr) theName , name ) ;
110 #else
111 strcpy( (char *) theName , name ) ;
112 c2pstr( (char *) theName ) ;
113 #endif
114
115 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
116 if ( resHandle != 0L )
117 {
118 GetResInfo( resHandle , &theId , &theType , theName ) ;
119 ReleaseResource( resHandle ) ;
120 }
121 }
122 if ( theId != -1 )
519cb848 123 {
2f1ae414
SC
124 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
125 if ( theIcon )
126 {
3dec57ad
SC
127 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
128 M_BITMAPHANDLERDATA->m_width = 32 ;
129 M_BITMAPHANDLERDATA->m_height = 32 ;
2f1ae414 130
3dec57ad
SC
131 M_BITMAPHANDLERDATA->m_depth = 8 ;
132 M_BITMAPHANDLERDATA->m_ok = true ;
133 M_BITMAPHANDLERDATA->m_numColors = 256 ;
134 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
2f1ae414
SC
135 return TRUE ;
136 }
519cb848
SC
137 }
138 return FALSE ;
03e11df5 139}