]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
0d0512bd | 2 | // Name: msw/icon.cpp |
2bda0e17 KB |
3 | // Purpose: wxIcon class |
4 | // Author: Julian Smart | |
0d0512bd | 5 | // Modified by: 20.11.99 (VZ): don't derive from wxBitmap any more |
2bda0e17 KB |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
0d0512bd VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
0d0512bd | 21 | #pragma implementation "icon.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
0d0512bd | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
0d0512bd VZ |
32 | #include "wx/defs.h" |
33 | #include "wx/list.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/icon.h" | |
f02b73c4 | 37 | #include "wx/bitmap.h" |
f94dfb38 | 38 | #include "wx/log.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
41 | #include "wx/msw/private.h" | |
2bda0e17 | 42 | |
0d0512bd VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWin macros | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
621b3e21 | 47 | IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) |
2bda0e17 | 48 | |
0d0512bd VZ |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
2bda0e17 | 52 | |
0d0512bd VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // wxIconRefData | |
55 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 56 | |
0d0512bd | 57 | void wxIconRefData::Free() |
2bda0e17 | 58 | { |
0d0512bd | 59 | if ( m_hIcon ) |
032af30f | 60 | { |
04ef50df | 61 | #ifndef __WXMICROWIN__ |
0d0512bd | 62 | ::DestroyIcon((HICON) m_hIcon); |
04ef50df | 63 | #endif |
032af30f VZ |
64 | |
65 | m_hIcon = 0; | |
66 | } | |
2bda0e17 KB |
67 | } |
68 | ||
0d0512bd VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // wxIcon | |
71 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 72 | |
4b7f2165 | 73 | wxIcon::wxIcon(const char bits[], int width, int height) |
2bda0e17 | 74 | { |
4b7f2165 VZ |
75 | wxBitmap bmp(bits, width, height); |
76 | CopyFromBitmap(bmp); | |
2bda0e17 KB |
77 | } |
78 | ||
0d0512bd VZ |
79 | wxIcon::wxIcon(const wxString& iconfile, |
80 | long flags, | |
81 | int desiredWidth, | |
82 | int desiredHeight) | |
2bda0e17 KB |
83 | |
84 | { | |
0d0512bd | 85 | LoadFile(iconfile, flags, desiredWidth, desiredHeight); |
2bda0e17 KB |
86 | } |
87 | ||
aaf7ab43 VZ |
88 | wxIcon::wxIcon(const wxIconLocation& loc) |
89 | { | |
90 | // wxICOFileHandler accepts names in the format "filename;index" | |
91 | wxString fullname = loc.GetFileName(); | |
92 | if ( loc.GetIndex() ) | |
93 | { | |
94 | fullname << _T(';') << loc.GetIndex(); | |
95 | } | |
96 | //else: 0 is default | |
97 | ||
81ba2662 | 98 | LoadFile(fullname, wxBITMAP_TYPE_ICO); |
aaf7ab43 VZ |
99 | } |
100 | ||
0d0512bd | 101 | wxIcon::~wxIcon() |
2bda0e17 KB |
102 | { |
103 | } | |
104 | ||
9d769508 VZ |
105 | wxObjectRefData *wxIcon::CloneRefData(const wxObjectRefData *dataOrig) const |
106 | { | |
107 | const wxIconRefData * | |
108 | data = wx_static_cast(const wxIconRefData *, dataOrig); | |
109 | if ( !data ) | |
110 | return NULL; | |
111 | ||
112 | wxIcon *self = wx_const_cast(wxIcon *, this); | |
b9e3186d VZ |
113 | self->UnRef(); |
114 | self->m_refData = new wxIconRefData(*data); | |
9d769508 VZ |
115 | |
116 | if ( data->m_hIcon ) | |
117 | { | |
118 | ::CopyIcon(HICON(data->m_hIcon)); | |
119 | } | |
120 | ||
121 | return m_refData; | |
122 | } | |
123 | ||
4b7f2165 VZ |
124 | void wxIcon::CopyFromBitmap(const wxBitmap& bmp) |
125 | { | |
04ef50df | 126 | #ifndef __WXMICROWIN__ |
7fd328a3 | 127 | HICON hicon = wxBitmapToHICON(bmp); |
4b7f2165 VZ |
128 | if ( !hicon ) |
129 | { | |
f6bcfd97 | 130 | wxLogLastError(wxT("CreateIconIndirect")); |
4b7f2165 VZ |
131 | } |
132 | else | |
133 | { | |
134 | SetHICON((WXHICON)hicon); | |
135 | SetSize(bmp.GetWidth(), bmp.GetHeight()); | |
136 | } | |
7fd328a3 | 137 | #endif // __WXMICROWIN__ |
4b7f2165 VZ |
138 | } |
139 | ||
140 | void wxIcon::CreateIconFromXpm(const char **data) | |
141 | { | |
142 | wxBitmap bmp(data); | |
143 | CopyFromBitmap(bmp); | |
144 | } | |
145 | ||
0d0512bd VZ |
146 | bool wxIcon::LoadFile(const wxString& filename, |
147 | long type, | |
148 | int desiredWidth, int desiredHeight) | |
2bda0e17 | 149 | { |
0d0512bd | 150 | UnRef(); |
2bda0e17 | 151 | |
0d0512bd | 152 | wxGDIImageHandler *handler = FindHandler(type); |
2bda0e17 | 153 | |
0d0512bd | 154 | if ( !handler ) |
2bda0e17 | 155 | { |
0d0512bd | 156 | // say something? |
59af881e | 157 | return false; |
2bda0e17 KB |
158 | } |
159 | ||
0d0512bd | 160 | return handler->Load(this, filename, type, desiredWidth, desiredHeight); |
2bda0e17 KB |
161 | } |
162 |