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