]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
i18n fixes
[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
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 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
54 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
55 else
56 m_images.Append( new wxBitmap(bitmap) );
57 return m_images.Number();
58 }
59
60 const wxBitmap *wxImageList::GetBitmap( int index ) const
61 {
62 wxNode *node = m_images.Nth( index );
63
64 wxCHECK_MSG( node, (wxBitmap *) NULL, "wrong index in image list" );
65
66 return (wxBitmap*)node->Data();
67 }
68
69 bool wxImageList::Replace( int index, const wxBitmap &bitmap )
70 {
71 wxNode *node = m_images.Nth( index );
72
73 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
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
81 if (index == m_images.Number()-1)
82 {
83 m_images.DeleteNode( node );
84 m_images.Append( newBitmap );
85 }
86 else
87 {
88 wxNode *next = node->Next();
89 m_images.DeleteNode( node );
90 m_images.Insert( next, newBitmap );
91 }
92
93 return TRUE;
94 }
95
96 bool wxImageList::Remove( int index )
97 {
98 wxNode *node = m_images.Nth( index );
99
100 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
101
102 m_images.DeleteNode( node );
103
104 return TRUE;
105 }
106
107 bool wxImageList::RemoveAll()
108 {
109 m_images.Clear();
110
111 return TRUE;
112 }
113
114 bool wxImageList::GetSize( int index, int &width, int &height ) const
115 {
116 width = 0;
117 height = 0;
118
119 wxNode *node = m_images.Nth( index );
120
121 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
122
123 wxBitmap *bm = (wxBitmap*)node->Data();
124 width = bm->GetWidth();
125 height = bm->GetHeight();
126
127 return TRUE;
128 }
129
130 bool wxImageList::Draw( int index, wxDC &dc, int x, int y,
131 int flags, bool WXUNUSED(solidBackground) )
132 {
133 wxNode *node = m_images.Nth( index );
134
135 wxCHECK_MSG( node, FALSE, "wrong index in image list" );
136
137 wxBitmap *bm = (wxBitmap*)node->Data();
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 );
143
144 return TRUE;
145 }
146
147