]> git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
fixed wxString char<->wchar_t conversion constructors to not truncate strings and...
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #include "wx/bitmap.h"
38 #include "wx/log.h"
39 #endif
40
41 #include "wx/msw/private.h"
42
43 // ----------------------------------------------------------------------------
44 // wxWin macros
45 // ----------------------------------------------------------------------------
46
47 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // wxIconRefData
55 // ----------------------------------------------------------------------------
56
57 void wxIconRefData::Free()
58 {
59 if ( m_hIcon )
60 {
61 #ifndef __WXMICROWIN__
62 ::DestroyIcon((HICON) m_hIcon);
63 #endif
64
65 m_hIcon = 0;
66 }
67 }
68
69 // ----------------------------------------------------------------------------
70 // wxIcon
71 // ----------------------------------------------------------------------------
72
73 wxIcon::wxIcon(const char bits[], int width, int height)
74 {
75 wxBitmap bmp(bits, width, height);
76 CopyFromBitmap(bmp);
77 }
78
79 wxIcon::wxIcon(const wxString& iconfile,
80 long flags,
81 int desiredWidth,
82 int desiredHeight)
83
84 {
85 LoadFile(iconfile, flags, desiredWidth, desiredHeight);
86 }
87
88 wxIcon::wxIcon(const wxIconLocation& loc)
89 {
90 // wxICOFileHandler accepts names in the format "filename;index"
91 wxString fullname = loc.GetFileName();
92 if ( loc.GetIndex() )
93 {
94 fullname << _T(';') << loc.GetIndex();
95 }
96 //else: 0 is default
97
98 LoadFile(fullname, wxBITMAP_TYPE_ICO);
99 }
100
101 wxIcon::~wxIcon()
102 {
103 }
104
105 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
106 {
107 #ifndef __WXMICROWIN__
108 HICON hicon = wxBitmapToHICON(bmp);
109 if ( !hicon )
110 {
111 wxLogLastError(wxT("CreateIconIndirect"));
112 }
113 else
114 {
115 SetHICON((WXHICON)hicon);
116 SetSize(bmp.GetWidth(), bmp.GetHeight());
117 }
118 #endif // __WXMICROWIN__
119 }
120
121 void wxIcon::CreateIconFromXpm(const char **data)
122 {
123 wxBitmap bmp(data);
124 CopyFromBitmap(bmp);
125 }
126
127 bool wxIcon::LoadFile(const wxString& filename,
128 long type,
129 int desiredWidth, int desiredHeight)
130 {
131 UnRef();
132
133 wxGDIImageHandler *handler = FindHandler(type);
134
135 if ( !handler )
136 {
137 // say something?
138 return FALSE;
139 }
140
141 return handler->Load(this, filename, type, desiredWidth, desiredHeight);
142 }
143