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