]> git.saurik.com Git - wxWidgets.git/blame - src/mac/icon.cpp
wxCocoa: Added basic (i.e. not working) implementation of wxComboBox
[wxWidgets.git] / src / mac / 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
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
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 33wxIcon::wxIcon(const char bits[], int width, int height) :
d84afea9 34 wxBitmap(bits, width, height)
e9576ca5 35{
3dec57ad 36
e9576ca5
SC
37}
38
3dec57ad 39wxIcon::wxIcon( const char **bits ) :
d84afea9 40 wxBitmap(bits)
2f1ae414
SC
41{
42}
43
3dec57ad 44wxIcon::wxIcon( char **bits ) :
d84afea9 45 wxBitmap(bits)
2f1ae414
SC
46{
47}
48
76a5e5d2 49wxIcon::wxIcon(const wxString& icon_file, int flags,
e9576ca5 50 int desiredWidth, int desiredHeight)
e9576ca5 51{
76a5e5d2 52 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
e9576ca5
SC
53}
54
55wxIcon::~wxIcon()
56{
57}
58
76a5e5d2 59bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
e9576ca5
SC
60 int desiredWidth, int desiredHeight)
61{
e40298d5
JS
62 UnRef();
63
64 m_refData = new wxBitmapRefData;
65
66 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
67
68 if ( handler )
69 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
70 else
71 return FALSE;
e9576ca5
SC
72}
73
d062e17f
GD
74void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
75{
76 wxIcon *icon = (wxIcon*)(&bmp);
77 *this = *icon;
78}
79
519cb848
SC
80IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
81
82bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
e40298d5 83 int desiredWidth, int desiredHeight)
519cb848 84{
e40298d5 85 short theId = -1 ;
427ff662 86 if ( name == wxT("wxICON_INFORMATION") )
3dec57ad
SC
87 {
88 theId = kNoteIcon ;
89 }
427ff662 90 else if ( name == wxT("wxICON_QUESTION") )
3dec57ad
SC
91 {
92 theId = kCautionIcon ;
93 }
427ff662 94 else if ( name == wxT("wxICON_WARNING") )
3dec57ad 95 {
e40298d5
JS
96 theId = kCautionIcon ;
97 }
427ff662 98 else if ( name == wxT("wxICON_ERROR") )
3dec57ad
SC
99 {
100 theId = kStopIcon ;
101 }
102 else
103 {
e40298d5
JS
104 Str255 theName ;
105 OSType theType ;
427ff662 106 wxMacStringToPascal( name , theName ) ;
e40298d5
JS
107
108 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
109 if ( resHandle != 0L )
110 {
111 GetResInfo( resHandle , &theId , &theType , theName ) ;
112 ReleaseResource( resHandle ) ;
113 }
114 }
115 if ( theId != -1 )
116 {
117 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
118 if ( theIcon )
119 {
120 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
121 M_BITMAPHANDLERDATA->m_width = 32 ;
122 M_BITMAPHANDLERDATA->m_height = 32 ;
123
124 M_BITMAPHANDLERDATA->m_depth = 8 ;
125 M_BITMAPHANDLERDATA->m_ok = true ;
126 M_BITMAPHANDLERDATA->m_numColors = 256 ;
127 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
128 return TRUE ;
129 }
3dec57ad 130 }
e40298d5 131 return FALSE ;
03e11df5 132}