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