]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: imaglist.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
01111366 RR |
5 | // Id: $id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
c801d85f KB |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "imaglist.h" | |
12 | #endif | |
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" |
c801d85f KB |
22 | |
23 | //----------------------------------------------------------------------------- | |
24 | // wxImageList | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
27 | IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) | |
28 | ||
219f895a | 29 | wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) ) |
c801d85f | 30 | { |
b46e8696 RR |
31 | m_width = width; |
32 | m_height = height; | |
33 | Create(); | |
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 | |
0423b685 | 45 | bool wxImageList::Create() |
c801d85f | 46 | { |
b46e8696 RR |
47 | m_images.DeleteContents( TRUE ); |
48 | return TRUE; | |
e1e955e1 | 49 | } |
c801d85f KB |
50 | |
51 | int wxImageList::Add( const wxBitmap &bitmap ) | |
52 | { | |
f60d0f94 JS |
53 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) |
54 | m_images.Append( new wxIcon( (const wxIcon&) bitmap ) ); | |
55 | else | |
56 | m_images.Append( new wxBitmap(bitmap) ); | |
b46e8696 | 57 | return m_images.Number(); |
e1e955e1 | 58 | } |
c801d85f | 59 | |
b46e8696 RR |
60 | const wxBitmap *wxImageList::GetBitmap( int index ) const |
61 | { | |
62 | wxNode *node = m_images.Nth( index ); | |
63 | ||
87138c52 | 64 | wxCHECK_MSG( node, (wxBitmap *) NULL, _T("wrong index in image list") ); |
b46e8696 | 65 | |
8b21b87f | 66 | return (wxBitmap*)node->Data(); |
40413a5b DP |
67 | } |
68 | ||
0423b685 | 69 | bool wxImageList::Replace( int index, const wxBitmap &bitmap ) |
c801d85f | 70 | { |
b46e8696 RR |
71 | wxNode *node = m_images.Nth( index ); |
72 | ||
87138c52 | 73 | wxCHECK_MSG( node, FALSE, _T("wrong index in image list") ); |
f60d0f94 JS |
74 | |
75 | wxBitmap* newBitmap = NULL; | |
76 | if (bitmap.IsKindOf(CLASSINFO(wxIcon))) | |
77 | newBitmap = new wxIcon( (const wxIcon&) bitmap ); | |
78 | else | |
79 | newBitmap = new wxBitmap(bitmap) ; | |
80 | ||
b46e8696 RR |
81 | if (index == m_images.Number()-1) |
82 | { | |
83 | m_images.DeleteNode( node ); | |
f60d0f94 | 84 | m_images.Append( newBitmap ); |
b46e8696 RR |
85 | } |
86 | else | |
87 | { | |
88 | wxNode *next = node->Next(); | |
89 | m_images.DeleteNode( node ); | |
f60d0f94 | 90 | m_images.Insert( next, newBitmap ); |
b46e8696 | 91 | } |
c801d85f | 92 | |
b46e8696 | 93 | return TRUE; |
e1e955e1 | 94 | } |
c801d85f | 95 | |
0423b685 | 96 | bool wxImageList::Remove( int index ) |
c801d85f | 97 | { |
b46e8696 RR |
98 | wxNode *node = m_images.Nth( index ); |
99 | ||
87138c52 | 100 | wxCHECK_MSG( node, FALSE, _T("wrong index in image list") ); |
b46e8696 RR |
101 | |
102 | m_images.DeleteNode( node ); | |
103 | ||
104 | return TRUE; | |
e1e955e1 | 105 | } |
c801d85f | 106 | |
0423b685 | 107 | bool wxImageList::RemoveAll() |
c801d85f | 108 | { |
b46e8696 RR |
109 | m_images.Clear(); |
110 | ||
111 | return TRUE; | |
e1e955e1 | 112 | } |
c801d85f | 113 | |
0423b685 | 114 | bool wxImageList::GetSize( int index, int &width, int &height ) const |
c801d85f | 115 | { |
b46e8696 RR |
116 | width = 0; |
117 | height = 0; | |
118 | ||
119 | wxNode *node = m_images.Nth( index ); | |
120 | ||
87138c52 | 121 | wxCHECK_MSG( node, FALSE, _T("wrong index in image list") ); |
b46e8696 | 122 | |
c801d85f KB |
123 | wxBitmap *bm = (wxBitmap*)node->Data(); |
124 | width = bm->GetWidth(); | |
125 | height = bm->GetHeight(); | |
b46e8696 | 126 | |
c801d85f | 127 | return TRUE; |
e1e955e1 | 128 | } |
c801d85f | 129 | |
219f895a RR |
130 | bool wxImageList::Draw( int index, wxDC &dc, int x, int y, |
131 | int flags, bool WXUNUSED(solidBackground) ) | |
c801d85f | 132 | { |
b46e8696 RR |
133 | wxNode *node = m_images.Nth( index ); |
134 | ||
87138c52 | 135 | wxCHECK_MSG( node, FALSE, _T("wrong index in image list") ); |
b46e8696 RR |
136 | |
137 | wxBitmap *bm = (wxBitmap*)node->Data(); | |
f60d0f94 JS |
138 | |
139 | if (bm->IsKindOf(CLASSINFO(wxIcon))) | |
140 | dc.DrawIcon( * ((wxIcon*) bm), x, y); | |
141 | else | |
142 | dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 ); | |
219f895a | 143 | |
b46e8696 | 144 | return TRUE; |
e1e955e1 | 145 | } |
c801d85f KB |
146 | |
147 |