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