]> git.saurik.com Git - wxWidgets.git/blame - src/msw/icon.cpp
1. wxImageHandler::DoCanRead() introduced to solve the virtual function name
[wxWidgets.git] / src / msw / icon.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: icon.cpp
3// Purpose: wxIcon class
4// Author: Julian Smart
5// Modified by:
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
12#ifdef __GNUG__
13#pragma implementation "icon.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/setup.h"
26#include "wx/list.h"
27#include "wx/utils.h"
28#include "wx/app.h"
29#include "wx/icon.h"
30#endif
31
32#include "wx/msw/private.h"
33#include "assert.h"
34
47d67540 35#if wxUSE_RESOURCE_LOADING_IN_MSW
2bda0e17
KB
36#include "wx/msw/curico.h"
37#include "wx/msw/curicop.h"
38#endif
39
40#if !USE_SHARED_LIBRARIES
41IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
42IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler)
43IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler)
44#endif
45
46/*
47 * Icons
48 */
49
50
51wxIconRefData::wxIconRefData(void)
52{
53 m_hIcon = (WXHICON) NULL ;
54}
55
56wxIconRefData::~wxIconRefData(void)
57{
8ed57d93
VZ
58 if ( m_hIcon )
59 ::DestroyIcon((HICON) m_hIcon);
2bda0e17
KB
60}
61
62wxIcon::wxIcon(void)
63{
64}
65
debe6624 66wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
2bda0e17
KB
67{
68}
69
debe6624 70wxIcon::wxIcon(const wxString& icon_file, long flags,
2bda0e17
KB
71 int desiredWidth, int desiredHeight)
72
73{
74 LoadFile(icon_file, flags, desiredWidth, desiredHeight);
75}
76
77wxIcon::~wxIcon(void)
78{
79}
80
81bool wxIcon::FreeResource(bool force)
82{
83 if (M_ICONDATA && M_ICONDATA->m_hIcon)
84 {
85 DestroyIcon((HICON) M_ICONDATA->m_hIcon);
8ed57d93 86 M_ICONDATA->m_hIcon = (WXHICON) NULL;
2bda0e17
KB
87 }
88 return TRUE;
89}
90
debe6624 91bool wxIcon::LoadFile(const wxString& filename, long type,
2bda0e17
KB
92 int desiredWidth, int desiredHeight)
93{
94 UnRef();
95
96 m_refData = new wxIconRefData;
97
98 wxBitmapHandler *handler = FindHandler(type);
99
100 if ( handler )
8ed57d93 101 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
2bda0e17 102 else
8ed57d93 103 return FALSE;
2bda0e17
KB
104}
105
106void wxIcon::SetHICON(WXHICON ico)
107{
108 if ( !M_ICONDATA )
8ed57d93 109 m_refData = new wxIconRefData;
2bda0e17
KB
110
111 M_ICONDATA->m_hIcon = ico;
112}
113
debe6624 114bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
2bda0e17
KB
115 int desiredWidth, int desiredHeight)
116{
47d67540 117#if wxUSE_RESOURCE_LOADING_IN_MSW
8ed57d93
VZ
118 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
119 {
120 wxIcon *icon = (wxIcon *)bitmap;
121 wxIconRefData *data = (wxIconRefData *)icon->GetRefData();
837e5743 122 data->m_hIcon = (WXHICON)ReadIconFile((wxChar *)name.c_str(), wxGetInstance(),
8ed57d93
VZ
123 &data->m_width, &data->m_height);
124
125 data->m_ok = data->m_hIcon != 0;
126 return data->m_ok;
127 }
128 else
129 return FALSE;
2bda0e17 130#else
8ed57d93 131 return FALSE;
2bda0e17
KB
132#endif
133}
134
debe6624 135bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
2bda0e17
KB
136 int desiredWidth, int desiredHeight)
137{
8ed57d93
VZ
138 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
139 {
2432b92d 140#if defined(__WIN32__) && !defined(__SC__)
2bda0e17
KB
141 if (desiredWidth > -1 && desiredHeight > -1)
142 {
143 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR);
144 }
145 else
146#endif
147 {
8ed57d93 148 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name);
2bda0e17
KB
149 }
150
151#ifdef __WIN32__
8ed57d93
VZ
152 // Win32s doesn't have GetIconInfo function...
153 if (M_ICONHANDLERDATA->m_hIcon && wxGetOsVersion()!=wxWIN32S)
154 {
155 ICONINFO info ;
156 if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info))
157 {
158 HBITMAP ms_bitmap = info.hbmMask ;
159 if (ms_bitmap)
160 {
161 BITMAP bm;
162 ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm);
163 M_ICONHANDLERDATA->m_width = bm.bmWidth;
164 M_ICONHANDLERDATA->m_height = bm.bmHeight;
165 }
166 if (info.hbmMask)
167 ::DeleteObject(info.hbmMask) ;
168 if (info.hbmColor)
169 ::DeleteObject(info.hbmColor) ;
170 }
171 }
2bda0e17 172#else
8ed57d93
VZ
173 M_ICONHANDLERDATA->m_width = 32;
174 M_ICONHANDLERDATA->m_height = 32;
2bda0e17 175#endif
f60d0f94
JS
176 // Override the found values with desired values
177 if (desiredWidth > -1 && desiredHeight > -1)
178 {
179 M_ICONHANDLERDATA->m_width = desiredWidth;
180 M_ICONHANDLERDATA->m_height = desiredHeight;
181 }
182
8ed57d93
VZ
183 M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0);
184 return M_ICONHANDLERDATA->m_ok;
185 }
186 else
187 return FALSE;
2bda0e17
KB
188}
189