]>
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 | ||
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 | ||
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 | { |
9bd41907 VZ |
70 | wxASSERT_MSG( bitmap.GetWidth() == m_width && |
71 | bitmap.GetHeight() == m_height, | |
72 | _T("invalid bitmap size in wxImageList: this might work ") | |
73 | _T("on this platform but definitely won't under Windows.") ); | |
74 | ||
f60d0f94 JS |
75 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) |
76 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
77 | else | |
78 | m_images.Append( new wxBitmap(bitmap) ); | |
b1d4dd7a | 79 | return m_images.GetCount()-1; |
e1e955e1 | 80 | } |
c801d85f | 81 | |
3cd94a0d | 82 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) |
4d449473 VS |
83 | { |
84 | wxBitmap bmp(bitmap); | |
a7f1fbf6 RD |
85 | if (mask.Ok()) |
86 | bmp.SetMask(new wxMask(mask)); | |
4d449473 VS |
87 | return Add(bmp); |
88 | } | |
89 | ||
3cd94a0d | 90 | int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour ) |
4d449473 | 91 | { |
368d59f0 | 92 | wxImage img = bitmap.ConvertToImage(); |
4d449473 | 93 | img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue()); |
368d59f0 | 94 | return Add(wxBitmap(img)); |
4d449473 VS |
95 | } |
96 | ||
3cd94a0d | 97 | const wxBitmap *wxGenericImageList::GetBitmap( int index ) const |
b46e8696 | 98 | { |
222ed1d6 | 99 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 100 | |
223d09f6 | 101 | wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") ); |
43543d98 | 102 | |
b1d4dd7a | 103 | return (wxBitmap*)node->GetData(); |
40413a5b | 104 | } |
43543d98 | 105 | |
3cd94a0d | 106 | bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap ) |
c801d85f | 107 | { |
222ed1d6 | 108 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 109 | |
223d09f6 | 110 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
f60d0f94 | 111 | |
999836aa VZ |
112 | wxBitmap* newBitmap = (bitmap.IsKindOf(CLASSINFO(wxIcon))) ? |
113 | #if defined(__VISAGECPP__) | |
114 | //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff | |
115 | //so construct it from a bitmap object until I can figure this nonsense out. (DW) | |
116 | new wxBitmap(bitmap) | |
117 | #else | |
118 | new wxBitmap( (const wxIcon&) bitmap ) | |
119 | #endif | |
120 | : new wxBitmap(bitmap) ; | |
f60d0f94 | 121 | |
b1d4dd7a | 122 | if (index == (int) m_images.GetCount() - 1) |
b46e8696 | 123 | { |
222ed1d6 MB |
124 | delete node->GetData(); |
125 | m_images.Erase( node ); | |
f60d0f94 | 126 | m_images.Append( newBitmap ); |
b46e8696 RR |
127 | } |
128 | else | |
129 | { | |
222ed1d6 MB |
130 | wxList::compatibility_iterator next = node->GetNext(); |
131 | delete node->GetData(); | |
132 | m_images.Erase( node ); | |
f60d0f94 | 133 | m_images.Insert( next, newBitmap ); |
b46e8696 | 134 | } |
43543d98 | 135 | |
b46e8696 | 136 | return TRUE; |
e1e955e1 | 137 | } |
c801d85f | 138 | |
3cd94a0d | 139 | bool wxGenericImageList::Remove( int index ) |
c801d85f | 140 | { |
222ed1d6 | 141 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 142 | |
223d09f6 | 143 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 144 | |
222ed1d6 MB |
145 | delete node->GetData(); |
146 | m_images.Erase( node ); | |
43543d98 | 147 | |
b46e8696 | 148 | return TRUE; |
e1e955e1 | 149 | } |
c801d85f | 150 | |
3cd94a0d | 151 | bool wxGenericImageList::RemoveAll() |
c801d85f | 152 | { |
222ed1d6 | 153 | WX_CLEAR_LIST(wxList, m_images); |
b46e8696 | 154 | m_images.Clear(); |
43543d98 | 155 | |
b46e8696 | 156 | return TRUE; |
e1e955e1 | 157 | } |
c801d85f | 158 | |
3cd94a0d | 159 | bool wxGenericImageList::GetSize( int index, int &width, int &height ) const |
c801d85f | 160 | { |
b46e8696 RR |
161 | width = 0; |
162 | height = 0; | |
43543d98 | 163 | |
222ed1d6 | 164 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 165 | |
223d09f6 | 166 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 167 | |
b1d4dd7a | 168 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
c801d85f KB |
169 | width = bm->GetWidth(); |
170 | height = bm->GetHeight(); | |
43543d98 | 171 | |
c801d85f | 172 | return TRUE; |
e1e955e1 | 173 | } |
c801d85f | 174 | |
3cd94a0d | 175 | bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y, |
219f895a | 176 | int flags, bool WXUNUSED(solidBackground) ) |
c801d85f | 177 | { |
222ed1d6 | 178 | wxList::compatibility_iterator node = m_images.Item( index ); |
43543d98 | 179 | |
223d09f6 | 180 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 181 | |
b1d4dd7a | 182 | wxBitmap *bm = (wxBitmap*)node->GetData(); |
f60d0f94 JS |
183 | |
184 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
185 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
186 | else | |
187 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
219f895a | 188 | |
b46e8696 | 189 | return TRUE; |
e1e955e1 | 190 | } |
c801d85f KB |
191 | |
192 |