]>
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" |
c801d85f KB |
24 | |
25 | //----------------------------------------------------------------------------- | |
26 | // wxImageList | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) | |
30 | ||
f6bcfd97 | 31 | wxImageList::wxImageList( int width, int height, bool mask, int initialCount ) |
c801d85f | 32 | { |
f6bcfd97 | 33 | (void)Create(width, height, mask, initialCount); |
e1e955e1 | 34 | } |
c801d85f | 35 | |
0423b685 | 36 | wxImageList::~wxImageList() |
c801d85f | 37 | { |
e1e955e1 | 38 | } |
c801d85f | 39 | |
0423b685 | 40 | int wxImageList::GetImageCount() const |
c801d85f | 41 | { |
b46e8696 | 42 | return m_images.Number(); |
e1e955e1 | 43 | } |
c801d85f | 44 | |
f6bcfd97 BP |
45 | bool wxImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) |
46 | { | |
47 | m_width = width; | |
48 | m_height = height; | |
49 | ||
50 | return Create(); | |
51 | } | |
52 | ||
0423b685 | 53 | bool wxImageList::Create() |
c801d85f | 54 | { |
b46e8696 RR |
55 | m_images.DeleteContents( TRUE ); |
56 | return TRUE; | |
e1e955e1 | 57 | } |
c801d85f KB |
58 | |
59 | int wxImageList::Add( const wxBitmap &bitmap ) | |
60 | { | |
f60d0f94 JS |
61 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) |
62 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
63 | else | |
64 | m_images.Append( new wxBitmap(bitmap) ); | |
b00c5607 | 65 | return m_images.Number()-1; |
e1e955e1 | 66 | } |
c801d85f | 67 | |
4d449473 VS |
68 | int wxImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) |
69 | { | |
70 | wxBitmap bmp(bitmap); | |
a7f1fbf6 RD |
71 | if (mask.Ok()) |
72 | bmp.SetMask(new wxMask(mask)); | |
4d449473 VS |
73 | return Add(bmp); |
74 | } | |
75 | ||
76 | int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour ) | |
77 | { | |
368d59f0 | 78 | wxImage img = bitmap.ConvertToImage(); |
4d449473 | 79 | img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue()); |
368d59f0 | 80 | return Add(wxBitmap(img)); |
4d449473 VS |
81 | } |
82 | ||
43543d98 | 83 | const wxBitmap *wxImageList::GetBitmap( int index ) const |
b46e8696 RR |
84 | { |
85 | wxNode *node = m_images.Nth( index ); | |
43543d98 | 86 | |
223d09f6 | 87 | wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") ); |
43543d98 | 88 | |
8b21b87f | 89 | return (wxBitmap*)node->Data(); |
40413a5b | 90 | } |
43543d98 | 91 | |
0423b685 | 92 | bool wxImageList::Replace( int index, const wxBitmap &bitmap ) |
c801d85f | 93 | { |
b46e8696 | 94 | wxNode *node = m_images.Nth( index ); |
43543d98 | 95 | |
223d09f6 | 96 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
f60d0f94 JS |
97 | |
98 | wxBitmap* newBitmap = NULL; | |
99 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) | |
43543d98 DW |
100 | #if defined(__VISAGECPP__) |
101 | //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff | |
102 | //so construct it from a bitmap object until I can figure this nonsense out. (DW) | |
103 | newBitmap = new wxBitmap(bitmap) ; | |
104 | #else | |
8f177c8e | 105 | newBitmap = new wxBitmap( (const wxIcon&) bitmap ); |
43543d98 | 106 | #endif |
f60d0f94 JS |
107 | else |
108 | newBitmap = new wxBitmap(bitmap) ; | |
109 | ||
b46e8696 RR |
110 | if (index == m_images.Number()-1) |
111 | { | |
112 | m_images.DeleteNode( node ); | |
f60d0f94 | 113 | m_images.Append( newBitmap ); |
b46e8696 RR |
114 | } |
115 | else | |
116 | { | |
117 | wxNode *next = node->Next(); | |
118 | m_images.DeleteNode( node ); | |
f60d0f94 | 119 | m_images.Insert( next, newBitmap ); |
b46e8696 | 120 | } |
43543d98 | 121 | |
b46e8696 | 122 | return TRUE; |
e1e955e1 | 123 | } |
c801d85f | 124 | |
0423b685 | 125 | bool wxImageList::Remove( int index ) |
c801d85f | 126 | { |
b46e8696 | 127 | wxNode *node = m_images.Nth( index ); |
43543d98 | 128 | |
223d09f6 | 129 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 130 | |
b46e8696 | 131 | m_images.DeleteNode( node ); |
43543d98 | 132 | |
b46e8696 | 133 | return TRUE; |
e1e955e1 | 134 | } |
c801d85f | 135 | |
0423b685 | 136 | bool wxImageList::RemoveAll() |
c801d85f | 137 | { |
b46e8696 | 138 | m_images.Clear(); |
43543d98 | 139 | |
b46e8696 | 140 | return TRUE; |
e1e955e1 | 141 | } |
c801d85f | 142 | |
0423b685 | 143 | bool wxImageList::GetSize( int index, int &width, int &height ) const |
c801d85f | 144 | { |
b46e8696 RR |
145 | width = 0; |
146 | height = 0; | |
43543d98 | 147 | |
b46e8696 | 148 | wxNode *node = m_images.Nth( index ); |
43543d98 | 149 | |
223d09f6 | 150 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 151 | |
c801d85f KB |
152 | wxBitmap *bm = (wxBitmap*)node->Data(); |
153 | width = bm->GetWidth(); | |
154 | height = bm->GetHeight(); | |
43543d98 | 155 | |
c801d85f | 156 | return TRUE; |
e1e955e1 | 157 | } |
c801d85f | 158 | |
219f895a RR |
159 | bool wxImageList::Draw( int index, wxDC &dc, int x, int y, |
160 | int flags, bool WXUNUSED(solidBackground) ) | |
c801d85f | 161 | { |
b46e8696 | 162 | wxNode *node = m_images.Nth( index ); |
43543d98 | 163 | |
223d09f6 | 164 | wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") ); |
43543d98 | 165 | |
b46e8696 | 166 | wxBitmap *bm = (wxBitmap*)node->Data(); |
f60d0f94 JS |
167 | |
168 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
169 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
170 | else | |
171 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
219f895a | 172 | |
b46e8696 | 173 | return TRUE; |
e1e955e1 | 174 | } |
c801d85f KB |
175 | |
176 |