]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
CW Win32 support
[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 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "wx/imaglist.h"
22
23 //-----------------------------------------------------------------------------
24 // wxImageList
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
28
29 wxImageList::wxImageList( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
30 {
31 m_width = width;
32 m_height = height;
33 Create();
34 }
35
36 wxImageList::~wxImageList()
37 {
38 }
39
40 int wxImageList::GetImageCount() const
41 {
42 return m_images.Number();
43 }
44
45 bool wxImageList::Create()
46 {
47 m_images.DeleteContents( TRUE );
48 return TRUE;
49 }
50
51 int wxImageList::Add( const wxBitmap &bitmap )
52 {
53 m_images.Append( new wxBitmap(bitmap) );
54 return m_images.Number();
55 }
56
57 const wxBitmap *wxImageList::GetBitmap( int index ) const
58 {
59 wxNode *node = m_images.Nth( index );
60
61 wxCHECK_MSG( node, (wxBitmap *) NULL, "wrong index in image list" );
62
63 return (wxBitmap*)node->Data();
64 }
65
66 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
67 {
68 wxNode *node = m_images.Nth( index );
69
70 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
71
72 if (index == m_images.Number()-1)
73 {
74 m_images.DeleteNode( node );
75 m_images.Append( new wxBitmap(bitmap) );
76 }
77 else
78 {
79 wxNode *next = node->Next();
80 m_images.DeleteNode( node );
81 m_images.Insert( next, new wxBitmap(bitmap) );
82 }
83
84 return TRUE;
85 }
86
87 bool wxImageList::Remove( int index )
88 {
89 wxNode *node = m_images.Nth( index );
90
91 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
92
93 m_images.DeleteNode( node );
94
95 return TRUE;
96 }
97
98 bool wxImageList::RemoveAll()
99 {
100 m_images.Clear();
101
102 return TRUE;
103 }
104
105 bool wxImageList::GetSize( int index, int &width, int &height ) const
106 {
107 width = 0;
108 height = 0;
109
110 wxNode *node = m_images.Nth( index );
111
112 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
113
114 wxBitmap *bm = (wxBitmap*)node->Data();
115 width = bm->GetWidth();
116 height = bm->GetHeight();
117
118 return TRUE;
119 }
120
121 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
122 int flags, bool WXUNUSED(solidBackground) )
123 {
124 wxNode *node = m_images.Nth( index );
125
126 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
127
128 wxBitmap *bm = (wxBitmap*)node->Data();
129
130 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
131
132 return TRUE;
133 }
134
135