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