]> git.saurik.com Git - wxWidgets.git/blame - src/msw/icon.cpp
fix build errors deriving from making wxColourData members private
[wxWidgets.git] / src / msw / icon.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/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
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
0d0512bd 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
27#ifndef WX_PRECOMP
0d0512bd
VZ
28 #include "wx/list.h"
29 #include "wx/utils.h"
30 #include "wx/app.h"
31 #include "wx/icon.h"
f02b73c4 32 #include "wx/bitmap.h"
f94dfb38 33 #include "wx/log.h"
2bda0e17
KB
34#endif
35
36#include "wx/msw/private.h"
2bda0e17 37
0d0512bd
VZ
38// ----------------------------------------------------------------------------
39// wxWin macros
40// ----------------------------------------------------------------------------
41
621b3e21 42IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
2bda0e17 43
0d0512bd
VZ
44// ============================================================================
45// implementation
46// ============================================================================
2bda0e17 47
0d0512bd
VZ
48// ----------------------------------------------------------------------------
49// wxIconRefData
50// ----------------------------------------------------------------------------
2bda0e17 51
0d0512bd 52void wxIconRefData::Free()
2bda0e17 53{
0d0512bd 54 if ( m_hIcon )
032af30f 55 {
04ef50df 56#ifndef __WXMICROWIN__
0d0512bd 57 ::DestroyIcon((HICON) m_hIcon);
04ef50df 58#endif
032af30f
VZ
59
60 m_hIcon = 0;
61 }
2bda0e17
KB
62}
63
0d0512bd
VZ
64// ----------------------------------------------------------------------------
65// wxIcon
66// ----------------------------------------------------------------------------
2bda0e17 67
4b7f2165 68wxIcon::wxIcon(const char bits[], int width, int height)
2bda0e17 69{
4b7f2165
VZ
70 wxBitmap bmp(bits, width, height);
71 CopyFromBitmap(bmp);
2bda0e17
KB
72}
73
0d0512bd 74wxIcon::wxIcon(const wxString& iconfile,
e86f2cc8 75 wxBitmapType type,
0d0512bd
VZ
76 int desiredWidth,
77 int desiredHeight)
2bda0e17
KB
78
79{
e86f2cc8 80 LoadFile(iconfile, type, desiredWidth, desiredHeight);
2bda0e17
KB
81}
82
aaf7ab43
VZ
83wxIcon::wxIcon(const wxIconLocation& loc)
84{
85 // wxICOFileHandler accepts names in the format "filename;index"
86 wxString fullname = loc.GetFileName();
87 if ( loc.GetIndex() )
88 {
89 fullname << _T(';') << loc.GetIndex();
90 }
91 //else: 0 is default
92
81ba2662 93 LoadFile(fullname, wxBITMAP_TYPE_ICO);
aaf7ab43
VZ
94}
95
0d0512bd 96wxIcon::~wxIcon()
2bda0e17
KB
97{
98}
99
9d769508
VZ
100wxObjectRefData *wxIcon::CloneRefData(const wxObjectRefData *dataOrig) const
101{
102 const wxIconRefData *
103 data = wx_static_cast(const wxIconRefData *, dataOrig);
104 if ( !data )
105 return NULL;
106
d79c8ea9
VZ
107 // we don't have to copy m_hIcon because we're only called from SetHICON()
108 // which overwrites m_hIcon anyhow currently
109 //
110 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
111 // to copy it neither as the handle would be inconsistent with the new size
112 return new wxIconRefData(*data);
9d769508
VZ
113}
114
4b7f2165
VZ
115void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
116{
04ef50df 117#ifndef __WXMICROWIN__
7fd328a3 118 HICON hicon = wxBitmapToHICON(bmp);
4b7f2165
VZ
119 if ( !hicon )
120 {
f6bcfd97 121 wxLogLastError(wxT("CreateIconIndirect"));
4b7f2165
VZ
122 }
123 else
124 {
125 SetHICON((WXHICON)hicon);
126 SetSize(bmp.GetWidth(), bmp.GetHeight());
127 }
7fd328a3 128#endif // __WXMICROWIN__
4b7f2165
VZ
129}
130
e45080c1 131void wxIcon::CreateIconFromXpm(const char* const* data)
4b7f2165
VZ
132{
133 wxBitmap bmp(data);
134 CopyFromBitmap(bmp);
135}
136
0d0512bd 137bool wxIcon::LoadFile(const wxString& filename,
e86f2cc8 138 wxBitmapType type,
0d0512bd 139 int desiredWidth, int desiredHeight)
2bda0e17 140{
0d0512bd 141 UnRef();
2bda0e17 142
0d0512bd 143 wxGDIImageHandler *handler = FindHandler(type);
2bda0e17 144
0d0512bd 145 if ( !handler )
2bda0e17 146 {
3e0630be
VZ
147 // load via wxBitmap which, in turn, uses wxImage allowing us to
148 // support more formats
149 wxBitmap bmp;
150 if ( !bmp.LoadFile(filename, type) )
151 return false;
152
153 CopyFromBitmap(bmp);
154 return true;
2bda0e17
KB
155 }
156
0d0512bd 157 return handler->Load(this, filename, type, desiredWidth, desiredHeight);
2bda0e17 158}