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