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