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