]>
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
8ed57d93 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
0d0512bd VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
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" |
2bda0e17 KB |
38 | #endif |
39 | ||
40 | #include "wx/msw/private.h" | |
2bda0e17 | 41 | |
47d67540 | 42 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
0d0512bd VZ |
43 | #include "wx/msw/curico.h" |
44 | #include "wx/msw/curicop.h" | |
2bda0e17 KB |
45 | #endif |
46 | ||
0d0512bd VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // wxWin macros | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
4b7f2165 | 51 | IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxIconBase) |
2bda0e17 | 52 | |
0d0512bd VZ |
53 | // ============================================================================ |
54 | // implementation | |
55 | // ============================================================================ | |
2bda0e17 | 56 | |
0d0512bd VZ |
57 | // ---------------------------------------------------------------------------- |
58 | // wxIconRefData | |
59 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 60 | |
0d0512bd | 61 | void wxIconRefData::Free() |
2bda0e17 | 62 | { |
0d0512bd | 63 | if ( m_hIcon ) |
032af30f | 64 | { |
0d0512bd | 65 | ::DestroyIcon((HICON) m_hIcon); |
032af30f VZ |
66 | |
67 | m_hIcon = 0; | |
68 | } | |
2bda0e17 KB |
69 | } |
70 | ||
0d0512bd VZ |
71 | // ---------------------------------------------------------------------------- |
72 | // wxIcon | |
73 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 74 | |
4b7f2165 | 75 | wxIcon::wxIcon(const char bits[], int width, int height) |
2bda0e17 | 76 | { |
4b7f2165 VZ |
77 | wxBitmap bmp(bits, width, height); |
78 | CopyFromBitmap(bmp); | |
2bda0e17 KB |
79 | } |
80 | ||
0d0512bd VZ |
81 | wxIcon::wxIcon(const wxString& iconfile, |
82 | long flags, | |
83 | int desiredWidth, | |
84 | int desiredHeight) | |
2bda0e17 KB |
85 | |
86 | { | |
0d0512bd | 87 | LoadFile(iconfile, flags, desiredWidth, desiredHeight); |
2bda0e17 KB |
88 | } |
89 | ||
0d0512bd | 90 | wxIcon::~wxIcon() |
2bda0e17 KB |
91 | { |
92 | } | |
93 | ||
4b7f2165 VZ |
94 | void wxIcon::CopyFromBitmap(const wxBitmap& bmp) |
95 | { | |
96 | #ifdef __WIN32__ | |
97 | wxMask *mask = bmp.GetMask(); | |
98 | if ( !mask ) | |
99 | { | |
100 | // we must have a mask for an icon, so even if it's probably incorrect, | |
101 | // do create it (grey is the "standard" transparent colour) | |
102 | mask = new wxMask(bmp, *wxLIGHT_GREY); | |
103 | } | |
104 | ||
105 | ICONINFO iconInfo; | |
106 | iconInfo.fIcon = TRUE; // we want an icon, not a cursor | |
107 | iconInfo.hbmMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap()); | |
108 | iconInfo.hbmColor = GetHbitmapOf(bmp); | |
109 | ||
110 | HICON hicon = ::CreateIconIndirect(&iconInfo); | |
111 | if ( !hicon ) | |
112 | { | |
113 | wxLogLastError("CreateIconIndirect"); | |
114 | } | |
115 | else | |
116 | { | |
117 | SetHICON((WXHICON)hicon); | |
118 | SetSize(bmp.GetWidth(), bmp.GetHeight()); | |
119 | } | |
120 | ||
121 | if ( !bmp.GetMask() ) | |
122 | { | |
123 | // we created the mask, now delete it | |
124 | delete mask; | |
125 | } | |
126 | #else // Win16 | |
127 | // there are some functions in curico.cpp which probably could be used | |
128 | // here... | |
129 | wxFAIL_MSG("not implemented"); | |
130 | #endif // Win32/16 | |
131 | } | |
132 | ||
133 | void wxIcon::CreateIconFromXpm(const char **data) | |
134 | { | |
135 | wxBitmap bmp(data); | |
136 | CopyFromBitmap(bmp); | |
137 | } | |
138 | ||
0d0512bd VZ |
139 | bool wxIcon::LoadFile(const wxString& filename, |
140 | long type, | |
141 | int desiredWidth, int desiredHeight) | |
2bda0e17 | 142 | { |
0d0512bd | 143 | UnRef(); |
2bda0e17 | 144 | |
0d0512bd | 145 | wxGDIImageHandler *handler = FindHandler(type); |
2bda0e17 | 146 | |
0d0512bd | 147 | if ( !handler ) |
2bda0e17 | 148 | { |
0d0512bd VZ |
149 | // say something? |
150 | return FALSE; | |
2bda0e17 KB |
151 | } |
152 | ||
0d0512bd | 153 | return handler->Load(this, filename, type, desiredWidth, desiredHeight); |
2bda0e17 KB |
154 | } |
155 |