]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
wxString::Truncates() now doesn't change the sharied copies of the string
[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 {
52 wxNode *node = m_images.Nth( index );
53
54 wxCHECK_MSG( node, (wxBitmap *) NULL, "wrong index in image list" );
55
56 return (wxBitmap*)node->Data();
57 }
58
59 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
60 {
61 wxNode *node = m_images.Nth( index );
62
63 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
64
65 if (index == m_images.Number()-1)
66 {
67 m_images.DeleteNode( node );
68 m_images.Append( new wxBitmap(bitmap) );
69 }
70 else
71 {
72 wxNode *next = node->Next();
73 m_images.DeleteNode( node );
74 m_images.Insert( next, new wxBitmap(bitmap) );
75 }
76
77 return TRUE;
78 }
79
80 bool wxImageList::Remove( int index )
81 {
82 wxNode *node = m_images.Nth( index );
83
84 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
85
86 m_images.DeleteNode( node );
87
88 return TRUE;
89 }
90
91 bool wxImageList::RemoveAll()
92 {
93 m_images.Clear();
94
95 return TRUE;
96 }
97
98 bool wxImageList::GetSize( int index, int &width, int &height ) const
99 {
100 width = 0;
101 height = 0;
102
103 wxNode *node = m_images.Nth( index );
104
105 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
106
107 wxBitmap *bm = (wxBitmap*)node->Data();
108 width = bm->GetWidth();
109 height = bm->GetHeight();
110
111 return TRUE;
112 }
113
114 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
115 int flags, bool WXUNUSED(solidBackground) )
116 {
117 wxNode *node = m_images.Nth( index );
118
119 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
120
121 wxBitmap *bm = (wxBitmap*)node->Data();
122
123 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
124
125 return TRUE;
126 }
127
128