]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "icon.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/icon.h" | |
17 | ||
2646f485 | 18 | IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) |
2646f485 SC |
19 | |
20 | #include "wx/mac/private.h" | |
21 | ||
22 | ||
23 | /* | |
24 | * Icons | |
25 | */ | |
26 | ||
27 | wxIcon::wxIcon() | |
28 | { | |
29 | } | |
30 | ||
31 | wxIcon::wxIcon(const char bits[], int width, int height) : | |
32 | wxBitmap(bits, width, height) | |
33 | { | |
34 | ||
35 | } | |
36 | ||
37 | wxIcon::wxIcon( const char **bits ) : | |
38 | wxBitmap(bits) | |
39 | { | |
40 | } | |
41 | ||
42 | wxIcon::wxIcon( char **bits ) : | |
43 | wxBitmap(bits) | |
44 | { | |
45 | } | |
46 | ||
47 | wxIcon::wxIcon(const wxString& icon_file, int flags, | |
48 | int desiredWidth, int desiredHeight) | |
49 | { | |
50 | LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight); | |
51 | } | |
52 | ||
53 | wxIcon::~wxIcon() | |
54 | { | |
55 | } | |
56 | ||
57 | bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, | |
58 | int desiredWidth, int desiredHeight) | |
59 | { | |
60 | UnRef(); | |
61 | ||
62 | m_refData = new wxBitmapRefData; | |
63 | ||
64 | wxBitmapHandler *handler = FindHandler((wxBitmapType)type); | |
65 | ||
66 | if ( handler ) | |
67 | return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); | |
68 | else | |
69 | return FALSE; | |
70 | } | |
71 | ||
72 | void wxIcon::CopyFromBitmap(const wxBitmap& bmp) | |
73 | { | |
74 | wxIcon *icon = (wxIcon*)(&bmp); | |
75 | *this = *icon; | |
76 | } | |
77 | ||
78 | IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) | |
79 | ||
80 | bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
81 | int desiredWidth, int desiredHeight) | |
82 | { | |
83 | short theId = -1 ; | |
84 | if ( name == wxT("wxICON_INFORMATION") ) | |
85 | { | |
86 | theId = kNoteIcon ; | |
87 | } | |
88 | else if ( name == wxT("wxICON_QUESTION") ) | |
89 | { | |
90 | theId = kCautionIcon ; | |
91 | } | |
92 | else if ( name == wxT("wxICON_WARNING") ) | |
93 | { | |
94 | theId = kCautionIcon ; | |
95 | } | |
96 | else if ( name == wxT("wxICON_ERROR") ) | |
97 | { | |
98 | theId = kStopIcon ; | |
99 | } | |
100 | else | |
101 | { | |
102 | Str255 theName ; | |
103 | OSType theType ; | |
104 | wxMacStringToPascal( name , theName ) ; | |
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 ) | |
114 | { | |
115 | CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; | |
116 | if ( theIcon ) | |
117 | { | |
118 | M_BITMAPHANDLERDATA->m_hIcon = theIcon ; | |
119 | M_BITMAPHANDLERDATA->m_width = 32 ; | |
120 | M_BITMAPHANDLERDATA->m_height = 32 ; | |
121 | ||
122 | M_BITMAPHANDLERDATA->m_depth = 8 ; | |
123 | M_BITMAPHANDLERDATA->m_ok = true ; | |
124 | M_BITMAPHANDLERDATA->m_numColors = 256 ; | |
125 | M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ; | |
126 | return TRUE ; | |
127 | } | |
128 | } | |
129 | return FALSE ; | |
130 | } |