]> git.saurik.com Git - wxWidgets.git/blame - src/msw/imaglist.cpp
Added test for wxUSE_STATLINE in statline.cpp
[wxWidgets.git] / src / msw / imaglist.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: imaglist.cpp
3// Purpose: wxImageList
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "imaglist.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#if defined(__WIN95__)
24
25#ifndef WX_PRECOMP
26#include <stdio.h>
27#include "wx/setup.h"
28#include "wx/window.h"
0c589ad0
BM
29#include "wx/icon.h"
30#include "wx/dc.h"
31#include "wx/string.h"
2bda0e17
KB
32#endif
33
ce3ed50d
JS
34#include "wx/log.h"
35#include "wx/intl.h"
36
2bda0e17
KB
37#include "wx/msw/imaglist.h"
38#include "wx/msw/private.h"
39
57c208c5 40#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
2bda0e17
KB
41#include <commctrl.h>
42#endif
43
44#if !USE_SHARED_LIBRARY
45IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
46#endif
47
48wxImageList::wxImageList(void)
49{
50 m_hImageList = 0;
51}
52
53wxImageList::~wxImageList(void)
54{
55 if ( m_hImageList )
56 ImageList_Destroy((HIMAGELIST) m_hImageList);
57 m_hImageList = 0;
58}
59
60
61// Attributes
62////////////////////////////////////////////////////////////////////////////
63
64// Returns the number of images in the image list.
65int wxImageList::GetImageCount(void) const
66{
67 return ImageList_GetImageCount((HIMAGELIST) m_hImageList);
68}
69
70// Operations
71////////////////////////////////////////////////////////////////////////////
72
73// Creates an image list
debe6624 74bool wxImageList::Create(int width, int height, bool mask, int initial)
2bda0e17
KB
75{
76 UINT flags = 0;
77 if ( mask )
78 flags |= ILC_MASK;
79
80 // Grow by 1, I guess this is reasonable behaviour most of the time
81 m_hImageList = (WXHIMAGELIST) ImageList_Create(width, height, flags, initial, 1);
82 return (m_hImageList != 0);
83}
84
85// Adds a bitmap, and optionally a mask bitmap.
86// Note that wxImageList creates new bitmaps, so you may delete
87// 'bitmap' and 'mask'.
88int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
89{
90 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
91 HBITMAP hBitmap2 = 0;
92 if ( mask.Ok() )
93 hBitmap2 = (HBITMAP) mask.GetHBITMAP();
e29b83a4
VZ
94
95 int index = ImageList_Add((HIMAGELIST) GetHIMAGELIST(), hBitmap1, hBitmap2);
96 if ( index == -1 )
97 {
98 wxLogError(_("Couldn't add an image to the image list."));
99 }
100
101 return index;
2bda0e17
KB
102}
103
104// Adds a bitmap, using the specified colour to create the mask bitmap
105// Note that wxImageList creates new bitmaps, so you may delete
106// 'bitmap'.
107int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
108{
57c208c5
JS
109#ifdef __TWIN32__
110 wxFAIL_MSG("ImageList_AddMasked not implemented in TWIN32");
111 return -1;
112#else
2bda0e17
KB
113 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
114 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
115 return ImageList_AddMasked((HIMAGELIST) GetHIMAGELIST(), hBitmap1, colorRef);
57c208c5 116#endif
2bda0e17
KB
117}
118
119// Adds a bitmap and mask from an icon.
120int wxImageList::Add(const wxIcon& icon)
121{
122 HICON hIcon = (HICON) icon.GetHICON();
123 return ImageList_AddIcon((HIMAGELIST) GetHIMAGELIST(), hIcon);
124}
125
126// Replaces a bitmap, optionally passing a mask bitmap.
127// Note that wxImageList creates new bitmaps, so you may delete
128// 'bitmap' and 'mask'.
debe6624 129bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask)
2bda0e17 130{
57c208c5
JS
131#ifdef __TWIN32__
132 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
133 return FALSE;
134#else
2bda0e17
KB
135 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
136 HBITMAP hBitmap2 = 0;
137 if ( mask.Ok() )
138 hBitmap2 = (HBITMAP) mask.GetHBITMAP();
139 return (ImageList_Replace((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, hBitmap2) != 0);
57c208c5 140#endif
2bda0e17
KB
141}
142
143/* Not supported by Win95
144// Replacing a bitmap, using the specified colour to create the mask bitmap
145// Note that wxImageList creates new bitmaps, so you may delete
146// 'bitmap'.
debe6624 147bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
2bda0e17
KB
148{
149 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
150 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
151 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
152}
153*/
154
155// Replaces a bitmap and mask from an icon.
debe6624 156bool wxImageList::Replace(int index, const wxIcon& icon)
2bda0e17
KB
157{
158 HICON hIcon = (HICON) icon.GetHICON();
159 return (ImageList_ReplaceIcon((HIMAGELIST) GetHIMAGELIST(), index, hIcon) != 0);
160}
161
162// Removes the image at the given index.
debe6624 163bool wxImageList::Remove(int index)
2bda0e17 164{
57c208c5
JS
165#ifdef __TWIN32__
166 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
167 return FALSE;
168#else
2bda0e17 169 return (ImageList_Remove((HIMAGELIST) GetHIMAGELIST(), index) != 0);
57c208c5 170#endif
2bda0e17
KB
171}
172
173// Remove all images
174bool wxImageList::RemoveAll(void)
175{
176 // TODO: Is this correct?
177 while ( GetImageCount() > 0 )
178 {
179 Remove(0);
180 }
181 return TRUE;
182}
183
184// Draws the given image on a dc at the specified position.
185// If 'solidBackground' is TRUE, Draw sets the image list background
186// colour to the background colour of the wxDC, to speed up
187// drawing by eliminating masked drawing where possible.
debe6624
JS
188bool wxImageList::Draw(int index, wxDC& dc, int x, int y,
189 int flags, bool solidBackground)
2bda0e17 190{
57c208c5
JS
191#ifdef __TWIN32__
192 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
193 return FALSE;
194#else
2bda0e17
KB
195 HDC hDC = (HDC) dc.GetHDC();
196 if ( !hDC )
197 return FALSE;
198
199 if ( solidBackground )
200 {
c0ed460c 201 wxBrush *brush = & dc.GetBackground();
2bda0e17
KB
202 if ( brush && brush->Ok())
203 {
204 wxColour col(brush->GetColour());
205 ImageList_SetBkColor((HIMAGELIST) GetHIMAGELIST(),
206 PALETTERGB(col.Red(), col.Green(), col.Blue()));
207 }
208 else
209 ImageList_SetBkColor((HIMAGELIST) GetHIMAGELIST(),
210 CLR_NONE);
211 }
212 else
213 ImageList_SetBkColor((HIMAGELIST) GetHIMAGELIST(),
214 CLR_NONE);
215
216 UINT style = 0;
217 if ( flags & wxIMAGELIST_DRAW_NORMAL )
218 style |= ILD_NORMAL;
219 if ( flags & wxIMAGELIST_DRAW_TRANSPARENT )
220 style |= ILD_TRANSPARENT;
221 if ( flags & wxIMAGELIST_DRAW_SELECTED )
222 style |= ILD_SELECTED;
223 if ( flags & wxIMAGELIST_DRAW_FOCUSED )
224 style |= ILD_FOCUS;
225
226 return (ImageList_Draw((HIMAGELIST) GetHIMAGELIST(), index, hDC,
227 x, y, style) != 0);
57c208c5 228#endif
2bda0e17
KB
229}
230
231#endif
232