]>
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 | |
f6bcfd97 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
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 | ||
f60d0f94 | 21 | #include "wx/generic/imaglist.h" |
64698f9a | 22 | #include "wx/icon.h" |
4d449473 | 23 | #include "wx/image.h" |
00dd3b18 | 24 | #include "wx/dc.h" |
c801d85f KB |
25 | |
26 | //----------------------------------------------------------------------------- | |
27 | // wxImageList | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
3cd94a0d | 30 | IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject) |
c801d85f | 31 | |
b31989e2 JS |
32 | #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__) |
33 | /* | |
34 | * wxImageList has to be a real class or we have problems with | |
35 | * the run-time information. | |
36 | */ | |
37 | ||
38 | IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList) | |
39 | #endif | |
40 | ||
3cd94a0d | 41 | wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount ) |
c801d85f | 42 | { |
f6bcfd97 | 43 | (void)Create(width, height, mask, initialCount); |
e1e955e1 | 44 | } |
c801d85f | 45 | |
3cd94a0d | 46 | wxGenericImageList::~wxGenericImageList() |
c801d85f | 47 | { |
e1e955e1 | 48 | } |
c801d85f | 49 | |
3cd94a0d | 50 | int wxGenericImageList::GetImageCount() const |
c801d85f | 51 | { |
b1d4dd7a | 52 | return m_images.GetCount(); |
e1e955e1 | 53 | } |
c801d85f | 54 | |
3cd94a0d | 55 | bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) |
f6bcfd97 BP |
56 | { |
57 | m_width = width; | |
58 | m_height = height; | |
59 | ||
60 | return Create(); | |
61 | } | |
62 | ||
3cd94a0d | 63 | bool wxGenericImageList::Create() |
c801d85f | 64 | { |
b46e8696 | 65 | return TRUE; |
e1e955e1 | 66 | } |
c801d85f | 67 | |
3cd94a0d | 68 | int wxGenericImageList::Add( const wxBitmap &bitmap ) |
c801d85f | 69 | { |
f60d0f94 JS |
70 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) |
71 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
72 | else | |
73 | m_images.Append( new wxBitmap(bitmap) ); | |
b1d4dd7a | 74 | return m_images.GetCount()-1; |
e1e955e1 | 75 | } |
c801d85f | 76 | |
3cd94a0d | 77 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) |
4d449473 VS |
78 | { |
79 | wxBitmap bmp(bitmap); | |
a7f1fbf6 RD |
80 | if (mask.Ok()) |
81 | bmp.SetMask(new wxMask(mask)); | |
4d449473 VS |
82 | return Add(bmp); |
83 | } | |
84 | ||
3cd94a0d | 85 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour ) |
4d449473 | 86 | { |
368d59f0 | 87 | wxImage img = bitmap.ConvertToImage(); |
4d449473 | 88 | img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue()); |
368d59f0 | 89 | return Add(wxBitmap(img)); |
4d449473 VS |
90 | } |
91 | ||
3cd94a0d | 92 | const wxBitmap *wxGenericImageList::GetBitmap( int index ) const |
b46e8696 | 93 | { |
222ed1d6 | 94 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 95 | |
223d09f6 | 96 | wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") ); |
43543d98 | 97 | |
b1d4dd7a | 98 | return (wxBitmap*)node->GetData(); |
40413a5b | 99 | } |
43543d98 | 100 | |
3cd94a0d | 101 | bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap ) |
c801d85f | 102 | { |
222ed1d6 | 103 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 104 | |
223d09f6 | 105 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
f60d0f94 JS |
106 | |
107 | wxBitmap* newBitmap = NULL; | |
108 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) | |
43543d98 DW |
109 | #if defined(__VISAGECPP__) |
110 | //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff | |
111 | //so construct it from a bitmap object until I can figure this nonsense out. (DW) | |
112 | newBitmap = new wxBitmap(bitmap) ; | |
113 | #else | |
8f177c8e | 114 | newBitmap = new wxBitmap( (const wxIcon&) bitmap ); |
43543d98 | 115 | #endif |
f60d0f94 JS |
116 | else |
117 | newBitmap = new wxBitmap(bitmap) ; | |
118 | ||
b1d4dd7a | 119 | if (index == (int) m_images.GetCount() - 1) |
b46e8696 | 120 | { |
222ed1d6 MB |
121 | delete node->GetData(); |
122 | m_images.Erase( node ); | |
f60d0f94 | 123 | m_images.Append( newBitmap ); |
b46e8696 RR |
124 | } |
125 | else | |
126 | { | |
222ed1d6 MB |
127 | wxList::compatibility_iterator next = node->GetNext(); |
128 | delete node->GetData(); | |
129 | m_images.Erase( node ); | |
f60d0f94 | 130 | m_images.Insert( next, newBitmap ); |
b46e8696 | 131 | } |
43543d98 | 132 | |
b46e8696 | 133 | return TRUE; |
e1e955e1 | 134 | } |
c801d85f | 135 | |
3cd94a0d | 136 | bool wxGenericImageList::Remove( int index ) |
c801d85f | 137 | { |
222ed1d6 | 138 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 139 | |
223d09f6 | 140 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 141 | |
222ed1d6 MB |
142 | delete node->GetData(); |
143 | m_images.Erase( node ); | |
43543d98 | 144 | |
b46e8696 | 145 | return TRUE; |
e1e955e1 | 146 | } |
c801d85f | 147 | |
3cd94a0d | 148 | bool wxGenericImageList::RemoveAll() |
c801d85f | 149 | { |
222ed1d6 | 150 | WX_CLEAR_LIST(wxList, m_images); |
b46e8696 | 151 | m_images.Clear(); |
43543d98 | 152 | |
b46e8696 | 153 | return TRUE; |
e1e955e1 | 154 | } |
c801d85f | 155 | |
3cd94a0d | 156 | bool wxGenericImageList::GetSize( int index, int &width, int &height ) const |
c801d85f | 157 | { |
b46e8696 RR |
158 | width = 0; |
159 | height = 0; | |
43543d98 | 160 | |
222ed1d6 | 161 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 162 | |
223d09f6 | 163 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 164 | |
b1d4dd7a | 165 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
c801d85f KB |
166 | width = bm->GetWidth(); |
167 | height = bm->GetHeight(); | |
43543d98 | 168 | |
c801d85f | 169 | return TRUE; |
e1e955e1 | 170 | } |
c801d85f | 171 | |
3cd94a0d | 172 | bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y, |
219f895a | 173 | int flags, bool WXUNUSED(solidBackground) ) |
c801d85f | 174 | { |
222ed1d6 | 175 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 176 | |
223d09f6 | 177 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 178 | |
b1d4dd7a | 179 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
f60d0f94 JS |
180 | |
181 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
182 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
183 | else | |
184 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
219f895a | 185 | |
b46e8696 | 186 | return TRUE; |
e1e955e1 | 187 | } |
c801d85f KB |
188 | |
189 |