]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/generic/imaglist.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
01111366 RR |
5 | // Id: $id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
1e6d9499 JS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
93763ad5 | 14 | #pragma hdrstop |
1e6d9499 JS |
15 | #endif |
16 | ||
93763ad5 | 17 | #if wxUSE_IMAGLIST |
9de05dfd | 18 | |
4055ed82 | 19 | #ifndef __WXPALMOS__ |
9de05dfd | 20 | |
f60d0f94 | 21 | #include "wx/generic/imaglist.h" |
9de05dfd | 22 | |
64698f9a | 23 | #include "wx/icon.h" |
4d449473 | 24 | #include "wx/image.h" |
00dd3b18 | 25 | #include "wx/dc.h" |
c801d85f KB |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // wxImageList | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
3cd94a0d | 31 | IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject) |
c801d85f | 32 | |
3a5bcc4d | 33 | #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) |
b31989e2 JS |
34 | /* |
35 | * wxImageList has to be a real class or we have problems with | |
36 | * the run-time information. | |
37 | */ | |
38 | ||
39 | IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList) | |
40 | #endif | |
41 | ||
3cd94a0d | 42 | wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount ) |
c801d85f | 43 | { |
f6bcfd97 | 44 | (void)Create(width, height, mask, initialCount); |
e1e955e1 | 45 | } |
c801d85f | 46 | |
3cd94a0d | 47 | wxGenericImageList::~wxGenericImageList() |
c801d85f | 48 | { |
3fc93ebd | 49 | (void)RemoveAll(); |
e1e955e1 | 50 | } |
c801d85f | 51 | |
3cd94a0d | 52 | int wxGenericImageList::GetImageCount() const |
c801d85f | 53 | { |
b1d4dd7a | 54 | return m_images.GetCount(); |
e1e955e1 | 55 | } |
c801d85f | 56 | |
3cd94a0d | 57 | bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) |
f6bcfd97 BP |
58 | { |
59 | m_width = width; | |
60 | m_height = height; | |
61 | ||
62 | return Create(); | |
63 | } | |
64 | ||
3cd94a0d | 65 | bool wxGenericImageList::Create() |
c801d85f | 66 | { |
ca65c044 | 67 | return true; |
e1e955e1 | 68 | } |
c801d85f | 69 | |
3cd94a0d | 70 | int wxGenericImageList::Add( const wxBitmap &bitmap ) |
c801d85f | 71 | { |
b931414d RD |
72 | wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height) |
73 | || (m_width == 0 && m_height == 0), | |
9bd41907 VZ |
74 | _T("invalid bitmap size in wxImageList: this might work ") |
75 | _T("on this platform but definitely won't under Windows.") ); | |
76 | ||
f60d0f94 JS |
77 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) |
78 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
79 | else | |
80 | m_images.Append( new wxBitmap(bitmap) ); | |
b931414d RD |
81 | |
82 | if (m_width == 0 && m_height == 0) | |
83 | { | |
84 | m_width = bitmap.GetWidth(); | |
85 | m_height = bitmap.GetHeight(); | |
86 | } | |
93763ad5 | 87 | |
b1d4dd7a | 88 | return m_images.GetCount()-1; |
e1e955e1 | 89 | } |
c801d85f | 90 | |
3cd94a0d | 91 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) |
4d449473 VS |
92 | { |
93 | wxBitmap bmp(bitmap); | |
a7f1fbf6 RD |
94 | if (mask.Ok()) |
95 | bmp.SetMask(new wxMask(mask)); | |
4d449473 VS |
96 | return Add(bmp); |
97 | } | |
98 | ||
3cd94a0d | 99 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour ) |
4d449473 | 100 | { |
368d59f0 | 101 | wxImage img = bitmap.ConvertToImage(); |
4d449473 | 102 | img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue()); |
368d59f0 | 103 | return Add(wxBitmap(img)); |
4d449473 VS |
104 | } |
105 | ||
49bf4e3e | 106 | const wxBitmap *wxGenericImageList::GetBitmapPtr( int index ) const |
b46e8696 | 107 | { |
222ed1d6 | 108 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 109 | |
223d09f6 | 110 | wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") ); |
43543d98 | 111 | |
b1d4dd7a | 112 | return (wxBitmap*)node->GetData(); |
40413a5b | 113 | } |
43543d98 | 114 | |
49bf4e3e | 115 | // Get the bitmap |
f45fac95 | 116 | wxBitmap wxGenericImageList::GetBitmap(int index) const |
49bf4e3e JS |
117 | { |
118 | const wxBitmap* bmp = GetBitmapPtr(index); | |
119 | if (bmp) | |
120 | return *bmp; | |
121 | else | |
122 | return wxNullBitmap; | |
123 | } | |
124 | ||
125 | // Get the icon | |
f45fac95 | 126 | wxIcon wxGenericImageList::GetIcon(int index) const |
49bf4e3e JS |
127 | { |
128 | const wxBitmap* bmp = GetBitmapPtr(index); | |
129 | if (bmp) | |
130 | { | |
131 | wxIcon icon; | |
132 | icon.CopyFromBitmap(*bmp); | |
133 | return icon; | |
134 | } | |
135 | else | |
136 | return wxNullIcon; | |
137 | } | |
138 | ||
3cd94a0d | 139 | bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap ) |
c801d85f | 140 | { |
222ed1d6 | 141 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 142 | |
ca65c044 | 143 | wxCHECK_MSG( node, false, wxT("wrong index in image list") ); |
f60d0f94 | 144 | |
999836aa VZ |
145 | wxBitmap* newBitmap = (bitmap.IsKindOf(CLASSINFO(wxIcon))) ? |
146 | #if defined(__VISAGECPP__) | |
147 | //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff | |
148 | //so construct it from a bitmap object until I can figure this nonsense out. (DW) | |
149 | new wxBitmap(bitmap) | |
150 | #else | |
151 | new wxBitmap( (const wxIcon&) bitmap ) | |
152 | #endif | |
153 | : new wxBitmap(bitmap) ; | |
f60d0f94 | 154 | |
b1d4dd7a | 155 | if (index == (int) m_images.GetCount() - 1) |
b46e8696 | 156 | { |
222ed1d6 MB |
157 | delete node->GetData(); |
158 | m_images.Erase( node ); | |
f60d0f94 | 159 | m_images.Append( newBitmap ); |
b46e8696 RR |
160 | } |
161 | else | |
162 | { | |
222ed1d6 MB |
163 | wxList::compatibility_iterator next = node->GetNext(); |
164 | delete node->GetData(); | |
165 | m_images.Erase( node ); | |
f60d0f94 | 166 | m_images.Insert( next, newBitmap ); |
b46e8696 | 167 | } |
43543d98 | 168 | |
ca65c044 | 169 | return true; |
e1e955e1 | 170 | } |
c801d85f | 171 | |
3cd94a0d | 172 | bool wxGenericImageList::Remove( int index ) |
c801d85f | 173 | { |
222ed1d6 | 174 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 175 | |
ca65c044 | 176 | wxCHECK_MSG( node, false, wxT("wrong index in image list") ); |
43543d98 | 177 | |
222ed1d6 MB |
178 | delete node->GetData(); |
179 | m_images.Erase( node ); | |
43543d98 | 180 | |
ca65c044 | 181 | return true; |
e1e955e1 | 182 | } |
c801d85f | 183 | |
3cd94a0d | 184 | bool wxGenericImageList::RemoveAll() |
c801d85f | 185 | { |
222ed1d6 | 186 | WX_CLEAR_LIST(wxList, m_images); |
b46e8696 | 187 | m_images.Clear(); |
43543d98 | 188 | |
ca65c044 | 189 | return true; |
e1e955e1 | 190 | } |
c801d85f | 191 | |
3cd94a0d | 192 | bool wxGenericImageList::GetSize( int index, int &width, int &height ) const |
c801d85f | 193 | { |
b46e8696 RR |
194 | width = 0; |
195 | height = 0; | |
43543d98 | 196 | |
222ed1d6 | 197 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 198 | |
ca65c044 | 199 | wxCHECK_MSG( node, false, wxT("wrong index in image list") ); |
43543d98 | 200 | |
b1d4dd7a | 201 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
c801d85f KB |
202 | width = bm->GetWidth(); |
203 | height = bm->GetHeight(); | |
43543d98 | 204 | |
ca65c044 | 205 | return true; |
e1e955e1 | 206 | } |
c801d85f | 207 | |
3cd94a0d | 208 | bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y, |
219f895a | 209 | int flags, bool WXUNUSED(solidBackground) ) |
c801d85f | 210 | { |
222ed1d6 | 211 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 212 | |
ca65c044 | 213 | wxCHECK_MSG( node, false, wxT("wrong index in image list") ); |
43543d98 | 214 | |
b1d4dd7a | 215 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
f60d0f94 JS |
216 | |
217 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
218 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
219 | else | |
220 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
219f895a | 221 | |
ca65c044 | 222 | return true; |
e1e955e1 | 223 | } |
c801d85f | 224 | |
58c5c7ec | 225 | #endif // wxUSE_IMAGLIST |
4055ed82 | 226 | #endif // __WXPALMOS__ |