]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
wxTreeCtrl::Delete() bug corrected, sample expanded to test it
[wxWidgets.git] / src / generic / imaglist.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: imaglist.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "imaglist.h"
12 #endif
13
14 #include "wx/imaglist.h"
15
16 //-----------------------------------------------------------------------------
17 // wxImageList
18 //-----------------------------------------------------------------------------
19
20 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
21
22 wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
23 {
24 m_width = width;
25 m_height = height;
26 Create();
27 }
28
29 wxImageList::~wxImageList()
30 {
31 }
32
33 int wxImageList::GetImageCount() const
34 {
35 return m_images.Number();
36 }
37
38 bool wxImageList::Create()
39 {
40 m_images.DeleteContents( TRUE );
41 return TRUE;
42 }
43
44 int wxImageList::Add( const wxBitmap &bitmap )
45 {
46 m_images.Append( new wxBitmap(bitmap) );
47 return m_images.Number();
48 }
49
50 const wxBitmap *wxImageList::GetBitmap(int index) const {
51 wxNode *node = m_images.Nth(index);
52 if (node != NULL)
53 return (wxBitmap*)node->Data();
54
55 return (wxBitmap *) NULL;
56 }
57
58 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
59 {
60 wxNode *node = m_images.Nth( index );
61 if (!node) return FALSE;
62
63 if (index == m_images.Number()-1)
64 {
65 m_images.DeleteNode( node );
66 m_images.Append( new wxBitmap(bitmap) );
67 }
68 else
69 {
70 wxNode *next = node->Next();
71 m_images.DeleteNode( node );
72 m_images.Insert( next, new wxBitmap(bitmap) );
73 }
74
75 return TRUE;
76 }
77
78 bool wxImageList::Remove( int index )
79 {
80 wxNode *node = m_images.Nth( index );
81 if (node) m_images.DeleteNode( node );
82 return (node != NULL);
83 }
84
85 bool wxImageList::RemoveAll()
86 {
87 m_images.Clear();
88 return TRUE;
89 }
90
91 bool wxImageList::GetSize( int index, int &width, int &height ) const
92 {
93 wxNode *node = m_images.Nth( index );
94 if (node)
95 {
96 wxBitmap *bm = (wxBitmap*)node->Data();
97 width = bm->GetWidth();
98 height = bm->GetHeight();
99 return TRUE;
100 }
101 else
102 {
103 width = 0;
104 height = 0;
105 return FALSE;
106 }
107 }
108
109 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
110 int flags, bool WXUNUSED(solidBackground) )
111 {
112 wxNode *node = m_images.Nth( index );
113 if (!node) return FALSE;
114 wxBitmap *bm = (wxBitmap*)node->Data();
115
116 wxIcon *icon = (wxIcon*)bm;
117 dc.DrawIcon( *icon, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
118
119 return TRUE;
120 }
121
122