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