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